|
5 | 5 | if TYPE_CHECKING: |
6 | 6 | from zarr.core.dtype.wrapper import TBaseDType, TBaseScalar, ZDType |
7 | 7 |
|
| 8 | +import pytest |
| 9 | +import requests |
| 10 | + |
| 11 | + |
| 12 | +class _TestZDTypeSchema: |
| 13 | + # subclasses define the URL for the schema, if available |
| 14 | + schema_url: ClassVar[str] = "" |
| 15 | + |
| 16 | + @pytest.fixture(scope="class") |
| 17 | + def get_schema(self) -> object: |
| 18 | + response = requests.get(self.schema_url) |
| 19 | + response.raise_for_status() |
| 20 | + return json_schema.loads(response.text) |
| 21 | + |
| 22 | + def test_schema(self, schema: json_schema.Schema) -> None: |
| 23 | + assert schema.is_valid(self.test_cls.to_json(zarr_format=2)) |
| 24 | + |
8 | 25 |
|
9 | 26 | class _TestZDType: |
10 | 27 | test_cls: type[ZDType[TBaseDType, TBaseScalar]] |
@@ -47,50 +64,10 @@ def test_scalar_roundtrip_v2(self, scalar_v2_params: Any) -> None: |
47 | 64 | dtype_json, scalar_json = scalar_v2_params |
48 | 65 | zdtype = self.test_cls.from_json(dtype_json, zarr_format=2) |
49 | 66 | scalar = zdtype.from_json_value(scalar_json, zarr_format=2) |
50 | | - assert self._scalar_equals(scalar_json, zdtype.to_json_value(scalar, zarr_format=2)) |
| 67 | + assert scalar_json == zdtype.to_json_value(scalar, zarr_format=2) |
51 | 68 |
|
52 | 69 | def test_scalar_roundtrip_v3(self, scalar_v3_params: Any) -> None: |
53 | 70 | dtype_json, scalar_json = scalar_v3_params |
54 | 71 | zdtype = self.test_cls.from_json(dtype_json, zarr_format=3) |
55 | 72 | scalar = zdtype.from_json_value(scalar_json, zarr_format=3) |
56 | | - assert self._scalar_equals(scalar_json, zdtype.to_json_value(scalar, zarr_format=3)) |
57 | | - |
58 | | - @staticmethod |
59 | | - def _scalar_equals(a: object, b: object) -> bool: |
60 | | - """ |
61 | | - Compare two scalars for equality. Subclasses that test dtypes with scalars that don't allow |
62 | | - simple equality like nans should override this method. |
63 | | - """ |
64 | | - return a == b |
65 | | - |
66 | | - """ @abc.abstractmethod |
67 | | - def test_cast_value(self, value: Any) -> None: |
68 | | - raise NotImplementedError |
69 | | -
|
70 | | - @abc.abstractmethod |
71 | | - def test_check_value(self) -> None: |
72 | | - raise NotImplementedError |
73 | | -
|
74 | | - @abc.abstractmethod |
75 | | - def test_default_value(self) -> None: |
76 | | - raise NotImplementedError |
77 | | -
|
78 | | - @abc.abstractmethod |
79 | | - def test_check_json(self, value: Any) -> None: |
80 | | - raise NotImplementedError |
81 | | -
|
82 | | - @abc.abstractmethod |
83 | | - def test_from_json_roundtrip_v2(self, value: Any) -> None: |
84 | | - raise NotImplementedError |
85 | | -
|
86 | | - @abc.abstractmethod |
87 | | - def test_from_json_roundtrip_v3(self, value: Any) -> None: |
88 | | - raise NotImplementedError |
89 | | -
|
90 | | - @abc.abstractmethod |
91 | | - def test_from_json_value_roundtrip_v2(self, value: Any) -> None: |
92 | | - raise NotImplementedError |
93 | | -
|
94 | | - @abc.abstractmethod |
95 | | - def test_from_json_value_roundtrip_v3(self, value: Any) -> None: |
96 | | - raise NotImplementedError """ |
| 73 | + assert scalar_json == zdtype.to_json_value(scalar, zarr_format=3) |
0 commit comments