forked from hMatoba/EXIF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
128 lines (109 loc) · 3.84 KB
/
test.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import io
import os
try:
import unittest2 as unittest
except ImportError:
import unittest
from PIL import Image
from EXIF import Exif, ZerothIFD, ExifIFD, GPSIFD, _ExifReader
EXIF_DICT = {
ZerothIFD.ProcessingSoftware: "PIL", # ascii
ZerothIFD.Make: "Make", # ascii
ZerothIFD.Model: "XXX-XXX", # ascii
ZerothIFD.JPEGTables: b"\xaa\xaa", # undefined
ZerothIFD.ClipPath: 255, # byte
ZerothIFD.Rating: 65535, # short
ZerothIFD.XClipPathUnits: 4294967295, # long
ZerothIFD.XResolution: (4294967295, 1), # rational
ZerothIFD.CameraCalibration1: (2147483647, -2147483648), # srational
ZerothIFD.BlackLevelDeltaH: ((1, 1), (1, 1), (1, 1), ), # srational
ExifIFD.DateTimeOriginal: "2099:09:29 10:10:10", # ascii
ExifIFD.LensMake: "LM", # ascii
ExifIFD.OECF: b"\xaa\xaa\xaa\xaa\xaa\xaa", # undefined
ExifIFD.Sharpness: 65535, # short
ExifIFD.ISOSpeed: 4294967295, # long
ExifIFD.ExposureTime: (4294967295, 1), # rational
ExifIFD.ExposureBiasValue: (2147483647, -2147483648), # srational
ExifIFD.LensSpecification: ((1, 1), (1, 1), (1, 1), (1, 1), ), # rational
ZerothIFD.GPSTag: {
GPSIFD.GPSVersionID: 255, # byte
GPSIFD.GPSDateStamp: "1999:99:99 99:99:99", # ascii
GPSIFD.GPSDifferential: 65535, # short
GPSIFD.GPSLatitude: (4294967295, 1), # rational
}
}
INPUT_FILE_JPG = os.path.join("images", "01.jpg")
INPUT_FILE_TIF = os.path.join("images", "01.tif")
class ExifTests(unittest.TestCase):
def test_roundtrip(self):
exif = Exif(EXIF_DICT)
exif.load(exif.to_bytes())
exif.pop(34665) # Exif IFD pointer
self.assertDictEqual(exif, EXIF_DICT)
def test_file_generate(self):
f = io.BytesIO()
exif = Exif(EXIF_DICT)
im1 = Image.new("RGBA", (16, 16))
im1.save(f, format="JPEG", exif=exif.to_bytes())
f.seek(0)
im2 = Image.open(f)
im2.close()
def test_no_exif_file_generate(self):
f = io.BytesIO()
exif = Exif()
im1 = Image.new("RGBA", (16, 16))
im1.save(f, format="JPEG", exif=exif.to_bytes())
f.seek(0)
im2 = Image.open(f)
im2.close()
def test_ExifReader(self):
with self.assertRaises(ValueError):
_ExifReader("dummy")
with self.assertRaises(ValueError):
e = _ExifReader(b"Exif\x00\x00")
e.get_info((100, 1, b"dummy"))
def test_Exif(self):
with self.assertRaises(ValueError):
Exif(0)
exif = Exif()
self.assertDictEqual(exif, {})
exif2 = Exif(exif.to_bytes())
self.assertDictEqual(exif2, {})
def test_load_jpg(self):
f = io.BytesIO()
exif = Exif(INPUT_FILE_JPG)
im1 = Image.new("RGBA", (16, 16))
im1.save(f, format="JPEG", exif=exif.to_bytes())
f.seek(0)
im2 = Image.open(f)
im2.close()
def test_load_tif(self):
f = io.BytesIO()
exif = Exif(INPUT_FILE_TIF)
im1 = Image.new("RGBA", (16, 16))
im1.save(f, format="JPEG", exif=exif.to_bytes())
f.seek(0)
im2 = Image.open(f)
im2.close()
def test_load_jpeg_on_memory(self):
with open(INPUT_FILE_JPG, "rb") as f:
data = f.read()
f = io.BytesIO()
exif = Exif(data)
im1 = Image.new("RGBA", (16, 16))
im1.save(f, format="JPEG", exif=exif.to_bytes())
f.seek(0)
im2 = Image.open(f)
im2.close()
def test_load_tif_on_memory(self):
with open(INPUT_FILE_TIF, "rb") as f:
data = f.read()
f = io.BytesIO()
exif = Exif(data)
im1 = Image.new("RGBA", (16, 16))
im1.save(f, format="JPEG", exif=exif.to_bytes())
f.seek(0)
im2 = Image.open(f)
im2.close()
if __name__ == "__main__":
unittest.main()