66import pytest
77
88from cwltool .main import main
9+ from cwltool .singularity import _IMAGES , _IMAGES_LOCK
910
1011from .util import (
1112 get_data ,
1718)
1819
1920
21+ @pytest .fixture (autouse = True )
22+ def clear_singularity_image_cache () -> None :
23+ with _IMAGES_LOCK :
24+ _IMAGES .clear ()
25+
26+
2027@needs_singularity_2_6
2128def test_singularity_pullfolder (tmp_path : Path , monkeypatch : pytest .MonkeyPatch ) -> None :
2229 """Test singularity respects SINGULARITY_PULLFOLDER."""
@@ -149,7 +156,7 @@ def test_singularity3_docker_image_id_in_tool(tmp_path: Path) -> None:
149156 "hello" ,
150157 ]
151158 )
152- assert result_code == 0
159+ assert result_code == 0 , stderr
153160 result_code1 , stdout , stderr = get_main_output (
154161 [
155162 "--singularity" ,
@@ -159,3 +166,89 @@ def test_singularity3_docker_image_id_in_tool(tmp_path: Path) -> None:
159166 ]
160167 )
161168 assert result_code1 == 0
169+
170+
171+ @needs_singularity_3_or_newer
172+ def test_singularity_dockerfile_no_name_no_cache (tmp_path : Path ) -> None :
173+ workdir = tmp_path / "working_dir"
174+ workdir .mkdir ()
175+ with working_directory (workdir ):
176+ result_code , stdout , stderr = get_main_output (
177+ [
178+ "--singularity" ,
179+ get_data ("tests/sing_dockerfile_test.cwl" ),
180+ "--message" ,
181+ "hello" ,
182+ ]
183+ )
184+ assert result_code == 0 , stderr
185+ assert not (workdir / "bea92b9b6910cbbd2ae602f5bb0f0f27_latest.sif" ).exists ()
186+
187+
188+ @needs_singularity_3_or_newer
189+ def test_singularity_dockerfile_no_name_with_cache (
190+ tmp_path : Path , monkeypatch : pytest .MonkeyPatch
191+ ) -> None :
192+ workdir = tmp_path / "working_dir"
193+ workdir .mkdir ()
194+ cachedir = tmp_path / "cache"
195+ cachedir .mkdir ()
196+ monkeypatch .setenv ("CWL_SINGULARITY_CACHE" , str (cachedir ))
197+ with working_directory (workdir ):
198+ result_code , stdout , stderr = get_main_output (
199+ [
200+ "--singularity" ,
201+ get_data ("tests/sing_dockerfile_test.cwl" ),
202+ "--message" ,
203+ "hello" ,
204+ ]
205+ )
206+ assert result_code == 0 , stderr
207+ assert not (workdir / "bea92b9b6910cbbd2ae602f5bb0f0f27_latest.sif" ).exists ()
208+ assert (cachedir / "bea92b9b6910cbbd2ae602f5bb0f0f27_latest.sif" ).exists ()
209+
210+
211+ @needs_singularity_3_or_newer
212+ def test_singularity_dockerfile_with_name_no_cache (tmp_path : Path ) -> None :
213+ workdir = tmp_path / "working_dir"
214+ workdir .mkdir ()
215+ with working_directory (workdir ):
216+ result_code , stdout , stderr = get_main_output (
217+ [
218+ "--singularity" ,
219+ get_data ("tests/sing_dockerfile_named_test.cwl" ),
220+ "--message" ,
221+ "hello" ,
222+ ]
223+ )
224+ assert result_code == 0 , stderr
225+ print (list (workdir .iterdir ()))
226+ assert not (workdir / "bea92b9b6910cbbd2ae602f5bb0f0f27_latest.sif" ).exists ()
227+ assert not (workdir / "customDebian_latest.sif" ).exists ()
228+
229+
230+ @needs_singularity_3_or_newer
231+ def test_singularity_dockerfile_with_name_with_cache (
232+ tmp_path : Path , monkeypatch : pytest .MonkeyPatch
233+ ) -> None :
234+ workdir = tmp_path / "working_dir"
235+ workdir .mkdir ()
236+ cachedir = tmp_path / "cache"
237+ cachedir .mkdir ()
238+ monkeypatch .setenv ("CWL_SINGULARITY_CACHE" , str (cachedir ))
239+ with working_directory (workdir ):
240+ result_code , stdout , stderr = get_main_output (
241+ [
242+ "--singularity" ,
243+ get_data ("tests/sing_dockerfile_named_test.cwl" ),
244+ "--message" ,
245+ "hello" ,
246+ ]
247+ )
248+ print (list (workdir .iterdir ()))
249+ print (list (cachedir .iterdir ()))
250+ assert result_code == 0 , stderr
251+ assert not (workdir / "bea92b9b6910cbbd2ae602f5bb0f0f27_latest.sif" ).exists ()
252+ assert not (cachedir / "bea92b9b6910cbbd2ae602f5bb0f0f27_latest.sif" ).exists ()
253+ assert not (workdir / "customDebian_latest.sif" ).exists ()
254+ assert (cachedir / "customDebian_latest.sif" ).exists ()
0 commit comments