aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Tilloy <olivier@tilloy.net>2009-04-22 09:42:17 +0200
committerOlivier Tilloy <olivier@tilloy.net>2009-04-22 09:42:17 +0200
commit80c93ece679e312215acb222e3875bcd72044fa1 (patch)
tree140ef41ca44f8a3c1b0b28d88f458772f2bad4c7
parenta957d33fcf418758942f388ae0064015a37ce291 (diff)
downloadpyexiv2-80c93ece679e312215acb222e3875bcd72044fa1.tar.gz
Dictionary-like setter for tags: unit tests.
-rw-r--r--src/pyexiv2.py2
-rw-r--r--unittest/metadata.py53
2 files changed, 52 insertions, 3 deletions
diff --git a/src/pyexiv2.py b/src/pyexiv2.py
index e550a01..677ef7e 100644
--- a/src/pyexiv2.py
+++ b/src/pyexiv2.py
@@ -1185,7 +1185,7 @@ class ImageMetadata(object):
"""
family = key.split('.')[0].lower()
try:
- return getattr(self, '_set_%s_tag' % family)(key, tag)
+ return getattr(self, '_set_%s_tag' % family)(tag)
except AttributeError:
raise KeyError(key)
diff --git a/unittest/metadata.py b/unittest/metadata.py
index 9cca766..62918c5 100644
--- a/unittest/metadata.py
+++ b/unittest/metadata.py
@@ -592,8 +592,57 @@ class TestImageMetadata(unittest.TestCase):
self.failUnlessRaises(KeyError, self.metadata.__getitem__, key)
def test_setitem(self):
- # TODO
- raise(NotImplementedError())
+ self.metadata.read()
+ self._set_exif_tags()
+ self._set_iptc_tags()
+ self._set_xmp_tags()
+ # Set new tags
+ key = 'Exif.Photo.ExposureBiasValue'
+ tag = ExifTag(key, 'ExposureBiasValue', 'Exposure Bias',
+ 'The exposure bias. The units is the APEX value. ' \
+ 'Ordinarily it is given in the range of -99.99 to 99.99.',
+ 'SRational', '0/3', '0')
+ self.metadata[key] = tag
+ self.failUnless(key in self.metadata._tags['exif'])
+ self.failUnlessEqual(self.metadata._tags['exif'][key], tag)
+ key = 'Iptc.Application2.City'
+ tag = IptcTag(key, 'City', 'City', 'Identifies city of object data ' \
+ 'origin according to guidelines established by the ' \
+ 'provider.', 'String', ['Barcelona'])
+ self.metadata[key] = tag
+ self.failUnless(key in self.metadata._tags['iptc'])
+ self.failUnlessEqual(self.metadata._tags['iptc'][key], tag)
+ key = 'Xmp.dc.description'
+ tag = XmpTag(key, 'description', 'Description', 'A textual ' \
+ 'description of the content of the resource. Multiple ' \
+ 'values may be present for different languages.',
+ 'Lang Alt', 'lang="x-default" Sunset picture.')
+ self.metadata[key] = tag
+ self.failUnless(key in self.metadata._tags['xmp'])
+ self.failUnlessEqual(self.metadata._tags['xmp'][key], tag)
+ # Replace existing tags
+ key = 'Exif.Photo.ExifVersion'
+ tag = ExifTag(key, 'ExifVersion', 'Exif Version', 'The version of ' \
+ 'this standard supported. Nonexistence of this field is' \
+ ' taken to mean nonconformance to the standard.',
+ 'Undefined', '48 50 50 48 ', '2.20')
+ self.metadata[key] = tag
+ self.failUnless(key in self.metadata._tags['exif'])
+ self.failUnlessEqual(self.metadata._tags['exif'][key], tag)
+ key = 'Iptc.Application2.Caption'
+ tag = IptcTag(key, 'Caption', 'Caption', 'A textual description of ' \
+ 'the object data.', 'String', ['Sunset on Barcelona.'])
+ self.metadata[key] = tag
+ self.failUnless(key in self.metadata._tags['iptc'])
+ self.failUnlessEqual(self.metadata._tags['iptc'][key], tag)
+ key = 'Xmp.dc.subject'
+ tag = XmpTag(key, 'subject', 'Subject', 'An unordered array of ' \
+ 'descriptive phrases or keywords that specify the topic ' \
+ 'of the content of the resource.', 'bag Text',
+ 'sunset, Barcelona, beautiful, beach')
+ self.metadata[key] = tag
+ self.failUnless(key in self.metadata._tags['xmp'])
+ self.failUnlessEqual(self.metadata._tags['xmp'][key], tag)
def test_delitem(self):
# TODO