Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Side by Side Diff: build/android/pylib/utils/mock_calls.py

Issue 935333002: Update from https://crrev.com/316786 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « build/android/pylib/utils/md5sum.py ('k') | build/android/pylib/utils/mock_calls_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 Args: 103 Args:
104 call: a mock.call instance identifying a target to patch 104 call: a mock.call instance identifying a target to patch
105 Extra keyword arguments are processed by mock.patch 105 Extra keyword arguments are processed by mock.patch
106 106
107 Returns: 107 Returns:
108 A context manager to mock/unmock the target of the call 108 A context manager to mock/unmock the target of the call
109 """ 109 """
110 if call.name.startswith('self.'): 110 if call.name.startswith('self.'):
111 target = self.call_target(call.parent) 111 target = self.call_target(call.parent)
112 _, attribute = call.name.rsplit('.', 1) 112 _, attribute = call.name.rsplit('.', 1)
113 return mock.patch.object(target, attribute, **kwargs) 113 if (hasattr(type(target), attribute)
114 and isinstance(getattr(type(target), attribute), property)):
115 return mock.patch.object(
116 type(target), attribute, new_callable=mock.PropertyMock, **kwargs)
117 else:
118 return mock.patch.object(target, attribute, **kwargs)
114 else: 119 else:
115 return mock.patch(call.name, **kwargs) 120 return mock.patch(call.name, **kwargs)
116 121
117 def watchCalls(self, calls): 122 def watchCalls(self, calls):
118 """Add calls to the set of watched calls. 123 """Add calls to the set of watched calls.
119 124
120 Args: 125 Args:
121 calls: a sequence of mock.call instances identifying targets to watch 126 calls: a sequence of mock.call instances identifying targets to watch
122 """ 127 """
123 self._watched.update((call.name, call) for call in calls) 128 self._watched.update((call.name, call) for call in calls)
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 Raises: 173 Raises:
169 AssertionError if the watched targets do not receive the exact sequence 174 AssertionError if the watched targets do not receive the exact sequence
170 of calls specified. Missing calls, extra calls, and calls with 175 of calls specified. Missing calls, extra calls, and calls with
171 mismatching arguments, all cause the assertion to fail. 176 mismatching arguments, all cause the assertion to fail.
172 """ 177 """
173 return self._AssertCalls(self, calls, self._watched) 178 return self._AssertCalls(self, calls, self._watched)
174 179
175 def assertCall(self, call, action=None): 180 def assertCall(self, call, action=None):
176 return self.assertCalls((call, action)) 181 return self.assertCalls((call, action))
177 182
OLDNEW
« no previous file with comments | « build/android/pylib/utils/md5sum.py ('k') | build/android/pylib/utils/mock_calls_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698