Skip to content

Commit

Permalink
Merge branch 'python-pillow:main' into gif-seek-optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
AnonymouX47 committed Feb 21, 2022
2 parents aaf18a7 + 9e6537d commit 1890f8a
Show file tree
Hide file tree
Showing 28 changed files with 272 additions and 198 deletions.
18 changes: 18 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@ Changelog (Pillow)
9.1.0 (unreleased)
------------------

- Added FITS reading #6056
[radarhere, hugovk]

- Added rawmode argument to Image.getpalette() #6061
[radarhere]

- Fixed BUFR, GRIB and HDF5 stub saving #6071
[radarhere]

- Do not automatically remove temporary ImageShow files on Unix #6045
[radarhere]

- Correctly read JPEG compressed BLP images #4685
[Meithal, radarhere]

- Merged _MODE_CONV typ into ImageMode as typestr #6057
[radarhere]

- Consider palette size when converting and in getpalette() #6060
[radarhere]

Expand Down
Binary file modified Tests/images/hopper.fits
Binary file not shown.
9 changes: 3 additions & 6 deletions Tests/test_bmp_reference.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os

import pytest
import warnings

from PIL import Image

Expand All @@ -20,16 +19,14 @@ def test_bad():
either"""
for f in get_files("b"):

with pytest.warns(None) as record:
# Assert that there is no unclosed file warning
with warnings.catch_warnings():
try:
with Image.open(f) as im:
im.load()
except Exception: # as msg:
pass

# Assert that there is no unclosed file warning
assert not record


def test_questionable():
"""These shouldn't crash/dos, but it's not well defined that these
Expand Down
10 changes: 4 additions & 6 deletions Tests/test_file_dcx.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import warnings

import pytest

from PIL import DcxImagePlugin, Image
Expand Down Expand Up @@ -31,21 +33,17 @@ def open():


def test_closed_file():
with pytest.warns(None) as record:
with warnings.catch_warnings():
im = Image.open(TEST_FILE)
im.load()
im.close()

assert not record


def test_context_manager():
with pytest.warns(None) as record:
with warnings.catch_warnings():
with Image.open(TEST_FILE) as im:
im.load()

assert not record


def test_invalid_file():
with open("Tests/images/flower.jpg", "rb") as fp:
Expand Down
80 changes: 80 additions & 0 deletions Tests/test_file_fits.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
from io import BytesIO

import pytest

from PIL import FitsImagePlugin, FitsStubImagePlugin, Image

from .helper import assert_image_equal, hopper

TEST_FILE = "Tests/images/hopper.fits"


def test_open():
# Act
with Image.open(TEST_FILE) as im:

# Assert
assert im.format == "FITS"
assert im.size == (128, 128)
assert im.mode == "L"

assert_image_equal(im, hopper("L"))


def test_invalid_file():
# Arrange
invalid_file = "Tests/images/flower.jpg"

# Act / Assert
with pytest.raises(SyntaxError):
FitsImagePlugin.FitsImageFile(invalid_file)


def test_truncated_fits():
# No END to headers
image_data = b"SIMPLE = T" + b" " * 50 + b"TRUNCATE"
with pytest.raises(OSError):
FitsImagePlugin.FitsImageFile(BytesIO(image_data))


def test_naxis_zero():
# This test image has been manually hexedited
# to set the number of data axes to zero
with pytest.raises(ValueError):
with Image.open("Tests/images/hopper_naxis_zero.fits"):
pass


def test_stub_deprecated():
class Handler:
opened = False
loaded = False

def open(self, im):
self.opened = True

def load(self, im):
self.loaded = True
return Image.new("RGB", (1, 1))

handler = Handler()
with pytest.warns(DeprecationWarning):
FitsStubImagePlugin.register_handler(handler)

with Image.open(TEST_FILE) as im:
assert im.format == "FITS"
assert im.size == (128, 128)
assert im.mode == "L"

assert handler.opened
assert not handler.loaded

im.load()
assert handler.loaded

