Skip to content

Commit 05067bb

Browse files
committed
Fix mypy and format
1 parent 0a1505c commit 05067bb

File tree

2 files changed

+35
-18
lines changed

2 files changed

+35
-18
lines changed

cwltool/context.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,9 @@ def __init__(self, kwargs: Optional[dict[str, Any]] = None) -> None:
192192
self.default_stderr: Optional[Union[IO[bytes], TextIO]] = None
193193
self.validate_only: bool = False
194194
self.validate_stdout: Optional["SupportsWrite[str]"] = None
195-
self.workflow_job_step_name_callback: Optional[Callable[[WorkflowJobStep, CWLObjectType], str]] = None
195+
self.workflow_job_step_name_callback: Optional[
196+
Callable[[WorkflowJobStep, CWLObjectType], str]
197+
] = None
196198

197199
super().__init__(kwargs)
198200
if self.tmp_outdir_prefix == "":

tests/test_context.py

+32-17
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
import sys
33
import logging
44
from io import StringIO
5+
from typing import MutableMapping, cast
56

67
from cwltool.context import RuntimeContext
78
from cwltool.factory import Factory
9+
from cwltool.utils import CWLObjectType, CWLOutputType
10+
from cwltool.workflow_job import WorkflowJobStep
811

912
from .util import get_data
1013

@@ -29,6 +32,7 @@ def test_replace_default_stdout_stderr() -> None:
2932
sys.stdout = original_stdout
3033
sys.stderr = original_stderr
3134

35+
3236
def test_workflow_job_step_name_callback() -> None:
3337
"""Test ability to hook custom workflow step naming"""
3438

@@ -40,36 +44,47 @@ def test_workflow_job_step_name_callback() -> None:
4044
try:
4145
runtime_context = RuntimeContext()
4246

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+
)
4654

4755
runtime_context.workflow_job_step_name_callback = step_name_hook
4856

4957
factory = Factory(None, None, runtime_context)
5058
revsort = factory.make(get_data("tests/wf/revsort.cwl"))
5159

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)
5369

54-
del result["sorted_output"]["location"]
70+
sorted_out = cast(MutableMapping[str, str], result["sorted_output"])
71+
loc = sorted_out["location"]
5572

5673
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,
6583
},
6684
}
6785

6886
print(stream.getvalue())
6987

70-
assert (
71-
"foostep"
72-
in stream.getvalue()
73-
)
88+
assert "foostep" in stream.getvalue()
7489
finally:
7590
_logger.removeHandler(streamhandler)

0 commit comments

Comments
 (0)