Skip to content

Commit 14e9312

Browse files
committed
use unittest.skipIf
1 parent fe3a67e commit 14e9312

File tree

4 files changed

+143
-145
lines changed

4 files changed

+143
-145
lines changed

zarr/tests/test_convenience.py

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -579,38 +579,42 @@ def test_logging(self):
579579
h5py = None
580580

581581

582-
if h5py is not None:
582+
def temp_h5f():
583+
fn = tempfile.mktemp()
584+
atexit.register(os.remove, fn)
585+
h5f = h5py.File(fn, mode='w')
586+
atexit.register(lambda v: v.close(), h5f)
587+
return h5f
583588

584-
def temp_h5f():
585-
fn = tempfile.mktemp()
586-
atexit.register(os.remove, fn)
587-
h5f = h5py.File(fn, mode='w')
588-
atexit.register(lambda v: v.close(), h5f)
589-
return h5f
590-
591-
class TestCopyHDF5ToZarr(TestCopy):
592-
593-
def __init__(self, *args, **kwargs):
594-
super(TestCopyHDF5ToZarr, self).__init__(*args, **kwargs)
595-
self.source_h5py = True
596-
self.dest_h5py = False
597-
self.new_source = temp_h5f
598-
self.new_dest = group
599-
600-
class TestCopyZarrToHDF5(TestCopy):
601-
602-
def __init__(self, *args, **kwargs):
603-
super(TestCopyZarrToHDF5, self).__init__(*args, **kwargs)
604-
self.source_h5py = False
605-
self.dest_h5py = True
606-
self.new_source = group
607-
self.new_dest = temp_h5f
608-
609-
class TestCopyHDF5ToHDF5(TestCopy):
610-
611-
def __init__(self, *args, **kwargs):
612-
super(TestCopyHDF5ToHDF5, self).__init__(*args, **kwargs)
613-
self.source_h5py = True
614-
self.dest_h5py = True
615-
self.new_source = temp_h5f
616-
self.new_dest = temp_h5f
589+
590+
@unittest.skipIf(h5py is None, 'h5py is not installed')
591+
class TestCopyHDF5ToZarr(TestCopy):
592+
593+
def __init__(self, *args, **kwargs):
594+
super(TestCopyHDF5ToZarr, self).__init__(*args, **kwargs)
595+
self.source_h5py = True
596+
self.dest_h5py = False
597+
self.new_source = temp_h5f
598+
self.new_dest = group
599+
600+
601+
@unittest.skipIf(h5py is None, 'h5py is not installed')
602+
class TestCopyZarrToHDF5(TestCopy):
603+
604+
def __init__(self, *args, **kwargs):
605+
super(TestCopyZarrToHDF5, self).__init__(*args, **kwargs)
606+
self.source_h5py = False
607+
self.dest_h5py = True
608+
self.new_source = group
609+
self.new_dest = temp_h5f
610+
611+
612+
@unittest.skipIf(h5py is None, 'h5py is not installed')
613+
class TestCopyHDF5ToHDF5(TestCopy):
614+
615+
def __init__(self, *args, **kwargs):
616+
super(TestCopyHDF5ToHDF5, self).__init__(*args, **kwargs)
617+
self.source_h5py = True
618+
self.dest_h5py = True
619+
self.new_source = temp_h5f
620+
self.new_dest = temp_h5f

zarr/tests/test_core.py

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,24 +1251,23 @@ def test_nbytes_stored(self):
12511251
bsddb3 = None
12521252

12531253

1254-
if bsddb3 is not None:
1254+
@unittest.skipIf(bsddb3 is None, 'bsddb3 is not installed')
1255+
class TestArrayWithDBMStoreBerkeleyDB(TestArray):
12551256

