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

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

Issue 762883002: Make device serial required in AdbWrapper/DeviceUtils (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: renamed: exclude -> ignore Created 6 years 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/instrumentation/test_runner_test.py ('k') | no next file » | 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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 return mock.patch(call.name, **kwargs) 115 return mock.patch(call.name, **kwargs)
116 116
117 def watchCalls(self, calls): 117 def watchCalls(self, calls):
118 """Add calls to the set of watched calls. 118 """Add calls to the set of watched calls.
119 119
120 Args: 120 Args:
121 calls: a sequence of mock.call instances identifying targets to watch 121 calls: a sequence of mock.call instances identifying targets to watch
122 """ 122 """
123 self._watched.update((call.name, call) for call in calls) 123 self._watched.update((call.name, call) for call in calls)
124 124
125 def watchMethodCalls(self, call): 125 def watchMethodCalls(self, call, ignore=None):
126 """Watch all public methods of the target identified by a self.call. 126 """Watch all public methods of the target identified by a self.call.
127 127
128 Args: 128 Args:
129 call: a self.call instance indetifying an object 129 call: a self.call instance indetifying an object
130 ignore: a list of public methods to ignore when watching for calls
130 """ 131 """
131 target = self.call_target(call) 132 target = self.call_target(call)
133 if ignore is None:
134 ignore = []
132 self.watchCalls(getattr(call, method) 135 self.watchCalls(getattr(call, method)
133 for method in dir(target.__class__) 136 for method in dir(target.__class__)
134 if not method.startswith('_')) 137 if not method.startswith('_') and not method in ignore)
135 138
136 def clearWatched(self): 139 def clearWatched(self):
137 """Clear the set of watched calls.""" 140 """Clear the set of watched calls."""
138 self._watched = {} 141 self._watched = {}
139 142
140 def assertCalls(self, *calls): 143 def assertCalls(self, *calls):
141 """A context manager to assert that a sequence of calls is made. 144 """A context manager to assert that a sequence of calls is made.
142 145
143 During the assertion, a number of functions and methods will be "watched", 146 During the assertion, a number of functions and methods will be "watched",
144 and any calls made to them is expected to appear---in the exact same order, 147 and any calls made to them is expected to appear---in the exact same order,
(...skipping 20 matching lines...) Expand all
165 Raises: 168 Raises:
166 AssertionError if the watched targets do not receive the exact sequence 169 AssertionError if the watched targets do not receive the exact sequence
167 of calls specified. Missing calls, extra calls, and calls with 170 of calls specified. Missing calls, extra calls, and calls with
168 mismatching arguments, all cause the assertion to fail. 171 mismatching arguments, all cause the assertion to fail.
169 """ 172 """
170 return self._AssertCalls(self, calls, self._watched) 173 return self._AssertCalls(self, calls, self._watched)
171 174
172 def assertCall(self, call, action=None): 175 def assertCall(self, call, action=None):
173 return self.assertCalls((call, action)) 176 return self.assertCalls((call, action))
174 177
OLDNEW
« no previous file with comments | « build/android/pylib/instrumentation/test_runner_test.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698