diff options
author | Olivier Tilloy <olivier@tilloy.net> | 2010-05-21 20:35:46 +0200 |
---|---|---|
committer | Olivier Tilloy <olivier@tilloy.net> | 2010-05-21 20:35:46 +0200 |
commit | 299b446e7a286c2486be81680fbdd024d852627e (patch) | |
tree | 7b1e096bb846c05770d590c50405ba36e7817643 /test/metadata.py | |
parent | fb7521b48430c3a1733464f87e2bd1ec789a0b7e (diff) | |
parent | 59797a333d118cf12ba5d16a89993e5e85938f18 (diff) | |
download | pyexiv2-299b446e7a286c2486be81680fbdd024d852627e.tar.gz |
Get, set and delete the image comment.
This was a regression compared to the 0.1.x series.
Diffstat (limited to 'test/metadata.py')
-rw-r--r-- | test/metadata.py | 51 |
1 files changed, 44 insertions, 7 deletions
diff --git a/test/metadata.py b/test/metadata.py index 86935ce..98be0be 100644 --- a/test/metadata.py +++ b/test/metadata.py @@ -36,18 +36,31 @@ import tempfile import unittest -EMPTY_PNG_DATA = \ - '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x01\x00\x00\x00\x01\x08' \ - '\x02\x00\x00\x00\x90wS\xde\x00\x00\x00\x0cIDATx\x9cc```\x00\x00\x00\x04' \ - '\x00\x01\xf6\x178U\x00\x00\x00\x00IEND\xaeB`\x82' +EMPTY_JPG_DATA = \ + '\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x01\x00H\x00H\x00\x00\xff\xdb' \ + '\x00C\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff' \ + '\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff' \ + '\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff' \ + '\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xc0\x00\x0b\x08' \ + '\x00\x01\x00\x01\x01\x01\x11\x00\xff\xc4\x00\x1f\x00\x00\x01\x05\x01\x01' \ + '\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x01\x02\x03\x04\x05\x06' \ + '\x07\x08\t\n\x0b\xff\xc4\x00\xb5\x10\x00\x02\x01\x03\x03\x02\x04\x03\x05' \ + '\x05\x04\x04\x00\x00\x01}\x01\x02\x03\x00\x04\x11\x05\x12!1A\x06\x13Qa' \ + '\x07"q\x142\x81\x91\xa1\x08#B\xb1\xc1\x15R\xd1\xf0$3br\x82\t\n\x16\x17' \ + "\x18\x19\x1a%&\'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz\x83\x84\x85" \ + '\x86\x87\x88\x89\x8a\x92\x93\x94\x95\x96\x97\x98\x99\x9a\xa2\xa3\xa4\xa5' \ + '\xa6\xa7\xa8\xa9\xaa\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xc2\xc3\xc4\xc5' \ + '\xc6\xc7\xc8\xc9\xca\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xe1\xe2\xe3\xe4' \ + '\xe5\xe6\xe7\xe8\xe9\xea\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xff\xda' \ + '\x00\x08\x01\x01\x00\x00?\x00\x92\xbf\xff\xd9' class TestImageMetadata(unittest.TestCase): def setUp(self): # Create an empty image file - fd, self.pathname = tempfile.mkstemp(suffix='.png') - os.write(fd, EMPTY_PNG_DATA) + fd, self.pathname = tempfile.mkstemp(suffix='.jpg') + os.write(fd, EMPTY_JPG_DATA) os.close(fd) # Write some metadata m = ImageMetadata(self.pathname) @@ -58,6 +71,7 @@ class TestImageMetadata(unittest.TestCase): m['Iptc.Application2.DateCreated'] = [datetime.date(2004, 7, 13)] m['Xmp.dc.format'] = ('image', 'jpeg') m['Xmp.dc.subject'] = ['image', 'test', 'pyexiv2'] + m.comment = 'Hello World!' m.write() self.metadata = ImageMetadata(self.pathname) @@ -477,12 +491,33 @@ class TestImageMetadata(unittest.TestCase): for key in keys: self.failUnlessRaises(KeyError, self.metadata.__delitem__, key) + ########################## + # Test the image comment # + ########################## + + def test_get_comment(self): + self.metadata.read() + self.failUnlessEqual(self.metadata.comment, 'Hello World!') + + def test_set_comment(self): + self.metadata.read() + comment = 'Welcome to the real world.' + self.metadata.comment = comment + self.failUnlessEqual(self.metadata.comment, comment) + self.metadata.comment = None + self.failUnlessEqual(self.metadata.comment, '') + + def test_delete_comment(self): + self.metadata.read() + del self.metadata.comment + self.failUnlessEqual(self.metadata.comment, '') + #################### # Test metadata copy #################### def _set_up_other(self): - self.other = ImageMetadata.from_buffer(EMPTY_PNG_DATA) + self.other = ImageMetadata.from_buffer(EMPTY_JPG_DATA) def test_copy_metadata(self): self.metadata.read() @@ -511,3 +546,5 @@ class TestImageMetadata(unittest.TestCase): for key in self.metadata.xmp_keys: self.failUnlessEqual(self.metadata[key].value, self.other[key].value) + self.failUnlessEqual(self.metadata.comment, self.other.comment) + |