aboutsummaryrefslogtreecommitdiffstats
path: root/test/xmp.py
diff options
context:
space:
mode:
authorOlivier Tilloy <olivier@tilloy.net>2011-08-18 08:51:18 +0200
committerOlivier Tilloy <olivier@tilloy.net>2011-08-18 08:51:18 +0200
commit846611ba355fa09e66cee3e0253d7b364c6e7910 (patch)
tree14dfbf0ec7bb8341e8e7efe7b130ec0a1525964e /test/xmp.py
parent8db919cfb2e31409116026d76a72e82f4f0824c1 (diff)
parent235aec27487a8a247269a444be0198f6b47731cb (diff)
downloadpyexiv2-846611ba355fa09e66cee3e0253d7b364c6e7910.tar.gz
Check the type before setting an XMP tag’s value and raise a TypeError if it doesn’t match.
Allow setting the value of a LangAlt tag to a single string, in which case it is automatically converted to {'x-default': value}.
Diffstat (limited to 'test/xmp.py')
-rw-r--r--test/xmp.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/test/xmp.py b/test/xmp.py
index 7e7522e..6183277 100644
--- a/test/xmp.py
+++ b/test/xmp.py
@@ -2,7 +2,7 @@
# ******************************************************************************
#
-# Copyright (C) 2009-2010 Olivier Tilloy <olivier@tilloy.net>
+# Copyright (C) 2009-2011 Olivier Tilloy <olivier@tilloy.net>
#
# This file is part of the pyexiv2 distribution.
#
@@ -364,6 +364,24 @@ class TestXmpTag(unittest.TestCase):
self.failUnlessEqual(tag.type, 'Lang Alt')
self.failUnlessRaises(ValueError, tag._set_value, {})
+ def test_set_value_incorrect_type(self):
+ # Expecting a list of values
+ tag = XmpTag('Xmp.dc.publisher')
+ self.failUnlessEqual(tag.type, 'bag ProperName')
+ self.failUnlessRaises(TypeError, tag._set_value, None)
+ self.failUnlessRaises(TypeError, tag._set_value, 'bleh')
+ # Expecting a dictionary mapping language codes to values
+ tag = XmpTag('Xmp.dc.description')
+ self.failUnlessEqual(tag.type, 'Lang Alt')
+ self.failUnlessRaises(TypeError, tag._set_value, None)
+ self.failUnlessRaises(TypeError, tag._set_value, ['bleh'])
+
+ def test_set_value_basestring_for_langalt(self):
+ tag = XmpTag('Xmp.dc.description')
+ self.failUnlessEqual(tag.type, 'Lang Alt')
+ tag.value = 'bleh'
+ self.failUnlessEqual(tag.value, {'x-default': 'bleh'})
+
class TestXmpNamespaces(unittest.TestCase):