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

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

Issue 1288993002: Revert of [Android] Remove android_commands and android_testrunner. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
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
11 # pylint: disable=W0212 11 # pylint: disable=W0212
12 # pylint: disable=W0613 12 # pylint: disable=W0613
13 13
14 import collections 14 import collections
15 import datetime 15 import datetime
16 import logging 16 import logging
17 import os 17 import os
18 import re 18 import re
19 import sys 19 import sys
20 import unittest 20 import unittest
21 21
22 from pylib import android_commands
22 from pylib import cmd_helper 23 from pylib import cmd_helper
23 from pylib import constants 24 from pylib import constants
24 from pylib import device_signal 25 from pylib import device_signal
25 from pylib.device import adb_wrapper 26 from pylib.device import adb_wrapper
26 from pylib.device import device_errors 27 from pylib.device import device_errors
27 from pylib.device import device_utils 28 from pylib.device import device_utils
28 from pylib.device import intent 29 from pylib.device import intent
29 from pylib.sdk import split_select 30 from pylib.sdk import split_select
30 from pylib.utils import mock_calls 31 from pylib.utils import mock_calls
31 32
33 # RunCommand from third_party/android_testrunner/run_command.py is mocked
34 # below, so its path needs to be in sys.path.
35 sys.path.append(os.path.join(
36 constants.DIR_SOURCE_ROOT, 'third_party', 'android_testrunner'))
37
32 sys.path.append(os.path.join( 38 sys.path.append(os.path.join(
33 constants.DIR_SOURCE_ROOT, 'third_party', 'pymock')) 39 constants.DIR_SOURCE_ROOT, 'third_party', 'pymock'))
34 import mock # pylint: disable=F0401 40 import mock # pylint: disable=F0401
35 41
36 42
37 class DeviceUtilsInitTest(unittest.TestCase): 43 class DeviceUtilsInitTest(unittest.TestCase):
38 44
39 def testInitWithStr(self): 45 def testInitWithStr(self):
40 serial_as_str = str('0123456789abcdef') 46 serial_as_str = str('0123456789abcdef')
41 d = device_utils.DeviceUtils('0123456789abcdef') 47 d = device_utils.DeviceUtils('0123456789abcdef')
42 self.assertEqual(serial_as_str, d.adb.GetDeviceSerial()) 48 self.assertEqual(serial_as_str, d.adb.GetDeviceSerial())
43 49
44 def testInitWithUnicode(self): 50 def testInitWithUnicode(self):
45 serial_as_unicode = unicode('fedcba9876543210') 51 serial_as_unicode = unicode('fedcba9876543210')
46 d = device_utils.DeviceUtils(serial_as_unicode) 52 d = device_utils.DeviceUtils(serial_as_unicode)
47 self.assertEqual(serial_as_unicode, d.adb.GetDeviceSerial()) 53 self.assertEqual(serial_as_unicode, d.adb.GetDeviceSerial())
48 54
49 def testInitWithAdbWrapper(self): 55 def testInitWithAdbWrapper(self):
50 serial = '123456789abcdef0' 56 serial = '123456789abcdef0'
51 a = adb_wrapper.AdbWrapper(serial) 57 a = adb_wrapper.AdbWrapper(serial)
52 d = device_utils.DeviceUtils(a) 58 d = device_utils.DeviceUtils(a)
53 self.assertEqual(serial, d.adb.GetDeviceSerial()) 59 self.assertEqual(serial, d.adb.GetDeviceSerial())
54 60
61 def testInitWithAndroidCommands(self):
62 serial = '0fedcba987654321'
63 a = android_commands.AndroidCommands(device=serial)
64 d = device_utils.DeviceUtils(a)
65 self.assertEqual(serial, d.adb.GetDeviceSerial())
66
55 def testInitWithMissing_fails(self): 67 def testInitWithMissing_fails(self):
56 with self.assertRaises(ValueError): 68 with self.assertRaises(ValueError):
57 device_utils.DeviceUtils(None) 69 device_utils.DeviceUtils(None)
58 with self.assertRaises(ValueError): 70 with self.assertRaises(ValueError):
59 device_utils.DeviceUtils('') 71 device_utils.DeviceUtils('')
60 72
61 73
62 class DeviceUtilsGetAVDsTest(mock_calls.TestCase): 74 class DeviceUtilsGetAVDsTest(mock_calls.TestCase):
63 75
64 def testGetAVDs(self): 76 def testGetAVDs(self):
(...skipping 1864 matching lines...) Expand 10 before | Expand all | Expand 10 after
1929 self.call.device.WriteFile(mock.ANY, mock.ANY), 1941 self.call.device.WriteFile(mock.ANY, mock.ANY),
1930 (self.call.device.RunShellCommand( 1942 (self.call.device.RunShellCommand(
1931 ['source', mock_temp_file ], as_root=True)), 1943 ['source', mock_temp_file ], as_root=True)),
1932 self.call.adb.WaitForDevice()): 1944 self.call.adb.WaitForDevice()):
1933 self.device.RestartAdbd() 1945 self.device.RestartAdbd()
1934 1946
1935 1947
1936 if __name__ == '__main__': 1948 if __name__ == '__main__':
1937 logging.getLogger().setLevel(logging.DEBUG) 1949 logging.getLogger().setLevel(logging.DEBUG)
1938 unittest.main(verbosity=2) 1950 unittest.main(verbosity=2)
OLDNEW
« no previous file with comments | « build/android/pylib/device/device_utils.py ('k') | build/android/pylib/gtest/test_package_apk.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698