Skip to content

Commit 4a586e0

Browse files
committed
Add CoordsSchema test cases
1 parent 4735350 commit 4a586e0

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

tests/test_core.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,14 @@ def test_attr_schema(type, value, validate, json):
161161
({'foo': AttrSchema(value=1)},),
162162
{},
163163
[{'foo': 'bar'}],
164-
r'value .* != .*',
164+
r'attrs .* != .*',
165+
),
166+
(
167+
AttrsSchema,
168+
({'foo': AttrSchema(value=1)},),
169+
{'allow_extra_keys': False},
170+
[{'foo': 'bar', 'x': 0}],
171+
r'attrs has extra keys.*',
165172
),
166173
(
167174
CoordsSchema,
@@ -172,16 +179,23 @@ def test_attr_schema(type, value, validate, json):
172179
),
173180
(
174181
CoordsSchema,
175-
({'x': DataArraySchema(name='x', dtype=np.str_)},),
182+
({'x': DataArraySchema(dtype=np.str_)},),
176183
{},
177-
[{'x': xr.DataArray([0, 1], name='x')}],
184+
[{'x': xr.DataArray([0, 1])}],
178185
r'dtype .* != .*',
179186
),
180187
(
181188
CoordsSchema,
182-
({'x': DataArraySchema(name='x')},),
189+
({'x': DataArraySchema(dims=('x',))},),
190+
{},
191+
[{'x': xr.DataArray([0, 1], name='x')}],
192+
r'dim mismatch in axis .* != .*',
193+
),
194+
(
195+
CoordsSchema,
196+
({'x': DataArraySchema()},),
183197
{"allow_extra_keys": False},
184-
[{'x': xr.DataArray([0, 1], name='x'), 'y': xr.DataArray([0, 1], name='y')}],
198+
[{'x': xr.DataArray([0, 1]), 'y': xr.DataArray([0, 1])}],
185199
r'coords has extra keys.*',
186200
),
187201
],

xarray_schema/components.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ def validate(self, attr: Any):
349349

350350
if self.value is not None:
351351
if self.value is not None and self.value != attr:
352-
raise SchemaError(f'value {attr} != {self.value}')
352+
raise SchemaError(f'attrs {attr} != {self.value}')
353353

354354
@property
355355
def json(self) -> dict:

0 commit comments

Comments
 (0)