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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 'Available Android Virtual Devices:\n' | 77 'Available Android Virtual Devices:\n' |
78 ' Name: my_android5.0\n' | 78 ' Name: my_android5.0\n' |
79 ' Path: /some/path/to/.android/avd/my_android5.0.avd\n' | 79 ' Path: /some/path/to/.android/avd/my_android5.0.avd\n' |
80 ' Target: Android 5.0 (API level 21)\n' | 80 ' Target: Android 5.0 (API level 21)\n' |
81 ' Tag/ABI: default/x86\n' | 81 ' Tag/ABI: default/x86\n' |
82 ' Skin: WVGA800\n'): | 82 ' Skin: WVGA800\n'): |
83 self.assertEquals(['my_android5.0'], | 83 self.assertEquals(['my_android5.0'], |
84 device_utils.GetAVDs()) | 84 device_utils.GetAVDs()) |
85 | 85 |
86 | 86 |
87 class DeviceUtilsRestartServerTest(mock_calls.TestCase): | |
88 | |
89 @mock.patch('time.sleep', mock.Mock()) | |
90 def testRestartServer_succeeds(self): | |
91 with self.assertCalls( | |
92 mock.call.pylib.device.adb_wrapper.AdbWrapper.KillServer(), | |
93 (mock.call.pylib.cmd_helper.GetCmdStatusAndOutput(['pgrep', 'adb']), | |
94 (1, '')), | |
95 mock.call.pylib.device.adb_wrapper.AdbWrapper.StartServer(), | |
96 (mock.call.pylib.cmd_helper.GetCmdStatusAndOutput(['pgrep', 'adb']), | |
97 (1, '')), | |
98 (mock.call.pylib.cmd_helper.GetCmdStatusAndOutput(['pgrep', 'adb']), | |
99 (0, '123\n'))): | |
100 device_utils.RestartServer() | |
101 | |
102 | |
103 class MockTempFile(object): | 87 class MockTempFile(object): |
104 | 88 |
105 def __init__(self, name='/tmp/some/file'): | 89 def __init__(self, name='/tmp/some/file'): |
106 self.file = mock.MagicMock(spec=file) | 90 self.file = mock.MagicMock(spec=file) |
107 self.file.name = name | 91 self.file.name = name |
108 | 92 |
109 def __enter__(self): | 93 def __enter__(self): |
110 return self.file | 94 return self.file |
111 | 95 |
112 def __exit__(self, exc_type, exc_val, exc_tb): | 96 def __exit__(self, exc_type, exc_val, exc_tb): |
(...skipping 1444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1557 self.assertTrue( | 1541 self.assertTrue( |
1558 isinstance(device, device_utils.DeviceUtils) | 1542 isinstance(device, device_utils.DeviceUtils) |
1559 and serial == str(device), | 1543 and serial == str(device), |
1560 'Expected a DeviceUtils object with serial %s' % serial) | 1544 'Expected a DeviceUtils object with serial %s' % serial) |
1561 | 1545 |
1562 | 1546 |
1563 if __name__ == '__main__': | 1547 if __name__ == '__main__': |
1564 logging.getLogger().setLevel(logging.DEBUG) | 1548 logging.getLogger().setLevel(logging.DEBUG) |
1565 unittest.main(verbosity=2) | 1549 unittest.main(verbosity=2) |
1566 | 1550 |
OLD | NEW |