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 import collections | 5 import collections |
6 import inspect | 6 import inspect |
7 import unittest | 7 import unittest |
8 | 8 |
9 | 9 |
10 class AutoStubMixIn(object): | 10 class AutoStubMixIn(object): |
(...skipping 16 matching lines...) Expand all Loading... |
27 for obj, items in self._saved.iteritems(): | 27 for obj, items in self._saved.iteritems(): |
28 for member, previous_value in items.iteritems(): | 28 for member, previous_value in items.iteritems(): |
29 setattr(obj, member, previous_value) | 29 setattr(obj, member, previous_value) |
30 | 30 |
31 | 31 |
32 class SimpleMock(object): | 32 class SimpleMock(object): |
33 """Really simple manual class mock.""" | 33 """Really simple manual class mock.""" |
34 def __init__(self, unit_test): | 34 def __init__(self, unit_test): |
35 """Do not call __init__ if you want to use the global call list to detect | 35 """Do not call __init__ if you want to use the global call list to detect |
36 ordering across different instances. | 36 ordering across different instances. |
| 37 |
| 38 Args: |
| 39 unit_test (unittest.TestCase): instance of a test class. |
37 """ | 40 """ |
38 self.calls = [] | 41 self.calls = [] |
39 self.unit_test = unit_test | 42 self.unit_test = unit_test |
40 self.assertEqual = unit_test.assertEqual | 43 self.assertEqual = unit_test.assertEqual |
41 | 44 |
42 def pop_calls(self): | 45 def pop_calls(self): |
43 """Returns the list of calls up to date. | 46 """Returns the list of calls up to date. |
44 | 47 |
45 Good to do self.assertEqual(expected, mock.pop_calls()). | 48 Good to do self.assertEqual(expected, mock.pop_calls()). |
46 """ | 49 """ |
(...skipping 15 matching lines...) Expand all Loading... |
62 | 65 |
63 class TestCase(unittest.TestCase, AutoStubMixIn): | 66 class TestCase(unittest.TestCase, AutoStubMixIn): |
64 """Adds self.mock() and self.has_failed() to a TestCase.""" | 67 """Adds self.mock() and self.has_failed() to a TestCase.""" |
65 def tearDown(self): | 68 def tearDown(self): |
66 AutoStubMixIn.tearDown(self) | 69 AutoStubMixIn.tearDown(self) |
67 unittest.TestCase.tearDown(self) | 70 unittest.TestCase.tearDown(self) |
68 | 71 |
69 def has_failed(self): | 72 def has_failed(self): |
70 """Returns True if the test has failed.""" | 73 """Returns True if the test has failed.""" |
71 return not self._resultForDoCleanups.wasSuccessful() | 74 return not self._resultForDoCleanups.wasSuccessful() |
OLD | NEW |