Skip to content

Commit 5a04b95

Browse files
authored
Run slow tests on valgrind, but without timeout (#8975)
1 parent 06e618c commit 5a04b95

File tree

8 files changed

+31
-15
lines changed

8 files changed

+31
-15
lines changed

Tests/helper.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,12 @@ def assert_tuple_approx_equal(
161161
pytest.fail(msg + ": " + repr(actuals) + " != " + repr(targets))
162162

163163

164+
def timeout_unless_slower_valgrind(timeout: float) -> pytest.MarkDecorator:
165+
if "PILLOW_VALGRIND_TEST" in os.environ:
166+
return pytest.mark.pil_noop_mark()
167+
return pytest.mark.timeout(timeout)
168+
169+
164170
def skip_unless_feature(feature: str) -> pytest.MarkDecorator:
165171
reason = f"{feature} not available"
166172
return pytest.mark.skipif(not features.check(feature), reason=reason)

Tests/test_file_eps.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
is_win32,
1616
mark_if_feature_version,
1717
skip_unless_feature,
18+
timeout_unless_slower_valgrind,
1819
)
1920

2021
HAS_GHOSTSCRIPT = EpsImagePlugin.has_ghostscript()
@@ -398,7 +399,7 @@ def test_emptyline() -> None:
398399
assert image.format == "EPS"
399400

400401

401-
@pytest.mark.timeout(timeout=5)
402+
@timeout_unless_slower_valgrind(5)
402403
@pytest.mark.parametrize(
403404
"test_file",
404405
["Tests/images/eps/timeout-d675703545fee17acab56e5fec644c19979175de.eps"],

Tests/test_file_fli.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77

88
from PIL import FliImagePlugin, Image, ImageFile
99

10-
from .helper import assert_image_equal, assert_image_equal_tofile, is_pypy
10+
from .helper import (
11+
assert_image_equal,
12+
assert_image_equal_tofile,
13+
is_pypy,
14+
timeout_unless_slower_valgrind,
15+
)
1116

1217
# created as an export of a palette image from Gimp2.6
1318
# save as...-> hopper.fli, default options.
@@ -189,7 +194,7 @@ def test_seek() -> None:
189194
"Tests/images/timeout-bff0a9dc7243a8e6ede2408d2ffa6a9964698b87.fli",
190195
],
191196
)
192-
@pytest.mark.timeout(timeout=3)
197+
@timeout_unless_slower_valgrind(3)
193198
def test_timeouts(test_file: str) -> None:
194199
with open(test_file, "rb") as f:
195200
with Image.open(f) as im:

Tests/test_file_jpeg.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
is_win32,
3333
mark_if_feature_version,
3434
skip_unless_feature,
35+
timeout_unless_slower_valgrind,
3536
)
3637

3738
ElementTree: ModuleType | None
@@ -1033,7 +1034,7 @@ def test_save_xmp(self, tmp_path: Path) -> None:
10331034
with pytest.raises(ValueError):
10341035
im.save(f, xmp=b"1" * 65505)
10351036

1036-
@pytest.mark.timeout(timeout=1)
1037+
@timeout_unless_slower_valgrind(1)
10371038
def test_eof(self, monkeypatch: pytest.MonkeyPatch) -> None:
10381039
# Even though this decoder never says that it is finished
10391040
# the image should still end when there is no new data

Tests/test_file_pdf.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@
1313

1414
from PIL import Image, PdfParser, features
1515

16-
from .helper import hopper, mark_if_feature_version, skip_unless_feature
16+
from .helper import (
17+
hopper,
18+
mark_if_feature_version,
19+
skip_unless_feature,
20+
timeout_unless_slower_valgrind,
21+
)
1722

1823

1924
def helper_save_as_pdf(tmp_path: Path, mode: str, **kwargs: Any) -> str:
@@ -339,8 +344,7 @@ def test_pdf_append_to_bytesio() -> None:
339344
assert len(f.getvalue()) > initial_size
340345

341346

342-
@pytest.mark.timeout(1)
343-
@pytest.mark.skipif("PILLOW_VALGRIND_TEST" in os.environ, reason="Valgrind is slower")
347+
@timeout_unless_slower_valgrind(1)
344348
@pytest.mark.parametrize("newline", (b"\r", b"\n"))
345349
def test_redos(newline: bytes) -> None:
346350
malicious = b" trailer<<>>" + newline * 3456

Tests/test_file_tiff.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
hopper,
2727
is_pypy,
2828
is_win32,
29+
timeout_unless_slower_valgrind,
2930
)
3031

3132
ElementTree: ModuleType | None
@@ -988,7 +989,7 @@ def test_string_dimension(self) -> None:
988989
with pytest.raises(OSError):
989990
im.load()
990991

991-
@pytest.mark.timeout(6)
992+
@timeout_unless_slower_valgrind(6)
992993
@pytest.mark.filterwarnings("ignore:Truncated File Read")
993994
def test_timeout(self, monkeypatch: pytest.MonkeyPatch) -> None:
994995
with Image.open("Tests/images/timeout-6646305047838720") as im:
@@ -1001,7 +1002,7 @@ def test_timeout(self, monkeypatch: pytest.MonkeyPatch) -> None:
10011002
"Tests/images/oom-225817ca0f8c663be7ab4b9e717b02c661e66834.tif",
10021003
],
10031004
)
1004-
@pytest.mark.timeout(2)
1005+
@timeout_unless_slower_valgrind(2)
10051006
def test_oom(self, test_file: str) -> None:
10061007
with pytest.raises(UnidentifiedImageError):
10071008
with pytest.warns(UserWarning):

Tests/test_image.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
is_win32,
3535
mark_if_feature_version,
3636
skip_unless_feature,
37+
timeout_unless_slower_valgrind,
3738
)
3839

3940
ElementTree: ModuleType | None
@@ -572,10 +573,7 @@ def test_check_size(self) -> None:
572573
i = Image.new("RGB", [1, 1])
573574
assert isinstance(i.size, tuple)
574575

575-
@pytest.mark.timeout(0.75)
576-
@pytest.mark.skipif(
577-
"PILLOW_VALGRIND_TEST" in os.environ, reason="Valgrind is slower"
578-
)
576+
@timeout_unless_slower_valgrind(0.75)
579577
@pytest.mark.parametrize("size", ((0, 100000000), (100000000, 0)))
580578
def test_empty_image(self, size: tuple[int, int]) -> None:
581579
Image.new("RGB", size)

Tests/test_imagefontpil.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from PIL import Image, ImageDraw, ImageFont, _util, features
99

10-
from .helper import assert_image_equal_tofile
10+
from .helper import assert_image_equal_tofile, timeout_unless_slower_valgrind
1111

1212
fonts = [ImageFont.load_default_imagefont()]
1313
if not features.check_module("freetype2"):
@@ -72,7 +72,7 @@ def test_decompression_bomb() -> None:
7272
font.getmask("A" * 1_000_000)
7373

7474

75-
@pytest.mark.timeout(4)
75+
@timeout_unless_slower_valgrind(4)
7676
def test_oom() -> None:
7777
glyph = struct.pack(
7878
">hhhhhhhhhh", 1, 0, -32767, -32767, 32767, 32767, -32767, -32767, 32767, 32767

0 commit comments

Comments
 (0)