aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2012-01-02 23:11:11 +0100
committerMichał Górny <mgorny@gentoo.org>2012-01-02 23:13:22 +0100
commit948bbafc0f1a2c2eeb524cca38ac98ea966bb475 (patch)
treeafe3de1fcaedb4888d33c0131c545f2b124ca61a /pmstestsuite
parentIntegrate the D-Bus object with base D-Bus test case class. (diff)
downloadpms-test-suite-948bbafc0f1a2c2eeb524cca38ac98ea966bb475.tar.gz
pms-test-suite-948bbafc0f1a2c2eeb524cca38ac98ea966bb475.tar.bz2
pms-test-suite-948bbafc0f1a2c2eeb524cca38ac98ea966bb475.zip
Merge D-Bus into main case classes.
Diffstat (limited to 'pmstestsuite')
-rw-r--r--pmstestsuite/library/case.py78
-rw-r--r--pmstestsuite/library/depend_case.py2
-rw-r--r--pmstestsuite/library/eclass_case.py2
-rw-r--r--pmstestsuite/library/standard/dbus_case.py140
4 files changed, 86 insertions, 136 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)
diff --git a/pmstestsuite/library/depend_case.py b/pmstestsuite/library/depend_case.py
index bc06aa3..3f34ca7 100644
--- a/pmstestsuite/library/depend_case.py
+++ b/pmstestsuite/library/depend_case.py
@@ -1,5 +1,5 @@
# vim:fileencoding=utf-8
-# (c) 2011 Michał Górny <mgorny@gentoo.org>
+# (c) 2011-2012 Michał Górny <mgorny@gentoo.org>
# Released under the terms of the 2-clause BSD license.
from .case import EbuildTestCase, AssertionResult
diff --git a/pmstestsuite/library/eclass_case.py b/pmstestsuite/library/eclass_case.py
index cd64a9a..d409e0d 100644
--- a/pmstestsuite/library/eclass_case.py
+++ b/pmstestsuite/library/eclass_case.py
@@ -1,5 +1,5 @@
# vim:fileencoding=utf-8
-# (c) 2011 Michał Górny <mgorny@gentoo.org>
+# (c) 2011-2012 Michał Górny <mgorny@gentoo.org>
# Released under the terms of the 2-clause BSD license.
from abc import abstractproperty
diff --git a/pmstestsuite/library/standard/dbus_case.py b/pmstestsuite/library/standard/dbus_case.py
index ac9c4d1..14258b7 100644
--- a/pmstestsuite/library/standard/dbus_case.py
+++ b/pmstestsuite/library/standard/dbus_case.py
@@ -2,143 +2,19 @@
# (c) 2011-2012 Michał Górny <mgorny@gentoo.org>
# Released under the terms of the 2-clause BSD license.
-import dbus.service
-
from pmstestsuite.library.case import EbuildTestCase
from pmstestsuite.library.depend_case import EbuildDependencyTestCase, \
EclassDependencyTestCase
from pmstestsuite.library.eclass_case import EclassTestCase
-from pmstestsuite.dbus_handler import DBusHandler, dbus_interface_name, dbus_object_prefix
-
-dbus_handler = DBusHandler()
-
-class DBusBaseTestCase(dbus.service.Object):
- """ A base D-Bus test case class. """
-
- def __init__(self):
- """
- Initialize the D-Bus interface for the test.
- """
- self.reset()
- dbus.service.Object.__init__(
- self,
- dbus_handler.bus,
- '%s/%s' % (dbus_object_prefix, self.p.replace('-', '_'))
- )
-
- def reset(self):
- """
- Reset 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 _finalize(self):
- """
- Finalize the object, ensuring that C{pkg_setup()} will be called.
- """
- if self.phase_funcs['pkg_setup']:
- self.phase_funcs['pkg_setup'].insert(0, 'pms-test_pkg_setup')
-
- 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):
- self.assertTrue(self.dbus_started, 'build started')
- self.check_dbus_result(self._pop_dbus_output(), pm)
-
-class DBusEbuildTestCase(DBusBaseTestCase, EbuildTestCase):
- """ D-Bus capable ebuild test case. """
-
- def __init__(self, *args, **kwargs):
- """ Initialize the test case and the D-Bus object for it. """
- EbuildTestCase.__init__(self, *args, **kwargs)
- DBusBaseTestCase.__init__(self)
-
- def check_dbus_result(self, output, pm):
- EbuildTestCase.check_result(self, pm)
-
-class DBusEclassTestCase(DBusBaseTestCase, EclassTestCase):
- """ D-Bus capable eclass test case. """
-
- def __init__(self, *args, **kwargs):
- """ Initialize the test case and the D-Bus object for it. """
- EclassTestCase.__init__(self, *args, **kwargs)
- DBusBaseTestCase.__init__(self)
-
- def check_dbus_result(self, output, pm):
- EclassTestCase.check_result(self, pm)
-
-class DBusEbuildDependencyTestCase(DBusBaseTestCase, EbuildDependencyTestCase):
- """ D-Bus capable dependency test case. """
-
- def __init__(self, *args, **kwargs):
- """ Initialize the test case and the D-Bus object for it. """
- EbuildDependencyTestCase.__init__(self, *args, **kwargs)
- DBusBaseTestCase.__init__(self)
-
- def check_dbus_result(self, output, pm):
- EbuildDependencyTestCase.check_result(self, pm)
-
- def check_result(self, pm):
- started = self.dbus_started
- self.check_dbus_result(self._pop_dbus_output(), pm)
- self.assertBool(not self.expect_failure, started, 'build started')
-
-class DBusEclassDependencyTestCase(DBusBaseTestCase, EclassDependencyTestCase):
- """ D-Bus capable eclass dependency test case. """
+class DBusEbuildTestCase(EbuildTestCase):
+ pass
- def __init__(self, *args, **kwargs):
- """ Initialize the test case and the D-Bus object for it. """
- EclassDependencyTestCase.__init__(self, *args, **kwargs)
- DBusBaseTestCase.__init__(self)
+class DBusEclassTestCase(EclassTestCase):
+ pass
- def check_dbus_result(self, output, pm):
- EclassDependencyTestCase.check_result(self, pm)
+class DBusEbuildDependencyTestCase(EbuildDependencyTestCase):
+ pass
- def check_result(self, pm):
- started = self.dbus_started
- self.check_dbus_result(self._pop_dbus_output(), pm)
- self.assertBool(not self.expect_failure, started, 'build started')
+class DBusEclassDependencyTestCase(EclassDependencyTestCase):
+ pass