Pillow/Tests/test_file_iptc.py

72 lines
1.2 KiB
Python
Raw Normal View History

2019-09-26 15:12:28 +03:00
import sys
from io import StringIO
2014-07-30 20:34:20 +04:00
from PIL import Image, IptcImagePlugin
2020-01-27 14:46:52 +03:00
from .helper import hopper
2014-07-30 20:34:20 +04:00
TEST_FILE = "Tests/images/iptc.jpg"
2020-01-27 14:46:52 +03:00
def test_getiptcinfo_jpg_none():
# Arrange
with hopper() as im:
2014-07-30 20:34:20 +04:00
2020-01-27 14:46:52 +03:00
# Act
iptc = IptcImagePlugin.getiptcinfo(im)
2014-07-30 20:34:20 +04:00
2020-01-27 14:46:52 +03:00
# Assert
assert iptc is None
2014-07-30 20:34:20 +04:00
2020-01-27 14:46:52 +03:00
def test_getiptcinfo_jpg_found():
# Arrange
with Image.open(TEST_FILE) as im:
2014-07-30 20:34:20 +04:00
2020-01-27 14:46:52 +03:00
# Act
iptc = IptcImagePlugin.getiptcinfo(im)
2017-03-01 12:20:18 +03:00
2020-01-27 14:46:52 +03:00
# Assert
assert isinstance(iptc, dict)
assert iptc[(2, 90)] == b"Budapest"
assert iptc[(2, 101)] == b"Hungary"
2017-03-01 12:20:18 +03:00
2020-01-27 14:46:52 +03:00
def test_getiptcinfo_tiff_none():
# Arrange
with Image.open("Tests/images/hopper.tif") as im:
2014-07-30 20:34:20 +04:00
# Act
2020-01-27 14:46:52 +03:00
iptc = IptcImagePlugin.getiptcinfo(im)
2014-07-30 20:34:20 +04:00
2020-01-27 14:46:52 +03:00
# Assert
assert iptc is None
2014-07-30 20:34:20 +04:00
2014-08-01 12:56:21 +04:00
2020-01-27 14:46:52 +03:00
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)
2014-08-01 12:56:21 +04:00
2020-01-27 14:46:52 +03:00
# Reset stdout
sys.stdout = old_stdout
2014-08-01 12:56:21 +04:00
2020-01-27 14:46:52 +03:00
# Assert
assert mystdout.getvalue() == "61 62 63 \n"