Skip to content

Commit f5a52f6

Browse files
committed
increase test coverage
1 parent 3ee6e11 commit f5a52f6

File tree

3 files changed

+33
-18
lines changed

3 files changed

+33
-18
lines changed

zarr/meta.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,10 @@ def decode_group_metadata(b):
8383
zarr_format = meta.get('zarr_format', None)
8484
if zarr_format != ZARR_FORMAT:
8585
raise MetadataError('unsupported zarr format: %s' % zarr_format)
86-
try:
87-
meta = dict(
88-
zarr_format=meta['zarr_format'],
89-
)
90-
except Exception as e:
91-
raise MetadataError('error decoding metadata: %s' % e)
92-
else:
93-
return meta
86+
meta = dict(
87+
zarr_format=ZARR_FORMAT,
88+
)
89+
return meta
9490

9591

9692
def encode_group_metadata(meta=None):

zarr/tests/test_attrs.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,20 @@
1515
class TestAttributes(unittest.TestCase):
1616

1717
def init_attributes(self, store, readonly=False):
18-
key = 'attrs'
19-
store[key] = json.dumps(dict()).encode('ascii')
20-
return Attributes(store, key=key, readonly=readonly)
18+
return Attributes(store, key='attrs', readonly=readonly)
2119

2220
def test_storage(self):
2321

2422
store = dict()
25-
a = self.init_attributes(store)
26-
assert 'attrs' in store
27-
assert isinstance(store['attrs'], binary_type)
28-
d = json.loads(text_type(store['attrs'], 'ascii'))
29-
eq(dict(), d)
23+
a = Attributes(store=store, key='attrs')
24+
assert 'foo' not in a
25+
assert 'bar' not in a
26+
eq(dict(), a.asdict())
3027

3128
a['foo'] = 'bar'
3229
a['baz'] = 42
33-
30+
assert 'attrs' in store
31+
assert isinstance(store['attrs'], binary_type)
3432
d = json.loads(text_type(store['attrs'], 'ascii'))
3533
eq(dict(foo='bar', baz=42), d)
3634

zarr/tests/test_meta.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from zarr.compat import PY2
1111
from zarr.meta import decode_array_metadata, encode_dtype, decode_dtype, \
12-
ZARR_FORMAT
12+
ZARR_FORMAT, decode_group_metadata
1313
from zarr.errors import MetadataError
1414

1515

@@ -101,3 +101,24 @@ def test_encode_decode_dtype():
101101
o = json.loads(s)
102102
d = decode_dtype(o)
103103
eq(np.dtype(dt), d)
104+
105+
106+
def test_decode_group():
107+
108+
# typical
109+
b = '''{
110+
"zarr_format": %s
111+
}''' % ZARR_FORMAT
112+
if not PY2:
113+
b = b.encode('ascii')
114+
meta = decode_group_metadata(b)
115+
eq(ZARR_FORMAT, meta['zarr_format'])
116+
117+
# unsupported format
118+
b = '''{
119+
"zarr_format": %s
120+
}''' % (ZARR_FORMAT - 1)
121+
if not PY2:
122+
b = b.encode('ascii')
123+
with assert_raises(MetadataError):
124+
decode_group_metadata(b)

0 commit comments

Comments
 (0)