33import hashlib
44import pathlib
55
6+ import pytest
7+
68import emsarray
79import emsarray .operations .cache
810
911# Sha1
1012empty_sha1_hash = "da39a3ee5e6b4b0d3255bfef95601890afd80709"
11- attr_hash_lon = "86508f0e34ae9311b4dd4643e5afbf275eaf0052 "
12- str_hash = 'd79c41b2fb9cbfa7e81c951747609057691cb686 '
13- int_hash = '604b8984b112bf57de911f48a75ec769dd63411f '
14- attr_hash_lat = "08d7bc76818a474e80847c26ed78d588374bfbc4 "
15- cache_key_hash_cf1d_sha1 = "414050a852498ee4b57154ead45b048756004cb5 "
13+ attr_hash_lon = "4151c4ac3e0e913dd2c5520c0b2c33e6f20eb004 "
14+ str_hash = '67a0425c3bcb8a47ccc39615e59ab489d0c4b6a1 '
15+ int_hash = '7b08e025e311c3dfcf5179b67c0fdc08e73de261 '
16+ attr_hash_lat = "2cb433979fc2d9c3884eea8569dd6a44406950f3 "
17+ cache_key_hash_cf1d_sha1 = "2b006999273225ed70d4810357b6a06e6bebe9a6 "
1618
1719# Blake2b
18- cache_key_hash_cf1d = "bf5d43b5a378ebfbd4c1204d6e088d8445b9d2fea75a8d8cf2d610f05a72f282"
19- cache_key_hash_cf2d = "93b2546b28b544792db65b4709a760ca3145a22329072a24d59f714ff5694c30"
20- cache_key_hash_shoc_standard = "d88fe0470c7e38c38b04e9e5028f3d671e855cf31ec242af8bd656cccbe373bf"
21- cache_key_hash_ugrid_mesh2d = "e541bf3bbe4a3ed3a64ce48efb493bef0271ff45431036168be08376a89cea57"
22- cache_key_hash_ugrid_mesh2d_one_indexed = "f0ebdfdff229659f81037d4ed90aa629433b0a1843ae6d8d9f0c7c732f1a9754"
20+ cache_key_hash_cf1d = "1a3226072f08441ee79f727b0775709209ff2965299539c898ecc401cf17e23f"
21+ cache_key_hash_cf2d = "c8d2671af35e96a08c6e33f616bc460ba3957bfa3ffc4529cfd84378e9de4c2f"
22+ cache_key_hash_shoc_standard = "18788cd57e4aff55dc5c0918513942bc6849d7b90e53a09bb77c4598fa3daf29"
23+ cache_key_hash_ugrid_mesh2d = "9e7c0ded2bfcc6843131e09303b8bec53e6edfbb18115e2c50e07adce29e8702"
24+ cache_key_hash_ugrid_mesh2d_one_indexed = "045be69d5ef70b20f26dc9a14e6cea8a11fe3cc9a3c4c4b303aed6f22206ac7a"
25+
26+
27+ @pytest .fixture
28+ def emsarray_version ():
29+ return '1.0.0'
2330
2431
2532def test_hash_attributes (datasets : pathlib .Path ):
@@ -72,7 +79,9 @@ def test_hash_int():
7279 assert result_hash == int_hash
7380
7481
75- def test_cache_key_cfgrid1d (datasets : pathlib .Path ):
82+ def test_cache_key_cfgrid1d (datasets : pathlib .Path , monkeypatch , emsarray_version ):
83+ monkeypatch .setattr (emsarray , "__version__" , emsarray_version )
84+
7685 dataset_cf = emsarray .open_dataset (datasets / 'cfgrid1d.nc' )
7786
7887 result_cache_key_cf = emsarray .operations .cache .make_cache_key (dataset_cf )
@@ -82,7 +91,9 @@ def test_cache_key_cfgrid1d(datasets: pathlib.Path):
8291 assert result_cache_key_cf == cache_key_hash_cf1d
8392
8493
85- def test_cache_key_cfgrid2d (datasets : pathlib .Path ):
94+ def test_cache_key_cfgrid2d (datasets : pathlib .Path , monkeypatch , emsarray_version ):
95+ monkeypatch .setattr (emsarray , "__version__" , emsarray_version )
96+
8697 dataset_cf = emsarray .open_dataset (datasets / 'cfgrid2d.nc' )
8798
8899 result_cache_key_cf = emsarray .operations .cache .make_cache_key (dataset_cf )
@@ -92,7 +103,9 @@ def test_cache_key_cfgrid2d(datasets: pathlib.Path):
92103 assert result_cache_key_cf == cache_key_hash_cf2d
93104
94105
95- def test_cache_key_shoc_standard (datasets : pathlib .Path ):
106+ def test_cache_key_shoc_standard (datasets : pathlib .Path , monkeypatch , emsarray_version ):
107+ monkeypatch .setattr (emsarray , "__version__" , emsarray_version )
108+
96109 dataset_cf = emsarray .open_dataset (datasets / 'shoc_standard.nc' )
97110
98111 result_cache_key_cf = emsarray .operations .cache .make_cache_key (dataset_cf )
@@ -102,7 +115,9 @@ def test_cache_key_shoc_standard(datasets: pathlib.Path):
102115 assert result_cache_key_cf == cache_key_hash_shoc_standard
103116
104117
105- def test_cache_key_ugrid_mesh2d (datasets : pathlib .Path ):
118+ def test_cache_key_ugrid_mesh2d (datasets : pathlib .Path , monkeypatch , emsarray_version ):
119+ monkeypatch .setattr (emsarray , "__version__" , emsarray_version )
120+
106121 dataset_cf = emsarray .open_dataset (datasets / 'ugrid_mesh2d.nc' )
107122
108123 result_cache_key_cf = emsarray .operations .cache .make_cache_key (dataset_cf )
@@ -112,7 +127,9 @@ def test_cache_key_ugrid_mesh2d(datasets: pathlib.Path):
112127 assert result_cache_key_cf == cache_key_hash_ugrid_mesh2d
113128
114129
115- def test_cache_key_ugrid_mesh2d_one_indexed (datasets : pathlib .Path ):
130+ def test_cache_key_ugrid_mesh2d_one_indexed (datasets : pathlib .Path , monkeypatch , emsarray_version ):
131+ monkeypatch .setattr (emsarray , "__version__" , emsarray_version )
132+
116133 dataset_cf = emsarray .open_dataset (datasets / 'ugrid_mesh2d_one_indexed.nc' )
117134
118135 result_cache_key_cf = emsarray .operations .cache .make_cache_key (dataset_cf )
@@ -122,7 +139,9 @@ def test_cache_key_ugrid_mesh2d_one_indexed(datasets: pathlib.Path):
122139 assert result_cache_key_cf == cache_key_hash_ugrid_mesh2d_one_indexed
123140
124141
125- def test_cache_key_is_deterministic (datasets : pathlib .Path ):
142+ def test_cache_key_is_deterministic (datasets : pathlib .Path , monkeypatch , emsarray_version ):
143+ monkeypatch .setattr (emsarray , "__version__" , emsarray_version )
144+
126145 dataset_cf = emsarray .open_dataset (datasets / 'cfgrid1d.nc' )
127146
128147 result_cache_key_cf_1 = emsarray .operations .cache .make_cache_key (dataset_cf )
@@ -133,7 +152,9 @@ def test_cache_key_is_deterministic(datasets: pathlib.Path):
133152 assert result_cache_key_cf_1 == cache_key_hash_cf1d
134153
135154
136- def test_hash_attributes_is_deterministic (datasets : pathlib .Path ):
155+ def test_hash_attributes_is_deterministic (datasets : pathlib .Path , monkeypatch , emsarray_version ):
156+ monkeypatch .setattr (emsarray , "__version__" , emsarray_version )
157+
137158 dataset = emsarray .open_dataset (datasets / 'cfgrid1d.nc' )
138159
139160 m_lon_1 = hashlib .sha1 ()
@@ -150,7 +171,9 @@ def test_hash_attributes_is_deterministic(datasets: pathlib.Path):
150171 assert result_hash_lon_1 == attr_hash_lon
151172
152173
153- def test_cache_key_gives_unique_keys (datasets : pathlib .Path ):
174+ def test_cache_key_gives_unique_keys (datasets : pathlib .Path , monkeypatch , emsarray_version ):
175+ monkeypatch .setattr (emsarray , "__version__" , emsarray_version )
176+
154177 dataset_cf = emsarray .open_dataset (datasets / 'cfgrid1d.nc' )
155178 dataset_ugrid = emsarray .open_dataset (datasets / 'ugrid_mesh2d.nc' )
156179
@@ -166,7 +189,9 @@ def test_cache_key_gives_unique_keys(datasets: pathlib.Path):
166189 assert result_cache_key_ugrid == cache_key_hash_ugrid_mesh2d
167190
168191
169- def test_hash_attributes_gives_unique_keys (datasets : pathlib .Path ):
192+ def test_hash_attributes_gives_unique_keys (datasets : pathlib .Path , monkeypatch , emsarray_version ):
193+ monkeypatch .setattr (emsarray , "__version__" , emsarray_version )
194+
170195 dataset = emsarray .open_dataset (datasets / 'cfgrid1d.nc' )
171196
172197 m_lon = hashlib .sha1 ()
@@ -190,7 +215,9 @@ def test_hash_attributes_gives_unique_keys(datasets: pathlib.Path):
190215 assert result_hash_lat == attr_hash_lat
191216
192217
193- def test_cache_key_cfgrid1d_sha1 (datasets : pathlib .Path ):
218+ def test_cache_key_cfgrid1d_sha1 (datasets : pathlib .Path , monkeypatch , emsarray_version ):
219+ monkeypatch .setattr (emsarray , "__version__" , emsarray_version )
220+
194221 dataset_cf = emsarray .open_dataset (datasets / 'cfgrid1d.nc' )
195222
196223 result_cache_key_cf = emsarray .operations .cache .make_cache_key (dataset_cf , hashlib .sha1 ())
0 commit comments