← Back to team overview

testtools-dev team mailing list archive

[Merge] lp:~jml/testtools/test-result-decorator into lp:testtools

 

Jonathan Lange has proposed merging lp:~jml/testtools/test-result-decorator into lp:testtools with lp:~jml/testtools/forward-current-tags as a prerequisite.

Requested reviews:
  testtools committers (testtools-committers)

For more details, see:
https://code.launchpad.net/~jml/testtools/test-result-decorator/+merge/101621

Adds TestResultDecorator to testtools, since it's application is more generally useful than in subunit.
-- 
https://code.launchpad.net/~jml/testtools/test-result-decorator/+merge/101621
Your team testtools developers is subscribed to branch lp:testtools.
=== modified file 'NEWS'
--- NEWS	2012-04-03 03:28:29 +0000
+++ NEWS	2012-04-11 18:15:18 +0000
@@ -16,6 +16,12 @@
 * ``ErrorHolder`` is now just a function - all the logic is in ``PlaceHolder``.
   (Robert Collins)
 
+Improvements
+------------
+
+* ``TestResultDecorator`` brought over from subunit.  (Jonathan Lange)
+
+
 0.9.14
 ~~~~~~
 

=== modified file 'doc/for-framework-folk.rst'
--- doc/for-framework-folk.rst	2011-08-09 12:36:31 +0000
+++ doc/for-framework-folk.rst	2012-04-11 18:15:18 +0000
@@ -151,6 +151,14 @@
 component test results return.
 
 
+TestResultDecorator
+-------------------
+
+Not strictly a ``TestResult``, but something that implements the extended
+``TestResult`` interface of testtools.  It can be subclassed to create objects
+that wrap ``TestResults``.
+
+
 TextTestResult
 --------------
 

=== modified file 'testtools/__init__.py'
--- testtools/__init__.py	2012-02-16 10:52:15 +0000
+++ testtools/__init__.py	2012-04-11 18:15:18 +0000
@@ -17,6 +17,7 @@
     'TestCase',
     'TestCommand',
     'TestResult',
+    'TestResultDecorator',
     'TextTestResult',
     'RunTest',
     'skip',
@@ -56,6 +57,7 @@
     ExtendedToOriginalDecorator,
     MultiTestResult,
     TestResult,
+    TestResultDecorator,
     TextTestResult,
     ThreadsafeForwardingResult,
     )

=== modified file 'testtools/testresult/__init__.py'
--- testtools/testresult/__init__.py	2011-01-22 17:56:00 +0000
+++ testtools/testresult/__init__.py	2012-04-11 18:15:18 +0000
@@ -6,6 +6,7 @@
     'ExtendedToOriginalDecorator',
     'MultiTestResult',
     'TestResult',
+    'TestResultDecorator',
     'TextTestResult',
     'ThreadsafeForwardingResult',
     ]
@@ -14,6 +15,7 @@
     ExtendedToOriginalDecorator,
     MultiTestResult,
     TestResult,
+    TestResultDecorator,
     TextTestResult,
     ThreadsafeForwardingResult,
     )

=== modified file 'testtools/testresult/real.py'
--- testtools/testresult/real.py	2012-04-11 18:15:18 +0000
+++ testtools/testresult/real.py	2012-04-11 18:15:18 +0000
@@ -7,6 +7,7 @@
     'ExtendedToOriginalDecorator',
     'MultiTestResult',
     'TestResult',
+    'TestResultDecorator',
     'ThreadsafeForwardingResult',
     ]
 
@@ -653,6 +654,75 @@
         return self.decorated.wasSuccessful()
 
 
+class TestResultDecorator(object):
+    """General pass-through decorator.
+
+    This provides a base that other TestResults can inherit from to
+    gain basic forwarding functionality.
+    """
+
+    def __init__(self, decorated):
+        """Create a TestResultDecorator forwarding to decorated."""
+        self.decorated = decorated
+
+    def startTest(self, test):
+        return self.decorated.startTest(test)
+
+    def startTestRun(self):
+        return self.decorated.startTestRun()
+
+    def stopTest(self, test):
+        return self.decorated.stopTest(test)
+
+    def stopTestRun(self):
+        return self.decorated.stopTestRun()
+
+    def addError(self, test, err=None, details=None):
+        return self.decorated.addError(test, err, details=details)
+
+    def addFailure(self, test, err=None, details=None):
+        return self.decorated.addFailure(test, err, details=details)
+
+    def addSuccess(self, test, details=None):
+        return self.decorated.addSuccess(test, details=details)
+
+    def addSkip(self, test, reason=None, details=None):
+        return self.decorated.addSkip(test, reason, details=details)
+
+    def addExpectedFailure(self, test, err=None, details=None):
+        return self.decorated.addExpectedFailure(test, err, details=details)
+
+    def addUnexpectedSuccess(self, test, details=None):
+        return self.decorated.addUnexpectedSuccess(test, details=details)
+
+    def progress(self, offset, whence):
+        return self.decorated.progress(offset, whence)
+
+    def wasSuccessful(self):
+        return self.decorated.wasSuccessful()
+
+    @property
+    def current_tags(self):
+        return self.decorated.current_tags
+
+    @property
+    def shouldStop(self):
+        return self.decorated.shouldStop
+
+    def stop(self):
+        return self.decorated.stop()
+
+    @property
+    def testsRun(self):
+        return self.decorated.testsRun
+
+    def tags(self, new_tags, gone_tags):
+        return self.decorated.tags(new_tags, gone_tags)
+
+    def time(self, a_datetime):
+        return self.decorated.time(a_datetime)
+
+
 class _StringException(Exception):
     """An exception made from an arbitrary string."""
 

=== modified file 'testtools/tests/test_testresult.py'
--- testtools/tests/test_testresult.py	2012-04-11 18:15:18 +0000
+++ testtools/tests/test_testresult.py	2012-04-11 18:15:18 +0000
@@ -19,6 +19,7 @@
     MultiTestResult,
     TestCase,
     TestResult,
+    TestResultDecorator,
     TextTestResult,
     ThreadsafeForwardingResult,
     testresult,
@@ -411,6 +412,14 @@
         return ExtendedToOriginalDecorator(Python27TestResult())
 
 
+class TestTestResultDecoratorContract(TestCase, StartTestRunContract):
+
+    run_test_with = FullStackRunTest
+
+    def makeResult(self):
+        return TestResultDecorator(TestResult())
+
+
 class TestTestResult(TestCase):
     """Tests for 'TestResult'."""
 


Follow ups