| 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 | |
| 10 import sys | 9 import sys |
| 11 import unittest | 10 import unittest |
| 12 | 11 |
| 13 from pylib import constants | 12 from devil import devil_env |
| 14 | 13 |
| 15 sys.path.append(os.path.join( | 14 sys.path.append(devil_env.config.pymock_path) |
| 16 constants.DIR_SOURCE_ROOT, 'third_party', 'pymock')) | |
| 17 import mock # pylint: disable=F0401 | 15 import mock # pylint: disable=F0401 |
| 18 | 16 |
| 19 | 17 |
| 20 class TestCase(unittest.TestCase): | 18 class TestCase(unittest.TestCase): |
| 21 """Adds assertCalls to TestCase objects.""" | 19 """Adds assertCalls to TestCase objects.""" |
| 22 class _AssertCalls(object): | 20 class _AssertCalls(object): |
| 23 def __init__(self, test_case, expected_calls, watched): | 21 def __init__(self, test_case, expected_calls, watched): |
| 24 def call_action(pair): | 22 def call_action(pair): |
| 25 if isinstance(pair, type(mock.call)): | 23 if isinstance(pair, type(mock.call)): |
| 26 return (pair, None) | 24 return (pair, None) |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 Raises: | 171 Raises: |
| 174 AssertionError if the watched targets do not receive the exact sequence | 172 AssertionError if the watched targets do not receive the exact sequence |
| 175 of calls specified. Missing calls, extra calls, and calls with | 173 of calls specified. Missing calls, extra calls, and calls with |
| 176 mismatching arguments, all cause the assertion to fail. | 174 mismatching arguments, all cause the assertion to fail. |
| 177 """ | 175 """ |
| 178 return self._AssertCalls(self, calls, self._watched) | 176 return self._AssertCalls(self, calls, self._watched) |
| 179 | 177 |
| 180 def assertCall(self, call, action=None): | 178 def assertCall(self, call, action=None): |
| 181 return self.assertCalls((call, action)) | 179 return self.assertCalls((call, action)) |
| 182 | 180 |
| OLD | NEW |