| 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 1533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1544 def testStr_returnsSerial(self): | 1544 def testStr_returnsSerial(self): |
| 1545 with self.assertCalls( | 1545 with self.assertCalls( |
| 1546 (self.call.adb.GetDeviceSerial(), '0123456789abcdef')): | 1546 (self.call.adb.GetDeviceSerial(), '0123456789abcdef')): |
| 1547 self.assertEqual('0123456789abcdef', str(self.device)) | 1547 self.assertEqual('0123456789abcdef', str(self.device)) |
| 1548 | 1548 |
| 1549 | 1549 |
| 1550 class DeviceUtilsParallelTest(mock_calls.TestCase): | 1550 class DeviceUtilsParallelTest(mock_calls.TestCase): |
| 1551 | 1551 |
| 1552 def testParallel_default(self): | 1552 def testParallel_default(self): |
| 1553 test_serials = ['0123456789abcdef', 'fedcba9876543210'] | 1553 test_serials = ['0123456789abcdef', 'fedcba9876543210'] |
| 1554 with self.assertCall( | 1554 with self.assertCalls( |
| 1555 mock.call.pylib.device.adb_wrapper.AdbWrapper.GetDevices(), | 1555 (mock.call.pylib.device.device_filter.DefaultFilters(), None), |
| 1556 [_AdbWrapperMock(serial) for serial in test_serials]): | 1556 (mock.call.pylib.device.adb_wrapper.AdbWrapper.Devices(filters=None), |
| 1557 [_AdbWrapperMock(serial) for serial in test_serials])): |
| 1557 parallel_devices = device_utils.DeviceUtils.parallel() | 1558 parallel_devices = device_utils.DeviceUtils.parallel() |
| 1558 for serial, device in zip(test_serials, parallel_devices.pGet(None)): | 1559 for serial, device in zip(test_serials, parallel_devices.pGet(None)): |
| 1559 self.assertTrue( | 1560 self.assertTrue( |
| 1560 isinstance(device, device_utils.DeviceUtils) | 1561 isinstance(device, device_utils.DeviceUtils) |
| 1561 and serial == str(device), | 1562 and serial == str(device), |
| 1562 'Expected a DeviceUtils object with serial %s' % serial) | 1563 'Expected a DeviceUtils object with serial %s' % serial) |
| 1563 | 1564 |
| 1564 def testParallel_noDevices(self): | 1565 def testParallel_noDevices(self): |
| 1565 with self.assertCall( | 1566 with self.assertCalls( |
| 1566 mock.call.pylib.device.adb_wrapper.AdbWrapper.GetDevices(), []): | 1567 (mock.call.pylib.device.device_filter.DefaultFilters(), None), |
| 1568 (mock.call.pylib.device.adb_wrapper.AdbWrapper.Devices(filters=None), |
| 1569 [])): |
| 1567 with self.assertRaises(device_errors.NoDevicesError): | 1570 with self.assertRaises(device_errors.NoDevicesError): |
| 1568 device_utils.DeviceUtils.parallel() | 1571 device_utils.DeviceUtils.parallel() |
| 1569 | 1572 |
| 1570 | 1573 |
| 1571 class DeviceUtilsClientCache(DeviceUtilsTest): | 1574 class DeviceUtilsClientCache(DeviceUtilsTest): |
| 1572 | 1575 |
| 1573 def testClientCache_twoCaches(self): | 1576 def testClientCache_twoCaches(self): |
| 1574 self.device._cache['test'] = 0 | 1577 self.device._cache['test'] = 0 |
| 1575 client_cache_one = self.device.GetClientCache('ClientOne') | 1578 client_cache_one = self.device.GetClientCache('ClientOne') |
| 1576 client_cache_one['test'] = 1 | 1579 client_cache_one['test'] = 1 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1591 self.assertEqual(client_cache_one, {'test': 1}) | 1594 self.assertEqual(client_cache_one, {'test': 1}) |
| 1592 self.assertEqual(client_cache_two, {'test': 1}) | 1595 self.assertEqual(client_cache_two, {'test': 1}) |
| 1593 self.device._ClearCache() | 1596 self.device._ClearCache() |
| 1594 self.assertEqual(client_cache_one, {}) | 1597 self.assertEqual(client_cache_one, {}) |
| 1595 self.assertEqual(client_cache_two, {}) | 1598 self.assertEqual(client_cache_two, {}) |
| 1596 | 1599 |
| 1597 if __name__ == '__main__': | 1600 if __name__ == '__main__': |
| 1598 logging.getLogger().setLevel(logging.DEBUG) | 1601 logging.getLogger().setLevel(logging.DEBUG) |
| 1599 unittest.main(verbosity=2) | 1602 unittest.main(verbosity=2) |
| 1600 | 1603 |
| OLD | NEW |