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/, pmstestsuite/
Date: Thu, 28 Jul 2011 18:02:24
Message-Id: 079c4be9ec9753ae426a3935af6b4a53f3c49556.mgorny@gentoo
1 commit: 079c4be9ec9753ae426a3935af6b4a53f3c49556
2 Author: Michał Górny <mgorny <AT> gentoo <DOT> org>
3 AuthorDate: Thu Jul 28 17:13:11 2011 +0000
4 Commit: Michał Górny <mgorny <AT> gentoo <DOT> org>
5 CommitDate: Thu Jul 28 17:13:11 2011 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/pms-test-suite.git;a=commit;h=079c4be9
7
8 Introduce asserts for test cases.
9
10 ---
11 pmstestsuite/cli.py | 18 +++++++-
12 pmstestsuite/library/case.py | 68 +++++++++++++++++++++++++++-
13 pmstestsuite/library/standard/dbus_case.py | 18 ++++---
14 3 files changed, 93 insertions(+), 11 deletions(-)
15
16 diff --git a/pmstestsuite/cli.py b/pmstestsuite/cli.py
17 index 518d826..892b8ab 100644
18 --- a/pmstestsuite/cli.py
19 +++ b/pmstestsuite/cli.py
20 @@ -111,7 +111,7 @@ class PMSTestSuiteCLI(object):
21
22 self.pm.package_limit = opts.limit_pkgs
23 self.update_manifests = not opts.no_manifests
24 -
25 +
26 limit_tests = set()
27 for t in opts.tests:
28 limit_tests.update(t.split())
29 @@ -121,8 +121,17 @@ class PMSTestSuiteCLI(object):
30 def tests_done(self):
31 print('-> Checking test results...')
32 self.failed = []
33 + self.asserts = [] # temporary
34 for t in self.test_library:
35 - res = t.check_result(self.pm)
36 + try:
37 + res = t.check_result(self.pm)
38 + except AssertionError as e:
39 + res = False
40 + self.asserts.append(str(e))
41 + else:
42 + # forward compat
43 + if res is None:
44 + res = True
45 if not res:
46 self.failed.append(t)
47 t.clean(self.pm)
48 @@ -143,6 +152,11 @@ class PMSTestSuiteCLI(object):
49 for t in self.failed:
50 print('- %s' % t)
51
52 + if self.asserts:
53 + print('[DEBUG] asserts:')
54 + for a in self.asserts:
55 + print('- %s' % a)
56 +
57 self.ret = 0 if not self.failed else 1
58 self.loop.quit()
59
60
61 diff --git a/pmstestsuite/library/case.py b/pmstestsuite/library/case.py
62 index 3f5d31e..0dd64b8 100644
63 --- a/pmstestsuite/library/case.py
64 +++ b/pmstestsuite/library/case.py
65 @@ -102,6 +102,70 @@ class TestCase(ABCObject):
66 """
67 pass
68
69 + def assertTrue(self, cond, msg):
70 + """
71 + Assert that the condition evaluates to True.
72 +
73 + @param cond: the condition
74 + @type cond: bool
75 + @param msg: assertion description
76 + @type msg: string
77 + """
78 + self.assertBool(True, cond, msg)
79 +
80 + def assertFalse(self, cond, msg):
81 + """
82 + Assert that the condition evaluates to False.
83 +
84 + @param cond: the condition
85 + @type cond: bool
86 + @param msg: assertion description
87 + @type msg: string
88 + """
89 + self.assertBool(False, cond, msg)
90 +
91 + def assertBool(self, expect, cond, msg):
92 + """
93 + Assert that the condition evaluates to expected boolean result.
94 +
95 + @param expect: expected result
96 + @type expect: bool
97 + @param cond: the condition
98 + @type cond: bool
99 + @param msg: assertion description
100 + @type msg: string
101 + """
102 + if bool(cond) != expect:
103 + raise AssertionError(msg)
104 +
105 + def assertTrue(self, cond, msg):
106 + """
107 + Assert that the condition evaluates to True.
108 +
109 + @param cond: the condition
110 + @type cond: bool
111 + @param msg: assertion description
112 + @type msg: string
113 + """
114 + if not cond:
115 + raise AssertionError(msg)
116 +
117 + def assertContains(self, needle, container, msg = None):
118 + """
119 + Assert the following condition: C{needle in container}.
120 +
121 + @param needle: the needle to look for
122 + @type needle: any
123 + @param container: the container to look for needle in
124 + @type container: iterable
125 + @param msg: assertion description or C{None} for default one
126 + @type msg: string/C{None}
127 + """
128 + if msg is None:
129 + msg = '%s in %s' % (repr(needle), repr(container))
130 + if needle not in container:
131 + raise AssertionError(msg)
132 +
133 @abstractmethod
134 def check_result(self, pm):
135 """
136 @@ -303,4 +367,6 @@ class EbuildTestCase(TestCase):
137 """
138
139 merged = self.atom(pm) in pm.installed
140 - return (merged != self.expect_failure)
141 + self.assertBool(not self.expect_failure, merged,
142 + 'package merged')
143 + return True
144
145 diff --git a/pmstestsuite/library/standard/dbus_case.py b/pmstestsuite/library/standard/dbus_case.py
146 index 8bc1c99..e69e4de 100644
147 --- a/pmstestsuite/library/standard/dbus_case.py
148 +++ b/pmstestsuite/library/standard/dbus_case.py
149 @@ -105,8 +105,8 @@ class DBusEbuildTestCase(EbuildTestCase):
150 return EbuildTestCase.check_result(self, pm)
151
152 def check_result(self, pm):
153 - return self.dbus_started \
154 - and self.check_dbus_result('\n'.join(self.dbus_output), pm)
155 + self.assertTrue(self.dbus_started, 'build started')
156 + return self.check_dbus_result('\n'.join(self.dbus_output), pm)
157
158 class DBusEclassTestCase(EclassTestCase):
159 """ D-Bus capable eclass test case. """
160 @@ -136,8 +136,8 @@ class DBusEclassTestCase(EclassTestCase):
161 return EbuildTestCase.check_result(self, pm)
162
163 def check_result(self, pm):
164 - return self.dbus_started \
165 - and self.check_dbus_result('\n'.join(self.dbus_output), pm)
166 + self.assertTrue(self.dbus_started, 'build started')
167 + return self.check_dbus_result('\n'.join(self.dbus_output), pm)
168
169 class DBusEbuildDependencyTestCase(EbuildDependencyTestCase):
170 """ D-Bus capable dependency test case. """
171 @@ -167,8 +167,9 @@ class DBusEbuildDependencyTestCase(EbuildDependencyTestCase):
172 return EbuildDependencyTestCase.check_result(self, pm)
173
174 def check_result(self, pm):
175 - return self.dbus_started != self.expect_failure \
176 - and self.check_dbus_result('\n'.join(self.dbus_output), pm)
177 + self.assertBool(not self.expect_failure, self.dbus_started,
178 + 'build started')
179 + return self.check_dbus_result('\n'.join(self.dbus_output), pm)
180
181 class DBusEclassDependencyTestCase(EclassDependencyTestCase):
182 """ D-Bus capable eclass dependency test case. """
183 @@ -198,5 +199,6 @@ class DBusEclassDependencyTestCase(EclassDependencyTestCase):
184 return EclassDependencyTestCase.check_result(self, pm)
185
186 def check_result(self, pm):
187 - return self.dbus_started != self.expect_failure \
188 - and self.check_dbus_result('\n'.join(self.dbus_output), pm)
189 + self.assertBool(not self.expect_failure, self.dbus_started,
190 + 'build started')
191 + return self.check_dbus_result('\n'.join(self.dbus_output), pm)