Skip to content

Commit

Permalink
N5FSStore: try to increase code coverage
Browse files Browse the repository at this point in the history
 * Adds a test for the dimension_separator warning
 * uses the parent test_complex for listdir
  • Loading branch information
joshmoore committed Sep 17, 2021
1 parent 864773d commit b8f12a8
Showing 1 changed file with 29 additions and 17 deletions.
46 changes: 29 additions & 17 deletions zarr/tests/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -900,13 +900,20 @@ def mock_walker_no_slash(_path):
@pytest.mark.skipif(have_fsspec is False, reason="needs fsspec")
class TestFSStore(StoreTests):

def create_store(self, normalize_keys=False, dimension_separator="."):
path = tempfile.mkdtemp()
atexit.register(atexit_rmtree, path)
def create_store(self, normalize_keys=False,
dimension_separator=".",
path=None,
**kwargs):

if path is None:
path = tempfile.mkdtemp()
atexit.register(atexit_rmtree, path)

store = FSStore(
path,
normalize_keys=normalize_keys,
dimension_separator=dimension_separator)
dimension_separator=dimension_separator,
**kwargs)
return store

def test_init_array(self):
Expand Down Expand Up @@ -937,8 +944,9 @@ def test_dimension_separator(self):
def test_complex(self):
path1 = tempfile.mkdtemp()
path2 = tempfile.mkdtemp()
store = FSStore("simplecache::file://" + path1,
simplecache={"same_names": True, "cache_storage": path2})
store = self.create_store(path="simplecache::file://" + path1,
simplecache={"same_names": True,
"cache_storage": path2})
assert not store
assert not os.listdir(path1)
assert not os.listdir(path2)
Expand Down Expand Up @@ -979,10 +987,10 @@ def test_create(self):
def test_read_only(self):
path = tempfile.mkdtemp()
atexit.register(atexit_rmtree, path)
store = FSStore(path)
store = self.create_store(path=path)
store['foo'] = b"bar"

store = FSStore(path, mode='r')
store = self.create_store(path=path, mode='r')

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

filepath = os.path.join(path, "foo")
with pytest.raises(ValueError):
FSStore(filepath, mode='r')
self.create_store(path=filepath, mode='r')

def test_eq(self):
store1 = FSStore("anypath")
store2 = FSStore("anypath")
store1 = self.create_store(path="anypath")
store2 = self.create_store(path="anypath")
assert store1 == store2

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

@pytest.mark.skipif(have_fsspec is False, reason="needs fsspec")
class TestN5FSStore(TestFSStore):
def create_store(self, normalize_keys=False):
path = tempfile.mkdtemp()
atexit.register(atexit_rmtree, path)
store = N5FSStore(path, normalize_keys=normalize_keys)
def create_store(self, normalize_keys=False, path=None, **kwargs):

if path is None:
path = tempfile.mkdtemp()
atexit.register(atexit_rmtree, path)

store = N5FSStore(path, normalize_keys=normalize_keys, **kwargs)
return store

def test_equal(self):
Expand Down Expand Up @@ -1375,8 +1386,9 @@ def test_init_group_overwrite_chunk_store(self):
self._test_init_group_overwrite_chunk_store('C')

def test_dimension_separator(self):
with pytest.raises(TypeError):
self.create_store(key_separator='.')

with pytest.warns(UserWarning, match='dimension_separator'):
self.create_store(dimension_separator='/')


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

0 comments on commit b8f12a8

Please sign in to comment.