diff options
author | Olivier Tilloy <olivier@tilloy.net> | 2010-12-16 21:39:31 +0100 |
---|---|---|
committer | Olivier Tilloy <olivier@tilloy.net> | 2010-12-16 21:39:31 +0100 |
commit | c544e5a53ffd95e569e7664dccb18c4e9b61ad4e (patch) | |
tree | ab1e02f1097ecbc142ce72bcd3e88de291ada07d /test/usercomment.py | |
parent | 9208dd96b81523096a4d1c6091123b492040d670 (diff) | |
download | pyexiv2-c544e5a53ffd95e569e7664dccb18c4e9b61ad4e.tar.gz |
Starting from 0.20, exiv2 converts unicode comments to UTF-8.
Handle correctly all versions (≥ 0.19).
Diffstat (limited to 'test/usercomment.py')
-rw-r--r-- | test/usercomment.py | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/test/usercomment.py b/test/usercomment.py index 72c9dbb..9104fa2 100644 --- a/test/usercomment.py +++ b/test/usercomment.py @@ -48,6 +48,14 @@ class TestUserCommentReadWrite(unittest.TestCase): m.read() return m + def _expected_raw_value(self, endianness, value): + from pyexiv2 import __exiv2_version__ + if __exiv2_version__ >= '0.20': + return value + else: + encodings = {'ii': 'utf-16le', 'mm': 'utf-16be'} + return value.decode('utf-8').encode(encodings[endianness]) + def test_read_ascii(self): m = self._read_image('usercomment-ascii.jpg') tag = m['Exif.Photo.UserComment'] @@ -57,13 +65,13 @@ class TestUserCommentReadWrite(unittest.TestCase): def test_read_unicode_little_endian(self): m = self._read_image('usercomment-unicode-ii.jpg') tag = m['Exif.Photo.UserComment'] - self.assertEqual(tag.raw_value, 'charset="Unicode" d\x00\xe9\x00j\x00\xe0\x00 \x00v\x00u\x00') + self.assertEqual(tag.raw_value, 'charset="Unicode" %s' % self._expected_raw_value('ii', 'déjà vu')) self.assertEqual(tag.value, u'déjà vu') def test_read_unicode_big_endian(self): m = self._read_image('usercomment-unicode-mm.jpg') tag = m['Exif.Photo.UserComment'] - self.assertEqual(tag.raw_value, 'charset="Unicode" \x00d\x00\xe9\x00j\x00\xe0\x00 \x00v\x00u') + self.assertEqual(tag.raw_value, 'charset="Unicode" %s' % self._expected_raw_value('mm', 'déjà vu')) self.assertEqual(tag.value, u'déjà vu') def test_write_ascii(self): @@ -84,14 +92,14 @@ class TestUserCommentReadWrite(unittest.TestCase): m = self._read_image('usercomment-unicode-ii.jpg') tag = m['Exif.Photo.UserComment'] tag.value = u'DÉJÀ VU' - self.assertEqual(tag.raw_value, 'charset="Unicode" D\x00\xc9\x00J\x00\xc0\x00 \x00V\x00U\x00') + self.assertEqual(tag.raw_value, 'charset="Unicode" %s' % self._expected_raw_value('ii', 'DÉJÀ VU')) self.assertEqual(tag.value, u'DÉJÀ VU') def test_write_unicode_big_endian(self): m = self._read_image('usercomment-unicode-mm.jpg') tag = m['Exif.Photo.UserComment'] tag.value = u'DÉJÀ VU' - self.assertEqual(tag.raw_value, 'charset="Unicode" \x00D\x00\xc9\x00J\x00\xc0\x00 \x00V\x00U') + self.assertEqual(tag.raw_value, 'charset="Unicode" %s' % self._expected_raw_value('mm', 'DÉJÀ VU')) self.assertEqual(tag.value, u'DÉJÀ VU') |