1515 _IMAGES ,
1616 _IMAGES_LOCK ,
1717 _inspect_singularity_sandbox_image ,
18+ _normalize_sif_id ,
1819)
1920
2021from .util import (
@@ -33,6 +34,39 @@ def clear_singularity_image_cache() -> None:
3334 _IMAGES .clear ()
3435
3536
37+ def test_normalize_sif_id_resists_collision () -> None :
38+ """Test that tricky image names can't collide."""
39+ assert _normalize_sif_id ("ubuntu:latest" ) != _normalize_sif_id ("ubuntu_latest" )
40+ assert _normalize_sif_id ("docker://user_name/repo" ) != _normalize_sif_id ("docker://user/name_repo" )
41+ assert _normalize_sif_id ("http://something.com/something.sif" ) != _normalize_sif_id ("http:_something.com/something.sif" )
42+
43+
44+ def test_normalize_sif_id_implies_latest () -> None :
45+ """
46+ Test that image names that imply latest are equivalent to those that
47+ specify it.
48+ """
49+ assert _normalize_sif_id ("ubuntu" ) == _normalize_sif_id ("ubuntu:latest" )
50+ assert _normalize_sif_id ("quay.io/adamnovak/hap.py" ) == _normalize_sif_id ("quay.io/adamnovak/hap.py:latest" )
51+
52+
53+ def test_normalize_sif_id_does_not_tag_protocols () -> None :
54+ """
55+ Test that if an image comes from a string with a protocol, no tag is added.
56+ """
57+ assert _normalize_sif_id ("docker://library/ubuntu" ) != _normalize_sif_id ("docker://library/ubuntu:latest" )
58+
59+
60+ def test_normalize_sif_id_matches_cwl_utils_tests () -> None :
61+ """
62+ Make sure that the particular values tested in cwl-utils get the same
63+ answers here as there.
64+ """
65+
66+ assert _normalize_sif_id ("some_name/repo:123" ) == f"some___name_s_repo:123.sif"
67+ assert _normalize_sif_id ("some/name_repo:123" ) == f"some_s_name___repo:123.sif"
68+
69+
3670@needs_singularity_2_6
3771def test_singularity_pullfolder (tmp_path : Path , monkeypatch : pytest .MonkeyPatch ) -> None :
3872 """Test singularity respects SINGULARITY_PULLFOLDER."""
@@ -194,7 +228,7 @@ def test_singularity_dockerfile_no_name_no_cache(tmp_path: Path) -> None:
194228 ]
195229 )
196230 assert result_code == 0 , stderr
197- assert not (workdir / "bea92b9b6910cbbd2ae602f5bb0f0f27_latest.sif" ).exists ()
231+ assert not (workdir / _normalize_sif_id ( "bea92b9b6910cbbd2ae602f5bb0f0f27" ) ).exists ()
198232
199233
200234@needs_singularity_3_or_newer
@@ -217,8 +251,8 @@ def test_singularity_dockerfile_no_name_with_cache(
217251 ]
218252 )
219253 assert result_code == 0 , stderr
220- assert not (workdir / "bea92b9b6910cbbd2ae602f5bb0f0f27_latest.sif" ).exists ()
221- assert (cachedir / "bea92b9b6910cbbd2ae602f5bb0f0f27_latest.sif" ).exists ()
254+ assert not (workdir / _normalize_sif_id ( "bea92b9b6910cbbd2ae602f5bb0f0f27" ) ).exists ()
255+ assert (cachedir / _normalize_sif_id ( "bea92b9b6910cbbd2ae602f5bb0f0f27" ) ).exists ()
222256
223257
224258@needs_singularity_3_or_newer
@@ -236,8 +270,8 @@ def test_singularity_dockerfile_with_name_no_cache(tmp_path: Path) -> None:
236270 )
237271 assert result_code == 0 , stderr
238272 print (list (workdir .iterdir ()))
239- assert not (workdir / "bea92b9b6910cbbd2ae602f5bb0f0f27_latest.sif" ).exists ()
240- assert not (workdir / "customDebian_latest.sif" ).exists ()
273+ assert not (workdir / _normalize_sif_id ( "bea92b9b6910cbbd2ae602f5bb0f0f27" ) ).exists ()
274+ assert not (workdir / _normalize_sif_id ( "customDebian" ) ).exists ()
241275
242276
243277@needs_singularity_3_or_newer
@@ -262,10 +296,10 @@ def test_singularity_dockerfile_with_name_with_cache(
262296 print (list (workdir .iterdir ()))
263297 print (list (cachedir .iterdir ()))
264298 assert result_code == 0 , stderr
265- assert not (workdir / "bea92b9b6910cbbd2ae602f5bb0f0f27_latest.sif" ).exists ()
266- assert not (cachedir / "bea92b9b6910cbbd2ae602f5bb0f0f27_latest.sif" ).exists ()
267- assert not (workdir / "customDebian_latest.sif" ).exists ()
268- assert (cachedir / "customDebian_latest.sif" ).exists ()
299+ assert not (workdir / _normalize_sif_id ( "bea92b9b6910cbbd2ae602f5bb0f0f27" ) ).exists ()
300+ assert not (cachedir / _normalize_sif_id ( "bea92b9b6910cbbd2ae602f5bb0f0f27" ) ).exists ()
301+ assert not (workdir / _normalize_sif_id ( "customDebian" ) ).exists ()
302+ assert (cachedir / _normalize_sif_id ( "customDebian" ) ).exists ()
269303
270304
271305@needs_singularity
0 commit comments