~osomon/pyexiv2/pyexiv2-0.3

« back to all changes in this revision

Viewing changes to test/utils.py

  • Committer: Olivier Tilloy
  • Date: 2010-12-26 18:51:16 UTC
  • mto: This revision was merged to the branch mainline in revision 348.
  • Revision ID: olivier@tilloy.net-20101226185116-8abareh34iuep6js
New convenience function to factorize further the code that handles fractions: fraction_to_string(...).

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
import unittest
28
28
 
29
29
from pyexiv2.utils import undefined_to_string, string_to_undefined, \
30
 
                          Rational, Fraction, is_fraction, make_fraction
 
30
                          Rational, Fraction, \
 
31
                          is_fraction, make_fraction, fraction_to_string
31
32
 
32
33
 
33
34
class TestConversions(unittest.TestCase):
88
89
        self.assertRaises(TypeError, make_fraction, 5, 3, 2)
89
90
        self.assertRaises(TypeError, make_fraction, None)
90
91
 
 
92
    def test_fraction_to_string(self):
 
93
        self.assertEqual(fraction_to_string(make_fraction(3, 5)), '3/5')
 
94
        self.assertEqual(fraction_to_string(make_fraction(-3, 5)), '-3/5')
 
95
        self.assertEqual(fraction_to_string(make_fraction(0, 1)), '0/1')
 
96
        self.assertRaises(TypeError, fraction_to_string, None)
 
97
        self.assertRaises(TypeError, fraction_to_string, 'invalid')
 
98