Skip to content

Commit 50849fe

Browse files
committed
correct test invocations and weaken the requirements for crc32c json
1 parent a63982f commit 50849fe

File tree

3 files changed

+316
-94
lines changed

3 files changed

+316
-94
lines changed

src/zarr/codecs/crc32c_.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from collections.abc import Mapping
44
from dataclasses import dataclass
5-
from typing import TYPE_CHECKING, Literal, TypedDict, TypeGuard, cast, overload
5+
from typing import TYPE_CHECKING, Literal, NotRequired, TypedDict, TypeGuard, cast, overload
66

77
import numpy as np
88
import typing_extensions
@@ -21,7 +21,7 @@
2121

2222

2323
class Crc32cConfig_V2(TypedDict):
24-
location: ReadOnly[Literal["start", "end"]]
24+
location: NotRequired[ReadOnly[Literal["start", "end"]]]
2525

2626

2727
class Crc32cConfig_V3(TypedDict): ...
@@ -37,9 +37,9 @@ class Crc32cJSON_V3(NamedConfig[Literal["crc32c"], Crc32cConfig_V3]): ...
3737
def check_json_v2(data: object) -> TypeGuard[Crc32cJSON_V2]:
3838
return (
3939
isinstance(data, Mapping)
40-
and set(data.keys()) == {"id", "location"}
40+
and "id" in data
4141
and data["id"] == "crc32c"
42-
and data["location"] in ("start", "end")
42+
and data.get("location", "end") in ("start", "end")
4343
)
4444

4545

@@ -64,7 +64,7 @@ def from_dict(cls, data: dict[str, JSON]) -> Self:
6464
@classmethod
6565
def _from_json_v2(cls, data: CodecJSON) -> Self:
6666
if check_json_v2(data):
67-
if data["location"] != "end":
67+
if data.get("location", "end") != "end":
6868
raise ValueError('The crc32c codec only supports the "end" location')
6969
return cls()
7070
msg = (

tests/test_codecs/test_crc32c.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ def test_from_json_v2_valid(self) -> None:
6969
"invalid_data",
7070
[
7171
{"id": "wrong_codec"}, # Wrong codec name
72-
{"name": "crc32c"}, # V3 format in V2 method
73-
{"id": "crc32c", "extra": "field"}, # Extra fields
7472
{}, # Missing id
7573
{"other": "field"}, # Wrong field name
7674
],
@@ -138,7 +136,6 @@ def test_check_json_v2_valid(self, valid_data: Crc32cJSON_V2) -> None:
138136
[
139137
{"id": "wrong_codec"},
140138
{"name": "crc32c"},
141-
{"id": "crc32c", "extra": "field"},
142139
{},
143140
"not_a_dict",
144141
None,

0 commit comments

Comments
 (0)