conditional mark for valgrind ignore

This commit is contained in:
Eric Soroos 2021-04-09 23:33:21 +02:00
parent 441e6426ae
commit a3a69c8385
10 changed files with 41 additions and 22 deletions

View File

@ -173,6 +173,16 @@ def skip_unless_feature_version(feature, version_required, reason=None):
return pytest.mark.skipif(version_available < version_required, reason=reason)
def mark_if_feature_version(mark, feature, version_blacklist, reason=None):
if not features.check(feature):
return
if reason is None:
reason = f"{feature} is {version_blacklist}"
version_required = parse_version(version_blacklist)
version_available = parse_version(features.version(feature))
return mark(version_available == version_blacklist, reason=reason)
@pytest.mark.skipif(sys.platform.startswith("win32"), reason="Requires Unix or macOS")
class PillowLeakTestCase:
# requires unix/macOS

View File

@ -9,6 +9,7 @@ from .helper import (
assert_image_similar_tofile,
hopper,
skip_unless_feature,
mark_if_feature_version,
)
HAS_GHOSTSCRIPT = EpsImagePlugin.has_ghostscript()
@ -64,7 +65,7 @@ def test_invalid_file():
EpsImagePlugin.EpsImageFile(invalid_file)
@pytest.mark.valgrind_known_error(reason="Known Failing")
@mark_if_feature_version(pytest.mark.valgrind_known_error, 'libjpeg_turbo', '2.0', reason="Known Failing")
@pytest.mark.skipif(not HAS_GHOSTSCRIPT, reason="Ghostscript not available")
def test_cmyk():
with Image.open("Tests/images/pil_sample_cmyk.eps") as cmyk_image:

View File

