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
|
# standard imports
import os
import unittest
# external imports
import pyexiv2
# bsie imports
from bsie.utils import errors
# objects to test
from bsie.reader.exif import Exif, Iptc
## code ##
class TestExif(unittest.TestCase):
def test_call(self):
rdr = Exif()
# discards non-image files
self.assertRaises(errors.UnsupportedFileFormatError, rdr,
os.path.join(os.path.dirname(__file__), 'invalid.doc'))
# raises on invalid image files
self.assertRaises(errors.UnsupportedFileFormatError, rdr,
os.path.join(os.path.dirname(__file__), 'invalid.jpg'))
# raises on invalid image files
pyexiv2.set_log_level(3) # suppress log message
self.assertRaises(errors.ReaderError, rdr,
os.path.join(os.path.dirname(__file__), 'testimage_exif_corrupted.jpg'))
# returns dict with exif info
self.assertDictEqual(rdr(os.path.join(os.path.dirname(__file__), 'testimage_exif.jpg')), {
'Exif.Image.Artist': 'nobody',
'Exif.Image.ExifTag': '110',
'Exif.Image.ResolutionUnit': '2',
'Exif.Image.XResolution': '300/1',
'Exif.Image.YCbCrPositioning': '1',
'Exif.Image.YResolution': '300/1',
'Exif.Photo.ColorSpace': '65535',
'Exif.Photo.ComponentsConfiguration': '1 2 3 0',
'Exif.Photo.ExifVersion': '48 50 51 50',
'Exif.Photo.FlashpixVersion': '48 49 48 48',
'Exif.Photo.ISOSpeedRatings': '200',
})
class TestIptc(unittest.TestCase):
def test_call(self):
rdr = Iptc()
# discards non-image files
self.assertRaises(errors.UnsupportedFileFormatError, rdr,
os.path.join(os.path.dirname(__file__), 'invalid.doc'))
# raises on invalid image files
self.assertRaises(errors.UnsupportedFileFormatError, rdr,
os.path.join(os.path.dirname(__file__), 'invalid.jpg'))
# raises on invalid image files
pyexiv2.set_log_level(3) # suppress log message
self.assertRaises(errors.ReaderError, rdr,
os.path.join(os.path.dirname(__file__), 'testimage_exif_corrupted.jpg'))
# returns dict with exif info
self.assertDictEqual(rdr(os.path.join(os.path.dirname(__file__), 'testimage_exif.jpg')), {
'Iptc.Application2.Keywords': ['hello', 'world'],
'Iptc.Application2.RecordVersion': '4',
})
## main ##
if __name__ == '__main__':
unittest.main()
## EOF ##
|