Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
d-v-b committed Dec 10, 2024
1 parent 5efbe30 commit 192fc8b
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions xarray/tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -3401,8 +3401,8 @@ def test_append(self) -> None:
if has_zarr_v3:
expected = {
"set": 4,
"get": 16, # TODO: fixme upstream (should be 8)
"list_dir": 3, # TODO: fixme upstream (should be 2)
"get": 9, # TODO: fixme upstream (should be 8)
"list_dir": 2, # TODO: fixme upstream (should be 2)
"list_prefix": 0,
}
else:
Expand All @@ -3424,8 +3424,8 @@ def test_append(self) -> None:
if has_zarr_v3:
expected = {
"set": 4,
"get": 16, # TODO: fixme upstream (should be 8)
"list_dir": 3, # TODO: fixme upstream (should be 2)
"get": 9, # TODO: fixme upstream (should be 8)
"list_dir": 2, # TODO: fixme upstream (should be 2)
"list_prefix": 0,
}
else:
Expand Down Expand Up @@ -3479,7 +3479,7 @@ def test_region_write(self) -> None:
expected = {
"set": 1,
"get": 3,
"list_dir": 2,
"list_dir": 0,
"list_prefix": 0,
}
else:
Expand All @@ -3502,8 +3502,8 @@ def test_region_write(self) -> None:
if has_zarr_v3:
expected = {
"set": 1,
"get": 5,
"list_dir": 2,
"get": 4,
"list_dir": 0,
"list_prefix": 0,
}
else:
Expand All @@ -3525,7 +3525,7 @@ def test_region_write(self) -> None:
expected = {
"set": 0,
"get": 5,
"list_dir": 1,
"list_dir": 0,
"list_prefix": 0,
}
else:
Expand Down Expand Up @@ -3567,13 +3567,26 @@ def create_zarr_target(self):
yield tmp

@contextlib.contextmanager
def create_store(self, cache_members: bool = False):
def create_store(self, **kwargs):
with self.create_zarr_target() as store_target:
group = backends.ZarrStore.open_group(
store_target, mode="a", cache_members=cache_members
)
group = backends.ZarrStore.open_group(store_target, mode="a", **kwargs)
yield group

def test_write_store(self) -> None:
# This test is overriden from the base implementation because we need to ensure
# that the members cache is off, as the `ZarrStore` instance is re-used in the
# test function. Refactoring the base version of this test to
# if this test is refactored to no longer re-use the store object, then
# this implementation can be removed.

expected = create_test_data()
with self.create_store(cache_members=False) as store:
expected.dump_to_store(store)
# we need to cf decode the store because it has time and
# non-dimension coordinates
with xr.decode_cf(store) as actual:
assert_allclose(expected, actual)


@requires_zarr
class TestZarrWriteEmpty(TestZarrDirectoryStore):
Expand Down

0 comments on commit 192fc8b

Please sign in to comment.