* [gentoo-commits] proj/pms-test-suite:master commit in: pmstestsuite/library/standard/, pmstestsuite/library/, pmstestsuite/
@ 2011-07-28 17:15 Michał Górny
0 siblings, 0 replies; 2+ messages in thread
From: Michał Górny @ 2011-07-28 17:15 UTC (permalink / raw
To: gentoo-commits
commit: 079c4be9ec9753ae426a3935af6b4a53f3c49556
Author: Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Thu Jul 28 17:13:11 2011 +0000
Commit: Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Thu Jul 28 17:13:11 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/pms-test-suite.git;a=commit;h=079c4be9
Introduce asserts for test cases.
---
pmstestsuite/cli.py | 18 +++++++-
pmstestsuite/library/case.py | 68 +++++++++++++++++++++++++++-
pmstestsuite/library/standard/dbus_case.py | 18 ++++---
3 files changed, 93 insertions(+), 11 deletions(-)
diff --git a/pmstestsuite/cli.py b/pmstestsuite/cli.py
index 518d826..892b8ab 100644
--- a/pmstestsuite/cli.py
+++ b/pmstestsuite/cli.py
@@ -111,7 +111,7 @@ class PMSTestSuiteCLI(object):
self.pm.package_limit = opts.limit_pkgs
self.update_manifests = not opts.no_manifests
-
+
limit_tests = set()
for t in opts.tests:
limit_tests.update(t.split())
@@ -121,8 +121,17 @@ class PMSTestSuiteCLI(object):
def tests_done(self):
print('-> Checking test results...')
self.failed = []
+ self.asserts = [] # temporary
for t in self.test_library:
- res = t.check_result(self.pm)
+ try:
+ res = t.check_result(self.pm)
+ except AssertionError as e:
+ res = False
+ self.asserts.append(str(e))
+ else:
+ # forward compat
+ if res is None:
+ res = True
if not res:
self.failed.append(t)
t.clean(self.pm)
@@ -143,6 +152,11 @@ class PMSTestSuiteCLI(object):
for t in self.failed:
print('- %s' % t)
+ if self.asserts:
+ print('[DEBUG] asserts:')
+ for a in self.asserts:
+ print('- %s' % a)
+
self.ret = 0 if not self.failed else 1
self.loop.quit()
diff --git a/pmstestsuite/library/case.py b/pmstestsuite/library/case.py
index 3f5d31e..0dd64b8 100644
--- a/pmstestsuite/library/case.py
+++ b/pmstestsuite/library/case.py
@@ -102,6 +102,70 @@ class TestCase(ABCObject):
"""
pass
+ def assertTrue(self, cond, msg):
+ """
+ Assert that the condition evaluates to True.
+
+ @param cond: the condition
+ @type cond: bool
+ @param msg: assertion description
+ @type msg: string
+ """
+ self.assertBool(True, cond, msg)
+
+ def assertFalse(self, cond, msg):
+ """
+ Assert that the condition evaluates to False.
+
+ @param cond: the condition
+ @type cond: bool
+ @param msg: assertion description
+ @type msg: string
+ """
+ self.assertBool(False, cond, msg)
+
+ def assertBool(self, expect, cond, msg):
+ """
+ Assert that the condition evaluates to expected boolean result.
+
+ @param expect: expected result
+ @type expect: bool
+ @param cond: the condition
+ @type cond: bool
+ @param msg: assertion description
+ @type msg: string
+ """
+ if bool(cond) != expect:
+ raise AssertionError(msg)
+
+ def assertTrue(self, cond, msg):
+ """
+ Assert that the condition evaluates to True.
+
+ @param cond: the condition
+ @type cond: bool
+ @param msg: assertion description
+ @type msg: string
+ """
+ if not cond:
+ raise AssertionError(msg)
+
+ def assertContains(self, needle, container, msg = None):
+ """
+ Assert the following condition: C{needle in container}.
+
+ @param needle: the needle to look for
+ @type needle: any
+ @param container: the container to look for needle in
+ @type container: iterable
+ @param msg: assertion description or C{None} for default one
+ @type msg: string/C{None}
+ """
+ if msg is None:
+ msg = '%s in %s' % (repr(needle), repr(container))
+ if needle not in container:
+ raise AssertionError(msg)
+
@abstractmethod
def check_result(self, pm):
"""
@@ -303,4 +367,6 @@ class EbuildTestCase(TestCase):
"""
merged = self.atom(pm) in pm.installed
- return (merged != self.expect_failure)
+ self.assertBool(not self.expect_failure, merged,
+ 'package merged')
+ return True
diff --git a/pmstestsuite/library/standard/dbus_case.py b/pmstestsuite/library/standard/dbus_case.py
index 8bc1c99..e69e4de 100644
--- a/pmstestsuite/library/standard/dbus_case.py
+++ b/pmstestsuite/library/standard/dbus_case.py
@@ -105,8 +105,8 @@ class DBusEbuildTestCase(EbuildTestCase):
return EbuildTestCase.check_result(self, pm)
def check_result(self, pm):
- return self.dbus_started \
- and self.check_dbus_result('\n'.join(self.dbus_output), pm)
+ self.assertTrue(self.dbus_started, 'build started')
+ return self.check_dbus_result('\n'.join(self.dbus_output), pm)
class DBusEclassTestCase(EclassTestCase):
""" D-Bus capable eclass test case. """
@@ -136,8 +136,8 @@ class DBusEclassTestCase(EclassTestCase):
return EbuildTestCase.check_result(self, pm)
def check_result(self, pm):
- return self.dbus_started \
- and self.check_dbus_result('\n'.join(self.dbus_output), pm)
+ self.assertTrue(self.dbus_started, 'build started')
+ return self.check_dbus_result('\n'.join(self.dbus_output), pm)
class DBusEbuildDependencyTestCase(EbuildDependencyTestCase):
""" D-Bus capable dependency test case. """
@@ -167,8 +167,9 @@ class DBusEbuildDependencyTestCase(EbuildDependencyTestCase):
return EbuildDependencyTestCase.check_result(self, pm)
def check_result(self, pm):
- return self.dbus_started != self.expect_failure \
- and self.check_dbus_result('\n'.join(self.dbus_output), pm)
+ self.assertBool(not self.expect_failure, self.dbus_started,
+ 'build started')
+ return self.check_dbus_result('\n'.join(self.dbus_output), pm)
class DBusEclassDependencyTestCase(EclassDependencyTestCase):
""" D-Bus capable eclass dependency test case. """
@@ -198,5 +199,6 @@ class DBusEclassDependencyTestCase(EclassDependencyTestCase):
return EclassDependencyTestCase.check_result(self, pm)
def check_result(self, pm):
- return self.dbus_started != self.expect_failure \
- and self.check_dbus_result('\n'.join(self.dbus_output), pm)
+ self.assertBool(not self.expect_failure, self.dbus_started,
+ 'build started')
+ return self.check_dbus_result('\n'.join(self.dbus_output), pm)
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [gentoo-commits] proj/pms-test-suite:master commit in: pmstestsuite/library/standard/, pmstestsuite/library/, pmstestsuite/
@ 2011-08-03 20:17 Michał Górny
0 siblings, 0 replies; 2+ messages in thread
From: Michał Górny @ 2011-08-03 20:17 UTC (permalink / raw
To: gentoo-commits
commit: 417cc44cec713c41b91ee19281b8f13b88a931e7
Author: Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Wed Aug 3 20:02:32 2011 +0000
Commit: Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Wed Aug 3 20:02:32 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/pms-test-suite.git;a=commit;h=417cc44c
Drop bool return in check_results() backwards compat.
---
pmstestsuite/cli.py | 18 +++++-------------
pmstestsuite/library/case.py | 1 -
pmstestsuite/library/depend_case.py | 10 ++++------
pmstestsuite/library/standard/dbus_case.py | 14 +++++++-------
4 files changed, 16 insertions(+), 27 deletions(-)
diff --git a/pmstestsuite/cli.py b/pmstestsuite/cli.py
index 155dc2c..f21c7a9 100644
--- a/pmstestsuite/cli.py
+++ b/pmstestsuite/cli.py
@@ -129,21 +129,13 @@ class PMSTestSuiteCLI(object):
self.failed = []
for t in self.test_library:
try:
- res = t.check_result(self.pm)
- except AssertionError:
- res = False
- outc = 'F'
- except Exception:
- res = False
- outc = 'E'
- # XXX: store exception details somewhere
+ t.check_result(self.pm)
+ except Exception as e:
+ outc = 'F' if isinstance(e, AssertionError) else 'E'
+ self.failed.append(t)
+ # XXX: store exception details somewhere?
else:
outc = '.'
- # forward compat
- if res is None:
- res = True
- if not res:
- self.failed.append(t)
t.clean(self.pm)
print(outc, end='')
print('')
diff --git a/pmstestsuite/library/case.py b/pmstestsuite/library/case.py
index 9ff757a..6b74fc6 100644
--- a/pmstestsuite/library/case.py
+++ b/pmstestsuite/library/case.py
@@ -480,4 +480,3 @@ class EbuildTestCase(TestCase):
merged = self.atom(pm) in pm.installed
self.assertBool(not self.expect_failure, merged,
'package merged')
- return True
diff --git a/pmstestsuite/library/depend_case.py b/pmstestsuite/library/depend_case.py
index f5f7327..793d7ce 100644
--- a/pmstestsuite/library/depend_case.py
+++ b/pmstestsuite/library/depend_case.py
@@ -66,10 +66,9 @@ class EbuildDependencyTestCase(EbuildTestCase):
return of
def check_result(self, pm):
- res = EbuildTestCase.check_result(self, pm)
+ EbuildTestCase.check_result(self, pm)
for o in self.dependant_ebuilds:
- res &= o.check_result(pm)
- return res
+ o.check_result(pm)
class EclassDependencyTestCase(EclassTestCase, EbuildDependencyTestCase):
"""
@@ -151,7 +150,6 @@ class EclassDependencyTestCase(EclassTestCase, EbuildDependencyTestCase):
return of
def check_result(self, pm):
- res = EclassTestCase.check_result(self, pm)
+ EclassTestCase.check_result(self, pm)
for o in self.dependant_ebuilds:
- res &= o.check_result(pm)
- return res
+ o.check_result(pm)
diff --git a/pmstestsuite/library/standard/dbus_case.py b/pmstestsuite/library/standard/dbus_case.py
index e0cd09c..97462fb 100644
--- a/pmstestsuite/library/standard/dbus_case.py
+++ b/pmstestsuite/library/standard/dbus_case.py
@@ -104,7 +104,7 @@ class DBusBaseTestCase(object):
def check_result(self, pm):
self.assertTrue(self.dbus_started, 'build started')
- return self.check_dbus_result(self.dbus_output, pm)
+ self.check_dbus_result(self.dbus_output, pm)
class DBusEbuildTestCase(DBusBaseTestCase, EbuildTestCase):
""" D-Bus capable base test case. """
@@ -115,7 +115,7 @@ class DBusEbuildTestCase(DBusBaseTestCase, EbuildTestCase):
DBusBaseTestCase.__init__(self)
def check_dbus_result(self, output, pm):
- return EbuildTestCase.check_result(self, pm)
+ EbuildTestCase.check_result(self, pm)
class DBusEclassTestCase(DBusBaseTestCase, EclassTestCase):
""" D-Bus capable eclass test case. """
@@ -126,7 +126,7 @@ class DBusEclassTestCase(DBusBaseTestCase, EclassTestCase):
DBusBaseTestCase.__init__(self)
def check_dbus_result(self, output, pm):
- return EclassTestCase.check_result(self, pm)
+ EclassTestCase.check_result(self, pm)
class DBusEbuildDependencyTestCase(DBusBaseTestCase, EbuildDependencyTestCase):
""" D-Bus capable dependency test case. """
@@ -137,12 +137,12 @@ class DBusEbuildDependencyTestCase(DBusBaseTestCase, EbuildDependencyTestCase):
DBusBaseTestCase.__init__(self)
def check_dbus_result(self, output, pm):
- return EbuildDependencyTestCase.check_result(self, pm)
+ EbuildDependencyTestCase.check_result(self, pm)
def check_result(self, pm):
self.assertBool(not self.expect_failure, self.dbus_started,
'build started')
- return self.check_dbus_result(self.dbus_output, pm)
+ self.check_dbus_result(self.dbus_output, pm)
class DBusEclassDependencyTestCase(DBusBaseTestCase, EclassDependencyTestCase):
""" D-Bus capable eclass dependency test case. """
@@ -153,9 +153,9 @@ class DBusEclassDependencyTestCase(DBusBaseTestCase, EclassDependencyTestCase):
DBusBaseTestCase.__init__(self)
def check_dbus_result(self, output, pm):
- return EclassDependencyTestCase.check_result(self, pm)
+ EclassDependencyTestCase.check_result(self, pm)
def check_result(self, pm):
self.assertBool(not self.expect_failure, self.dbus_started,
'build started')
- return self.check_dbus_result(self.dbus_output, pm)
+ self.check_dbus_result(self.dbus_output, pm)
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-08-03 20:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-28 17:15 [gentoo-commits] proj/pms-test-suite:master commit in: pmstestsuite/library/standard/, pmstestsuite/library/, pmstestsuite/ Michał Górny
-- strict thread matches above, loose matches on Subject: below --
2011-08-03 20:17 Michał Górny
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox