diff options
author | Olivier Tilloy <olivier@tilloy.net> | 2009-03-26 09:59:08 +0100 |
---|---|---|
committer | Olivier Tilloy <olivier@tilloy.net> | 2009-03-26 09:59:08 +0100 |
commit | 938d8711997d22301718d3a181d638267abb0ef6 (patch) | |
tree | cfdb3d954d1622429d5a132d30f7f6f2220cb08b /unittest | |
parent | c3d3594126d448f12060a584abc622fd2148560d (diff) | |
download | pyexiv2-938d8711997d22301718d3a181d638267abb0ef6.tar.gz |
Delete an EXIF tag.
Diffstat (limited to 'unittest')
-rw-r--r-- | unittest/exif.py | 24 | ||||
-rw-r--r-- | unittest/metadata.py | 37 |
2 files changed, 59 insertions, 2 deletions
diff --git a/unittest/exif.py b/unittest/exif.py index 1ce1d3c..6b463fd 100644 --- a/unittest/exif.py +++ b/unittest/exif.py @@ -36,6 +36,12 @@ class ImageMetadataMock(object): def _set_exif_tag_value(self, key, value): self.tags[key] = value + def _delete_exif_tag(self, key): + try: + del self.tags[key] + except KeyError: + pass + class TestExifTag(unittest.TestCase): @@ -221,3 +227,21 @@ class TestExifTag(unittest.TestCase): tag.value = 2 self.failIfEqual(tag.value, old_value) self.assertEqual(tag.metadata.tags[tag.key], '2') + + def test_del_value_no_metadata(self): + tag = ExifTag('Exif.Thumbnail.Orientation', 'Orientation', + 'Orientation', 'The image orientation viewed in terms ' \ + 'of rows and columns.', 'Short', '1', 'top, left') + del tag.value + self.failIf(hasattr(tag, 'value')) + + def test_del_value_with_metadata(self): + tag = ExifTag('Exif.Thumbnail.Orientation', 'Orientation', + 'Orientation', 'The image orientation viewed in terms ' \ + 'of rows and columns.', 'Short', '1', 'top, left') + tag.metadata = ImageMetadataMock() + tag.metadata._set_exif_tag_value(tag.key, tag.to_string()) + self.assertEqual(tag.metadata.tags, {tag.key: '1'}) + del tag.value + self.failIf(hasattr(tag, 'value')) + self.failIf(tag.metadata.tags.has_key(tag.key)) diff --git a/unittest/metadata.py b/unittest/metadata.py index 1055c85..029774a 100644 --- a/unittest/metadata.py +++ b/unittest/metadata.py @@ -52,6 +52,12 @@ class ImageMock(object): def setExifTag(self, key, value): self.tags['exif'][key] = value + def deleteExifTag(self, key): + try: + del self.tags['exif'][key] + except KeyError: + pass + def iptcKeys(self): return self.tags['iptc'].keys() @@ -197,11 +203,11 @@ class TestImageMetadata(unittest.TestCase): self.assertEqual(self.metadata._image.tags['exif'][tag.key], tag.raw_value) - def test_set_exif_tag_overwrite_already_gotten(self): + def test_set_exif_tag_overwrite_already_cached(self): self.metadata.read() self._set_exif_tags() self.assertEqual(self.metadata._tags['exif'], {}) - # Overwrite an existing tag already gotten + # Overwrite an existing tag already cached key = 'Exif.Photo.ExifVersion' tag = self.metadata._get_exif_tag(key) self.assertEqual(self.metadata._tags['exif'][key], tag) @@ -242,6 +248,33 @@ class TestImageMetadata(unittest.TestCase): self.metadata._set_exif_tag_value(key, value) self.assertEqual(self.metadata._image.tags['exif'][key], value) + def test_delete_exif_tag_inexistent(self): + self.metadata.read() + self._set_exif_tags() + key = 'Exif.Image.Artist' + self.failUnlessRaises(KeyError, self.metadata._delete_exif_tag, key) + + def test_delete_exif_tag_not_cached(self): + self.metadata.read() + self._set_exif_tags() + key = 'Exif.Image.DateTime' + self.assertEqual(self.metadata._tags['exif'], {}) + self.assert_(self.metadata._image.tags['exif'].has_key(key)) + self.metadata._delete_exif_tag(key) + self.assertEqual(self.metadata._tags['exif'], {}) + self.failIf(self.metadata._image.tags['exif'].has_key(key)) + + def test_delete_exif_tag_cached(self): + self.metadata.read() + self._set_exif_tags() + key = 'Exif.Image.DateTime' + self.assert_(self.metadata._image.tags['exif'].has_key(key)) + tag = self.metadata._get_exif_tag(key) + self.assertEqual(self.metadata._tags['exif'][key], tag) + self.metadata._delete_exif_tag(key) + self.assertEqual(self.metadata._tags['exif'], {}) + self.failIf(self.metadata._image.tags['exif'].has_key(key)) + def test_iptc_keys(self): self.metadata.read() self._set_iptc_tags() |