diff options
author | Olivier Tilloy <olivier@tilloy.net> | 2011-05-24 11:18:41 +0200 |
---|---|---|
committer | Olivier Tilloy <olivier@tilloy.net> | 2011-05-24 11:18:41 +0200 |
commit | 8d5aabc65a460ecb9e5f1275bc83bf784333afb2 (patch) | |
tree | f853d8c10387ac077d5cac524b673c73eb363deb /test | |
parent | fb0e651326f38481cf04908b4a3547bf36b5aefd (diff) | |
download | pyexiv2-8d5aabc65a460ecb9e5f1275bc83bf784333afb2.tar.gz |
Do not fail to parse rationals stored as '0/0'.
In the crazy world of EXIF metadata, this means a null fraction, i.e. 0/1.
Diffstat (limited to 'test')
-rw-r--r-- | test/rational.py | 12 | ||||
-rw-r--r-- | test/utils.py | 2 |
2 files changed, 14 insertions, 0 deletions
diff --git a/test/rational.py b/test/rational.py index 1ee5670..bff8e5f 100644 --- a/test/rational.py +++ b/test/rational.py @@ -52,6 +52,16 @@ class TestRational(unittest.TestCase): else: self.fail('Denominator is not read-only.') + def test_match_string(self): + self.assertEqual(Rational.match_string('4/3'), (4, 3)) + self.assertEqual(Rational.match_string('-4/3'), (-4, 3)) + self.assertEqual(Rational.match_string('0/3'), (0, 3)) + self.assertEqual(Rational.match_string('0/0'), (0, 0)) + self.assertRaises(ValueError, Rational.match_string, '+3/5') + self.assertRaises(ValueError, Rational.match_string, '3 / 5') + self.assertRaises(ValueError, Rational.match_string, '3/-5') + self.assertRaises(ValueError, Rational.match_string, 'invalid') + def test_from_string(self): self.assertEqual(Rational.from_string('4/3'), Rational(4, 3)) self.assertEqual(Rational.from_string('-4/3'), Rational(-4, 3)) @@ -59,6 +69,8 @@ class TestRational(unittest.TestCase): self.assertRaises(ValueError, Rational.from_string, '3 / 5') self.assertRaises(ValueError, Rational.from_string, '3/-5') self.assertRaises(ValueError, Rational.from_string, 'invalid') + self.assertRaises(ZeroDivisionError, Rational.from_string, '1/0') + self.assertRaises(ZeroDivisionError, Rational.from_string, '0/0') def test_to_string(self): self.assertEqual(str(Rational(3, 5)), '3/5') diff --git a/test/utils.py b/test/utils.py index 11b1766..0b55254 100644 --- a/test/utils.py +++ b/test/utils.py @@ -78,11 +78,13 @@ class TestFractions(unittest.TestCase): self.assertEqual(make_fraction(-3, 5), Fraction(-3, 5)) self.assertEqual(make_fraction('3/2'), Fraction(3, 2)) self.assertEqual(make_fraction('-3/4'), Fraction(-3, 4)) + self.assertEqual(make_fraction('0/0'), Fraction(0, 1)) else: self.assertEqual(make_fraction(3, 5), Rational(3, 5)) self.assertEqual(make_fraction(-3, 5), Rational(-3, 5)) self.assertEqual(make_fraction('3/2'), Rational(3, 2)) self.assertEqual(make_fraction('-3/4'), Rational(-3, 4)) + self.assertEqual(make_fraction('0/0'), Rational(0, 1)) self.assertRaises(ZeroDivisionError, make_fraction, 3, 0) self.assertRaises(ZeroDivisionError, make_fraction, '3/0') |