@@ -187,22 +187,27 @@ def test_create_dataset(self):
187
187
eq ('/bar' , d3 .name )
188
188
assert_is (store , d3 .store )
189
189
190
- def test_getitem_contains (self ):
190
+ def test_getitem_contains_iterators (self ):
191
191
# setup
192
192
store = self .create_store ()
193
193
init_group (store )
194
194
g1 = Group (store = store )
195
195
g2 = g1 .create_group ('foo/bar' )
196
- d1 = g1 .create_dataset ('a/b/c' , shape = 1000 , chunks = 100 )
196
+ d1 = g2 .create_dataset ('/ a/b/c' , shape = 1000 , chunks = 100 )
197
197
d1 [:] = np .arange (1000 )
198
+ d2 = g1 .create_dataset ('foo/baz' , shape = 3000 , chunks = 300 )
199
+ d2 [:] = np .arange (3000 )
198
200
199
201
# test __getitem__
200
202
assert_is_instance (g1 ['foo' ], Group )
201
203
assert_is_instance (g1 ['foo' ]['bar' ], Group )
202
204
assert_is_instance (g1 ['foo/bar' ], Group )
203
205
assert_is_instance (g1 ['/foo/bar/' ], Group )
206
+ assert_is_instance (g1 ['foo/baz' ], Array )
204
207
eq (g2 , g1 ['foo/bar' ])
205
208
eq (g1 ['foo' ]['bar' ], g1 ['foo/bar' ])
209
+ eq (d2 , g1 ['foo/baz' ])
210
+ assert_array_equal (d2 [:], g1 ['foo/baz' ])
206
211
assert_is_instance (g1 ['a' ], Group )
207
212
assert_is_instance (g1 ['a' ]['b' ], Group )
208
213
assert_is_instance (g1 ['a/b' ], Group )
@@ -215,27 +220,68 @@ def test_getitem_contains(self):
215
220
# test __contains__
216
221
assert 'foo' in g1
217
222
assert 'foo/bar' in g1
223
+ assert 'foo/baz' in g1
218
224
assert 'bar' in g1 ['foo' ]
219
225
assert 'a' in g1
220
226
assert 'a/b' in g1
221
227
assert 'a/b/c' in g1
222
228
assert 'baz' not in g1
223
229
assert 'a/b/c/d' not in g1
224
230
assert 'a/z' not in g1
231
+ assert 'quux' not in g1 ['foo' ]
225
232
226
233
# test key errors
227
234
with assert_raises (KeyError ):
228
235
g1 ['baz' ]
229
236
with assert_raises (KeyError ):
230
237
g1 ['x/y/z' ]
231
238
239
+ # test __len__
240
+ eq (2 , len (g1 ))
241
+ eq (2 , len (g1 ['foo' ]))
242
+ eq (0 , len (g1 ['foo/bar' ]))
243
+ eq (1 , len (g1 ['a' ]))
244
+ eq (1 , len (g1 ['a/b' ]))
245
+
246
+ # test keys()
247
+ eq (['a' , 'foo' ], sorted (g1 .keys ()))
248
+ eq (['bar' , 'baz' ], sorted (g1 ['foo' ].keys ()))
249
+ eq ([], sorted (g1 ['foo/bar' ].keys ()))
250
+
251
+ def test_empty_getitem_contains_iterators (self ):
252
+ # setup
253
+ store = self .create_store ()
254
+ init_group (store )
255
+ g = Group (store = store )
256
+
257
+ # test
258
+ eq ([], list (g .keys ()))
259
+ eq (0 , len (g ))
260
+ assert 'foo' not in g
261
+
262
+ def test_group_repr (self ):
263
+ store = self .create_store ()
264
+ init_group (store )
265
+ g = Group (store = store )
266
+ expect = 'zarr.hierarchy.Group(/, 0)\n store: builtins.dict'
267
+ actual = repr (g )
268
+ eq (expect , actual )
269
+
232
270
233
271
class TestGroupDictStore (TestGroup ):
234
272
235
273
@staticmethod
236
274
def create_store ():
237
275
return DictStore ()
238
276
277
+ def test_group_repr (self ):
278
+ store = self .create_store ()
279
+ init_group (store )
280
+ g = Group (store = store )
281
+ expect = 'zarr.hierarchy.Group(/, 0)\n store: zarr.storage.DictStore'
282
+ actual = repr (g )
283
+ eq (expect , actual )
284
+
239
285
240
286
def rmtree_if_exists (path , rmtree = shutil .rmtree , isdir = os .path .isdir ):
241
287
if isdir (path ):
@@ -251,6 +297,15 @@ def create_store():
251
297
store = DirectoryStore (path )
252
298
return store
253
299
300
+ def test_group_repr (self ):
301
+ store = self .create_store ()
302
+ init_group (store )
303
+ g = Group (store = store )
304
+ expect = 'zarr.hierarchy.Group(/, 0)\n ' \
305
+ ' store: zarr.storage.DirectoryStore'
306
+ actual = repr (g )
307
+ eq (expect , actual )
308
+
254
309
255
310
class TestGroupZipStore (TestGroup ):
256
311
@@ -260,3 +315,12 @@ def create_store():
260
315
atexit .register (os .remove , path )
261
316
store = ZipStore (path )
262
317
return store
318
+
319
+ def test_group_repr (self ):
320
+ store = self .create_store ()
321
+ init_group (store )
322
+ g = Group (store = store )
323
+ expect = 'zarr.hierarchy.Group(/, 0)\n ' \
324
+ ' store: zarr.storage.ZipStore'
325
+ actual = repr (g )
326
+ eq (expect , actual )
0 commit comments