| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 """ | 5 """ |
| 6 A test facility to assert call sequences while mocking their behavior. | 6 A test facility to assert call sequences while mocking their behavior. |
| 7 """ | 7 """ |
| 8 | 8 |
| 9 import os | 9 import os |
| 10 import sys | 10 import sys |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 def do_check(call): | 30 def do_check(call): |
| 31 def side_effect(*args, **kwargs): | 31 def side_effect(*args, **kwargs): |
| 32 received_call = call(*args, **kwargs) | 32 received_call = call(*args, **kwargs) |
| 33 self._test_case.assertTrue( | 33 self._test_case.assertTrue( |
| 34 self._expected_calls, | 34 self._expected_calls, |
| 35 msg=('Unexpected call: %s' % str(received_call))) | 35 msg=('Unexpected call: %s' % str(received_call))) |
| 36 expected_call, action = self._expected_calls.pop(0) | 36 expected_call, action = self._expected_calls.pop(0) |
| 37 self._test_case.assertTrue( | 37 self._test_case.assertTrue( |
| 38 received_call == expected_call, | 38 received_call == expected_call, |
| 39 msg=('Expected call missmatch:\n' | 39 msg=('Expected call mismatch:\n' |
| 40 ' expected: %s\n' | 40 ' expected: %s\n' |
| 41 ' received: %s\n' | 41 ' received: %s\n' |
| 42 % (str(expected_call), str(received_call)))) | 42 % (str(expected_call), str(received_call)))) |
| 43 if callable(action): | 43 if callable(action): |
| 44 return action(*args, **kwargs) | 44 return action(*args, **kwargs) |
| 45 else: | 45 else: |
| 46 return action | 46 return action |
| 47 return side_effect | 47 return side_effect |
| 48 | 48 |
| 49 self._test_case = test_case | 49 self._test_case = test_case |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 Raises: | 173 Raises: |
| 174 AssertionError if the watched targets do not receive the exact sequence | 174 AssertionError if the watched targets do not receive the exact sequence |
| 175 of calls specified. Missing calls, extra calls, and calls with | 175 of calls specified. Missing calls, extra calls, and calls with |
| 176 mismatching arguments, all cause the assertion to fail. | 176 mismatching arguments, all cause the assertion to fail. |
| 177 """ | 177 """ |
| 178 return self._AssertCalls(self, calls, self._watched) | 178 return self._AssertCalls(self, calls, self._watched) |
| 179 | 179 |
| 180 def assertCall(self, call, action=None): | 180 def assertCall(self, call, action=None): |
| 181 return self.assertCalls((call, action)) | 181 return self.assertCalls((call, action)) |
| 182 | 182 |
| OLD | NEW |