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

Side by Side Diff: build/android/pylib/device/device_utils_test.py

Issue 796663002: Update from https://crrev.com/307758 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Updates for SkCanvas::NewRaster deprecation 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
OLDNEW
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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 def setUp(self): 247 def setUp(self):
248 self._get_adb_path_patch = mock.patch('pylib.constants.GetAdbPath', 248 self._get_adb_path_patch = mock.patch('pylib.constants.GetAdbPath',
249 mock.Mock(return_value='adb')) 249 mock.Mock(return_value='adb'))
250 self._get_adb_path_patch.start() 250 self._get_adb_path_patch.start()
251 self.device = device_utils.DeviceUtils( 251 self.device = device_utils.DeviceUtils(
252 '0123456789abcdef', default_timeout=1, default_retries=0) 252 '0123456789abcdef', default_timeout=1, default_retries=0)
253 253
254 def tearDown(self): 254 def tearDown(self):
255 self._get_adb_path_patch.stop() 255 self._get_adb_path_patch.stop()
256 256
257
258 def _AdbWrapperMock(test_serial):
259 adb = mock.Mock(spec=adb_wrapper.AdbWrapper)
260 adb.__str__ = mock.Mock(return_value=test_serial)
261 adb.GetDeviceSerial.return_value = test_serial
262 return adb
263
264
257 class DeviceUtilsNewImplTest(mock_calls.TestCase): 265 class DeviceUtilsNewImplTest(mock_calls.TestCase):
258 266
259 def setUp(self): 267 def setUp(self):
260 test_serial = '0123456789abcdef' 268 self.adb = _AdbWrapperMock('0123456789abcdef')
261 self.adb = mock.Mock(spec=adb_wrapper.AdbWrapper)
262 self.adb.__str__ = mock.Mock(return_value=test_serial)
263 self.adb.GetDeviceSerial.return_value = test_serial
264 self.device = device_utils.DeviceUtils( 269 self.device = device_utils.DeviceUtils(
265 self.adb, default_timeout=10, default_retries=0) 270 self.adb, default_timeout=10, default_retries=0)
266 self.watchMethodCalls(self.call.adb, ignore=['GetDeviceSerial']) 271 self.watchMethodCalls(self.call.adb, ignore=['GetDeviceSerial'])
267 272
268 def ShellError(self, output=None, exit_code=1): 273 def ShellError(self, output=None, exit_code=1):
269 def action(cmd, *args, **kwargs): 274 def action(cmd, *args, **kwargs):
270 raise device_errors.AdbCommandFailedError( 275 raise device_errors.AdbCommandFailedError(
271 cmd, output, exit_code, str(self.device)) 276 cmd, output, exit_code, str(self.device))
272 if output is None: 277 if output is None:
273 output = 'Permission denied\n' 278 output = 'Permission denied\n'
(...skipping 900 matching lines...) Expand 10 before | Expand all | Expand 10 after
1174 self.call.adb.Push('/tmp/file/on.host', '/path/to/device/file')): 1179 self.call.adb.Push('/tmp/file/on.host', '/path/to/device/file')):
1175 self.device.WriteFile('/path/to/device/file', contents, force_push=True) 1180 self.device.WriteFile('/path/to/device/file', contents, force_push=True)
1176 tmp_host.file.write.assert_called_once_with(contents) 1181 tmp_host.file.write.assert_called_once_with(contents)
1177 1182
1178 def testWriteFile_withPushAndSU(self): 1183 def testWriteFile_withPushAndSU(self):
1179 tmp_host = MockTempFile('/tmp/file/on.host') 1184 tmp_host = MockTempFile('/tmp/file/on.host')
1180 contents = 'some large contents ' * 26 # 20 * 26 = 520 chars 1185 contents = 'some large contents ' * 26 # 20 * 26 = 520 chars
1181 with self.assertCalls( 1186 with self.assertCalls(
1182 (mock.call.tempfile.NamedTemporaryFile(), tmp_host), 1187 (mock.call.tempfile.NamedTemporaryFile(), tmp_host),
1183 (self.call.device.NeedsSU(), True), 1188 (self.call.device.NeedsSU(), True),
1184 (mock.call.pylib.utils.device_temp_file.DeviceTempFile(self.device), 1189 (mock.call.pylib.utils.device_temp_file.DeviceTempFile(self.adb),
1185 MockTempFile('/external/path/tmp/on.device')), 1190 MockTempFile('/external/path/tmp/on.device')),
1186 self.call.adb.Push('/tmp/file/on.host', '/external/path/tmp/on.device'), 1191 self.call.adb.Push('/tmp/file/on.host', '/external/path/tmp/on.device'),
1187 self.call.device.RunShellCommand( 1192 self.call.device.RunShellCommand(
1188 ['cp', '/external/path/tmp/on.device', '/path/to/device/file'], 1193 ['cp', '/external/path/tmp/on.device', '/path/to/device/file'],
1189 as_root=True, check_return=True)): 1194 as_root=True, check_return=True)):
1190 self.device.WriteFile('/path/to/device/file', contents, as_root=True) 1195 self.device.WriteFile('/path/to/device/file', contents, as_root=True)
1191 tmp_host.file.write.assert_called_once_with(contents) 1196 tmp_host.file.write.assert_called_once_with(contents)
1192 1197
1193 def testWriteFile_withPush_rejected(self): 1198 def testWriteFile_withPush_rejected(self):
1194 tmp_host = MockTempFile('/tmp/file/on.host') 1199 tmp_host = MockTempFile('/tmp/file/on.host')
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
1511 1516
1512 1517
1513 class DeviceUtilsStrTest(DeviceUtilsNewImplTest): 1518 class DeviceUtilsStrTest(DeviceUtilsNewImplTest):
1514 1519
1515 def testStr_returnsSerial(self): 1520 def testStr_returnsSerial(self):
1516 with self.assertCalls( 1521 with self.assertCalls(
1517 (self.call.adb.GetDeviceSerial(), '0123456789abcdef')): 1522 (self.call.adb.GetDeviceSerial(), '0123456789abcdef')):
1518 self.assertEqual('0123456789abcdef', str(self.device)) 1523 self.assertEqual('0123456789abcdef', str(self.device))
1519 1524
1520 1525
1526 class DeviceUtilsParallelTest(mock_calls.TestCase):
1527
1528 def testParallel_default(self):
1529 test_serials = ['0123456789abcdef', 'fedcba9876543210']
1530 with self.assertCall(
1531 mock.call.pylib.device.adb_wrapper.AdbWrapper.GetDevices(),
1532 [_AdbWrapperMock(serial) for serial in test_serials]):
1533 parallel_devices = device_utils.DeviceUtils.parallel()
1534 for serial, device in zip(test_serials, parallel_devices.pGet(None)):
1535 self.assertTrue(
1536 isinstance(device, device_utils.DeviceUtils)
1537 and serial == str(device),
1538 'Expected a DeviceUtils object with serial %s' % serial)
1539
1540
1521 if __name__ == '__main__': 1541 if __name__ == '__main__':
1522 logging.getLogger().setLevel(logging.DEBUG) 1542 logging.getLogger().setLevel(logging.DEBUG)
1523 unittest.main(verbosity=2) 1543 unittest.main(verbosity=2)
1524 1544
OLDNEW
« no previous file with comments | « build/android/pylib/device/device_utils.py ('k') | build/android/pylib/utils/device_temp_file.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698