2121from concurrent .futures import ThreadPoolExecutor
2222from six .moves import range
2323from six .moves import zip
24- from typing import Any , Dict , List
24+ from typing import Any , Dict , List , Text
2525
2626from cwltest .utils import compare , CompareFail , TestResult
2727
4040templock = threading .Lock ()
4141
4242
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+
4371def run_test (args , i , tests , timeout ):
4472 # type: (argparse.Namespace, int, List[Dict[str, str]], int) -> TestResult
4573
@@ -56,28 +84,7 @@ def run_test(args, i, tests, timeout):
5684 else :
5785 suffix = "\n "
5886 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 )
8188
8289 sys .stderr .write ("%sTest [%i/%i] %s\n " % (prefix , i + 1 , len (tests ), suffix ))
8390 sys .stderr .flush ()
@@ -142,8 +149,7 @@ def run_test(args, i, tests, timeout):
142149 return TestResult ((1 if fail_message else 0 ), outstr , outerr , duration , args .classname , fail_message )
143150
144151
145- def main (): # type: () -> int
146-
152+ def arg_parser (): # type: () -> argparse.ArgumentParser
147153 parser = argparse .ArgumentParser (description = 'Compliance tests for cwltool' )
148154 parser .add_argument ("--test" , type = str , help = "YAML file describing test cases" , required = True )
149155 parser .add_argument ("--basedir" , type = str , help = "Basedir to use for tests" , default = "." )
@@ -164,8 +170,12 @@ def main(): # type: () -> int
164170 parser .add_argument ("--timeout" , type = int , default = DEFAULT_TIMEOUT , help = "Time of execution in seconds after "
165171 "which the test will be skipped."
166172 "Defaults to 900 sec (15 minutes)" )
173+ return parser
174+
175+
176+ def main (): # type: () -> int
167177
168- args = parser .parse_args ()
178+ args = arg_parser () .parse_args (sys . argv [ 1 :] )
169179 if '--' in args .args :
170180 args .args .remove ('--' )
171181
@@ -174,7 +184,7 @@ def main(): # type: () -> int
174184 args .testargs = [testarg for testarg in args .testargs if testarg .count ('==' ) == 1 ]
175185
176186 if not args .test :
177- parser .print_help ()
187+ arg_parser () .print_help ()
178188 return 1
179189
180190 with open (args .test ) as f :
0 commit comments