Add list of design documents implemented in version 2.6
[ganeti-local] / test / testutils.py
index 3c46a0c..1a47a66 100644 (file)
@@ -27,6 +27,7 @@ import stat
 import tempfile
 import unittest
 import logging
+import types
 
 from ganeti import utils
 
@@ -78,6 +79,18 @@ class GanetiTestProgram(unittest.TestProgram):
     else:
       raise Exception("Assertion not evaluated")
 
+    # The following piece of code is a backport from Python 2.6. Python 2.4/2.5
+    # only accept class instances as test runners. Being able to pass classes
+    # reduces the amount of code necessary for using a custom test runner.
+    # 2.6 and above should use their own code, however.
+    if (self.testRunner and sys.hexversion < 0x2060000 and
+        isinstance(self.testRunner, (type, types.ClassType))):
+      try:
+        self.testRunner = self.testRunner(verbosity=self.verbosity)
+      except TypeError:
+        # didn't accept the verbosity argument
+        self.testRunner = self.testRunner()
+
     return unittest.TestProgram.runTests(self)
 
 
@@ -123,6 +136,32 @@ class GanetiTestCase(unittest.TestCase):
     actual_mode = stat.S_IMODE(st.st_mode)
     self.assertEqual(actual_mode, expected_mode)
 
+  def assertFileUid(self, file_name, expected_uid):
+    """Checks that the user id of a file is what we expect.
+
+    @type file_name: str
+    @param file_name: the file whose contents we should check
+    @type expected_uid: int
+    @param expected_uid: the user id we expect
+
+    """
+    st = os.stat(file_name)
+    actual_uid = st.st_uid
+    self.assertEqual(actual_uid, expected_uid)
+
+  def assertFileGid(self, file_name, expected_gid):
+    """Checks that the group id of a file is what we expect.
+
+    @type file_name: str
+    @param file_name: the file whose contents we should check
+    @type expected_gid: int
+    @param expected_gid: the group id we expect
+
+    """
+    st = os.stat(file_name)
+    actual_gid = st.st_gid
+    self.assertEqual(actual_gid, expected_gid)
+
   def assertEqualValues(self, first, second, msg=None):
     """Compares two values whether they're equal.