Commit 855bffd2 authored by Guido Trotter's avatar Guido Trotter
Browse files

Fix and Improve TryToRoman unittest



1) Don't break when the roman module is not found
2) Test that not finding the roman module doesn't make TryToRoman fail
(currently that is the case)
Signed-off-by: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent e2736e40
......@@ -61,11 +61,31 @@ class TestPartial(testutils.GanetiTestCase):
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")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment