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