aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorOlivier Tilloy <olivier@tilloy.net>2010-12-16 21:39:31 +0100
committerOlivier Tilloy <olivier@tilloy.net>2010-12-16 21:39:31 +0100
commitc544e5a53ffd95e569e7664dccb18c4e9b61ad4e (patch)
treeab1e02f1097ecbc142ce72bcd3e88de291ada07d /test
parent9208dd96b81523096a4d1c6091123b492040d670 (diff)
downloadpyexiv2-c544e5a53ffd95e569e7664dccb18c4e9b61ad4e.tar.gz
Starting from 0.20, exiv2 converts unicode comments to UTF-8.
Handle correctly all versions (≥ 0.19).
Diffstat (limited to 'test')
-rw-r--r--test/exif.py6
-rw-r--r--test/usercomment.py16
2 files changed, 15 insertions, 7 deletions
diff --git a/test/exif.py b/test/exif.py
index f1496e9..1f929b7 100644
--- a/test/exif.py
+++ b/test/exif.py
@@ -135,10 +135,10 @@ class TestExifTag(unittest.TestCase):
tag = ExifTag('Exif.Photo.UserComment')
self.assertEqual(tag.type, 'Comment')
self.assertEqual(tag._convert_to_python('A comment'), 'A comment')
- charsets = ('Ascii', 'Jis', 'Unicode', 'Undefined', 'InvalidCharsetId')
- for charset in charsets:
+ for charset in ('Ascii', 'Jis', 'Unicode', 'Undefined', 'InvalidCharsetId'):
self.assertEqual(tag._convert_to_python('charset="%s" A comment' % charset), 'A comment')
- self.failIfEqual(tag._convert_to_python('charset="%s" déjà vu' % charset), 'déjà vu')
+ for charset in ('Ascii', 'Jis', 'Undefined', 'InvalidCharsetId'):
+ self.failIfEqual(tag._convert_to_python('charset="%s" déjà vu' % charset), u'déjà vu')
def test_convert_to_string_comment(self):
# Valid values
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')