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

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

Issue 806843002: Reland of Migrate DeviceUtils.ReadFile to adb_wrapper (try 3) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: enable command line test only for android Created 5 years, 11 months 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/flag_changer.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 58dd56ac9ee8a01abcde63f65744733a8f7d046b..23a26e7477ee6a6879732bbb7256f2319c8dd9d4 100755
--- a/build/android/pylib/device/device_utils_test.py
+++ b/build/android/pylib/device/device_utils_test.py
@@ -1049,56 +1049,33 @@ class DeviceUtilsPullFileTest(DeviceUtilsNewImplTest):
'/test/file/host/path')
-class DeviceUtilsReadFileTest(DeviceUtilsOldImplTest):
+class DeviceUtilsReadFileTest(DeviceUtilsNewImplTest):
def testReadFile_exists(self):
- with self.assertCallsSequence([
- ("adb -s 0123456789abcdef shell "
- "'cat \"/read/this/test/file\" 2>/dev/null'",
- 'this is a test file')]):
- self.assertEqual(['this is a test file'],
+ with self.assertCall(
+ self.call.adb.Shell('cat /read/this/test/file'),
+ 'this is a test file\r\n'):
+ self.assertEqual('this is a test file\n',
self.device.ReadFile('/read/this/test/file'))
def testReadFile_doesNotExist(self):
- with self.assertCalls(
- "adb -s 0123456789abcdef shell "
- "'cat \"/this/file/does.not.exist\" 2>/dev/null'",
- ''):
- self.device.ReadFile('/this/file/does.not.exist')
-
- def testReadFile_asRoot_withRoot(self):
- self.device.old_interface._privileged_command_runner = (
- self.device.old_interface.RunShellCommand)
- self.device.old_interface._protected_file_access_method_initialized = True
- with self.assertCallsSequence([
- ("adb -s 0123456789abcdef shell "
- "'cat \"/this/file/must.be.read.by.root\" 2> /dev/null'",
- 'this is a test file\nread by root')]):
- self.assertEqual(
- ['this is a test file', 'read by root'],
- self.device.ReadFile('/this/file/must.be.read.by.root',
- as_root=True))
+ 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.device.ReadFile('/this/file/does.not.exist')
- def testReadFile_asRoot_withSu(self):
- self.device.old_interface._privileged_command_runner = (
- self.device.old_interface.RunShellCommandWithSU)
- self.device.old_interface._protected_file_access_method_initialized = True
- with self.assertCallsSequence([
- ("adb -s 0123456789abcdef shell "
- "'su -c cat \"/this/file/can.be.read.with.su\" 2> /dev/null'",
- 'this is a test file\nread with su')]):
+ 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.assertEqual(
- ['this is a test file', 'read with su'],
+ 'this is a test file\nread with su\n',
self.device.ReadFile('/this/file/can.be.read.with.su',
as_root=True))
- def testReadFile_asRoot_rejected(self):
- self.device.old_interface._privileged_command_runner = None
- self.device.old_interface._protected_file_access_method_initialized = True
- with self.assertRaises(device_errors.CommandFailedError):
- self.device.ReadFile('/this/file/cannot.be.read.by.user',
- as_root=True)
-
class DeviceUtilsWriteFileTest(DeviceUtilsNewImplTest):
« no previous file with comments | « build/android/pylib/device/device_utils.py ('k') | build/android/pylib/flag_changer.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698