aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'pmstestsuite/library/case.py')
-rw-r--r--pmstestsuite/library/case.py85
1 files changed, 80 insertions, 5 deletions
diff --git a/pmstestsuite/library/case.py b/pmstestsuite/library/case.py
index 00a6cd4..a5817fb 100644
--- a/pmstestsuite/library/case.py
+++ b/pmstestsuite/library/case.py
@@ -58,42 +58,92 @@ def cleanup_test_case_name(classname):
return pn_re.sub('\\1-\\2', classname).lower()
class AssertionResult(ABCObject, BoolCompat):
+ """
+ Base class for assertion results.
+ """
+
def __init__(self, name):
self._name = name
self._undefined = False
@property
def name(self):
+ """
+ The assertion name.
+
+ @type: str
+ """
return self._name
@property
def prefix(self):
+ """
+ The assertion name prefix.
+
+ @type: str
+ """
return None
@property
def unprefixed_name(self):
+ """
+ The assertion name without prefix.
+
+ @type: str
+ """
return self.name
@property
def undefined(self):
+ """
+ Whether the assertion has undefined result.
+
+ @type: bool
+ """
return self._undefined
@abstractproperty
def expected(self):
+ """
+ Expected value.
+
+ @type: any
+ """
pass
@abstractproperty
def actual(self):
+ """
+ Actual value.
+
+ @type: any
+ """
pass
@abstractmethod
def __bool__(self):
+ """
+ Check whether the assertion succeeds.
+
+ @return: whether the assertion matches
+ @rtype: bool
+ """
pass
def __str__(self):
+ """
+ Return the stringified assertion description.
+
+ @return: stringified assertion
+ @rtype: str
+ """
return '%s == %s' % (self.actual, self.expected)
class BoolAssertionResult(AssertionResult):
+ """
+ Assertion for a boolean match.
+ """
+
def __init__(self, name, expect, cond):
AssertionResult.__init__(self, name)
self._expect = bool(expect)
@@ -113,6 +163,10 @@ class BoolAssertionResult(AssertionResult):
return self._expect == self._cond
class ContainsAssertionResult(AssertionResult):
+ """
+ Assertion checking whether a value is on the list.
+ """
+
def __init__(self, name, needle, container):
AssertionResult.__init__(self, name)
self._cont = container
@@ -135,6 +189,10 @@ class ContainsAssertionResult(AssertionResult):
return self._need in self._cont
class EqualAssertionResult(AssertionResult):
+ """
+ Assertion checking universal equality.
+ """
+
def __init__(self, name, expect, value):
AssertionResult.__init__(self, name)
self._expect = expect
@@ -152,6 +210,10 @@ class EqualAssertionResult(AssertionResult):
return self._expect == self._value
class NotEqualAssertionResult(EqualAssertionResult):
+ """
+ Assertion checking universal non-equality.
+ """
+
def __bool__(self):
if self._value is None:
return False
@@ -322,8 +384,8 @@ class TestCase(ABCObject):
@param value: the actual value
@type value: any
- @param expect: the unallowed value
- @type expect: any
+ @param unallowed: the unallowed value
+ @type unallowed: any
@param msg: assertion description
@type msg: string
@param undefined: whether the result is undefined
@@ -463,7 +525,7 @@ class EbuildTestCase(TestCase):
return 'pms-test/%s' % self.p
def atom(self, pm):
- """ Return atom for the test. """
+ """ Return an exact-match atom for the test. """
return pm.Atom('=%s' % self.cpv)
def _finalize(self):
@@ -501,12 +563,22 @@ class EbuildTestCase(TestCase):
class EbuildTestCaseEbuildFile(object):
""" Lazy ebuild contents evaluator for EbuildTestCase. """
def __init__(self, parent):
- """ Instantiate the evaluator for test case <parent>. """
+ """
+ Instantiate the evaluator for test case.
+
+ @param parent: relevant test case
+ @type parent: L{EbuildTestCase}
+ """
assert(isinstance(parent, EbuildTestCase))
self._parent = parent
def __str__(self):
- """ Return the ebuild contents as string. """
+ """
+ Return the ebuild contents as string.
+
+ @return: ebuild contents
+ @rtype: str
+ """
contents = [ebuild_header % (self._parent.eapi,
' '.join(['pms-test'] + self._parent.inherits))]
@@ -542,6 +614,9 @@ class EbuildTestCase(TestCase):
"""
Check the correctness of the result of test execution. By default,
checks whether the ebuild was actually merged.
+
+ @param pm: the package manager instance
+ @type pm: L{PackageManager}
"""
merged = self.atom(pm) in pm.installed