1+ import os
12import shutil
23import sys
34from pathlib import Path
2122from tests .dsl import utils
2223
2324
24- @pytest .fixture
25- def tmp_cache_root (tmpdir ):
26- original_root = gt_config .cache_settings ["root_path" ]
27- gt_config .cache_settings ["root_path" ] = tmpdir
28-
29- yield tmpdir
30-
31- # restore original cache settings
32- gt_config .cache_settings ["root_path" ] = original_root
33-
34-
35- @pytest .fixture
36- def restore_cache_dir ():
37- cache_dir = gt_config .cache_settings ["dir_name" ]
38-
39- yield
40-
41- gt_config .cache_settings ["dir_name" ] = cache_dir
42-
43-
4425def _stencil (inp : Field [float ], out : Field [float ]):
4526 with computation (PARALLEL ), interval (...):
4627 out = inp
@@ -87,9 +68,9 @@ def __call__(self):
8768
8869
8970@pytest .mark .skipif (
90- MPI .COMM_WORLD .Get_size () > 1 , reason = "relocatibility checked with a one-rank setup"
71+ MPI .COMM_WORLD .Get_size () > 1 , reason = "Relocatability checked with a one-rank setup"
9172)
92- def test_relocatability_orchestration (restore_cache_dir ) -> None :
73+ def test_relocatability_orchestration () -> None :
9374 # Compile on default
9475 p0 = OrchestratedProgram ("dace:cpu" , DaCeOrchestration .BuildAndRun )
9576 p0 ()
@@ -98,32 +79,34 @@ def test_relocatability_orchestration(restore_cache_dir) -> None:
9879 Path .cwd ()
9980 / ".gt_cache_FV3_A"
10081 / "dacecache"
101- / "test_caches_OrchestratedProgram___call__ "
82+ / "tests_dsl_test_caches_OrchestratedProgram___call__ "
10283 )
10384 assert expected_cache_dir .exists ()
10485
10586
10687@pytest .mark .skipif (
107- MPI .COMM_WORLD .Get_size () > 1 , reason = "relocatibility checked with a one-rank setup"
88+ MPI .COMM_WORLD .Get_size () > 1 , reason = "Relocatability checked with a one-rank setup"
10889)
109- def test_relocatability_orchestration_tmpdir (restore_cache_dir , tmp_cache_root ) -> None :
90+ def test_relocatability_orchestration_tmpdir (tmpdir ) -> None :
91+ gt_config .cache_settings ["root_path" ] = tmpdir
92+
11093 # Compile in temporary directory that is only available in this test session.
11194 backend = "dace:cpu"
11295 p1 = OrchestratedProgram (backend , DaCeOrchestration .BuildAndRun )
11396 p1 ()
11497
11598 expected_cache_dir = (
116- tmp_cache_root
99+ tmpdir
117100 / ".gt_cache_FV3_A"
118101 / "dacecache"
119- / "test_caches_OrchestratedProgram___call__ "
102+ / "tests_dsl_test_caches_OrchestratedProgram___call__ "
120103 )
121104 assert expected_cache_dir .exists ()
122105
123- # Check relocability by copying the second cache directory,
106+ # Check relocatability by copying the second cache directory,
124107 # changing the path of gt_config.cache_settings and trying to Run on it
125- relocated_path = tmp_cache_root / ".my_relocated_cache_path"
126- shutil .copytree (tmp_cache_root , relocated_path , dirs_exist_ok = False )
108+ relocated_path = tmpdir / ".my_relocated_cache_path"
109+ shutil .copytree (tmpdir , relocated_path , dirs_exist_ok = False )
127110 gt_config .cache_settings ["root_path" ] = relocated_path
128111 p2 = OrchestratedProgram (backend , DaCeOrchestration .Run )
129112 p2 ()
@@ -136,9 +119,14 @@ def test_relocatability_orchestration_tmpdir(restore_cache_dir, tmp_cache_root)
136119
137120
138121@pytest .mark .skipif (
139- MPI .COMM_WORLD .Get_size () > 1 , reason = "relocatibility checked with a one-rank setup"
122+ MPI .COMM_WORLD .Get_size () > 1 , reason = "Relocatability checked with a one-rank setup"
140123)
141- def test_relocatability (restore_cache_dir ) -> None :
124+ def test_relocatability () -> None :
125+ gt_config .cache_settings ["dir_name" ] = os .environ .get (
126+ "GT_CACHE_DIR_NAME" , f".gt_cache_{ MPI .COMM_WORLD .Get_rank ():06} "
127+ )
128+ gt_config .cache_settings ["root_path" ] = Path .cwd ()
129+
142130 # Compile on default
143131 backend = "dace:cpu"
144132 p0 = OrchestratedProgram (backend , DaCeOrchestration .Python )
@@ -151,16 +139,23 @@ def test_relocatability(restore_cache_dir) -> None:
151139 / ".gt_cache_000000"
152140 / f"{ python_version } _1013"
153141 / f"{ backend_sanitized } "
142+ / "tests"
143+ / "dsl"
154144 / "test_caches"
155145 / "_stencil"
156146 )
157147 assert expected_cache_path .exists ()
158148
159149
160150@pytest .mark .skipif (
161- MPI .COMM_WORLD .Get_size () > 1 , reason = "relocatibility checked with a one-rank setup"
151+ MPI .COMM_WORLD .Get_size () > 1 , reason = "Relocatability checked with a one-rank setup"
162152)
163- def test_relocatability_tmpdir (restore_cache_dir , tmp_cache_root ) -> None :
153+ def test_relocatability_tmpdir (tmpdir ) -> None :
154+ gt_config .cache_settings ["dir_name" ] = os .environ .get (
155+ "GT_CACHE_DIR_NAME" , f".gt_cache_{ MPI .COMM_WORLD .Get_rank ():06} "
156+ )
157+ gt_config .cache_settings ["root_path" ] = tmpdir
158+
164159 # Compile in another directory
165160 backend = "dace:cpu"
166161 p1 = OrchestratedProgram (backend , DaCeOrchestration .Python )
@@ -169,21 +164,21 @@ def test_relocatability_tmpdir(restore_cache_dir, tmp_cache_root) -> None:
169164 backend_sanitized = backend .replace (":" , "" )
170165 python_version = f"py{ sys .version_info [0 ]} { sys .version_info [1 ]} "
171166 expected_cache_path = (
172- tmp_cache_root
167+ tmpdir
173168 / ".gt_cache_000000"
174169 / f"{ python_version } _1013"
175170 / f"{ backend_sanitized } "
171+ / "tests"
172+ / "dsl"
176173 / "test_caches"
177174 / "_stencil"
178175 )
179176 assert expected_cache_path .exists ()
180177
181- # Check relocability by copying the first cache directory,
178+ # Check relocatability by copying the first cache directory,
182179 # changing the path of gt_config.cache_settings and trying to Run on it
183- relocated_path = tmp_cache_root / ".my_relocated_cache_path"
184- shutil .copytree (
185- tmp_cache_root / ".gt_cache_000000" , relocated_path , dirs_exist_ok = False
186- )
180+ relocated_path = tmpdir / ".my_relocated_cache_path"
181+ shutil .copytree (tmpdir / ".gt_cache_000000" , relocated_path , dirs_exist_ok = False )
187182 gt_config .cache_settings ["root_path" ] = relocated_path
188183
189184 p2 = OrchestratedProgram (backend , DaCeOrchestration .Python )
@@ -194,6 +189,8 @@ def test_relocatability_tmpdir(restore_cache_dir, tmp_cache_root) -> None:
194189 / ".gt_cache_000000"
195190 / f"{ python_version } _1013"
196191 / f"{ backend_sanitized } "
192+ / "tests"
193+ / "dsl"
197194 / "test_caches"
198195 / "_stencil"
199196 )
0 commit comments