Skip to content

Commit b8f12a8

Browse files
committed
N5FSStore: try to increase code coverage
* Adds a test for the dimension_separator warning * uses the parent test_complex for listdir
1 parent 864773d commit b8f12a8

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

zarr/tests/test_storage.py

Lines changed: 29 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)
@@ -979,10 +987,10 @@ def test_create(self):
979987
def test_read_only(self):
980988
path = tempfile.mkdtemp()
981989
atexit.register(atexit_rmtree, path)
982-
store = FSStore(path)
990+
store = self.create_store(path=path)
983991
store['foo'] = b"bar"
984992

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

987995
with pytest.raises(PermissionError):
988996
store['foo'] = b"hex"
@@ -1000,11 +1008,11 @@ def test_read_only(self):
10001008

10011009
filepath = os.path.join(path, "foo")
10021010
with pytest.raises(ValueError):
1003-
FSStore(filepath, mode='r')
1011+
self.create_store(path=filepath, mode='r')
10041012

10051013
def test_eq(self):
1006-
store1 = FSStore("anypath")
1007-
store2 = FSStore("anypath")
1014+
store1 = self.create_store(path="anypath")
1015+
store2 = self.create_store(path="anypath")
10081016
assert store1 == store2
10091017

10101018
@pytest.mark.usefixtures("s3")
@@ -1300,10 +1308,13 @@ def test_filters(self):
13001308

13011309
@pytest.mark.skipif(have_fsspec is False, reason="needs fsspec")
13021310
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)
1311+
def create_store(self, normalize_keys=False, path=None, **kwargs):
1312+
1313+
if path is None:
1314+
path = tempfile.mkdtemp()
1315+
atexit.register(atexit_rmtree, path)
1316+
1317+
store = N5FSStore(path, normalize_keys=normalize_keys, **kwargs)
13071318
return store
13081319

13091320
def test_equal(self):
@@ -1375,8 +1386,9 @@ def test_init_group_overwrite_chunk_store(self):
13751386
self._test_init_group_overwrite_chunk_store('C')
13761387

13771388
def test_dimension_separator(self):
1378-
with pytest.raises(TypeError):
1379-
self.create_store(key_separator='.')
1389+
1390+
with pytest.warns(UserWarning, match='dimension_separator'):
1391+
self.create_store(dimension_separator='/')
13801392

13811393

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

0 commit comments

Comments
 (0)