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

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

Issue 1290173003: [Android] Reland of Remove android_commands and android_testrunner. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed: removed references from content/telemetry.isolate and TELEMETRY_DEPS 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
23 from pylib import cmd_helper 22 from pylib import cmd_helper
24 from pylib import constants 23 from pylib import constants
25 from pylib import device_signal 24 from pylib import device_signal
26 from pylib.device import adb_wrapper 25 from pylib.device import adb_wrapper
27 from pylib.device import device_errors 26 from pylib.device import device_errors
28 from pylib.device import device_utils 27 from pylib.device import device_utils
29 from pylib.device import intent 28 from pylib.device import intent
30 from pylib.sdk import split_select 29 from pylib.sdk import split_select
31 from pylib.utils import mock_calls 30 from pylib.utils import mock_calls
32 31
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
38 sys.path.append(os.path.join( 32 sys.path.append(os.path.join(
39 constants.DIR_SOURCE_ROOT, 'third_party', 'pymock')) 33 constants.DIR_SOURCE_ROOT, 'third_party', 'pymock'))
40 import mock # pylint: disable=F0401 34 import mock # pylint: disable=F0401
41 35
42 36
43 class DeviceUtilsInitTest(unittest.TestCase): 37 class DeviceUtilsInitTest(unittest.TestCase):
44 38
45 def testInitWithStr(self): 39 def testInitWithStr(self):
46 serial_as_str = str('0123456789abcdef') 40 serial_as_str = str('0123456789abcdef')
47 d = device_utils.DeviceUtils('0123456789abcdef') 41 d = device_utils.DeviceUtils('0123456789abcdef')
48 self.assertEqual(serial_as_str, d.adb.GetDeviceSerial()) 42 self.assertEqual(serial_as_str, d.adb.GetDeviceSerial())
49 43
50 def testInitWithUnicode(self): 44 def testInitWithUnicode(self):
51 serial_as_unicode = unicode('fedcba9876543210') 45 serial_as_unicode = unicode('fedcba9876543210')
52 d = device_utils.DeviceUtils(serial_as_unicode) 46 d = device_utils.DeviceUtils(serial_as_unicode)
53 self.assertEqual(serial_as_unicode, d.adb.GetDeviceSerial()) 47 self.assertEqual(serial_as_unicode, d.adb.GetDeviceSerial())
54 48
55 def testInitWithAdbWrapper(self): 49 def testInitWithAdbWrapper(self):
56 serial = '123456789abcdef0' 50 serial = '123456789abcdef0'
57 a = adb_wrapper.AdbWrapper(serial) 51 a = adb_wrapper.AdbWrapper(serial)
58 d = device_utils.DeviceUtils(a) 52 d = device_utils.DeviceUtils(a)
59 self.assertEqual(serial, d.adb.GetDeviceSerial()) 53 self.assertEqual(serial, d.adb.GetDeviceSerial())
60 54
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
67 def testInitWithMissing_fails(self): 55 def testInitWithMissing_fails(self):
68 with self.assertRaises(ValueError): 56 with self.assertRaises(ValueError):
69 device_utils.DeviceUtils(None) 57 device_utils.DeviceUtils(None)
70 with self.assertRaises(ValueError): 58 with self.assertRaises(ValueError):
71 device_utils.DeviceUtils('') 59 device_utils.DeviceUtils('')
72 60
73 61
74 class DeviceUtilsGetAVDsTest(mock_calls.TestCase): 62 class DeviceUtilsGetAVDsTest(mock_calls.TestCase):
75 63
76 def testGetAVDs(self): 64 def testGetAVDs(self):
(...skipping 1864 matching lines...) Expand 10 before | Expand all | Expand 10 after
1941 self.call.device.WriteFile(mock.ANY, mock.ANY), 1929 self.call.device.WriteFile(mock.ANY, mock.ANY),
1942 (self.call.device.RunShellCommand( 1930 (self.call.device.RunShellCommand(
1943 ['source', mock_temp_file ], as_root=True)), 1931 ['source', mock_temp_file ], as_root=True)),
1944 self.call.adb.WaitForDevice()): 1932 self.call.adb.WaitForDevice()):
1945 self.device.RestartAdbd() 1933 self.device.RestartAdbd()
1946 1934
1947 1935
1948 if __name__ == '__main__': 1936 if __name__ == '__main__':
1949 logging.getLogger().setLevel(logging.DEBUG) 1937 logging.getLogger().setLevel(logging.DEBUG)
1950 unittest.main(verbosity=2) 1938 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