aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Tilloy <olivier@tilloy.net>2009-01-26 09:23:02 +0100
committerOlivier Tilloy <olivier@tilloy.net>2009-01-26 09:23:02 +0100
commit8ad3455085286b470e000b927b9dea3a6d35c2ab (patch)
tree29844fbfbf24b551b76f5fce9c03756a0b412e36
parent5df2b0deb5c6fb13e9401b4fb3f4accdee1711b4 (diff)
downloadpyexiv2-8ad3455085286b470e000b927b9dea3a6d35c2ab.tar.gz
XMP Text conversion + unit tests.
-rw-r--r--src/pyexiv2.py8
-rw-r--r--unittest/xmp.py14
2 files changed, 19 insertions, 3 deletions
diff --git a/src/pyexiv2.py b/src/pyexiv2.py
index 2147c93..d746a83 100644
--- a/src/pyexiv2.py
+++ b/src/pyexiv2.py
@@ -594,9 +594,13 @@ class XmpTag(MetadataTag):
elif xtype == 'Real':
# TODO
return value
+
elif xtype == 'Text':
- # TODO
- return value
+ try:
+ return unicode(value, 'utf-8')
+ except TypeError:
+ return value
+
elif xtype == 'Thumbnail':
# TODO
return value
diff --git a/unittest/xmp.py b/unittest/xmp.py
index 7f8f916..8663f64 100644
--- a/unittest/xmp.py
+++ b/unittest/xmp.py
@@ -127,6 +127,18 @@ class TestXmpTag(unittest.TestCase):
# Invalid values
self.assertEqual(XmpTag._convert_to_python('invalid', xtype), 'invalid')
self.assertEqual(XmpTag._convert_to_python('image-jpeg', xtype), 'image-jpeg')
-
+
+ def test_convert_to_python_text(self):
+ xtype = 'Text'
+ # Valid values
+ self.assertEqual(XmpTag._convert_to_python('Some text.', xtype), u'Some text.')
+ self.assertEqual(XmpTag._convert_to_python(u'Some text.', xtype), u'Some text.')
+ self.assertEqual(XmpTag._convert_to_python('Some text with exotic chàräctérʐ.', xtype),
+ u'Some text with exotic chàräctérʐ.')
+ self.assertEqual(XmpTag._convert_to_python(u'Some text with exotic chàräctérʐ.', xtype),
+ u'Some text with exotic chàräctérʐ.')
+ # Invalid values
+ self.assertEqual(XmpTag._convert_to_python(12, xtype), 12)
+ self.assertEqual(XmpTag._convert_to_python(3.14, xtype), 3.14)
# TODO: other types