X-Git-Url: https://code.grnet.gr/git/ganeti-local/blobdiff_plain/c6a65efb455352087ee2b10c3a014e7303b6284c..48aaca91efa214b37dba94f28582be73f3c90dbd:/test/testutils.py diff --git a/test/testutils.py b/test/testutils.py index 2578c3d..3fcfbc4 100644 --- a/test/testutils.py +++ b/test/testutils.py @@ -136,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. @@ -197,3 +223,32 @@ def UnifyValueType(data): for (key, value) in data.iteritems()]) return data + + +class CallCounter(object): + """Utility class to count number of calls to a function/method. + + """ + def __init__(self, fn): + """Initializes this class. + + @type fn: Callable + + """ + self._fn = fn + self._count = 0 + + def __call__(self, *args, **kwargs): + """Calls wrapped function with given parameters. + + """ + self._count += 1 + return self._fn(*args, **kwargs) + + def Count(self): + """Returns number of calls. + + @rtype: number + + """ + return self._count