@@ -285,6 +285,80 @@ def test_dockerfile_singularity_build(monkeypatch: pytest.MonkeyPatch, tmp_path:
285285 shutil .rmtree (subdir )
286286
287287
288+ @needs_singularity
289+ def test_singularity_get_image_from_sandbox (monkeypatch : pytest .MonkeyPatch , tmp_path : Path ):
290+ """Test that SingularityCommandLineJob.get_image correctly handle sandbox image."""
291+
292+ (tmp_path / "out" ).mkdir (exist_ok = True )
293+ tmp_outdir_prefix = tmp_path / "out"
294+ (tmp_path / "3" ).mkdir (exist_ok = True )
295+ tmpdir_prefix = str (tmp_path / "tmp" )
296+ runtime_context = RuntimeContext (
297+ {"tmpdir_prefix" : tmpdir_prefix , "user_space_docker_cmd" : None }
298+ )
299+ builder = Builder (
300+ {},
301+ [],
302+ [],
303+ {},
304+ schema .Names (),
305+ [],
306+ [],
307+ {},
308+ None ,
309+ None ,
310+ StdFsAccess ,
311+ StdFsAccess ("" ),
312+ None ,
313+ 0.1 ,
314+ True ,
315+ False ,
316+ False ,
317+ "no_listing" ,
318+ runtime_context .get_outdir (),
319+ runtime_context .get_tmpdir (),
320+ runtime_context .get_stagedir (),
321+ INTERNAL_VERSION ,
322+ "singularity" ,
323+ )
324+
325+ workdir = tmp_path / "working_dir"
326+ workdir .mkdir ()
327+ # build a sandbox image
328+ repo_path = workdir / "container_repo"
329+ repo_path .mkdir ()
330+ image_path = repo_path / "alpine"
331+ image_path .mkdir ()
332+
333+ # directory exists but is not an image
334+ monkeypatch .setattr ("cwltool.singularity._inspect_singularity_image" , lambda * args , ** kwargs : False )
335+ assert not SingularityCommandLineJob (
336+ builder , {}, CommandLineTool .make_path_mapper , [], [], ""
337+ ).get_image (
338+ {
339+ "class" : "DockerRequirement" ,
340+ "dockerPull" : f"{ image_path } " ,
341+ },
342+ pull_image = False ,
343+ tmp_outdir_prefix = str (tmp_outdir_prefix ),
344+ force_pull = False ,
345+ )
346+
347+ # directory exists and is an image:
348+ monkeypatch .setattr ("cwltool.singularity._inspect_singularity_image" , lambda * args , ** kwargs : True )
349+ assert SingularityCommandLineJob (
350+ builder , {}, CommandLineTool .make_path_mapper , [], [], ""
351+ ).get_image (
352+ {
353+ "class" : "DockerRequirement" ,
354+ "dockerPull" : f"{ image_path } " ,
355+ },
356+ pull_image = False ,
357+ tmp_outdir_prefix = str (tmp_outdir_prefix ),
358+ force_pull = False ,
359+ )
360+
361+
288362def test_docker_tmpdir_prefix (tmp_path : Path ) -> None :
289363 """Test that DockerCommandLineJob respects temp directory directives."""
290364 (tmp_path / "3" ).mkdir ()
0 commit comments