OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """ | 6 """ |
7 Unit tests for the contents of device_utils.py (mostly DeviceUtils). | 7 Unit tests for the contents of device_utils.py (mostly DeviceUtils). |
8 """ | 8 """ |
9 | 9 |
10 # pylint: disable=C0321 | 10 # pylint: disable=C0321 |
(...skipping 21 matching lines...) Expand all Loading... |
32 # RunCommand from third_party/android_testrunner/run_command.py is mocked | 32 # RunCommand from third_party/android_testrunner/run_command.py is mocked |
33 # below, so its path needs to be in sys.path. | 33 # below, so its path needs to be in sys.path. |
34 sys.path.append(os.path.join( | 34 sys.path.append(os.path.join( |
35 constants.DIR_SOURCE_ROOT, 'third_party', 'android_testrunner')) | 35 constants.DIR_SOURCE_ROOT, 'third_party', 'android_testrunner')) |
36 | 36 |
37 sys.path.append(os.path.join( | 37 sys.path.append(os.path.join( |
38 constants.DIR_SOURCE_ROOT, 'third_party', 'pymock')) | 38 constants.DIR_SOURCE_ROOT, 'third_party', 'pymock')) |
39 import mock # pylint: disable=F0401 | 39 import mock # pylint: disable=F0401 |
40 | 40 |
41 | 41 |
42 class DeviceUtilsInitTest(unittest.TestCase): | 42 class DeviceUtilsTest(unittest.TestCase): |
43 | 43 |
44 def testInitWithStr(self): | 44 def testInitWithStr(self): |
45 serial_as_str = str('0123456789abcdef') | 45 serial_as_str = str('0123456789abcdef') |
46 d = device_utils.DeviceUtils('0123456789abcdef') | 46 d = device_utils.DeviceUtils('0123456789abcdef') |
47 self.assertEqual(serial_as_str, d.adb.GetDeviceSerial()) | 47 self.assertEqual(serial_as_str, d.adb.GetDeviceSerial()) |
48 | 48 |
49 def testInitWithUnicode(self): | 49 def testInitWithUnicode(self): |
50 serial_as_unicode = unicode('fedcba9876543210') | 50 serial_as_unicode = unicode('fedcba9876543210') |
51 d = device_utils.DeviceUtils(serial_as_unicode) | 51 d = device_utils.DeviceUtils(serial_as_unicode) |
52 self.assertEqual(serial_as_unicode, d.adb.GetDeviceSerial()) | 52 self.assertEqual(serial_as_unicode, d.adb.GetDeviceSerial()) |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 def __exit__(self, exc_type, exc_val, exc_tb): | 114 def __exit__(self, exc_type, exc_val, exc_tb): |
115 pass | 115 pass |
116 | 116 |
117 | 117 |
118 class _PatchedFunction(object): | 118 class _PatchedFunction(object): |
119 def __init__(self, patched=None, mocked=None): | 119 def __init__(self, patched=None, mocked=None): |
120 self.patched = patched | 120 self.patched = patched |
121 self.mocked = mocked | 121 self.mocked = mocked |
122 | 122 |
123 | 123 |
| 124 class DeviceUtilsOldImplTest(unittest.TestCase): |
| 125 |
| 126 class AndroidCommandsCalls(object): |
| 127 |
| 128 def __init__(self, test_case, cmd_ret, comp): |
| 129 self._cmds = cmd_ret |
| 130 self._comp = comp |
| 131 self._run_command = _PatchedFunction() |
| 132 self._test_case = test_case |
| 133 self._total_received = 0 |
| 134 |
| 135 def __enter__(self): |
| 136 self._run_command.patched = mock.patch( |
| 137 'run_command.RunCommand', |
| 138 side_effect=lambda c, **kw: self._ret(c)) |
| 139 self._run_command.mocked = self._run_command.patched.__enter__() |
| 140 |
| 141 def _ret(self, actual_cmd): |
| 142 if sys.exc_info()[0] is None: |
| 143 on_failure_fmt = ('\n' |
| 144 ' received command: %s\n' |
| 145 ' expected command: %s') |
| 146 self._test_case.assertGreater( |
| 147 len(self._cmds), self._total_received, |
| 148 msg=on_failure_fmt % (actual_cmd, None)) |
| 149 expected_cmd, ret = self._cmds[self._total_received] |
| 150 self._total_received += 1 |
| 151 self._test_case.assertTrue( |
| 152 self._comp(expected_cmd, actual_cmd), |
| 153 msg=on_failure_fmt % (actual_cmd, expected_cmd)) |
| 154 return ret |
| 155 return '' |
| 156 |
| 157 def __exit__(self, exc_type, exc_val, exc_tb): |
| 158 self._run_command.patched.__exit__(exc_type, exc_val, exc_tb) |
| 159 if exc_type is None: |
| 160 on_failure = "adb commands don't match.\nExpected:%s\nActual:%s" % ( |
| 161 ''.join('\n %s' % c for c, _ in self._cmds), |
| 162 ''.join('\n %s' % a[0] |
| 163 for _, a, kw in self._run_command.mocked.mock_calls)) |
| 164 self._test_case.assertEqual( |
| 165 len(self._cmds), len(self._run_command.mocked.mock_calls), |
| 166 msg=on_failure) |
| 167 for (expected_cmd, _r), (_n, actual_args, actual_kwargs) in zip( |
| 168 self._cmds, self._run_command.mocked.mock_calls): |
| 169 self._test_case.assertEqual(1, len(actual_args), msg=on_failure) |
| 170 self._test_case.assertTrue(self._comp(expected_cmd, actual_args[0]), |
| 171 msg=on_failure) |
| 172 self._test_case.assertTrue('timeout_time' in actual_kwargs, |
| 173 msg=on_failure) |
| 174 self._test_case.assertTrue('retry_count' in actual_kwargs, |
| 175 msg=on_failure) |
| 176 |
| 177 def assertNoAdbCalls(self): |
| 178 return type(self).AndroidCommandsCalls(self, [], str.__eq__) |
| 179 |
| 180 def assertCalls(self, cmd, ret, comp=str.__eq__): |
| 181 return type(self).AndroidCommandsCalls(self, [(cmd, ret)], comp) |
| 182 |
| 183 def assertCallsSequence(self, cmd_ret, comp=str.__eq__): |
| 184 return type(self).AndroidCommandsCalls(self, cmd_ret, comp) |
| 185 |
| 186 def setUp(self): |
| 187 self._get_adb_path_patch = mock.patch('pylib.constants.GetAdbPath', |
| 188 mock.Mock(return_value='adb')) |
| 189 self._get_adb_path_patch.start() |
| 190 self.device = device_utils.DeviceUtils( |
| 191 '0123456789abcdef', default_timeout=1, default_retries=0) |
| 192 |
| 193 def tearDown(self): |
| 194 self._get_adb_path_patch.stop() |
| 195 |
| 196 |
124 def _AdbWrapperMock(test_serial): | 197 def _AdbWrapperMock(test_serial): |
125 adb = mock.Mock(spec=adb_wrapper.AdbWrapper) | 198 adb = mock.Mock(spec=adb_wrapper.AdbWrapper) |
126 adb.__str__ = mock.Mock(return_value=test_serial) | 199 adb.__str__ = mock.Mock(return_value=test_serial) |
127 adb.GetDeviceSerial.return_value = test_serial | 200 adb.GetDeviceSerial.return_value = test_serial |
128 return adb | 201 return adb |
129 | 202 |
130 | 203 |
131 class DeviceUtilsTest(mock_calls.TestCase): | 204 class DeviceUtilsNewImplTest(mock_calls.TestCase): |
132 | 205 |
133 def setUp(self): | 206 def setUp(self): |
134 self.adb = _AdbWrapperMock('0123456789abcdef') | 207 self.adb = _AdbWrapperMock('0123456789abcdef') |
135 self.device = device_utils.DeviceUtils( | 208 self.device = device_utils.DeviceUtils( |
136 self.adb, default_timeout=10, default_retries=0) | 209 self.adb, default_timeout=10, default_retries=0) |
137 self.watchMethodCalls(self.call.adb, ignore=['GetDeviceSerial']) | 210 self.watchMethodCalls(self.call.adb, ignore=['GetDeviceSerial']) |
138 | 211 |
139 def ShellError(self, output=None, status=1): | 212 def ShellError(self, output=None, status=1): |
140 def action(cmd, *args, **kwargs): | 213 def action(cmd, *args, **kwargs): |
141 raise device_errors.AdbShellCommandFailedError( | 214 raise device_errors.AdbShellCommandFailedError( |
142 cmd, output, status, str(self.device)) | 215 cmd, output, status, str(self.device)) |
143 if output is None: | 216 if output is None: |
144 output = 'Permission denied\n' | 217 output = 'Permission denied\n' |
145 return action | 218 return action |
146 | 219 |
147 def TimeoutError(self, msg=None): | 220 def TimeoutError(self, msg=None): |
148 if msg is None: | 221 if msg is None: |
149 msg = 'Operation timed out' | 222 msg = 'Operation timed out' |
150 return mock.Mock(side_effect=device_errors.CommandTimeoutError( | 223 return mock.Mock(side_effect=device_errors.CommandTimeoutError( |
151 msg, str(self.device))) | 224 msg, str(self.device))) |
152 | 225 |
153 def CommandError(self, msg=None): | 226 def CommandError(self, msg=None): |
154 if msg is None: | 227 if msg is None: |
155 msg = 'Command failed' | 228 msg = 'Command failed' |
156 return mock.Mock(side_effect=device_errors.CommandFailedError( | 229 return mock.Mock(side_effect=device_errors.CommandFailedError( |
157 msg, str(self.device))) | 230 msg, str(self.device))) |
158 | 231 |
159 | 232 |
160 class DeviceUtilsIsOnlineTest(DeviceUtilsTest): | 233 class DeviceUtilsIsOnlineTest(DeviceUtilsNewImplTest): |
161 | 234 |
162 def testIsOnline_true(self): | 235 def testIsOnline_true(self): |
163 with self.assertCall(self.call.adb.GetState(), 'device'): | 236 with self.assertCall(self.call.adb.GetState(), 'device'): |
164 self.assertTrue(self.device.IsOnline()) | 237 self.assertTrue(self.device.IsOnline()) |
165 | 238 |
166 def testIsOnline_false(self): | 239 def testIsOnline_false(self): |
167 with self.assertCall(self.call.adb.GetState(), 'offline'): | 240 with self.assertCall(self.call.adb.GetState(), 'offline'): |
168 self.assertFalse(self.device.IsOnline()) | 241 self.assertFalse(self.device.IsOnline()) |
169 | 242 |
170 def testIsOnline_error(self): | 243 def testIsOnline_error(self): |
171 with self.assertCall(self.call.adb.GetState(), self.CommandError()): | 244 with self.assertCall(self.call.adb.GetState(), self.CommandError()): |
172 self.assertFalse(self.device.IsOnline()) | 245 self.assertFalse(self.device.IsOnline()) |
173 | 246 |
174 | 247 |
175 class DeviceUtilsHasRootTest(DeviceUtilsTest): | 248 class DeviceUtilsHasRootTest(DeviceUtilsNewImplTest): |
176 | 249 |
177 def testHasRoot_true(self): | 250 def testHasRoot_true(self): |
178 with self.assertCall(self.call.adb.Shell('ls /root'), 'foo\n'): | 251 with self.assertCall(self.call.adb.Shell('ls /root'), 'foo\n'): |
179 self.assertTrue(self.device.HasRoot()) | 252 self.assertTrue(self.device.HasRoot()) |
180 | 253 |
181 def testHasRoot_false(self): | 254 def testHasRoot_false(self): |
182 with self.assertCall(self.call.adb.Shell('ls /root'), self.ShellError()): | 255 with self.assertCall(self.call.adb.Shell('ls /root'), self.ShellError()): |
183 self.assertFalse(self.device.HasRoot()) | 256 self.assertFalse(self.device.HasRoot()) |
184 | 257 |
185 | 258 |
186 class DeviceUtilsEnableRootTest(DeviceUtilsTest): | 259 class DeviceUtilsEnableRootTest(DeviceUtilsNewImplTest): |
187 | 260 |
188 def testEnableRoot_succeeds(self): | 261 def testEnableRoot_succeeds(self): |
189 with self.assertCalls( | 262 with self.assertCalls( |
190 (self.call.device.IsUserBuild(), False), | 263 (self.call.device.IsUserBuild(), False), |
191 self.call.adb.Root(), | 264 self.call.adb.Root(), |
192 self.call.adb.WaitForDevice()): | 265 self.call.adb.WaitForDevice()): |
193 self.device.EnableRoot() | 266 self.device.EnableRoot() |
194 | 267 |
195 def testEnableRoot_userBuild(self): | 268 def testEnableRoot_userBuild(self): |
196 with self.assertCalls( | 269 with self.assertCalls( |
197 (self.call.device.IsUserBuild(), True)): | 270 (self.call.device.IsUserBuild(), True)): |
198 with self.assertRaises(device_errors.CommandFailedError): | 271 with self.assertRaises(device_errors.CommandFailedError): |
199 self.device.EnableRoot() | 272 self.device.EnableRoot() |
200 | 273 |
201 def testEnableRoot_rootFails(self): | 274 def testEnableRoot_rootFails(self): |
202 with self.assertCalls( | 275 with self.assertCalls( |
203 (self.call.device.IsUserBuild(), False), | 276 (self.call.device.IsUserBuild(), False), |
204 (self.call.adb.Root(), self.CommandError())): | 277 (self.call.adb.Root(), self.CommandError())): |
205 with self.assertRaises(device_errors.CommandFailedError): | 278 with self.assertRaises(device_errors.CommandFailedError): |
206 self.device.EnableRoot() | 279 self.device.EnableRoot() |
207 | 280 |
208 | 281 |
209 class DeviceUtilsIsUserBuildTest(DeviceUtilsTest): | 282 class DeviceUtilsIsUserBuildTest(DeviceUtilsNewImplTest): |
210 | 283 |
211 def testIsUserBuild_yes(self): | 284 def testIsUserBuild_yes(self): |
212 with self.assertCall( | 285 with self.assertCall( |
213 self.call.device.GetProp('ro.build.type', cache=True), 'user'): | 286 self.call.device.GetProp('ro.build.type', cache=True), 'user'): |
214 self.assertTrue(self.device.IsUserBuild()) | 287 self.assertTrue(self.device.IsUserBuild()) |
215 | 288 |
216 def testIsUserBuild_no(self): | 289 def testIsUserBuild_no(self): |
217 with self.assertCall( | 290 with self.assertCall( |
218 self.call.device.GetProp('ro.build.type', cache=True), 'userdebug'): | 291 self.call.device.GetProp('ro.build.type', cache=True), 'userdebug'): |
219 self.assertFalse(self.device.IsUserBuild()) | 292 self.assertFalse(self.device.IsUserBuild()) |
220 | 293 |
221 | 294 |
222 class DeviceUtilsGetExternalStoragePathTest(DeviceUtilsTest): | 295 class DeviceUtilsGetExternalStoragePathTest(DeviceUtilsNewImplTest): |
223 | 296 |
224 def testGetExternalStoragePath_succeeds(self): | 297 def testGetExternalStoragePath_succeeds(self): |
225 with self.assertCall( | 298 with self.assertCall( |
226 self.call.adb.Shell('echo $EXTERNAL_STORAGE'), '/fake/storage/path\n'): | 299 self.call.adb.Shell('echo $EXTERNAL_STORAGE'), '/fake/storage/path\n'): |
227 self.assertEquals('/fake/storage/path', | 300 self.assertEquals('/fake/storage/path', |
228 self.device.GetExternalStoragePath()) | 301 self.device.GetExternalStoragePath()) |
229 | 302 |
230 def testGetExternalStoragePath_fails(self): | 303 def testGetExternalStoragePath_fails(self): |
231 with self.assertCall(self.call.adb.Shell('echo $EXTERNAL_STORAGE'), '\n'): | 304 with self.assertCall(self.call.adb.Shell('echo $EXTERNAL_STORAGE'), '\n'): |
232 with self.assertRaises(device_errors.CommandFailedError): | 305 with self.assertRaises(device_errors.CommandFailedError): |
233 self.device.GetExternalStoragePath() | 306 self.device.GetExternalStoragePath() |
234 | 307 |
235 | 308 |
236 class DeviceUtilsGetApplicationPathTest(DeviceUtilsTest): | 309 class DeviceUtilsGetApplicationPathTest(DeviceUtilsNewImplTest): |
237 | 310 |
238 def testGetApplicationPath_exists(self): | 311 def testGetApplicationPath_exists(self): |
239 with self.assertCalls( | 312 with self.assertCalls( |
240 (self.call.adb.Shell('getprop ro.build.version.sdk'), '19\n'), | 313 (self.call.adb.Shell('getprop ro.build.version.sdk'), '19\n'), |
241 (self.call.adb.Shell('pm path android'), | 314 (self.call.adb.Shell('pm path android'), |
242 'package:/path/to/android.apk\n')): | 315 'package:/path/to/android.apk\n')): |
243 self.assertEquals('/path/to/android.apk', | 316 self.assertEquals('/path/to/android.apk', |
244 self.device.GetApplicationPath('android')) | 317 self.device.GetApplicationPath('android')) |
245 | 318 |
246 def testGetApplicationPath_notExists(self): | 319 def testGetApplicationPath_notExists(self): |
247 with self.assertCalls( | 320 with self.assertCalls( |
248 (self.call.adb.Shell('getprop ro.build.version.sdk'), '19\n'), | 321 (self.call.adb.Shell('getprop ro.build.version.sdk'), '19\n'), |
249 (self.call.adb.Shell('pm path not.installed.app'), '')): | 322 (self.call.adb.Shell('pm path not.installed.app'), '')): |
250 self.assertEquals(None, | 323 self.assertEquals(None, |
251 self.device.GetApplicationPath('not.installed.app')) | 324 self.device.GetApplicationPath('not.installed.app')) |
252 | 325 |
253 def testGetApplicationPath_fails(self): | 326 def testGetApplicationPath_fails(self): |
254 with self.assertCalls( | 327 with self.assertCalls( |
255 (self.call.adb.Shell('getprop ro.build.version.sdk'), '19\n'), | 328 (self.call.adb.Shell('getprop ro.build.version.sdk'), '19\n'), |
256 (self.call.adb.Shell('pm path android'), | 329 (self.call.adb.Shell('pm path android'), |
257 self.CommandError('ERROR. Is package manager running?\n'))): | 330 self.CommandError('ERROR. Is package manager running?\n'))): |
258 with self.assertRaises(device_errors.CommandFailedError): | 331 with self.assertRaises(device_errors.CommandFailedError): |
259 self.device.GetApplicationPath('android') | 332 self.device.GetApplicationPath('android') |
260 | 333 |
261 | 334 |
262 @mock.patch('time.sleep', mock.Mock()) | 335 @mock.patch('time.sleep', mock.Mock()) |
263 class DeviceUtilsWaitUntilFullyBootedTest(DeviceUtilsTest): | 336 class DeviceUtilsWaitUntilFullyBootedTest(DeviceUtilsNewImplTest): |
264 | 337 |
265 def testWaitUntilFullyBooted_succeedsNoWifi(self): | 338 def testWaitUntilFullyBooted_succeedsNoWifi(self): |
266 with self.assertCalls( | 339 with self.assertCalls( |
267 self.call.adb.WaitForDevice(), | 340 self.call.adb.WaitForDevice(), |
268 # sd_card_ready | 341 # sd_card_ready |
269 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'), | 342 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'), |
270 (self.call.adb.Shell('test -d /fake/storage/path'), ''), | 343 (self.call.adb.Shell('test -d /fake/storage/path'), ''), |
271 # pm_ready | 344 # pm_ready |
272 (self.call.device.GetApplicationPath('android'), | 345 (self.call.device.GetApplicationPath('android'), |
273 'package:/some/fake/path'), | 346 'package:/some/fake/path'), |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 (self.call.adb.Shell('dumpsys wifi'), 'stuff\nmore stuff\n'), | 436 (self.call.adb.Shell('dumpsys wifi'), 'stuff\nmore stuff\n'), |
364 # wifi_enabled | 437 # wifi_enabled |
365 (self.call.adb.Shell('dumpsys wifi'), 'stuff\nmore stuff\n'), | 438 (self.call.adb.Shell('dumpsys wifi'), 'stuff\nmore stuff\n'), |
366 # wifi_enabled | 439 # wifi_enabled |
367 (self.call.adb.Shell('dumpsys wifi'), self.TimeoutError())): | 440 (self.call.adb.Shell('dumpsys wifi'), self.TimeoutError())): |
368 with self.assertRaises(device_errors.CommandTimeoutError): | 441 with self.assertRaises(device_errors.CommandTimeoutError): |
369 self.device.WaitUntilFullyBooted(wifi=True) | 442 self.device.WaitUntilFullyBooted(wifi=True) |
370 | 443 |
371 | 444 |
372 @mock.patch('time.sleep', mock.Mock()) | 445 @mock.patch('time.sleep', mock.Mock()) |
373 class DeviceUtilsRebootTest(DeviceUtilsTest): | 446 class DeviceUtilsRebootTest(DeviceUtilsNewImplTest): |
374 | 447 |
375 def testReboot_nonBlocking(self): | 448 def testReboot_nonBlocking(self): |
376 with self.assertCalls( | 449 with self.assertCalls( |
377 self.call.adb.Reboot(), | 450 self.call.adb.Reboot(), |
378 (self.call.device.IsOnline(), True), | 451 (self.call.device.IsOnline(), True), |
379 (self.call.device.IsOnline(), False)): | 452 (self.call.device.IsOnline(), False)): |
380 self.device.Reboot(block=False) | 453 self.device.Reboot(block=False) |
381 | 454 |
382 def testReboot_blocking(self): | 455 def testReboot_blocking(self): |
383 with self.assertCalls( | 456 with self.assertCalls( |
384 self.call.adb.Reboot(), | 457 self.call.adb.Reboot(), |
385 (self.call.device.IsOnline(), True), | 458 (self.call.device.IsOnline(), True), |
386 (self.call.device.IsOnline(), False), | 459 (self.call.device.IsOnline(), False), |
387 self.call.device.WaitUntilFullyBooted(wifi=False)): | 460 self.call.device.WaitUntilFullyBooted(wifi=False)): |
388 self.device.Reboot(block=True) | 461 self.device.Reboot(block=True) |
389 | 462 |
390 def testReboot_blockUntilWifi(self): | 463 def testReboot_blockUntilWifi(self): |
391 with self.assertCalls( | 464 with self.assertCalls( |
392 self.call.adb.Reboot(), | 465 self.call.adb.Reboot(), |
393 (self.call.device.IsOnline(), True), | 466 (self.call.device.IsOnline(), True), |
394 (self.call.device.IsOnline(), False), | 467 (self.call.device.IsOnline(), False), |
395 self.call.device.WaitUntilFullyBooted(wifi=True)): | 468 self.call.device.WaitUntilFullyBooted(wifi=True)): |
396 self.device.Reboot(block=True, wifi=True) | 469 self.device.Reboot(block=True, wifi=True) |
397 | 470 |
398 | 471 |
399 class DeviceUtilsInstallTest(DeviceUtilsTest): | 472 class DeviceUtilsInstallTest(DeviceUtilsNewImplTest): |
400 | 473 |
401 def testInstall_noPriorInstall(self): | 474 def testInstall_noPriorInstall(self): |
402 with self.assertCalls( | 475 with self.assertCalls( |
403 (mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'), | 476 (mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'), |
404 'this.is.a.test.package'), | 477 'this.is.a.test.package'), |
405 (self.call.device.GetApplicationPath('this.is.a.test.package'), None), | 478 (self.call.device.GetApplicationPath('this.is.a.test.package'), None), |
406 self.call.adb.Install('/fake/test/app.apk', reinstall=False)): | 479 self.call.adb.Install('/fake/test/app.apk', reinstall=False)): |
407 self.device.Install('/fake/test/app.apk', retries=0) | 480 self.device.Install('/fake/test/app.apk', retries=0) |
408 | 481 |
409 def testInstall_differentPriorInstall(self): | 482 def testInstall_differentPriorInstall(self): |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 with self.assertCalls( | 519 with self.assertCalls( |
447 (mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'), | 520 (mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'), |
448 'this.is.a.test.package'), | 521 'this.is.a.test.package'), |
449 (self.call.device.GetApplicationPath('this.is.a.test.package'), None), | 522 (self.call.device.GetApplicationPath('this.is.a.test.package'), None), |
450 (self.call.adb.Install('/fake/test/app.apk', reinstall=False), | 523 (self.call.adb.Install('/fake/test/app.apk', reinstall=False), |
451 self.CommandError('Failure\r\n'))): | 524 self.CommandError('Failure\r\n'))): |
452 with self.assertRaises(device_errors.CommandFailedError): | 525 with self.assertRaises(device_errors.CommandFailedError): |
453 self.device.Install('/fake/test/app.apk', retries=0) | 526 self.device.Install('/fake/test/app.apk', retries=0) |
454 | 527 |
455 | 528 |
456 class DeviceUtilsRunShellCommandTest(DeviceUtilsTest): | 529 class DeviceUtilsRunShellCommandTest(DeviceUtilsNewImplTest): |
457 | 530 |
458 def setUp(self): | 531 def setUp(self): |
459 super(DeviceUtilsRunShellCommandTest, self).setUp() | 532 super(DeviceUtilsRunShellCommandTest, self).setUp() |
460 self.device.NeedsSU = mock.Mock(return_value=False) | 533 self.device.NeedsSU = mock.Mock(return_value=False) |
461 | 534 |
462 def testRunShellCommand_commandAsList(self): | 535 def testRunShellCommand_commandAsList(self): |
463 with self.assertCall(self.call.adb.Shell('pm list packages'), ''): | 536 with self.assertCall(self.call.adb.Shell('pm list packages'), ''): |
464 self.device.RunShellCommand(['pm', 'list', 'packages']) | 537 self.device.RunShellCommand(['pm', 'list', 'packages']) |
465 | 538 |
466 def testRunShellCommand_commandAsListQuoted(self): | 539 def testRunShellCommand_commandAsListQuoted(self): |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 | 650 |
578 def testRunShellCommand_checkReturn_disabled(self): | 651 def testRunShellCommand_checkReturn_disabled(self): |
579 cmd = 'ls /root' | 652 cmd = 'ls /root' |
580 output = 'opendir failed, Permission denied\n' | 653 output = 'opendir failed, Permission denied\n' |
581 with self.assertCall(self.call.adb.Shell(cmd), self.ShellError(output)): | 654 with self.assertCall(self.call.adb.Shell(cmd), self.ShellError(output)): |
582 self.assertEquals([output.rstrip()], | 655 self.assertEquals([output.rstrip()], |
583 self.device.RunShellCommand(cmd, check_return=False)) | 656 self.device.RunShellCommand(cmd, check_return=False)) |
584 | 657 |
585 | 658 |
586 @mock.patch('time.sleep', mock.Mock()) | 659 @mock.patch('time.sleep', mock.Mock()) |
587 class DeviceUtilsKillAllTest(DeviceUtilsTest): | 660 class DeviceUtilsKillAllTest(DeviceUtilsNewImplTest): |
588 | 661 |
589 def testKillAll_noMatchingProcesses(self): | 662 def testKillAll_noMatchingProcesses(self): |
590 with self.assertCall(self.call.adb.Shell('ps'), | 663 with self.assertCall(self.call.adb.Shell('ps'), |
591 'USER PID PPID VSIZE RSS WCHAN PC NAME\n'): | 664 'USER PID PPID VSIZE RSS WCHAN PC NAME\n'): |
592 with self.assertRaises(device_errors.CommandFailedError): | 665 with self.assertRaises(device_errors.CommandFailedError): |
593 self.device.KillAll('test_process') | 666 self.device.KillAll('test_process') |
594 | 667 |
595 def testKillAll_nonblocking(self): | 668 def testKillAll_nonblocking(self): |
596 with self.assertCalls( | 669 with self.assertCalls( |
597 (self.call.adb.Shell('ps'), | 670 (self.call.adb.Shell('ps'), |
(...skipping 30 matching lines...) Expand all Loading... |
628 def testKillAll_sigterm(self): | 701 def testKillAll_sigterm(self): |
629 with self.assertCalls( | 702 with self.assertCalls( |
630 (self.call.adb.Shell('ps'), | 703 (self.call.adb.Shell('ps'), |
631 'USER PID PPID VSIZE RSS WCHAN PC NAME\n' | 704 'USER PID PPID VSIZE RSS WCHAN PC NAME\n' |
632 'u0_a1 1234 174 123456 54321 ffffffff 456789ab some.process\n'), | 705 'u0_a1 1234 174 123456 54321 ffffffff 456789ab some.process\n'), |
633 (self.call.adb.Shell('kill -15 1234'), '')): | 706 (self.call.adb.Shell('kill -15 1234'), '')): |
634 self.assertEquals(1, | 707 self.assertEquals(1, |
635 self.device.KillAll('some.process', signum=signal.SIGTERM)) | 708 self.device.KillAll('some.process', signum=signal.SIGTERM)) |
636 | 709 |
637 | 710 |
638 class DeviceUtilsStartActivityTest(DeviceUtilsTest): | 711 class DeviceUtilsStartActivityTest(DeviceUtilsNewImplTest): |
639 | 712 |
640 def testStartActivity_actionOnly(self): | 713 def testStartActivity_actionOnly(self): |
641 test_intent = intent.Intent(action='android.intent.action.VIEW') | 714 test_intent = intent.Intent(action='android.intent.action.VIEW') |
642 with self.assertCall( | 715 with self.assertCall( |
643 self.call.adb.Shell('am start ' | 716 self.call.adb.Shell('am start ' |
644 '-a android.intent.action.VIEW'), | 717 '-a android.intent.action.VIEW'), |
645 'Starting: Intent { act=android.intent.action.VIEW }'): | 718 'Starting: Intent { act=android.intent.action.VIEW }'): |
646 self.device.StartActivity(test_intent) | 719 self.device.StartActivity(test_intent) |
647 | 720 |
648 def testStartActivity_success(self): | 721 def testStartActivity_success(self): |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
792 flags='0x10000000') | 865 flags='0x10000000') |
793 with self.assertCall( | 866 with self.assertCall( |
794 self.call.adb.Shell('am start ' | 867 self.call.adb.Shell('am start ' |
795 '-a android.intent.action.VIEW ' | 868 '-a android.intent.action.VIEW ' |
796 '-n this.is.a.test.package/.Main ' | 869 '-n this.is.a.test.package/.Main ' |
797 '-f 0x10000000'), | 870 '-f 0x10000000'), |
798 'Starting: Intent { act=android.intent.action.VIEW }'): | 871 'Starting: Intent { act=android.intent.action.VIEW }'): |
799 self.device.StartActivity(test_intent) | 872 self.device.StartActivity(test_intent) |
800 | 873 |
801 | 874 |
802 class DeviceUtilsStartInstrumentationTest(DeviceUtilsTest): | 875 class DeviceUtilsStartInstrumentationTest(DeviceUtilsNewImplTest): |
803 | 876 |
804 def testStartInstrumentation_nothing(self): | 877 def testStartInstrumentation_nothing(self): |
805 with self.assertCalls( | 878 with self.assertCalls( |
806 self.call.device.RunShellCommand( | 879 self.call.device.RunShellCommand( |
807 ['am', 'instrument', 'test.package/.TestInstrumentation'], | 880 ['am', 'instrument', 'test.package/.TestInstrumentation'], |
808 check_return=True)): | 881 check_return=True)): |
809 self.device.StartInstrumentation( | 882 self.device.StartInstrumentation( |
810 'test.package/.TestInstrumentation', | 883 'test.package/.TestInstrumentation', |
811 finish=False, raw=False, extras=None) | 884 finish=False, raw=False, extras=None) |
812 | 885 |
(...skipping 21 matching lines...) Expand all Loading... |
834 with self.assertCalls( | 907 with self.assertCalls( |
835 self.call.device.RunShellCommand( | 908 self.call.device.RunShellCommand( |
836 ['am', 'instrument', '-e', 'foo', 'Foo', '-e', 'bar', 'Bar', | 909 ['am', 'instrument', '-e', 'foo', 'Foo', '-e', 'bar', 'Bar', |
837 'test.package/.TestInstrumentation'], | 910 'test.package/.TestInstrumentation'], |
838 check_return=True)): | 911 check_return=True)): |
839 self.device.StartInstrumentation( | 912 self.device.StartInstrumentation( |
840 'test.package/.TestInstrumentation', | 913 'test.package/.TestInstrumentation', |
841 finish=False, raw=False, extras={'foo': 'Foo', 'bar': 'Bar'}) | 914 finish=False, raw=False, extras={'foo': 'Foo', 'bar': 'Bar'}) |
842 | 915 |
843 | 916 |
844 class DeviceUtilsBroadcastIntentTest(DeviceUtilsTest): | 917 class DeviceUtilsBroadcastIntentTest(DeviceUtilsNewImplTest): |
845 | 918 |
846 def testBroadcastIntent_noExtras(self): | 919 def testBroadcastIntent_noExtras(self): |
847 test_intent = intent.Intent(action='test.package.with.an.INTENT') | 920 test_intent = intent.Intent(action='test.package.with.an.INTENT') |
848 with self.assertCall( | 921 with self.assertCall( |
849 self.call.adb.Shell('am broadcast -a test.package.with.an.INTENT'), | 922 self.call.adb.Shell('am broadcast -a test.package.with.an.INTENT'), |
850 'Broadcasting: Intent { act=test.package.with.an.INTENT } '): | 923 'Broadcasting: Intent { act=test.package.with.an.INTENT } '): |
851 self.device.BroadcastIntent(test_intent) | 924 self.device.BroadcastIntent(test_intent) |
852 | 925 |
853 def testBroadcastIntent_withExtra(self): | 926 def testBroadcastIntent_withExtra(self): |
854 test_intent = intent.Intent(action='test.package.with.an.INTENT', | 927 test_intent = intent.Intent(action='test.package.with.an.INTENT', |
855 extras={'foo': 'bar value'}) | 928 extras={'foo': 'bar value'}) |
856 with self.assertCall( | 929 with self.assertCall( |
857 self.call.adb.Shell( | 930 self.call.adb.Shell( |
858 "am broadcast -a test.package.with.an.INTENT --es foo 'bar value'"), | 931 "am broadcast -a test.package.with.an.INTENT --es foo 'bar value'"), |
859 'Broadcasting: Intent { act=test.package.with.an.INTENT } '): | 932 'Broadcasting: Intent { act=test.package.with.an.INTENT } '): |
860 self.device.BroadcastIntent(test_intent) | 933 self.device.BroadcastIntent(test_intent) |
861 | 934 |
862 def testBroadcastIntent_withExtra_noValue(self): | 935 def testBroadcastIntent_withExtra_noValue(self): |
863 test_intent = intent.Intent(action='test.package.with.an.INTENT', | 936 test_intent = intent.Intent(action='test.package.with.an.INTENT', |
864 extras={'foo': None}) | 937 extras={'foo': None}) |
865 with self.assertCall( | 938 with self.assertCall( |
866 self.call.adb.Shell( | 939 self.call.adb.Shell( |
867 'am broadcast -a test.package.with.an.INTENT --esn foo'), | 940 'am broadcast -a test.package.with.an.INTENT --esn foo'), |
868 'Broadcasting: Intent { act=test.package.with.an.INTENT } '): | 941 'Broadcasting: Intent { act=test.package.with.an.INTENT } '): |
869 self.device.BroadcastIntent(test_intent) | 942 self.device.BroadcastIntent(test_intent) |
870 | 943 |
871 | 944 |
872 class DeviceUtilsGoHomeTest(DeviceUtilsTest): | 945 class DeviceUtilsGoHomeTest(DeviceUtilsNewImplTest): |
873 | 946 |
874 def testGoHome(self): | 947 def testGoHome(self): |
875 with self.assertCall( | 948 with self.assertCall( |
876 self.call.adb.Shell('am start -W -a android.intent.action.MAIN ' | 949 self.call.adb.Shell('am start -W -a android.intent.action.MAIN ' |
877 '-c android.intent.category.HOME'), | 950 '-c android.intent.category.HOME'), |
878 'Starting: Intent { act=android.intent.action.MAIN }\r\n'): | 951 'Starting: Intent { act=android.intent.action.MAIN }\r\n'): |
879 self.device.GoHome() | 952 self.device.GoHome() |
880 | 953 |
881 | 954 |
882 class DeviceUtilsForceStopTest(DeviceUtilsTest): | 955 class DeviceUtilsForceStopTest(DeviceUtilsNewImplTest): |
883 | 956 |
884 def testForceStop(self): | 957 def testForceStop(self): |
885 with self.assertCall( | 958 with self.assertCall( |
886 self.call.adb.Shell('am force-stop this.is.a.test.package'), | 959 self.call.adb.Shell('am force-stop this.is.a.test.package'), |
887 ''): | 960 ''): |
888 self.device.ForceStop('this.is.a.test.package') | 961 self.device.ForceStop('this.is.a.test.package') |
889 | 962 |
890 | 963 |
891 class DeviceUtilsClearApplicationStateTest(DeviceUtilsTest): | 964 class DeviceUtilsClearApplicationStateTest(DeviceUtilsNewImplTest): |
892 | 965 |
893 def testClearApplicationState_packageDoesntExist(self): | 966 def testClearApplicationState_packageDoesntExist(self): |
894 with self.assertCalls( | 967 with self.assertCalls( |
895 (self.call.adb.Shell('getprop ro.build.version.sdk'), '17\n'), | 968 (self.call.adb.Shell('getprop ro.build.version.sdk'), '17\n'), |
896 (self.call.device.GetApplicationPath('this.package.does.not.exist'), | 969 (self.call.device.GetApplicationPath('this.package.does.not.exist'), |
897 None)): | 970 None)): |
898 self.device.ClearApplicationState('this.package.does.not.exist') | 971 self.device.ClearApplicationState('this.package.does.not.exist') |
899 | 972 |
900 def testClearApplicationState_packageDoesntExistOnAndroidJBMR2OrAbove(self): | 973 def testClearApplicationState_packageDoesntExistOnAndroidJBMR2OrAbove(self): |
901 with self.assertCalls( | 974 with self.assertCalls( |
(...skipping 12 matching lines...) Expand all Loading... |
914 self.device.ClearApplicationState('this.package.exists') | 987 self.device.ClearApplicationState('this.package.exists') |
915 | 988 |
916 def testClearApplicationState_packageExistsOnAndroidJBMR2OrAbove(self): | 989 def testClearApplicationState_packageExistsOnAndroidJBMR2OrAbove(self): |
917 with self.assertCalls( | 990 with self.assertCalls( |
918 (self.call.adb.Shell('getprop ro.build.version.sdk'), '18\n'), | 991 (self.call.adb.Shell('getprop ro.build.version.sdk'), '18\n'), |
919 (self.call.adb.Shell('pm clear this.package.exists'), | 992 (self.call.adb.Shell('pm clear this.package.exists'), |
920 'Success\r\n')): | 993 'Success\r\n')): |
921 self.device.ClearApplicationState('this.package.exists') | 994 self.device.ClearApplicationState('this.package.exists') |
922 | 995 |
923 | 996 |
924 class DeviceUtilsSendKeyEventTest(DeviceUtilsTest): | 997 class DeviceUtilsSendKeyEventTest(DeviceUtilsNewImplTest): |
925 | 998 |
926 def testSendKeyEvent(self): | 999 def testSendKeyEvent(self): |
927 with self.assertCall(self.call.adb.Shell('input keyevent 66'), ''): | 1000 with self.assertCall(self.call.adb.Shell('input keyevent 66'), ''): |
928 self.device.SendKeyEvent(66) | 1001 self.device.SendKeyEvent(66) |
929 | 1002 |
930 | 1003 |
931 class DeviceUtilsPushChangedFilesIndividuallyTest(DeviceUtilsTest): | 1004 class DeviceUtilsPushChangedFilesIndividuallyTest(DeviceUtilsNewImplTest): |
932 | 1005 |
933 def testPushChangedFilesIndividually_empty(self): | 1006 def testPushChangedFilesIndividually_empty(self): |
934 test_files = [] | 1007 test_files = [] |
935 with self.assertCalls(): | 1008 with self.assertCalls(): |
936 self.device._PushChangedFilesIndividually(test_files) | 1009 self.device._PushChangedFilesIndividually(test_files) |
937 | 1010 |
938 def testPushChangedFilesIndividually_single(self): | 1011 def testPushChangedFilesIndividually_single(self): |
939 test_files = [('/test/host/path', '/test/device/path')] | 1012 test_files = [('/test/host/path', '/test/device/path')] |
940 with self.assertCalls(self.call.adb.Push(*test_files[0])): | 1013 with self.assertCalls(self.call.adb.Push(*test_files[0])): |
941 self.device._PushChangedFilesIndividually(test_files) | 1014 self.device._PushChangedFilesIndividually(test_files) |
942 | 1015 |
943 def testPushChangedFilesIndividually_multiple(self): | 1016 def testPushChangedFilesIndividually_multiple(self): |
944 test_files = [ | 1017 test_files = [ |
945 ('/test/host/path/file1', '/test/device/path/file1'), | 1018 ('/test/host/path/file1', '/test/device/path/file1'), |
946 ('/test/host/path/file2', '/test/device/path/file2')] | 1019 ('/test/host/path/file2', '/test/device/path/file2')] |
947 with self.assertCalls( | 1020 with self.assertCalls( |
948 self.call.adb.Push(*test_files[0]), | 1021 self.call.adb.Push(*test_files[0]), |
949 self.call.adb.Push(*test_files[1])): | 1022 self.call.adb.Push(*test_files[1])): |
950 self.device._PushChangedFilesIndividually(test_files) | 1023 self.device._PushChangedFilesIndividually(test_files) |
951 | 1024 |
952 | 1025 |
953 class DeviceUtilsPushChangedFilesZippedTest(DeviceUtilsTest): | 1026 class DeviceUtilsPushChangedFilesZippedTest(DeviceUtilsNewImplTest): |
954 | 1027 |
955 def testPushChangedFilesZipped_empty(self): | 1028 def testPushChangedFilesZipped_empty(self): |
956 test_files = [] | 1029 test_files = [] |
957 with self.assertCalls(): | 1030 with self.assertCalls(): |
958 self.device._PushChangedFilesZipped(test_files) | 1031 self.device._PushChangedFilesZipped(test_files) |
959 | 1032 |
960 def _testPushChangedFilesZipped_spec(self, test_files): | 1033 def _testPushChangedFilesZipped_spec(self, test_files): |
961 mock_zip_temp = mock.mock_open() | 1034 mock_zip_temp = mock.mock_open() |
962 mock_zip_temp.return_value.name = '/test/temp/file/tmp.zip' | 1035 mock_zip_temp.return_value.name = '/test/temp/file/tmp.zip' |
963 with self.assertCalls( | 1036 with self.assertCalls( |
(...skipping 18 matching lines...) Expand all Loading... |
982 def testPushChangedFilesZipped_single(self): | 1055 def testPushChangedFilesZipped_single(self): |
983 self._testPushChangedFilesZipped_spec( | 1056 self._testPushChangedFilesZipped_spec( |
984 [('/test/host/path/file1', '/test/device/path/file1')]) | 1057 [('/test/host/path/file1', '/test/device/path/file1')]) |
985 | 1058 |
986 def testPushChangedFilesZipped_multiple(self): | 1059 def testPushChangedFilesZipped_multiple(self): |
987 self._testPushChangedFilesZipped_spec( | 1060 self._testPushChangedFilesZipped_spec( |
988 [('/test/host/path/file1', '/test/device/path/file1'), | 1061 [('/test/host/path/file1', '/test/device/path/file1'), |
989 ('/test/host/path/file2', '/test/device/path/file2')]) | 1062 ('/test/host/path/file2', '/test/device/path/file2')]) |
990 | 1063 |
991 | 1064 |
992 class DeviceUtilsFileExistsTest(DeviceUtilsTest): | 1065 class DeviceUtilsFileExistsTest(DeviceUtilsNewImplTest): |
993 | 1066 |
994 def testFileExists_usingTest_fileExists(self): | 1067 def testFileExists_usingTest_fileExists(self): |
995 with self.assertCall( | 1068 with self.assertCall( |
996 self.call.device.RunShellCommand( | 1069 self.call.device.RunShellCommand( |
997 ['test', '-e', '/path/file.exists'], check_return=True), ''): | 1070 ['test', '-e', '/path/file.exists'], check_return=True), ''): |
998 self.assertTrue(self.device.FileExists('/path/file.exists')) | 1071 self.assertTrue(self.device.FileExists('/path/file.exists')) |
999 | 1072 |
1000 def testFileExists_usingTest_fileDoesntExist(self): | 1073 def testFileExists_usingTest_fileDoesntExist(self): |
1001 with self.assertCall( | 1074 with self.assertCall( |
1002 self.call.device.RunShellCommand( | 1075 self.call.device.RunShellCommand( |
1003 ['test', '-e', '/does/not/exist'], check_return=True), | 1076 ['test', '-e', '/does/not/exist'], check_return=True), |
1004 self.ShellError('', 1)): | 1077 self.ShellError('', 1)): |
1005 self.assertFalse(self.device.FileExists('/does/not/exist')) | 1078 self.assertFalse(self.device.FileExists('/does/not/exist')) |
1006 | 1079 |
1007 | 1080 |
1008 class DeviceUtilsPullFileTest(DeviceUtilsTest): | 1081 class DeviceUtilsPullFileTest(DeviceUtilsNewImplTest): |
1009 | 1082 |
1010 def testPullFile_existsOnDevice(self): | 1083 def testPullFile_existsOnDevice(self): |
1011 with mock.patch('os.path.exists', return_value=True): | 1084 with mock.patch('os.path.exists', return_value=True): |
1012 with self.assertCall( | 1085 with self.assertCall( |
1013 self.call.adb.Pull('/data/app/test.file.exists', | 1086 self.call.adb.Pull('/data/app/test.file.exists', |
1014 '/test/file/host/path')): | 1087 '/test/file/host/path')): |
1015 self.device.PullFile('/data/app/test.file.exists', | 1088 self.device.PullFile('/data/app/test.file.exists', |
1016 '/test/file/host/path') | 1089 '/test/file/host/path') |
1017 | 1090 |
1018 def testPullFile_doesntExistOnDevice(self): | 1091 def testPullFile_doesntExistOnDevice(self): |
1019 with mock.patch('os.path.exists', return_value=True): | 1092 with mock.patch('os.path.exists', return_value=True): |
1020 with self.assertCall( | 1093 with self.assertCall( |
1021 self.call.adb.Pull('/data/app/test.file.does.not.exist', | 1094 self.call.adb.Pull('/data/app/test.file.does.not.exist', |
1022 '/test/file/host/path'), | 1095 '/test/file/host/path'), |
1023 self.CommandError('remote object does not exist')): | 1096 self.CommandError('remote object does not exist')): |
1024 with self.assertRaises(device_errors.CommandFailedError): | 1097 with self.assertRaises(device_errors.CommandFailedError): |
1025 self.device.PullFile('/data/app/test.file.does.not.exist', | 1098 self.device.PullFile('/data/app/test.file.does.not.exist', |
1026 '/test/file/host/path') | 1099 '/test/file/host/path') |
1027 | 1100 |
1028 | 1101 |
1029 class DeviceUtilsReadFileTest(DeviceUtilsTest): | 1102 class DeviceUtilsReadFileTest(DeviceUtilsNewImplTest): |
1030 | 1103 |
1031 def testReadFile_exists(self): | 1104 def testReadFile_exists(self): |
1032 with self.assertCall( | 1105 with self.assertCall( |
1033 self.call.adb.Shell('cat /read/this/test/file'), | 1106 self.call.adb.Shell('cat /read/this/test/file'), |
1034 'this is a test file\r\n'): | 1107 'this is a test file\r\n'): |
1035 self.assertEqual('this is a test file\n', | 1108 self.assertEqual('this is a test file\n', |
1036 self.device.ReadFile('/read/this/test/file')) | 1109 self.device.ReadFile('/read/this/test/file')) |
1037 | 1110 |
1038 def testReadFile_doesNotExist(self): | 1111 def testReadFile_doesNotExist(self): |
1039 with self.assertCall( | 1112 with self.assertCall( |
1040 self.call.adb.Shell('cat /this/file/does.not.exist'), | 1113 self.call.adb.Shell('cat /this/file/does.not.exist'), |
1041 self.ShellError('/system/bin/sh: cat: /this/file/does.not.exist: ' | 1114 self.ShellError('/system/bin/sh: cat: /this/file/does.not.exist: ' |
1042 'No such file or directory')): | 1115 'No such file or directory')): |
1043 with self.assertRaises(device_errors.AdbCommandFailedError): | 1116 with self.assertRaises(device_errors.AdbCommandFailedError): |
1044 self.device.ReadFile('/this/file/does.not.exist') | 1117 self.device.ReadFile('/this/file/does.not.exist') |
1045 | 1118 |
1046 def testReadFile_withSU(self): | 1119 def testReadFile_withSU(self): |
1047 with self.assertCalls( | 1120 with self.assertCalls( |
1048 (self.call.device.NeedsSU(), True), | 1121 (self.call.device.NeedsSU(), True), |
1049 (self.call.adb.Shell("su -c sh -c 'cat /this/file/can.be.read.with.su'"), | 1122 (self.call.adb.Shell("su -c sh -c 'cat /this/file/can.be.read.with.su'"), |
1050 'this is a test file\nread with su')): | 1123 'this is a test file\nread with su')): |
1051 self.assertEqual( | 1124 self.assertEqual( |
1052 'this is a test file\nread with su\n', | 1125 'this is a test file\nread with su\n', |
1053 self.device.ReadFile('/this/file/can.be.read.with.su', | 1126 self.device.ReadFile('/this/file/can.be.read.with.su', |
1054 as_root=True)) | 1127 as_root=True)) |
1055 | 1128 |
1056 | 1129 |
1057 class DeviceUtilsWriteFileTest(DeviceUtilsTest): | 1130 class DeviceUtilsWriteFileTest(DeviceUtilsNewImplTest): |
1058 | 1131 |
1059 def testWriteFileWithPush_success(self): | 1132 def testWriteFileWithPush_success(self): |
1060 tmp_host = MockTempFile('/tmp/file/on.host') | 1133 tmp_host = MockTempFile('/tmp/file/on.host') |
1061 contents = 'some interesting contents' | 1134 contents = 'some interesting contents' |
1062 with self.assertCalls( | 1135 with self.assertCalls( |
1063 (mock.call.tempfile.NamedTemporaryFile(), tmp_host), | 1136 (mock.call.tempfile.NamedTemporaryFile(), tmp_host), |
1064 self.call.adb.Push('/tmp/file/on.host', '/path/to/device/file')): | 1137 self.call.adb.Push('/tmp/file/on.host', '/path/to/device/file')): |
1065 self.device._WriteFileWithPush('/path/to/device/file', contents) | 1138 self.device._WriteFileWithPush('/path/to/device/file', contents) |
1066 tmp_host.file.write.assert_called_once_with(contents) | 1139 tmp_host.file.write.assert_called_once_with(contents) |
1067 | 1140 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1110 self.device.WriteFile('/test/file/to write', 'the contents') | 1183 self.device.WriteFile('/test/file/to write', 'the contents') |
1111 | 1184 |
1112 def testWriteFile_withEchoAndSU(self): | 1185 def testWriteFile_withEchoAndSU(self): |
1113 with self.assertCalls( | 1186 with self.assertCalls( |
1114 (self.call.device.NeedsSU(), True), | 1187 (self.call.device.NeedsSU(), True), |
1115 (self.call.adb.Shell("su -c sh -c 'echo -n contents > /test/file'"), | 1188 (self.call.adb.Shell("su -c sh -c 'echo -n contents > /test/file'"), |
1116 '')): | 1189 '')): |
1117 self.device.WriteFile('/test/file', 'contents', as_root=True) | 1190 self.device.WriteFile('/test/file', 'contents', as_root=True) |
1118 | 1191 |
1119 | 1192 |
1120 class DeviceUtilsLsTest(DeviceUtilsTest): | 1193 class DeviceUtilsLsTest(DeviceUtilsNewImplTest): |
1121 | 1194 |
1122 def testLs_directory(self): | 1195 def testLs_directory(self): |
1123 result = [('.', adb_wrapper.DeviceStat(16889, 4096, 1417436123)), | 1196 result = [('.', adb_wrapper.DeviceStat(16889, 4096, 1417436123)), |
1124 ('..', adb_wrapper.DeviceStat(16873, 4096, 12382237)), | 1197 ('..', adb_wrapper.DeviceStat(16873, 4096, 12382237)), |
1125 ('testfile.txt', adb_wrapper.DeviceStat(33206, 3, 1417436122))] | 1198 ('testfile.txt', adb_wrapper.DeviceStat(33206, 3, 1417436122))] |
1126 with self.assertCalls( | 1199 with self.assertCalls( |
1127 (self.call.adb.Ls('/data/local/tmp'), result)): | 1200 (self.call.adb.Ls('/data/local/tmp'), result)): |
1128 self.assertEquals(result, | 1201 self.assertEquals(result, |
1129 self.device.Ls('/data/local/tmp')) | 1202 self.device.Ls('/data/local/tmp')) |
1130 | 1203 |
1131 def testLs_nothing(self): | 1204 def testLs_nothing(self): |
1132 with self.assertCalls( | 1205 with self.assertCalls( |
1133 (self.call.adb.Ls('/data/local/tmp/testfile.txt'), [])): | 1206 (self.call.adb.Ls('/data/local/tmp/testfile.txt'), [])): |
1134 self.assertEquals([], | 1207 self.assertEquals([], |
1135 self.device.Ls('/data/local/tmp/testfile.txt')) | 1208 self.device.Ls('/data/local/tmp/testfile.txt')) |
1136 | 1209 |
1137 | 1210 |
1138 class DeviceUtilsStatTest(DeviceUtilsTest): | 1211 class DeviceUtilsStatTest(DeviceUtilsNewImplTest): |
1139 | 1212 |
1140 def testStat_file(self): | 1213 def testStat_file(self): |
1141 result = [('.', adb_wrapper.DeviceStat(16889, 4096, 1417436123)), | 1214 result = [('.', adb_wrapper.DeviceStat(16889, 4096, 1417436123)), |
1142 ('..', adb_wrapper.DeviceStat(16873, 4096, 12382237)), | 1215 ('..', adb_wrapper.DeviceStat(16873, 4096, 12382237)), |
1143 ('testfile.txt', adb_wrapper.DeviceStat(33206, 3, 1417436122))] | 1216 ('testfile.txt', adb_wrapper.DeviceStat(33206, 3, 1417436122))] |
1144 with self.assertCalls( | 1217 with self.assertCalls( |
1145 (self.call.adb.Ls('/data/local/tmp'), result)): | 1218 (self.call.adb.Ls('/data/local/tmp'), result)): |
1146 self.assertEquals(adb_wrapper.DeviceStat(33206, 3, 1417436122), | 1219 self.assertEquals(adb_wrapper.DeviceStat(33206, 3, 1417436122), |
1147 self.device.Stat('/data/local/tmp/testfile.txt')) | 1220 self.device.Stat('/data/local/tmp/testfile.txt')) |
1148 | 1221 |
1149 def testStat_directory(self): | 1222 def testStat_directory(self): |
1150 result = [('.', adb_wrapper.DeviceStat(16873, 4096, 12382237)), | 1223 result = [('.', adb_wrapper.DeviceStat(16873, 4096, 12382237)), |
1151 ('..', adb_wrapper.DeviceStat(16873, 4096, 12382237)), | 1224 ('..', adb_wrapper.DeviceStat(16873, 4096, 12382237)), |
1152 ('tmp', adb_wrapper.DeviceStat(16889, 4096, 1417436123))] | 1225 ('tmp', adb_wrapper.DeviceStat(16889, 4096, 1417436123))] |
1153 with self.assertCalls( | 1226 with self.assertCalls( |
1154 (self.call.adb.Ls('/data/local'), result)): | 1227 (self.call.adb.Ls('/data/local'), result)): |
1155 self.assertEquals(adb_wrapper.DeviceStat(16889, 4096, 1417436123), | 1228 self.assertEquals(adb_wrapper.DeviceStat(16889, 4096, 1417436123), |
1156 self.device.Stat('/data/local/tmp')) | 1229 self.device.Stat('/data/local/tmp')) |
1157 | 1230 |
1158 def testStat_doesNotExist(self): | 1231 def testStat_doesNotExist(self): |
1159 result = [('.', adb_wrapper.DeviceStat(16889, 4096, 1417436123)), | 1232 result = [('.', adb_wrapper.DeviceStat(16889, 4096, 1417436123)), |
1160 ('..', adb_wrapper.DeviceStat(16873, 4096, 12382237)), | 1233 ('..', adb_wrapper.DeviceStat(16873, 4096, 12382237)), |
1161 ('testfile.txt', adb_wrapper.DeviceStat(33206, 3, 1417436122))] | 1234 ('testfile.txt', adb_wrapper.DeviceStat(33206, 3, 1417436122))] |
1162 with self.assertCalls( | 1235 with self.assertCalls( |
1163 (self.call.adb.Ls('/data/local/tmp'), result)): | 1236 (self.call.adb.Ls('/data/local/tmp'), result)): |
1164 with self.assertRaises(device_errors.CommandFailedError): | 1237 with self.assertRaises(device_errors.CommandFailedError): |
1165 self.device.Stat('/data/local/tmp/does.not.exist.txt') | 1238 self.device.Stat('/data/local/tmp/does.not.exist.txt') |
1166 | 1239 |
1167 | 1240 |
1168 class DeviceUtilsSetJavaAssertsTest(DeviceUtilsTest): | 1241 class DeviceUtilsSetJavaAssertsTest(DeviceUtilsNewImplTest): |
1169 | 1242 |
1170 def testSetJavaAsserts_enable(self): | 1243 def testSetJavaAsserts_enable(self): |
1171 with self.assertCalls( | 1244 with self.assertCalls( |
1172 (self.call.device.ReadFile(constants.DEVICE_LOCAL_PROPERTIES_PATH), | 1245 (self.call.device.ReadFile(constants.DEVICE_LOCAL_PROPERTIES_PATH), |
1173 'some.example.prop=with an example value\n' | 1246 'some.example.prop=with an example value\n' |
1174 'some.other.prop=value_ok\n'), | 1247 'some.other.prop=value_ok\n'), |
1175 self.call.device.WriteFile( | 1248 self.call.device.WriteFile( |
1176 constants.DEVICE_LOCAL_PROPERTIES_PATH, | 1249 constants.DEVICE_LOCAL_PROPERTIES_PATH, |
1177 'some.example.prop=with an example value\n' | 1250 'some.example.prop=with an example value\n' |
1178 'some.other.prop=value_ok\n' | 1251 'some.other.prop=value_ok\n' |
(...skipping 19 matching lines...) Expand all Loading... |
1198 def testSetJavaAsserts_alreadyEnabled(self): | 1271 def testSetJavaAsserts_alreadyEnabled(self): |
1199 with self.assertCalls( | 1272 with self.assertCalls( |
1200 (self.call.device.ReadFile(constants.DEVICE_LOCAL_PROPERTIES_PATH), | 1273 (self.call.device.ReadFile(constants.DEVICE_LOCAL_PROPERTIES_PATH), |
1201 'some.example.prop=with an example value\n' | 1274 'some.example.prop=with an example value\n' |
1202 'dalvik.vm.enableassertions=all\n' | 1275 'dalvik.vm.enableassertions=all\n' |
1203 'some.other.prop=value_ok\n'), | 1276 'some.other.prop=value_ok\n'), |
1204 (self.call.device.GetProp('dalvik.vm.enableassertions'), 'all')): | 1277 (self.call.device.GetProp('dalvik.vm.enableassertions'), 'all')): |
1205 self.assertFalse(self.device.SetJavaAsserts(True)) | 1278 self.assertFalse(self.device.SetJavaAsserts(True)) |
1206 | 1279 |
1207 | 1280 |
1208 class DeviceUtilsGetPropTest(DeviceUtilsTest): | 1281 class DeviceUtilsGetPropTest(DeviceUtilsNewImplTest): |
1209 | 1282 |
1210 def testGetProp_exists(self): | 1283 def testGetProp_exists(self): |
1211 with self.assertCall( | 1284 with self.assertCall( |
1212 self.call.adb.Shell('getprop test.property'), 'property_value\n'): | 1285 self.call.adb.Shell('getprop test.property'), 'property_value\n'): |
1213 self.assertEqual('property_value', | 1286 self.assertEqual('property_value', |
1214 self.device.GetProp('test.property')) | 1287 self.device.GetProp('test.property')) |
1215 | 1288 |
1216 def testGetProp_doesNotExist(self): | 1289 def testGetProp_doesNotExist(self): |
1217 with self.assertCall( | 1290 with self.assertCall( |
1218 self.call.adb.Shell('getprop property.does.not.exist'), '\n'): | 1291 self.call.adb.Shell('getprop property.does.not.exist'), '\n'): |
(...skipping 13 matching lines...) Expand all Loading... |
1232 (self.call.adb.Shell('getprop ro.build.type'), self.ShellError()), | 1305 (self.call.adb.Shell('getprop ro.build.type'), self.ShellError()), |
1233 (self.call.adb.Shell('getprop ro.build.type'), 'userdebug\n')): | 1306 (self.call.adb.Shell('getprop ro.build.type'), 'userdebug\n')): |
1234 self.assertEqual('userdebug', | 1307 self.assertEqual('userdebug', |
1235 self.device.GetProp('ro.build.type', | 1308 self.device.GetProp('ro.build.type', |
1236 cache=True, retries=3)) | 1309 cache=True, retries=3)) |
1237 self.assertEqual('userdebug', | 1310 self.assertEqual('userdebug', |
1238 self.device.GetProp('ro.build.type', | 1311 self.device.GetProp('ro.build.type', |
1239 cache=True, retries=3)) | 1312 cache=True, retries=3)) |
1240 | 1313 |
1241 | 1314 |
1242 class DeviceUtilsSetPropTest(DeviceUtilsTest): | 1315 class DeviceUtilsSetPropTest(DeviceUtilsNewImplTest): |
1243 | 1316 |
1244 def testSetProp(self): | 1317 def testSetProp(self): |
1245 with self.assertCall( | 1318 with self.assertCall( |
1246 self.call.adb.Shell("setprop test.property 'test value'"), ''): | 1319 self.call.adb.Shell("setprop test.property 'test value'"), ''): |
1247 self.device.SetProp('test.property', 'test value') | 1320 self.device.SetProp('test.property', 'test value') |
1248 | 1321 |
1249 def testSetProp_check_succeeds(self): | 1322 def testSetProp_check_succeeds(self): |
1250 with self.assertCalls( | 1323 with self.assertCalls( |
1251 (self.call.adb.Shell('setprop test.property new_value'), ''), | 1324 (self.call.adb.Shell('setprop test.property new_value'), ''), |
1252 (self.call.adb.Shell('getprop test.property'), 'new_value')): | 1325 (self.call.adb.Shell('getprop test.property'), 'new_value')): |
1253 self.device.SetProp('test.property', 'new_value', check=True) | 1326 self.device.SetProp('test.property', 'new_value', check=True) |
1254 | 1327 |
1255 def testSetProp_check_fails(self): | 1328 def testSetProp_check_fails(self): |
1256 with self.assertCalls( | 1329 with self.assertCalls( |
1257 (self.call.adb.Shell('setprop test.property new_value'), ''), | 1330 (self.call.adb.Shell('setprop test.property new_value'), ''), |
1258 (self.call.adb.Shell('getprop test.property'), 'old_value')): | 1331 (self.call.adb.Shell('getprop test.property'), 'old_value')): |
1259 with self.assertRaises(device_errors.CommandFailedError): | 1332 with self.assertRaises(device_errors.CommandFailedError): |
1260 self.device.SetProp('test.property', 'new_value', check=True) | 1333 self.device.SetProp('test.property', 'new_value', check=True) |
1261 | 1334 |
1262 | 1335 |
1263 class DeviceUtilsGetPidsTest(DeviceUtilsTest): | 1336 class DeviceUtilsGetPidsTest(DeviceUtilsNewImplTest): |
1264 | 1337 |
1265 def testGetPids_noMatches(self): | 1338 def testGetPids_noMatches(self): |
1266 with self.assertCall(self.call.adb.Shell('ps'), | 1339 with self.assertCall(self.call.adb.Shell('ps'), |
1267 'USER PID PPID VSIZE RSS WCHAN PC NAME\n' | 1340 'USER PID PPID VSIZE RSS WCHAN PC NAME\n' |
1268 'user 1000 100 1024 1024 ffffffff 00000000 no.match\n'): | 1341 'user 1000 100 1024 1024 ffffffff 00000000 no.match\n'): |
1269 self.assertEqual({}, self.device.GetPids('does.not.match')) | 1342 self.assertEqual({}, self.device.GetPids('does.not.match')) |
1270 | 1343 |
1271 def testGetPids_oneMatch(self): | 1344 def testGetPids_oneMatch(self): |
1272 with self.assertCall(self.call.adb.Shell('ps'), | 1345 with self.assertCall(self.call.adb.Shell('ps'), |
1273 'USER PID PPID VSIZE RSS WCHAN PC NAME\n' | 1346 'USER PID PPID VSIZE RSS WCHAN PC NAME\n' |
(...skipping 15 matching lines...) Expand all Loading... |
1289 def testGetPids_exactMatch(self): | 1362 def testGetPids_exactMatch(self): |
1290 with self.assertCall(self.call.adb.Shell('ps'), | 1363 with self.assertCall(self.call.adb.Shell('ps'), |
1291 'USER PID PPID VSIZE RSS WCHAN PC NAME\n' | 1364 'USER PID PPID VSIZE RSS WCHAN PC NAME\n' |
1292 'user 1000 100 1024 1024 ffffffff 00000000 not.exact.match\n' | 1365 'user 1000 100 1024 1024 ffffffff 00000000 not.exact.match\n' |
1293 'user 1234 100 1024 1024 ffffffff 00000000 exact.match\n'): | 1366 'user 1234 100 1024 1024 ffffffff 00000000 exact.match\n'): |
1294 self.assertEqual( | 1367 self.assertEqual( |
1295 {'not.exact.match': '1000', 'exact.match': '1234'}, | 1368 {'not.exact.match': '1000', 'exact.match': '1234'}, |
1296 self.device.GetPids('exact.match')) | 1369 self.device.GetPids('exact.match')) |
1297 | 1370 |
1298 | 1371 |
1299 class DeviceUtilsTakeScreenshotTest(DeviceUtilsTest): | 1372 class DeviceUtilsTakeScreenshotTest(DeviceUtilsNewImplTest): |
1300 | 1373 |
1301 def testTakeScreenshot_fileNameProvided(self): | 1374 def testTakeScreenshot_fileNameProvided(self): |
1302 with self.assertCalls( | 1375 with self.assertCalls( |
1303 (mock.call.pylib.utils.device_temp_file.DeviceTempFile( | 1376 (mock.call.pylib.utils.device_temp_file.DeviceTempFile( |
1304 self.adb, suffix='.png'), | 1377 self.adb, suffix='.png'), |
1305 MockTempFile('/tmp/path/temp-123.png')), | 1378 MockTempFile('/tmp/path/temp-123.png')), |
1306 (self.call.adb.Shell('/system/bin/screencap -p /tmp/path/temp-123.png'), | 1379 (self.call.adb.Shell('/system/bin/screencap -p /tmp/path/temp-123.png'), |
1307 ''), | 1380 ''), |
1308 self.call.device.PullFile('/tmp/path/temp-123.png', | 1381 self.call.device.PullFile('/tmp/path/temp-123.png', |
1309 '/test/host/screenshot.png')): | 1382 '/test/host/screenshot.png')): |
1310 self.device.TakeScreenshot('/test/host/screenshot.png') | 1383 self.device.TakeScreenshot('/test/host/screenshot.png') |
1311 | 1384 |
1312 | 1385 |
1313 class DeviceUtilsGetMemoryUsageForPidTest(DeviceUtilsTest): | 1386 class DeviceUtilsGetMemoryUsageForPidTest(DeviceUtilsOldImplTest): |
1314 | 1387 |
1315 def setUp(self): | 1388 def setUp(self): |
1316 super(DeviceUtilsGetMemoryUsageForPidTest, self).setUp() | 1389 super(DeviceUtilsGetMemoryUsageForPidTest, self).setUp() |
| 1390 self.device.old_interface._privileged_command_runner = ( |
| 1391 self.device.old_interface.RunShellCommand) |
| 1392 self.device.old_interface._protected_file_access_method_initialized = True |
1317 | 1393 |
1318 def testGetMemoryUsageForPid_validPid(self): | 1394 def testGetMemoryUsageForPid_validPid(self): |
1319 with self.assertCalls( | 1395 with self.assertCallsSequence([ |
1320 (self.call.device.RunShellCommand( | 1396 ("adb -s 0123456789abcdef shell 'showmap 1234'", |
1321 ['showmap', '1234'], as_root=True, check_return=True), | 1397 '100 101 102 103 104 105 106 107 TOTAL\r\n'), |
1322 ['100 101 102 103 104 105 106 107 TOTAL']), | 1398 ("adb -s 0123456789abcdef shell " |
1323 (self.call.device.ReadFile('/proc/1234/status', as_root=True), | 1399 "'cat \"/proc/1234/status\" 2> /dev/null'", |
1324 'VmHWM: 1024 kB\n')): | 1400 'VmHWM: 1024 kB') |
| 1401 ]): |
1325 self.assertEqual( | 1402 self.assertEqual( |
1326 { | 1403 { |
1327 'Size': 100, | 1404 'Size': 100, |
1328 'Rss': 101, | 1405 'Rss': 101, |
1329 'Pss': 102, | 1406 'Pss': 102, |
1330 'Shared_Clean': 103, | 1407 'Shared_Clean': 103, |
1331 'Shared_Dirty': 104, | 1408 'Shared_Dirty': 104, |
1332 'Private_Clean': 105, | 1409 'Private_Clean': 105, |
1333 'Private_Dirty': 106, | 1410 'Private_Dirty': 106, |
1334 'VmHWM': 1024 | 1411 'VmHWM': 1024 |
1335 }, | 1412 }, |
1336 self.device.GetMemoryUsageForPid(1234)) | 1413 self.device.GetMemoryUsageForPid(1234)) |
1337 | 1414 |
1338 def testGetMemoryUsageForPid_noSmaps(self): | 1415 def testGetMemoryUsageForPid_invalidPid(self): |
1339 with self.assertCalls( | 1416 with self.assertCalls( |
1340 (self.call.device.RunShellCommand( | 1417 "adb -s 0123456789abcdef shell 'showmap 4321'", |
1341 ['showmap', '4321'], as_root=True, check_return=True), | 1418 'cannot open /proc/4321/smaps: No such file or directory\r\n'): |
1342 ['cannot open /proc/4321/smaps: No such file or directory']), | 1419 self.assertEqual({}, self.device.GetMemoryUsageForPid(4321)) |
1343 (self.call.device.ReadFile('/proc/4321/status', as_root=True), | |
1344 'VmHWM: 1024 kb\n')): | |
1345 self.assertEquals({'VmHWM': 1024}, self.device.GetMemoryUsageForPid(4321)) | |
1346 | |
1347 def testGetMemoryUsageForPid_noStatus(self): | |
1348 with self.assertCalls( | |
1349 (self.call.device.RunShellCommand( | |
1350 ['showmap', '4321'], as_root=True, check_return=True), | |
1351 ['100 101 102 103 104 105 106 107 TOTAL']), | |
1352 (self.call.device.ReadFile('/proc/4321/status', as_root=True), | |
1353 self.CommandError())): | |
1354 self.assertEquals( | |
1355 { | |
1356 'Size': 100, | |
1357 'Rss': 101, | |
1358 'Pss': 102, | |
1359 'Shared_Clean': 103, | |
1360 'Shared_Dirty': 104, | |
1361 'Private_Clean': 105, | |
1362 'Private_Dirty': 106, | |
1363 }, | |
1364 self.device.GetMemoryUsageForPid(4321)) | |
1365 | 1420 |
1366 | 1421 |
1367 class DeviceUtilsStrTest(DeviceUtilsTest): | 1422 class DeviceUtilsStrTest(DeviceUtilsNewImplTest): |
1368 | 1423 |
1369 def testStr_returnsSerial(self): | 1424 def testStr_returnsSerial(self): |
1370 with self.assertCalls( | 1425 with self.assertCalls( |
1371 (self.call.adb.GetDeviceSerial(), '0123456789abcdef')): | 1426 (self.call.adb.GetDeviceSerial(), '0123456789abcdef')): |
1372 self.assertEqual('0123456789abcdef', str(self.device)) | 1427 self.assertEqual('0123456789abcdef', str(self.device)) |
1373 | 1428 |
1374 | 1429 |
1375 class DeviceUtilsParallelTest(mock_calls.TestCase): | 1430 class DeviceUtilsParallelTest(mock_calls.TestCase): |
1376 | 1431 |
1377 def testParallel_default(self): | 1432 def testParallel_default(self): |
1378 test_serials = ['0123456789abcdef', 'fedcba9876543210'] | 1433 test_serials = ['0123456789abcdef', 'fedcba9876543210'] |
1379 with self.assertCall( | 1434 with self.assertCall( |
1380 mock.call.pylib.device.adb_wrapper.AdbWrapper.GetDevices(), | 1435 mock.call.pylib.device.adb_wrapper.AdbWrapper.GetDevices(), |
1381 [_AdbWrapperMock(serial) for serial in test_serials]): | 1436 [_AdbWrapperMock(serial) for serial in test_serials]): |
1382 parallel_devices = device_utils.DeviceUtils.parallel() | 1437 parallel_devices = device_utils.DeviceUtils.parallel() |
1383 for serial, device in zip(test_serials, parallel_devices.pGet(None)): | 1438 for serial, device in zip(test_serials, parallel_devices.pGet(None)): |
1384 self.assertTrue( | 1439 self.assertTrue( |
1385 isinstance(device, device_utils.DeviceUtils) | 1440 isinstance(device, device_utils.DeviceUtils) |
1386 and serial == str(device), | 1441 and serial == str(device), |
1387 'Expected a DeviceUtils object with serial %s' % serial) | 1442 'Expected a DeviceUtils object with serial %s' % serial) |
1388 | 1443 |
1389 | 1444 |
1390 if __name__ == '__main__': | 1445 if __name__ == '__main__': |
1391 logging.getLogger().setLevel(logging.DEBUG) | 1446 logging.getLogger().setLevel(logging.DEBUG) |
1392 unittest.main(verbosity=2) | 1447 unittest.main(verbosity=2) |
1393 | 1448 |
OLD | NEW |