| OLD | NEW |
| (Empty) | |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 """ |
| 6 Unit tests for the contents of device_utils.py (mostly DeviceUtils). |
| 7 """ |
| 8 |
| 9 # pylint: disable=W0212 |
| 10 # pylint: disable=W0613 |
| 11 |
| 12 import unittest |
| 13 from pylib import android_commands |
| 14 from pylib import cmd_helper |
| 15 from pylib.device import adb_wrapper |
| 16 from pylib.device import device_utils |
| 17 |
| 18 |
| 19 class DeviceUtilsTest(unittest.TestCase): |
| 20 def testGetAVDs(self): |
| 21 pass |
| 22 |
| 23 def testRestartServerNotRunning(self): |
| 24 # TODO(jbudorick) If these fail, it's not DeviceUtils's fault. |
| 25 self.assertEqual(0, cmd_helper.RunCmd(['pkill', 'adb'])) |
| 26 self.assertNotEqual(0, cmd_helper.RunCmd(['pgrep', 'adb'])) |
| 27 device_utils.RestartServer() |
| 28 self.assertEqual(0, cmd_helper.RunCmd(['pgrep', 'adb'])) |
| 29 |
| 30 def testRestartServerAlreadyRunning(self): |
| 31 if cmd_helper.RunCmd(['pgrep', 'adb']) != 0: |
| 32 device_utils.RestartServer() |
| 33 code, original_pid = cmd_helper.GetCmdStatusAndOutput(['pgrep', 'adb']) |
| 34 self.assertEqual(0, code) |
| 35 device_utils.RestartServer() |
| 36 code, new_pid = cmd_helper.GetCmdStatusAndOutput(['pgrep', 'adb']) |
| 37 self.assertEqual(0, code) |
| 38 self.assertNotEqual(original_pid, new_pid) |
| 39 |
| 40 def testInitWithStr(self): |
| 41 serial_as_str = str('0123456789abcdef') |
| 42 d = device_utils.DeviceUtils('0123456789abcdef') |
| 43 self.assertEqual(serial_as_str, d.old_interface.GetDevice()) |
| 44 |
| 45 def testInitWithUnicode(self): |
| 46 serial_as_unicode = unicode('fedcba9876543210') |
| 47 d = device_utils.DeviceUtils(serial_as_unicode) |
| 48 self.assertEqual(serial_as_unicode, d.old_interface.GetDevice()) |
| 49 |
| 50 def testInitWithAdbWrapper(self): |
| 51 serial = '123456789abcdef0' |
| 52 a = adb_wrapper.AdbWrapper(serial) |
| 53 d = device_utils.DeviceUtils(a) |
| 54 self.assertEqual(serial, d.old_interface.GetDevice()) |
| 55 |
| 56 def testInitWithAndroidCommands(self): |
| 57 serial = '0fedcba987654321' |
| 58 a = android_commands.AndroidCommands(device=serial) |
| 59 d = device_utils.DeviceUtils(a) |
| 60 self.assertEqual(serial, d.old_interface.GetDevice()) |
| 61 |
| 62 def testInitWithNone(self): |
| 63 d = device_utils.DeviceUtils(None) |
| 64 self.assertIsNone(d.old_interface.GetDevice()) |
| 65 |
| 66 |
| 67 if __name__ == '__main__': |
| 68 unittest.main() |
| 69 |
| OLD | NEW |