Skip to content

Commit 165a133

Browse files
authored
Do not import from Tests directory in checks (#9143)
2 parents e786019 + f69c221 commit 165a133

File tree

4 files changed

+28
-24
lines changed

4 files changed

+28
-24
lines changed

checks/check_imaging_leaks.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
#!/usr/bin/env python3
22
from __future__ import annotations
33

4+
import sys
45
from collections.abc import Callable
56
from typing import Any
67

78
import pytest
89

910
from PIL import Image
1011

11-
from .helper import is_win32
12-
1312
min_iterations = 100
1413
max_iterations = 10000
1514

16-
pytestmark = pytest.mark.skipif(is_win32(), reason="requires Unix or macOS")
15+
pytestmark = pytest.mark.skipif(
16+
sys.platform.startswith("win32"), reason="requires Unix or macOS"
17+
)
1718

1819

1920
def _get_mem_usage() -> float:

checks/check_j2k_leaks.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
from __future__ import annotations
22

3+
import sys
34
from io import BytesIO
45

56
import pytest
67

7-
from PIL import Image
8-
9-
from .helper import is_win32, skip_unless_feature
8+
from PIL import Image, features
109

1110
# Limits for testing the leak
1211
mem_limit = 1024 * 1048576
@@ -15,8 +14,10 @@
1514
test_file = "Tests/images/rgb_trns_ycbc.jp2"
1615

1716
pytestmark = [
18-
pytest.mark.skipif(is_win32(), reason="requires Unix or macOS"),
19-
skip_unless_feature("jpg_2000"),
17+
pytest.mark.skipif(
18+
sys.platform.startswith("win32"), reason="requires Unix or macOS"
19+
),
20+
pytest.mark.skipif(not features.check("jpg_2000"), reason="jpg_2000 not available"),
2021
]
2122

2223

checks/check_jpeg_leaks.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from __future__ import annotations
22

3+
import sys
34
from io import BytesIO
45

56
import pytest
67

7-
from .helper import hopper, is_win32
8+
from PIL import Image
89

910
iterations = 5000
1011

@@ -18,7 +19,9 @@
1819
"""
1920

2021

21-
pytestmark = pytest.mark.skipif(is_win32(), reason="requires Unix or macOS")
22+
pytestmark = pytest.mark.skipif(
23+
sys.platform.startswith("win32"), reason="requires Unix or macOS"
24+
)
2225

2326
"""
2427
pre patch:
@@ -112,10 +115,10 @@
112115
),
113116
)
114117
def test_qtables_leak(qtables: tuple[tuple[int, ...]] | list[tuple[int, ...]]) -> None:
115-
im = hopper("RGB")
116-
for _ in range(iterations):
117-
test_output = BytesIO()
118-
im.save(test_output, "JPEG", qtables=qtables)
118+
with Image.open("Tests/images/hopper.ppm") as im:
119+
for _ in range(iterations):
120+
test_output = BytesIO()
121+
im.save(test_output, "JPEG", qtables=qtables)
119122

120123

121124
def test_exif_leak() -> None:
@@ -173,12 +176,12 @@ def test_exif_leak() -> None:
173176
0 +----------------------------------------------------------------------->Gi
174177
0 11.33
175178
"""
176-
im = hopper("RGB")
177179
exif = b"12345678" * 4096
178180

179-
for _ in range(iterations):
180-
test_output = BytesIO()
181-
im.save(test_output, "JPEG", exif=exif)
181+
with Image.open("Tests/images/hopper.ppm") as im:
182+
for _ in range(iterations):
183+
test_output = BytesIO()
184+
im.save(test_output, "JPEG", exif=exif)
182185

183186

184187
def test_base_save() -> None:
@@ -207,8 +210,7 @@ def test_base_save() -> None:
207210
| :@ @@ @ # : : :: :: @:: :::: :::: :::: : : : : : : :::::::::::: :::@:::
208211
0 +----------------------------------------------------------------------->Gi
209212
0 7.882"""
210-
im = hopper("RGB")
211-
212-
for _ in range(iterations):
213-
test_output = BytesIO()
214-
im.save(test_output, "JPEG")
213+
with Image.open("Tests/images/hopper.ppm") as im:
214+
for _ in range(iterations):
215+
test_output = BytesIO()
216+
im.save(test_output, "JPEG")

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ skip_install = true
3030
deps =
3131
-r .ci/requirements-mypy.txt
3232
commands =
33-
mypy conftest.py selftest.py setup.py docs src winbuild Tests {posargs}
33+
mypy conftest.py selftest.py setup.py checks docs src winbuild Tests {posargs}

0 commit comments

Comments
 (0)