Skip to content

Commit f358fed

Browse files
committed
Extend the test suite for dim_sep
1 parent 10c874e commit f358fed

File tree

6 files changed

+139
-17
lines changed

6 files changed

+139
-17
lines changed

fixture/flat/.zarray

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"chunks": [
3+
2,
4+
2
5+
],
6+
"compressor": {
7+
"blocksize": 0,
8+
"clevel": 5,
9+
"cname": "lz4",
10+
"id": "blosc",
11+
"shuffle": 1
12+
},
13+
"dtype": "<i8",
14+
"fill_value": 0,
15+
"filters": null,
16+
"order": "C",
17+
"shape": [
18+
2,
19+
2
20+
],
21+
"zarr_format": 2
22+
}

fixture/flat/0.0

48 Bytes
Binary file not shown.

fixture/nested/.zarray

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"chunks": [
3+
2,
4+
2
5+
],
6+
"compressor": {
7+
"blocksize": 0,
8+
"clevel": 5,
9+
"cname": "lz4",
10+
"id": "blosc",
11+
"shuffle": 1
12+
},
13+
"dimension_separator": "/",
14+
"dtype": "<i8",
15+
"fill_value": 0,
16+
"filters": null,
17+
"order": "C",
18+
"shape": [
19+
2,
20+
2
21+
],
22+
"zarr_format": 2
23+
}

fixture/nested/0/0

48 Bytes
Binary file not shown.

zarr/tests/test_dim_separator.py

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import atexit
2+
import tempfile
3+
import unittest
4+
from numbers import Integral
5+
6+
import numpy as np
7+
import pytest
8+
from numcodecs import Adler32, Zlib
9+
from numpy.testing import assert_array_equal
10+
11+
import zarr
12+
from zarr.convenience import (
13+
consolidate_metadata,
14+
copy,
15+
copy_store,
16+
load,
17+
open,
18+
open_consolidated,
19+
save,
20+
save_group,
21+
copy_all,
22+
)
23+
from zarr.core import Array
24+
from zarr.errors import CopyError
25+
from zarr.hierarchy import Group, group
26+
from zarr.storage import (ConsolidatedMetadataStore, MemoryStore,
27+
DirectoryStore, NestedDirectoryStore, FSStore,
28+
atexit_rmtree, getsize)
29+
from zarr.tests.util import have_fsspec
30+
31+
32+
@pytest.fixture(params=("static_nested",
33+
"static_flat",
34+
"directory_nested",
35+
"directory_flat",
36+
"directory_default",
37+
"nesteddirectory_nested",
38+
"nesteddirectory_default",
39+
"fs_nested",
40+
"fs_flat",
41+
"fs_default"))
42+
def dataset(tmpdir, request):
43+
"""
44+
Generate a variety of different Zarrs using
45+
different store implementations as well as
46+
different dimension_separator arguments.
47+
"""
48+
49+
loc = tmpdir.join("dim_sep_test.zarr")
50+
which = request.param
51+
kwargs = {}
52+
53+
if which.startswith("static"):
54+
if which.endswith("nested"):
55+
return "fixture/nested"
56+
else:
57+
return "fixture/flat"
58+
59+
if which.startswith("directory"):
60+
store_class = DirectoryStore
61+
elif which.startswith("nested"):
62+
store_class = NestedDirectoryStore
63+
else:
64+
if have_fsspec is False:
65+
pytest.skip("no fsspec")
66+
store_class = FSStore
67+
kwargs["mode"] = "w"
68+
kwargs["auto_mkdir"] = True
69+
70+
if which.endswith("nested"):
71+
kwargs["dimension_separator"] = "/"
72+
elif which.endswith("flat"):
73+
kwargs["dimension_separator"] = "."
74+
75+
store = store_class(str(loc), **kwargs)
76+
zarr.creation.array(store=store, data=[[1, 2], [3, 4]])
77+
return str(loc)
78+
79+
80+
def verify(array):
81+
assert 1 == array[0][0]
82+
83+
84+
def test_open(dataset):
85+
verify(zarr.open(dataset))
86+
87+
def test_fsstore(dataset):
88+
verify(zarr.Array(store=FSStore(dataset)))
89+
90+
def test_directory(dataset):
91+
verify(zarr.Array(store=DirectoryStore(dataset)))
92+
93+
def test_nested(dataset):
94+
verify(zarr.Array(store=NestedDirectoryStore(dataset)))

zarr/tests/test_storage.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -890,23 +890,6 @@ def mock_walker_no_slash(_path):
890890
)
891891
assert res == {'.zgroup', 'g1/.zgroup', 'd1/.zarray'}
892892

893-
def test_read_nested(self):
894-
import zarr
895-
path = tempfile.mkdtemp()
896-
atexit.register(atexit_rmtree, path)
897-
898-
store1 = NestedDirectoryStore(path)
899-
g1 = zarr.open(store=store1, mode="w")
900-
g1.create_dataset("data", data=[[1, 2], [3, 4]])
901-
902-
store2 = NestedDirectoryStore(path)
903-
g2 = zarr.open(store=store2)
904-
assert g2.data[0][0] == 1
905-
906-
store3 = DirectoryStore(path)
907-
g3 = zarr.open(store=store3)
908-
assert g3.data[0][0] == 1
909-
910893

911894
@pytest.mark.skipif(have_fsspec is False, reason="needs fsspec")
912895
class TestFSStore(StoreTests):

0 commit comments

Comments
 (0)