* [gentoo-commits] proj/pms-test-suite:master commit in: pmstestsuite/library/, pmstestsuite/, pmstestsuite/output/
@ 2011-08-05 17:09 Michał Górny
0 siblings, 0 replies; only message in thread
From: Michał Górny @ 2011-08-05 17:09 UTC (permalink / raw
To: gentoo-commits
commit: 7b60ab13e5e9a2bb7e99840e3ad18f1bc012c1b9
Author: Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Fri Aug 5 17:02:04 2011 +0000
Commit: Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Fri Aug 5 17:02:04 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/pms-test-suite.git;a=commit;h=7b60ab13
Introduce a dedicated TestResult object.
This way, we keep the boolean test result & assertions in the same,
clean place.
---
pmstestsuite/cli.py | 22 ++++++++++--------
pmstestsuite/library/case.py | 13 +++++++++++
pmstestsuite/output/__init__.py | 44 +++++++++++++++++++++++++++++++++++++-
pmstestsuite/output/cli.py | 2 +-
4 files changed, 68 insertions(+), 13 deletions(-)
diff --git a/pmstestsuite/cli.py b/pmstestsuite/cli.py
index adf341e..d50bb4a 100644
--- a/pmstestsuite/cli.py
+++ b/pmstestsuite/cli.py
@@ -13,7 +13,7 @@ from pmstestsuite import PV
from pmstestsuite.library import load_library
from pmstestsuite.repository import NewEbuildRepository
from pmstestsuite.repository.pms_eclass import get_common_eclass_files
-from pmstestsuite.output import get_output_modules
+from pmstestsuite.output import get_output_modules, TestResult
from pmstestsuite.pm import get_package_managers
class PMSTestSuiteCLI(object):
@@ -167,17 +167,19 @@ class PMSTestSuiteCLI(object):
self._print_stage('Checking test results')
self.results = {}
for t in self.test_library:
- try:
- t.check_result(self.pm)
- except Exception as e:
- outc = 'F' if isinstance(e, AssertionError) else 'E'
- self.results[t] = False
- # XXX: store exception details somewhere?
- else:
+ tr = TestResult(t, self.pm)
+
+ if tr:
outc = '.'
- self.results[t] = True
- t.clean(self.pm)
+ elif tr.exception:
+ outc = 'E'
+ raise tr.exception
+ else:
+ outc = 'F'
print(outc, end='')
+
+ self.results[t] = tr
+ t.clean(self.pm)
print('')
if self.pm.has_pending_actions:
diff --git a/pmstestsuite/library/case.py b/pmstestsuite/library/case.py
index 6b74fc6..d05815c 100644
--- a/pmstestsuite/library/case.py
+++ b/pmstestsuite/library/case.py
@@ -288,6 +288,19 @@ class TestCase(ABCObject):
"""
pass
+ def pop_assertions(self):
+ """
+ Get a copy of the assertion list and clear its container afterwards.
+ This way, the test case can be reused with other PM.
+
+ @return: assertion list
+ @rtype: list(L{AssertionResult})
+ """
+
+ ret = self.assertions
+ self.assertions = []
+ return ret
+
class EbuildTestCase(TestCase):
"""
Test case using a single ebuild (per EAPI).
diff --git a/pmstestsuite/output/__init__.py b/pmstestsuite/output/__init__.py
index b6a1446..e57aad9 100644
--- a/pmstestsuite/output/__init__.py
+++ b/pmstestsuite/output/__init__.py
@@ -2,9 +2,49 @@
# (c) 2011 Michał Górny <mgorny@gentoo.org>
# Released under the terms of the 2-clause BSD license.
-from gentoopm.util import ABCObject
+from gentoopm.util import ABCObject, BoolCompat
from abc import abstractmethod, abstractproperty
+class TestResult(BoolCompat):
+ """ Test result container. """
+
+ _SUCCESS = 0
+ _FAILURE = 1
+ _EXCEPT = 2
+
+ def __init__(self, t, *args):
+ """
+ Instantiate test results by checking the test results.
+
+ @param t: test to check
+ @type t: L{TestCase}
+ @param args: args to pass to check_result()
+ """
+
+ try:
+ t.check_result(*args)
+ except AssertionError:
+ self._res = self._FAILURE
+ except Exception as e:
+ self._res = self._EXCEPT
+ self._exc = e
+ else:
+ self._res = self._SUCCESS
+ self._assert = t.pop_assertions()
+
+ def __bool__(self):
+ return self._res == self._SUCCESS
+
+ @property
+ def assertions(self):
+ return self._assert
+
+ @property
+ def exception(self):
+ if self._res == self._EXCEPT:
+ return self._exc
+ return None
+
class OutputModule(ABCObject):
""" A module handling test results output. """
@@ -23,7 +63,7 @@ class OutputModule(ABCObject):
Output the test results.
@param results: test result dict
- @type results: dict(L{TestCase} -> bool)
+ @type results: dict(L{TestCase} -> L{TestResult})
@param verbose: whether to output the results verbosely
@type verbose: bool
@return: whether all of the tests succeeded
diff --git a/pmstestsuite/output/cli.py b/pmstestsuite/output/cli.py
index f7d882f..3d0217f 100644
--- a/pmstestsuite/output/cli.py
+++ b/pmstestsuite/output/cli.py
@@ -18,7 +18,7 @@ class CLIOutput(OutputModule):
tl = failed if not verbose else results.items()
for t, r in tl:
print('- %s [%s]' % (t, 'OK' if r else 'FAILED'))
- for a in t.assertions:
+ for a in r.assertions:
print('-> %s: %s [%s]' % (a.name, str(a),
'OK' if a else 'FAILED'))
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2011-08-05 17:10 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-05 17:09 [gentoo-commits] proj/pms-test-suite:master commit in: pmstestsuite/library/, pmstestsuite/, pmstestsuite/output/ 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