diff options
author | Michał Górny <mgorny@gentoo.org> | 2011-07-28 19:13:11 +0200 |
---|---|---|
committer | Michał Górny <mgorny@gentoo.org> | 2011-07-28 19:13:11 +0200 |
commit | 079c4be9ec9753ae426a3935af6b4a53f3c49556 (patch) | |
tree | 596214e17818166319db7f83b0bc645c2ceb8230 /pmstestsuite/library/case.py | |
parent | Add a test for DEFINED_PHASES due to eclass inherit. (diff) | |
download | pms-test-suite-079c4be9ec9753ae426a3935af6b4a53f3c49556.tar.gz pms-test-suite-079c4be9ec9753ae426a3935af6b4a53f3c49556.tar.bz2 pms-test-suite-079c4be9ec9753ae426a3935af6b4a53f3c49556.zip |
Introduce asserts for test cases.
Diffstat (limited to 'pmstestsuite/library/case.py')
-rw-r--r-- | pmstestsuite/library/case.py | 68 |
1 files changed, 67 insertions, 1 deletions
diff --git a/pmstestsuite/library/case.py b/pmstestsuite/library/case.py index 3f5d31e..0dd64b8 100644 --- a/pmstestsuite/library/case.py +++ b/pmstestsuite/library/case.py @@ -102,6 +102,70 @@ class TestCase(ABCObject): """ pass + def assertTrue(self, cond, msg): + """ + Assert that the condition evaluates to True. + + @param cond: the condition + @type cond: bool + @param msg: assertion description + @type msg: string + """ + self.assertBool(True, cond, msg) + + def assertFalse(self, cond, msg): + """ + Assert that the condition evaluates to False. + + @param cond: the condition + @type cond: bool + @param msg: assertion description + @type msg: string + """ + self.assertBool(False, cond, msg) + + def assertBool(self, expect, cond, msg): + """ + Assert that the condition evaluates to expected boolean result. + + @param expect: expected result + @type expect: bool + @param cond: the condition + @type cond: bool + @param msg: assertion description + @type msg: string + """ + if bool(cond) != expect: + raise AssertionError(msg) + + def assertTrue(self, cond, msg): + """ + Assert that the condition evaluates to True. + + @param cond: the condition + @type cond: bool + @param msg: assertion description + @type msg: string + """ + if not cond: + raise AssertionError(msg) + + def assertContains(self, needle, container, msg = None): + """ + Assert the following condition: C{needle in container}. + + @param needle: the needle to look for + @type needle: any + @param container: the container to look for needle in + @type container: iterable + @param msg: assertion description or C{None} for default one + @type msg: string/C{None} + """ + if msg is None: + msg = '%s in %s' % (repr(needle), repr(container)) + if needle not in container: + raise AssertionError(msg) + @abstractmethod def check_result(self, pm): """ @@ -303,4 +367,6 @@ class EbuildTestCase(TestCase): """ merged = self.atom(pm) in pm.installed - return (merged != self.expect_failure) + self.assertBool(not self.expect_failure, merged, + 'package merged') + return True |