From 8febdad8dd51ad5c75a1db78492973588c7cbf6b Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Thu, 1 Apr 2021 17:41:46 +0300 Subject: [PATCH] Review, typos and lint --- Tests/test_file_blp.py | 3 ++- Tests/test_file_eps.py | 5 ++--- Tests/test_file_psd.py | 11 +++++++++-- Tests/test_file_tiff.py | 5 ++--- src/PIL/ImageFile.py | 4 +--- src/PIL/PsdImagePlugin.py | 1 + src/libImaging/FliDecode.c | 2 +- 7 files changed, 18 insertions(+), 13 deletions(-) diff --git a/Tests/test_file_blp.py b/Tests/test_file_blp.py index 6f6634251..15bd7e4f8 100644 --- a/Tests/test_file_blp.py +++ b/Tests/test_file_blp.py @@ -1,6 +1,7 @@ -from PIL import Image import pytest +from PIL import Image + from .helper import assert_image_equal_tofile diff --git a/Tests/test_file_eps.py b/Tests/test_file_eps.py index e616ffa0c..7caac34c3 100644 --- a/Tests/test_file_eps.py +++ b/Tests/test_file_eps.py @@ -1,4 +1,5 @@ import io + import pytest from PIL import EpsImagePlugin, Image, features @@ -268,9 +269,7 @@ def test_emptyline(): @pytest.mark.timeout(timeout=5) @pytest.mark.parametrize( "test_file", - [ - ("Tests/images/timeout-d675703545fee17acab56e5fec644c19979175de.eps") - ], + ["Tests/images/timeout-d675703545fee17acab56e5fec644c19979175de.eps"], ) def test_timeout(test_file): with open(test_file, "rb") as f: diff --git a/Tests/test_file_psd.py b/Tests/test_file_psd.py index 8c58310bd..bf2a5fea0 100644 --- a/Tests/test_file_psd.py +++ b/Tests/test_file_psd.py @@ -131,11 +131,18 @@ def test_combined_larger_than_size(): with Image.open("Tests/images/combined_larger_than_size.psd"): pass + @pytest.mark.parametrize( "test_file,raises", [ - ("Tests/images/timeout-1ee28a249896e05b83840ae8140622de8e648ba9.psd", Image.UnidentifiedImageError), - ("Tests/images/timeout-598843abc37fc080ec36a2699ebbd44f795d3a6f.psd", Image.UnidentifiedImageError), + ( + "Tests/images/timeout-1ee28a249896e05b83840ae8140622de8e648ba9.psd", + Image.UnidentifiedImageError, + ), + ( + "Tests/images/timeout-598843abc37fc080ec36a2699ebbd44f795d3a6f.psd", + Image.UnidentifiedImageError, + ), ("Tests/images/timeout-c8efc3fded6426986ba867a399791bae544f59bc.psd", OSError), ("Tests/images/timeout-dedc7a4ebd856d79b4359bbcc79e8ef231ce38f6.psd", OSError), ], diff --git a/Tests/test_file_tiff.py b/Tests/test_file_tiff.py index 1bc46ee30..c24438c48 100644 --- a/Tests/test_file_tiff.py +++ b/Tests/test_file_tiff.py @@ -625,12 +625,11 @@ class TestFileTiff: ) def test_string_dimension(self): # Assert that an error is raised if one of the dimensions is a string - with pytest.raises(OSError): - with Image.open("Tests/images/string_dimension.tiff") as im: + with Image.open("Tests/images/string_dimension.tiff") as im: + with pytest.raises(OSError): im.load() - @pytest.mark.skipif(not is_win32(), reason="Windows only") class TestFileTiffW32: def test_fd_leak(self, tmp_path): diff --git a/src/PIL/ImageFile.py b/src/PIL/ImageFile.py index 2ed1520fd..0258a2ec1 100644 --- a/src/PIL/ImageFile.py +++ b/src/PIL/ImageFile.py @@ -547,7 +547,7 @@ def _safe_read(fp, size): :param size: Number of bytes to read. :returns: A string containing size bytes of data. - Raises an OSError if the file is truncated and the read can not be completed + Raises an OSError if the file is truncated and the read cannot be completed """ if size <= 0: @@ -569,8 +569,6 @@ def _safe_read(fp, size): return b"".join(data) - - class PyCodecState: def __init__(self): self.xsize = 0 diff --git a/src/PIL/PsdImagePlugin.py b/src/PIL/PsdImagePlugin.py index 96de58fe7..e7b884674 100644 --- a/src/PIL/PsdImagePlugin.py +++ b/src/PIL/PsdImagePlugin.py @@ -171,6 +171,7 @@ class PsdImageFile(ImageFile.ImageFile): finally: self.__fp = None + def _layerinfo(fp, ct_bytes): # read layerinfo block layers = [] diff --git a/src/libImaging/FliDecode.c b/src/libImaging/FliDecode.c index 35a6ccccc..3a6030703 100644 --- a/src/libImaging/FliDecode.c +++ b/src/libImaging/FliDecode.c @@ -244,7 +244,7 @@ ImagingFliDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t byt } advance = I32(ptr); if (advance == 0 ) { - // If there's no advance, we're in in infinite loop + // If there's no advance, we're in an infinite loop state->errcode = IMAGING_CODEC_BROKEN; return -1; }