14
14
import pytest
15
15
from numpy .testing import assert_array_almost_equal , assert_array_equal
16
16
17
+ from numcodecs .compat import ensure_bytes
18
+
17
19
from zarr .codecs import BZ2 , AsType , Blosc , Zlib
18
20
from zarr .errors import MetadataError
19
21
from zarr .hierarchy import group
@@ -54,7 +56,7 @@ def test_get_set_del_contains(self):
54
56
store ['foo' ]
55
57
store ['foo' ] = b'bar'
56
58
assert 'foo' in store
57
- assert b'bar' == store ['foo' ]
59
+ assert b'bar' == ensure_bytes ( store ['foo' ])
58
60
59
61
# test __delitem__ (optional)
60
62
try :
@@ -101,10 +103,10 @@ def test_pop(self):
101
103
store ['baz' ] = b'qux'
102
104
assert len (store ) == 2
103
105
v = store .pop ('foo' )
104
- assert v == b'bar'
106
+ assert ensure_bytes ( v ) == b'bar'
105
107
assert len (store ) == 1
106
108
v = store .pop ('baz' )
107
- assert v == b'qux'
109
+ assert ensure_bytes ( v ) == b'qux'
108
110
assert len (store ) == 0
109
111
with pytest .raises (KeyError ):
110
112
store .pop ('xxx' )
@@ -123,7 +125,7 @@ def test_popitem(self):
123
125
store ['foo' ] = b'bar'
124
126
k , v = store .popitem ()
125
127
assert k == 'foo'
126
- assert v == b'bar'
128
+ assert ensure_bytes ( v ) == b'bar'
127
129
assert len (store ) == 0
128
130
with pytest .raises (KeyError ):
129
131
store .popitem ()
@@ -148,8 +150,8 @@ def test_update(self):
148
150
assert 'foo' not in store
149
151
assert 'baz' not in store
150
152
store .update (foo = b'bar' , baz = b'quux' )
151
- assert b'bar' == store ['foo' ]
152
- assert b'quux' == store ['baz' ]
153
+ assert b'bar' == ensure_bytes ( store ['foo' ])
154
+ assert b'quux' == ensure_bytes ( store ['baz' ])
153
155
154
156
if hasattr (store , 'close' ):
155
157
store .close ()
@@ -174,9 +176,9 @@ def test_iterators(self):
174
176
assert 4 == len (store )
175
177
assert {'a' , 'b' , 'c/d' , 'c/e/f' } == set (store )
176
178
assert {'a' , 'b' , 'c/d' , 'c/e/f' } == set (store .keys ())
177
- assert {b'aaa' , b'bbb' , b'ddd' , b'fff' } == set (store .values ())
179
+ assert {b'aaa' , b'bbb' , b'ddd' , b'fff' } == set (map ( ensure_bytes , store .values () ))
178
180
assert ({('a' , b'aaa' ), ('b' , b'bbb' ), ('c/d' , b'ddd' ), ('c/e/f' , b'fff' )} ==
179
- set (store .items ()))
181
+ set (map ( lambda kv : ( kv [ 0 ], ensure_bytes ( kv [ 1 ])), store .items () )))
180
182
181
183
if hasattr (store , 'close' ):
182
184
store .close ()
@@ -203,8 +205,8 @@ def test_pickle(self):
203
205
# verify
204
206
assert n == len (store2 )
205
207
assert keys == sorted (store2 .keys ())
206
- assert b'bar' == store2 ['foo' ]
207
- assert b'quux' == store2 ['baz' ]
208
+ assert b'bar' == ensure_bytes ( store2 ['foo' ])
209
+ assert b'quux' == ensure_bytes ( store2 ['baz' ])
208
210
209
211
if hasattr (store2 , 'close' ):
210
212
store2 .close ()
@@ -730,10 +732,10 @@ def setdel_hierarchy_checks(store):
730
732
# test __setitem__ overwrite level
731
733
store ['x/y/z' ] = b'xxx'
732
734
store ['x/y' ] = b'yyy'
733
- assert b'yyy' == store ['x/y' ]
735
+ assert b'yyy' == ensure_bytes ( store ['x/y' ])
734
736
assert 'x/y/z' not in store
735
737
store ['x' ] = b'zzz'
736
- assert b'zzz' == store ['x' ]
738
+ assert b'zzz' == ensure_bytes ( store ['x' ])
737
739
assert 'x/y' not in store
738
740
739
741
# test __delitem__ overwrite level
@@ -819,7 +821,7 @@ def test_pickle_ext(self):
819
821
# check point to same underlying directory
820
822
assert 'xxx' not in store
821
823
store2 ['xxx' ] = b'yyy'
822
- assert b'yyy' == store ['xxx' ]
824
+ assert b'yyy' == ensure_bytes ( store ['xxx' ])
823
825
824
826
def test_setdel (self ):
825
827
store = self .create_store ()
0 commit comments