-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Xarray Backends tests; fix
list_prefix
bug (#423)
* Add Xarray Backends tests. This is somewhat hacky, since these tests aren't intended to run externally. But it works! and it's finding bugs! * Rename to fix default python action * fix * cleanup * fix bug. * Add fs,mem,minio testing * try again * skip pickling test * try again
- Loading branch information
Showing
3 changed files
with
153 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import contextlib | ||
import os | ||
import tempfile | ||
import time | ||
|
||
import pytest | ||
|
||
import zarr | ||
from icechunk import IcechunkStore, S3Credentials, StorageConfig | ||
from xarray.tests.test_backends import ( | ||
ZarrBase, | ||
default_zarr_version, # noqa: F401; needed otherwise not discovered | ||
) | ||
|
||
|
||
@pytest.mark.skipif( | ||
not os.environ.get("ICECHUNK_XARRAY_BACKENDS_TESTS", None), | ||
reason="skipping Xarray backends tests", | ||
) | ||
class IcechunkStoreBase(ZarrBase): | ||
@pytest.mark.parametrize("consolidated", [False, True, None]) | ||
@pytest.mark.parametrize("compute", [False, True]) | ||
@pytest.mark.parametrize("use_dask", [False, True]) | ||
@pytest.mark.parametrize("write_empty", [False, True, None]) | ||
def test_write_region(self, consolidated, compute, use_dask, write_empty) -> None: | ||
if consolidated is not False: | ||
pytest.skip("consolidated not supported.") | ||
super().test_write_region(consolidated, compute, use_dask, write_empty) | ||
|
||
@pytest.mark.parametrize("consolidated", [False, True, None]) | ||
def test_roundtrip_consolidated(self, consolidated) -> None: | ||
if consolidated is not False: | ||
pytest.skip("consolidated not supported.") | ||
super().test_roundtrip_consolidated(consolidated) | ||
|
||
|
||
class TestIcechunkStoreFilesystem(IcechunkStoreBase): | ||
@contextlib.contextmanager | ||
def create_zarr_target(self): | ||
if zarr.config.config["default_zarr_version"] == 2: | ||
pytest.skip("v2 not supported") | ||
with tempfile.TemporaryDirectory() as tmpdir: | ||
yield IcechunkStore.create(StorageConfig.filesystem(tmpdir)) | ||
|
||
|
||
class TestIcechunkStoreMemory(IcechunkStoreBase): | ||
@contextlib.contextmanager | ||
def create_zarr_target(self): | ||
if zarr.config.config["default_zarr_version"] == 2: | ||
pytest.skip("v2 not supported") | ||
yield IcechunkStore.create(StorageConfig.memory()) | ||
|
||
def test_pickle(self): | ||
pytest.skip(reason="memory icechunk stores cannot be pickled.") | ||
|
||
def test_pickle_dataarray(self): | ||
pytest.skip(reason="memory icechunk stores cannot be pickled.") | ||
|
||
|
||
class TestIcechunkStoreMinio(IcechunkStoreBase): | ||
@contextlib.contextmanager | ||
def create_zarr_target(self): | ||
if zarr.config.config["default_zarr_version"] == 2: | ||
pytest.skip("v2 not supported") | ||
storage_config = { | ||
"bucket": "testbucket", | ||
"prefix": "python-xarray-test__" + str(time.time()), | ||
"endpoint_url": "http://localhost:9000", | ||
"region": "us-east-1", | ||
"allow_http": True, | ||
} | ||
storage_config = StorageConfig.s3_from_config( | ||
**storage_config, | ||
credentials=S3Credentials( | ||
access_key_id="minio123", secret_access_key="minio123" | ||
), | ||
) | ||
store = IcechunkStore.create(storage=storage_config, read_only=False) | ||
yield store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters