Skip to content

Commit 3b56155

Browse files
committed
N5FSStore: try to increase code coverage
* Adds a test for the dimension_separator warning * uses the parent test_complex for listdir * "nocover" the import error since fsspec is ever present
1 parent 864773d commit 3b56155

File tree

2 files changed

+44
-18
lines changed

2 files changed

+44
-18
lines changed

zarr/n5.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ def _contains_attrs(self, path):
567567

568568
attrs = attrs_to_zarr(self._load_n5_attrs(attrs_key))
569569
return len(attrs) > 0
570-
except ImportError:
570+
except ImportError: # pragma: no cover
571571
pass
572572

573573

zarr/tests/test_storage.py

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -900,13 +900,20 @@ def mock_walker_no_slash(_path):
900900
@pytest.mark.skipif(have_fsspec is False, reason="needs fsspec")
901901
class TestFSStore(StoreTests):
902902

903-
def create_store(self, normalize_keys=False, dimension_separator="."):
904-
path = tempfile.mkdtemp()
905-
atexit.register(atexit_rmtree, path)
903+
def create_store(self, normalize_keys=False,
904+
dimension_separator=".",
905+
path=None,
906+
**kwargs):
907+
908+
if path is None:
909+
path = tempfile.mkdtemp()
910+
atexit.register(atexit_rmtree, path)
911+
906912
store = FSStore(
907913
path,
908914
normalize_keys=normalize_keys,
909-
dimension_separator=dimension_separator)
915+
dimension_separator=dimension_separator,
916+
**kwargs)
910917
return store
911918

912919
def test_init_array(self):
@@ -937,8 +944,9 @@ def test_dimension_separator(self):
937944
def test_complex(self):
938945
path1 = tempfile.mkdtemp()
939946
path2 = tempfile.mkdtemp()
940-
store = FSStore("simplecache::file://" + path1,
941-
simplecache={"same_names": True, "cache_storage": path2})
947+
store = self.create_store(path="simplecache::file://" + path1,
948+
simplecache={"same_names": True,
949+
"cache_storage": path2})
942950
assert not store
943951
assert not os.listdir(path1)
944952
assert not os.listdir(path2)
@@ -949,6 +957,20 @@ def test_complex(self):
949957
assert store["foo"] == b"hello"
950958
assert 'foo' in os.listdir(path2)
951959

960+
def test_deep_ndim(self):
961+
import zarr
962+
963+
store = self.create_store()
964+
foo = zarr.open_group(store=store)
965+
bar = foo.create_group("bar")
966+
baz = bar.create_dataset("baz",
967+
shape=(4, 4, 4),
968+
chunks=(2, 2, 2),
969+
dtype="i8")
970+
baz[:] = 1
971+
assert set(store.listdir()) == set([".zgroup", "bar"])
972+
assert foo["bar"]["baz"][(0, 0, 0)] == 1
973+
952974
def test_not_fsspec(self):
953975
import zarr
954976
path = tempfile.mkdtemp()
@@ -979,10 +1001,10 @@ def test_create(self):
9791001
def test_read_only(self):
9801002
path = tempfile.mkdtemp()
9811003
atexit.register(atexit_rmtree, path)
982-
store = FSStore(path)
1004+
store = self.create_store(path=path)
9831005
store['foo'] = b"bar"
9841006

985-
store = FSStore(path, mode='r')
1007+
store = self.create_store(path=path, mode='r')
9861008

9871009
with pytest.raises(PermissionError):
9881010
store['foo'] = b"hex"
@@ -1000,11 +1022,11 @@ def test_read_only(self):
10001022

10011023
filepath = os.path.join(path, "foo")
10021024
with pytest.raises(ValueError):
1003-
FSStore(filepath, mode='r')
1025+
self.create_store(path=filepath, mode='r')
10041026

10051027
def test_eq(self):
1006-
store1 = FSStore("anypath")
1007-
store2 = FSStore("anypath")
1028+
store1 = self.create_store(path="anypath")
1029+
store2 = self.create_store(path="anypath")
10081030
assert store1 == store2
10091031

10101032
@pytest.mark.usefixtures("s3")
@@ -1300,10 +1322,13 @@ def test_filters(self):
13001322

13011323
@pytest.mark.skipif(have_fsspec is False, reason="needs fsspec")
13021324
class TestN5FSStore(TestFSStore):
1303-
def create_store(self, normalize_keys=False):
1304-
path = tempfile.mkdtemp()
1305-
atexit.register(atexit_rmtree, path)
1306-
store = N5FSStore(path, normalize_keys=normalize_keys)
1325+
def create_store(self, normalize_keys=False, path=None, **kwargs):
1326+
1327+
if path is None:
1328+
path = tempfile.mkdtemp()
1329+
atexit.register(atexit_rmtree, path)
1330+
1331+
store = N5FSStore(path, normalize_keys=normalize_keys, **kwargs)
13071332
return store
13081333

13091334
def test_equal(self):
@@ -1375,8 +1400,9 @@ def test_init_group_overwrite_chunk_store(self):
13751400
self._test_init_group_overwrite_chunk_store('C')
13761401

13771402
def test_dimension_separator(self):
1378-
with pytest.raises(TypeError):
1379-
self.create_store(key_separator='.')
1403+
1404+
with pytest.warns(UserWarning, match='dimension_separator'):
1405+
self.create_store(dimension_separator='/')
13801406

13811407

13821408
@pytest.mark.skipif(have_fsspec is False, reason="needs fsspec")

0 commit comments

Comments
 (0)