mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-14 05:36:48 +03:00
24183d652e
for more information, see https://pre-commit.ci
69 lines
1.2 KiB
Python
69 lines
1.2 KiB
Python
import sys
|
|
from io import StringIO
|
|
|
|
from PIL import Image, IptcImagePlugin
|
|
|
|
from .helper import hopper
|
|
|
|
TEST_FILE = "Tests/images/iptc.jpg"
|
|
|
|
|
|
def test_getiptcinfo_jpg_none():
|
|
# Arrange
|
|
with hopper() as im:
|
|
# Act
|
|
iptc = IptcImagePlugin.getiptcinfo(im)
|
|
|
|
# Assert
|
|
assert iptc is None
|
|
|
|
|
|
def test_getiptcinfo_jpg_found():
|
|
# Arrange
|
|
with Image.open(TEST_FILE) as im:
|
|
# Act
|
|
iptc = IptcImagePlugin.getiptcinfo(im)
|
|
|
|
# Assert
|
|
assert isinstance(iptc, dict)
|
|
assert iptc[(2, 90)] == b"Budapest"
|
|
assert iptc[(2, 101)] == b"Hungary"
|
|
|
|
|
|
def test_getiptcinfo_tiff_none():
|
|
# Arrange
|
|
with Image.open("Tests/images/hopper.tif") as im:
|
|
# Act
|
|
iptc = IptcImagePlugin.getiptcinfo(im)
|
|
|
|
# Assert
|
|
assert iptc is None
|
|
|
|
|
|
def test_i():
|
|
# Arrange
|
|
c = b"a"
|
|
|
|
# Act
|
|
ret = IptcImagePlugin.i(c)
|
|
|
|
# Assert
|
|
assert ret == 97
|
|
|
|
|
|
def test_dump():
|
|
# Arrange
|
|
c = b"abc"
|
|
# Temporarily redirect stdout
|
|
old_stdout = sys.stdout
|
|
sys.stdout = mystdout = StringIO()
|
|
|
|
# Act
|
|
IptcImagePlugin.dump(c)
|
|
|
|
# Reset stdout
|
|
sys.stdout = old_stdout
|
|
|
|
# Assert
|
|
assert mystdout.getvalue() == "61 62 63 \n"
|