aboutsummaryrefslogtreecommitdiffstats
path: root/unittest
diff options
context:
space:
mode:
authorOlivier Tilloy <olivier@tilloy.net>2009-03-09 09:19:16 +0100
committerOlivier Tilloy <olivier@tilloy.net>2009-03-09 09:19:16 +0100
commit3c23acdb070d2c3230f3ecf497b4fbd760f5a10e (patch)
treeed4b492f1a821fb315f4fd55439b4300df179a6a /unittest
parent4b0b859dd1d0884da54d633cf6dec8c5f4d8318f (diff)
downloadpyexiv2-3c23acdb070d2c3230f3ecf497b4fbd760f5a10e.tar.gz
EXIF Rational and SRational conversion.
Diffstat (limited to 'unittest')
-rw-r--r--unittest/exif.py38
-rw-r--r--unittest/rational.py4
2 files changed, 41 insertions, 1 deletions
diff --git a/unittest/exif.py b/unittest/exif.py
index 86eab63..0f7df8f 100644
--- a/unittest/exif.py
+++ b/unittest/exif.py
@@ -25,7 +25,7 @@
# ******************************************************************************
import unittest
-from pyexiv2 import ExifTag, ExifValueError
+from pyexiv2 import ExifTag, ExifValueError, Rational
import datetime
@@ -129,6 +129,42 @@ class TestExifTag(unittest.TestCase):
self.failUnlessRaises(ExifValueError, ExifTag._convert_to_string, 'invalid', xtype)
self.failUnlessRaises(ExifValueError, ExifTag._convert_to_string, 3.14, xtype)
+ def test_convert_to_python_rational(self):
+ xtype = 'Rational'
+ # Valid values
+ self.assertEqual(ExifTag._convert_to_python('5/3', xtype, None), Rational(5, 3))
+ # Invalid values
+ self.failUnlessRaises(ExifValueError, ExifTag._convert_to_python, 'invalid', xtype, None)
+ self.failUnlessRaises(ExifValueError, ExifTag._convert_to_python, '-5/3', xtype, None)
+ self.failUnlessRaises(ExifValueError, ExifTag._convert_to_python, '5 / 3', xtype, None)
+ self.failUnlessRaises(ExifValueError, ExifTag._convert_to_python, '5/-3', xtype, None)
+
+ def test_convert_to_string_rational(self):
+ xtype = 'Rational'
+ # Valid values
+ self.assertEqual(ExifTag._convert_to_string(Rational(5, 3), xtype), '5/3')
+ # Invalid values
+ self.failUnlessRaises(ExifValueError, ExifTag._convert_to_string, 'invalid', xtype)
+ self.failUnlessRaises(ExifValueError, ExifTag._convert_to_string, Rational(-5, 3), xtype)
+
+ def test_convert_to_python_srational(self):
+ xtype = 'SRational'
+ # Valid values
+ self.assertEqual(ExifTag._convert_to_python('5/3', xtype, None), Rational(5, 3))
+ self.assertEqual(ExifTag._convert_to_python('-5/3', xtype, None), Rational(-5, 3))
+ # Invalid values
+ self.failUnlessRaises(ExifValueError, ExifTag._convert_to_python, 'invalid', xtype, None)
+ self.failUnlessRaises(ExifValueError, ExifTag._convert_to_python, '5 / 3', xtype, None)
+ self.failUnlessRaises(ExifValueError, ExifTag._convert_to_python, '5/-3', xtype, None)
+
+ def test_convert_to_string_srational(self):
+ xtype = 'SRational'
+ # Valid values
+ self.assertEqual(ExifTag._convert_to_string(Rational(5, 3), xtype), '5/3')
+ self.assertEqual(ExifTag._convert_to_string(Rational(-5, 3), xtype), '-5/3')
+ # Invalid values
+ self.failUnlessRaises(ExifValueError, ExifTag._convert_to_string, 'invalid', xtype)
+
def test_convert_to_python_undefined(self):
xtype = 'Undefined'
# Valid values
diff --git a/unittest/rational.py b/unittest/rational.py
index f475846..81edfb9 100644
--- a/unittest/rational.py
+++ b/unittest/rational.py
@@ -44,6 +44,10 @@ class TestRational(unittest.TestCase):
self.assertRaises(ValueError, Rational.from_string, '3/-5')
self.assertRaises(ValueError, Rational.from_string, 'invalid')
+ def test_to_string(self):
+ self.assertEqual(str(Rational(3, 5)), '3/5')
+ self.assertEqual(str(Rational(-3, 5)), '-3/5')
+
def test_equality(self):
r1 = Rational(2, 1)
r2 = Rational(2, 1)