From 311b611afe06b812f81268fdce4e4f9a6542be3a Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Thu, 29 Feb 2024 22:58:52 +0100 Subject: [PATCH 1/3] Clear index when closing project (#1718) --- novelwriter/core/project.py | 1 + 1 file changed, 1 insertion(+) diff --git a/novelwriter/core/project.py b/novelwriter/core/project.py index dbe09be8..14d4bd29 100644 --- a/novelwriter/core/project.py +++ b/novelwriter/core/project.py @@ -410,6 +410,7 @@ class NWProject: def closeProject(self, idleTime: float = 0.0) -> None: """Close the project.""" logger.info("Closing project") + self._index.clearIndex() # Triggers clear signal, see #1718 self._options.saveSettings() self._tree.writeToCFile() self._session.appendSession(idleTime) From 4ac050fe75c7c144aca44b54f1a7af0cbed77e37 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Thu, 29 Feb 2024 23:06:19 +0100 Subject: [PATCH 2/3] Add regression test --- tests/test_core/test_core_index.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/test_core/test_core_index.py b/tests/test_core/test_core_index.py index f225d0f2..7811f5e6 100644 --- a/tests/test_core/test_core_index.py +++ b/tests/test_core/test_core_index.py @@ -26,6 +26,7 @@ import pytest from shutil import copyfile from mocked import causeException +from novelwriter import SHARED from novelwriter.core.item import NWItem from tools import C, buildTestProject, cmpFiles, writeFile @@ -36,7 +37,7 @@ from novelwriter.core.project import NWProject @pytest.mark.core -def testCoreIndex_LoadSave(monkeypatch, prjLipsum, mockGUI, tstPaths): +def testCoreIndex_LoadSave(qtbot, monkeypatch, prjLipsum, mockGUI, tstPaths): """Test core functionality of scanning, saving, loading and checking the index cache file. """ @@ -148,8 +149,10 @@ def testCoreIndex_LoadSave(monkeypatch, prjLipsum, mockGUI, tstPaths): assert "fb609cd8319dc" in index._itemIndex assert "7a992350f3eb6" in index._itemIndex - # Finalise - project.closeProject() + # Close Project + with qtbot.waitSignal(SHARED.indexCleared, timeout=1000): + # Regression test for issue #1718 + project.closeProject() # END Test testCoreIndex_LoadSave From 72b14ff08cbc38e827019d0e2054038f664ee420 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Thu, 29 Feb 2024 23:07:22 +0100 Subject: [PATCH 3/3] Clean up imports --- tests/test_core/test_core_index.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_core/test_core_index.py b/tests/test_core/test_core_index.py index 7811f5e6..eb9144ed 100644 --- a/tests/test_core/test_core_index.py +++ b/tests/test_core/test_core_index.py @@ -25,13 +25,13 @@ import pytest from shutil import copyfile -from mocked import causeException -from novelwriter import SHARED -from novelwriter.core.item import NWItem from tools import C, buildTestProject, cmpFiles, writeFile +from mocked import causeException +from novelwriter import SHARED from novelwriter.enum import nwComment, nwItemClass, nwItemLayout from novelwriter.constants import nwFiles +from novelwriter.core.item import NWItem from novelwriter.core.index import IndexItem, NWIndex, countWords, TagsIndex, processComment from novelwriter.core.project import NWProject