1
1
import xarray as xr
2
+ from xarray .tests import assert_allclose , create_test_data
3
+
2
4
from xarray .namedarray .parallelcompat import list_chunkmanagers
5
+ import pytest
3
6
import cubed
7
+ from cubed .runtime .create import create_executor
4
8
5
9
from cubed_xarray .cubedmanager import CubedManager
6
10
7
11
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
+
8
23
class TestDiscoverCubedManager :
9
24
def test_list_cubedmanager (self ):
10
25
chunkmanagers = list_chunkmanagers ()
@@ -20,3 +35,19 @@ def test_chunk(self):
20
35
# TODO test cubed is default when dask not installed
21
36
22
37
# 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