1256-
class TestArrayWithDBMStoreBerkeleyDB(TestArray):
1257-
1258-
@staticmethod
1259-
def create_array(read_only=False, **kwargs):
1260-
path = mktemp(suffix='.dbm')
1261-
atexit.register(os.remove, path)
1262-
store = DBMStore(path, flag='n', open=bsddb3.btopen)
1263-
cache_metadata = kwargs.pop('cache_metadata', True)
1264-
cache_attrs = kwargs.pop('cache_attrs', True)
1265-
kwargs.setdefault('compressor', Zlib(1))
1266-
init_array(store, **kwargs)
1267-
return Array(store, read_only=read_only, cache_metadata=cache_metadata,
1268-
cache_attrs=cache_attrs)
1257+
@staticmethod
1258+
def create_array(read_only=False, **kwargs):
1259+
path = mktemp(suffix='.dbm')
1260+
atexit.register(os.remove, path)
1261+
store = DBMStore(path, flag='n', open=bsddb3.btopen)
1262+
cache_metadata = kwargs.pop('cache_metadata', True)
1263+
cache_attrs = kwargs.pop('cache_attrs', True)
1264+
kwargs.setdefault('compressor', Zlib(1))
1265+
init_array(store, **kwargs)
1266+
return Array(store, read_only=read_only, cache_metadata=cache_metadata,
1267+
cache_attrs=cache_attrs)
12691268

1270-
def test_nbytes_stored(self):
1271-
pass # not implemented
1269+
def test_nbytes_stored(self):
1270+
pass # not implemented
12721271

12731272

12741273
try:
@@ -1277,41 +1276,42 @@ def test_nbytes_stored(self):
12771276
lmdb = None
12781277

12791278

1280-
if lmdb is not None:
1279+
@unittest.skipIf(lmdb is None, 'lmdb is not installed')
1280+
class TestArrayWithLMDBStore(TestArray):
12811281

1282-
class TestArrayWithLMDBStore(TestArray):
1282+
@staticmethod
1283+
def create_array(read_only=False, **kwargs):
1284+
path = mktemp(suffix='.lmdb')
1285+
atexit.register(atexit_rmtree, path)
1286+
store = LMDBStore(path, buffers=True)
1287+
cache_metadata = kwargs.pop('cache_metadata', True)
1288+
cache_attrs = kwargs.pop('cache_attrs', True)
1289+
kwargs.setdefault('compressor', Zlib(1))
1290+
init_array(store, **kwargs)
1291+
return Array(store, read_only=read_only, cache_metadata=cache_metadata,
1292+
cache_attrs=cache_attrs)
12831293

1284-
@staticmethod
1285-
def create_array(read_only=False, **kwargs):
1286-
path = mktemp(suffix='.lmdb')
1287-
atexit.register(atexit_rmtree, path)
1288-
store = LMDBStore(path, buffers=True)
1289-
cache_metadata = kwargs.pop('cache_metadata', True)
1290-
cache_attrs = kwargs.pop('cache_attrs', True)
1291-
kwargs.setdefault('compressor', Zlib(1))
1292-
init_array(store, **kwargs)
1293-
return Array(store, read_only=read_only, cache_metadata=cache_metadata,
1294-
cache_attrs=cache_attrs)
1294+
def test_nbytes_stored(self):
1295+
pass # not implemented
12951296

1296-
def test_nbytes_stored(self):
1297-
pass # not implemented
12981297

1299-
class TestArrayWithLMDBStoreNoBuffers(TestArray):
1298+
@unittest.skipIf(lmdb is None, 'lmdb is not installed')
1299+
class TestArrayWithLMDBStoreNoBuffers(TestArray):
13001300

1301-
@staticmethod
1302-
def create_array(read_only=False, **kwargs):
1303-
path = mktemp(suffix='.lmdb')
1304-
atexit.register(atexit_rmtree, path)
1305-
store = LMDBStore(path, buffers=False)
1306-
cache_metadata = kwargs.pop('cache_metadata', True)
1307-
cache_attrs = kwargs.pop('cache_attrs', True)
1308-
kwargs.setdefault('compressor', Zlib(1))
1309-
init_array(store, **kwargs)
1310-
return Array(store, read_only=read_only, cache_metadata=cache_metadata,
1311-
cache_attrs=cache_attrs)
1301+
@staticmethod
1302+
def create_array(read_only=False, **kwargs):
1303+
path = mktemp(suffix='.lmdb')
1304+
atexit.register(atexit_rmtree, path)
1305+
store = LMDBStore(path, buffers=False)
1306+
cache_metadata = kwargs.pop('cache_metadata', True)
1307+
cache_attrs = kwargs.pop('cache_attrs', True)
1308+
kwargs.setdefault('compressor', Zlib(1))
1309+
init_array(store, **kwargs)
1310+
return Array(store, read_only=read_only, cache_metadata=cache_metadata,
1311+
cache_attrs=cache_attrs)
13121312

