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 | |
parent | acb36f66dbf72e1c8c377b16bc26b5855c85aa7a (diff) | |
download | pyexiv2-9208dd96b81523096a4d1c6091123b492040d670.tar.gz |
Unit test adding comments to an empty image an reading them back.
-rwxr-xr-x | test/TestsRunner.py | 5 | ||||
-rw-r--r-- | test/usercomment.py | 37 |
2 files changed, 38 insertions, 4 deletions
diff --git a/test/TestsRunner.py b/test/TestsRunner.py index 76a4a52..8c9f41a 100755 --- a/test/TestsRunner.py +++ b/test/TestsRunner.py @@ -39,7 +39,7 @@ from metadata import TestImageMetadata from buffer import TestBuffer from encoding import TestEncodings from utils import TestConversions -from usercomment import TestUserComment +from usercomment import TestUserCommentReadWrite, TestUserCommentAdd def run_unit_tests(): @@ -56,7 +56,8 @@ def run_unit_tests(): suite.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(TestBuffer)) suite.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(TestEncodings)) suite.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(TestConversions)) - suite.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(TestUserComment)) + suite.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(TestUserCommentReadWrite)) + suite.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(TestUserCommentAdd)) # Run the test suite return unittest.TextTestRunner(verbosity=2).run(suite) 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') + |