| 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 b7e807e06d74cf063d247e10b99c93fe870b4b5c..7c20f0dac612e6367470f8617366c88ca9e210f3 100755
|
| --- a/build/android/pylib/device/device_utils_test.py
|
| +++ b/build/android/pylib/device/device_utils_test.py
|
| @@ -1046,31 +1046,100 @@ class DeviceUtilsPullFileTest(DeviceUtilsTest):
|
|
|
| class DeviceUtilsReadFileTest(DeviceUtilsTest):
|
|
|
| + def testReadFileWithPull_success(self):
|
| + tmp_host_dir = '/tmp/dir/on.host/'
|
| + tmp_host = MockTempFile('/tmp/dir/on.host/tmp_ReadFileWithPull')
|
| + tmp_host.file.read.return_value = 'some interesting contents'
|
| + with self.assertCalls(
|
| + (mock.call.tempfile.mkdtemp(), tmp_host_dir),
|
| + (self.call.adb.Pull('/path/to/device/file', mock.ANY)),
|
| + (mock.call.__builtin__.open(mock.ANY, 'r'), tmp_host),
|
| + (mock.call.os.path.exists(tmp_host_dir), True),
|
| + (mock.call.shutil.rmtree(tmp_host_dir), None)):
|
| + self.assertEquals('some interesting contents',
|
| + self.device._ReadFileWithPull('/path/to/device/file'))
|
| + tmp_host.file.read.assert_called_once_with()
|
| +
|
| + def testReadFileWithPull_rejected(self):
|
| + tmp_host_dir = '/tmp/dir/on.host/'
|
| + with self.assertCalls(
|
| + (mock.call.tempfile.mkdtemp(), tmp_host_dir),
|
| + (self.call.adb.Pull('/path/to/device/file', mock.ANY),
|
| + self.CommandError()),
|
| + (mock.call.os.path.exists(tmp_host_dir), True),
|
| + (mock.call.shutil.rmtree(tmp_host_dir), None)):
|
| + with self.assertRaises(device_errors.CommandFailedError):
|
| + self.device._ReadFileWithPull('/path/to/device/file')
|
| +
|
| def testReadFile_exists(self):
|
| - with self.assertCall(
|
| - self.call.adb.Shell('cat /read/this/test/file'),
|
| - 'this is a test file\r\n'):
|
| + with self.assertCalls(
|
| + (self.call.device.RunShellCommand(
|
| + ['ls', '-l', '/read/this/test/file'],
|
| + as_root=False, check_return=True),
|
| + ['-rw-rw---- root foo 256 1970-01-01 00:00 file']),
|
| + (self.call.device.RunShellCommand(
|
| + ['cat', '/read/this/test/file'], as_root=False, check_return=True),
|
| + ['this is a test file'])):
|
| self.assertEqual('this is a test file\n',
|
| self.device.ReadFile('/read/this/test/file'))
|
|
|
| def testReadFile_doesNotExist(self):
|
| with self.assertCall(
|
| - self.call.adb.Shell('cat /this/file/does.not.exist'),
|
| - self.ShellError('/system/bin/sh: cat: /this/file/does.not.exist: '
|
| - 'No such file or directory')):
|
| - with self.assertRaises(device_errors.AdbCommandFailedError):
|
| + self.call.device.RunShellCommand(
|
| + ['ls', '-l', '/this/file/does.not.exist'],
|
| + as_root=False, check_return=True),
|
| + self.CommandError('File does not exist')):
|
| + with self.assertRaises(device_errors.CommandFailedError):
|
| self.device.ReadFile('/this/file/does.not.exist')
|
|
|
| def testReadFile_withSU(self):
|
| with self.assertCalls(
|
| - (self.call.device.NeedsSU(), True),
|
| - (self.call.adb.Shell("su -c sh -c 'cat /this/file/can.be.read.with.su'"),
|
| - 'this is a test file\nread with su')):
|
| + (self.call.device.RunShellCommand(
|
| + ['ls', '-l', '/this/file/can.be.read.with.su'],
|
| + as_root=True, check_return=True),
|
| + ['-rw------- root root 256 1970-01-01 00:00 can.be.read.with.su']),
|
| + (self.call.device.RunShellCommand(
|
| + ['cat', '/this/file/can.be.read.with.su'],
|
| + as_root=True, check_return=True),
|
| + ['this is a test file', 'read with su'])):
|
| self.assertEqual(
|
| 'this is a test file\nread with su\n',
|
| self.device.ReadFile('/this/file/can.be.read.with.su',
|
| as_root=True))
|
|
|
| + def testReadFile_withPull(self):
|
| + contents = 'a' * 123456
|
| + with self.assertCalls(
|
| + (self.call.device.RunShellCommand(
|
| + ['ls', '-l', '/read/this/big/test/file'],
|
| + as_root=False, check_return=True),
|
| + ['-rw-rw---- root foo 123456 1970-01-01 00:00 file']),
|
| + (self.call.device._ReadFileWithPull('/read/this/big/test/file'),
|
| + contents)):
|
| + self.assertEqual(
|
| + contents, self.device.ReadFile('/read/this/big/test/file'))
|
| +
|
| + def testReadFile_withPullAndSU(self):
|
| + contents = 'b' * 123456
|
| + with self.assertCalls(
|
| + (self.call.device.RunShellCommand(
|
| + ['ls', '-l', '/this/big/file/can.be.read.with.su'],
|
| + as_root=True, check_return=True),
|
| + ['-rw------- root root 123456 1970-01-01 00:00 can.be.read.with.su']),
|
| + (self.call.device.NeedsSU(), True),
|
| + (mock.call.pylib.utils.device_temp_file.DeviceTempFile(self.adb),
|
| + MockTempFile('/sdcard/tmp/on.device')),
|
| + self.call.device.RunShellCommand(
|
| + ['cp', '/this/big/file/can.be.read.with.su',
|
| + '/sdcard/tmp/on.device'],
|
| + as_root=True, check_return=True),
|
| + (self.call.device._ReadFileWithPull('/sdcard/tmp/on.device'),
|
| + contents)):
|
| + self.assertEqual(
|
| + contents,
|
| + self.device.ReadFile('/this/big/file/can.be.read.with.su',
|
| + as_root=True))
|
| +
|
|
|
| class DeviceUtilsWriteFileTest(DeviceUtilsTest):
|
|
|
|
|