Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use pytest.importorskip in tests #492

Merged
merged 3 commits into from
Nov 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ Upcoming Release
* Removed support for Python 2.
By :user:`jhamman`; :issue:`393`, :issue:`470`.

* Updates tests to use ``pytest.importorskip``.
By :user:`James Bourbeau <jrbourbeau>`; :issue:`492`

* Update ``DirectoryStore`` to create files with more permissive permissions.
By :user:`Eduardo Gonzalez <eddienko>` and :user:`James Bourbeau <jrbourbeau>`; :issue:`493`

Expand Down
4 changes: 1 addition & 3 deletions zarr/tests/test_convenience.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,14 +654,14 @@ def test_logging(self):


def temp_h5f():
h5py = pytest.importorskip("h5py")
fn = tempfile.mktemp()
atexit.register(os.remove, fn)
h5f = h5py.File(fn, mode='w')
atexit.register(lambda v: v.close(), h5f)
return h5f


@unittest.skipIf(h5py is None, 'h5py is not installed')
class TestCopyHDF5ToZarr(TestCopy):

def __init__(self, *args, **kwargs):
Expand All @@ -672,7 +672,6 @@ def __init__(self, *args, **kwargs):
self.new_dest = group


@unittest.skipIf(h5py is None, 'h5py is not installed')
class TestCopyZarrToHDF5(TestCopy):

def __init__(self, *args, **kwargs):
Expand All @@ -683,7 +682,6 @@ def __init__(self, *args, **kwargs):
self.new_dest = temp_h5f


@unittest.skipIf(h5py is None, 'h5py is not installed')
class TestCopyHDF5ToHDF5(TestCopy):

def __init__(self, *args, **kwargs):
Expand Down
42 changes: 7 additions & 35 deletions zarr/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,7 @@
LRUStoreCache, NestedDirectoryStore, SQLiteStore,
atexit_rmglob, atexit_rmtree, init_array, init_group)
from zarr.util import buffer_size

try:
import azure.storage.blob as asb
except ImportError: # pragma: no cover
asb = None


# also check for environment variables indicating whether tests requiring
# services should be run
ZARR_TEST_ABS = os.environ.get('ZARR_TEST_ABS', '0')
from zarr.tests.util import skip_test_env_var


# noinspection PyMethodMayBeStatic
Expand Down Expand Up @@ -1404,13 +1395,12 @@ def test_nbytes_stored(self):
assert expect_nbytes_stored == z.nbytes_stored


@pytest.mark.skipif(asb is None or ZARR_TEST_ABS == '0',
reason="azure-blob-storage could not be imported or tests not"
"enabled via environment variable")
@skip_test_env_var("ZARR_TEST_ABS")
class TestArrayWithABSStore(TestArray):

@staticmethod
def absstore():
asb = pytest.importorskip("azure.storage.blob")
blob_client = asb.BlockBlobService(is_emulated=True)
blob_client.delete_container('test')
blob_client.create_container('test')
Expand Down Expand Up @@ -1737,17 +1727,11 @@ def test_nbytes_stored(self):
pass # not implemented


try:
import bsddb3
except ImportError: # pragma: no cover
bsddb3 = None


@unittest.skipIf(bsddb3 is None, 'bsddb3 is not installed')
class TestArrayWithDBMStoreBerkeleyDB(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
bsddb3 = pytest.importorskip("bsddb3")
path = mktemp(suffix='.dbm')
atexit.register(os.remove, path)
store = DBMStore(path, flag='n', open=bsddb3.btopen)
Expand All @@ -1762,17 +1746,11 @@ def test_nbytes_stored(self):
pass # not implemented


try:
import lmdb
except ImportError: # pragma: no cover
lmdb = None


@unittest.skipIf(lmdb is None, 'lmdb is not installed')
class TestArrayWithLMDBStore(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
pytest.importorskip("lmdb")
path = mktemp(suffix='.lmdb')
atexit.register(atexit_rmtree, path)
store = LMDBStore(path, buffers=True)
Expand All @@ -1790,11 +1768,11 @@ def test_nbytes_stored(self):
pass # not implemented


@unittest.skipIf(lmdb is None, 'lmdb is not installed')
class TestArrayWithLMDBStoreNoBuffers(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
pytest.importorskip("lmdb")
path = mktemp(suffix='.lmdb')
atexit.register(atexit_rmtree, path)
store = LMDBStore(path, buffers=False)
Expand All @@ -1809,17 +1787,11 @@ def test_nbytes_stored(self):
pass # not implemented


try:
import sqlite3
except ImportError: # pragma: no cover
sqlite3 = None


@unittest.skipIf(sqlite3 is None, 'python built without sqlite')
class TestArrayWithSQLiteStore(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
pytest.importorskip("sqlite3")
path = mktemp(suffix='.db')
atexit.register(atexit_rmtree, path)
store = SQLiteStore(path)
Expand Down
40 changes: 6 additions & 34 deletions zarr/tests/test_hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,7 @@
atexit_rmtree, group_meta_key, init_array,
init_group)
from zarr.util import InfoReporter

try:
import azure.storage.blob as asb
except ImportError: # pragma: no cover
asb = None


# also check for environment variables indicating whether tests requiring
# services should be run
ZARR_TEST_ABS = os.environ.get('ZARR_TEST_ABS', '0')
from zarr.tests.util import skip_test_env_var


# noinspection PyStatementEffect
Expand Down Expand Up @@ -887,13 +878,12 @@ def create_store():
return store, None


@pytest.mark.skipif(asb is None or ZARR_TEST_ABS == '0',
reason="azure-blob-storage could not be imported or tests not enabled"
"via environment variable")
@skip_test_env_var("ZARR_TEST_ABS")
class TestGroupWithABSStore(TestGroup):

@staticmethod
def create_store():
asb = pytest.importorskip("azure.storage.blob")
blob_client = asb.BlockBlobService(is_emulated=True)
blob_client.delete_container('test')
blob_client.create_container('test')
Expand Down Expand Up @@ -933,50 +923,32 @@ def create_store():
return store, None


try:
import bsddb3
except ImportError: # pragma: no cover
bsddb3 = None


@unittest.skipIf(bsddb3 is None, 'bsddb3 is not installed')
class TestGroupWithDBMStoreBerkeleyDB(TestGroup):

@staticmethod
def create_store():
bsddb3 = pytest.importorskip("bsddb3")
path = tempfile.mktemp(suffix='.dbm')
atexit.register(os.remove, path)
store = DBMStore(path, flag='n', open=bsddb3.btopen)
return store, None


try:
import lmdb
except ImportError: # pragma: no cover
lmdb = None


@unittest.skipIf(lmdb is None, 'lmdb is not installed')
class TestGroupWithLMDBStore(TestGroup):

@staticmethod
def create_store():
pytest.importorskip("lmdb")
path = tempfile.mktemp(suffix='.lmdb')
atexit.register(atexit_rmtree, path)
store = LMDBStore(path)
return store, None


try:
import sqlite3
except ImportError: # pragma: no cover
sqlite3 = None


@unittest.skipIf(sqlite3 is None, 'python built without sqlite')
class TestGroupWithSQLiteStore(TestGroup):

def create_store(self):
pytest.importorskip("sqlite3")
path = tempfile.mktemp(suffix='.db')
atexit.register(atexit_rmtree, path)
store = SQLiteStore(path)
Expand Down
Loading