Skip to content

Use pytest.skipif to properly report skipped CRC32C codec tests #740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 60 additions & 34 deletions numcodecs/tests/test_checksum32.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,54 +39,59 @@
np.random.randint(-(2**63), -(2**63) + 20, size=1000, dtype='i8').view('m8[m]'),
]

codecs = [
base_codecs = [
CRC32(),
CRC32(location="end"),
Adler32(),
Adler32(location="end"),
]
if has_crc32c:
codecs.extend(
[
CRC32C(location="start"),
CRC32C(),
]
)


@pytest.mark.parametrize(("codec", "arr"), itertools.product(codecs, arrays))
def get_all_codecs():
codecs = base_codecs.copy()
if has_crc32c:
codecs.extend(
[
CRC32C(location="start"),
CRC32C(),
]
)
return codecs


@pytest.mark.parametrize(("codec", "arr"), itertools.product(get_all_codecs(), arrays))
def test_encode_decode(codec, arr):
check_encode_decode(arr, codec)


@pytest.mark.parametrize(("codec", "arr"), itertools.product(codecs, arrays))
@pytest.mark.parametrize(("codec", "arr"), itertools.product(get_all_codecs(), arrays))
def test_errors(codec, arr):
enc = codec.encode(arr)
with pytest.raises(RuntimeError):
codec.decode(enc[:-1])


@pytest.mark.parametrize("codec", codecs)
@pytest.mark.parametrize("codec", get_all_codecs())
def test_config(codec):
check_config(codec)


@pytest.mark.parametrize("codec", codecs)
@pytest.mark.parametrize("codec", get_all_codecs())
def test_err_input_too_small(codec):
buf = b'000' # 3 bytes are too little for a 32-bit checksum
with pytest.raises(ValueError):
codec.decode(buf)


@pytest.mark.parametrize("codec", codecs)
@pytest.mark.parametrize("codec", get_all_codecs())
def test_err_encode_non_contiguous(codec):
# non-contiguous memory
arr = np.arange(1000, dtype='i4')[::2]
with pytest.raises(ValueError):
codec.encode(arr)


@pytest.mark.parametrize("codec", codecs)
@pytest.mark.parametrize("codec", get_all_codecs())
def test_err_encode_list(codec):
data = ['foo', 'bar', 'baz']
with pytest.raises(TypeError):
Expand All @@ -98,39 +103,60 @@
CRC32(location="foo")
with pytest.raises(ValueError):
Adler32(location="foo")
if has_crc32c:
with pytest.raises(ValueError):
CRC32C(location="foo")
if not has_crc32c:
pytest.skip("Needs `crc32c` installed")

Check warning on line 107 in numcodecs/tests/test_checksum32.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/tests/test_checksum32.py#L107

Added line #L107 was not covered by tests
with pytest.raises(ValueError):
CRC32C(location="foo")


@pytest.mark.parametrize(
"repr_str",
[
"CRC32(location='start')",
"CRC32(location='end')",
"Adler32(location='start')",
"Adler32(location='end')",
pytest.param(
"CRC32C(location='start')",
marks=pytest.mark.skipif(not has_crc32c, reason="Needs `crc32c` installed"),
),
pytest.param(
"CRC32C(location='end')",
marks=pytest.mark.skipif(not has_crc32c, reason="Needs `crc32c` installed"),
),
],
)
def test_repr(repr_str):
check_repr(repr_str)


def test_repr():
check_repr("CRC32(location='start')")
check_repr("CRC32(location='end')")
check_repr("Adler32(location='start')")
check_repr("Adler32(location='end')")
if has_crc32c:
check_repr("CRC32C(location='start')")
check_repr("CRC32C(location='end')")
@pytest.mark.parametrize(
('codec_id', 'codec_instance'),
[
(CRC32.codec_id, CRC32()),
(Adler32.codec_id, Adler32()),
],
)
def test_backwards_compatibility(codec_id, codec_instance):
check_backwards_compatibility(codec_id, arrays, [codec_instance])


def test_backwards_compatibility():
check_backwards_compatibility(CRC32.codec_id, arrays, [CRC32()])
check_backwards_compatibility(Adler32.codec_id, arrays, [Adler32()])
if has_crc32c:
check_backwards_compatibility(CRC32C.codec_id, arrays, [CRC32C()])
@pytest.mark.skipif(not has_crc32c, reason="Needs `crc32c` installed")
def test_backwards_compatibility_crc32c():
check_backwards_compatibility(CRC32C.codec_id, arrays, [CRC32C()])


@pytest.mark.parametrize("codec", codecs)
@pytest.mark.parametrize("codec", get_all_codecs())
def test_err_encode_object_buffer(codec):
check_err_encode_object_buffer(codec)


@pytest.mark.parametrize("codec", codecs)
@pytest.mark.parametrize("codec", get_all_codecs())
def test_err_decode_object_buffer(codec):
check_err_decode_object_buffer(codec)


@pytest.mark.parametrize("codec", codecs)
@pytest.mark.parametrize("codec", get_all_codecs())
def test_err_out_too_small(codec):
arr = np.arange(10, dtype='i4')
out = np.empty_like(arr)[:-1]
Expand All @@ -145,7 +171,7 @@
assert np.frombuffer(buf, dtype="<u4", offset=(len(buf) - 4))[0] == np.uint32(4218238699)


@pytest.mark.parametrize("codec", codecs)
@pytest.mark.parametrize("codec", get_all_codecs())
def test_err_checksum(codec):
arr = np.arange(0, 64, dtype="uint8")
buf = bytearray(codec.encode(arr))
Expand Down
Loading