7
7
from importlib .resources import files
8
8
from io import StringIO
9
9
from pathlib import Path
10
- from typing import Any , Optional
10
+ from typing import Any , Optional , cast
11
11
12
12
import pytest
13
13
from ruamel .yaml .comments import CommentedMap , CommentedSeq
14
14
from schema_salad .avro .schema import Names
15
+ from schema_salad .ref_resolver import file_uri
15
16
from schema_salad .utils import yaml_no_ts
16
17
17
18
import cwltool .load_tool
18
19
import cwltool .singularity
19
20
import cwltool .udocker
20
21
from cwltool .command_line_tool import CommandLineTool
21
- from cwltool .context import LoadingContext , RuntimeContext
22
+ from cwltool .context import RuntimeContext
22
23
from cwltool .main import main
23
24
from cwltool .mpi import MpiConfig , MPIRequirementName
24
25
@@ -292,15 +293,22 @@ def schema_ext11() -> Generator[Names, None, None]:
292
293
293
294
mpiReq = CommentedMap ({"class" : MPIRequirementName , "processes" : 1 })
294
295
containerReq = CommentedMap ({"class" : "DockerRequirement" })
295
- basetool = CommentedMap ({"cwlVersion" : "v1.1" , "inputs" : CommentedSeq (), "outputs" : CommentedSeq ()})
296
+ basetool = CommentedMap (
297
+ {
298
+ "cwlVersion" : "v1.1" ,
299
+ "class" : "CommandLineTool" ,
300
+ "inputs" : CommentedSeq (),
301
+ "outputs" : CommentedSeq (),
302
+ }
303
+ )
296
304
297
305
298
306
def mk_tool (
299
307
schema : Names ,
300
308
opts : list [str ],
301
309
reqs : Optional [list [CommentedMap ]] = None ,
302
310
hints : Optional [list [CommentedMap ]] = None ,
303
- ) -> tuple [LoadingContext , RuntimeContext , CommentedMap ]:
311
+ ) -> tuple [RuntimeContext , CommandLineTool ]:
304
312
tool = basetool .copy ()
305
313
306
314
if reqs is not None :
@@ -310,53 +318,57 @@ def mk_tool(
310
318
311
319
args = cwltool .argparser .arg_parser ().parse_args (opts )
312
320
args .enable_ext = True
321
+ args .basedir = os .path .dirname (os .path .abspath ("." ))
313
322
rc = RuntimeContext (vars (args ))
314
323
lc = cwltool .main .setup_loadingContext (None , rc , args )
315
324
lc .avsc_names = schema
316
- return lc , rc , tool
325
+ tool ["id" ] = file_uri (os .path .abspath ("./mktool.cwl" ))
326
+ assert lc .loader is not None
327
+ lc .loader .idx [tool ["id" ]] = tool
328
+ return rc , cast (CommandLineTool , cwltool .load_tool .load_tool (tool , lc ))
317
329
318
330
319
331
def test_singularity (schema_ext11 : Names ) -> None :
320
- lc , rc , tool = mk_tool (schema_ext11 , ["--singularity" ], reqs = [mpiReq , containerReq ])
321
- clt = CommandLineTool ( tool , lc )
332
+ rc , clt = mk_tool (schema_ext11 , ["--singularity" ], reqs = [mpiReq , containerReq ])
333
+ clt . _init_job ({}, rc )
322
334
jr = clt .make_job_runner (rc )
323
335
assert jr is cwltool .singularity .SingularityCommandLineJob
324
336
325
337
326
338
def test_udocker (schema_ext11 : Names ) -> None :
327
- lc , rc , tool = mk_tool (schema_ext11 , ["--udocker" ], reqs = [mpiReq , containerReq ])
328
- clt = CommandLineTool ( tool , lc )
339
+ rc , clt = mk_tool (schema_ext11 , ["--udocker" ], reqs = [mpiReq , containerReq ])
340
+ clt . _init_job ({}, rc )
329
341
jr = clt .make_job_runner (rc )
330
342
assert jr is cwltool .udocker .UDockerCommandLineJob
331
343
332
344
333
345
def test_docker_hint (schema_ext11 : Names ) -> None :
334
346
# Docker hint, MPI required
335
- lc , rc , tool = mk_tool (schema_ext11 , [], hints = [containerReq ], reqs = [mpiReq ])
336
- clt = CommandLineTool ( tool , lc )
347
+ rc , clt = mk_tool (schema_ext11 , [], hints = [containerReq ], reqs = [mpiReq ])
348
+ clt . _init_job ({}, rc )
337
349
jr = clt .make_job_runner (rc )
338
350
assert jr is cwltool .job .CommandLineJob
339
351
340
352
341
353
def test_docker_required (schema_ext11 : Names ) -> None :
342
354
# Docker required, MPI hinted
343
- lc , rc , tool = mk_tool (schema_ext11 , [], reqs = [containerReq ], hints = [mpiReq ])
344
- clt = CommandLineTool ( tool , lc )
355
+ rc , clt = mk_tool (schema_ext11 , [], reqs = [containerReq ], hints = [mpiReq ])
356
+ clt . _init_job ({}, rc )
345
357
jr = clt .make_job_runner (rc )
346
358
assert jr is cwltool .docker .DockerCommandLineJob
347
359
348
360
349
361
def test_docker_mpi_both_required (schema_ext11 : Names ) -> None :
350
362
# Both required - error
351
- lc , rc , tool = mk_tool (schema_ext11 , [], reqs = [mpiReq , containerReq ])
352
- clt = CommandLineTool (tool , lc )
363
+ rc , clt = mk_tool (schema_ext11 , [], reqs = [mpiReq , containerReq ])
353
364
with pytest .raises (cwltool .errors .UnsupportedRequirement ):
354
- clt .make_job_runner (rc )
365
+ clt ._init_job ({}, rc )
366
+ clt .make_job_runner (rc )
355
367
356
368
357
369
def test_docker_mpi_both_hinted (schema_ext11 : Names ) -> None :
358
370
# Both hinted - error
359
- lc , rc , tool = mk_tool (schema_ext11 , [], hints = [mpiReq , containerReq ])
360
- clt = CommandLineTool (tool , lc )
371
+ rc , clt = mk_tool (schema_ext11 , [], hints = [mpiReq , containerReq ])
361
372
with pytest .raises (cwltool .errors .UnsupportedRequirement ):
362
- clt .make_job_runner (rc )
373
+ clt ._init_job ({}, rc )
374
+ clt .make_job_runner (rc )
0 commit comments