Skip to content

Commit 136a5d9

Browse files
committed
fix: mypy
1 parent 557894d commit 136a5d9

File tree

4 files changed

+26
-21
lines changed

4 files changed

+26
-21
lines changed

src/tests/test_setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,11 @@ def test_sdist() -> None:
8989
f"mss-{__version__}/src/tests/test_macos.py",
9090
f"mss-{__version__}/src/tests/test_save.py",
9191
f"mss-{__version__}/src/tests/test_setup.py",
92-
f"mss-{__version__}/src/tests/test_third_party.py",
9392
f"mss-{__version__}/src/tests/test_tools.py",
9493
f"mss-{__version__}/src/tests/test_windows.py",
94+
f"mss-{__version__}/src/tests/third_party/__init__.py",
95+
f"mss-{__version__}/src/tests/third_party/test_numpy.py",
96+
f"mss-{__version__}/src/tests/third_party/test_pil.py",
9597
]
9698

9799

src/tests/third_party/__init__.py

Whitespace-only changes.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""This is part of the MSS Python's module.
2+
Source: https://github.com/BoboTiG/python-mss.
3+
"""
4+
5+
import os
6+
import os.path
7+
8+
import pytest
9+
10+
from mss import mss
11+
12+
pytest.importorskip("numpy", reason="Numpy module not available.")
13+
14+
import numpy as np # noqa: E402
15+
16+
17+
def test_numpy(pixel_ratio: int) -> None:
18+
box = {"top": 0, "left": 0, "width": 10, "height": 10}
19+
with mss(display=os.getenv("DISPLAY")) as sct:
20+
img = np.array(sct.grab(box))
21+
assert len(img) == 10 * pixel_ratio
Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,11 @@
1010

1111
from mss import mss
1212

13-
try:
14-
import numpy as np
15-
except (ImportError, RuntimeError):
16-
# RuntimeError on Python 3.9 (macOS): Polyfit sanity test emitted a warning, ...
17-
np = None
13+
pytest.importorskip("PIL", reason="PIL module not available.")
1814

19-
try:
20-
from PIL import Image
21-
except ImportError:
22-
Image = None
15+
from PIL import Image # noqa: E402
2316

2417

25-
@pytest.mark.skipif(np is None, reason="Numpy module not available.")
26-
def test_numpy(pixel_ratio: int) -> None:
27-
box = {"top": 0, "left": 0, "width": 10, "height": 10}
28-
with mss(display=os.getenv("DISPLAY")) as sct:
29-
img = np.array(sct.grab(box))
30-
assert len(img) == 10 * pixel_ratio
31-
32-
33-
@pytest.mark.skipif(Image is None, reason="PIL module not available.")
3418
def test_pil() -> None:
3519
width, height = 16, 16
3620
box = {"top": 0, "left": 0, "width": width, "height": height}
@@ -48,7 +32,6 @@ def test_pil() -> None:
4832
assert os.path.isfile("box.png")
4933

5034

51-
@pytest.mark.skipif(Image is None, reason="PIL module not available.")
5235
def test_pil_bgra() -> None:
5336
width, height = 16, 16
5437
box = {"top": 0, "left": 0, "width": width, "height": height}
@@ -66,7 +49,6 @@ def test_pil_bgra() -> None:
6649
assert os.path.isfile("box-bgra.png")
6750

6851

69-
@pytest.mark.skipif(Image is None, reason="PIL module not available.")
7052
def test_pil_not_16_rounded() -> None:
7153
width, height = 10, 10
7254
box = {"top": 0, "left": 0, "width": width, "height": height}

0 commit comments

Comments
 (0)