Skip to content

Commit fd25497

Browse files
Use pytest.importorskip, more modern test skips
1 parent fceaf95 commit fd25497

11 files changed

Lines changed: 32 additions & 65 deletions

tests/test_blosc.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@
44
import numpy as np
55
import pytest
66

7-
try:
8-
from numcodecs.blosc import Blosc
9-
10-
from numcodecs import blosc
11-
except ImportError: # pragma: no cover
12-
pytest.skip("numcodecs.blosc not available", allow_module_level=True)
13-
14-
157
from tests.common import (
168
check_backwards_compatibility,
179
check_config,
@@ -22,6 +14,9 @@
2214
is_wasm,
2315
)
2416

17+
blosc = pytest.importorskip("numcodecs.blosc")
18+
Blosc = blosc.Blosc
19+
2520
codecs = [
2621
Blosc(shuffle=Blosc.SHUFFLE),
2722
Blosc(clevel=0, shuffle=Blosc.SHUFFLE),

tests/test_lz4.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@
33
import numpy as np
44
import pytest
55

6-
try:
7-
from numcodecs.lz4 import LZ4
8-
except ImportError: # pragma: no cover
9-
pytest.skip("numcodecs.lz4 not available", allow_module_level=True)
10-
11-
126
from tests.common import (
137
check_backwards_compatibility,
148
check_config,
@@ -19,6 +13,8 @@
1913
check_repr,
2014
)
2115

16+
LZ4 = pytest.importorskip("numcodecs.lz4").LZ4
17+
2218
codecs = [
2319
LZ4(),
2420
LZ4(acceleration=-1),

tests/test_lzma.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
11
import itertools
2-
import unittest
32
from types import ModuleType
43
from typing import cast
54

65
import numpy as np
76
import pytest
87

9-
try:
10-
# noinspection PyProtectedMember
11-
from numcodecs.lzma import LZMA, _lzma
12-
except ImportError as e: # pragma: no cover
13-
raise unittest.SkipTest("LZMA not available") from e
14-
15-
168
from tests.common import (
179
check_backwards_compatibility,
1810
check_config,
@@ -22,6 +14,10 @@
2214
check_repr,
2315
)
2416

17+
_lzma_mod = pytest.importorskip("numcodecs.lzma")
18+
LZMA = _lzma_mod.LZMA
19+
_lzma = _lzma_mod._lzma
20+
2521
_lzma = cast(ModuleType, _lzma)
2622

2723
codecs = [

tests/test_msgpacks.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
1-
import unittest
2-
31
import numpy as np
42
import pytest
53

6-
try:
7-
from numcodecs.msgpacks import MsgPack
8-
except ImportError as e: # pragma: no cover
9-
raise unittest.SkipTest("msgpack not available") from e
10-
11-
124
from tests.common import (
135
check_backwards_compatibility,
146
check_config,
@@ -17,6 +9,8 @@
179
greetings,
1810
)
1911

12+
MsgPack = pytest.importorskip("numcodecs.msgpacks").MsgPack
13+
2014
# object array with strings
2115
# object array with mix strings / nans
2216
# object array with mix of string, int, float

tests/test_pyzstd.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
import numpy as np
44
import pytest
5-
import pyzstd
65
from numcodecs.zstd import Zstd
76

7+
pyzstd = pytest.importorskip("pyzstd")
8+
9+
810
test_data = [
911
b"Hello World!",
1012
np.arange(113).tobytes(),

tests/test_shuffle.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,15 @@
44
import numpy as np
55
import pytest
66

7-
try:
8-
from numcodecs.shuffle import Shuffle
9-
except ImportError: # pragma: no cover
10-
pytest.skip("numcodecs.shuffle not available", allow_module_level=True)
11-
12-
137
from tests.common import (
148
check_backwards_compatibility,
159
check_config,
1610
check_encode_decode,
1711
is_wasm,
1812
)
1913

14+
Shuffle = pytest.importorskip("numcodecs.shuffle").Shuffle
15+
2016
codecs = [
2117
Shuffle(),
2218
Shuffle(elementsize=0),

tests/test_vlen_array.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
import unittest
2-
31
import numpy as np
42
import pytest
53

6-
try:
7-
from numcodecs.vlen import VLenArray
8-
except ImportError as e: # pragma: no cover
9-
raise unittest.SkipTest("vlen-array not available") from e
104
from tests.common import (
115
assert_array_items_equal,
126
check_backwards_compatibility,
@@ -15,6 +9,8 @@
159
check_repr,
1610
)
1711

12+
VLenArray = pytest.importorskip("numcodecs.vlen").VLenArray
13+
1814
arrays = [
1915
np.array([np.array([1, 2, 3]), np.array([4]), np.array([5, 6])] * 300, dtype=object),
2016
np.array([np.array([1, 2, 3]), np.array([4]), np.array([5, 6])] * 300, dtype=object).reshape(

tests/test_vlen_bytes.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
import unittest
2-
31
import numpy as np
42
import pytest
53

6-
try:
7-
from numcodecs.vlen import VLenBytes
8-
except ImportError as e: # pragma: no cover
9-
raise unittest.SkipTest("vlen-bytes not available") from e
104
from tests.common import (
115
assert_array_items_equal,
126
check_backwards_compatibility,
@@ -16,6 +10,8 @@
1610
greetings,
1711
)
1812

13+
VLenBytes = pytest.importorskip("numcodecs.vlen").VLenBytes
14+
1915
greetings_bytes = [g.encode('utf-8') for g in greetings]
2016

2117

tests/test_vlen_utf8.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
import unittest
2-
31
import numpy as np
42
import pytest
53

6-
try:
7-
from numcodecs.vlen import VLenUTF8
8-
except ImportError as e: # pragma: no cover
9-
raise unittest.SkipTest("vlen-utf8 not available") from e
104
from tests.common import (
115
assert_array_items_equal,
126
check_backwards_compatibility,
@@ -16,6 +10,8 @@
1610
greetings,
1711
)
1812

13+
VLenUTF8 = pytest.importorskip("numcodecs.vlen").VLenUTF8
14+
1915
arrays = [
2016
np.array(['foo', 'bar', 'baz'] * 300, dtype=object),
2117
np.array(greetings * 100, dtype=object),

tests/test_zfpy.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,6 @@
44
import numpy as np
55
import pytest
66

7-
try:
8-
# noinspection PyProtectedMember
9-
from numcodecs.zfpy import ZFPY, _zfpy
10-
except ImportError: # pragma: no cover
11-
pytest.skip("ZFPY not available", allow_module_level=True)
12-
13-
147
from tests.common import (
158
check_backwards_compatibility,
169
check_config,
@@ -20,6 +13,10 @@
2013
check_repr,
2114
)
2215

16+
_zfpy_mod = pytest.importorskip("numcodecs.zfpy")
17+
ZFPY = _zfpy_mod.ZFPY
18+
_zfpy = _zfpy_mod._zfpy
19+
2320
_zfpy = cast(ModuleType, _zfpy)
2421

2522

0 commit comments

Comments
 (0)