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

Unified Diff: build/android/pylib/device/device_utils_test.py

Issue 706203003: Update from https://crrev.com/303153 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « build/android/pylib/device/device_utils.py ('k') | build/android/pylib/gtest/setup.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/pylib/device/device_utils_test.py
diff --git a/build/android/pylib/device/device_utils_test.py b/build/android/pylib/device/device_utils_test.py
index f23e21ee382f6c7a46a816811ae490cf9431acb7..fa4ffaae40c19274dcdfb8cfcaae9be12bfac109 100755
--- a/build/android/pylib/device/device_utils_test.py
+++ b/build/android/pylib/device/device_utils_test.py
@@ -313,7 +313,7 @@ class DeviceUtilsNewImplTest(unittest.TestCase):
or a _ShellError object to raise an AdbShellCommandFailedError.
'''
def mk_expected_call(cmd, return_value):
- expected_args = Args(cmd, expect_rc=0, timeout=10, retries=0)
+ expected_args = Args(cmd, expect_rc=0)
if isinstance(return_value, _ShellError):
return_value = device_errors.AdbShellCommandFailedError(cmd,
return_value.return_code, return_value.output, str(self.device))
@@ -348,6 +348,11 @@ class DeviceUtilsIsOnlineTest(DeviceUtilsNewImplTest):
self.assertFalse(self.device.IsOnline())
self.adb.GetState.assert_called_once_with()
+ def testIsOnline_error(self):
+ self.adb.GetState = mock.Mock(
+ side_effect=device_errors.CommandFailedError('falied'))
+ self.assertFalse(self.device.IsOnline())
+ self.adb.GetState.assert_called_once_with()
class DeviceUtilsHasRootTest(DeviceUtilsNewImplTest):
@@ -440,7 +445,7 @@ class DeviceUtilsWaitUntilFullyBootedTest(DeviceUtilsNewImplTest):
with self.assertShellCallSequence([
# sc_card_ready
('echo $EXTERNAL_STORAGE', '/fake/storage/path\r\n'),
- ('ls /fake/storage/path', '/fake/storage/path\r\n'),
+ ('test -d /fake/storage/path', ''),
# pm_ready
('pm path android', 'package:this.is.a.test.package\r\n'),
# boot_completed
@@ -452,7 +457,7 @@ class DeviceUtilsWaitUntilFullyBootedTest(DeviceUtilsNewImplTest):
with self.assertShellCallSequence([
# sc_card_ready
('echo $EXTERNAL_STORAGE', '/fake/storage/path\r\n'),
- ('ls /fake/storage/path', '/fake/storage/path\r\n'),
+ ('test -d /fake/storage/path', ''),
# pm_ready
('pm path android', 'package:this.is.a.test.package\r\n'),
# boot_completed
@@ -474,11 +479,11 @@ class DeviceUtilsWaitUntilFullyBootedTest(DeviceUtilsNewImplTest):
with self.assertShellCallSequence([
# sc_card_ready
('echo $EXTERNAL_STORAGE', '/fake/storage/path\r\n'),
- ('ls /fake/storage/path', '\r\n'),
+ ('test -d /fake/storage/path', _ShellError()),
# sc_card_ready
- ('ls /fake/storage/path', '\r\n'),
+ ('test -d /fake/storage/path', _ShellError()),
# sc_card_ready
- ('ls /fake/storage/path', _CmdTimeout())]):
+ ('test -d /fake/storage/path', _CmdTimeout())]):
with self.assertRaises(device_errors.CommandTimeoutError):
self.device.WaitUntilFullyBooted(wifi=False)
@@ -487,7 +492,7 @@ class DeviceUtilsWaitUntilFullyBootedTest(DeviceUtilsNewImplTest):
with self.assertShellCallSequence([
# sc_card_ready
('echo $EXTERNAL_STORAGE', '/fake/storage/path\r\n'),
- ('ls /fake/storage/path', '/fake/storage/path\r\n'),
+ ('test -d /fake/storage/path', ''),
# pm_ready
('pm path android', 'Error. Is package manager running?\r\n'),
# pm_ready
@@ -502,7 +507,7 @@ class DeviceUtilsWaitUntilFullyBootedTest(DeviceUtilsNewImplTest):
with self.assertShellCallSequence([
# sc_card_ready
('echo $EXTERNAL_STORAGE', '/fake/storage/path\r\n'),
- ('ls /fake/storage/path', '/fake/storage/path\r\n'),
+ ('test -d /fake/storage/path', ''),
# pm_ready
('pm path android', 'package:this.is.a.test.package\r\n'),
# boot_completed
@@ -519,7 +524,7 @@ class DeviceUtilsWaitUntilFullyBootedTest(DeviceUtilsNewImplTest):
with self.assertShellCallSequence([
# sc_card_ready
('echo $EXTERNAL_STORAGE', '/fake/storage/path\r\n'),
- ('ls /fake/storage/path', '/fake/storage/path\r\n'),
+ ('test -d /fake/storage/path', ''),
# pm_ready
('pm path android', 'package:this.is.a.test.package\r\n'),
# boot_completed
@@ -549,7 +554,7 @@ class DeviceUtilsRebootTest(DeviceUtilsNewImplTest):
with self.assertShellCallSequence([
# sc_card_ready
('echo $EXTERNAL_STORAGE', '/fake/storage/path\r\n'),
- ('ls /fake/storage/path', '/fake/storage/path\r\n'),
+ ('test -d /fake/storage/path', ''),
# pm_ready
('pm path android', 'package:this.is.a.test.package\r\n'),
# boot_completed
@@ -685,13 +690,13 @@ class DeviceUtilsRunShellCommandTest(DeviceUtilsNewImplTest):
def testRunShellCommand_withSu(self):
with self.assertShellCallSequence([
- ('ls /root', _ShellError()),
+ ('su -c ls /root && ! ls /root', ''),
('su -c setprop service.adb.root 0', '')]):
self.device.RunShellCommand('setprop service.adb.root 0', as_root=True)
def testRunShellCommand_withRoot(self):
with self.assertShellCallSequence([
- ('ls /root', '\r\n'),
+ ('su -c ls /root && ! ls /root', _ShellError()),
('setprop service.adb.root 0', '')]):
self.device.RunShellCommand('setprop service.adb.root 0', as_root=True)
@@ -789,7 +794,7 @@ class DeviceUtilsKillAllTest(DeviceUtilsNewImplTest):
('ps', 'USER PID PPID VSIZE RSS WCHAN PC NAME\r\n'
'u0_a1 1234 174 123456 54321 ffffffff 456789ab '
'this.is.a.test.process\r\n'),
- ('ls /root', _ShellError()),
+ ('su -c ls /root && ! ls /root', ''),
('su -c kill -9 1234', '')]):
self.assertEquals(1,
self.device.KillAll('this.is.a.test.process', as_root=True))
@@ -1090,7 +1095,7 @@ class DeviceUtilsPushChangedFilesZippedTest(DeviceUtilsHybridImplTest):
self.device._GetExternalStoragePathImpl = mock.Mock(
return_value='/test/device/external_dir')
self.device.IsOnline = mock.Mock(return_value=True)
- self.device._RunShellCommandImpl = mock.Mock()
+ self.device.RunShellCommand = mock.Mock()
mock_zip_temp = mock.mock_open()
mock_zip_temp.return_value.name = '/test/temp/file/tmp.zip'
with mock.patch('multiprocessing.Process') as mock_zip_proc, (
@@ -1102,13 +1107,13 @@ class DeviceUtilsPushChangedFilesZippedTest(DeviceUtilsHybridImplTest):
args=('/test/temp/file/tmp.zip', test_files))
self.adb.Push.assert_called_once_with(
'/test/temp/file/tmp.zip', '/test/device/external_dir/tmp.zip')
- self.assertEqual(2, self.device._RunShellCommandImpl.call_count)
- self.device._RunShellCommandImpl.assert_any_call(
+ self.assertEqual(2, self.device.RunShellCommand.call_count)
+ self.device.RunShellCommand.assert_any_call(
['unzip', '/test/device/external_dir/tmp.zip'],
as_root=True,
env={'PATH': '$PATH:/data/local/tmp/bin'},
check_return=True)
- self.device._RunShellCommandImpl.assert_any_call(
+ self.device.RunShellCommand.assert_any_call(
['rm', '/test/device/external_dir/tmp.zip'], check_return=True)
def testPushChangedFilesZipped_multiple(self):
@@ -1118,7 +1123,7 @@ class DeviceUtilsPushChangedFilesZippedTest(DeviceUtilsHybridImplTest):
self.device._GetExternalStoragePathImpl = mock.Mock(
return_value='/test/device/external_dir')
self.device.IsOnline = mock.Mock(return_value=True)
- self.device._RunShellCommandImpl = mock.Mock()
+ self.device.RunShellCommand = mock.Mock()
mock_zip_temp = mock.mock_open()
mock_zip_temp.return_value.name = '/test/temp/file/tmp.zip'
with mock.patch('multiprocessing.Process') as mock_zip_proc, (
@@ -1130,13 +1135,13 @@ class DeviceUtilsPushChangedFilesZippedTest(DeviceUtilsHybridImplTest):
args=('/test/temp/file/tmp.zip', test_files))
self.adb.Push.assert_called_once_with(
'/test/temp/file/tmp.zip', '/test/device/external_dir/tmp.zip')
- self.assertEqual(2, self.device._RunShellCommandImpl.call_count)
- self.device._RunShellCommandImpl.assert_any_call(
+ self.assertEqual(2, self.device.RunShellCommand.call_count)
+ self.device.RunShellCommand.assert_any_call(
['unzip', '/test/device/external_dir/tmp.zip'],
as_root=True,
env={'PATH': '$PATH:/data/local/tmp/bin'},
check_return=True)
- self.device._RunShellCommandImpl.assert_any_call(
+ self.device.RunShellCommand.assert_any_call(
['rm', '/test/device/external_dir/tmp.zip'], check_return=True)
@@ -1378,7 +1383,7 @@ class DeviceUtilsWriteTextFileTest(DeviceUtilsNewImplTest):
def testWriteTextFileTest_asRoot(self):
with self.assertShellCallSequence([
- ('ls /root', _ShellError()),
+ ('su -c ls /root && ! ls /root', ''),
('su -c echo string > /test/file', '')]):
self.device.WriteTextFile('/test/file', 'string', as_root=True)
« no previous file with comments | « build/android/pylib/device/device_utils.py ('k') | build/android/pylib/gtest/setup.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698