Gentoo Archives: gentoo-commits

From: "Michał Górny" <mgorny@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/pms-test-suite:master commit in: pmstestsuite/library/standard/, pmstestsuite/library/
Date: Mon, 02 Jan 2012 22:26:43
Message-Id: 948bbafc0f1a2c2eeb524cca38ac98ea966bb475.mgorny@gentoo
1 commit: 948bbafc0f1a2c2eeb524cca38ac98ea966bb475
2 Author: Michał Górny <mgorny <AT> gentoo <DOT> org>
3 AuthorDate: Mon Jan 2 22:11:11 2012 +0000
4 Commit: Michał Górny <mgorny <AT> gentoo <DOT> org>
5 CommitDate: Mon Jan 2 22:13:22 2012 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/pms-test-suite.git;a=commit;h=948bbafc
7
8 Merge D-Bus into main case classes.
9
10 ---
11 pmstestsuite/library/case.py | 78 +++++++++++++++-
12 pmstestsuite/library/depend_case.py | 2 +-
13 pmstestsuite/library/eclass_case.py | 2 +-
14 pmstestsuite/library/standard/dbus_case.py | 140 ++--------------------------
15 4 files changed, 86 insertions(+), 136 deletions(-)
16
17 diff --git a/pmstestsuite/library/case.py b/pmstestsuite/library/case.py
18 index 614a500..90406a0 100644
19 --- a/pmstestsuite/library/case.py
20 +++ b/pmstestsuite/library/case.py
21 @@ -5,8 +5,14 @@
22 import copy, itertools, random, re
23 from gentoopm.util import ABCObject, BoolCompat
24
25 +import dbus.service
26 +
27 from abc import ABCMeta, abstractmethod, abstractproperty
28
29 +from pmstestsuite.dbus_handler import DBusHandler, dbus_interface_name, dbus_object_prefix
30 +
31 +dbus_handler = DBusHandler()
32 +
33 # XXX: move to some consts module?
34 phase_func_names = [
35 'pkg_pretend', 'pkg_setup', 'src_unpack', 'src_prepare',
36 @@ -227,7 +233,7 @@ class NotEqualAssertionResult(EqualAssertionResult):
37 return '%s != %s' % (self.actual,
38 repr(self._expect))
39
40 -class TestCase(object): # was: ABCObject
41 +class TestCase(dbus.service.Object): # was: ABCObject
42 """
43 Base class for a test case.
44
45 @@ -239,9 +245,19 @@ class TestCase(object): # was: ABCObject
46 _finalized = False
47
48 def __init__(self, short_name):
49 + """
50 + Initialize the test class and the D-Bus interface for it.
51 + """
52 +
53 self.assertions = []
54 self._short_name = short_name
55
56 + dbus.service.Object.__init__(
57 + self,
58 + dbus_handler.bus,
59 + '%s/%s' % (dbus_object_prefix, self.p.replace('-', '_'))
60 + )
61 +
62 @property
63 def short_name(self):
64 return self._short_name
65 @@ -258,6 +274,8 @@ class TestCase(object): # was: ABCObject
66 def _finalize(self):
67 """
68 Do any final modifications to test case data. Mark it finalized.
69 + Ensure that C{pkg_setup()} will be called.
70 +
71 This function shall be called at most once per object.
72 """
73 self._finalized = True
74 @@ -531,6 +549,8 @@ class EbuildTestCase(TestCase):
75 def _finalize(self):
76 TestCase._finalize(self)
77
78 + if self.phase_funcs['pkg_setup']:
79 + self.phase_funcs['pkg_setup'].insert(0, 'pms-test_pkg_setup')
80 if 'DESCRIPTION' not in self.ebuild_vars:
81 self.ebuild_vars['DESCRIPTION'] = self._stripped_docstring
82
83 @@ -546,8 +566,9 @@ class EbuildTestCase(TestCase):
84 @param eapi: the EAPI
85 @type eapi: string
86 """
87 - TestCase.__init__(self, short_name)
88 self.eapi = eapi
89 + self.reset()
90 + TestCase.__init__(self, short_name)
91
92 for v in ('ebuild_vars', 'inherits', 'phase_funcs'):
93 setattr(self, v, copy.deepcopy(getattr(self, v)))
94 @@ -559,6 +580,34 @@ class EbuildTestCase(TestCase):
95 self.ebuild_vars['KEYWORDS'] = 'alpha amd64 arm hppa ia64 ' + \
96 'm68k ~mips ppc ppc64 s390 sh sparc x86'
97
98 + def reset(self):
99 + """
100 + Reset (D-Bus) test results.
101 + """
102 + self.dbus_output = []
103 + self.dbus_started = False
104 +
105 + @dbus.service.method(
106 + dbus_interface=dbus_interface_name,
107 + in_signature='', out_signature='')
108 + def test_started(self):
109 + """
110 + Notify the test suite that a particular test has been started.
111 + """
112 + self.dbus_started = True
113 +
114 + @dbus.service.method(
115 + dbus_interface=dbus_interface_name,
116 + in_signature='s', out_signature='')
117 + def append_output(self, l):
118 + """
119 + Append the string to the test output.
120 +
121 + @param l: result string
122 + @type l: C{dbus.UTF8String}
123 + """
124 + self.dbus_output.append(str(l))
125 +
126 def get_output_files(self):
127 class EbuildTestCaseEbuildFile(object):
128 """ Lazy ebuild contents evaluator for EbuildTestCase. """
129 @@ -610,6 +659,29 @@ class EbuildTestCase(TestCase):
130 def start(self, pm):
131 pm.merge(self.cpv)
132
133 + def check_dbus_result(self, output, pm):
134 + """
135 + Check whether the output sent through D-Bus matches expected test
136 + output.
137 +
138 + The default implementation simply checks whether the test was merged
139 + alike L{EbuildTestCase.check_result()}.
140 +
141 + @param output: the D-Bus output
142 + @type output: list(str)
143 + @param pm: the package manager instance
144 + @type pm: L{PackageManager}
145 + @return: C{True} if output matches expected test result, C{False}
146 + otherwise
147 + @rtype: bool
148 + """
149 + pass
150 +
151 + def _pop_dbus_output(self):
152 + ret = self.dbus_output
153 + self.reset()
154 + return ret
155 +
156 def check_result(self, pm):
157 """
158 Check the correctness of the result of test execution. By default,
159 @@ -622,3 +694,5 @@ class EbuildTestCase(TestCase):
160 merged = self.atom(pm) in pm.installed
161 self.assertBool(not self.expect_failure, merged,
162 'package merged')
163 + self.assertTrue(self.dbus_started, 'build started')
164 + self.check_dbus_result(self._pop_dbus_output(), pm)
165
166 diff --git a/pmstestsuite/library/depend_case.py b/pmstestsuite/library/depend_case.py
167 index bc06aa3..3f34ca7 100644
168 --- a/pmstestsuite/library/depend_case.py
169 +++ b/pmstestsuite/library/depend_case.py
170 @@ -1,5 +1,5 @@
171 # vim:fileencoding=utf-8
172 -# (c) 2011 Michał Górny <mgorny@g.o>
173 +# (c) 2011-2012 Michał Górny <mgorny@g.o>
174 # Released under the terms of the 2-clause BSD license.
175
176 from .case import EbuildTestCase, AssertionResult
177
178 diff --git a/pmstestsuite/library/eclass_case.py b/pmstestsuite/library/eclass_case.py
179 index cd64a9a..d409e0d 100644
180 --- a/pmstestsuite/library/eclass_case.py
181 +++ b/pmstestsuite/library/eclass_case.py
182 @@ -1,5 +1,5 @@
183 # vim:fileencoding=utf-8
184 -# (c) 2011 Michał Górny <mgorny@g.o>
185 +# (c) 2011-2012 Michał Górny <mgorny@g.o>
186 # Released under the terms of the 2-clause BSD license.
187
188 from abc import abstractproperty
189
190 diff --git a/pmstestsuite/library/standard/dbus_case.py b/pmstestsuite/library/standard/dbus_case.py
191 index ac9c4d1..14258b7 100644
192 --- a/pmstestsuite/library/standard/dbus_case.py
193 +++ b/pmstestsuite/library/standard/dbus_case.py
194 @@ -2,143 +2,19 @@
195 # (c) 2011-2012 Michał Górny <mgorny@g.o>
196 # Released under the terms of the 2-clause BSD license.
197
198 -import dbus.service
199 -
200 from pmstestsuite.library.case import EbuildTestCase
201 from pmstestsuite.library.depend_case import EbuildDependencyTestCase, \
202 EclassDependencyTestCase
203 from pmstestsuite.library.eclass_case import EclassTestCase
204
205 -from pmstestsuite.dbus_handler import DBusHandler, dbus_interface_name, dbus_object_prefix
206 -
207 -dbus_handler = DBusHandler()
208 -
209 -class DBusBaseTestCase(dbus.service.Object):
210 - """ A base D-Bus test case class. """
211 -
212 - def __init__(self):
213 - """
214 - Initialize the D-Bus interface for the test.
215 - """
216 - self.reset()
217 - dbus.service.Object.__init__(
218 - self,
219 - dbus_handler.bus,
220 - '%s/%s' % (dbus_object_prefix, self.p.replace('-', '_'))
221 - )
222 -
223 - def reset(self):
224 - """
225 - Reset test results.
226 - """
227 - self.dbus_output = []
228 - self.dbus_started = False
229 -
230 - @dbus.service.method(
231 - dbus_interface=dbus_interface_name,
232 - in_signature='', out_signature='')
233 - def test_started(self):
234 - """
235 - Notify the test suite that a particular test has been started.
236 - """
237 - self.dbus_started = True
238 -
239 - @dbus.service.method(
240 - dbus_interface=dbus_interface_name,
241 - in_signature='s', out_signature='')
242 - def append_output(self, l):
243 - """
244 - Append the string to the test output.
245 -
246 - @param l: result string
247 - @type l: C{dbus.UTF8String}
248 - """
249 - self.dbus_output.append(str(l))
250 -
251 - def _finalize(self):
252 - """
253 - Finalize the object, ensuring that C{pkg_setup()} will be called.
254 - """
255 - if self.phase_funcs['pkg_setup']:
256 - self.phase_funcs['pkg_setup'].insert(0, 'pms-test_pkg_setup')
257 -
258 - def check_dbus_result(self, output, pm):
259 - """
260 - Check whether the output sent through D-Bus matches expected test
261 - output.
262 -
263 - The default implementation simply checks whether the test was merged
264 - alike L{EbuildTestCase.check_result()}.
265 -
266 - @param output: the D-Bus output
267 - @type output: list(str)
268 - @param pm: the package manager instance
269 - @type pm: L{PackageManager}
270 - @return: C{True} if output matches expected test result, C{False}
271 - otherwise
272 - @rtype: bool
273 - """
274 - pass
275 -
276 - def _pop_dbus_output(self):
277 - ret = self.dbus_output
278 - self.reset()
279 - return ret
280 -
281 - def check_result(self, pm):
282 - self.assertTrue(self.dbus_started, 'build started')
283 - self.check_dbus_result(self._pop_dbus_output(), pm)
284 -
285 -class DBusEbuildTestCase(DBusBaseTestCase, EbuildTestCase):
286 - """ D-Bus capable ebuild test case. """
287 -
288 - def __init__(self, *args, **kwargs):
289 - """ Initialize the test case and the D-Bus object for it. """
290 - EbuildTestCase.__init__(self, *args, **kwargs)
291 - DBusBaseTestCase.__init__(self)
292 -
293 - def check_dbus_result(self, output, pm):
294 - EbuildTestCase.check_result(self, pm)
295 -
296 -class DBusEclassTestCase(DBusBaseTestCase, EclassTestCase):
297 - """ D-Bus capable eclass test case. """
298 -
299 - def __init__(self, *args, **kwargs):
300 - """ Initialize the test case and the D-Bus object for it. """
301 - EclassTestCase.__init__(self, *args, **kwargs)
302 - DBusBaseTestCase.__init__(self)
303 -
304 - def check_dbus_result(self, output, pm):
305 - EclassTestCase.check_result(self, pm)
306 -
307 -class DBusEbuildDependencyTestCase(DBusBaseTestCase, EbuildDependencyTestCase):
308 - """ D-Bus capable dependency test case. """
309 -
310 - def __init__(self, *args, **kwargs):
311 - """ Initialize the test case and the D-Bus object for it. """
312 - EbuildDependencyTestCase.__init__(self, *args, **kwargs)
313 - DBusBaseTestCase.__init__(self)
314 -
315 - def check_dbus_result(self, output, pm):
316 - EbuildDependencyTestCase.check_result(self, pm)
317 -
318 - def check_result(self, pm):
319 - started = self.dbus_started
320 - self.check_dbus_result(self._pop_dbus_output(), pm)
321 - self.assertBool(not self.expect_failure, started, 'build started')
322 -
323 -class DBusEclassDependencyTestCase(DBusBaseTestCase, EclassDependencyTestCase):
324 - """ D-Bus capable eclass dependency test case. """
325 +class DBusEbuildTestCase(EbuildTestCase):
326 + pass
327
328 - def __init__(self, *args, **kwargs):
329 - """ Initialize the test case and the D-Bus object for it. """
330 - EclassDependencyTestCase.__init__(self, *args, **kwargs)
331 - DBusBaseTestCase.__init__(self)
332 +class DBusEclassTestCase(EclassTestCase):
333 + pass
334
335 - def check_dbus_result(self, output, pm):
336 - EclassDependencyTestCase.check_result(self, pm)
337 +class DBusEbuildDependencyTestCase(EbuildDependencyTestCase):
338 + pass
339
340 - def check_result(self, pm):
341 - started = self.dbus_started
342 - self.check_dbus_result(self._pop_dbus_output(), pm)
343 - self.assertBool(not self.expect_failure, started, 'build started')
344 +class DBusEclassDependencyTestCase(EclassDependencyTestCase):
345 + pass