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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 d = device_utils.DeviceUtils(a) | 62 d = device_utils.DeviceUtils(a) |
63 self.assertEqual(serial, d.adb.GetDeviceSerial()) | 63 self.assertEqual(serial, d.adb.GetDeviceSerial()) |
64 | 64 |
65 def testInitWithMissing_fails(self): | 65 def testInitWithMissing_fails(self): |
66 with self.assertRaises(ValueError): | 66 with self.assertRaises(ValueError): |
67 device_utils.DeviceUtils(None) | 67 device_utils.DeviceUtils(None) |
68 with self.assertRaises(ValueError): | 68 with self.assertRaises(ValueError): |
69 device_utils.DeviceUtils('') | 69 device_utils.DeviceUtils('') |
70 | 70 |
71 | 71 |
| 72 class DeviceUtilsRestartServerTest(mock_calls.TestCase): |
| 73 |
| 74 @mock.patch('time.sleep', mock.Mock()) |
| 75 def testRestartServer_succeeds(self): |
| 76 with self.assertCalls( |
| 77 mock.call.pylib.device.adb_wrapper.AdbWrapper.KillServer(), |
| 78 (mock.call.pylib.cmd_helper.GetCmdStatusAndOutput(['pgrep', 'adb']), |
| 79 (1, '')), |
| 80 mock.call.pylib.device.adb_wrapper.AdbWrapper.StartServer(), |
| 81 (mock.call.pylib.cmd_helper.GetCmdStatusAndOutput(['pgrep', 'adb']), |
| 82 (1, '')), |
| 83 (mock.call.pylib.cmd_helper.GetCmdStatusAndOutput(['pgrep', 'adb']), |
| 84 (0, '123\n'))): |
| 85 device_utils.RestartServer() |
| 86 |
| 87 |
72 class MockTempFile(object): | 88 class MockTempFile(object): |
73 | 89 |
74 def __init__(self, name='/tmp/some/file'): | 90 def __init__(self, name='/tmp/some/file'): |
75 self.file = mock.MagicMock(spec=file) | 91 self.file = mock.MagicMock(spec=file) |
76 self.file.name = name | 92 self.file.name = name |
77 | 93 |
78 def __enter__(self): | 94 def __enter__(self): |
79 return self.file | 95 return self.file |
80 | 96 |
81 def __exit__(self, exc_type, exc_val, exc_tb): | 97 def __exit__(self, exc_type, exc_val, exc_tb): |
(...skipping 1443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1525 def testStr_returnsSerial(self): | 1541 def testStr_returnsSerial(self): |
1526 with self.assertCalls( | 1542 with self.assertCalls( |
1527 (self.call.adb.GetDeviceSerial(), '0123456789abcdef')): | 1543 (self.call.adb.GetDeviceSerial(), '0123456789abcdef')): |
1528 self.assertEqual('0123456789abcdef', str(self.device)) | 1544 self.assertEqual('0123456789abcdef', str(self.device)) |
1529 | 1545 |
1530 | 1546 |
1531 if __name__ == '__main__': | 1547 if __name__ == '__main__': |
1532 logging.getLogger().setLevel(logging.DEBUG) | 1548 logging.getLogger().setLevel(logging.DEBUG) |
1533 unittest.main(verbosity=2) | 1549 unittest.main(verbosity=2) |
1534 | 1550 |
OLD | NEW |