Skip to content

Commit fc682c1

Browse files
committed
fix types
1 parent e56479b commit fc682c1

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

tests/test_singularity.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
import shutil
55
import subprocess
66
from pathlib import Path
7+
from typing import Any
8+
from collections.abc import Callable
79

810
import pytest
11+
from mypy_extensions import KwArg, VarArg
912

1013
from cwltool.main import main
1114
from cwltool.singularity import _inspect_singularity_image
@@ -165,7 +168,7 @@ def test_singularity3_docker_image_id_in_tool(tmp_path: Path) -> None:
165168

166169

167170
@needs_singularity
168-
def test_singularity_local_sandbox_image(tmp_path: Path):
171+
def test_singularity_local_sandbox_image(tmp_path: Path) -> None:
169172
workdir = tmp_path / "working_dir"
170173
workdir.mkdir()
171174
with working_directory(workdir):
@@ -207,7 +210,7 @@ def test_singularity_local_sandbox_image(tmp_path: Path):
207210

208211

209212
@needs_singularity
210-
def test_singularity_inspect_image(tmp_path: Path, monkeypatch: pytest.MonkeyPatch):
213+
def test_singularity_inspect_image(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
211214
"""Test inspect a real image works."""
212215
workdir = tmp_path / "working_dir"
213216
workdir.mkdir()
@@ -232,25 +235,28 @@ def test_singularity_inspect_image(tmp_path: Path, monkeypatch: pytest.MonkeyPat
232235
pytest.skip(f"singularity sandbox image build didn't worked: {build.stderr}")
233236

234237

235-
def _make_run_result(returncode: int, stdout: str):
236-
"""Mock subprocess.run returning returncode and stdout."""
238+
class _DummyResult: # noqa: B903
239+
def __init__(self, rc: int, out: str) -> None:
240+
self.returncode = rc
241+
self.stdout = out
242+
237243

238-
class DummyResult: # noqa: B903
239-
def __init__(self, rc, out):
240-
self.returncode = rc
241-
self.stdout = out
244+
def _make_run_result(
245+
returncode: int, stdout: str
246+
) -> Callable[[VarArg(Any), KwArg(Any)], _DummyResult]:
247+
"""Mock subprocess.run returning returncode and stdout."""
242248

243-
def _runner(*args, **kwargs):
244-
return DummyResult(returncode, stdout)
249+
def _runner(*args: Any, **kwargs: Any) -> _DummyResult:
250+
return _DummyResult(returncode, stdout)
245251

246252
return _runner
247253

248254

249-
def test_json_decode_error_branch(monkeypatch):
255+
def test_json_decode_error_branch(monkeypatch: pytest.MonkeyPatch) -> None:
250256
"""Test json can't decode inspect result."""
251257
monkeypatch.setattr("cwltool.singularity.run", _make_run_result(0, "not-a-json"))
252258

253-
def _raise_json_error(s):
259+
def _raise_json_error(s: str) -> None:
254260
# construct and raise an actual JSONDecodeError
255261
raise json.JSONDecodeError("Expecting value", s, 0)
256262

@@ -259,22 +265,22 @@ def _raise_json_error(s):
259265
assert _inspect_singularity_image("/tmp/image") is False
260266

261267

262-
def test_singularity_sandbox_image_not_exists():
268+
def test_singularity_sandbox_image_not_exists() -> None:
263269
image_path = "/tmp/not_existing/image"
264270
res_inspect = _inspect_singularity_image(image_path)
265271
assert res_inspect is False
266272

267273

268-
def test_singularity_sandbox_not_an_image(tmp_path: Path):
274+
def test_singularity_sandbox_not_an_image(tmp_path: Path) -> None:
269275
image_path = tmp_path / "image"
270276
image_path.mkdir()
271277
res_inspect = _inspect_singularity_image(str(image_path))
272278
assert res_inspect is False
273279

274280

275-
def test_inspect_image_wrong_sb_call(monkeypatch: pytest.MonkeyPatch):
281+
def test_inspect_image_wrong_sb_call(monkeypatch: pytest.MonkeyPatch) -> None:
276282

277-
def mock_failed_subprocess(*args, **kwargs):
283+
def mock_failed_subprocess(*args: Any, **kwargs: Any) -> None:
278284
raise subprocess.CalledProcessError(returncode=1, cmd=args[0])
279285

280286
monkeypatch.setattr("cwltool.singularity.run", mock_failed_subprocess)

tests/test_tmpdir.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,9 @@ def test_dockerfile_singularity_build(monkeypatch: pytest.MonkeyPatch, tmp_path:
286286

287287

288288
@needs_singularity
289-
def test_singularity_get_image_from_sandbox(monkeypatch: pytest.MonkeyPatch, tmp_path: Path):
289+
def test_singularity_get_image_from_sandbox(
290+
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
291+
) -> None:
290292
"""Test that SingularityCommandLineJob.get_image correctly handle sandbox image."""
291293

292294
(tmp_path / "out").mkdir(exist_ok=True)

0 commit comments

Comments
 (0)