From 345fba5884902f3ca1249287478e0c14830338b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20M=C3=A9taireau?= Date: Thu, 17 Oct 2024 13:04:38 +0200 Subject: [PATCH] FIXUP: Do not start the threads in the tests. --- tests/gui/test_main_window.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/gui/test_main_window.py b/tests/gui/test_main_window.py index 939955e05..7cace8d59 100644 --- a/tests/gui/test_main_window.py +++ b/tests/gui/test_main_window.py @@ -552,39 +552,39 @@ def test_installation_failure_exception(qtbot: QtBot, mocker: MockerFixture) -> """Ensures that if an exception is raised during image installation, it is shown in the GUI. """ - # Setup + # Setup install to raise an exception mock_app = mocker.MagicMock() dummy = mocker.MagicMock(spec=Container) dummy.install.side_effect = RuntimeError("Error during install") dz = DangerzoneGui(mock_app, dummy) + + # Mock the InstallContainerThread to call the original run method instead of starting a new thread + mocker.patch.object(InstallContainerThread, 'start', InstallContainerThread.run) widget = WaitingWidgetContainer(dz) qtbot.addWidget(widget) - # Start the installation process - install_thread = InstallContainerThread(dz) - with qtbot.waitSignal(install_thread.finished, timeout=5000): - install_thread.start() + assert dummy.install.call_count == 1 - assert "the following error occured" in widget.label.text() - assert "Traceback" in widget.traceback.toPlainText() assert "Error during install" in widget.traceback.toPlainText() + assert "RuntimeError" in widget.traceback.toPlainText() def test_installation_failure_return_false(qtbot: QtBot, mocker: MockerFixture) -> None: - # Setup + """Ensures that if the installation returns False, the error is shown in the GUI.""" + # Setup install to return False mock_app = mocker.MagicMock() dummy = mocker.MagicMock(spec=Container) dummy.install.return_value = False dz = DangerzoneGui(mock_app, dummy) + + # Mock the InstallContainerThread to call the original run method instead of starting a new thread + mocker.patch.object(InstallContainerThread, 'start', InstallContainerThread.run) widget = WaitingWidgetContainer(dz) qtbot.addWidget(widget) - # Start the installation process - install_thread = InstallContainerThread(dz) - with qtbot.waitSignal(install_thread.finished, timeout=5000): - install_thread.start() + assert dummy.install.call_count == 1 assert "the following error occured" in widget.label.text() assert "The image cannot be found" in widget.traceback.toPlainText()