Skip to content

Commit

Permalink
FIXUP: Do not start the threads in the tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
almet committed Oct 17, 2024
1 parent 8da6d30 commit 345fba5
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions tests/gui/test_main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 345fba5

Please sign in to comment.