Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(727)

Side by Side Diff: build/android/pylib/device/device_utils_test.py

Issue 1101603002: [Android] Rework device filtering and add DeviceUtils.HealthyDevices. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: perezju comments Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 1529 matching lines...) Expand 10 before | Expand all | Expand 10 after
1540 1540
1541 1541
1542 class DeviceUtilsStrTest(DeviceUtilsTest): 1542 class DeviceUtilsStrTest(DeviceUtilsTest):
1543 1543
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):
1551
1552 def testParallel_default(self):
1553 test_serials = ['0123456789abcdef', 'fedcba9876543210']
1554 with self.assertCalls(
1555 (mock.call.pylib.device.device_filter.DefaultFilters(), None),
1556 (mock.call.pylib.device.adb_wrapper.AdbWrapper.Devices(filters=None),
1557 [_AdbWrapperMock(serial) for serial in test_serials])):
1558 parallel_devices = device_utils.DeviceUtils.parallel()
1559 for serial, device in zip(test_serials, parallel_devices.pGet(None)):
1560 self.assertTrue(
1561 isinstance(device, device_utils.DeviceUtils)
1562 and serial == str(device),
1563 'Expected a DeviceUtils object with serial %s' % serial)
1564
1565 def testParallel_noDevices(self):
1566 with self.assertCalls(
1567 (mock.call.pylib.device.device_filter.DefaultFilters(), None),
1568 (mock.call.pylib.device.adb_wrapper.AdbWrapper.Devices(filters=None),
1569 [])):
1570 with self.assertRaises(device_errors.NoDevicesError):
1571 device_utils.DeviceUtils.parallel()
1572
1573
1574 class DeviceUtilsClientCache(DeviceUtilsTest): 1550 class DeviceUtilsClientCache(DeviceUtilsTest):
1575 1551
1576 def testClientCache_twoCaches(self): 1552 def testClientCache_twoCaches(self):
1577 self.device._cache['test'] = 0 1553 self.device._cache['test'] = 0
1578 client_cache_one = self.device.GetClientCache('ClientOne') 1554 client_cache_one = self.device.GetClientCache('ClientOne')
1579 client_cache_one['test'] = 1 1555 client_cache_one['test'] = 1
1580 client_cache_two = self.device.GetClientCache('ClientTwo') 1556 client_cache_two = self.device.GetClientCache('ClientTwo')
1581 client_cache_two['test'] = 2 1557 client_cache_two['test'] = 2
1582 self.assertEqual(self.device._cache, {'test': 0}) 1558 self.assertEqual(self.device._cache, {'test': 0})
1583 self.assertEqual(client_cache_one, {'test': 1}) 1559 self.assertEqual(client_cache_one, {'test': 1})
1584 self.assertEqual(client_cache_two, {'test': 2}) 1560 self.assertEqual(client_cache_two, {'test': 2})
1585 self.device._ClearCache() 1561 self.device._ClearCache()
1586 self.assertEqual(self.device._cache, {}) 1562 self.assertEqual(self.device._cache, {})
1587 self.assertEqual(client_cache_one, {}) 1563 self.assertEqual(client_cache_one, {})
1588 self.assertEqual(client_cache_two, {}) 1564 self.assertEqual(client_cache_two, {})
1589 1565
1590 def testClientCache_multipleInstances(self): 1566 def testClientCache_multipleInstances(self):
1591 client_cache_one = self.device.GetClientCache('ClientOne') 1567 client_cache_one = self.device.GetClientCache('ClientOne')
1592 client_cache_one['test'] = 1 1568 client_cache_one['test'] = 1
1593 client_cache_two = self.device.GetClientCache('ClientOne') 1569 client_cache_two = self.device.GetClientCache('ClientOne')
1594 self.assertEqual(client_cache_one, {'test': 1}) 1570 self.assertEqual(client_cache_one, {'test': 1})
1595 self.assertEqual(client_cache_two, {'test': 1}) 1571 self.assertEqual(client_cache_two, {'test': 1})
1596 self.device._ClearCache() 1572 self.device._ClearCache()
1597 self.assertEqual(client_cache_one, {}) 1573 self.assertEqual(client_cache_one, {})
1598 self.assertEqual(client_cache_two, {}) 1574 self.assertEqual(client_cache_two, {})
1599 1575
1576
1577 class DeviceUtilsParallelTest(mock_calls.TestCase):
1578
1579 def testParallel_default(self):
1580 test_serials = ['0123456789abcdef', 'fedcba9876543210']
1581 with self.assertCall(
1582 mock.call.pylib.device.device_utils.DeviceUtils.HealthyDevices(),
1583 [device_utils.DeviceUtils(s) for s in test_serials]):
1584 parallel_devices = device_utils.DeviceUtils.parallel()
1585 for serial, device in zip(test_serials, parallel_devices.pGet(None)):
1586 self.assertTrue(isinstance(device, device_utils.DeviceUtils))
1587 self.assertEquals(serial, device.adb.GetDeviceSerial())
1588
1589 def testParallel_noDevices(self):
1590 with self.assertCall(
1591 mock.call.pylib.device.device_utils.DeviceUtils.HealthyDevices(), []):
1592 with self.assertRaises(device_errors.NoDevicesError):
1593 device_utils.DeviceUtils.parallel()
1594
1595
1596 class DeviceUtilsHealthyDevicesTest(mock_calls.TestCase):
1597
1598 def _createAdbWrapperMock(self, serial, is_ready=True):
1599 adb = _AdbWrapperMock(serial)
1600 adb.is_ready = is_ready
1601 return adb
1602
1603 def testHealthyDevices_default(self):
1604 test_serials = ['0123456789abcdef', 'fedcba9876543210']
1605 with self.assertCalls(
1606 (mock.call.pylib.device.device_blacklist.ReadBlacklist(), []),
1607 (mock.call.pylib.device.adb_wrapper.AdbWrapper.Devices(),
1608 [self._createAdbWrapperMock(s) for s in test_serials])):
1609 devices = device_utils.DeviceUtils.HealthyDevices()
1610 for serial, device in zip(test_serials, devices):
1611 self.assertTrue(isinstance(device, device_utils.DeviceUtils))
1612 self.assertEquals(serial, device.adb.GetDeviceSerial())
1613
1614 def testHealthyDevices_blacklisted(self):
1615 test_serials = ['0123456789abcdef', 'fedcba9876543210']
1616 with self.assertCalls(
1617 (mock.call.pylib.device.device_blacklist.ReadBlacklist(),
1618 ['fedcba9876543210']),
1619 (mock.call.pylib.device.adb_wrapper.AdbWrapper.Devices(),
1620 [self._createAdbWrapperMock(s) for s in test_serials])):
1621 devices = device_utils.DeviceUtils.HealthyDevices()
1622 self.assertEquals(1, len(devices))
1623 self.assertTrue(isinstance(devices[0], device_utils.DeviceUtils))
1624 self.assertEquals('0123456789abcdef', devices[0].adb.GetDeviceSerial())
1625
1626
1600 if __name__ == '__main__': 1627 if __name__ == '__main__':
1601 logging.getLogger().setLevel(logging.DEBUG) 1628 logging.getLogger().setLevel(logging.DEBUG)
1602 unittest.main(verbosity=2) 1629 unittest.main(verbosity=2)
1603 1630
OLDNEW
« no previous file with comments | « build/android/pylib/device/device_utils.py ('k') | build/android/pylib/local/device/local_device_environment.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698