From 195b447d9be108642e52f671012cbaf2de65bde6 Mon Sep 17 00:00:00 2001 From: Josh Moore Date: Wed, 14 Feb 2024 13:18:12 +0100 Subject: [PATCH] Move to have_X skip method for deps --- zarr/tests/test_core.py | 53 +++++++++++++---------------------------- zarr/tests/util.py | 24 +++++++++++++++++++ 2 files changed, 40 insertions(+), 37 deletions(-) diff --git a/zarr/tests/test_core.py b/zarr/tests/test_core.py index 85f55b7a15..7dec1cc224 100644 --- a/zarr/tests/test_core.py +++ b/zarr/tests/test_core.py @@ -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 @@ -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() @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/zarr/tests/util.py b/zarr/tests/util.py index b4f00f703d..b3c3249cab 100644 --- a/zarr/tests/util.py +++ b/zarr/tests/util.py @@ -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