OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Tests for the AdbWrapper class.""" | 5 """Tests for the AdbWrapper class.""" |
6 | 6 |
7 import os | 7 import os |
| 8 import socket |
8 import tempfile | 9 import tempfile |
9 import time | 10 import time |
10 import unittest | 11 import unittest |
11 | 12 |
12 from pylib.device import adb_wrapper | 13 import adb_wrapper |
13 | 14 |
14 | 15 |
15 class TestAdbWrapper(unittest.TestCase): | 16 class TestAdbWrapper(unittest.TestCase): |
16 | 17 |
17 def setUp(self): | 18 def setUp(self): |
18 devices = adb_wrapper.AdbWrapper.GetDevices() | 19 devices = adb_wrapper.AdbWrapper.GetDevices() |
19 assert devices, 'A device must be attached' | 20 assert devices, 'A device must be attached' |
20 self._adb = devices[0] | 21 self._adb = devices[0] |
21 self._adb.WaitForDevice() | 22 self._adb.WaitForDevice() |
22 | 23 |
23 @staticmethod | 24 def _MakeTempFile(self, contents): |
24 def _MakeTempFile(contents): | |
25 """Make a temporary file with the given contents. | 25 """Make a temporary file with the given contents. |
26 | 26 |
27 Args: | 27 Args: |
28 contents: string to write to the temporary file. | 28 contents: string to write to the temporary file. |
29 | 29 |
30 Returns: | 30 Returns: |
31 The absolute path to the file. | 31 The absolute path to the file. |
32 """ | 32 """ |
33 fi, path = tempfile.mkstemp() | 33 fi, path = tempfile.mkstemp() |
34 with os.fdopen(fi, 'wb') as f: | 34 with os.fdopen(fi, 'wb') as f: |
35 f.write(contents) | 35 f.write('foo') |
36 return path | 36 return path |
37 | 37 |
38 def testShell(self): | 38 def testShell(self): |
39 output = self._adb.Shell('echo test', expect_rc=0) | 39 output = self._adb.Shell('echo test', expect_rc=0) |
40 self.assertEqual(output.strip(), 'test') | 40 self.assertEqual(output.strip(), 'test') |
41 output = self._adb.Shell('echo test') | 41 output = self._adb.Shell('echo test') |
42 self.assertEqual(output.strip(), 'test') | 42 self.assertEqual(output.strip(), 'test') |
43 self.assertRaises(adb_wrapper.CommandFailedError, self._adb.Shell, | 43 self.assertRaises(adb_wrapper.CommandFailedError, self._adb.Shell, |
44 'echo test', expect_rc=1) | 44 'echo test', expect_rc=1) |
45 | 45 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 try: | 81 try: |
82 self._adb.Shell('start') | 82 self._adb.Shell('start') |
83 break | 83 break |
84 except adb_wrapper.CommandFailedError: | 84 except adb_wrapper.CommandFailedError: |
85 time.sleep(1) | 85 time.sleep(1) |
86 self._adb.Remount() | 86 self._adb.Remount() |
87 | 87 |
88 | 88 |
89 if __name__ == '__main__': | 89 if __name__ == '__main__': |
90 unittest.main() | 90 unittest.main() |
OLD | NEW |