diff --git a/test/ganeti.compat_unittest.py b/test/ganeti.compat_unittest.py index dbe9940e71403666d44c1d7f94f216a50b01172b..54a1c626f93ca9139b9d368a1028cf4fd7426af1 100755 --- a/test/ganeti.compat_unittest.py +++ b/test/ganeti.compat_unittest.py @@ -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")