Skip to content

Commit b43f161

Browse files
committed
Add test
1 parent 1965394 commit b43f161

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

numcodecs/tests/test_checksum32.py

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import importlib
12
import itertools
23
from contextlib import suppress
34

@@ -15,6 +16,9 @@
1516
)
1617

1718
has_crc32c = False
19+
has_google_crc32c = importlib.util.find_spec("google_crc32c") is not None
20+
has_legacy_crc32c = importlib.util.find_spec("crc32c") is not None
21+
1822
with suppress(ImportError):
1923
from numcodecs.checksum32 import CRC32C
2024

@@ -104,7 +108,7 @@ def test_err_location():
104108
with pytest.raises(ValueError):
105109
Adler32(location="foo")
106110
if not has_crc32c:
107-
pytest.skip("Needs `crc32c` installed")
111+
pytest.skip("Needs `crc32c` or `google_crc32c` installed")
108112
with pytest.raises(ValueError):
109113
CRC32C(location="foo")
110114

@@ -118,11 +122,15 @@ def test_err_location():
118122
"Adler32(location='end')",
119123
pytest.param(
120124
"CRC32C(location='start')",
121-
marks=pytest.mark.skipif(not has_crc32c, reason="Needs `crc32c` installed"),
125+
marks=pytest.mark.skipif(
126+
not has_crc32c, reason="Needs `crc32c` or `google_crc32c` installed"
127+
),
122128
),
123129
pytest.param(
124130
"CRC32C(location='end')",
125-
marks=pytest.mark.skipif(not has_crc32c, reason="Needs `crc32c` installed"),
131+
marks=pytest.mark.skipif(
132+
not has_crc32c, reason="Needs `crc32c` or `google_crc32c` installed"
133+
),
126134
),
127135
],
128136
)
@@ -141,7 +149,7 @@ def test_backwards_compatibility(codec_id, codec_instance):
141149
check_backwards_compatibility(codec_id, arrays, [codec_instance])
142150

143151

144-
@pytest.mark.skipif(not has_crc32c, reason="Needs `crc32c` installed")
152+
@pytest.mark.skipif(not has_crc32c, reason="Needs `crc32c` or `google_crc32c` installed")
145153
def test_backwards_compatibility_crc32c():
146154
check_backwards_compatibility(CRC32C.codec_id, arrays, [CRC32C()])
147155

@@ -164,14 +172,14 @@ def test_err_out_too_small(codec):
164172
codec.decode(codec.encode(arr), out)
165173

166174

167-
@pytest.mark.skipif(not has_crc32c, reason="Needs `crc32c` installed")
175+
@pytest.mark.skipif(not has_crc32c, reason="Needs `crc32c` or `google_crc32c` installed")
168176
def test_crc32c_checksum():
169177
arr = np.arange(0, 64, dtype="uint8")
170178
buf = CRC32C(location="end").encode(arr)
171179
assert np.frombuffer(buf, dtype="<u4", offset=(len(buf) - 4))[0] == np.uint32(4218238699)
172180

173181

174-
@pytest.mark.skipif(not has_crc32c, reason="Needs `crc32c` installed")
182+
@pytest.mark.skipif(not has_crc32c, reason="Needs `crc32c` or `google_crc32c` installed")
175183
def test_crc32c_incremental():
176184
"""Test that CRC32C.checksum supports incremental calculation via value parameter."""
177185
# Test incremental checksum calculation (for API compatibility)
@@ -197,3 +205,23 @@ def test_err_checksum(codec):
197205
buf[-1] = 0 # corrupt the checksum
198206
with pytest.raises(RuntimeError):
199207
codec.decode(buf)
208+
209+
210+
@pytest.mark.skipif(
211+
has_google_crc32c or not has_legacy_crc32c,
212+
reason="Only runs when legacy `crc32c` is used (not `google_crc32c`)",
213+
)
214+
def test_crc32c_deprecation_warning():
215+
"""Test that using legacy crc32c (not google_crc32c) issues a deprecation warning."""
216+
import sys
217+
218+
# Remove the module from cache to force re-import and trigger the warning
219+
if 'numcodecs.checksum32' in sys.modules:
220+
del sys.modules['numcodecs.checksum32']
221+
222+
with pytest.warns(
223+
DeprecationWarning, match="crc32c usage is deprecated since numcodecs v0.16.4"
224+
):
225+
import numcodecs.checksum32
226+
227+
importlib.reload(numcodecs.checksum32)

0 commit comments

Comments
 (0)