1313-
def test_nbytes_stored(self):
1314-
pass # not implemented
1313+
def test_nbytes_stored(self):
1314+
pass # not implemented
13151315

13161316

13171317
class TestArrayWithNoCompressor(TestArray):

zarr/tests/test_hierarchy.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -892,16 +892,15 @@ def create_store():
892892
bsddb3 = None
893893

894894

895-
if bsddb3 is not None:
895+
@unittest.skipIf(bsddb3 is None, 'bsddb3 is not installed')
896+
class TestGroupWithDBMStoreBerkeleyDB(TestGroup):
896897

897-
class TestGroupWithDBMStoreBerkeleyDB(TestGroup):
898-
899-
@staticmethod
900-
def create_store():
901-
path = tempfile.mktemp(suffix='.dbm')
902-
atexit.register(os.remove, path)
903-
store = DBMStore(path, flag='n', open=bsddb3.btopen)
904-
return store, None
898+
@staticmethod
899+
def create_store():
900+
path = tempfile.mktemp(suffix='.dbm')
901+
atexit.register(os.remove, path)
902+
store = DBMStore(path, flag='n', open=bsddb3.btopen)
903+
return store, None
905904

906905

907906
try:
@@ -910,16 +909,15 @@ def create_store():
910909
lmdb = None
911910

912911

913-
if lmdb is not None:
912+
@unittest.skipIf(lmdb is None, 'lmdb is not installed')
913+
class TestGroupWithLMDBStore(TestGroup):
914914

915-
class TestGroupWithLMDBStore(TestGroup):
916-
917-
@staticmethod
918-
def create_store():
919-
path = tempfile.mktemp(suffix='.lmdb')
920-
atexit.register(atexit_rmtree, path)
921-
store = LMDBStore(path)
922-
return store, None
915+
@staticmethod
916+
def create_store():
917+
path = tempfile.mktemp(suffix='.lmdb')
918+
atexit.register(atexit_rmtree, path)
919+
store = LMDBStore(path)
920+
return store, None
923921

924922

925923
class TestGroupWithChunkStore(TestGroup):

zarr/tests/test_storage.py

Lines changed: 44 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ def test_writeable_values(self):
9090
store = self.create_store()
9191

9292
# __setitem__ should accept any value that implements buffer interface
93-
store['foo'] = b'bar'
94-
store['foo'] = bytearray(b'bar')
95-
store['foo'] = array.array('B', b'bar')
96-
store['foo'] = np.frombuffer(b'bar', dtype='u1')
93+
store['foo1'] = b'bar'
94+
store['foo2'] = bytearray(b'bar')
95+
store['foo3'] = array.array('B', b'bar')
96+
store['foo4'] = np.frombuffer(b'bar', dtype='u1')
9797

9898
def test_update(self):
9999
store = self.create_store()
@@ -777,32 +777,30 @@ def create_store(self):
777777
gdbm = None
778778

779779

780-
if gdbm is not None:
781-
782-
class TestDBMStoreGnu(TestDBMStore):
780+
@unittest.skipIf(gdbm is None, 'gdbm is not installed')
781+
class TestDBMStoreGnu(TestDBMStore):
783782

