(
self,
consolidated: bool | None,
write_empty: bool | None,
)
| 4500 | @pytest.mark.parametrize("consolidated", [True, False, None]) |
| 4501 | @pytest.mark.parametrize("write_empty", [True, False, None]) |
| 4502 | def test_write_empty( |
| 4503 | self, |
| 4504 | consolidated: bool | None, |
| 4505 | write_empty: bool | None, |
| 4506 | ) -> None: |
| 4507 | def assert_expected_files(expected: list[str], store: str) -> None: |
| 4508 | """Convenience for comparing with actual files written""" |
| 4509 | ls = [] |
| 4510 | test_root = os.path.join(store, "test") |
| 4511 | for root, _, files in os.walk(test_root): |
| 4512 | ls.extend( |
| 4513 | [ |
| 4514 | os.path.join(root, f).removeprefix(test_root).lstrip("/") |
| 4515 | for f in files |
| 4516 | ] |
| 4517 | ) |
| 4518 | |
| 4519 | assert set(expected) == { |
| 4520 | file.lstrip("c/") |
| 4521 | for file in ls |
| 4522 | if (file not in (".zattrs", ".zarray", "zarr.json")) |
| 4523 | } |
| 4524 | |
| 4525 | # The zarr format is set by the `default_zarr_format` |
| 4526 | # pytest fixture that acts on a superclass |
| 4527 | zarr_format_3 = has_zarr_v3 and zarr.config.config["default_zarr_format"] == 3 |
| 4528 | if (write_empty is False) or (write_empty is None and has_zarr_v3): |
| 4529 | expected = ["0.1.0"] |
| 4530 | else: |
| 4531 | expected = [ |
| 4532 | "0.0.0", |
| 4533 | "0.0.1", |
| 4534 | "0.1.0", |
| 4535 | "0.1.1", |
| 4536 | ] |
| 4537 | |
| 4538 | # use nan for default fill_value behaviour |
| 4539 | data = np.array([np.nan, np.nan, 1.0, np.nan]).reshape((1, 2, 2)) |
| 4540 | |
| 4541 | if zarr_format_3: |
| 4542 | # transform to the path style of zarr 3 |
| 4543 | # e.g. 0/0/1 |
| 4544 | expected = [e.replace(".", "/") for e in expected] |
| 4545 | |
| 4546 | ds = xr.Dataset(data_vars={"test": (("Z", "Y", "X"), data)}) |
| 4547 | |
| 4548 | if has_dask: |
| 4549 | ds["test"] = ds["test"].chunk(1) |
| 4550 | encoding = None |
| 4551 | else: |
| 4552 | encoding = {"test": {"chunks": (1, 1, 1)}} |
| 4553 | |
| 4554 | with self.temp_dir() as (_d, store): |
| 4555 | ds.to_zarr( |
| 4556 | store, |
| 4557 | mode="w", |
| 4558 | encoding=encoding, |
| 4559 | write_empty_chunks=write_empty, |
nothing calls this directly
no test coverage detected