Skip to content

Commit e769f31

Browse files
committed
weaken codec JSON test, update crc32c test cases
1 parent feb2047 commit e769f31

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

src/zarr/codecs/crc32c_.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ def check_json_v2(data: object) -> TypeGuard[Crc32cJSON_V2]:
4444

4545

4646
def check_json_v3(data: object) -> TypeGuard[Crc32cJSON_V3]:
47+
if data == "crc32c":
48+
return True
4749
return (
4850
isinstance(data, Mapping)
4951
and set(data.keys()) in ({"name", "configuration"}, {"name"})

tests/test_codecs/conftest.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,24 @@ class BaseTestCodec:
2323
"""
2424

2525
test_cls: type[Codec]
26-
valid_json_v2: ClassVar[tuple[CodecJSON_V2, ...]]
27-
valid_json_v3: ClassVar[tuple[CodecJSON_V3, ...]]
28-
29-
def test_from_json_roundtrip_v2(self, valid_json_v2: CodecJSON_V2) -> None:
26+
valid_json_v2: ClassVar[tuple[CodecJSON_V2 | object, ...]]
27+
valid_json_v3: ClassVar[tuple[CodecJSON_V3 | object, ...]]
28+
29+
def test_from_json_v2(self, valid_json_v2: CodecJSON_V2) -> None:
30+
"""
31+
Test that the codec generated from valid JSON generates a JSON representation that generates
32+
the same codec
33+
"""
3034
codec = self.test_cls.from_json(valid_json_v2)
31-
assert codec.to_json(zarr_format=2) == valid_json_v2
35+
assert codec.from_json(codec.to_json(zarr_format=2)) == codec
3236

33-
def test_from_json_roundtrip_v3(self, valid_json_v3: CodecJSON_V3) -> None:
37+
def test_from_json_v3(self, valid_json_v3: CodecJSON_V3) -> None:
38+
"""
39+
Test that the codec generated from valid JSON generates a JSON representation that generates
40+
the same codec
41+
"""
3442
codec = self.test_cls.from_json(valid_json_v3)
35-
assert codec.to_json(zarr_format=3) == valid_json_v3
43+
assert codec.from_json(codec.to_json(zarr_format=3)) == codec
3644

3745

3846
def pytest_generate_tests(metafunc: Any) -> None:

tests/test_codecs/test_crc32c.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,15 @@
3434

3535
class TestCrc32cCodec(BaseTestCodec):
3636
test_cls = Crc32cCodec
37-
valid_json_v2 = ({"id": "crc32c"},)
38-
valid_json_v3 = ({"name": "crc32c"},)
37+
valid_json_v2 = (
38+
{"id": "crc32c"},
39+
pytest.param(
40+
{"id": "crc32c", "location": "start"},
41+
marks=pytest.mark.xfail(reason="start location not supported"),
42+
),
43+
{"id": "crc32c", "location": "end"},
44+
)
45+
valid_json_v3 = ({"name": "crc32c"}, "crc32c")
3946

4047

4148
class TestCrc32cCodecJSON:

0 commit comments

Comments
 (0)