aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/pyexiv2.py13
-rw-r--r--unittest/metadata.py35
2 files changed, 36 insertions, 12 deletions
diff --git a/src/pyexiv2.py b/src/pyexiv2.py
index 1aec66f..c66c73c 100644
--- a/src/pyexiv2.py
+++ b/src/pyexiv2.py
@@ -1098,13 +1098,20 @@ class ImageMetadata(object):
tag.metadata = self
def _set_iptc_tag_values(self, key, values):
- # Overwrite the tag value for an already existing tag.
+ # Overwrite the tag values for an already existing tag.
# The tag is already in cache.
# Warning: this is not meant to be called directly as it doesn't update
# the internal cache (which would leave the object in an inconsistent
# state).
- # TODO
- raise NotImplementedError()
+ # FIXME: this is sub-optimal as it sets all the values regardless of how
+ # many of them really changed. Need to implement the same method with an
+ # index/range parameter (here and in the C++ wrapper).
+ if key not in self.iptc_keys:
+ raise KeyError('Cannot set the value of an inexistent tag')
+ if type(values) is not list or not \
+ reduce(lambda x, y: x and type(y) is str, values, True):
+ raise TypeError('Expecting a list of strings')
+ self._image.setIptcTagValues(key, values)
def _set_xmp_tag(self, tag):
# TODO
diff --git a/unittest/metadata.py b/unittest/metadata.py
index abc6770..0fc3b4c 100644
--- a/unittest/metadata.py
+++ b/unittest/metadata.py
@@ -372,17 +372,34 @@ class TestImageMetadata(unittest.TestCase):
self.assertEqual(self.metadata._image.tags['iptc'][key],
new_tag.raw_value)
- def test_set_iptc_tag_value_inexistent(self):
- # TODO
- raise(NotImplementedError())
+ def test_set_iptc_tag_values_inexistent(self):
+ self.metadata.read()
+ self._set_iptc_tags()
+ key = 'Iptc.Application2.Urgency'
+ values = ['1']
+ self.failUnlessRaises(KeyError, self.metadata._set_iptc_tag_values,
+ key, values)
- def test_set_iptc_tag_value_wrong_type(self):
- # TODO
- raise(NotImplementedError())
+ def test_set_iptc_tag_values_wrong_type(self):
+ self.metadata.read()
+ self._set_iptc_tags()
+ key = 'Iptc.Application2.DateCreated'
+ value = '20090324'
+ self.failUnlessRaises(TypeError, self.metadata._set_iptc_tag_values,
+ key, value)
+ values = [datetime.date(2009, 3, 24)]
+ self.failUnlessRaises(TypeError, self.metadata._set_iptc_tag_values,
+ key, values)
- def test_set_iptc_tag_value(self):
- # TODO
- raise(NotImplementedError())
+ def test_set_iptc_tag_values(self):
+ self.metadata.read()
+ self._set_iptc_tags()
+ key = 'Iptc.Application2.DateCreated'
+ tag = self.metadata._get_iptc_tag(key)
+ values = ['2009-04-07']
+ self.failIfEqual(self.metadata._image.tags['iptc'][key], values)
+ self.metadata._set_iptc_tag_values(key, values)
+ self.assertEqual(self.metadata._image.tags['iptc'][key], values)
def test_delete_iptc_tag_inexistent(self):
# TODO