FitsStubImagePlugin._handler = None
Image.register_open(
FitsImagePlugin.FitsImageFile.format,
FitsImagePlugin.FitsImageFile,
FitsImagePlugin._accept,
)
63 changes: 0 additions & 63 deletions Tests/test_file_fitsstub.py

This file was deleted.

10 changes: 4 additions & 6 deletions Tests/test_file_fli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import warnings

import pytest

from PIL import FliImagePlugin, Image
Expand Down Expand Up @@ -38,21 +40,17 @@ def open():


def test_closed_file():
with pytest.warns(None) as record:
with warnings.catch_warnings():
im = Image.open(static_test_file)
im.load()
im.close()

assert not record


def test_context_manager():
with pytest.warns(None) as record:
with warnings.catch_warnings():
with Image.open(static_test_file) as im:
im.load()

assert not record


def test_tell():
# Arrange
Expand Down
9 changes: 3 additions & 6 deletions Tests/test_file_gif.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
from io import BytesIO

import pytest
Expand Down Expand Up @@ -39,21 +40,17 @@ def open():


def test_closed_file():
with pytest.warns(None) as record:
with warnings.catch_warnings():
im = Image.open(TEST_GIF)
im.load()
im.close()

assert not record


def test_context_manager():
with pytest.warns(None) as record:
with warnings.catch_warnings():
with Image.open(TEST_GIF) as im:
im.load()

assert not record


def test_invalid_file():
invalid_file = "Tests/images/flower.jpg"
Expand Down
4 changes: 2 additions & 2 deletions Tests/test_file_icns.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import io
import os
import warnings

import pytest

Expand All @@ -19,9 +20,8 @@ def test_sanity():
with Image.open(TEST_FILE) as im:

# Assert that there is no unclosed file warning
with pytest.warns(None) as record:
with warnings.catch_warnings():
im.load()
assert not record

assert im.mode == "RGBA"
assert im.size == (1024, 1024)
Expand Down
9 changes: 3 additions & 6 deletions Tests/test_file_im.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import filecmp
import warnings

import pytest

Expand Down Expand Up @@ -35,21 +36,17 @@ def open():


def test_closed_file():
with pytest.warns(None) as record:
with warnings.catch_warnings():
im = Image.open(TEST_IM)
im.load()
im.close()

assert not record


def test_context_manager():
with pytest.warns(None) as record:
with warnings.catch_warnings():
with Image.open(TEST_IM) as im:
im.load()

assert not record


def test_tell():
# Arrange
Expand Down
4 changes: 2 additions & 2 deletions Tests/test_file_jpeg.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import re
import warnings
from io import BytesIO

import pytest
Expand Down Expand Up @@ -756,9 +757,8 @@ def test_exif_x_resolution(self, tmp_path):
assert exif[282] == 180

out = str(tmp_path / "out.jpg")
with pytest.warns(None) as record:
with warnings.catch_warnings():
im.save(out, exif=exif)
assert not record

with Image.open(out) as reloaded:
assert reloaded.getexif()[282] == 180
Expand Down
9 changes: 3 additions & 6 deletions Tests/test_file_mpo.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
from io import BytesIO

import pytest
Expand Down Expand Up @@ -41,21 +42,17 @@ def open():


def test_closed_file():
with pytest.warns(None) as record:
with warnings.catch_warnings():
im = Image.open(test_files[0])
im.load()
im.close()

assert not record


def test_context_manager():
with pytest.warns(None) as record:
with warnings.catch_warnings():
with Image.open(test_files[0]) as im:
im.load()

assert not record


def test_app():
for test_file in test_files:
Expand Down
4 changes: 2 additions & 2 deletions Tests/test_file_png.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import re
import sys
import warnings
import zlib
from io import BytesIO

Expand Down Expand Up @@ -331,9 +332,8 @@ def test_load_verify(self):

with Image.open(TEST_PNG_FILE) as im:
# Assert that there is no unclosed file warning
with pytest.warns(None) as record:
with warnings.catch_warnings():
im.verify()
assert not record

with Image.open(TEST_PNG_FILE) as im:
im.load()
Expand Down

0 comments on commit 1890f8a

Please sign in to comment.