[Android] Fix DeviceUtils.__str__ when no serial is provided.
This CL also changes two instances of DeviceUtils.__init__(None) s.t. an explicit serial number is now provided. BUG=398127 Review URL: https://codereview.chromium.org/420273006 git-svn-id: http://src.chromium.org/svn/trunk/src/build@286124 4ff67af0-8c30-449e-8e8b-ad334ec8d88c
This commit is contained in:
Родитель
e113a571c9
Коммит
691941b28e
|
@ -37,3 +37,10 @@ class DeviceUnreachableError(BaseError):
|
|||
"""Exception for device unreachable failures."""
|
||||
pass
|
||||
|
||||
|
||||
class NoDevicesError(BaseError):
|
||||
"""Exception for having no devices attached."""
|
||||
|
||||
def __init__(self):
|
||||
super(NoDevicesError, self).__init__('No devices attached.')
|
||||
|
||||
|
|
|
@ -790,7 +790,12 @@ class DeviceUtils(object):
|
|||
|
||||
def __str__(self):
|
||||
"""Returns the device serial."""
|
||||
return self.old_interface.GetDevice()
|
||||
s = self.old_interface.GetDevice()
|
||||
if not s:
|
||||
s = self.old_interface.Adb().GetSerialNumber()
|
||||
if s == 'unknown':
|
||||
raise device_errors.NoDevicesError()
|
||||
return s
|
||||
|
||||
@staticmethod
|
||||
def parallel(devices=None, async=False):
|
||||
|
|
|
@ -1484,6 +1484,17 @@ class DeviceUtilsStrTest(DeviceUtilsOldImplTest):
|
|||
with self.assertNoAdbCalls():
|
||||
self.assertEqual('0123456789abcdef', str(self.device))
|
||||
|
||||
def testStr_noSerial(self):
|
||||
self.device = device_utils.DeviceUtils(None)
|
||||
with self.assertCalls('adb get-serialno', '0123456789abcdef'):
|
||||
self.assertEqual('0123456789abcdef', str(self.device))
|
||||
|
||||
def testStr_noSerial_noDevices(self):
|
||||
self.device = device_utils.DeviceUtils(None)
|
||||
with self.assertCalls('adb get-serialno', 'unknown'), (
|
||||
self.assertRaises(device_errors.NoDevicesError)):
|
||||
str(self.device)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
logging.getLogger().setLevel(logging.DEBUG)
|
||||
|
|
Загрузка…
Ссылка в новой задаче