2
# -*- coding: utf-8 -*-
4
# ******************************************************************************
6
# Copyright (C) 2006-2007 Olivier Tilloy <olivier@tilloy.net>
8
# This file is part of the pyexiv2 distribution.
10
# pyexiv2 is free software; you can redistribute it and/or
11
# modify it under the terms of the GNU General Public License
12
# as published by the Free Software Foundation; either version 2
13
# of the License, or (at your option) any later version.
15
# pyexiv2 is distributed in the hope that it will be useful,
16
# but WITHOUT ANY WARRANTY; without even the implied warranty of
17
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
# GNU General Public License for more details.
20
# You should have received a copy of the GNU General Public License
21
# along with pyexiv2; if not, write to the Free Software
22
# Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA.
25
# File: ReadMetadataTestCase.py
26
# Author(s): Olivier Tilloy <olivier@tilloy.net>
28
# ******************************************************************************
36
class ReadMetadataTestCase(unittest.TestCase):
39
Test case on reading the metadata contained in a file.
42
def checkTypeAndValue(self, tag, etype, evalue):
44
Check the type and the value of a metadata tag against expected values.
47
tag -- the full name of the tag (eg. 'Exif.Image.DateTime')
48
etype -- the expected type of the tag value
49
evalue -- the expected value of the tag
51
self.assertEqual(tag.__class__, etype)
52
self.assertEqual(tag, evalue)
54
def testReadMetadata(self):
56
Perform various tests on reading the metadata contained in a file.
58
# Check that the reference file is not corrupted
59
filename = os.path.join('data', 'smiley1.jpg')
60
md5sum = 'c066958457c685853293058f9bf129c1'
61
self.assert_(testutils.CheckFileSum(filename, md5sum))
63
# Read the image metadata
64
image = pyexiv2.Image(filename)
67
# Exhaustive tests on the values of EXIF metadata
68
exifTags = [('Exif.Image.ImageDescription', str, 'Well it is a smiley that happens to be green'),
69
('Exif.Image.XResolution', pyexiv2.Rational, pyexiv2.Rational(72, 1)),
70
('Exif.Image.YResolution', pyexiv2.Rational, pyexiv2.Rational(72, 1)),
71
('Exif.Image.ResolutionUnit', int, 2),
72
('Exif.Image.Software', str, 'ImageReady'),
73
('Exif.Image.DateTime', datetime.datetime, datetime.datetime(2004, 7, 13, 21, 23, 44)),
74
('Exif.Image.Artist', str, 'No one'),
75
('Exif.Image.Copyright', str, ''),
76
('Exif.Image.ExifTag', long, 226L),
77
('Exif.Photo.Flash', int, 80),
78
('Exif.Photo.PixelXDimension', long, 167L),
79
('Exif.Photo.PixelYDimension', long, 140L)]
80
self.assertEqual(image.exifKeys(), [tag[0] for tag in exifTags])
82
self.checkTypeAndValue(image[tag[0]], tag[1], tag[2])
84
# Exhaustive tests on the values of IPTC metadata
85
iptcTags = [('Iptc.Application2.Caption', str, 'yelimS green faced dude (iptc caption)'),
86
('Iptc.Application2.Writer', str, 'Nobody'),
87
('Iptc.Application2.Byline', str, 'Its me'),
88
('Iptc.Application2.ObjectName', str, 'GreeenDude'),
89
('Iptc.Application2.DateCreated', datetime.date, datetime.date(2004, 7, 13)),
90
('Iptc.Application2.City', str, 'Seattle'),
91
('Iptc.Application2.ProvinceState', str, 'WA'),
92
('Iptc.Application2.CountryName', str, 'USA'),
93
('Iptc.Application2.Category', str, 'Things'),
94
('Iptc.Application2.Keywords', tuple, ('Green', 'Smiley', 'Dude')),
95
('Iptc.Application2.Copyright', str, '\xa9 2004 Nobody')]
96
self.assertEqual(image.iptcKeys(), [tag[0] for tag in iptcTags])
98
self.checkTypeAndValue(image[tag[0]], tag[1], tag[2])
100
# Test on the JPEG comment
101
self.checkTypeAndValue(image.getComment(),
102
str, 'This is a jpeg comment, about the green smiley.')