From 59ed81f8387b1491890aa20482e2f1776ecf9970 Mon Sep 17 00:00:00 2001 From: Eric Soroos Date: Mon, 28 Dec 2020 13:48:46 +0100 Subject: [PATCH 1/8] Add pytest configuration for patching around an unknown valgrind mark --- Tests/conftest.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Tests/conftest.py b/Tests/conftest.py index 082f2f7c35c..1b2fffdc55f 100644 --- a/Tests/conftest.py +++ b/Tests/conftest.py @@ -10,3 +10,18 @@ def pytest_report_header(config): return out.getvalue() except Exception as e: return f"pytest_report_header failed: {e}" + +def pytest_configure(config): + # We're marking some tests to ignore valgrind errors and XFAIL them. + # Ensure that the mark is defined even in cases where pytest-valgrind isn't installed + + import pytest + import warnings + + with warnings.catch_warnings(): + warnings.simplefilter("error") + try: + getattr(pytest.mark, "valgrind_known_error") + except: + config.addinivalue_line("markers", + "valgrind_known_error: Tests that have known issues with valgrind") From bd384873243b095cfd057c7ec1a2d617923d152d Mon Sep 17 00:00:00 2001 From: Eric Soroos Date: Mon, 28 Dec 2020 13:49:12 +0100 Subject: [PATCH 2/8] Ignore this test in valgrind -- the metadata values don't make logical sense. --- Tests/test_file_libtiff.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Tests/test_file_libtiff.py b/Tests/test_file_libtiff.py index 7d3e10c2491..473671ce108 100644 --- a/Tests/test_file_libtiff.py +++ b/Tests/test_file_libtiff.py @@ -185,6 +185,7 @@ def test_write_metadata(self, tmp_path): for field in requested_fields: assert field in reloaded, f"{field} not in metadata" + @pytest.mark.valgrind_known_error(reason="Known Invalid Metadata") def test_additional_metadata(self, tmp_path): # these should not crash. Seriously dummy data, most of it doesn't make # any sense, so we're running up against limits where we're asking From d35995f945398d9c7cdefcae24d7fea889916116 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Wed, 30 Dec 2020 14:41:22 +1100 Subject: [PATCH 3/8] Lint fixes --- Tests/conftest.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Tests/conftest.py b/Tests/conftest.py index 1b2fffdc55f..7da77aa9fc5 100644 --- a/Tests/conftest.py +++ b/Tests/conftest.py @@ -11,17 +11,22 @@ def pytest_report_header(config): except Exception as e: return f"pytest_report_header failed: {e}" + def pytest_configure(config): # We're marking some tests to ignore valgrind errors and XFAIL them. - # Ensure that the mark is defined even in cases where pytest-valgrind isn't installed + # Ensure that the mark is defined + # even in cases where pytest-valgrind isn't installed - import pytest import warnings + import pytest + with warnings.catch_warnings(): warnings.simplefilter("error") try: getattr(pytest.mark, "valgrind_known_error") except: - config.addinivalue_line("markers", - "valgrind_known_error: Tests that have known issues with valgrind") + config.addinivalue_line( + "markers", + "valgrind_known_error: Tests that have known issues with valgrind", + ) From 59ee809f135b45a7cfa08303260dcf009ddb13c2 Mon Sep 17 00:00:00 2001 From: Andrew Murray <3112309+radarhere@users.noreply.github.com> Date: Thu, 31 Dec 2020 09:38:40 +1100 Subject: [PATCH 4/8] Updated capitalisation Co-authored-by: Hugo van Kemenade --- Tests/test_file_libtiff.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/test_file_libtiff.py b/Tests/test_file_libtiff.py index 473671ce108..9d495603428 100644 --- a/Tests/test_file_libtiff.py +++ b/Tests/test_file_libtiff.py @@ -185,7 +185,7 @@ def test_write_metadata(self, tmp_path): for field in requested_fields: assert field in reloaded, f"{field} not in metadata" - @pytest.mark.valgrind_known_error(reason="Known Invalid Metadata") + @pytest.mark.valgrind_known_error(reason="Known invalid metadata") def test_additional_metadata(self, tmp_path): # these should not crash. Seriously dummy data, most of it doesn't make # any sense, so we're running up against limits where we're asking From a58ff327d41307f8810b42311e8560fc3fc08495 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Thu, 31 Dec 2020 09:46:16 +1100 Subject: [PATCH 5/8] Moved imports to top of file --- Tests/conftest.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Tests/conftest.py b/Tests/conftest.py index 7da77aa9fc5..e0f3ded1dee 100644 --- a/Tests/conftest.py +++ b/Tests/conftest.py @@ -1,4 +1,7 @@ import io +import warnings + +import pytest def pytest_report_header(config): @@ -17,10 +20,6 @@ def pytest_configure(config): # Ensure that the mark is defined # even in cases where pytest-valgrind isn't installed - import warnings - - import pytest - with warnings.catch_warnings(): warnings.simplefilter("error") try: From 1d7c8e03d076188524b2d686c9afca6f2c1cc3bc Mon Sep 17 00:00:00 2001 From: Eric Soroos Date: Thu, 7 Jan 2021 14:50:25 +0100 Subject: [PATCH 6/8] known failing tests from valgrind -- uninitialized values --- Tests/test_file_eps.py | 2 +- Tests/test_file_jpeg.py | 6 ++++++ Tests/test_file_libtiff.py | 5 +++++ Tests/test_file_pdf.py | 2 +- Tests/test_file_png.py | 1 + Tests/test_file_webp_metadata.py | 8 ++++---- Tests/test_image.py | 1 + Tests/test_image_resample.py | 2 ++ Tests/test_image_thumbnail.py | 2 +- 9 files changed, 22 insertions(+), 7 deletions(-) diff --git a/Tests/test_file_eps.py b/Tests/test_file_eps.py index f585a06699d..1d76f5917ac 100644 --- a/Tests/test_file_eps.py +++ b/Tests/test_file_eps.py @@ -58,7 +58,7 @@ def test_invalid_file(): with pytest.raises(SyntaxError): EpsImagePlugin.EpsImageFile(invalid_file) - +@pytest.mark.valgrind_known_error(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: diff --git a/Tests/test_file_jpeg.py b/Tests/test_file_jpeg.py index ff469d15c31..435ecbaa7ad 100644 --- a/Tests/test_file_jpeg.py +++ b/Tests/test_file_jpeg.py @@ -114,6 +114,7 @@ def test(xdpi, ydpi=None): assert test(100, 200) == (100, 200) assert test(0) is None # square pixels + @pytest.mark.valgrind_known_error(reason="Known Failing") def test_icc(self, tmp_path): # Test ICC support with Image.open("Tests/images/rgb.jpg") as im1: @@ -153,6 +154,7 @@ def test(n): 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") 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 @@ -419,6 +421,7 @@ def test_ff00_jpeg_header(self): with Image.open(filename): pass + @pytest.mark.valgrind_known_error(reason="Known Failing") def test_truncated_jpeg_should_read_all_the_data(self): filename = "Tests/images/truncated_jpeg.jpg" ImageFile.LOAD_TRUNCATED_IMAGES = True @@ -437,6 +440,7 @@ def test_truncated_jpeg_throws_oserror(self): with pytest.raises(OSError): im.load() + @pytest.mark.valgrind_known_error(reason="Known Failing") def test_qtables(self, tmp_path): def _n_qtables_helper(n, test_file): with Image.open(test_file) as im: @@ -720,6 +724,7 @@ def test_invalid_exif(self): # OSError for unidentified image. assert im.info.get("dpi") == (72, 72) + @pytest.mark.valgrind_known_error(reason="Known Failing") def test_exif_x_resolution(self, tmp_path): with Image.open("Tests/images/flower.jpg") as im: exif = im.getexif() @@ -750,6 +755,7 @@ def test_ifd_offset_exif(self): # Act / Assert assert im._getexif()[306] == "2017:03:13 23:03:09" + @pytest.mark.valgrind_known_error(reason="Backtrace in Python Core") def test_photoshop(self): with Image.open("Tests/images/photoshop-200dpi.jpg") as im: assert im.info["photoshop"][0x03ED] == { diff --git a/Tests/test_file_libtiff.py b/Tests/test_file_libtiff.py index 9d495603428..accc9596fcb 100644 --- a/Tests/test_file_libtiff.py +++ b/Tests/test_file_libtiff.py @@ -815,12 +815,14 @@ def test_strip_cmyk_16l_jpeg(self): 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") @pytest.mark.xfail(is_big_endian(), reason="Fails on big-endian") 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") @pytest.mark.xfail(is_big_endian(), reason="Fails on big-endian") def test_strip_ycbcr_jpeg_1x1_sampling(self): infile = "Tests/images/tiff_strip_ycbcr_jpeg_1x1_sampling.tif" @@ -832,12 +834,14 @@ def test_tiled_cmyk_jpeg(self): 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") @pytest.mark.xfail(is_big_endian(), reason="Fails on big-endian") 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") @pytest.mark.xfail(is_big_endian(), reason="Fails on big-endian") def test_tiled_ycbcr_jpeg_2x2_sampling(self): infile = "Tests/images/tiff_tiled_ycbcr_jpeg_2x2_sampling.tif" @@ -865,6 +869,7 @@ def test_orientation(self): assert_image_similar(base_im, im, 0.7) + @pytest.mark.valgrind_known_error(reason="Backtrace in Python Core") def test_sampleformat_not_corrupted(self): # Assert that a TIFF image with SampleFormat=UINT tag is not corrupted # when saving to a new file. diff --git a/Tests/test_file_pdf.py b/Tests/test_file_pdf.py index 3e23beae72e..536b9316626 100644 --- a/Tests/test_file_pdf.py +++ b/Tests/test_file_pdf.py @@ -84,7 +84,7 @@ def test_unsupported_mode(tmp_path): with pytest.raises(ValueError): im.save(outfile) - +@pytest.mark.valgrind_known_error(reason="Known Failing") def test_save_all(tmp_path): # Single frame image helper_save_as_pdf(tmp_path, "RGB", save_all=True) diff --git a/Tests/test_file_png.py b/Tests/test_file_png.py index 9028aaf23b9..4cd4515aeb9 100644 --- a/Tests/test_file_png.py +++ b/Tests/test_file_png.py @@ -654,6 +654,7 @@ def test_exif_save(self, tmp_path): exif = reloaded._getexif() assert exif[274] == 1 + @pytest.mark.valgrind_known_error(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") diff --git a/Tests/test_file_webp_metadata.py b/Tests/test_file_webp_metadata.py index a2a05f96b92..290dc036290 100644 --- a/Tests/test_file_webp_metadata.py +++ b/Tests/test_file_webp_metadata.py @@ -1,5 +1,5 @@ from io import BytesIO - +import pytest from PIL import Image from .helper import skip_unless_feature @@ -38,7 +38,7 @@ def test_read_exif_metadata_without_prefix(): exif = im.getexif() assert exif[305] == "Adobe Photoshop CS6 (Macintosh)" - +@pytest.mark.valgrind_known_error(reason="Known Failing") def test_write_exif_metadata(): file_path = "Tests/images/flower.jpg" test_buffer = BytesIO() @@ -70,7 +70,7 @@ def test_read_icc_profile(): assert icc == expected_icc - +@pytest.mark.valgrind_known_error(reason="Known Failing") def test_write_icc_metadata(): file_path = "Tests/images/flower2.jpg" test_buffer = BytesIO() @@ -87,7 +87,7 @@ def test_write_icc_metadata(): if webp_icc_profile: assert webp_icc_profile == expected_icc_profile, "Webp ICC didn't match" - +@pytest.mark.valgrind_known_error(reason="Known Failing") def test_read_no_exif(): file_path = "Tests/images/flower.jpg" test_buffer = BytesIO() diff --git a/Tests/test_image.py b/Tests/test_image.py index f2a1917e856..ade9d03c980 100644 --- a/Tests/test_image.py +++ b/Tests/test_image.py @@ -652,6 +652,7 @@ def act(fp): assert not fp.closed + @pytest.mark.valgrind_known_error(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() diff --git a/Tests/test_image_resample.py b/Tests/test_image_resample.py index ef4ca410156..69449198e7d 100644 --- a/Tests/test_image_resample.py +++ b/Tests/test_image_resample.py @@ -455,6 +455,7 @@ def split_range(size, tiles): tiled.paste(tile, (x0, y0)) return tiled + @pytest.mark.valgrind_known_error(reason="Known Failing") def test_tiles(self): with Image.open("Tests/images/flower.jpg") as im: assert im.size == (480, 360) @@ -465,6 +466,7 @@ def test_tiles(self): tiled = self.resize_tiled(im, dst_size, *tiles) assert_image_similar(reference, tiled, 0.01) + @pytest.mark.valgrind_known_error(reason="Known Failing") def test_subsample(self): # This test shows advantages of the subpixel resizing # after supersampling (e.g. during JPEG decoding). diff --git a/Tests/test_image_thumbnail.py b/Tests/test_image_thumbnail.py index c42310c3227..d6d03577d80 100644 --- a/Tests/test_image_thumbnail.py +++ b/Tests/test_image_thumbnail.py @@ -87,7 +87,7 @@ def test_no_resize(): im.thumbnail((64, 64)) assert im.size == (64, 64) - +@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 im = Image.new("RGB", (257, 257), "red") From a6fa139f62a1e59dddfe3c742af4f372ab73e374 Mon Sep 17 00:00:00 2001 From: Eric Soroos Date: Thu, 7 Jan 2021 14:57:49 +0100 Subject: [PATCH 7/8] useless reptile --- Tests/test_file_eps.py | 1 + Tests/test_file_pdf.py | 1 + Tests/test_file_webp_metadata.py | 5 +++++ Tests/test_image_thumbnail.py | 1 + 4 files changed, 8 insertions(+) diff --git a/Tests/test_file_eps.py b/Tests/test_file_eps.py index 1d76f5917ac..1e56498ba72 100644 --- a/Tests/test_file_eps.py +++ b/Tests/test_file_eps.py @@ -58,6 +58,7 @@ def test_invalid_file(): with pytest.raises(SyntaxError): EpsImagePlugin.EpsImageFile(invalid_file) + @pytest.mark.valgrind_known_error(reason="Known Failing") @pytest.mark.skipif(not HAS_GHOSTSCRIPT, reason="Ghostscript not available") def test_cmyk(): diff --git a/Tests/test_file_pdf.py b/Tests/test_file_pdf.py index 536b9316626..e5bba483a4e 100644 --- a/Tests/test_file_pdf.py +++ b/Tests/test_file_pdf.py @@ -84,6 +84,7 @@ def test_unsupported_mode(tmp_path): with pytest.raises(ValueError): im.save(outfile) + @pytest.mark.valgrind_known_error(reason="Known Failing") def test_save_all(tmp_path): # Single frame image diff --git a/Tests/test_file_webp_metadata.py b/Tests/test_file_webp_metadata.py index 290dc036290..cb133e2c5bc 100644 --- a/Tests/test_file_webp_metadata.py +++ b/Tests/test_file_webp_metadata.py @@ -1,5 +1,7 @@ from io import BytesIO + import pytest + from PIL import Image from .helper import skip_unless_feature @@ -38,6 +40,7 @@ def test_read_exif_metadata_without_prefix(): exif = im.getexif() assert exif[305] == "Adobe Photoshop CS6 (Macintosh)" + @pytest.mark.valgrind_known_error(reason="Known Failing") def test_write_exif_metadata(): file_path = "Tests/images/flower.jpg" @@ -70,6 +73,7 @@ def test_read_icc_profile(): assert icc == expected_icc + @pytest.mark.valgrind_known_error(reason="Known Failing") def test_write_icc_metadata(): file_path = "Tests/images/flower2.jpg" @@ -87,6 +91,7 @@ def test_write_icc_metadata(): if webp_icc_profile: assert webp_icc_profile == expected_icc_profile, "Webp ICC didn't match" + @pytest.mark.valgrind_known_error(reason="Known Failing") def test_read_no_exif(): file_path = "Tests/images/flower.jpg" diff --git a/Tests/test_image_thumbnail.py b/Tests/test_image_thumbnail.py index d6d03577d80..6911ce460ed 100644 --- a/Tests/test_image_thumbnail.py +++ b/Tests/test_image_thumbnail.py @@ -87,6 +87,7 @@ def test_no_resize(): im.thumbnail((64, 64)) assert im.size == (64, 64) + @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 From 1d0149c369c077635b76c7b535854ce3b7151208 Mon Sep 17 00:00:00 2001 From: Eric Soroos Date: Thu, 7 Jan 2021 15:26:23 +0100 Subject: [PATCH 8/8] feck8 --- Tests/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/conftest.py b/Tests/conftest.py index e0f3ded1dee..6f9945204d4 100644 --- a/Tests/conftest.py +++ b/Tests/conftest.py @@ -24,7 +24,7 @@ def pytest_configure(config): warnings.simplefilter("error") try: getattr(pytest.mark, "valgrind_known_error") - except: + except Exception: config.addinivalue_line( "markers", "valgrind_known_error: Tests that have known issues with valgrind",