77from importlib .resources import files
88from io import StringIO
99from pathlib import Path
10- from typing import Any , Optional
10+ from typing import Any , Optional , cast
1111
1212import pytest
1313from ruamel .yaml .comments import CommentedMap , CommentedSeq
1414from schema_salad .avro .schema import Names
15+ from schema_salad .ref_resolver import file_uri
1516from schema_salad .utils import yaml_no_ts
1617
1718import cwltool .load_tool
1819import cwltool .singularity
1920import cwltool .udocker
20- from cwltool .command_line_tool import CommandLineTool
21- from cwltool .context import LoadingContext , RuntimeContext
21+ from cwltool .context import RuntimeContext
2222from cwltool .main import main
2323from cwltool .mpi import MpiConfig , MPIRequirementName
24+ from cwltool .command_line_tool import CommandLineTool
2425
2526from .util import get_data , working_directory
2627
@@ -292,15 +293,22 @@ def schema_ext11() -> Generator[Names, None, None]:
292293
293294mpiReq = CommentedMap ({"class" : MPIRequirementName , "processes" : 1 })
294295containerReq = 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+ )
296304
297305
298306def mk_tool (
299307 schema : Names ,
300308 opts : list [str ],
301309 reqs : Optional [list [CommentedMap ]] = None ,
302310 hints : Optional [list [CommentedMap ]] = None ,
303- ) -> tuple [LoadingContext , RuntimeContext , CommentedMap ]:
311+ ) -> tuple [RuntimeContext , CommandLineTool ]:
304312 tool = basetool .copy ()
305313
306314 if reqs is not None :
@@ -313,50 +321,53 @@ def mk_tool(
313321 rc = RuntimeContext (vars (args ))
314322 lc = cwltool .main .setup_loadingContext (None , rc , args )
315323 lc .avsc_names = schema
316- return lc , rc , tool
324+ tool ["id" ] = file_uri (os .path .abspath ("./mktool.cwl" ))
325+ assert lc .loader is not None
326+ lc .loader .idx [tool ["id" ]] = tool
327+ return rc , cast (CommandLineTool , cwltool .load_tool .load_tool (tool , lc ))
317328
318329
319330def test_singularity (schema_ext11 : Names ) -> None :
320- lc , rc , tool = mk_tool (schema_ext11 , ["--singularity" ], reqs = [mpiReq , containerReq ])
321- clt = CommandLineTool ( tool , lc )
331+ rc , clt = mk_tool (schema_ext11 , ["--singularity" ], reqs = [mpiReq , containerReq ])
332+ clt . _init_job ({}, rc )
322333 jr = clt .make_job_runner (rc )
323334 assert jr is cwltool .singularity .SingularityCommandLineJob
324335
325336
326337def test_udocker (schema_ext11 : Names ) -> None :
327- lc , rc , tool = mk_tool (schema_ext11 , ["--udocker" ], reqs = [mpiReq , containerReq ])
328- clt = CommandLineTool ( tool , lc )
338+ rc , clt = mk_tool (schema_ext11 , ["--udocker" ], reqs = [mpiReq , containerReq ])
339+ clt . _init_job ({}, rc )
329340 jr = clt .make_job_runner (rc )
330341 assert jr is cwltool .udocker .UDockerCommandLineJob
331342
332343
333344def test_docker_hint (schema_ext11 : Names ) -> None :
334345 # Docker hint, MPI required
335- lc , rc , tool = mk_tool (schema_ext11 , [], hints = [containerReq ], reqs = [mpiReq ])
336- clt = CommandLineTool ( tool , lc )
346+ rc , clt = mk_tool (schema_ext11 , [], hints = [containerReq ], reqs = [mpiReq ])
347+ clt . _init_job ({}, rc )
337348 jr = clt .make_job_runner (rc )
338349 assert jr is cwltool .job .CommandLineJob
339350
340351
341352def test_docker_required (schema_ext11 : Names ) -> None :
342353 # Docker required, MPI hinted
343- lc , rc , tool = mk_tool (schema_ext11 , [], reqs = [containerReq ], hints = [mpiReq ])
344- clt = CommandLineTool ( tool , lc )
354+ rc , clt = mk_tool (schema_ext11 , [], reqs = [containerReq ], hints = [mpiReq ])
355+ clt . _init_job ({}, rc )
345356 jr = clt .make_job_runner (rc )
346357 assert jr is cwltool .docker .DockerCommandLineJob
347358
348359
349360def test_docker_mpi_both_required (schema_ext11 : Names ) -> None :
350361 # Both required - error
351- lc , rc , tool = mk_tool (schema_ext11 , [], reqs = [mpiReq , containerReq ])
352- clt = CommandLineTool (tool , lc )
362+ rc , clt = mk_tool (schema_ext11 , [], reqs = [mpiReq , containerReq ])
353363 with pytest .raises (cwltool .errors .UnsupportedRequirement ):
354- clt .make_job_runner (rc )
364+ clt ._init_job ({}, rc )
365+ clt .make_job_runner (rc )
355366
356367
357368def test_docker_mpi_both_hinted (schema_ext11 : Names ) -> None :
358369 # Both hinted - error
359- lc , rc , tool = mk_tool (schema_ext11 , [], hints = [mpiReq , containerReq ])
360- clt = CommandLineTool (tool , lc )
370+ rc , clt = mk_tool (schema_ext11 , [], hints = [mpiReq , containerReq ])
361371 with pytest .raises (cwltool .errors .UnsupportedRequirement ):
362- clt .make_job_runner (rc )
372+ clt ._init_job ({}, rc )
373+ clt .make_job_runner (rc )
0 commit comments