| OLD | NEW |
| 1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 __version__ = '1.0' | 5 __version__ = '1.0' |
| 6 | 6 |
| 7 import collections | 7 import collections |
| 8 import inspect | 8 import inspect |
| 9 import unittest | 9 import unittest |
| 10 import sys |
| 10 | 11 |
| 11 | 12 |
| 12 class AutoStubMixIn(object): | 13 class AutoStubMixIn(object): |
| 13 """Automatically restores stubbed functions on unit test teardDown. | 14 """Automatically restores stubbed functions on unit test teardDown. |
| 14 | 15 |
| 15 It's an extremely lightweight mocking class that doesn't require bookeeping. | 16 It's an extremely lightweight mocking class that doesn't require bookeeping. |
| 16 """ | 17 """ |
| 17 _saved = None | 18 _saved = None |
| 18 | 19 |
| 19 def mock(self, obj, member, mock): | 20 def mock(self, obj, member, mock): |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 | 64 |
| 64 | 65 |
| 65 class TestCase(unittest.TestCase, AutoStubMixIn): | 66 class TestCase(unittest.TestCase, AutoStubMixIn): |
| 66 """Adds self.mock() and self.has_failed() to a TestCase.""" | 67 """Adds self.mock() and self.has_failed() to a TestCase.""" |
| 67 def tearDown(self): | 68 def tearDown(self): |
| 68 AutoStubMixIn.tearDown(self) | 69 AutoStubMixIn.tearDown(self) |
| 69 unittest.TestCase.tearDown(self) | 70 unittest.TestCase.tearDown(self) |
| 70 | 71 |
| 71 def has_failed(self): | 72 def has_failed(self): |
| 72 """Returns True if the test has failed.""" | 73 """Returns True if the test has failed.""" |
| 73 return not self._resultForDoCleanups.wasSuccessful() | 74 if self._resultForDoCleanups: |
| 75 return not self._resultForDoCleanups.wasSuccessful() |
| 76 ex, _, _, = sys.exc_info() |
| 77 return bool(ex) |
| OLD | NEW |