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 1449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1460 @mock.patch('time.sleep', mock.Mock()) | 1460 @mock.patch('time.sleep', mock.Mock()) |
1461 def testSetCharging_disabled(self): | 1461 def testSetCharging_disabled(self): |
1462 with self.assertCalls( | 1462 with self.assertCalls( |
1463 (self.call.device.FileExists(mock.ANY), True), | 1463 (self.call.device.FileExists(mock.ANY), True), |
1464 (self.call.device.RunShellCommand(mock.ANY, check_return=True), []), | 1464 (self.call.device.RunShellCommand(mock.ANY, check_return=True), []), |
1465 (self.call.device.GetCharging(), True), | 1465 (self.call.device.GetCharging(), True), |
1466 (self.call.device.RunShellCommand(mock.ANY, check_return=True), []), | 1466 (self.call.device.RunShellCommand(mock.ANY, check_return=True), []), |
1467 (self.call.device.GetCharging(), False)): | 1467 (self.call.device.GetCharging(), False)): |
1468 self.device.SetCharging(False) | 1468 self.device.SetCharging(False) |
1469 | 1469 |
| 1470 def testSetChargingDefault_enabled(self): |
| 1471 with self.assertCalls( |
| 1472 (self.call.device.FileExists(mock.ANY), False), |
| 1473 (self.call.device.FileExists(mock.ANY), False), |
| 1474 (self.call.device.RunShellCommand(mock.ANY, check_return=True), []), |
| 1475 (self.call.device.GetCharging(), False), |
| 1476 (self.call.device.RunShellCommand(mock.ANY, check_return=True), []), |
| 1477 (self.call.device.GetCharging(), True)): |
| 1478 self.device.SetCharging(True) |
| 1479 self.assertEqual( |
| 1480 'dumpsys battery reset', |
| 1481 self.device._cache['charging_config']['enable_command']) |
| 1482 |
| 1483 def testSetChargingDefault_disabled(self): |
| 1484 with self.assertCalls( |
| 1485 (self.call.device.FileExists(mock.ANY), False), |
| 1486 (self.call.device.FileExists(mock.ANY), False), |
| 1487 (self.call.device.RunShellCommand(mock.ANY, check_return=True), []), |
| 1488 (self.call.device.GetCharging(), True), |
| 1489 (self.call.device.RunShellCommand(mock.ANY, check_return=True), []), |
| 1490 (self.call.device.GetCharging(), False)): |
| 1491 self.device.SetCharging(False) |
| 1492 self.assertEqual( |
| 1493 'dumpsys battery set usb 0', |
| 1494 self.device._cache['charging_config']['disable_command']) |
1470 | 1495 |
1471 | 1496 |
1472 class DeviceUtilsStrTest(DeviceUtilsTest): | 1497 class DeviceUtilsStrTest(DeviceUtilsTest): |
1473 | 1498 |
1474 def testStr_returnsSerial(self): | 1499 def testStr_returnsSerial(self): |
1475 with self.assertCalls( | 1500 with self.assertCalls( |
1476 (self.call.adb.GetDeviceSerial(), '0123456789abcdef')): | 1501 (self.call.adb.GetDeviceSerial(), '0123456789abcdef')): |
1477 self.assertEqual('0123456789abcdef', str(self.device)) | 1502 self.assertEqual('0123456789abcdef', str(self.device)) |
1478 | 1503 |
1479 | 1504 |
(...skipping 15 matching lines...) Expand all Loading... |
1495 with self.assertCall( | 1520 with self.assertCall( |
1496 mock.call.pylib.device.adb_wrapper.AdbWrapper.GetDevices(), []): | 1521 mock.call.pylib.device.adb_wrapper.AdbWrapper.GetDevices(), []): |
1497 with self.assertRaises(device_errors.NoDevicesError): | 1522 with self.assertRaises(device_errors.NoDevicesError): |
1498 device_utils.DeviceUtils.parallel() | 1523 device_utils.DeviceUtils.parallel() |
1499 | 1524 |
1500 | 1525 |
1501 if __name__ == '__main__': | 1526 if __name__ == '__main__': |
1502 logging.getLogger().setLevel(logging.DEBUG) | 1527 logging.getLogger().setLevel(logging.DEBUG) |
1503 unittest.main(verbosity=2) | 1528 unittest.main(verbosity=2) |
1504 | 1529 |
OLD | NEW |