1
1
import os
2
+ import re
2
3
import sys
3
4
from textwrap import dedent
4
5
@@ -2085,18 +2086,16 @@ def test_parse_recreate(self, newconfig):
2085
2086
2086
2087
class TestCmdInvocation :
2087
2088
def test_help (self , cmd ):
2088
- result = cmd . run ( "tox" , "-h" )
2089
+ result = cmd ( "-h" )
2089
2090
assert not result .ret
2090
- result .stdout .fnmatch_lines ([
2091
- "*help*"
2092
- ])
2091
+ assert not result .err
2092
+ assert re .match (r'usage:.*help.*' , result .out , re .DOTALL )
2093
2093
2094
2094
def test_version_simple (self , cmd ):
2095
- result = cmd . run ( "tox" , "--version" )
2095
+ result = cmd ( "--version" )
2096
2096
assert not result .ret
2097
- stdout = result .stdout .str ()
2098
- assert tox .__version__ in stdout
2099
- assert "imported from" in stdout
2097
+ from tox import __version__
2098
+ assert "{} imported from" .format (__version__ ) in result .out
2100
2099
2101
2100
def test_version_no_plugins (self ):
2102
2101
pm = PluginManager ('fakeprject' )
@@ -2163,14 +2162,8 @@ def test_listenvs(self, cmd, initproj):
2163
2162
changedir = docs
2164
2163
'''
2165
2164
})
2166
- result = cmd .run ("tox" , "-l" )
2167
- result .stdout .fnmatch_lines ("""
2168
- py36
2169
- py27
2170
- py34
2171
- pypy
2172
- docs
2173
- """ )
2165
+ result = cmd ("-l" )
2166
+ assert result .outlines == ['py36' , 'py27' , 'py34' , 'pypy' , 'docs' ]
2174
2167
2175
2168
def test_listenvs_verbose_description (self , cmd , initproj ):
2176
2169
initproj ('listenvs_verbose_description' , filedefs = {
@@ -2193,15 +2186,14 @@ def test_listenvs_verbose_description(self, cmd, initproj):
2193
2186
description = let me overwrite that
2194
2187
'''
2195
2188
})
2196
- result = cmd .run ("tox" , "-lv" )
2197
- result .stdout .fnmatch_lines ("""
2198
- default environments:
2199
- py36 -> run pytest on Python 3.6
2200
- py27 -> run pytest on Python 2.7
2201
- py34 -> run pytest on Python 3.4
2202
- pypy -> publish to pypy
2203
- docs -> let me overwrite that
2204
- """ )
2189
+ result = cmd ("-lv" )
2190
+ assert result .outlines [2 :] == [
2191
+ 'default environments:' ,
2192
+ 'py36 -> run pytest on Python 3.6' ,
2193
+ 'py27 -> run pytest on Python 2.7' ,
2194
+ 'py34 -> run pytest on Python 3.4' ,
2195
+ 'pypy -> publish to pypy' ,
2196
+ 'docs -> let me overwrite that' ]
2205
2197
2206
2198
def test_listenvs_all (self , cmd , initproj ):
2207
2199
initproj ('listenvs_all' , filedefs = {
@@ -2216,15 +2208,8 @@ def test_listenvs_all(self, cmd, initproj):
2216
2208
changedir = docs
2217
2209
'''
2218
2210
})
2219
- result = cmd .run ("tox" , "-a" )
2220
- result .stdout .fnmatch_lines ("""
2221
- py36
2222
- py27
2223
- py34
2224
- pypy
2225
- docs
2226
- notincluded
2227
- """ )
2211
+ result = cmd ("-a" )
2212
+ assert result .outlines == ['py36' , 'py27' , 'py34' , 'pypy' , 'docs' , 'notincluded' ]
2228
2213
2229
2214
def test_listenvs_all_verbose_description (self , cmd , initproj ):
2230
2215
initproj ('listenvs_all_verbose_description' , filedefs = {
@@ -2241,19 +2226,19 @@ def test_listenvs_all_verbose_description(self, cmd, initproj):
2241
2226
2242
2227
[testenv:docs]
2243
2228
changedir = docs
2244
- '''
2229
+ ''' ,
2245
2230
})
2246
- result = cmd . run ( "tox" , "-av" )
2247
- result . stdout . fnmatch_lines ( """
2248
- default environments:
2249
- py27-windows -> run pytest on Python 2.7 on Windows platform
2250
- py27-linux -> run pytest on Python 2.7 on Linux platform
2251
- py36-windows -> run pytest on Python 3.6 on Windows platform
2252
- py36-linux -> run pytest on Python 3.6 on Linux platform
2253
-
2254
- additional environments:
2255
- docs -> generate documentation
2256
- """ )
2231
+ result = cmd ( "-av" )
2232
+ expected = [
2233
+ " default environments:" ,
2234
+ " py27-windows -> run pytest on Python 2.7 on Windows platform" ,
2235
+ " py27-linux -> run pytest on Python 2.7 on Linux platform" ,
2236
+ " py36-windows -> run pytest on Python 3.6 on Windows platform" ,
2237
+ " py36-linux -> run pytest on Python 3.6 on Linux platform" ,
2238
+ "" ,
2239
+ " additional environments:" ,
2240
+ " docs -> generate documentation" ]
2241
+ assert result . outlines [ - len ( expected ):] == expected
2257
2242
2258
2243
def test_listenvs_all_verbose_description_no_additional_environments (self , cmd , initproj ):
2259
2244
initproj ('listenvs_all_verbose_description' , filedefs = {
@@ -2262,29 +2247,25 @@ def test_listenvs_all_verbose_description_no_additional_environments(self, cmd,
2262
2247
envlist=py27,py36
2263
2248
'''
2264
2249
})
2265
- result = cmd .run ("tox" , "-av" )
2266
- result .stdout .fnmatch_lines ("""
2267
- default environments:
2268
- py27 -> [no description]
2269
- py36 -> [no description]
2270
- """ )
2271
- assert 'additional environments' not in result .stdout .str ()
2250
+ result = cmd ("-av" )
2251
+ expected = ["default environments:" ,
2252
+ "py27 -> [no description]" ,
2253
+ "py36 -> [no description]" ]
2254
+ assert result .out .splitlines ()[- 3 :] == expected
2255
+ assert 'additional environments' not in result .out
2272
2256
2273
2257
def test_config_specific_ini (self , tmpdir , cmd ):
2274
2258
ini = tmpdir .ensure ("hello.ini" )
2275
- result = cmd . run ( "tox" , "-c" , ini , "--showconfig" )
2259
+ result = cmd ( "-c" , ini , "--showconfig" )
2276
2260
assert not result .ret
2277
- result .stdout .fnmatch_lines ([
2278
- "*config-file*hello.ini*"
2279
- ])
2261
+ assert result .outlines [1 ] == 'config-file: {}' .format (ini )
2280
2262
2281
2263
def test_no_tox_ini (self , cmd , initproj ):
2282
- initproj ("noini-0.5" )
2283
- result = cmd . run ( "tox" )
2264
+ initproj ("noini-0.5" , )
2265
+ result = cmd ( )
2284
2266
assert result .ret
2285
- result .stderr .fnmatch_lines ([
2286
- "*ERROR*tox.ini*not*found*"
2287
- ])
2267
+ assert result .out == ''
2268
+ assert result .err == "ERROR: toxini file 'tox.ini' not found\n "
2288
2269
2289
2270
def test_override_workdir (self , tmpdir , cmd , initproj ):
2290
2271
baddir = "badworkdir-123"
@@ -2293,13 +2274,12 @@ def test_override_workdir(self, tmpdir, cmd, initproj):
2293
2274
'tox.ini' : '''
2294
2275
[tox]
2295
2276
toxworkdir=%s
2296
- ''' % baddir
2277
+ ''' % baddir ,
2297
2278
})
2298
- result = cmd . run ( "tox" , "--workdir" , gooddir , "--showconfig" )
2279
+ result = cmd ( "--workdir" , gooddir , "--showconfig" )
2299
2280
assert not result .ret
2300
- stdout = result .stdout .str ()
2301
- assert gooddir in stdout
2302
- assert baddir not in stdout
2281
+ assert gooddir in result .out
2282
+ assert baddir not in result .out
2303
2283
assert py .path .local (gooddir ).check ()
2304
2284
assert not py .path .local (baddir ).check ()
2305
2285
@@ -2312,20 +2292,16 @@ def test_showconfig_with_force_dep_version(self, cmd, initproj):
2312
2292
deps=
2313
2293
dep1==2.3
2314
2294
dep2
2315
- '''
2295
+ ''' ,
2316
2296
})
2317
- result = cmd . run ( "tox" , "--showconfig" )
2297
+ result = cmd ( "--showconfig" )
2318
2298
assert result .ret == 0
2319
- result .stdout .fnmatch_lines ([
2320
- r'*deps*dep1==2.3, dep2*'
2321
- ])
2299
+ assert any (re .match (r'.*deps.*dep1==2.3, dep2.*' , l ) for l in result .outlines )
2322
2300
# override dep1 specific version, and force version for dep2
2323
- result = cmd . run ( "tox" , "--showconfig" , "--force-dep=dep1" ,
2324
- "--force-dep=dep2==5.0" )
2301
+ result = cmd ( "--showconfig" , "--force-dep=dep1" ,
2302
+ "--force-dep=dep2==5.0" )
2325
2303
assert result .ret == 0
2326
- result .stdout .fnmatch_lines ([
2327
- r'*deps*dep1, dep2==5.0*'
2328
- ])
2304
+ assert any (re .match (r'.*deps.*dep1, dep2==5.0.*' , l ) for l in result .outlines )
2329
2305
2330
2306
@pytest .mark .xfail (
2331
2307
"'pypy' not in sys.executable" ,
@@ -2340,7 +2316,7 @@ def test_colon_symbol_in_directory_name(self, cmd, initproj):
2340
2316
commands = pip --version
2341
2317
'''
2342
2318
})
2343
- result = cmd . run ( "tox" )
2319
+ result = cmd ( )
2344
2320
assert result .ret == 0
2345
2321
2346
2322
0 commit comments