From 8ad3455085286b470e000b927b9dea3a6d35c2ab Mon Sep 17 00:00:00 2001 From: Olivier Tilloy Date: Mon, 26 Jan 2009 09:23:02 +0100 Subject: XMP Text conversion + unit tests. --- src/pyexiv2.py | 8 ++++++-- unittest/xmp.py | 14 +++++++++++++- 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 -- cgit