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 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 |
(...skipping 1519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1530 def testSetCharging_disabled(self): | 1530 def testSetCharging_disabled(self): |
1531 with self.assertCalls( | 1531 with self.assertCalls( |
1532 (self.call.device.FileExists(mock.ANY), True), | 1532 (self.call.device.FileExists(mock.ANY), True), |
1533 (self.call.device.RunShellCommand(mock.ANY, check_return=True), []), | 1533 (self.call.device.RunShellCommand(mock.ANY, check_return=True), []), |
1534 (self.call.device.GetCharging(), True), | 1534 (self.call.device.GetCharging(), True), |
1535 (self.call.device.RunShellCommand(mock.ANY, check_return=True), []), | 1535 (self.call.device.RunShellCommand(mock.ANY, check_return=True), []), |
1536 (self.call.device.GetCharging(), False)): | 1536 (self.call.device.GetCharging(), False)): |
1537 self.device.SetCharging(False) | 1537 self.device.SetCharging(False) |
1538 | 1538 |
1539 | 1539 |
| 1540 class DeviceUtilsSetBatteryMeasurementTest(DeviceUtilsTest): |
| 1541 |
| 1542 def testBatteryMeasurement(self): |
| 1543 with self.assertCalls( |
| 1544 (self.call.device.RunShellCommand( |
| 1545 mock.ANY, retries=0, single_line=True, |
| 1546 timeout=10, check_return=True), '22'), |
| 1547 (self.call.device.RunShellCommand( |
| 1548 ['dumpsys', 'batterystats', '--reset'], check_return=True), []), |
| 1549 (self.call.device.RunShellCommand( |
| 1550 ['dumpsys', 'batterystats', '--charged', '--checkin'], |
| 1551 check_return=True), []), |
| 1552 (self.call.device.RunShellCommand( |
| 1553 ['dumpsys', 'battery', 'set', 'usb', '0'], check_return=True), []), |
| 1554 (self.call.device.GetCharging(), False), |
| 1555 (self.call.device.RunShellCommand( |
| 1556 ['dumpsys', 'battery', 'set', 'usb', '1'], check_return=True), []), |
| 1557 (self.call.device.RunShellCommand( |
| 1558 ['dumpsys', 'battery', 'reset'], check_return=True), []), |
| 1559 (self.call.device.GetCharging(), True)): |
| 1560 with self.device.BatteryMeasurement(): |
| 1561 pass |
| 1562 |
1540 | 1563 |
1541 class DeviceUtilsStrTest(DeviceUtilsTest): | 1564 class DeviceUtilsStrTest(DeviceUtilsTest): |
1542 | 1565 |
1543 def testStr_returnsSerial(self): | 1566 def testStr_returnsSerial(self): |
1544 with self.assertCalls( | 1567 with self.assertCalls( |
1545 (self.call.adb.GetDeviceSerial(), '0123456789abcdef')): | 1568 (self.call.adb.GetDeviceSerial(), '0123456789abcdef')): |
1546 self.assertEqual('0123456789abcdef', str(self.device)) | 1569 self.assertEqual('0123456789abcdef', str(self.device)) |
1547 | 1570 |
1548 | 1571 |
1549 class DeviceUtilsParallelTest(mock_calls.TestCase): | 1572 class DeviceUtilsParallelTest(mock_calls.TestCase): |
(...skipping 14 matching lines...) Expand all Loading... |
1564 with self.assertCall( | 1587 with self.assertCall( |
1565 mock.call.pylib.device.adb_wrapper.AdbWrapper.GetDevices(), []): | 1588 mock.call.pylib.device.adb_wrapper.AdbWrapper.GetDevices(), []): |
1566 with self.assertRaises(device_errors.NoDevicesError): | 1589 with self.assertRaises(device_errors.NoDevicesError): |
1567 device_utils.DeviceUtils.parallel() | 1590 device_utils.DeviceUtils.parallel() |
1568 | 1591 |
1569 | 1592 |
1570 if __name__ == '__main__': | 1593 if __name__ == '__main__': |
1571 logging.getLogger().setLevel(logging.DEBUG) | 1594 logging.getLogger().setLevel(logging.DEBUG) |
1572 unittest.main(verbosity=2) | 1595 unittest.main(verbosity=2) |
1573 | 1596 |
OLD | NEW |