Skip to content

Commit 0bcb71f

Browse files
committed
get storage tests running
1 parent 76dbb54 commit 0bcb71f

File tree

3 files changed

+29
-30
lines changed

3 files changed

+29
-30
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,4 @@ zarr/version.py
6767
*~
6868
*.zip
6969
example
70-
70+
doesnotexist

zarr/storage.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ def __init__(self, path):
488488

489489
# guard conditions
490490
path = os.path.abspath(path)
491-
if os.path.exists and not os.path.isdir(path):
491+
if os.path.exists(path) and not os.path.isdir(path):
492492
raise ValueError('path exists but is not a directory')
493493

494494
self.path = path
@@ -552,15 +552,15 @@ def __eq__(self, other):
552552
)
553553

554554
def keys(self):
555-
dirnames = [self.path]
556-
while dirnames:
557-
dirname = dirnames.pop()
555+
todo = [(self.path, '')]
556+
while todo:
557+
dirname, prefix = todo.pop()
558558
for name in os.listdir(dirname):
559559
path = os.path.join(dirname, name)
560560
if os.path.isfile(path):
561-
yield path
561+
yield prefix + name
562562
elif os.path.isdir(path):
563-
dirnames.append(path)
563+
todo.append((path, prefix + name + '/'))
564564

565565
def __iter__(self):
566566
return self.keys()

zarr/tests/test_storage.py

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from nose.tools import assert_raises, eq_ as eq, assert_is_none
1515

1616

17-
from zarr.storage import DirectoryStore, MemoryStore, ZipStore, init_array
17+
from zarr.storage import DirectoryStore, DictStore, ZipStore, init_array
1818
from zarr.meta import decode_metadata
1919
from zarr.compat import text_type
2020

@@ -78,15 +78,13 @@ def test_get_set_del_contains(self):
7878
except NotImplementedError:
7979
pass
8080

81-
# check writeable values
82-
with assert_raises(TypeError):
83-
# non-writeable value
84-
store['foo'] = 42
85-
# alternative values
81+
def test_writeable_values(self):
82+
store = self.create_store()
83+
# store should accept anything that implements buffer interface
84+
store['foo'] = b'bar'
8685
store['foo'] = bytearray(b'bar')
87-
eq(b'bar', store['foo'])
8886
store['foo'] = array.array('B', b'bar')
89-
eq(b'bar', store['foo'])
87+
store['foo'] = np.frombuffer(b'bar', dtype='u1')
9088

9189
def test_update(self):
9290
store = self.create_store()
@@ -137,10 +135,16 @@ def test_pickle(self):
137135
eq(v, getattr(store2, k))
138136

139137

140-
class TestMemoryStore(StoreTests, unittest.TestCase):
138+
class TestGenericStore(StoreTests, unittest.TestCase):
141139

142140
def create_store(self):
143-
return MemoryStore()
141+
return dict()
142+
143+
144+
class TestDictStore(StoreTests, unittest.TestCase):
145+
146+
def create_store(self):
147+
return DictStore()
144148

145149

146150
class TestDirectoryStore(StoreTests, unittest.TestCase):
@@ -154,10 +158,14 @@ def create_store(self):
154158
def test_path(self):
155159

156160
# test behaviour with path that does not exist
157-
if os.path.exists('doesnotexist'):
158-
shutil.rmtree('doesnotexist')
159-
DirectoryStore('doesnotexist')
160-
assert os.path.isdir('doesnotexist')
161+
path = 'doesnotexist'
162+
if os.path.exists(path):
163+
shutil.rmtree(path)
164+
store = DirectoryStore(path)
165+
# should only be created on demand
166+
assert not os.path.exists(path)
167+
store['foo'] = b'bar'
168+
assert os.path.isdir(path)
161169

162170
# test behaviour with file path
163171
with tempfile.NamedTemporaryFile() as f:
@@ -184,12 +192,3 @@ def create_store(self):
184192
atexit.register(os.remove, path)
185193
store = ZipStore(path)
186194
return store
187-
188-
189-
class TestZipStoreMulti(StoreTests, unittest.TestCase):
190-
191-
def create_store(self):
192-
path = tempfile.mktemp(suffix='.zip')
193-
atexit.register(os.remove, path)
194-
store = ZipStore(path, arcpath='foo/bar')
195-
return store

0 commit comments

Comments
 (0)