11"""Tests to find local Singularity image."""
22
3+ import json
34import shutil
45import subprocess
56from pathlib import Path
@@ -202,10 +203,6 @@ def test_singularity_inspect_image(tmp_path: Path, monkeypatch: pytest.MonkeyPat
202203 repo_path = workdir / "container_repo"
203204 image_path = repo_path / "alpine"
204205
205- # test path does not exists
206- res_inspect = _inspect_singularity_image (str (image_path ))
207- assert res_inspect is False
208-
209206 # test image exists
210207 repo_path .mkdir ()
211208 cmd = [
@@ -217,14 +214,36 @@ def test_singularity_inspect_image(tmp_path: Path, monkeypatch: pytest.MonkeyPat
217214 ]
218215 build = subprocess .run (cmd , capture_output = True , text = True )
219216 if build .returncode == 0 :
220- # Verify the path is a container image
217+ # Verify the path is a correct container image
221218 res_inspect = _inspect_singularity_image (image_path )
222219 assert res_inspect is True
223220
224- # test wrong subprocess call
221+ # test wrong json output
222+ def mock_subprocess_run (* args , ** kwargs ):
223+ class Result :
224+ returncode = 0
225+ stdout = "not-json"
226+
227+ return Result ()
228+
229+ monkeypatch .setattr ("cwltool.singularity.run" , mock_subprocess_run )
230+ res_inspect = _inspect_singularity_image (image_path )
231+ assert res_inspect is False
232+ else :
233+ pytest .skip (f"singularity sandbox image build didn't worked: { build .stderr } " )
234+
235+
236+ def test_singularity_sandbox_image_not_exists ():
237+ image_path = "/tmp/not_existing/image"
238+ res_inspect = _inspect_singularity_image (image_path )
239+ assert res_inspect is False
240+
241+
242+ def test_inspect_image_wrong_sb_call (monkeypatch : pytest .MonkeyPatch ):
243+
225244 def mock_failed_subprocess (* args , ** kwargs ):
226245 raise subprocess .CalledProcessError (returncode = 1 , cmd = args [0 ])
227-
246+
228247 monkeypatch .setattr ("cwltool.singularity.run" , mock_failed_subprocess )
229- res_inspect = _inspect_singularity_image (str ( image_path ) )
230- assert res_inspect is False
248+ res_inspect = _inspect_singularity_image ("/tmp/container_repo/alpine" )
249+ assert res_inspect is False
0 commit comments