Skip to content

Commit

Permalink
Use updated serial when running fastboot command (#945)
Browse files Browse the repository at this point in the history
Make fastboot follow `AndroidDevice.update_serial`
  • Loading branch information
sztupkay authored Oct 17, 2024
1 parent de93e1e commit d0b760d
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 6 deletions.
13 changes: 7 additions & 6 deletions mobly/controllers/android_device_lib/fastboot.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,17 @@ class FastbootProxy:

def __init__(self, serial=''):
self.serial = serial
if serial:
self.fastboot_str = 'fastboot -s {}'.format(serial)
else:
self.fastboot_str = 'fastboot'

def fastboot_str(self):
if self.serial:
return 'fastboot -s {}'.format(self.serial)
return 'fastboot'

def _exec_fastboot_cmd(self, name, arg_str):
return exe_cmd(' '.join((self.fastboot_str, name, arg_str)))
return exe_cmd(' '.join((self.fastboot_str(), name, arg_str)))

def args(self, *args):
return exe_cmd(' '.join((self.fastboot_str,) + args))
return exe_cmd(' '.join((self.fastboot_str(),) + args))

def __getattr__(self, name):
def fastboot_call(*args):
Expand Down
57 changes: 57 additions & 0 deletions tests/mobly/controllers/android_device_lib/fastboot_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,63 @@ def test_fastboot_commands_and_results_are_logged_to_debug_log(
123,
)

@mock.patch('mobly.controllers.android_device_lib.fastboot.Popen')
def test_fastboot_without_serial(self, mock_popen):
expected_stdout = 'stdout'
expected_stderr = b'stderr'
mock_popen.return_value.communicate = mock.Mock(
return_value=(expected_stdout, expected_stderr)
)
mock_popen.return_value.returncode = 123

fastboot.FastbootProxy().fake_command('extra', 'flags')

mock_popen.assert_called_with(
'fastboot fake-command extra flags',
stdout=mock.ANY,
stderr=mock.ANY,
shell=True,
)

@mock.patch('mobly.controllers.android_device_lib.fastboot.Popen')
def test_fastboot_with_serial(self, mock_popen):
expected_stdout = 'stdout'
expected_stderr = b'stderr'
mock_popen.return_value.communicate = mock.Mock(
return_value=(expected_stdout, expected_stderr)
)
mock_popen.return_value.returncode = 123

fastboot.FastbootProxy('ABC').fake_command('extra', 'flags')

mock_popen.assert_called_with(
'fastboot -s ABC fake-command extra flags',
stdout=mock.ANY,
stderr=mock.ANY,
shell=True,
)

@mock.patch('mobly.controllers.android_device_lib.fastboot.Popen')
def test_fastboot_update_serial(self, mock_popen):
expected_stdout = 'stdout'
expected_stderr = b'stderr'
mock_popen.return_value.communicate = mock.Mock(
return_value=(expected_stdout, expected_stderr)
)
mock_popen.return_value.returncode = 123

fut = fastboot.FastbootProxy('ABC')
fut.fake_command('extra', 'flags')
fut.serial = 'XYZ'
fut.fake_command('extra', 'flags')

mock_popen.assert_called_with(
'fastboot -s XYZ fake-command extra flags',
stdout=mock.ANY,
stderr=mock.ANY,
shell=True,
)


if __name__ == '__main__':
unittest.main()

0 comments on commit d0b760d

Please sign in to comment.