14
14
from nose .tools import assert_raises , eq_ as eq , assert_is_none
15
15
16
16
17
- from zarr .storage import DirectoryStore , MemoryStore , ZipStore , init_array
17
+ from zarr .storage import DirectoryStore , DictStore , ZipStore , init_array
18
18
from zarr .meta import decode_metadata
19
19
from zarr .compat import text_type
20
20
@@ -78,15 +78,13 @@ def test_get_set_del_contains(self):
78
78
except NotImplementedError :
79
79
pass
80
80
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'
86
85
store ['foo' ] = bytearray (b'bar' )
87
- eq (b'bar' , store ['foo' ])
88
86
store ['foo' ] = array .array ('B' , b'bar' )
89
- eq (b'bar' , store [ 'foo' ] )
87
+ store [ 'foo' ] = np . frombuffer (b'bar' , dtype = 'u1' )
90
88
91
89
def test_update (self ):
92
90
store = self .create_store ()
@@ -137,10 +135,16 @@ def test_pickle(self):
137
135
eq (v , getattr (store2 , k ))
138
136
139
137
140
- class TestMemoryStore (StoreTests , unittest .TestCase ):
138
+ class TestGenericStore (StoreTests , unittest .TestCase ):
141
139
142
140
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 ()
144
148
145
149
146
150
class TestDirectoryStore (StoreTests , unittest .TestCase ):
@@ -154,10 +158,14 @@ def create_store(self):
154
158
def test_path (self ):
155
159
156
160
# 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 )
161
169
162
170
# test behaviour with file path
163
171
with tempfile .NamedTemporaryFile () as f :
@@ -184,12 +192,3 @@ def create_store(self):
184
192
atexit .register (os .remove , path )
185
193
store = ZipStore (path )
186
194
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