diff options
author | Olivier Tilloy <olivier@tilloy.net> | 2010-12-15 20:20:25 +0100 |
---|---|---|
committer | Olivier Tilloy <olivier@tilloy.net> | 2010-12-15 20:20:25 +0100 |
commit | 9208dd96b81523096a4d1c6091123b492040d670 (patch) | |
tree | f99275dc00c41eff1f8cbff1536b547bb890d7d0 /test/usercomment.py | |
parent | acb36f66dbf72e1c8c377b16bc26b5855c85aa7a (diff) | |
download | pyexiv2-9208dd96b81523096a4d1c6091123b492040d670.tar.gz |
Unit test adding comments to an empty image an reading them back.
Diffstat (limited to 'test/usercomment.py')
-rw-r--r-- | test/usercomment.py | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/test/usercomment.py b/test/usercomment.py index 651224d..72c9dbb 100644 --- a/test/usercomment.py +++ b/test/usercomment.py @@ -28,10 +28,12 @@ from pyexiv2.metadata import ImageMetadata import unittest import testutils -import os.path +import os +import tempfile +from metadata import EMPTY_JPG_DATA -class TestUserComment(unittest.TestCase): +class TestUserCommentReadWrite(unittest.TestCase): checksums = { 'usercomment-ascii.jpg': 'ad29ac65fb6f63c8361aaed6cb02f8c7', @@ -92,3 +94,34 @@ class TestUserComment(unittest.TestCase): self.assertEqual(tag.raw_value, 'charset="Unicode" \x00D\x00\xc9\x00J\x00\xc0\x00 \x00V\x00U') self.assertEqual(tag.value, u'DÉJÀ VU') + +class TestUserCommentAdd(unittest.TestCase): + + def setUp(self): + # Create an empty image file + fd, self.pathname = tempfile.mkstemp(suffix='.jpg') + os.write(fd, EMPTY_JPG_DATA) + os.close(fd) + + def tearDown(self): + os.remove(self.pathname) + + def _test_add_comment(self, value): + metadata = ImageMetadata(self.pathname) + metadata.read() + key = 'Exif.Photo.UserComment' + metadata[key] = value + metadata.write() + + metadata = ImageMetadata(self.pathname) + metadata.read() + self.assert_(key in metadata.exif_keys) + tag = metadata[key] + self.assertEqual(tag.value, value) + + def test_add_comment_ascii(self): + self._test_add_comment('deja vu') + + def test_add_comment_unicode(self): + self._test_add_comment(u'déjà vu') + |