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

Side by Side Diff: devil/devil/android/sdk/adb_wrapper_test.py

Issue 3002993002: devil: Raise DeviceUnreachableError on cmd output "waiting for device" (Closed)
Patch Set: cmnt Created 3 years, 4 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 unified diff | Download patch
« no previous file with comments | « devil/devil/android/sdk/adb_wrapper.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2017 The Chromium Authors. All rights reserved. 2 # Copyright 2017 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 some APIs with conditional logic in adb_wrapper.py 7 Unit tests for some APIs with conditional logic in adb_wrapper.py
8 """ 8 """
9 9
10 import unittest 10 import unittest
11 11
12 from devil import devil_env 12 from devil import devil_env
13 from devil.android import device_errors 13 from devil.android import device_errors
14 from devil.android.sdk import adb_wrapper 14 from devil.android.sdk import adb_wrapper
15 15
16 with devil_env.SysPath(devil_env.PYMOCK_PATH): 16 with devil_env.SysPath(devil_env.PYMOCK_PATH):
17 import mock # pylint: disable=import-error 17 import mock # pylint: disable=import-error
18 18
19 19
20 class AdbWrapperTest(unittest.TestCase): 20 class AdbWrapperTest(unittest.TestCase):
21 def setUp(self): 21 def setUp(self):
22 self.adb = adb_wrapper.AdbWrapper('ABC12345678') 22 self.device_serial = 'ABC12345678'
23 self.adb = adb_wrapper.AdbWrapper(self.device_serial)
23 24
24 def _MockRunDeviceAdbCmd(self, return_value): 25 def _MockRunDeviceAdbCmd(self, return_value):
25 return mock.patch.object( 26 return mock.patch.object(
26 self.adb, 27 self.adb,
27 '_RunDeviceAdbCmd', 28 '_RunDeviceAdbCmd',
28 mock.Mock(side_effect=None, return_value=return_value)) 29 mock.Mock(side_effect=None, return_value=return_value))
29 30
30 def testDisableVerityWhenDisabled(self): 31 def testDisableVerityWhenDisabled(self):
31 with self._MockRunDeviceAdbCmd('Verity already disabled on /system'): 32 with self._MockRunDeviceAdbCmd('Verity already disabled on /system'):
32 self.adb.DisableVerity() 33 self.adb.DisableVerity()
(...skipping 17 matching lines...) Expand all
50 def testFailEnableVerity(self): 51 def testFailEnableVerity(self):
51 with self._MockRunDeviceAdbCmd('error: closed'): 52 with self._MockRunDeviceAdbCmd('error: closed'):
52 self.assertRaises( 53 self.assertRaises(
53 device_errors.AdbCommandFailedError, self.adb.EnableVerity) 54 device_errors.AdbCommandFailedError, self.adb.EnableVerity)
54 55
55 def testFailDisableVerity(self): 56 def testFailDisableVerity(self):
56 with self._MockRunDeviceAdbCmd('error: closed'): 57 with self._MockRunDeviceAdbCmd('error: closed'):
57 self.assertRaises( 58 self.assertRaises(
58 device_errors.AdbCommandFailedError, self.adb.DisableVerity) 59 device_errors.AdbCommandFailedError, self.adb.DisableVerity)
59 60
61 @mock.patch('devil.utils.cmd_helper.GetCmdStatusAndOutputWithTimeout')
62 def testDeviceUnreachable(self, get_cmd_mock):
63 get_cmd_mock.return_value = (
64 1, "error: device '%s' not found" % self.device_serial)
65 self.assertRaises(
66 device_errors.DeviceUnreachableError, self.adb.Shell, '/bin/true')
67
68 @mock.patch('devil.utils.cmd_helper.GetCmdStatusAndOutputWithTimeout')
69 def testWaitingForDevice(self, get_cmd_mock):
70 get_cmd_mock.return_value = (1, '- waiting for device - ')
71 self.assertRaises(
72 device_errors.DeviceUnreachableError, self.adb.Shell, '/bin/true')
OLDNEW
« no previous file with comments | « devil/devil/android/sdk/adb_wrapper.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698