aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'pmstestsuite/library/case.py')
-rw-r--r--pmstestsuite/library/case.py78
1 files changed, 76 insertions, 2 deletions
diff --git a/pmstestsuite/library/case.py b/pmstestsuite/library/case.py
index 614a500..90406a0 100644
--- a/pmstestsuite/library/case.py
+++ b/pmstestsuite/library/case.py
@@ -5,8 +5,14 @@
import copy, itertools, random, re
from gentoopm.util import ABCObject, BoolCompat
+import dbus.service
+
from abc import ABCMeta, abstractmethod, abstractproperty
+from pmstestsuite.dbus_handler import DBusHandler, dbus_interface_name, dbus_object_prefix
+
+dbus_handler = DBusHandler()
+
# XXX: move to some consts module?
phase_func_names = [
'pkg_pretend', 'pkg_setup', 'src_unpack', 'src_prepare',
@@ -227,7 +233,7 @@ class NotEqualAssertionResult(EqualAssertionResult):
return '%s != %s' % (self.actual,
repr(self._expect))
-class TestCase(object): # was: ABCObject
+class TestCase(dbus.service.Object): # was: ABCObject
"""
Base class for a test case.
@@ -239,9 +245,19 @@ class TestCase(object): # was: ABCObject
_finalized = False
def __init__(self, short_name):
+ """
+ Initialize the test class and the D-Bus interface for it.
+ """
+
self.assertions = []
self._short_name = short_name
+ dbus.service.Object.__init__(
+ self,
+ dbus_handler.bus,
+ '%s/%s' % (dbus_object_prefix, self.p.replace('-', '_'))
+ )
+
@property
def short_name(self):
return self._short_name
@@ -258,6 +274,8 @@ class TestCase(object): # was: ABCObject
def _finalize(self):
"""
Do any final modifications to test case data. Mark it finalized.
+ Ensure that C{pkg_setup()} will be called.
+
This function shall be called at most once per object.
"""
self._finalized = True
@@ -531,6 +549,8 @@ class EbuildTestCase(TestCase):
def _finalize(self):
TestCase._finalize(self)
+ if self.phase_funcs['pkg_setup']:
+ self.phase_funcs['pkg_setup'].insert(0, 'pms-test_pkg_setup')
if 'DESCRIPTION' not in self.ebuild_vars:
self.ebuild_vars['DESCRIPTION'] = self._stripped_docstring
@@ -546,8 +566,9 @@ class EbuildTestCase(TestCase):
@param eapi: the EAPI
@type eapi: string
"""
- TestCase.__init__(self, short_name)
self.eapi = eapi
+ self.reset()
+ TestCase.__init__(self, short_name)
for v in ('ebuild_vars', 'inherits', 'phase_funcs'):
setattr(self, v, copy.deepcopy(getattr(self, v)))
@@ -559,6 +580,34 @@ class EbuildTestCase(TestCase):
self.ebuild_vars['KEYWORDS'] = 'alpha amd64 arm hppa ia64 ' + \
'm68k ~mips ppc ppc64 s390 sh sparc x86'
+ def reset(self):
+ """
+ Reset (D-Bus) test results.
+ """
+ self.dbus_output = []
+ self.dbus_started = False
+
+ @dbus.service.method(
+ dbus_interface=dbus_interface_name,
+ in_signature='', out_signature='')
+ def test_started(self):
+ """
+ Notify the test suite that a particular test has been started.
+ """
+ self.dbus_started = True
+
+ @dbus.service.method(
+ dbus_interface=dbus_interface_name,
+ in_signature='s', out_signature='')
+ def append_output(self, l):
+ """
+ Append the string to the test output.
+
+ @param l: result string
+ @type l: C{dbus.UTF8String}
+ """
+ self.dbus_output.append(str(l))
+
def get_output_files(self):
class EbuildTestCaseEbuildFile(object):
""" Lazy ebuild contents evaluator for EbuildTestCase. """
@@ -610,6 +659,29 @@ class EbuildTestCase(TestCase):
def start(self, pm):
pm.merge(self.cpv)
+ def check_dbus_result(self, output, pm):
+ """
+ Check whether the output sent through D-Bus matches expected test
+ output.
+
+ The default implementation simply checks whether the test was merged
+ alike L{EbuildTestCase.check_result()}.
+
+ @param output: the D-Bus output
+ @type output: list(str)
+ @param pm: the package manager instance
+ @type pm: L{PackageManager}
+ @return: C{True} if output matches expected test result, C{False}
+ otherwise
+ @rtype: bool
+ """
+ pass
+
+ def _pop_dbus_output(self):
+ ret = self.dbus_output
+ self.reset()
+ return ret
+
def check_result(self, pm):
"""
Check the correctness of the result of test execution. By default,
@@ -622,3 +694,5 @@ class EbuildTestCase(TestCase):
merged = self.atom(pm) in pm.installed
self.assertBool(not self.expect_failure, merged,
'package merged')
+ self.assertTrue(self.dbus_started, 'build started')
+ self.check_dbus_result(self._pop_dbus_output(), pm)