Do not import from Tests directory in checks (#9143)

This commit is contained in:
Hugo van Kemenade 2025-08-09 15:10:35 +03:00 committed by GitHub
commit 165a133d36
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 28 additions and 24 deletions

View File

@ -1,6 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from __future__ import annotations from __future__ import annotations
import sys
from collections.abc import Callable from collections.abc import Callable
from typing import Any from typing import Any
@ -8,12 +9,12 @@ import pytest
from PIL import Image from PIL import Image
from .helper import is_win32
min_iterations = 100 min_iterations = 100
max_iterations = 10000 max_iterations = 10000
pytestmark = pytest.mark.skipif(is_win32(), reason="requires Unix or macOS") pytestmark = pytest.mark.skipif(
sys.platform.startswith("win32"), reason="requires Unix or macOS"
)
def _get_mem_usage() -> float: def _get_mem_usage() -> float:

View File

@ -1,12 +1,11 @@
from __future__ import annotations from __future__ import annotations
import sys
from io import BytesIO from io import BytesIO
import pytest import pytest
from PIL import Image from PIL import Image, features
from .helper import is_win32, skip_unless_feature
# Limits for testing the leak # Limits for testing the leak
mem_limit = 1024 * 1048576 mem_limit = 1024 * 1048576
@ -15,8 +14,10 @@ iterations = int((mem_limit / stack_size) * 2)
test_file = "Tests/images/rgb_trns_ycbc.jp2" test_file = "Tests/images/rgb_trns_ycbc.jp2"
pytestmark = [ pytestmark = [
pytest.mark.skipif(is_win32(), reason="requires Unix or macOS"), pytest.mark.skipif(
skip_unless_feature("jpg_2000"), sys.platform.startswith("win32"), reason="requires Unix or macOS"
),
pytest.mark.skipif(not features.check("jpg_2000"), reason="jpg_2000 not available"),
] ]

View File

@ -1,10 +1,11 @@
from __future__ import annotations from __future__ import annotations
import sys
from io import BytesIO from io import BytesIO
import pytest import pytest
from .helper import hopper, is_win32 from PIL import Image
iterations = 5000 iterations = 5000
@ -18,7 +19,9 @@ valgrind --tool=massif python test-installed.py -s -v checks/check_jpeg_leaks.py
""" """
pytestmark = pytest.mark.skipif(is_win32(), reason="requires Unix or macOS") pytestmark = pytest.mark.skipif(
sys.platform.startswith("win32"), reason="requires Unix or macOS"
)
""" """
pre patch: pre patch:
@ -112,10 +115,10 @@ standard_chrominance_qtable = (
), ),
) )
def test_qtables_leak(qtables: tuple[tuple[int, ...]] | list[tuple[int, ...]]) -> None: def test_qtables_leak(qtables: tuple[tuple[int, ...]] | list[tuple[int, ...]]) -> None:
im = hopper("RGB") with Image.open("Tests/images/hopper.ppm") as im:
for _ in range(iterations): for _ in range(iterations):
test_output = BytesIO() test_output = BytesIO()
im.save(test_output, "JPEG", qtables=qtables) im.save(test_output, "JPEG", qtables=qtables)
def test_exif_leak() -> None: def test_exif_leak() -> None:
@ -173,12 +176,12 @@ def test_exif_leak() -> None:
0 +----------------------------------------------------------------------->Gi 0 +----------------------------------------------------------------------->Gi
0 11.33 0 11.33
""" """
im = hopper("RGB")
exif = b"12345678" * 4096 exif = b"12345678" * 4096
for _ in range(iterations): with Image.open("Tests/images/hopper.ppm") as im:
test_output = BytesIO() for _ in range(iterations):
im.save(test_output, "JPEG", exif=exif) test_output = BytesIO()
im.save(test_output, "JPEG", exif=exif)
def test_base_save() -> None: def test_base_save() -> None:
@ -207,8 +210,7 @@ def test_base_save() -> None:
| :@ @@ @ # : : :: :: @:: :::: :::: :::: : : : : : : :::::::::::: :::@::: | :@ @@ @ # : : :: :: @:: :::: :::: :::: : : : : : : :::::::::::: :::@:::
0 +----------------------------------------------------------------------->Gi 0 +----------------------------------------------------------------------->Gi
0 7.882""" 0 7.882"""
im = hopper("RGB") with Image.open("Tests/images/hopper.ppm") as im:
for _ in range(iterations):
for _ in range(iterations): test_output = BytesIO()
test_output = BytesIO() im.save(test_output, "JPEG")
im.save(test_output, "JPEG")

View File

@ -30,4 +30,4 @@ skip_install = true
deps = deps =
-r .ci/requirements-mypy.txt -r .ci/requirements-mypy.txt
commands = commands =
mypy conftest.py selftest.py setup.py docs src winbuild Tests {posargs} mypy conftest.py selftest.py setup.py checks docs src winbuild Tests {posargs}