Skip to content

Commit a46b6c0

Browse files
committed
Add a test
1 parent 15d4ab7 commit a46b6c0

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

cubed_xarray/tests/test_wrapping.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
import xarray as xr
2+
from xarray.tests import assert_allclose, create_test_data
3+
24
from xarray.namedarray.parallelcompat import list_chunkmanagers
5+
import pytest
36
import cubed
7+
from cubed.runtime.create import create_executor
48

59
from cubed_xarray.cubedmanager import CubedManager
610

711

12+
EXECUTORS = [create_executor("single-threaded"), create_executor("processes")]
13+
14+
@pytest.fixture(
15+
scope="module",
16+
params=EXECUTORS,
17+
ids=[executor.name for executor in EXECUTORS],
18+
)
19+
def executor(request):
20+
return request.param
21+
22+
823
class TestDiscoverCubedManager:
924
def test_list_cubedmanager(self):
1025
chunkmanagers = list_chunkmanagers()
@@ -20,3 +35,19 @@ def test_chunk(self):
2035
# TODO test cubed is default when dask not installed
2136

2237
# TODO test dask is default over cubed when both installed
38+
39+
40+
def test_to_zarr(tmpdir, executor):
41+
spec = cubed.Spec(allowed_mem="200MB", executor=executor)
42+
43+
original = create_test_data().chunk(chunked_array_type="cubed", from_array_kwargs={'spec': spec})
44+
45+
filename = tmpdir / "out.zarr"
46+
original.to_zarr(filename)
47+
48+
with xr.open_dataset(
49+
filename, chunks="auto", engine="zarr", chunked_array_type="cubed", from_array_kwargs={'spec': spec}
50+
) as restored:
51+
assert isinstance(restored.var1.data, cubed.Array)
52+
computed = restored.compute()
53+
assert_allclose(original, computed)

0 commit comments

Comments
 (0)