21
21
from concurrent .futures import ThreadPoolExecutor
22
22
from six .moves import range
23
23
from six .moves import zip
24
- from typing import Any , Dict , List
24
+ from typing import Any , Dict , List , Text
25
25
26
26
from cwltest .utils import compare , CompareFail , TestResult
27
27
40
40
templock = threading .Lock ()
41
41
42
42
43
+ def prepare_test_command (args , i , tests ):
44
+ # type: (argparse.Namespace, int, List[Dict[str, str]]) -> List[str]
45
+ t = tests [i ]
46
+ test_command = [args .tool ]
47
+ test_command .extend (args .args )
48
+
49
+ # Add additional arguments given in test case
50
+ if args .testargs is not None :
51
+ for testarg in args .testargs :
52
+ (test_case_name , prefix ) = testarg .split ('==' )
53
+ if test_case_name in t :
54
+ test_command .extend ([prefix , t [test_case_name ]])
55
+
56
+ # Add prefixes if running on MacOSX so that boot2docker writes to /Users
57
+ with templock :
58
+ if 'darwin' in sys .platform and args .tool == 'cwltool' :
59
+ outdir = tempfile .mkdtemp (prefix = os .path .abspath (os .path .curdir ))
60
+ test_command .extend (["--tmp-outdir-prefix={}" .format (outdir ), "--tmpdir-prefix={}" .format (outdir )])
61
+ else :
62
+ outdir = tempfile .mkdtemp ()
63
+ test_command .extend (["--outdir={}" .format (outdir ),
64
+ "--quiet" ,
65
+ t ["tool" ]])
66
+ if t .get ("job" ):
67
+ test_command .append (t ["job" ])
68
+ return test_command
69
+
70
+
43
71
def run_test (args , i , tests , timeout ):
44
72
# type: (argparse.Namespace, int, List[Dict[str, str]], int) -> TestResult
45
73
@@ -56,28 +84,7 @@ def run_test(args, i, tests, timeout):
56
84
else :
57
85
suffix = "\n "
58
86
try :
59
- test_command = [args .tool ]
60
- test_command .extend (args .args )
61
-
62
- # Add additional arguments given in test case
63
- if args .testargs is not None :
64
- for testarg in args .testargs :
65
- (test_case_name , prefix ) = testarg .split ('==' )
66
- if test_case_name in t :
67
- test_command .extend ([prefix , t [test_case_name ]])
68
-
69
- # Add prefixes if running on MacOSX so that boot2docker writes to /Users
70
- with templock :
71
- if 'darwin' in sys .platform and args .tool == 'cwltool' :
72
- outdir = tempfile .mkdtemp (prefix = os .path .abspath (os .path .curdir ))
73
- test_command .extend (["--tmp-outdir-prefix={}" .format (outdir ), "--tmpdir-prefix={}" .format (outdir )])
74
- else :
75
- outdir = tempfile .mkdtemp ()
76
- test_command .extend (["--outdir={}" .format (outdir ),
77
- "--quiet" ,
78
- t ["tool" ]])
79
- if t .get ("job" ):
80
- test_command .append (t ["job" ])
87
+ test_command = prepare_test_command (args , i , tests )
81
88
82
89
sys .stderr .write ("%sTest [%i/%i] %s\n " % (prefix , i + 1 , len (tests ), suffix ))
83
90
sys .stderr .flush ()
@@ -142,8 +149,7 @@ def run_test(args, i, tests, timeout):
142
149
return TestResult ((1 if fail_message else 0 ), outstr , outerr , duration , args .classname , fail_message )
143
150
144
151
145
- def main (): # type: () -> int
146
-
152
+ def arg_parser (): # type: () -> argparse.ArgumentParser
147
153
parser = argparse .ArgumentParser (description = 'Compliance tests for cwltool' )
148
154
parser .add_argument ("--test" , type = str , help = "YAML file describing test cases" , required = True )
149
155
parser .add_argument ("--basedir" , type = str , help = "Basedir to use for tests" , default = "." )
@@ -164,8 +170,12 @@ def main(): # type: () -> int
164
170
parser .add_argument ("--timeout" , type = int , default = DEFAULT_TIMEOUT , help = "Time of execution in seconds after "
165
171
"which the test will be skipped."
166
172
"Defaults to 900 sec (15 minutes)" )
173
+ return parser
174
+
175
+
176
+ def main (): # type: () -> int
167
177
168
- args = parser .parse_args ()
178
+ args = arg_parser () .parse_args (sys . argv [ 1 :] )
169
179
if '--' in args .args :
170
180
args .args .remove ('--' )
171
181
@@ -174,7 +184,7 @@ def main(): # type: () -> int
174
184
args .testargs = [testarg for testarg in args .testargs if testarg .count ('==' ) == 1 ]
175
185
176
186
if not args .test :
177
- parser .print_help ()
187
+ arg_parser () .print_help ()
178
188
return 1
179
189
180
190
with open (args .test ) as f :
0 commit comments