Skip to content

Commit 3a806b2

Browse files
committed
coverage to 100%
1 parent 3e31f33 commit 3a806b2

File tree

4 files changed

+51
-26
lines changed

4 files changed

+51
-26
lines changed

zarr/storage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ def __setitem__(self, key, value):
539539
if not os.path.exists(dir_path):
540540
try:
541541
os.makedirs(dir_path)
542-
except NotADirectoryError:
542+
except Exception:
543543
raise KeyError(key)
544544

545545
# write to temporary file

zarr/tests/test_core.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import shutil
77
import pickle
88
import os
9-
from collections import OrderedDict
109

1110

1211
import numpy as np
@@ -18,6 +17,7 @@
1817

1918
from zarr.core import Array
2019
from zarr.errors import ReadOnlyError
20+
from zarr.compat import PY2
2121

2222

2323
class TestArray(unittest.TestCase):
@@ -512,28 +512,29 @@ def test_pickle(self):
512512
assert_array_equal(z[:], z2[:])
513513

514514
def test_repr(self):
515+
if not PY2:
515516

516-
# no path
517-
z = self.create_array(shape=100, chunks=10, dtype='f4',
518-
compression='zlib', compression_opts=1)
519-
expect = """zarr.core.Array((100,), float32, chunks=(10,), order=C)
517+
# no path
518+
z = self.create_array(shape=100, chunks=10, dtype='f4',
519+
compression='zlib', compression_opts=1)
520+
expect = """zarr.core.Array((100,), float32, chunks=(10,), order=C)
520521
compression: zlib; compression_opts: 1
521522
nbytes: 400; nbytes_stored: 210; ratio: 1.9; initialized: 0/10
522523
store: builtins.dict
523524
"""
524-
actual = repr(z)
525-
for l1, l2 in zip(expect.split('\n'), actual.split('\n')):
526-
eq(l1, l2)
527-
528-
# with path
529-
z = self.create_array(path='foo/bar', shape=100, chunks=10, dtype='f4',
530-
compression='zlib', compression_opts=1)
531-
# flake8: noqa
532-
expect = """zarr.core.Array(/foo/bar, (100,), float32, chunks=(10,), order=C)
525+
actual = repr(z)
526+
for l1, l2 in zip(expect.split('\n'), actual.split('\n')):
527+
eq(l1, l2)
528+
529+
# with path
530+
z = self.create_array(path='foo/bar', shape=100, chunks=10, dtype='f4',
531+
compression='zlib', compression_opts=1)
532+
# flake8: noqa
533+
expect = """zarr.core.Array(/foo/bar, (100,), float32, chunks=(10,), order=C)
533534
compression: zlib; compression_opts: 1
534535
nbytes: 400; nbytes_stored: 210; ratio: 1.9; initialized: 0/10
535536
store: builtins.dict
536537
"""
537-
actual = repr(z)
538-
for l1, l2 in zip(expect.split('\n'), actual.split('\n')):
539-
eq(l1, l2)
538+
actual = repr(z)
539+
for l1, l2 in zip(expect.split('\n'), actual.split('\n')):
540+
eq(l1, l2)

zarr/tests/test_hierarchy.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,35 @@ def test_array_creation(self):
509509
with assert_raises(ReadOnlyError):
510510
grp.full_like('aa', a)
511511

512+
def test_paths(self):
513+
store = self.create_store()
514+
init_group(store)
515+
g1 = Group(store=store)
516+
g2 = g1.create_group('foo/bar')
517+
518+
eq(g1, g1['/'])
519+
eq(g1, g1['//'])
520+
eq(g1, g1['///'])
521+
eq(g1, g2['/'])
522+
eq(g1, g2['//'])
523+
eq(g1, g2['///'])
524+
eq(g2, g1['foo/bar'])
525+
eq(g2, g1['/foo/bar'])
526+
eq(g2, g1['foo/bar/'])
527+
eq(g2, g1['//foo/bar'])
528+
eq(g2, g1['//foo//bar//'])
529+
eq(g2, g1['///foo///bar///'])
530+
eq(g2, g2['/foo/bar'])
531+
532+
with assert_raises(ValueError):
533+
g1['']
534+
g1['.']
535+
g1['..']
536+
g1['foo/.']
537+
g1['foo/..']
538+
g1['foo/./bar']
539+
g1['foo/../bar']
540+
512541

513542
class TestGroupDictStore(TestGroup):
514543

zarr/util.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,17 +196,12 @@ def normalize_storage_path(path):
196196
path = path.replace('\\', '/')
197197

198198
# ensure no leading slash
199-
while path[0] == '/':
199+
while len(path) > 0 and path[0] == '/':
200200
path = path[1:]
201-
if not path:
202-
break
203201

204202
# ensure no trailing slash
205-
if path:
206-
while path[-1] == '/':
207-
path = path[:-1]
208-
if not path:
209-
break
203+
while len(path) > 0 and path[-1] == '/':
204+
path = path[:-1]
210205

211206
# collapse any repeated slashes
212207
previous_char = None

0 commit comments

Comments
 (0)