lint stuff

This commit is contained in:
Eric Soroos 2021-04-10 16:58:01 +02:00
parent af6fb9c518
commit 1c872a9eda
10 changed files with 79 additions and 34 deletions

View File

@ -180,8 +180,10 @@ def mark_if_feature_version(mark, feature, version_blacklist, reason=None):
reason = f"{feature} is {version_blacklist}" reason = f"{feature} is {version_blacklist}"
version_required = parse_version(version_blacklist) version_required = parse_version(version_blacklist)
version_available = parse_version(features.version(feature)) version_available = parse_version(features.version(feature))
if (version_available.major == version_required.major and if (
version_available.minor == version_required.minor): version_available.major == version_required.major
and version_available.minor == version_required.minor
):
return mark(reason=reason) return mark(reason=reason)
return pytest.mark.pil_noop_mark() return pytest.mark.pil_noop_mark()

View File

@ -9,10 +9,13 @@ from PIL import Image, features
if sys.platform.startswith("win32"): if sys.platform.startswith("win32"):
pytest.skip("Fuzzer is linux only", allow_module_level=True) pytest.skip("Fuzzer is linux only", allow_module_level=True)
if features.check('libjpeg_turbo'): if features.check("libjpeg_turbo"):
version = packaging.version.parse(features.version('libjpeg_turbo')) version = packaging.version.parse(features.version("libjpeg_turbo"))
if version.major == 2 and version.minor == 0: if version.major == 2 and version.minor == 0:
pytestmark = pytest.mark.valgrind_known_error(reason="Known failing with libjpeg_turbo 2.0") pytestmark = pytest.mark.valgrind_known_error(
reason="Known failing with libjpeg_turbo 2.0"
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
"path", "path",

View File

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

View File

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

View File

@ -17,8 +17,8 @@ from .helper import (
assert_image_similar, assert_image_similar,
assert_image_similar_tofile, assert_image_similar_tofile,
hopper, hopper,
skip_unless_feature,
mark_if_feature_version, mark_if_feature_version,
skip_unless_feature,
) )
@ -823,13 +823,17 @@ class TestFileLibTiff(LibTiffTestCase):
with Image.open(infile) as im: with Image.open(infile) as im:
assert_image_similar_tofile(im, "Tests/images/pil_sample_cmyk.jpg", 0.5) assert_image_similar_tofile(im, "Tests/images/pil_sample_cmyk.jpg", 0.5)
@mark_if_feature_version(pytest.mark.valgrind_known_error, 'libjpeg_turbo', '2.0', 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): def test_strip_ycbcr_jpeg_2x2_sampling(self):
infile = "Tests/images/tiff_strip_ycbcr_jpeg_2x2_sampling.tif" infile = "Tests/images/tiff_strip_ycbcr_jpeg_2x2_sampling.tif"
with Image.open(infile) as im: with Image.open(infile) as im:
assert_image_similar_tofile(im, "Tests/images/flower.jpg", 0.5) assert_image_similar_tofile(im, "Tests/images/flower.jpg", 0.5)
@mark_if_feature_version(pytest.mark.valgrind_known_error, 'libjpeg_turbo', '2.0', 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): def test_strip_ycbcr_jpeg_1x1_sampling(self):
infile = "Tests/images/tiff_strip_ycbcr_jpeg_1x1_sampling.tif" infile = "Tests/images/tiff_strip_ycbcr_jpeg_1x1_sampling.tif"
with Image.open(infile) as im: with Image.open(infile) as im:
@ -840,13 +844,17 @@ class TestFileLibTiff(LibTiffTestCase):
with Image.open(infile) as im: with Image.open(infile) as im:
assert_image_similar_tofile(im, "Tests/images/pil_sample_cmyk.jpg", 0.5) assert_image_similar_tofile(im, "Tests/images/pil_sample_cmyk.jpg", 0.5)
@mark_if_feature_version(pytest.mark.valgrind_known_error, 'libjpeg_turbo', '2.0', 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): def test_tiled_ycbcr_jpeg_1x1_sampling(self):
infile = "Tests/images/tiff_tiled_ycbcr_jpeg_1x1_sampling.tif" infile = "Tests/images/tiff_tiled_ycbcr_jpeg_1x1_sampling.tif"
with Image.open(infile) as im: with Image.open(infile) as im:
assert_image_equal_tofile(im, "Tests/images/flower2.jpg") assert_image_equal_tofile(im, "Tests/images/flower2.jpg")
@mark_if_feature_version(pytest.mark.valgrind_known_error, 'libjpeg_turbo', '2.0', 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): def test_tiled_ycbcr_jpeg_2x2_sampling(self):
infile = "Tests/images/tiff_tiled_ycbcr_jpeg_2x2_sampling.tif" infile = "Tests/images/tiff_tiled_ycbcr_jpeg_2x2_sampling.tif"
with Image.open(infile) as im: with Image.open(infile) as im:

View File

@ -11,7 +11,6 @@ from PIL import Image, PdfParser
from .helper import hopper, mark_if_feature_version from .helper import hopper, mark_if_feature_version
def helper_save_as_pdf(tmp_path, mode, **kwargs): def helper_save_as_pdf(tmp_path, mode, **kwargs):
# Arrange # Arrange
im = hopper(mode) im = hopper(mode)
@ -86,7 +85,9 @@ def test_unsupported_mode(tmp_path):
im.save(outfile) im.save(outfile)
@mark_if_feature_version(pytest.mark.valgrind_known_error, 'libjpeg_turbo', '2.0', 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): def test_save_all(tmp_path):
# Single frame image # Single frame image
helper_save_as_pdf(tmp_path, "RGB", save_all=True) helper_save_as_pdf(tmp_path, "RGB", save_all=True)

View File

@ -13,8 +13,8 @@ from .helper import (
hopper, hopper,
is_big_endian, is_big_endian,
is_win32, is_win32,
skip_unless_feature,
mark_if_feature_version, mark_if_feature_version,
skip_unless_feature,
) )
# sample png stream # sample png stream
@ -680,7 +680,9 @@ class TestFilePng:
exif = reloaded._getexif() exif = reloaded._getexif()
assert exif[274] == 1 assert exif[274] == 1
@mark_if_feature_version(pytest.mark.valgrind_known_error, 'libjpeg_turbo', '2.0', 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): def test_exif_from_jpg(self, tmp_path):
with Image.open("Tests/images/pil_sample_rgb.jpg") as im: with Image.open("Tests/images/pil_sample_rgb.jpg") as im:
test_file = str(tmp_path / "temp.png") test_file = str(tmp_path / "temp.png")

View File

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

View File

@ -16,8 +16,8 @@ from .helper import (
assert_not_all_same, assert_not_all_same,
hopper, hopper,
is_win32, is_win32,
skip_unless_feature,
mark_if_feature_version, mark_if_feature_version,
skip_unless_feature,
) )
@ -663,7 +663,9 @@ class TestImage:
assert not fp.closed assert not fp.closed
@mark_if_feature_version(pytest.mark.valgrind_known_error, 'libjpeg_turbo', '2.0', 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): def test_exif_jpeg(self, tmp_path):
with Image.open("Tests/images/exif-72dpi-int.jpg") as im: # Little endian with Image.open("Tests/images/exif-72dpi-int.jpg") as im: # Little endian
exif = im.getexif() exif = im.getexif()

View File

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