Chromium Code Reviews| 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 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 208 def assertNoAdbCalls(self): | 208 def assertNoAdbCalls(self): |
| 209 return type(self).AndroidCommandsCalls(self, [], str.__eq__) | 209 return type(self).AndroidCommandsCalls(self, [], str.__eq__) |
| 210 | 210 |
| 211 def assertCalls(self, cmd, ret, comp=str.__eq__): | 211 def assertCalls(self, cmd, ret, comp=str.__eq__): |
| 212 return type(self).AndroidCommandsCalls(self, [(cmd, ret)], comp) | 212 return type(self).AndroidCommandsCalls(self, [(cmd, ret)], comp) |
| 213 | 213 |
| 214 def assertCallsSequence(self, cmd_ret, comp=str.__eq__): | 214 def assertCallsSequence(self, cmd_ret, comp=str.__eq__): |
| 215 return type(self).AndroidCommandsCalls(self, cmd_ret, comp) | 215 return type(self).AndroidCommandsCalls(self, cmd_ret, comp) |
| 216 | 216 |
| 217 def setUp(self): | 217 def setUp(self): |
| 218 self.device = device_utils.DeviceUtils( | 218 with mock.patch('pylib.constants.GetAdbPath', |
|
jbudorick
2014/11/19 19:58:46
why not patch it in setUp and unpatch it in tearDo
| |
| 219 '0123456789abcdef', default_timeout=1, default_retries=0) | 219 mock.Mock(return_value='adb')): |
| 220 self.device = device_utils.DeviceUtils( | |
| 221 '0123456789abcdef', default_timeout=1, default_retries=0) | |
| 220 | 222 |
| 221 | 223 |
| 222 class DeviceUtilsNewImplTest(mock_calls.TestCase): | 224 class DeviceUtilsNewImplTest(mock_calls.TestCase): |
| 223 | 225 |
| 224 def setUp(self): | 226 def setUp(self): |
| 225 test_serial = '0123456789abcdef' | 227 test_serial = '0123456789abcdef' |
| 226 self.adb = mock.Mock(spec=adb_wrapper.AdbWrapper) | 228 self.adb = mock.Mock(spec=adb_wrapper.AdbWrapper) |
| 227 self.adb.__str__ = mock.Mock(return_value=test_serial) | 229 self.adb.__str__ = mock.Mock(return_value=test_serial) |
| 228 self.adb.GetDeviceSerial.return_value = test_serial | 230 self.adb.GetDeviceSerial.return_value = test_serial |
| 229 self.device = device_utils.DeviceUtils( | 231 self.device = device_utils.DeviceUtils( |
| (...skipping 1371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1601 self.assertEqual({}, self.device.GetMemoryUsageForPid(4321)) | 1603 self.assertEqual({}, self.device.GetMemoryUsageForPid(4321)) |
| 1602 | 1604 |
| 1603 | 1605 |
| 1604 class DeviceUtilsStrTest(DeviceUtilsOldImplTest): | 1606 class DeviceUtilsStrTest(DeviceUtilsOldImplTest): |
| 1605 | 1607 |
| 1606 def testStr_noAdbCalls(self): | 1608 def testStr_noAdbCalls(self): |
| 1607 with self.assertNoAdbCalls(): | 1609 with self.assertNoAdbCalls(): |
| 1608 self.assertEqual('0123456789abcdef', str(self.device)) | 1610 self.assertEqual('0123456789abcdef', str(self.device)) |
| 1609 | 1611 |
| 1610 def testStr_noSerial(self): | 1612 def testStr_noSerial(self): |
| 1611 self.device = device_utils.DeviceUtils(None) | 1613 with mock.patch('pylib.constants.GetAdbPath', |
| 1614 mock.Mock(return_value='adb')): | |
| 1615 self.device = device_utils.DeviceUtils(None) | |
| 1612 with self.assertCalls('adb get-serialno', '0123456789abcdef'): | 1616 with self.assertCalls('adb get-serialno', '0123456789abcdef'): |
| 1613 self.assertEqual('0123456789abcdef', str(self.device)) | 1617 self.assertEqual('0123456789abcdef', str(self.device)) |
| 1614 | 1618 |
| 1615 def testStr_noSerial_noDevices(self): | 1619 def testStr_noSerial_noDevices(self): |
| 1616 self.device = device_utils.DeviceUtils(None) | 1620 with mock.patch('pylib.constants.GetAdbPath', |
| 1621 mock.Mock(return_value='adb')): | |
| 1622 self.device = device_utils.DeviceUtils(None) | |
| 1617 with self.assertCalls('adb get-serialno', 'unknown'), ( | 1623 with self.assertCalls('adb get-serialno', 'unknown'), ( |
| 1618 self.assertRaises(device_errors.NoDevicesError)): | 1624 self.assertRaises(device_errors.NoDevicesError)): |
| 1619 str(self.device) | 1625 str(self.device) |
| 1620 | 1626 |
| 1621 | 1627 |
| 1622 if __name__ == '__main__': | 1628 if __name__ == '__main__': |
| 1623 logging.getLogger().setLevel(logging.DEBUG) | 1629 logging.getLogger().setLevel(logging.DEBUG) |
| 1624 unittest.main(verbosity=2) | 1630 unittest.main(verbosity=2) |
| 1625 | 1631 |
| OLD | NEW |