784-
def create_store(self):
785-
path = tempfile.mktemp(suffix='.gdbm')
786-
atexit.register(os.remove, path)
787-
store = DBMStore(path, flag='n', open=gdbm.open, write_lock=False)
788-
return store
783+
def create_store(self):
784+
path = tempfile.mktemp(suffix='.gdbm')
785+
atexit.register(os.remove, path)
786+
store = DBMStore(path, flag='n', open=gdbm.open, write_lock=False)
787+
return store
789788

790789

791-
if not PY2:
790+
if not PY2: # pragma: py2 no cover
792791
try:
793792
import dbm.ndbm as ndbm
794793
except ImportError: # pragma: no cover
795794
ndbm = None
796795

797-
if ndbm is not None:
798-
799-
class TestDBMStoreNDBM(TestDBMStore):
796+
@unittest.skipIf(ndbm is None, 'ndbm is not installed')
797+
class TestDBMStoreNDBM(TestDBMStore):
800798

801-
def create_store(self):
802-
path = tempfile.mktemp(suffix='.ndbm')
803-
atexit.register(atexit_rmglob, path + '*')
804-
store = DBMStore(path, flag='n', open=ndbm.open)
805-
return store
799+
def create_store(self):
800+
path = tempfile.mktemp(suffix='.ndbm')
801+
atexit.register(atexit_rmglob, path + '*')
802+
store = DBMStore(path, flag='n', open=ndbm.open)
803+
return store
806804

807805

808806
try:
@@ -811,15 +809,14 @@ def create_store(self):
811809
bsddb3 = None
812810

813811

814-
if bsddb3 is not None:
812+
@unittest.skipIf(bsddb3 is None, 'bsddb3 is not installed')
813+
class TestDBMStoreBerkeleyDB(TestDBMStore):
815814

816-
class TestDBMStoreBerkeleyDB(TestDBMStore):
817-
818-
def create_store(self):
819-
path = tempfile.mktemp(suffix='.dbm')
820-
atexit.register(os.remove, path)
821-
store = DBMStore(path, flag='n', open=bsddb3.btopen, write_lock=False)
822-
return store
815+
def create_store(self):
816+
path = tempfile.mktemp(suffix='.dbm')
817+
atexit.register(os.remove, path)
818+
store = DBMStore(path, flag='n', open=bsddb3.btopen, write_lock=False)
819+
return store
823820

824821

825822
try:
@@ -828,27 +825,26 @@ def create_store(self):
828825
lmdb = None
829826

830827

831-
if lmdb is not None:
832-
833-
class TestLMDBStore(StoreTests, unittest.TestCase):
828+
@unittest.skipIf(lmdb is None, 'lmdb is not installed')
829+
class TestLMDBStore(StoreTests, unittest.TestCase):
834830

835-
def create_store(self):
836-
path = tempfile.mktemp(suffix='.lmdb')
837-
atexit.register(atexit_rmtree, path)
838-
if PY2: # pragma: py3 no cover
839-
# don't use buffers, otherwise would have to rewrite tests as bytes and
840-
# buffer don't compare equal in PY2
841-
buffers = False
842-
else: # pragma: py2 no cover
843-
buffers = True
844-
store = LMDBStore(path, buffers=buffers)
845-
return store
831+
def create_store(self):
832+
path = tempfile.mktemp(suffix='.lmdb')
833+
atexit.register(atexit_rmtree, path)
834+
if PY2: # pragma: py3 no cover
835+
# don't use buffers, otherwise would have to rewrite tests as bytes and
836+
# buffer don't compare equal in PY2
837+
buffers = False
838+
else: # pragma: py2 no cover
839+
buffers = True
840+
store = LMDBStore(path, buffers=buffers)
841+
return store
846842

847-
def test_context_manager(self):
848-
with self.create_store() as store:
849-
store['foo'] = b'bar'
850-
store['baz'] = b'qux'
851-
assert 2 == len(store)
843+
def test_context_manager(self):
844+
with self.create_store() as store:
845+
store['foo'] = b'bar'
846+
store['baz'] = b'qux'
847+
assert 2 == len(store)
852848

853849

854850
class TestLRUStoreCache(StoreTests, unittest.TestCase):

0 commit comments

Comments
 (0)