Skip to content

Commit f5809a5

Browse files
author
Martin Durant
committed
more coverage
1 parent a987dbe commit f5809a5

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

zarr/storage.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@ def __init__(self, url, normalize_keys=True, key_separator='.',
970970
self.meta = json.loads(self.map.get(metadata_key, b"{}").decode())
971971
if mode == 'r' or 'zarr_consolidated_format' in self.meta:
972972
consolidated_format = self.meta.get('zarr_consolidated_format', None)
973-
if consolidated_format != 1:
973+
if consolidated_format != 1: # pragma: no cover
974974
raise MetadataError('unsupported zarr consolidated metadata format: %s' %
975975
consolidated_format)
976976
else:
@@ -989,11 +989,11 @@ def _normalize_key(self, key):
989989

990990
def __getitem__(self, key):
991991
if self.consolidated and self._is_meta(key):
992-
return self.meta[key]
992+
return self.meta[key].encode() # expect bytes out
993993
key = self._normalize_key(key)
994994
try:
995995
return self.map[key]
996-
except self.exceptions as e:
996+
except self.exceptions as e:
997997
raise KeyError(key) from e
998998

999999
def __setitem__(self, key, value):
@@ -1032,7 +1032,8 @@ def __contains__(self, key):
10321032
return key in self.map
10331033

10341034
def __eq__(self, other):
1035-
return type(self) == type(other) and self.map == other.map
1035+
return (type(self) == type(other) and self.map == other.map
1036+
and self.mode == other.mode)
10361037

10371038
def keys(self):
10381039
return iter(self.map)

zarr/tests/test_storage.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,12 +857,31 @@ def test_consolidated(self):
857857
store = FSStore(path, consolidated=True)
858858
store[".zarray"] = b"{}"
859859
assert ".zmetadata" in os.listdir(path)
860+
del store[".zarray"]
861+
with pytest.raises(KeyError):
862+
store[".zarray"]
863+
store[".zarray"] = b"{}"
864+
865+
os.remove(os.path.join(path, ".zarray"))
866+
store2 = FSStore(path, mode='r', consolidated=True)
867+
assert store != store2
868+
assert ".zarray" in store2
869+
assert store2[".zarray"] == b"{}"
870+
with pytest.raises(PermissionError):
871+
store2[".zarray"] = b"{{}}"
872+
with pytest.raises(PermissionError):
873+
del store2[".zarray"]
874+
875+
store.clear()
876+
assert ".zmetadata" not in store
860877

861878
def test_not_fsspec(self):
862879
import zarr
863880
path = tempfile.mkdtemp()
864881
with pytest.raises(ValueError, match="storage_options"):
865882
zarr.open_array(path, mode='w', storage_options={"some": "kwargs"})
883+
with pytest.raises(ValueError, match="storage_options"):
884+
zarr.open_group(path, mode='w', storage_options={"some": "kwargs"})
866885

867886

868887
class TestNestedDirectoryStore(TestDirectoryStore, unittest.TestCase):

0 commit comments

Comments
 (0)