diff options
Diffstat (limited to 'test/xmp.py')
-rw-r--r-- | test/xmp.py | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/test/xmp.py b/test/xmp.py index cfcf2fd..147bd93 100644 --- a/test/xmp.py +++ b/test/xmp.py @@ -28,7 +28,7 @@ import unittest from pyexiv2.xmp import XmpTag, XmpValueError, register_namespace, \ unregister_namespace, unregister_namespaces -from pyexiv2.utils import FixedOffset +from pyexiv2.utils import FixedOffset, Rational, Fraction from pyexiv2.metadata import ImageMetadata import datetime @@ -283,6 +283,31 @@ class TestXmpTag(unittest.TestCase): # Invalid values self.failUnlessRaises(XmpValueError, tag._convert_to_string, None, 'URL') + def test_convert_to_python_rational(self): + # Valid values + tag = XmpTag('Xmp.xmpDM.videoPixelAspectRatio') + self.assertEqual(tag.type, 'Rational') + self.assertEqual(tag._convert_to_python('5/3', 'Rational'), Rational(5, 3)) + self.assertEqual(tag._convert_to_python('-5/3', 'Rational'), Rational(-5, 3)) + + # Invalid values + self.failUnlessRaises(XmpValueError, tag._convert_to_python, 'invalid', 'Rational') + self.failUnlessRaises(XmpValueError, tag._convert_to_python, '5 / 3', 'Rational') + self.failUnlessRaises(XmpValueError, tag._convert_to_python, '5/-3', 'Rational') + + def test_convert_to_string_rational(self): + # Valid values + tag = XmpTag('Xmp.xmpDM.videoPixelAspectRatio') + self.assertEqual(tag.type, 'Rational') + self.assertEqual(tag._convert_to_string(Rational(5, 3), 'Rational'), '5/3') + self.assertEqual(tag._convert_to_string(Rational(-5, 3), 'Rational'), '-5/3') + if Fraction is not None: + self.assertEqual(tag._convert_to_string(Fraction('1.6'), 'Rational'), '8/5') + self.assertEqual(tag._convert_to_string(Fraction('-1.6'), 'Rational'), '-8/5') + + # Invalid values + self.failUnlessRaises(XmpValueError, tag._convert_to_string, 'invalid', 'Rational') + # TODO: other types |