aboutsummaryrefslogtreecommitdiffstats
path: root/unittest/exif.py
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/exif.py
parent4b0b859dd1d0884da54d633cf6dec8c5f4d8318f (diff)
downloadpyexiv2-3c23acdb070d2c3230f3ecf497b4fbd760f5a10e.tar.gz
EXIF Rational and SRational conversion.
Diffstat (limited to 'unittest/exif.py')
-rw-r--r--unittest/exif.py38
1 files changed, 37 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