diff options
author | Michał Górny <mgorny@gentoo.org> | 2011-08-05 19:02:04 +0200 |
---|---|---|
committer | Michał Górny <mgorny@gentoo.org> | 2011-08-05 19:02:04 +0200 |
commit | 7b60ab13e5e9a2bb7e99840e3ad18f1bc012c1b9 (patch) | |
tree | aef8bf3fb358d2ce967a5b80eb44bbbc14337dcf /pmstestsuite/output/__init__.py | |
parent | Support running tests using multiple PMs. (diff) | |
download | pms-test-suite-7b60ab13e5e9a2bb7e99840e3ad18f1bc012c1b9.tar.gz pms-test-suite-7b60ab13e5e9a2bb7e99840e3ad18f1bc012c1b9.tar.bz2 pms-test-suite-7b60ab13e5e9a2bb7e99840e3ad18f1bc012c1b9.zip |
Introduce a dedicated TestResult object.
This way, we keep the boolean test result & assertions in the same,
clean place.
Diffstat (limited to 'pmstestsuite/output/__init__.py')
-rw-r--r-- | pmstestsuite/output/__init__.py | 44 |
1 files changed, 42 insertions, 2 deletions
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 |