OLD | NEW |
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 battery_utils.py | 7 Unit tests for the contents of battery_utils.py |
8 """ | 8 """ |
9 | 9 |
10 # pylint: disable=W0613 | 10 # pylint: disable=W0613 |
11 | 11 |
12 import logging | 12 import logging |
13 import os | 13 import os |
14 import sys | 14 import sys |
15 import unittest | 15 import unittest |
16 | 16 |
| 17 from pylib import android_commands |
17 from pylib import constants | 18 from pylib import constants |
18 from pylib.device import battery_utils | 19 from pylib.device import battery_utils |
19 from pylib.device import device_errors | 20 from pylib.device import device_errors |
20 from pylib.device import device_utils | 21 from pylib.device import device_utils |
21 from pylib.device import device_utils_test | 22 from pylib.device import device_utils_test |
22 from pylib.utils import mock_calls | 23 from pylib.utils import mock_calls |
23 | 24 |
24 # RunCommand from third_party/android_testrunner/run_command.py is mocked | 25 # RunCommand from third_party/android_testrunner/run_command.py is mocked |
25 # below, so its path needs to be in sys.path. | 26 # below, so its path needs to be in sys.path. |
26 sys.path.append(os.path.join( | 27 sys.path.append(os.path.join( |
(...skipping 27 matching lines...) Expand all Loading... |
54 self.adb, default_timeout=10, default_retries=0) | 55 self.adb, default_timeout=10, default_retries=0) |
55 self.watchMethodCalls(self.call.adb, ignore=['GetDeviceSerial']) | 56 self.watchMethodCalls(self.call.adb, ignore=['GetDeviceSerial']) |
56 self.battery = battery_utils.BatteryUtils( | 57 self.battery = battery_utils.BatteryUtils( |
57 self.device, default_timeout=10, default_retries=0) | 58 self.device, default_timeout=10, default_retries=0) |
58 | 59 |
59 | 60 |
60 class BatteryUtilsInitTest(unittest.TestCase): | 61 class BatteryUtilsInitTest(unittest.TestCase): |
61 | 62 |
62 def testInitWithDeviceUtil(self): | 63 def testInitWithDeviceUtil(self): |
63 serial = '0fedcba987654321' | 64 serial = '0fedcba987654321' |
64 d = device_utils.DeviceUtils(serial) | 65 a = android_commands.AndroidCommands(device=serial) |
| 66 d = device_utils.DeviceUtils(a) |
65 b = battery_utils.BatteryUtils(d) | 67 b = battery_utils.BatteryUtils(d) |
66 self.assertEqual(d, b._device) | 68 self.assertEqual(d, b._device) |
67 | 69 |
68 def testInitWithMissing_fails(self): | 70 def testInitWithMissing_fails(self): |
69 with self.assertRaises(TypeError): | 71 with self.assertRaises(TypeError): |
70 battery_utils.BatteryUtils(None) | 72 battery_utils.BatteryUtils(None) |
71 with self.assertRaises(TypeError): | 73 with self.assertRaises(TypeError): |
72 battery_utils.BatteryUtils('') | 74 battery_utils.BatteryUtils('') |
73 | 75 |
74 | 76 |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 _DUMPSYS_OUTPUT), | 307 _DUMPSYS_OUTPUT), |
306 (self.call.device.ReadFile('/proc/uid_stat/1000/tcp_snd'), 1), | 308 (self.call.device.ReadFile('/proc/uid_stat/1000/tcp_snd'), 1), |
307 (self.call.device.ReadFile('/proc/uid_stat/1000/tcp_rcv'), 2)): | 309 (self.call.device.ReadFile('/proc/uid_stat/1000/tcp_rcv'), 2)): |
308 self.battery._cache.clear() | 310 self.battery._cache.clear() |
309 self.assertEqual(self.battery.GetNetworkData('test_package1'), (1,2)) | 311 self.assertEqual(self.battery.GetNetworkData('test_package1'), (1,2)) |
310 | 312 |
311 | 313 |
312 if __name__ == '__main__': | 314 if __name__ == '__main__': |
313 logging.getLogger().setLevel(logging.DEBUG) | 315 logging.getLogger().setLevel(logging.DEBUG) |
314 unittest.main(verbosity=2) | 316 unittest.main(verbosity=2) |
OLD | NEW |