37
37
UNSUPPORTED_FEATURE = 33
38
38
DEFAULT_TIMEOUT = 600 # 10 minutes
39
39
40
- if sys .version_info < (3 , 0 ):
41
- import subprocess32 as subprocess # nosec
42
- from pipes import quote
43
- else :
44
- import subprocess # nosec
45
- from shlex import quote
40
+ import subprocess # nosec
41
+ from shlex import quote
46
42
47
43
templock = threading .Lock ()
48
44
@@ -55,7 +51,7 @@ def prepare_test_command(
55
51
cwd , # type: str
56
52
verbose = False , # type: bool
57
53
): # type: (...) -> List[str]
58
- """ Turn the test into a command line. """
54
+ """Turn the test into a command line."""
59
55
test_command = [tool ]
60
56
test_command .extend (args )
61
57
@@ -72,26 +68,26 @@ def prepare_test_command(
72
68
outdir = tempfile .mkdtemp (prefix = os .path .abspath (os .path .curdir ))
73
69
test_command .extend (
74
70
[
75
- "--tmp-outdir-prefix={}" . format ( outdir ) ,
76
- "--tmpdir-prefix={}" . format ( outdir ) ,
71
+ f "--tmp-outdir-prefix={ outdir } " ,
72
+ f "--tmpdir-prefix={ outdir } " ,
77
73
]
78
74
)
79
75
else :
80
76
outdir = tempfile .mkdtemp ()
81
- test_command .extend (["--outdir={}" . format ( outdir ) ])
77
+ test_command .extend ([f "--outdir={ outdir } " ])
82
78
if not verbose :
83
79
test_command .extend (["--quiet" ])
84
80
85
81
cwd = schema_salad .ref_resolver .file_uri (cwd )
86
82
toolpath = test ["tool" ]
87
83
if toolpath .startswith (cwd ):
88
- toolpath = toolpath [len (cwd )+ 1 :]
84
+ toolpath = toolpath [len (cwd ) + 1 :]
89
85
test_command .extend ([os .path .normcase (toolpath )])
90
86
91
87
jobpath = test .get ("job" )
92
88
if jobpath :
93
89
if jobpath .startswith (cwd ):
94
- jobpath = jobpath [len (cwd )+ 1 :]
90
+ jobpath = jobpath [len (cwd ) + 1 :]
95
91
test_command .append (os .path .normcase (jobpath ))
96
92
return test_command
97
93
@@ -108,7 +104,7 @@ def run_test(
108
104
global templock
109
105
110
106
out = {} # type: Dict[str,Any]
111
- outdir = outstr = outerr = u ""
107
+ outdir = outstr = outerr = ""
112
108
test_command = [] # type: List[str]
113
109
duration = 0.0
114
110
prefix = ""
@@ -145,7 +141,13 @@ def run_test(
145
141
146
142
start_time = time .time ()
147
143
stderr = subprocess .PIPE if not args .verbose else None
148
- process = subprocess .Popen (test_command , stdout = subprocess .PIPE , stderr = stderr , universal_newlines = True , cwd = cwd ) # nosec
144
+ process = subprocess .Popen ( # nosec
145
+ test_command ,
146
+ stdout = subprocess .PIPE ,
147
+ stderr = stderr ,
148
+ universal_newlines = True ,
149
+ cwd = cwd ,
150
+ )
149
151
outstr , outerr = process .communicate (timeout = timeout )
150
152
return_code = process .poll ()
151
153
duration = time .time () - start_time
@@ -167,25 +169,25 @@ def run_test(
167
169
if test .get ("should_fail" , False ):
168
170
return TestResult (0 , outstr , outerr , duration , args .classname )
169
171
_logger .error (
170
- u """Test %i failed: %s""" ,
172
+ """Test %i failed: %s""" ,
171
173
test_number ,
172
174
" " .join ([quote (tc ) for tc in test_command ]),
173
175
)
174
176
_logger .error (test .get ("doc" ))
175
177
if err .returncode == UNSUPPORTED_FEATURE :
176
- _logger .error (u "Does not support required feature" )
178
+ _logger .error ("Does not support required feature" )
177
179
else :
178
- _logger .error (u "Returned non-zero" )
180
+ _logger .error ("Returned non-zero" )
179
181
_logger .error (outerr )
180
182
return TestResult (1 , outstr , outerr , duration , args .classname , str (err ))
181
183
except (yamlscanner .ScannerError , TypeError ) as err :
182
184
_logger .error (
183
- u """Test %i failed: %s""" ,
185
+ """Test %i failed: %s""" ,
184
186
test_number ,
185
- u " " .join ([quote (tc ) for tc in test_command ]),
187
+ " " .join ([quote (tc ) for tc in test_command ]),
186
188
)
187
189
_logger .error (outstr )
188
- _logger .error (u "Parse error %s" , str (err ))
190
+ _logger .error ("Parse error %s" , str (err ))
189
191
_logger .error (outerr )
190
192
except KeyboardInterrupt :
191
193
_logger .error (
@@ -204,7 +206,7 @@ def run_test(
204
206
return TestResult (2 , outstr , outerr , timeout , args .classname , "Test timed out" )
205
207
finally :
206
208
if process is not None and process .returncode is None :
207
- _logger .error (u """Terminating lingering process""" )
209
+ _logger .error ("""Terminating lingering process""" )
208
210
process .terminate ()
209
211
for _ in range (0 , 3 ):
210
212
time .sleep (1 )
@@ -217,24 +219,24 @@ def run_test(
217
219
218
220
if test .get ("should_fail" , False ):
219
221
_logger .warning (
220
- u """Test %i failed: %s""" ,
222
+ """Test %i failed: %s""" ,
221
223
test_number ,
222
- u " " .join ([quote (tc ) for tc in test_command ]),
224
+ " " .join ([quote (tc ) for tc in test_command ]),
223
225
)
224
226
_logger .warning (test .get ("doc" ))
225
- _logger .warning (u "Returned zero but it should be non-zero" )
227
+ _logger .warning ("Returned zero but it should be non-zero" )
226
228
return TestResult (1 , outstr , outerr , duration , args .classname )
227
229
228
230
try :
229
231
compare (test .get ("output" ), out )
230
232
except CompareFail as ex :
231
233
_logger .warning (
232
- u """Test %i failed: %s""" ,
234
+ """Test %i failed: %s""" ,
233
235
test_number ,
234
- u " " .join ([quote (tc ) for tc in test_command ]),
236
+ " " .join ([quote (tc ) for tc in test_command ]),
235
237
)
236
238
_logger .warning (test .get ("doc" ))
237
- _logger .warning (u "Compare failure %s" , ex )
239
+ _logger .warning ("Compare failure %s" , ex )
238
240
fail_message = str (ex )
239
241
240
242
if outdir :
@@ -345,13 +347,14 @@ def arg_parser(): # type: () -> argparse.ArgumentParser
345
347
346
348
pkg = pkg_resources .require ("cwltest" )
347
349
if pkg :
348
- ver = u"%s %s" % ( sys .argv [0 ], pkg [0 ].version )
350
+ ver = f" { sys .argv [0 ]} { pkg [0 ].version } "
349
351
else :
350
- ver = u"%s %s" % (sys .argv [0 ], "unknown version" )
352
+ ver = "{} {}" . format (sys .argv [0 ], "unknown version" )
351
353
parser .add_argument ("--version" , action = "version" , version = ver )
352
354
353
355
return parser
354
356
357
+
355
358
def expand_number_range (nr : str ) -> List [int ]:
356
359
ans : List [int ] = []
357
360
for s in nr .split ("," ):
@@ -362,6 +365,7 @@ def expand_number_range(nr: str) -> List[int]:
362
365
ans .append (int (s ) - 1 )
363
366
return ans
364
367
368
+
365
369
def main (): # type: () -> int
366
370
367
371
args = arg_parser ().parse_args (sys .argv [1 :])
@@ -558,12 +562,12 @@ def main(): # type: () -> int
558
562
else :
559
563
color = "yellow"
560
564
561
- with open ("{ }/{}.json". format ( args . badgedir , t ) , "w" ) as out :
565
+ with open (f" { args . badgedir } /{ t } .json" , "w" ) as out :
562
566
out .write (
563
567
json .dumps (
564
568
{
565
- "subject" : "{}" . format ( t ) ,
566
- "status" : "{ }%". format ( percent ) ,
569
+ "subject" : f" { t } " ,
570
+ "status" : f" { percent } %" ,
567
571
"color" : color ,
568
572
}
569
573
)
0 commit comments