2
2
import sys
3
3
import logging
4
4
from io import StringIO
5
+ from typing import MutableMapping , cast
5
6
6
7
from cwltool .context import RuntimeContext
7
8
from cwltool .factory import Factory
9
+ from cwltool .utils import CWLObjectType , CWLOutputType
10
+ from cwltool .workflow_job import WorkflowJobStep
8
11
9
12
from .util import get_data
10
13
@@ -29,6 +32,7 @@ def test_replace_default_stdout_stderr() -> None:
29
32
sys .stdout = original_stdout
30
33
sys .stderr = original_stderr
31
34
35
+
32
36
def test_workflow_job_step_name_callback () -> None :
33
37
"""Test ability to hook custom workflow step naming"""
34
38
@@ -40,36 +44,47 @@ def test_workflow_job_step_name_callback() -> None:
40
44
try :
41
45
runtime_context = RuntimeContext ()
42
46
43
- def step_name_hook (step , job ):
44
- print (step , job )
45
- return "%s on %s" % (step .name , job .get ("revtool_input" , job .get ("sorted_input" )).get ("basename" ))
47
+ def step_name_hook (step : WorkflowJobStep , job : CWLObjectType ) -> str :
48
+ j1 = cast (MutableMapping [str , CWLObjectType ], job )
49
+ inp = cast (MutableMapping [str , str ], j1 .get ("revtool_input" , j1 .get ("sorted_input" )))
50
+ return "%s on %s" % (
51
+ step .name ,
52
+ inp .get ("basename" ),
53
+ )
46
54
47
55
runtime_context .workflow_job_step_name_callback = step_name_hook
48
56
49
57
factory = Factory (None , None , runtime_context )
50
58
revsort = factory .make (get_data ("tests/wf/revsort.cwl" ))
51
59
52
- result = revsort (workflow_input = {"class" : "File" , "location" : "whale.txt" , "format" : "https://www.iana.org/assignments/media-types/text/plain" })
60
+ result = revsort (
61
+ workflow_input = {
62
+ "class" : "File" ,
63
+ "location" : "whale.txt" ,
64
+ "format" : "https://www.iana.org/assignments/media-types/text/plain" ,
65
+ }
66
+ )
67
+
68
+ result = cast (CWLObjectType , result )
53
69
54
- del result ["sorted_output" ]["location" ]
70
+ sorted_out = cast (MutableMapping [str , str ], result ["sorted_output" ])
71
+ loc = sorted_out ["location" ]
55
72
56
73
assert result == {
57
- 'sorted_output' : {
58
- 'basename' : 'output.txt ' ,
59
- 'checksum' : 'sha1$b9214658cc453331b62c2282b772a5c063dbd284' ,
60
- 'class' : 'File' ,
61
- 'http://commonwl.org/cwltool#generation' : 0 ,
62
- 'nameext' : '.txt' ,
63
- 'nameroot' : 'output' ,
64
- 'size' : 1111 ,
74
+ "sorted_output" : {
75
+ "basename" : "output.txt " ,
76
+ "checksum" : "sha1$b9214658cc453331b62c2282b772a5c063dbd284" ,
77
+ "class" : "File" ,
78
+ "http://commonwl.org/cwltool#generation" : 0 ,
79
+ "nameext" : ".txt" ,
80
+ "nameroot" : "output" ,
81
+ "size" : 1111 ,
82
+ "location" : loc ,
65
83
},
66
84
}
67
85
68
86
print (stream .getvalue ())
69
87
70
- assert (
71
- "foostep"
72
- in stream .getvalue ()
73
- )
88
+ assert "foostep" in stream .getvalue ()
74
89
finally :
75
90
_logger .removeHandler (streamhandler )
0 commit comments