11"""Tests to find local Singularity image."""
22
33import shutil
4+ import subprocess
45from pathlib import Path
56
67import pytest
@@ -164,8 +165,6 @@ def test_singularity3_docker_image_id_in_tool(tmp_path: Path) -> None:
164165
165166@needs_singularity
166167def test_singularity_local_sandbox_image (tmp_path : Path ):
167- import subprocess
168-
169168 workdir = tmp_path / "working_dir"
170169 workdir .mkdir ()
171170 with working_directory (workdir ):
@@ -182,10 +181,6 @@ def test_singularity_local_sandbox_image(tmp_path: Path):
182181
183182 build = subprocess .run (cmd , capture_output = True , text = True )
184183 if build .returncode == 0 :
185- # Verify the path is a container image
186- res_inspect = _inspect_singularity_image (container_path / "alpine" )
187- assert res_inspect is True
188-
189184 result_code , stdout , stderr = get_main_output (
190185 [
191186 "--singularity" ,
@@ -198,3 +193,28 @@ def test_singularity_local_sandbox_image(tmp_path: Path):
198193 assert result_code == 0
199194 else :
200195 pytest .skip (f"Failed to build the singularity image: { build .stderr } " )
196+
197+
198+ @needs_singularity
199+ def test_singularity_inspect_image (tmp_path : Path ):
200+ workdir = tmp_path / "working_dir"
201+ workdir .mkdir ()
202+ with working_directory (workdir ):
203+ # build a sandbox image
204+ repo_path = Path (f"{ workdir } /container_repo/" )
205+ image_path = repo_path / "alpine"
206+ res_inspect = _inspect_singularity_image (image_path )
207+ assert res_inspect is False
208+ repo_path .mkdir ()
209+ cmd = [
210+ "singularity" ,
211+ "build" ,
212+ "--sandbox" ,
213+ image_path ,
214+ "docker://alpine:latest" ,
215+ ]
216+ build = subprocess .run (cmd , capture_output = True , text = True )
217+ if build .returncode == 0 :
218+ # Verify the path is a container image
219+ res_inspect = _inspect_singularity_image (image_path )
220+ assert res_inspect is True
0 commit comments