16
16
import ruamel .yaml as yaml
17
17
import ruamel .yaml .scanner as yamlscanner
18
18
import schema_salad .ref_resolver
19
+ import schema_salad .schema
20
+ import schema_salad .avro .schema
19
21
import pkg_resources # part of setuptools
20
22
21
23
import junit_xml
@@ -49,6 +51,7 @@ def prepare_test_command(
49
51
args , # type: List[str]
50
52
testargs , # type: Optional[List[str]]
51
53
test , # type: Dict[str, str]
54
+ cwd , # type: str
52
55
verbose = False , # type: bool
53
56
): # type: (...) -> List[str]
54
57
""" Turn the test into a command line. """
@@ -77,9 +80,18 @@ def prepare_test_command(
77
80
test_command .extend (["--outdir={}" .format (outdir )])
78
81
if not verbose :
79
82
test_command .extend (["--quiet" ])
80
- test_command .extend ([os .path .normcase (test ["tool" ])])
81
- if test .get ("job" ):
82
- test_command .append (os .path .normcase (test ["job" ]))
83
+
84
+ cwd = schema_salad .ref_resolver .file_uri (cwd )
85
+ toolpath = test ["tool" ]
86
+ if toolpath .startswith (cwd ):
87
+ toolpath = toolpath [len (cwd )+ 1 :]
88
+ test_command .extend ([os .path .normcase (toolpath )])
89
+
90
+ jobpath = test .get ("job" )
91
+ if jobpath :
92
+ if jobpath .startswith (cwd ):
93
+ jobpath = jobpath [len (cwd )+ 1 :]
94
+ test_command .append (os .path .normcase (jobpath ))
83
95
return test_command
84
96
85
97
@@ -106,8 +118,9 @@ def run_test(
106
118
suffix = "\n "
107
119
try :
108
120
process = None # type: Optional[subprocess.Popen[str]]
121
+ cwd = os .getcwd ()
109
122
test_command = prepare_test_command (
110
- args .tool , args .args , args .testargs , test , verbose
123
+ args .tool , args .args , args .testargs , test , cwd , verbose
111
124
)
112
125
113
126
if test .get ("short_name" ):
@@ -131,7 +144,7 @@ def run_test(
131
144
132
145
start_time = time .time ()
133
146
stderr = subprocess .PIPE if not args .verbose else None
134
- process = subprocess .Popen (test_command , stdout = subprocess .PIPE , stderr = stderr , universal_newlines = True )
147
+ process = subprocess .Popen (test_command , stdout = subprocess .PIPE , stderr = stderr , universal_newlines = True , cwd = cwd )
135
148
outstr , outerr = process .communicate (timeout = timeout )
136
149
return_code = process .poll ()
137
150
duration = time .time () - start_time
@@ -342,8 +355,18 @@ def main(): # type: () -> int
342
355
arg_parser ().print_help ()
343
356
return 1
344
357
345
- with open (args .test ) as f :
346
- tests = yaml .load (f , Loader = yaml .SafeLoader )
358
+ schema_resource = pkg_resources .resource_stream (__name__ , "cwltest-schema.yml" )
359
+ cache = {"https://w3id.org/cwl/cwltest/cwltest-schema.yml" : schema_resource .read ().decode ("utf-8" )}
360
+ (document_loader ,
361
+ avsc_names ,
362
+ schema_metadata ,
363
+ metaschema_loader ) = schema_salad .schema .load_schema ("https://w3id.org/cwl/cwltest/cwltest-schema.yml" , cache = cache )
364
+
365
+ if not isinstance (avsc_names , schema_salad .avro .schema .Names ):
366
+ print (avsc_names )
367
+ return 1
368
+
369
+ tests , metadata = schema_salad .schema .load_and_validate (document_loader , avsc_names , args .test , True )
347
370
348
371
failures = 0
349
372
unsupported = 0
@@ -378,6 +401,10 @@ def main(): # type: () -> int
378
401
if any ((tag in ts for tag in tags )):
379
402
tests .append (t )
380
403
404
+ for t in tests :
405
+ if t .get ("label" ):
406
+ t ["short_name" ] = t ["label" ]
407
+
381
408
if args .l :
382
409
for i , t in enumerate (tests ):
383
410
if t .get ("short_name" ):
0 commit comments