Skip to content

Commit

Permalink
Move to have_X skip method for deps
Browse files Browse the repository at this point in the history
  • Loading branch information
joshmoore committed Feb 14, 2024
1 parent 827545d commit 195b447
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 37 deletions.
53 changes: 16 additions & 37 deletions zarr/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,14 @@
)
from zarr.tests.test_storage_v3 import DummyStorageTransfomer
from zarr.util import buffer_size
from zarr.tests.util import abs_container, skip_test_env_var, have_fsspec, mktemp
from zarr.tests.util import (
abs_container,
have_bsddb3,
have_lmdb,
have_sqlite3,
mktemp,
skip_test_env_var,
)
from zarr.types import DIMENSION_SEPARATOR

# noinspection PyMethodMayBeStatic
Expand Down Expand Up @@ -2018,7 +2025,7 @@ def expected(self):
]


@pytest.mark.skipif(have_fsspec is False, reason="needs fsspec")
@pytest.mark.skipif(have_bsddb3 is False, reason="needs bsddb3")
class TestArrayWithN5FSStore(TestArrayWithN5Store):
def create_store(self):
path = mkdtemp()
Expand All @@ -2038,13 +2045,9 @@ def test_nbytes_stored(self):
pass # not implemented


@pytest.mark.skipif(have_bsddb3 is False, reason="needs bsddb3")
class TestArrayWithDBMStoreBerkeleyDB(TestArray):
def __init__(self): # pragma: no cover
# Skip warning tests as well
pytest.importorskip("bsddb3")

def create_store(self):
bsddb3 = pytest.importorskip("bsddb3")
path = mktemp(suffix=".dbm")
atexit.register(os.remove, path)
store = DBMStore(path, flag="n", open=bsddb3.btopen)
Expand All @@ -2054,13 +2057,9 @@ def test_nbytes_stored(self):
pass # not implemented


@pytest.mark.skipif(have_lmdb is False, reason="needs lmdb")
class TestArrayWithLMDBStore(TestArray):
def __init__(self): # pragma: no cover
# Skip warning tests as well
pytest.importorskip("lmdb")

def create_store(self):
pytest.importorskip("lmdb")
path = mktemp(suffix=".lmdb")
atexit.register(atexit_rmtree, path)
store = LMDBStore(path, buffers=True)
Expand All @@ -2073,13 +2072,9 @@ def test_nbytes_stored(self):
pass # not implemented


@pytest.mark.skipif(have_lmdb is False, reason="needs lmdb")
class TestArrayWithLMDBStoreNoBuffers(TestArray):
def __init__(self): # pragma: no cover
# Skip warning tests as well
pytest.importorskip("lmdb")

def create_store(self):
pytest.importorskip("lmdb")
path = mktemp(suffix=".lmdb")
atexit.register(atexit_rmtree, path)
store = LMDBStore(path, buffers=False)
Expand All @@ -2089,13 +2084,9 @@ def test_nbytes_stored(self):
pass # not implemented


@pytest.mark.skipif(have_sqlite3 is False, reason="needs sqlite3")
class TestArrayWithSQLiteStore(TestArray):
def __init__(self): # pragma: no cover
# Skip warning tests as well
pytest.importorskip("sqlite3")

def create_store(self):
pytest.importorskip("sqlite3")
path = mktemp(suffix=".db")
atexit.register(atexit_rmtree, path)
store = SQLiteStore(path)
Expand Down Expand Up @@ -2774,13 +2765,9 @@ def test_nbytes_stored(self):


@pytest.mark.skipif(not v3_api_available, reason="V3 is disabled")
@pytest.mark.skipif(have_bsddb3 is False, reason="needs bsddb3")
class TestArrayWithDBMStoreV3BerkeleyDB(TestArrayV3):
def __init__(self): # pragma: no cover
# Skip warning tests as well
pytest.importorskip("bsddb3")

def create_store(self) -> DBMStoreV3:
bsddb3 = pytest.importorskip("bsddb3")
path = mktemp(suffix=".dbm")
atexit.register(os.remove, path)
store = DBMStoreV3(path, flag="n", open=bsddb3.btopen)
Expand All @@ -2791,15 +2778,11 @@ def test_nbytes_stored(self):


@pytest.mark.skipif(not v3_api_available, reason="V3 is disabled")
@pytest.mark.skipif(have_lmdb is False, reason="needs lmdb")
class TestArrayWithLMDBStoreV3(TestArrayV3):
lmdb_buffers = True

def __init__(self): # pragma: no cover
# Skip warning tests as well
pytest.importorskip("lmdb")

def create_store(self) -> LMDBStoreV3:
pytest.importorskip("lmdb")
path = mktemp(suffix=".lmdb")
atexit.register(atexit_rmtree, path)
store = LMDBStoreV3(path, buffers=self.lmdb_buffers)
Expand All @@ -2821,13 +2804,9 @@ def test_nbytes_stored(self):


@pytest.mark.skipif(not v3_api_available, reason="V3 is disabled")
@pytest.mark.skipif(have_sqlite3 is False, reason="needs sqlite3")
class TestArrayWithSQLiteStoreV3(TestArrayV3):
def __init__(self): # pragma: no cover
# Skip warning tests as well
pytest.importorskip("sqlite3")

def create_store(self):
pytest.importorskip("sqlite3")
path = mktemp(suffix=".db")
atexit.register(atexit_rmtree, path)
store = SQLiteStoreV3(path)
Expand Down
24 changes: 24 additions & 0 deletions zarr/tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,30 @@ def skip_test_env_var(name):
have_fsspec = False


try:
import bsddb3 # noqa: F401

have_bsddb3 = True
except ImportError: # pragma: no cover
have_bsddb3 = False


try:
import lmdb # noqa: F401

have_lmdb = True
except ImportError: # pragma: no cover
have_lmdb = False


try:
import sqlite3 # noqa: F401

have_sqlite3 = True
except ImportError: # pragma: no cover
have_sqlite3 = False


def abs_container():
from azure.core.exceptions import ResourceExistsError
import azure.storage.blob as asb
Expand Down

0 comments on commit 195b447

Please sign in to comment.