From 31776a51a7e771f28cc3b2ec967e4e8624af162a Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Wed, 29 May 2024 21:37:02 +0200 Subject: [PATCH] Add some more easy coverage --- novelwriter/guimain.py | 18 ++++-------------- tests/test_gui/test_gui_guimain.py | 14 +++++++++++++- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/novelwriter/guimain.py b/novelwriter/guimain.py index 37c42cb2..14b124fa 100644 --- a/novelwriter/guimain.py +++ b/novelwriter/guimain.py @@ -304,9 +304,6 @@ class GuiMain(QMainWindow): self.keyEscape.setKey(Qt.Key.Key_Escape) self.keyEscape.activated.connect(self._keyPressEscape) - # Check that config loaded fine - self.reportConfErr() - # Initialise Main GUI self.initMain() self.asProjTimer.start() @@ -328,6 +325,10 @@ class GuiMain(QMainWindow): def postLaunchTasks(self, cmdOpen: str | None) -> None: """Process tasks after the main window has been created.""" + # Check that config loaded fine + if CONFIG.hasError: + SHARED.error(CONFIG.errorText()) + if cmdOpen: QApplication.processEvents() logger.info("Command line path: %s", cmdOpen) @@ -843,15 +844,6 @@ class GuiMain(QMainWindow): SHARED.error(self.tr("Could not initialise the dialog.")) return - def reportConfErr(self) -> None: - """Checks if the Config module has any errors to report, and let - the user know if this is the case. The Config module caches - errors since it is initialised before the GUI itself. - """ - if CONFIG.hasError: - SHARED.error(CONFIG.errorText()) - return - ## # Main Window Actions ## @@ -882,9 +874,7 @@ class GuiMain(QMainWindow): if SHARED.hasProject: self.closeProject(True) - CONFIG.saveConfig() - self.reportConfErr() QApplication.quit() diff --git a/tests/test_gui/test_gui_guimain.py b/tests/test_gui/test_gui_guimain.py index 09142051..4baf2758 100644 --- a/tests/test_gui/test_gui_guimain.py +++ b/tests/test_gui/test_gui_guimain.py @@ -84,6 +84,10 @@ def testGuiMain_Launch(qtbot, monkeypatch, nwGUI, projPath): # Check that latest release info updated assert CONFIG.lastNotes != "0x0" + # Set some config error + CONFIG._hasError = True + CONFIG._errData.append("Foo") + # Check that project open dialog launches nwGUI.postLaunchTasks(None) qtbot.waitUntil(lambda: SHARED.findTopLevelWidget(GuiWelcome) is not None, timeout=1000) @@ -91,6 +95,10 @@ def testGuiMain_Launch(qtbot, monkeypatch, nwGUI, projPath): welcome.show() welcome.close() + # Config errors should be cleared + assert SHARED.lastAlert == "Foo" + assert CONFIG._hasError is False + # qtbot.stop() @@ -578,7 +586,11 @@ def testGuiMain_Viewing(qtbot, monkeypatch, nwGUI, projPath, mockRnd): assert nwGUI.viewDocument(None) is False assert nwGUI.splitView.isVisible() is False - # Open the test project + # Open project requires a path + assert nwGUI.openProject(None) is False + assert SHARED.hasProject is False + + # Open the test project, properly nwGUI.openProject(projPath) assert nwGUI.docEditor.docHandle == C.hTitlePage