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