@ -25,6 +25,7 @@ from .helper import (
hopper,
is_win32,
skip_unless_feature,
mark_if_feature_version,
)
TEST_FILE = "Tests/images/hopper.jpg"
@ -116,7 +117,7 @@ class TestFileJpeg:
assert test(100, 200) == (100, 200)
assert test(0) is None # square pixels
@pytest.mark.valgrind_known_error(reason="Known Failing")
@mark_if_feature_version(pytest.mark.valgrind_known_error, 'libjpeg_turbo', '2.0', reason="Known Failing")
def test_icc(self, tmp_path):
# Test ICC support
with Image.open("Tests/images/rgb.jpg") as im1:
@ -156,7 +157,7 @@ class TestFileJpeg:
test(ImageFile.MAXBLOCK + 1) # full buffer block plus one byte
test(ImageFile.MAXBLOCK * 4 + 3) # large block
@pytest.mark.valgrind_known_error(reason="Known Failing")
@mark_if_feature_version(pytest.mark.valgrind_known_error, 'libjpeg_turbo', '2.0', reason="Known Failing")
def test_large_icc_meta(self, tmp_path):
# https://github.com/python-pillow/Pillow/issues/148
# Sometimes the meta data on the icc_profile block is bigger than
@ -423,7 +424,7 @@ class TestFileJpeg:
with Image.open(filename):
pass
@pytest.mark.valgrind_known_error(reason="Known Failing")
@mark_if_feature_version(pytest.mark.valgrind_known_error, 'libjpeg_turbo', '2.0', reason="Known Failing")
def test_truncated_jpeg_should_read_all_the_data(self):
filename = "Tests/images/truncated_jpeg.jpg"
ImageFile.LOAD_TRUNCATED_IMAGES = True
@ -442,7 +443,7 @@ class TestFileJpeg:
with pytest.raises(OSError):
im.load()
@pytest.mark.valgrind_known_error(reason="Known Failing")
@mark_if_feature_version(pytest.mark.valgrind_known_error, 'libjpeg_turbo', '2.0', reason="Known Failing")
def test_qtables(self, tmp_path):
def _n_qtables_helper(n, test_file):
with Image.open(test_file) as im:
@ -726,7 +727,7 @@ class TestFileJpeg:
# OSError for unidentified image.
assert im.info.get("dpi") == (72, 72)
@pytest.mark.valgrind_known_error(reason="Known Failing")
@mark_if_feature_version(pytest.mark.valgrind_known_error, 'libjpeg_turbo', '2.0', reason="Known Failing")
def test_exif_x_resolution(self, tmp_path):
with Image.open("Tests/images/flower.jpg") as im:
exif = im.getexif()
@ -757,7 +758,7 @@ class TestFileJpeg:
# Act / Assert
assert im._getexif()[306] == "2017:03:13 23:03:09"
@pytest.mark.valgrind_known_error(reason="Backtrace in Python Core")
@mark_if_feature_version(pytest.mark.valgrind_known_error, 'libjpeg_turbo', '2.0', reason="Known Failing")
def test_photoshop(self):
with Image.open("Tests/images/photoshop-200dpi.jpg") as im:
assert im.info["photoshop"][0x03ED] == {

View File

@ -18,6 +18,7 @@ from .helper import (
assert_image_similar_tofile,
hopper,
skip_unless_feature,
mark_if_feature_version,
)
@ -822,13 +823,13 @@ class TestFileLibTiff(LibTiffTestCase):
with Image.open(infile) as im:
assert_image_similar_tofile(im, "Tests/images/pil_sample_cmyk.jpg", 0.5)
@pytest.mark.valgrind_known_error(reason="Known Failing")
@mark_if_feature_version(pytest.mark.valgrind_known_error, 'libjpeg_turbo', '2.0', reason="Known Failing")
def test_strip_ycbcr_jpeg_2x2_sampling(self):
infile = "Tests/images/tiff_strip_ycbcr_jpeg_2x2_sampling.tif"
with Image.open(infile) as im:
assert_image_similar_tofile(im, "Tests/images/flower.jpg", 0.5)
@pytest.mark.valgrind_known_error(reason="Known Failing")
@mark_if_feature_version(pytest.mark.valgrind_known_error, 'libjpeg_turbo', '2.0', reason="Known Failing")
def test_strip_ycbcr_jpeg_1x1_sampling(self):
infile = "Tests/images/tiff_strip_ycbcr_jpeg_1x1_sampling.tif"
with Image.open(infile) as im:
@ -839,13 +840,13 @@ class TestFileLibTiff(LibTiffTestCase):
with Image.open(infile) as im:
assert_image_similar_tofile(im, "Tests/images/pil_sample_cmyk.jpg", 0.5)
@pytest.mark.valgrind_known_error(reason="Known Failing")
@mark_if_feature_version(pytest.mark.valgrind_known_error, 'libjpeg_turbo', '2.0', reason="Known Failing")
def test_tiled_ycbcr_jpeg_1x1_sampling(self):
infile = "Tests/images/tiff_tiled_ycbcr_jpeg_1x1_sampling.tif"
with Image.open(infile) as im:
assert_image_equal_tofile(im, "Tests/images/flower2.jpg")
@pytest.mark.valgrind_known_error(reason="Known Failing")
@mark_if_feature_version(pytest.mark.valgrind_known_error, 'libjpeg_turbo', '2.0', reason="Known Failing")
def test_tiled_ycbcr_jpeg_2x2_sampling(self):
infile = "Tests/images/tiff_tiled_ycbcr_jpeg_2x2_sampling.tif"
with Image.open(infile) as im:

View File

@ -8,7 +8,8 @@ import pytest
from PIL import Image, PdfParser
from .helper import hopper
from .helper import hopper, mark_if_feature_version
def helper_save_as_pdf(tmp_path, mode, **kwargs):
@ -85,7 +86,7 @@ def test_unsupported_mode(tmp_path):
im.save(outfile)
@pytest.mark.valgrind_known_error(reason="Known Failing")
@mark_if_feature_version(pytest.mark.valgrind_known_error, 'libjpeg_turbo', '2.0', reason="Known Failing")
def test_save_all(tmp_path):
# Single frame image
helper_save_as_pdf(tmp_path, "RGB", save_all=True)

View File

@ -14,6 +14,7 @@ from .helper import (
is_big_endian,
is_win32,
skip_unless_feature,
mark_if_feature_version,
)
# sample png stream
@ -679,7 +680,7 @@ class TestFilePng:
exif = reloaded._getexif()
assert exif[274] == 1
@pytest.mark.valgrind_known_error(reason="Known Failing")
@mark_if_feature_version(pytest.mark.valgrind_known_error, 'libjpeg_turbo', '2.0', reason="Known Failing")
def test_exif_from_jpg(self, tmp_path):
with Image.open("Tests/images/pil_sample_rgb.jpg") as im:
test_file = str(tmp_path / "temp.png")

View File

@ -4,7 +4,8 @@ import pytest
from PIL import Image
from .helper import skip_unless_feature
from .helper import skip_unless_feature, mark_if_feature_version
pytestmark = [
skip_unless_feature("webp"),
@ -41,7 +42,7 @@ def test_read_exif_metadata_without_prefix():
assert exif[305] == "Adobe Photoshop CS6 (Macintosh)"
@pytest.mark.valgrind_known_error(reason="Known Failing")
@mark_if_feature_version(pytest.mark.valgrind_known_error, 'libjpeg_turbo', '2.0', reason="Known Failing")
def test_write_exif_metadata():
file_path = "Tests/images/flower.jpg"
test_buffer = BytesIO()
@ -74,7 +75,7 @@ def test_read_icc_profile():
assert icc == expected_icc
@pytest.mark.valgrind_known_error(reason="Known Failing")
@mark_if_feature_version(pytest.mark.valgrind_known_error, 'libjpeg_turbo', '2.0', reason="Known Failing")
def test_write_icc_metadata():
file_path = "Tests/images/flower2.jpg"
test_buffer = BytesIO()
@ -92,7 +93,7 @@ def test_write_icc_metadata():
assert webp_icc_profile == expected_icc_profile, "Webp ICC didn't match"
@pytest.mark.valgrind_known_error(reason="Known Failing")
@mark_if_feature_version(pytest.mark.valgrind_known_error, 'libjpeg_turbo', '2.0', reason="Known Failing")
def test_read_no_exif():
file_path = "Tests/images/flower.jpg"
test_buffer = BytesIO()

View File

@ -17,6 +17,7 @@ from .helper import (
hopper,
is_win32,
skip_unless_feature,
mark_if_feature_version,
)
@ -662,7 +663,7 @@ class TestImage:
assert not fp.closed
@pytest.mark.valgrind_known_error(reason="Known Failing")
@mark_if_feature_version(pytest.mark.valgrind_known_error, 'libjpeg_turbo', '2.0', reason="Known Failing")
def test_exif_jpeg(self, tmp_path):
with Image.open("Tests/images/exif-72dpi-int.jpg") as im: # Little endian
exif = im.getexif()

View File

@ -4,7 +4,8 @@ import pytest
from PIL import Image, ImageDraw
from .helper import assert_image_equal, assert_image_similar, hopper
from .helper import assert_image_equal, assert_image_similar, hopper, mark_if_feature_version
class TestImagingResampleVulnerability:
@ -455,7 +456,7 @@ class TestCoreResampleBox:
tiled.paste(tile, (x0, y0))
return tiled
@pytest.mark.valgrind_known_error(reason="Known Failing")
@mark_if_feature_version(pytest.mark.valgrind_known_error, 'libjpeg_turbo', '2.0', reason="Known Failing")
def test_tiles(self):
with Image.open("Tests/images/flower.jpg") as im:
assert im.size == (480, 360)
@ -466,7 +467,7 @@ class TestCoreResampleBox:
tiled = self.resize_tiled(im, dst_size, *tiles)
assert_image_similar(reference, tiled, 0.01)
@pytest.mark.valgrind_known_error(reason="Known Failing")
@mark_if_feature_version(pytest.mark.valgrind_known_error, 'libjpeg_turbo', '2.0', reason="Known Failing")
def test_subsample(self):
# This test shows advantages of the subpixel resizing
# after supersampling (e.g. during JPEG decoding).

View File

@ -88,6 +88,7 @@ def test_no_resize():
assert im.size == (64, 64)
# valgrind test is failing with memory allocated in libjpeg
@pytest.mark.valgrind_known_error(reason="Known Failing")
def test_DCT_scaling_edges():
# Make an image with red borders and size (N * 8) + 1 to cross DCT grid