44import shutil
55import subprocess
66from pathlib import Path
7+ from typing import Any
8+ from collections .abc import Callable
79
810import pytest
11+ from mypy_extensions import KwArg , VarArg
912
1013from cwltool .main import main
1114from 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 )
0 commit comments