Skip to content

Commit 4f00646

Browse files
authored
Test Array storing different compressors, endian and attributes (#405)
* Test correct handling of endian data Try storing data as both big endian and little endian. Ensure that the data stored remains equal regardless of the stored endian order. * Test store's handling of Array attributes Make sure that the JSON contains the keys added to the Array attributes. * Add test of multiple compressors with Arrays
1 parent 569915d commit 4f00646

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

zarr/tests/test_core.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import unittest
44
from tempfile import mkdtemp, mktemp
55
import atexit
6+
import json
67
import shutil
78
import pickle
89
import os
@@ -20,8 +21,9 @@
2021
from zarr.core import Array
2122
from zarr.errors import PermissionError
2223
from zarr.compat import PY2, text_type, binary_type, zip_longest
24+
from zarr.meta import ensure_str
2325
from zarr.util import buffer_size
24-
from numcodecs import (Delta, FixedScaleOffset, Zlib, Blosc, BZ2, MsgPack, Pickle,
26+
from numcodecs import (Delta, FixedScaleOffset, LZ4, GZip, Zlib, Blosc, BZ2, MsgPack, Pickle,
2527
Categorize, JSON, VLenUTF8, VLenBytes, VLenArray)
2628
from numcodecs.compat import ensure_bytes, ensure_ndarray
2729
from numcodecs.tests.common import greetings
@@ -1215,6 +1217,39 @@ def test_iter(self):
12151217
for expect, actual in zip_longest(a, z):
12161218
assert_array_equal(expect, actual)
12171219

1220+
def test_compressors(self):
1221+
compressors = [
1222+
None, BZ2(), Blosc(), LZ4(), Zlib(), GZip()
1223+
]
1224+
if LZMA:
1225+
compressors.append(LZMA())
1226+
for compressor in compressors:
1227+
a = self.create_array(shape=1000, chunks=100, compressor=compressor)
1228+
a[0:100] = 1
1229+
assert np.all(a[0:100] == 1)
1230+
a[:] = 1
1231+
assert np.all(a[:] == 1)
1232+
1233+
def test_endian(self):
1234+
dtype = np.dtype('float32')
1235+
a1 = self.create_array(shape=1000, chunks=100, dtype=dtype.newbyteorder('<'))
1236+
a1[:] = 1
1237+
x1 = a1[:]
1238+
a2 = self.create_array(shape=1000, chunks=100, dtype=dtype.newbyteorder('>'))
1239+
a2[:] = 1
1240+
x2 = a2[:]
1241+
assert_array_equal(x1, x2)
1242+
1243+
def test_attributes(self):
1244+
a = self.create_array(shape=10, chunks=10, dtype='i8')
1245+
a.attrs['foo'] = 'bar'
1246+
attrs = json.loads(ensure_str(a.store[a.attrs.key]))
1247+
assert 'foo' in attrs and attrs['foo'] == 'bar'
1248+
a.attrs['bar'] = 'foo'
1249+
attrs = json.loads(ensure_str(a.store[a.attrs.key]))
1250+
assert 'foo' in attrs and attrs['foo'] == 'bar'
1251+
assert 'bar' in attrs and attrs['bar'] == 'foo'
1252+
12181253

12191254
class TestArrayWithPath(TestArray):
12201255

0 commit comments

Comments
 (0)