class TestTryToRoman(testutils.GanetiTestCase):
"""test the compat.TryToRoman function"""
+ def setUp(self):
+ testutils.GanetiTestCase.setUp(self)
+ # Save the compat.roman module so we can alter it with a fake...
+ self.compat_roman_module = compat.roman
+
+ def tearDown(self):
+ # ...and restore it at the end of the test
+ compat.roman = self.compat_roman_module
+ testutils.GanetiTestCase.tearDown(self)
+
def testAFewIntegers(self):
+ # This test only works is the roman module is installed
+ if compat.roman is not None:
+ self.assertEquals(compat.TryToRoman(0), 0)
+ self.assertEquals(compat.TryToRoman(1), "I")
+ self.assertEquals(compat.TryToRoman(4), "IV")
+ self.assertEquals(compat.TryToRoman(5), "V")
+
+ def testWithNoRoman(self):
+ # compat.roman is saved/restored in setUp/tearDown
+ compat.roman = None
self.assertEquals(compat.TryToRoman(0), 0)
- self.assertEquals(compat.TryToRoman(1), "I")
- self.assertEquals(compat.TryToRoman(4), "IV")
- self.assertEquals(compat.TryToRoman(5), "V")
+ self.assertEquals(compat.TryToRoman(1), 1)
+ self.assertEquals(compat.TryToRoman(4), 4)
+ self.assertEquals(compat.TryToRoman(5), 5)
def testStrings(self):
self.assertEquals(compat.TryToRoman("astring"), "astring")