forked from zarr-developers/zarr-python
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_dim_separator.py
75 lines (57 loc) · 2 KB
/
test_dim_separator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import pytest
from numpy.testing import assert_array_equal
import zarr
from zarr.core import Array
from zarr.storage import (DirectoryStore, NestedDirectoryStore, FSStore)
from zarr.tests.util import have_fsspec
@pytest.fixture(params=("static_nested",
"static_flat",
"directory_nested",
"directory_flat",
"directory_default",
"nesteddirectory_nested",
"nesteddirectory_default",
"fs_nested",
"fs_flat",
"fs_default"))
def dataset(tmpdir, request):
"""
Generate a variety of different Zarrs using
different store implementations as well as
different dimension_separator arguments.
"""
loc = tmpdir.join("dim_sep_test.zarr")
which = request.param
kwargs = {}
if which.startswith("static"):
if which.endswith("nested"):
return "fixture/nested"
else:
return "fixture/flat"
if which.startswith("directory"):
store_class = DirectoryStore
elif which.startswith("nested"):
store_class = NestedDirectoryStore
else:
if have_fsspec is False:
pytest.skip("no fsspec")
store_class = FSStore
kwargs["mode"] = "w"
kwargs["auto_mkdir"] = True
if which.endswith("nested"):
kwargs["dimension_separator"] = "/"
elif which.endswith("flat"):
kwargs["dimension_separator"] = "."
store = store_class(str(loc), **kwargs)
zarr.creation.array(store=store, data=[[1, 2], [3, 4]])
return str(loc)
def verify(array):
assert_array_equal(array[:], [[1, 2], [3, 4]])
def test_open(dataset):
verify(zarr.open(dataset))
def test_fsstore(dataset):
verify(Array(store=FSStore(dataset)))
def test_directory(dataset):
verify(zarr.Array(store=DirectoryStore(dataset)))
def test_nested(dataset):
verify(Array(store=NestedDirectoryStore(dataset)))