def test_flash_finished(): """ Ensure state is set back as expected when the flashing thread is finished. """ view = mock.MagicMock() editor = mock.MagicMock() mm = MicrobitMode(editor, view) mm.flash_thread = mock.MagicMock() mm.flash_timer = mock.MagicMock() mm.flash_finished() view.button_bar.slots['flash'].setEnabled.assert_called_once_with(True) editor.show_status_message.assert_called_once_with("Finished flashing.") assert mm.flash_thread is None assert mm.flash_timer is None
def test_flash_finished(): """ Ensure state is set back as expected when the flashing thread is finished. """ view = mock.MagicMock() editor = mock.MagicMock() mm = MicrobitMode(editor, view) mm.flash_thread = mock.MagicMock() mm.flash_timer = mock.MagicMock() mm.flash_finished() view.button_bar.slots['flash'].setEnabled.assert_called_once_with(True) editor.show_status_message.assert_called_once_with("Finished flashing.") assert mm.flash_thread is None assert mm.flash_timer is None
def test_flash_finished_copy_main(): """ Ensure state is set back as expected when the flashing thread is finished. """ view = mock.MagicMock() editor = mock.MagicMock() mm = MicrobitMode(editor, view) mm.python_script = 'foo' mm.copy_main = mock.MagicMock() mm.set_buttons = mock.MagicMock() mm.flash_thread = mock.MagicMock() mm.flash_timer = mock.MagicMock() mm.flash_finished() mm.set_buttons.assert_called_once_with(flash=True) editor.show_status_message.assert_called_once_with("Finished flashing.") assert mm.flash_thread is None assert mm.flash_timer is None mm.copy_main.assert_called_once_with()
def test_flash_finished_no_copy(): """ Ensure state is set back as expected when the flashing thread is finished. If no python_script is set, then copy_main is NOT called. """ view = mock.MagicMock() editor = mock.MagicMock() mm = MicrobitMode(editor, view) mm.copy_main = mock.MagicMock() mm.set_buttons = mock.MagicMock() mm.flash_thread = mock.MagicMock() mm.flash_finished() mm.set_buttons.assert_called_once_with(flash=True, repl=True, files=True, plotter=True) editor.show_status_message.assert_called_once_with("Finished flashing.") assert mm.flash_thread is None assert mm.copy_main.call_count == 0
def test_flash_finished_copy_main_encounters_error(): """ If copy_main encounters an error, flash_failed is called. """ view = mock.MagicMock() editor = mock.MagicMock() mm = MicrobitMode(editor, view) mm.flash_failed = mock.MagicMock() mm.python_script = 'foo' error = IOError('boom') mm.copy_main = mock.MagicMock(side_effect=error) mm.set_buttons = mock.MagicMock() mm.flash_thread = mock.MagicMock() mm.flash_timer = mock.MagicMock() mm.flash_finished() mm.set_buttons.assert_called_once_with(flash=True) editor.show_status_message.assert_called_once_with("Finished flashing.") assert mm.flash_thread is None assert mm.flash_timer is None mm.copy_main.assert_called_once_with() mm.flash_failed.assert_called_once_with(error)