| 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 1474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1485 def testStr_returnsSerial(self): | 1485 def testStr_returnsSerial(self): |
| 1486 with self.assertCalls( | 1486 with self.assertCalls( |
| 1487 (self.call.adb.GetDeviceSerial(), '0123456789abcdef')): | 1487 (self.call.adb.GetDeviceSerial(), '0123456789abcdef')): |
| 1488 self.assertEqual('0123456789abcdef', str(self.device)) | 1488 self.assertEqual('0123456789abcdef', str(self.device)) |
| 1489 | 1489 |
| 1490 | 1490 |
| 1491 class DeviceUtilsParallelTest(mock_calls.TestCase): | 1491 class DeviceUtilsParallelTest(mock_calls.TestCase): |
| 1492 | 1492 |
| 1493 def testParallel_default(self): | 1493 def testParallel_default(self): |
| 1494 test_serials = ['0123456789abcdef', 'fedcba9876543210'] | 1494 test_serials = ['0123456789abcdef', 'fedcba9876543210'] |
| 1495 with self.assertCalls( | 1495 with self.assertCall( |
| 1496 (mock.call.pylib.device.device_filter.DefaultFilters(), None), | 1496 mock.call.pylib.device.adb_wrapper.AdbWrapper.GetDevices(), |
| 1497 (mock.call.pylib.device.adb_wrapper.AdbWrapper.Devices(filters=None), | 1497 [_AdbWrapperMock(serial) for serial in test_serials]): |
| 1498 [_AdbWrapperMock(serial) for serial in test_serials])): | |
| 1499 parallel_devices = device_utils.DeviceUtils.parallel() | 1498 parallel_devices = device_utils.DeviceUtils.parallel() |
| 1500 for serial, device in zip(test_serials, parallel_devices.pGet(None)): | 1499 for serial, device in zip(test_serials, parallel_devices.pGet(None)): |
| 1501 self.assertTrue( | 1500 self.assertTrue( |
| 1502 isinstance(device, device_utils.DeviceUtils) | 1501 isinstance(device, device_utils.DeviceUtils) |
| 1503 and serial == str(device), | 1502 and serial == str(device), |
| 1504 'Expected a DeviceUtils object with serial %s' % serial) | 1503 'Expected a DeviceUtils object with serial %s' % serial) |
| 1505 | 1504 |
| 1506 def testParallel_noDevices(self): | 1505 def testParallel_noDevices(self): |
| 1507 with self.assertCalls( | 1506 with self.assertCall( |
| 1508 (mock.call.pylib.device.device_filter.DefaultFilters(), None), | 1507 mock.call.pylib.device.adb_wrapper.AdbWrapper.GetDevices(), []): |
| 1509 (mock.call.pylib.device.adb_wrapper.AdbWrapper.Devices(filters=None), | |
| 1510 [])): | |
| 1511 with self.assertRaises(device_errors.NoDevicesError): | 1508 with self.assertRaises(device_errors.NoDevicesError): |
| 1512 device_utils.DeviceUtils.parallel() | 1509 device_utils.DeviceUtils.parallel() |
| 1513 | 1510 |
| 1514 | 1511 |
| 1515 class DeviceUtilsClientCache(DeviceUtilsTest): | 1512 class DeviceUtilsClientCache(DeviceUtilsTest): |
| 1516 | 1513 |
| 1517 def testClientCache_twoCaches(self): | 1514 def testClientCache_twoCaches(self): |
| 1518 self.device._cache['test'] = 0 | 1515 self.device._cache['test'] = 0 |
| 1519 client_cache_one = self.device.GetClientCache('ClientOne') | 1516 client_cache_one = self.device.GetClientCache('ClientOne') |
| 1520 client_cache_one['test'] = 1 | 1517 client_cache_one['test'] = 1 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1535 self.assertEqual(client_cache_one, {'test': 1}) | 1532 self.assertEqual(client_cache_one, {'test': 1}) |
| 1536 self.assertEqual(client_cache_two, {'test': 1}) | 1533 self.assertEqual(client_cache_two, {'test': 1}) |
| 1537 self.device._ClearCache() | 1534 self.device._ClearCache() |
| 1538 self.assertEqual(client_cache_one, {}) | 1535 self.assertEqual(client_cache_one, {}) |
| 1539 self.assertEqual(client_cache_two, {}) | 1536 self.assertEqual(client_cache_two, {}) |
| 1540 | 1537 |
| 1541 if __name__ == '__main__': | 1538 if __name__ == '__main__': |
| 1542 logging.getLogger().setLevel(logging.DEBUG) | 1539 logging.getLogger().setLevel(logging.DEBUG) |
| 1543 unittest.main(verbosity=2) | 1540 unittest.main(verbosity=2) |
| 1544 | 1541 |
| OLD | NEW |