From 855bffd2c91ade0dc0ca91549030d9617a36b545 Mon Sep 17 00:00:00 2001
From: Guido Trotter <ultrotter@google.com>
Date: Tue, 1 Jun 2010 11:45:30 +0100
Subject: [PATCH] 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: Guido Trotter <ultrotter@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>
---
 test/ganeti.compat_unittest.py | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/test/ganeti.compat_unittest.py b/test/ganeti.compat_unittest.py
index dbe9940e7..54a1c626f 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")
-- 
GitLab