-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
test_file_iptc.py
71 lines (47 loc) · 1.19 KB
/
test_file_iptc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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"