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 inspect | 5 import inspect |
6 import unittest | 6 import unittest |
7 | 7 |
8 | 8 |
9 class OrderedDict(object): | 9 class OrderedDict(object): |
10 """Incomplete and inefficient implementation of collections.OrderedDict.""" | 10 """Incomplete and inefficient implementation of collections.OrderedDict.""" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 def tearDown(self): | 49 def tearDown(self): |
50 """Restore all the mocked members.""" | 50 """Restore all the mocked members.""" |
51 if self._saved: | 51 if self._saved: |
52 for obj, items in self._saved.iteritems(): | 52 for obj, items in self._saved.iteritems(): |
53 for member, previous_value in items.iteritems(): | 53 for member, previous_value in items.iteritems(): |
54 setattr(obj, member, previous_value) | 54 setattr(obj, member, previous_value) |
55 | 55 |
56 | 56 |
57 class SimpleMock(object): | 57 class SimpleMock(object): |
58 """Really simple manual class mock.""" | 58 """Really simple manual class mock.""" |
59 calls = [] | |
60 | |
61 def __init__(self, unit_test): | 59 def __init__(self, unit_test): |
62 """Do not call __init__ if you want to use the global call list to detect | 60 """Do not call __init__ if you want to use the global call list to detect |
63 ordering across different instances. | 61 ordering across different instances. |
64 """ | 62 """ |
65 self.calls = [] | 63 self.calls = [] |
66 self.unit_test = unit_test | 64 self.unit_test = unit_test |
67 self.assertEquals = unit_test.assertEquals | 65 self.assertEquals = unit_test.assertEquals |
68 | 66 |
69 def pop_calls(self): | 67 def pop_calls(self): |
70 """Returns the list of calls up to date. | 68 """Returns the list of calls up to date. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 if hasattr(super(TestCase, self), 'assertIn'): | 119 if hasattr(super(TestCase, self), 'assertIn'): |
122 return super(TestCase, self).assertIn(expr1, expr2, msg) | 120 return super(TestCase, self).assertIn(expr1, expr2, msg) |
123 if expr1 not in expr2: | 121 if expr1 not in expr2: |
124 self.fail(msg or '%r not in %r' % (expr1, expr2)) | 122 self.fail(msg or '%r not in %r' % (expr1, expr2)) |
125 | 123 |
126 def assertLess(self, a, b, msg=None): | 124 def assertLess(self, a, b, msg=None): |
127 if hasattr(super(TestCase, self), 'assertLess'): | 125 if hasattr(super(TestCase, self), 'assertLess'): |
128 return super(TestCase, self).assertLess(a, b, msg) | 126 return super(TestCase, self).assertLess(a, b, msg) |
129 if not a < b: | 127 if not a < b: |
130 self.fail(msg or '%r not less than %r' % (a, b)) | 128 self.fail(msg or '%r not less than %r' % (a, b)) |
OLD | NEW |