Skip to content

Commit 10a6118

Browse files
committed
enable LZMA tests under py27
1 parent 9a09cfb commit 10a6118

File tree

3 files changed

+47
-42
lines changed

3 files changed

+47
-42
lines changed

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ commands =
2020
py36: python -m doctest -o NORMALIZE_WHITESPACE -o ELLIPSIS docs/tutorial.rst docs/spec/v2.rst
2121
py36: flake8 --max-line-length=100 zarr
2222
deps =
23+
py27: backports.lzma
2324
-rrequirements_dev.txt
2425
# linux only
2526
-rrequirements_dev_optional.txt

zarr/tests/test_core.py

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,45 +1421,47 @@ def test_hexdigest(self):
14211421
assert '95d40c391f167db8b1290e3c39d9bf741edacdf6' == z.hexdigest()
14221422

14231423

1424-
# TODO rely on backports and remove the PY2 exclusion
1425-
if not PY2: # pragma: py2 no cover
1426-
1427-
from zarr.codecs import LZMA
1428-
1429-
class TestArrayWithLZMACompressor(TestArray):
1430-
1431-
def create_array(self, read_only=False, **kwargs):
1432-
store = dict()
1433-
compressor = LZMA(preset=1)
1434-
kwargs.setdefault('compressor', compressor)
1435-
cache_metadata = kwargs.pop('cache_metadata', True)
1436-
cache_attrs = kwargs.pop('cache_attrs', True)
1437-
init_array(store, **kwargs)
1438-
return Array(store, read_only=read_only, cache_metadata=cache_metadata,
1439-
cache_attrs=cache_attrs)
1440-
1441-
def test_hexdigest(self):
1442-
# Check basic 1-D array
1443-
z = self.create_array(shape=(1050,), chunks=100, dtype='i4')
1444-
assert '93ecaa530a1162a9d48a3c1dcee4586ccfc59bae' == z.hexdigest()
1445-
1446-
# Check basic 1-D array with different type
1447-
z = self.create_array(shape=(1050,), chunks=100, dtype='f4')
1448-
assert '04a9755a0cd638683531b7816c7fa4fbb6f577f2' == z.hexdigest()
1449-
1450-
# Check basic 2-D array
1451-
z = self.create_array(shape=(20, 35,), chunks=10, dtype='i4')
1452-
assert 'b93b163a21e8500519250a6defb821d03eb5d9e0' == z.hexdigest()
1453-
1454-
# Check basic 1-D array with some data
1455-
z = self.create_array(shape=(1050,), chunks=100, dtype='i4')
1456-
z[200:400] = np.arange(200, 400, dtype='i4')
1457-
assert 'cde499f3dc945b4e97197ff8e3cf8188a1262c35' == z.hexdigest()
1458-
1459-
# Check basic 1-D array with attributes
1460-
z = self.create_array(shape=(1050,), chunks=100, dtype='i4')
1461-
z.attrs['foo'] = 'bar'
1462-
assert 'e2cf3afbf66ad0e28a2b6b68b1b07817c69aaee2' == z.hexdigest()
1424+
try:
1425+
from numcodecs import LZMA
1426+
except ImportError: # pragma: no cover
1427+
LZMA = None
1428+
1429+
1430+
@unittest.skipIf(LZMA is None, 'LZMA codec not available')
1431+
class TestArrayWithLZMACompressor(TestArray):
1432+
1433+
def create_array(self, read_only=False, **kwargs):
1434+
store = dict()
1435+
compressor = LZMA(preset=1)
1436+
kwargs.setdefault('compressor', compressor)
1437+
cache_metadata = kwargs.pop('cache_metadata', True)
1438+
cache_attrs = kwargs.pop('cache_attrs', True)
1439+
init_array(store, **kwargs)
1440+
return Array(store, read_only=read_only, cache_metadata=cache_metadata,
1441+
cache_attrs=cache_attrs)
1442+
1443+
def test_hexdigest(self):
1444+
# Check basic 1-D array
1445+
z = self.create_array(shape=(1050,), chunks=100, dtype='i4')
1446+
assert '93ecaa530a1162a9d48a3c1dcee4586ccfc59bae' == z.hexdigest()
1447+
1448+
# Check basic 1-D array with different type
1449+
z = self.create_array(shape=(1050,), chunks=100, dtype='f4')
1450+
assert '04a9755a0cd638683531b7816c7fa4fbb6f577f2' == z.hexdigest()
1451+
1452+
# Check basic 2-D array
1453+
z = self.create_array(shape=(20, 35,), chunks=10, dtype='i4')
1454+
assert 'b93b163a21e8500519250a6defb821d03eb5d9e0' == z.hexdigest()
1455+
1456+
# Check basic 1-D array with some data
1457+
z = self.create_array(shape=(1050,), chunks=100, dtype='i4')
1458+
z[200:400] = np.arange(200, 400, dtype='i4')
1459+
assert 'cde499f3dc945b4e97197ff8e3cf8188a1262c35' == z.hexdigest()
1460+
1461+
# Check basic 1-D array with attributes
1462+
z = self.create_array(shape=(1050,), chunks=100, dtype='i4')
1463+
z.attrs['foo'] = 'bar'
1464+
assert 'e2cf3afbf66ad0e28a2b6b68b1b07817c69aaee2' == z.hexdigest()
14631465

14641466

14651467
class TestArrayWithFilters(TestArray):

zarr/tests/test_filters.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919
Blosc(),
2020
]
2121

22-
# TODO rely on backports and remove PY2 exclusion
23-
if not PY2: # pragma: py2 no cover
24-
from zarr.codecs import LZMA
22+
try:
23+
from numcodecs import LZMA
24+
except ImportError: # pragma: no cover
25+
LZMA = None
26+
else:
2527
compressors.append(LZMA())
2628

2729

0 commit comments

Comments
 (0)