aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Tilloy <olivier@tilloy.net>2009-04-08 09:29:34 +0200
committerOlivier Tilloy <olivier@tilloy.net>2009-04-08 09:29:34 +0200
commitf47b027237b1081818615d18ee0475ca8a4663d3 (patch)
tree342aaccf98c99e2765019a67d0839554ee898cb3
parent958ad5168aaf8b8b01c1bd664eea591818e32d04 (diff)
downloadpyexiv2-f47b027237b1081818615d18ee0475ca8a4663d3.tar.gz
Delete an IPTC tag.
-rw-r--r--src/pyexiv2.py10
-rw-r--r--unittest/metadata.py33
2 files changed, 35 insertions, 8 deletions
diff --git a/src/pyexiv2.py b/src/pyexiv2.py
index c66c73c..014b58f 100644
--- a/src/pyexiv2.py
+++ b/src/pyexiv2.py
@@ -1149,8 +1149,14 @@ class ImageMetadata(object):
pass
def _delete_iptc_tag(self, key):
- # TODO
- raise NotImplementedError()
+ if key not in self.iptc_keys:
+ raise KeyError('Cannot delete an inexistent tag')
+ self._image.deleteIptcTag(key)
+ try:
+ del self._tags['iptc'][key]
+ except KeyError:
+ # The tag was not cached.
+ pass
def _delete_xmp_tag(self, key):
# TODO
diff --git a/unittest/metadata.py b/unittest/metadata.py
index 0fc3b4c..ade5599 100644
--- a/unittest/metadata.py
+++ b/unittest/metadata.py
@@ -67,6 +67,12 @@ class ImageMock(object):
def setIptcTagValues(self, key, values):
self.tags['iptc'][key] = values
+ def deleteIptcTag(self, key):
+ try:
+ del self.tags['iptc'][key]
+ except KeyError:
+ pass
+
def xmpKeys(self):
return self.tags['xmp'].keys()
@@ -402,16 +408,31 @@ class TestImageMetadata(unittest.TestCase):
self.assertEqual(self.metadata._image.tags['iptc'][key], values)
def test_delete_iptc_tag_inexistent(self):
- # TODO
- raise(NotImplementedError())
+ self.metadata.read()
+ self._set_iptc_tags()
+ key = 'Iptc.Application2.LocationCode'
+ self.failUnlessRaises(KeyError, self.metadata._delete_iptc_tag, key)
def test_delete_iptc_tag_not_cached(self):
- # TODO
- raise(NotImplementedError())
+ self.metadata.read()
+ self._set_iptc_tags()
+ key = 'Iptc.Application2.Caption'
+ self.assertEqual(self.metadata._tags['iptc'], {})
+ self.assert_(self.metadata._image.tags['iptc'].has_key(key))
+ self.metadata._delete_iptc_tag(key)
+ self.assertEqual(self.metadata._tags['iptc'], {})
+ self.failIf(self.metadata._image.tags['iptc'].has_key(key))
def test_delete_iptc_tag_cached(self):
- # TODO
- raise(NotImplementedError())
+ self.metadata.read()
+ self._set_iptc_tags()
+ key = 'Iptc.Application2.Caption'
+ self.assert_(self.metadata._image.tags['iptc'].has_key(key))
+ tag = self.metadata._get_iptc_tag(key)
+ self.assertEqual(self.metadata._tags['iptc'][key], tag)
+ self.metadata._delete_iptc_tag(key)
+ self.assertEqual(self.metadata._tags['iptc'], {})
+ self.failIf(self.metadata._image.tags['iptc'].has_key(key))
##########################
# Test XMP-related methods