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
- from cwltool .command_line_tool import CommandLineTool
21
- from cwltool .context import LoadingContext , RuntimeContext
21
+ from cwltool .context import RuntimeContext
22
22
from cwltool .main import main
23
23
from cwltool .mpi import MpiConfig , MPIRequirementName
24
+ from cwltool .command_line_tool import CommandLineTool
24
25
25
26
from .util import get_data , working_directory
26
27
@@ -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 :
@@ -313,50 +321,53 @@ def mk_tool(
313
321
rc = RuntimeContext (vars (args ))
314
322
lc = cwltool .main .setup_loadingContext (None , rc , args )
315
323
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 ))
317
328
318
329
319
330
def 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 )
322
333
jr = clt .make_job_runner (rc )
323
334
assert jr is cwltool .singularity .SingularityCommandLineJob
324
335
325
336
326
337
def 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 )
329
340
jr = clt .make_job_runner (rc )
330
341
assert jr is cwltool .udocker .UDockerCommandLineJob
331
342
332
343
333
344
def test_docker_hint (schema_ext11 : Names ) -> None :
334
345
# 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 )
337
348
jr = clt .make_job_runner (rc )
338
349
assert jr is cwltool .job .CommandLineJob
339
350
340
351
341
352
def test_docker_required (schema_ext11 : Names ) -> None :
342
353
# 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 )
345
356
jr = clt .make_job_runner (rc )
346
357
assert jr is cwltool .docker .DockerCommandLineJob
347
358
348
359
349
360
def test_docker_mpi_both_required (schema_ext11 : Names ) -> None :
350
361
# 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 ])
353
363
with pytest .raises (cwltool .errors .UnsupportedRequirement ):
354
- clt .make_job_runner (rc )
364
+ clt ._init_job ({}, rc )
365
+ clt .make_job_runner (rc )
355
366
356
367
357
368
def test_docker_mpi_both_hinted (schema_ext11 : Names ) -> None :
358
369
# 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 ])
361
371
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