From 2178321208736b4af024293fd557eda54ce25fa0 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Tue, 12 Nov 2024 11:35:46 +0100 Subject: [PATCH] Exclude tests from coverage --- numcodecs/tests/common.py | 10 +++++----- numcodecs/tests/package_with_entrypoint/__init__.py | 4 ++-- numcodecs/tests/test_blosc.py | 2 +- numcodecs/tests/test_entrypoints_backport.py | 2 +- numcodecs/tests/test_lz4.py | 2 +- numcodecs/tests/test_lzma.py | 2 +- numcodecs/tests/test_msgpacks.py | 2 +- numcodecs/tests/test_pcodec.py | 2 +- numcodecs/tests/test_registry.py | 2 +- numcodecs/tests/test_shuffle.py | 2 +- numcodecs/tests/test_vlen_array.py | 2 +- numcodecs/tests/test_vlen_bytes.py | 2 +- numcodecs/tests/test_vlen_utf8.py | 2 +- numcodecs/tests/test_zarr3.py | 2 +- numcodecs/tests/test_zarr3_import.py | 2 +- numcodecs/tests/test_zfpy.py | 2 +- numcodecs/tests/test_zstd.py | 2 +- pyproject.toml | 5 +++++ 18 files changed, 27 insertions(+), 22 deletions(-) diff --git a/numcodecs/tests/common.py b/numcodecs/tests/common.py index 2de81052..d4e295e7 100644 --- a/numcodecs/tests/common.py +++ b/numcodecs/tests/common.py @@ -249,13 +249,13 @@ def check_backwards_compatibility(codec_id, arrays, codecs, precision=None, pref fixture_dir = os.path.join('fixture', codec_id, prefix) else: fixture_dir = os.path.join('fixture', codec_id) - if not os.path.exists(fixture_dir): # pragma: no cover + if not os.path.exists(fixture_dir): os.makedirs(fixture_dir) # save fixture data for i, arr in enumerate(arrays): arr_fn = os.path.join(fixture_dir, f'array.{i:02d}.npy') - if not os.path.exists(arr_fn): # pragma: no cover + if not os.path.exists(arr_fn): np.save(arr_fn, arr) # load fixture data @@ -275,13 +275,13 @@ def check_backwards_compatibility(codec_id, arrays, codecs, precision=None, pref # setup a directory to hold encoded data codec_dir = os.path.join(fixture_dir, f'codec.{j:02d}') - if not os.path.exists(codec_dir): # pragma: no cover + if not os.path.exists(codec_dir): os.makedirs(codec_dir) # file with codec configuration information codec_fn = os.path.join(codec_dir, 'config.json') # one time save config - if not os.path.exists(codec_fn): # pragma: no cover + if not os.path.exists(codec_fn): with open(codec_fn, mode='w') as cf: _json.dump(codec.get_config(), cf, sort_keys=True, indent=4) # load config and compare with expectation @@ -292,7 +292,7 @@ def check_backwards_compatibility(codec_id, arrays, codecs, precision=None, pref enc_fn = os.path.join(codec_dir, f'encoded.{i:02d}.dat') # one time encode and save array - if not os.path.exists(enc_fn): # pragma: no cover + if not os.path.exists(enc_fn): enc = codec.encode(arr) enc = ensure_bytes(enc) with open(enc_fn, mode='wb') as ef: diff --git a/numcodecs/tests/package_with_entrypoint/__init__.py b/numcodecs/tests/package_with_entrypoint/__init__.py index fddf4347..b9f48b24 100644 --- a/numcodecs/tests/package_with_entrypoint/__init__.py +++ b/numcodecs/tests/package_with_entrypoint/__init__.py @@ -4,8 +4,8 @@ class TestCodec(Codec): codec_id = "test" - def encode(self, buf): # pragma: no cover + def encode(self, buf): pass - def decode(self, buf, out=None): # pragma: no cover + def decode(self, buf, out=None): pass diff --git a/numcodecs/tests/test_blosc.py b/numcodecs/tests/test_blosc.py index 95fd4cf1..70eb2a6b 100644 --- a/numcodecs/tests/test_blosc.py +++ b/numcodecs/tests/test_blosc.py @@ -7,7 +7,7 @@ try: from numcodecs import blosc from numcodecs.blosc import Blosc -except ImportError: # pragma: no cover +except ImportError: pytest.skip("numcodecs.blosc not available", allow_module_level=True) diff --git a/numcodecs/tests/test_entrypoints_backport.py b/numcodecs/tests/test_entrypoints_backport.py index 7e1c32bc..8e668ba0 100644 --- a/numcodecs/tests/test_entrypoints_backport.py +++ b/numcodecs/tests/test_entrypoints_backport.py @@ -8,7 +8,7 @@ import numcodecs.registry importlib_spec = importlib.util.find_spec("importlib_metadata") -if importlib_spec is None or importlib_spec.loader is None: # pragma: no cover +if importlib_spec is None or importlib_spec.loader is None: pytest.skip( "This test module requires importlib_metadata to be installed", allow_module_level=True, diff --git a/numcodecs/tests/test_lz4.py b/numcodecs/tests/test_lz4.py index 82af464a..efff9715 100644 --- a/numcodecs/tests/test_lz4.py +++ b/numcodecs/tests/test_lz4.py @@ -5,7 +5,7 @@ try: from numcodecs.lz4 import LZ4 -except ImportError: # pragma: no cover +except ImportError: pytest.skip("numcodecs.lz4 not available", allow_module_level=True) diff --git a/numcodecs/tests/test_lzma.py b/numcodecs/tests/test_lzma.py index d93aecfd..9591065d 100644 --- a/numcodecs/tests/test_lzma.py +++ b/numcodecs/tests/test_lzma.py @@ -7,7 +7,7 @@ try: # noinspection PyProtectedMember from numcodecs.lzma import LZMA, _lzma -except ImportError as e: # pragma: no cover +except ImportError as e: raise unittest.SkipTest("LZMA not available") from e diff --git a/numcodecs/tests/test_msgpacks.py b/numcodecs/tests/test_msgpacks.py index 4f877845..3ca2747a 100644 --- a/numcodecs/tests/test_msgpacks.py +++ b/numcodecs/tests/test_msgpacks.py @@ -5,7 +5,7 @@ try: from numcodecs.msgpacks import MsgPack -except ImportError as e: # pragma: no cover +except ImportError as e: raise unittest.SkipTest("msgpack not available") from e diff --git a/numcodecs/tests/test_pcodec.py b/numcodecs/tests/test_pcodec.py index c10549bd..c64757f4 100644 --- a/numcodecs/tests/test_pcodec.py +++ b/numcodecs/tests/test_pcodec.py @@ -6,7 +6,7 @@ try: # initializing codec triggers ImportError PCodec() -except ImportError: # pragma: no cover +except ImportError: pytest.skip("pcodec not available", allow_module_level=True) from numcodecs.tests.common import ( diff --git a/numcodecs/tests/test_registry.py b/numcodecs/tests/test_registry.py index 4a0ba463..f956a3c4 100644 --- a/numcodecs/tests/test_registry.py +++ b/numcodecs/tests/test_registry.py @@ -39,4 +39,4 @@ def test_all_classes_registered(): ) if missing: - raise Exception(f"these codecs are missing: {missing}") # pragma: no cover + raise Exception(f"these codecs are missing: {missing}") diff --git a/numcodecs/tests/test_shuffle.py b/numcodecs/tests/test_shuffle.py index 1194e598..25f7d26c 100644 --- a/numcodecs/tests/test_shuffle.py +++ b/numcodecs/tests/test_shuffle.py @@ -6,7 +6,7 @@ try: from numcodecs.shuffle import Shuffle -except ImportError: # pragma: no cover +except ImportError: pytest.skip("numcodecs.shuffle not available", allow_module_level=True) diff --git a/numcodecs/tests/test_vlen_array.py b/numcodecs/tests/test_vlen_array.py index 79d6be42..136c77a7 100644 --- a/numcodecs/tests/test_vlen_array.py +++ b/numcodecs/tests/test_vlen_array.py @@ -5,7 +5,7 @@ try: from numcodecs.vlen import VLenArray -except ImportError as e: # pragma: no cover +except ImportError as e: raise unittest.SkipTest("vlen-array not available") from e from numcodecs.tests.common import ( assert_array_items_equal, diff --git a/numcodecs/tests/test_vlen_bytes.py b/numcodecs/tests/test_vlen_bytes.py index 3546dbaa..a9fb2339 100644 --- a/numcodecs/tests/test_vlen_bytes.py +++ b/numcodecs/tests/test_vlen_bytes.py @@ -5,7 +5,7 @@ try: from numcodecs.vlen import VLenBytes -except ImportError as e: # pragma: no cover +except ImportError as e: raise unittest.SkipTest("vlen-bytes not available") from e from numcodecs.tests.common import ( assert_array_items_equal, diff --git a/numcodecs/tests/test_vlen_utf8.py b/numcodecs/tests/test_vlen_utf8.py index 514c7dc1..737fd240 100644 --- a/numcodecs/tests/test_vlen_utf8.py +++ b/numcodecs/tests/test_vlen_utf8.py @@ -5,7 +5,7 @@ try: from numcodecs.vlen import VLenUTF8 -except ImportError as e: # pragma: no cover +except ImportError as e: raise unittest.SkipTest("vlen-utf8 not available") from e from numcodecs.tests.common import ( assert_array_items_equal, diff --git a/numcodecs/tests/test_zarr3.py b/numcodecs/tests/test_zarr3.py index ec1a398e..8610f475 100644 --- a/numcodecs/tests/test_zarr3.py +++ b/numcodecs/tests/test_zarr3.py @@ -215,7 +215,7 @@ def test_generic_bytes_codec(store: Store, codec_class: type[numcodecs.zarr3._Nu if "codec not available" in str(e): pytest.xfail(f"{codec_class.codec_name} is not available: {e}") else: - raise # pragma: no cover + raise except ImportError as e: pytest.xfail(f"{codec_class.codec_name} is not available: {e}") diff --git a/numcodecs/tests/test_zarr3_import.py b/numcodecs/tests/test_zarr3_import.py index 3feaf3e1..2d13f338 100644 --- a/numcodecs/tests/test_zarr3_import.py +++ b/numcodecs/tests/test_zarr3_import.py @@ -8,6 +8,6 @@ def test_zarr3_import(): try: import zarr # noqa: F401 - except ImportError: # pragma: no cover + except ImportError: with pytest.raises(ImportError, match=ERROR_MESSAGE_MATCH): import numcodecs.zarr3 # noqa: F401 diff --git a/numcodecs/tests/test_zfpy.py b/numcodecs/tests/test_zfpy.py index dce3c4d0..5a12ae43 100644 --- a/numcodecs/tests/test_zfpy.py +++ b/numcodecs/tests/test_zfpy.py @@ -4,7 +4,7 @@ try: # noinspection PyProtectedMember from numcodecs.zfpy import ZFPY, _zfpy -except ImportError: # pragma: no cover +except ImportError: pytest.skip("ZFPY not available", allow_module_level=True) diff --git a/numcodecs/tests/test_zstd.py b/numcodecs/tests/test_zstd.py index de42d9e1..d078aaa9 100644 --- a/numcodecs/tests/test_zstd.py +++ b/numcodecs/tests/test_zstd.py @@ -5,7 +5,7 @@ try: from numcodecs.zstd import Zstd -except ImportError: # pragma: no cover +except ImportError: pytest.skip("numcodecs.zstd not available", allow_module_level=True) diff --git a/pyproject.toml b/pyproject.toml index 5a1701f1..4387fb7d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -118,6 +118,11 @@ write_to = "numcodecs/version.py" skip = "./.git,fixture" ignore-words-list = "ba, compiletime, hist, nd, unparseable" +[tool.coverage.run] +omit = [ + "numcodecs/tests/**", +] + [tool.coverage.report] exclude_lines = [ "pragma: no cover",