diff options
Diffstat (limited to 'testrepository/ui/__init__.py')
-rw-r--r-- | testrepository/ui/__init__.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/testrepository/ui/__init__.py b/testrepository/ui/__init__.py index 8e10d5f..d59ac74 100644 --- a/testrepository/ui/__init__.py +++ b/testrepository/ui/__init__.py @@ -22,6 +22,9 @@ See AbstractUI for details on what UI classes should do and are responsible for. """ +from testtools import TestResult + + class AbstractUI(object): """The base class for UI objects, this providers helpers and the interface. @@ -159,3 +162,41 @@ class AbstractUI(object): """ # This might not be the right place. raise NotImplementedError(self.subprocess_Popen) + + +class BaseUITestResult(TestResult): + """An abstract test result used with the UI. + + AbstractUI.make_result probably wants to return an object like this. + """ + + def __init__(self, ui, get_id): + """Construct an `AbstractUITestResult`. + + :param ui: The UI this result is associated with. + :param get_id: A nullary callable that returns the id of the test run. + """ + super(BaseUITestResult, self).__init__() + self.ui = ui + self.get_id = get_id + + def _output_run(self, run_id): + """Output a test run. + + :param run_id: The run id. + """ + if self.ui.options.quiet: + return + values = [('id', run_id), ('tests', self.testsRun)] + failures = len(self.failures) + len(self.errors) + if failures: + values.append(('failures', failures)) + skips = sum(map(len, self.skip_reasons.itervalues())) + if skips: + values.append(('skips', skips)) + self.ui.output_values(values) + + def stopTestRun(self): + super(BaseUITestResult, self).stopTestRun() + run_id = self.get_id() + self._output_run(run_id) |