diff options
Diffstat (limited to 'build/fuchsia/test/flash_device_unittests.py')
-rwxr-xr-x | build/fuchsia/test/flash_device_unittests.py | 138 |
1 files changed, 37 insertions, 101 deletions
diff --git a/build/fuchsia/test/flash_device_unittests.py b/build/fuchsia/test/flash_device_unittests.py index 65f8dd5410..0cbe09d180 100755 --- a/build/fuchsia/test/flash_device_unittests.py +++ b/build/fuchsia/test/flash_device_unittests.py @@ -5,7 +5,6 @@ """File for testing flash_device.py.""" import os -import subprocess import unittest import unittest.mock as mock @@ -128,14 +127,14 @@ class FlashDeviceTest(unittest.TestCase): self._ffx_mock.return_value.stdout = \ '[{"title": "Build", "child": [{"value": "wrong.version"}, ' \ '{"value": "wrong_product"}]}]' - flash_device.update(_TEST_IMAGE_DIR, - 'check', - None, - should_pave=False) - # Regular boot is to check the versions. - mock_boot.assert_called_once_with(mock.ANY, - boot_device.BootMode.REGULAR, - None) + flash_device.update(_TEST_IMAGE_DIR, 'check', None) + mock_boot.assert_has_calls([ + mock.call(mock.ANY, boot_device.BootMode.REGULAR, None), + mock.call(mock.ANY, + boot_device.BootMode.REGULAR, + None, + must_boot=True) + ]) self.assertEqual(self._ffx_mock.call_count, 1) # get_system_info should not even be called due to early exit. @@ -152,14 +151,14 @@ class FlashDeviceTest(unittest.TestCase): self._ffx_mock.return_value.stdout = \ '[{"title": "Build", "child": [{"value": "wrong.version"}, ' \ '{"value": "wrong_product"}]}]' - flash_device.update(_TEST_IMAGE_DIR, - 'check', - None, - should_pave=False) - # Regular boot is to check the versions. - mock_boot.assert_called_once_with(mock.ANY, - boot_device.BootMode.REGULAR, - None) + flash_device.update(_TEST_IMAGE_DIR, 'check', None) + mock_boot.assert_has_calls([ + mock.call(mock.ANY, boot_device.BootMode.REGULAR, None), + mock.call(mock.ANY, + boot_device.BootMode.REGULAR, + None, + must_boot=True) + ]) self.assertEqual(self._ffx_mock.call_count, 2) def test_incorrect_target_info(self) -> None: @@ -167,10 +166,7 @@ class FlashDeviceTest(unittest.TestCase): retrieved.""" with mock.patch('os.path.exists', return_value=True): self._ffx_mock.return_value.stdout = '[{"title": "badtitle"}]' - flash_device.update(_TEST_IMAGE_DIR, - 'check', - None, - should_pave=False) + flash_device.update(_TEST_IMAGE_DIR, 'check', None) self.assertEqual(self._ffx_mock.call_count, 2) def test_update_with_serial_num(self) -> None: @@ -179,14 +175,15 @@ class FlashDeviceTest(unittest.TestCase): with mock.patch('time.sleep'), \ mock.patch('os.path.exists', return_value=True), \ mock.patch('flash_device.boot_device') as mock_boot: - flash_device.update(_TEST_IMAGE_DIR, - 'update', - None, - 'test_serial', - should_pave=False) - mock_boot.assert_called_once_with(mock.ANY, - boot_device.BootMode.BOOTLOADER, - 'test_serial') + flash_device.update(_TEST_IMAGE_DIR, 'update', None, 'test_serial') + mock_boot.assert_has_calls([ + mock.call(mock.ANY, boot_device.BootMode.BOOTLOADER, + 'test_serial'), + mock.call(mock.ANY, + boot_device.BootMode.REGULAR, + 'test_serial', + must_boot=True) + ]) self.assertEqual(self._ffx_mock.call_count, 2) def test_reboot_failure(self) -> None: @@ -201,42 +198,6 @@ class FlashDeviceTest(unittest.TestCase): _TEST_IMAGE_DIR, None) self.assertEqual(required, True) - # pylint: disable=no-self-use - def test_update_calls_paving_if_specified(self) -> None: - """Test update calls pave if specified.""" - with mock.patch('time.sleep'), \ - mock.patch('os.path.exists', return_value=True), \ - mock.patch('flash_device.running_unattended', - return_value=True), \ - mock.patch('flash_device.boot_device') as mock_boot, \ - mock.patch('flash_device.pave') as mock_pave: - flash_device.update(_TEST_IMAGE_DIR, - 'update', - 'some-target-id', - should_pave=True) - - mock_boot.assert_called_once_with('some-target-id', - boot_device.BootMode.RECOVERY, - None) - mock_pave.assert_called_once_with(_TEST_IMAGE_DIR, - 'some-target-id') - - # pylint: enable=no-self-use - - def test_update_raises_error_if_unattended_with_no_target(self) -> None: - """Test update raises error if no target specified.""" - - self._swarming_mock.return_value = True - with mock.patch('time.sleep'), \ - mock.patch('flash_device.pave'), \ - mock.patch('os.path.exists', return_value=True): - self.assertRaises(AssertionError, - flash_device.update, - _TEST_IMAGE_DIR, - 'update', - None, - should_pave=True) - def test_update_on_swarming(self) -> None: """Test update on swarming bots.""" @@ -245,47 +206,22 @@ class FlashDeviceTest(unittest.TestCase): mock.patch('os.path.exists', return_value=True), \ mock.patch('flash_device.boot_device') as mock_boot, \ mock.patch('subprocess.run'): - flash_device.update(_TEST_IMAGE_DIR, - 'update', - None, - 'test_serial', - should_pave=False) - mock_boot.assert_called_once_with(mock.ANY, - boot_device.BootMode.BOOTLOADER, - 'test_serial') + flash_device.update(_TEST_IMAGE_DIR, 'update', None, 'test_serial') + mock_boot.assert_has_calls([ + mock.call(mock.ANY, boot_device.BootMode.BOOTLOADER, + 'test_serial'), + mock.call(mock.ANY, + boot_device.BootMode.REGULAR, + 'test_serial', + must_boot=True) + ]) self.assertEqual(self._ffx_mock.call_count, 2) - # pylint: disable=no-self-use - def test_update_with_pave_timeout_defaults_to_flash(self) -> None: - """Test update falls back to flash if pave fails.""" - with mock.patch('time.sleep'), \ - mock.patch('os.path.exists', return_value=True), \ - mock.patch('flash_device.running_unattended', - return_value=True), \ - mock.patch('flash_device.pave') as mock_pave, \ - mock.patch('flash_device.boot_device'), \ - mock.patch('flash_device.flash') as mock_flash: - mock_pave.side_effect = subprocess.TimeoutExpired( - cmd='/some/cmd', - timeout=0, - ) - flash_device.update(_TEST_IMAGE_DIR, - 'update', - 'some-target-id', - should_pave=True) - mock_pave.assert_called_once_with(_TEST_IMAGE_DIR, - 'some-target-id') - mock_flash.assert_called_once_with(_TEST_IMAGE_DIR, - 'some-target-id', None) - - # pylint: enable=no-self-use - def test_main(self) -> None: """Tests |main| function.""" - with mock.patch( - 'sys.argv', - ['flash_device.py', '--os-check', 'ignore', '--no-pave']): + with mock.patch('sys.argv', + ['flash_device.py', '--os-check', 'ignore']): with mock.patch.dict(os.environ, {}): flash_device.main() self.assertEqual(self._ffx_mock.call_count, 0) |