Skip to content

Commit 2b18684

Browse files
Added seperate unit test for ugrid and cfgrid conventions for testing cache key generation on mfdatasets.
1 parent 04b0cab commit 2b18684

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

tests/operations/test_cache.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
attr_hash_lat = "2cb433979fc2d9c3884eea8569dd6a44406950f3"
1515
cache_key_hash_cf1d_sha1 = "2b006999273225ed70d4810357b6a06e6bebe9a6"
1616
cache_key_hash_multifile_cf2d_sha1 = "ea2d2e6131f1e499f622e83ed4fc2415649def06"
17+
cache_key_hash_multifile_ugrid_mesh2d_sha1 = "1d72e01b159135208324ae9a643166f85aecba27"
1718

1819
# Blake2b
1920
cache_key_hash_cf1d = "1a3226072f08441ee79f727b0775709209ff2965299539c898ecc401cf17e23f"
@@ -204,14 +205,12 @@ def test_cache_key_cfgrid1d_sha1(datasets: pathlib.Path):
204205
assert result_cache_key_cf == cache_key_hash_cf1d_sha1
205206

206207

207-
def test_cache_key_with_multifile_dataset(datasets: pathlib.Path):
208+
def test_cache_key_with_multifile_dataset_ugrid_mesh2d(datasets: pathlib.Path):
208209

209-
ugrid_path1 = datasets / 'multiple_dataset/modified_cf1.nc'
210-
ugrid_path2 = datasets / 'multiple_dataset/modified_cf2.nc'
211-
dataset_paths = [ugrid_path1, ugrid_path2]
210+
ugrid_path1 = datasets / 'multiple_dataset/ugrid_mesh2d/ugrid_mesh2d_2024-01-01.nc'
211+
ugrid_path2 = datasets / 'multiple_dataset/ugrid_mesh2d/ugrid_mesh2d_2024-01-02.nc'
212212

213-
ugrid_file1 = emsarray.open_dataset(ugrid_path1)
214-
ugrid_file2 = emsarray.open_dataset(ugrid_path2)
213+
dataset_paths = [ugrid_path1, ugrid_path2]
215214

216215
multifile_dataset = xarray.open_mfdataset(dataset_paths, data_vars=['values'])
217216

@@ -221,16 +220,22 @@ def test_cache_key_with_multifile_dataset(datasets: pathlib.Path):
221220

222221
multifile_ds_digest = multifile_ds_hash.hexdigest()
223222

224-
ugrid_file1_dtype = ugrid_file1.ems.topology.latitude.encoding.get('dtype', None).name
223+
assert multifile_ds_digest == cache_key_hash_multifile_ugrid_mesh2d_sha1
225224

226-
ugrid_file2_dtype = ugrid_file2.ems.topology.latitude.encoding.get('dtype', None).name
227225

228-
multifile_encoding = multifile_dataset.ems.topology.latitude.encoding.get('dtype', None)
226+
def test_cache_key_with_multifile_dataset_cfgrid2d(datasets: pathlib.Path):
229227

230-
assert multifile_encoding is None
228+
cfgrid_path1 = datasets / 'multiple_dataset/cfgrid2d/cfgrid2d_2024-01-01.nc'
229+
cfgrid_path2 = datasets / 'multiple_dataset/cfgrid2d/cfgrid2d_2024-01-02.nc'
231230

232-
assert ugrid_file1_dtype is not None
231+
dataset_paths = [cfgrid_path1, cfgrid_path2]
233232

234-
assert ugrid_file2_dtype is not None
233+
multifile_dataset = xarray.open_mfdataset(dataset_paths, data_vars=['values'])
234+
235+
multifile_ds_hash = hashlib.sha1()
236+
237+
multifile_dataset.ems.hash_geometry(multifile_ds_hash)
238+
239+
multifile_ds_digest = multifile_ds_hash.hexdigest()
235240

236241
assert multifile_ds_digest == cache_key_hash_multifile_cf2d_sha1

0 commit comments

Comments
 (0)