From 0a19b9385a3f749fb7efcc2218cfabea931ff616 Mon Sep 17 00:00:00 2001 From: Jonathan Lange Date: Sun, 24 Oct 2010 10:21:01 +0100 Subject: [PATCH] Translate addUnexpectedSuccess to addFailure instead of addSuccess. --- testtools/testresult/real.py | 6 +++++- testtools/tests/test_testresult.py | 33 ++++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/testtools/testresult/real.py b/testtools/testresult/real.py index 2423703..1493f90 100644 --- a/testtools/testresult/real.py +++ b/testtools/testresult/real.py @@ -11,6 +11,7 @@ __all__ = [ ] import datetime +import sys import unittest from testtools.compat import _format_exc_info, str_is_unicode, _u @@ -432,7 +433,10 @@ class ExtendedToOriginalDecorator(object): def addUnexpectedSuccess(self, test, details=None): outcome = getattr(self.decorated, 'addUnexpectedSuccess', None) if outcome is None: - return self.decorated.addSuccess(test) + try: + test.fail("") + except test.failureException: + return self.addFailure(test, sys.exc_info()) if details is not None: try: return outcome(test, details=details) diff --git a/testtools/tests/test_testresult.py b/testtools/tests/test_testresult.py index 4636525..f9f4283 100644 --- a/testtools/tests/test_testresult.py +++ b/testtools/tests/test_testresult.py @@ -810,7 +810,7 @@ class TestExtendedToOriginalAddSkip( self.make_27_result() self.check_outcome_details_to_string(self.outcome) - def test_outcome_Extended_py27_no_reason(self): + def test_outcome_Extended_py27_reason(self): self.make_27_result() self.check_outcome_details_to_arg(self.outcome, 'foo', {'reason': Content(UTF8_TEXT, lambda:['foo'])}) @@ -857,9 +857,38 @@ class TestExtendedToOriginalAddSuccess( class TestExtendedToOriginalAddUnexpectedSuccess( - TestExtendedToOriginalAddSuccess): + TestExtendedToOriginalResultDecoratorBase): outcome = 'addUnexpectedSuccess' + expected = 'addFailure' + + def test_outcome_Original_py26(self): + self.make_26_result() + getattr(self.converter, self.outcome)(self) + [event] = self.result._events + self.assertEqual((self.expected, self), event[:2]) + + def test_outcome_Original_py27(self): + self.make_27_result() + self.check_outcome_nothing(self.outcome) + + def test_outcome_Original_pyextended(self): + self.make_extended_result() + self.check_outcome_nothing(self.outcome) + + def test_outcome_Extended_py26(self): + self.make_26_result() + getattr(self.converter, self.outcome)(self) + [event] = self.result._events + self.assertEqual((self.expected, self), event[:2]) + + def test_outcome_Extended_py27(self): + self.make_27_result() + self.check_outcome_details_to_nothing(self.outcome) + + def test_outcome_Extended_pyextended(self): + self.make_extended_result() + self.check_outcome_details(self.outcome) class TestExtendedToOriginalResultOtherAttributes(