mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-11 04:07:21 +03:00
7da17ad41e
The previous test configuration made it difficult to run a single test with the pytest CLI. There were two major issues: - The Tests directory was not a package. It now includes a __init__.py file and imports from other tests modules are done with relative imports. - setup.cfg always specified the Tests directory. So even if a specific test were specified as a CLI arg, this configuration would also always include all tests. This configuration has been removed to allow specifying a single test on the command line. Contributors can now run specific tests with a single command such as: $ tox -e py37 -- Tests/test_file_pdf.py::TestFilePdf.test_rgb This makes it easy and faster to iterate on a single test failure and is very familiar to those that have previously used tox and pytest. When running tox or pytest with no arguments, they still discover and runs all tests in the Tests directory.
89 lines
2.7 KiB
Python
89 lines
2.7 KiB
Python
from .helper import unittest, PillowTestCase, hopper
|
|
|
|
import io
|
|
from PIL import Image, IcoImagePlugin
|
|
|
|
TEST_ICO_FILE = "Tests/images/hopper.ico"
|
|
|
|
|
|
class TestFileIco(PillowTestCase):
|
|
|
|
def test_sanity(self):
|
|
im = Image.open(TEST_ICO_FILE)
|
|
im.load()
|
|
self.assertEqual(im.mode, "RGBA")
|
|
self.assertEqual(im.size, (16, 16))
|
|
self.assertEqual(im.format, "ICO")
|
|
|
|
def test_invalid_file(self):
|
|
with open("Tests/images/flower.jpg", "rb") as fp:
|
|
self.assertRaises(SyntaxError,
|
|
IcoImagePlugin.IcoImageFile, fp)
|
|
|
|
def test_save_to_bytes(self):
|
|
output = io.BytesIO()
|
|
im = hopper()
|
|
im.save(output, "ico", sizes=[(32, 32), (64, 64)])
|
|
|
|
# the default image
|
|
output.seek(0)
|
|
reloaded = Image.open(output)
|
|
self.assertEqual(reloaded.info['sizes'], {(32, 32), (64, 64)})
|
|
|
|
self.assertEqual(im.mode, reloaded.mode)
|
|
self.assertEqual((64, 64), reloaded.size)
|
|
self.assertEqual(reloaded.format, "ICO")
|
|
self.assert_image_equal(reloaded,
|
|
hopper().resize((64, 64), Image.LANCZOS))
|
|
|
|
# the other one
|
|
output.seek(0)
|
|
reloaded = Image.open(output)
|
|
reloaded.size = (32, 32)
|
|
|
|
self.assertEqual(im.mode, reloaded.mode)
|
|
self.assertEqual((32, 32), reloaded.size)
|
|
self.assertEqual(reloaded.format, "ICO")
|
|
self.assert_image_equal(reloaded,
|
|
hopper().resize((32, 32), Image.LANCZOS))
|
|
|
|
def test_incorrect_size(self):
|
|
im = Image.open(TEST_ICO_FILE)
|
|
with self.assertRaises(ValueError):
|
|
im.size = (1, 1)
|
|
|
|
def test_save_256x256(self):
|
|
"""Issue #2264 https://github.com/python-pillow/Pillow/issues/2264"""
|
|
# Arrange
|
|
im = Image.open("Tests/images/hopper_256x256.ico")
|
|
outfile = self.tempfile("temp_saved_hopper_256x256.ico")
|
|
|
|
# Act
|
|
im.save(outfile)
|
|
im_saved = Image.open(outfile)
|
|
|
|
# Assert
|
|
self.assertEqual(im_saved.size, (256, 256))
|
|
|
|
def test_only_save_relevant_sizes(self):
|
|
"""Issue #2266 https://github.com/python-pillow/Pillow/issues/2266
|
|
Should save in 16x16, 24x24, 32x32, 48x48 sizes
|
|
and not in 16x16, 24x24, 32x32, 48x48, 48x48, 48x48, 48x48 sizes
|
|
"""
|
|
# Arrange
|
|
im = Image.open("Tests/images/python.ico") # 16x16, 32x32, 48x48
|
|
outfile = self.tempfile("temp_saved_python.ico")
|
|
|
|
# Act
|
|
im.save(outfile)
|
|
im_saved = Image.open(outfile)
|
|
|
|
# Assert
|
|
self.assertEqual(
|
|
im_saved.info['sizes'],
|
|
{(16, 16), (24, 24), (32, 32), (48, 48)})
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|