aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Tilloy <olivier@tilloy.net>2010-11-30 20:48:22 +0100
committerOlivier Tilloy <olivier@tilloy.net>2010-11-30 20:48:22 +0100
commit9b18a14ed49351304e1ac4d63d1a6411d22bb1a0 (patch)
treece626e165d33ace30ccfa02229fefe61b7619f1c
parent95ed963c2cdbdeff64fc70168d44ac9e47d051d2 (diff)
downloadpyexiv2-9b18a14ed49351304e1ac4d63d1a6411d22bb1a0.tar.gz
Unit tests for Rational conversions in XMP tags.
-rw-r--r--test/xmp.py27
1 files changed, 26 insertions, 1 deletions
diff --git a/test/xmp.py b/test/xmp.py
index 10e03a8..845b048 100644
--- a/test/xmp.py
+++ b/test/xmp.py
@@ -27,7 +27,7 @@
import unittest
from pyexiv2.xmp import XmpTag, XmpValueError
-from pyexiv2.utils import FixedOffset
+from pyexiv2.utils import FixedOffset, Rational, Fraction
import datetime
@@ -281,6 +281,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