From 26b4da9eb4ad0661dc8596c7e55331c12dbb3148 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Wed, 20 Nov 2024 19:58:34 +0100 Subject: [PATCH] Fix most tests with minor issues --- tests/lipsum/nwProject.nwx | 12 ++- .../coreProject_NewFileFolder_nwProject.nwx | 24 ++--- .../coreProject_NewRoot_nwProject.nwx | 24 ++--- .../coreTools_DocDuplicator_nwProject.nwx | 42 +++++---- .../reference/fmtToDocX_SaveDocument_core.xml | 6 +- tests/test_core/test_core_docbuild.py | 24 ++--- tests/test_core/test_core_index.py | 25 +++-- tests/test_core/test_core_project.py | 94 +------------------ tests/test_dialogs/test_dlg_docsplit.py | 3 - tests/test_formats/test_fmt_todocx.py | 2 +- tests/test_gui/test_gui_doceditor.py | 2 - tests/test_gui/test_gui_docviewer.py | 4 +- tests/test_gui/test_gui_docviewerpanel.py | 4 +- tests/test_gui/test_gui_guimain.py | 3 +- tests/test_gui/test_gui_mainmenu.py | 1 - tests/test_gui/test_gui_noveltree.py | 2 +- tests/test_gui/test_gui_outline.py | 2 - tests/test_gui/test_gui_projtree.py | 17 ++-- tests/test_gui/test_gui_statusbar.py | 1 - tests/test_tools/test_tools_manussettings.py | 8 ++ tests/tools.py | 1 + 21 files changed, 109 insertions(+), 192 deletions(-) diff --git a/tests/lipsum/nwProject.nwx b/tests/lipsum/nwProject.nwx index 8da7d6cc..8287a1e5 100644 --- a/tests/lipsum/nwProject.nwx +++ b/tests/lipsum/nwProject.nwx @@ -1,6 +1,6 @@ - - + + Lorem Ipsum lipsum.com @@ -25,13 +25,13 @@ Finished - New + New Minor Major Main - + Novel @@ -116,5 +116,9 @@ Ancient Europe + + + Trash + diff --git a/tests/reference/coreProject_NewFileFolder_nwProject.nwx b/tests/reference/coreProject_NewFileFolder_nwProject.nwx index 4aba7481..fbfa9e9c 100644 --- a/tests/reference/coreProject_NewFileFolder_nwProject.nwx +++ b/tests/reference/coreProject_NewFileFolder_nwProject.nwx @@ -33,18 +33,6 @@ Novel - - - Plot - - - - Characters - - - - World - Title Page @@ -69,6 +57,14 @@ Hello + + + Plot + + + + Characters + Jane @@ -77,5 +73,9 @@ John + + + Locations + diff --git a/tests/reference/coreProject_NewRoot_nwProject.nwx b/tests/reference/coreProject_NewRoot_nwProject.nwx index 4bfbb568..1a6938aa 100644 --- a/tests/reference/coreProject_NewRoot_nwProject.nwx +++ b/tests/reference/coreProject_NewRoot_nwProject.nwx @@ -33,18 +33,6 @@ Novel - - - Plot - - - - Characters - - - - World - Title Page @@ -61,6 +49,18 @@ New Scene + + + Plot + + + + Characters + + + + Locations + Novel diff --git a/tests/reference/coreTools_DocDuplicator_nwProject.nwx b/tests/reference/coreTools_DocDuplicator_nwProject.nwx index 5f6685a6..431cc119 100644 --- a/tests/reference/coreTools_DocDuplicator_nwProject.nwx +++ b/tests/reference/coreTools_DocDuplicator_nwProject.nwx @@ -1,5 +1,5 @@ - + New Project Jane Doe @@ -16,7 +16,7 @@ - New + New Note Draft Finished @@ -28,23 +28,11 @@ Main - + Novel - - - Plot - - - - Characters - - - - World - Title Page @@ -57,6 +45,10 @@ New Chapter + + + New Chapter + New Scene @@ -65,6 +57,10 @@ New Scene + + + New Scene + New Chapter @@ -77,7 +73,7 @@ New Scene - + Novel @@ -97,9 +93,17 @@ New Scene - - - New Chapter + + + Plot + + + + Characters + + + + Locations diff --git a/tests/reference/fmtToDocX_SaveDocument_core.xml b/tests/reference/fmtToDocX_SaveDocument_core.xml index 2d07ced8..a46abe5d 100644 --- a/tests/reference/fmtToDocX_SaveDocument_core.xml +++ b/tests/reference/fmtToDocX_SaveDocument_core.xml @@ -1,10 +1,10 @@ - 2024-10-28T20:12:57 - 2024-10-28T20:12:57 + 2024-11-20T19:45:15 + 2024-11-20T19:45:15 lipsum.com Lorem Ipsum en_GB - 50 + 51 lipsum.com diff --git a/tests/test_core/test_core_docbuild.py b/tests/test_core/test_core_docbuild.py index 166b281a..a8d85dcc 100644 --- a/tests/test_core/test_core_docbuild.py +++ b/tests/test_core/test_core_docbuild.py @@ -93,7 +93,7 @@ def testCoreDocBuild_OpenDocument(monkeypatch, mockGUI, prjLipsum, fncPath, tstP assert docBuild._outline is True - assert len(docBuild) == 21 + assert len(docBuild) == 22 # Check FODT Build # ================ @@ -151,7 +151,7 @@ def testCoreDocBuild_OpenDocument(monkeypatch, mockGUI, prjLipsum, fncPath, tstP with monkeypatch.context() as mp: mp.setattr("novelwriter.formats.toodt.ToOdt.doConvert", causeException) - assert len(docBuild) == 21 + assert len(docBuild) == 22 count = 0 error = [] @@ -196,7 +196,7 @@ def testCoreDocBuild_HTML(monkeypatch, mockGUI, prjLipsum, fncPath, tstPaths): docBuild = NWBuildDocument(project, build) docBuild.queueAll() - assert len(docBuild) == 21 + assert len(docBuild) == 22 # Check HTML5 Build # ================= @@ -264,7 +264,7 @@ def testCoreDocBuild_Markdown(monkeypatch, mockGUI, prjLipsum, fncPath, tstPaths docBuild = NWBuildDocument(project, build) docBuild.queueAll() - assert len(docBuild) == 21 + assert len(docBuild) == 22 # Check Standard Markdown Build # ============================= @@ -332,7 +332,7 @@ def testCoreDocBuild_DocX(mockGUI, prjLipsum, fncPath): docBuild = NWBuildDocument(project, build) docBuild.queueAll() - assert len(docBuild) == 21 + assert len(docBuild) == 22 # Check Build # =========== @@ -365,7 +365,7 @@ def testCoreDocBuild_PDF(mockGUI, prjLipsum, fncPath): docBuild = NWBuildDocument(project, build) docBuild.queueAll() - assert len(docBuild) == 21 + assert len(docBuild) == 22 # Check Build # =========== @@ -397,7 +397,7 @@ def testCoreDocBuild_NWD(mockGUI, prjLipsum, fncPath, tstPaths): docBuild = NWBuildDocument(project, build) docBuild.queueAll() - assert len(docBuild) == 21 + assert len(docBuild) == 22 # Check NWD Build # =============== @@ -474,8 +474,8 @@ def testCoreDocBuild_Custom(mockGUI, fncPath: Path): # Add an invalid item to the project nHandle = "0123456789def" - project.tree._order.append(nHandle) - project.tree._tree[nHandle] = None # type: ignore + project.tree._items[nHandle] = None # type: ignore + project.tree._nodes[nHandle] = None # type: ignore docBuild.queueAll() assert len(docBuild) == 8 @@ -517,12 +517,6 @@ def testCoreDocBuild_IterBuild(mockGUI, fncPath: Path, mockRnd): project.storage.getDocument(hPlotDoc).writeDocument("# Main Plot\n**Text**") project.storage.getDocument(hCharDoc).writeDocument("# Jane Doe\n~~Text~~") - # Fix project order as this has never been opened in a GUI - project.tree.setOrder([ # type: ignore - C.hNovelRoot, C.hTitlePage, C.hChapterDir, C.hChapterDoc, C.hSceneDoc, - C.hPlotRoot, hPlotDoc, C.hCharRoot, hCharDoc, C.hWorldRoot - ]) - docBuild = NWBuildDocument(project, build) docBuild.queueAll() assert len(docBuild) == 10 diff --git a/tests/test_core/test_core_index.py b/tests/test_core/test_core_index.py index f4562d5b..94eea4e4 100644 --- a/tests/test_core/test_core_index.py +++ b/tests/test_core/test_core_index.py @@ -59,6 +59,7 @@ def testCoreIndex_LoadSave(qtbot, monkeypatch, prjLipsum, mockGUI, tstPaths): "67a8707f2f249": False, # Character ROOT "6c6afb1247750": False, # Plot ROOT "60bdf227455cc": False, # World ROOT + "1ace7ab1a0fc6": False, # Trash ROOT } for tItem in project.tree: index.reIndexHandle(tItem.itemHandle) @@ -346,6 +347,7 @@ def testCoreIndex_ScanText(monkeypatch, mockGUI, fncPath, mockRnd): # Some items for fail to scan tests dHandle = project.newFolder("Folder", C.hNovelRoot) xHandle = project.newFile("No Layout", C.hNovelRoot) + xIndex = project.tree.model.indexFromHandle(xHandle) assert isinstance(dHandle, str) assert isinstance(xHandle, str) @@ -363,10 +365,13 @@ def testCoreIndex_ScanText(monkeypatch, mockGUI, fncPath, mockRnd): assert index.scanText(xHandle, "Hello World!") is False # Create the trash folder - tHandle = project.trashFolder() + tNode = project.tree.trash + assert tNode is not None + tIndex = project.tree.model.indexFromNode(tNode) + tHandle = tNode.item.itemHandle assert project.tree[tHandle] is not None - xItem.setParent(tHandle) - project.tree.updateItemData(xItem.itemHandle) + + project.tree.model.multiMove([xIndex], tIndex) assert xItem.itemRoot == tHandle assert xItem.itemClass == nwItemClass.TRASH assert index.scanText(xHandle, "## Hello World!") is True @@ -374,9 +379,10 @@ def testCoreIndex_ScanText(monkeypatch, mockGUI, fncPath, mockRnd): # Create the archive root aHandle = project.newRoot(nwItemClass.ARCHIVE) + aIndex = project.tree.model.indexFromHandle(aHandle) assert project.tree[aHandle] is not None - xItem.setParent(aHandle) - project.tree.updateItemData(xItem.itemHandle) + + project.tree.model.multiMove([xIndex], aIndex) assert index.scanText(xHandle, "### Hello World!") is True assert xItem.mainHeading == "H3" @@ -901,7 +907,8 @@ def testCoreIndex_ExtractData(mockGUI, fncPath, mockRnd): ] # Add a fake handle to the tree and check that it's ignored - project.tree._order.append("0000000000000") + project.tree._items["0000000000000"] = None # type: ignore + project.tree._nodes["0000000000000"] = None # type: ignore assert [(h, t) for h, t, _ in index._itemIndex.iterNovelStructure(activeOnly=False)] == [ (C.hTitlePage, "T0001"), (C.hChapterDoc, "T0001"), @@ -912,7 +919,8 @@ def testCoreIndex_ExtractData(mockGUI, fncPath, mockRnd): (sHandle, "T0001"), (tHandle, "T0001"), ] - project.tree._order.remove("0000000000000") + del project.tree._items["0000000000000"] + del project.tree._nodes["0000000000000"] # Extract stats assert index.getNovelWordCount(activeOnly=False) == 43 @@ -1281,7 +1289,8 @@ def testCoreIndex_ItemIndex(mockGUI, fncPath, mockRnd): assert nStruct[0][0] == uHandle # Inject garbage into tree - project.tree._order.append("stuff") + project.tree._items["stuff"] = None # type: ignore + project.tree._nodes["stuff"] = None # type: ignore nStruct = list(itemIndex.iterNovelStructure()) assert len(nStruct) == 4 assert nStruct[0][0] == nHandle diff --git a/tests/test_core/test_core_project.py b/tests/test_core/test_core_project.py index 30be4157..3cda98d4 100644 --- a/tests/test_core/test_core_project.py +++ b/tests/test_core/test_core_project.py @@ -29,12 +29,8 @@ from PyQt5.QtWidgets import QMessageBox from novelwriter import CONFIG, SHARED from novelwriter.constants import nwFiles -from novelwriter.core.index import NWIndex -from novelwriter.core.item import NWItem -from novelwriter.core.options import OptionState from novelwriter.core.project import NWProject, NWProjectState from novelwriter.core.projectxml import ProjectXMLReader, ProjectXMLWriter, XMLReadState -from novelwriter.core.tree import NWTree from novelwriter.enum import nwItemClass from tests.mocked import causeOSError @@ -284,7 +280,7 @@ def testCoreProject_Open(monkeypatch, caplog, mockGUI, fncPath, mockRnd): # Fail checking items should still pass with monkeypatch.context() as mp: - mp.setattr("novelwriter.core.tree.NWTree.updateItemData", lambda *a: False) + mp.setattr("novelwriter.core.tree.NWTree.checkConsistency", lambda *a: (1, 0)) assert project.openProject(fncPath, clearLock=True) is True # Trigger an index rebuild @@ -326,70 +322,6 @@ def testCoreProject_Save(monkeypatch, mockGUI, mockRnd, fncPath): project.closeProject() -@pytest.mark.core -def testCoreProject_AccessItems(mockGUI, fncPath, mockRnd): - """Test helper functions for the project folder.""" - project = NWProject() - buildTestProject(project, fncPath) - - # Storage Objects - assert isinstance(project.index, NWIndex) - assert isinstance(project.tree, NWTree) - assert isinstance(project.options, OptionState) - - # Move Novel ROOT to after its files - oldOrder = [ - C.hNovelRoot, - C.hPlotRoot, - C.hCharRoot, - C.hWorldRoot, - C.hTitlePage, - C.hChapterDir, - C.hChapterDoc, - C.hSceneDoc, - ] - newOrder = [ - C.hTitlePage, - C.hChapterDoc, - C.hSceneDoc, - C.hChapterDir, - C.hNovelRoot, - C.hPlotRoot, - C.hCharRoot, - C.hWorldRoot, - ] - assert project.tree.handles() == oldOrder - project.setTreeOrder(newOrder) - assert project.tree.handles() == newOrder - - # Add a non-existing item - project.tree._order.append(C.hInvalid) - - # Add an item with a non-existent parent - nHandle = project.newFile("Test File", C.hChapterDir) - nItem = project.tree[nHandle] - assert isinstance(nItem, NWItem) - nItem.setParent("cba9876543210") - assert nItem.itemParent == "cba9876543210" - - retOrder = [] - for tItem in project.iterProjectItems(): - retOrder.append(tItem.itemHandle) - - assert retOrder == [ - C.hNovelRoot, - C.hPlotRoot, - C.hCharRoot, - C.hWorldRoot, - nHandle, - C.hTitlePage, - C.hChapterDir, - C.hChapterDoc, - C.hSceneDoc, - ] - assert nItem.itemParent is None - - @pytest.mark.core def testCoreProject_Methods(monkeypatch, mockGUI, fncPath, mockRnd): """Test other project class methods and functions.""" @@ -411,13 +343,6 @@ def testCoreProject_Methods(monkeypatch, mockGUI, fncPath, mockRnd): mp.setattr("novelwriter.core.project.time", lambda: 1600005600) assert project.currentEditTime == 6834 - # Trash folder - # Should create on first call, and just returned on later calls - hTrash = "0000000000010" - assert project.tree[hTrash] is None - assert project.trashFolder() == hTrash - assert project.trashFolder() == hTrash - # Spell check project.setProjectChanged(False) project.data.setSpellCheck(True) @@ -480,23 +405,6 @@ def testCoreProject_Methods(monkeypatch, mockGUI, fncPath, mockRnd): assert project.data.autoReplace == {"A": "B", "C": "D"} assert project.projChanged - # Change project tree order - oldOrder = [ - "0000000000008", "0000000000009", "000000000000a", - "000000000000b", "000000000000c", "000000000000d", - "000000000000e", "000000000000f", "0000000000010", - ] - newOrder = [ - "000000000000b", "000000000000c", "000000000000d", - "0000000000008", "0000000000009", "000000000000a", - "000000000000e", "000000000000f", - ] - assert project.tree.handles() == oldOrder - project.setTreeOrder(newOrder) - assert project.tree.handles() == newOrder - project.setTreeOrder(oldOrder) - assert project.tree.handles() == oldOrder - @pytest.mark.core def testCoreProject_Backup(monkeypatch, mockGUI, fncPath, tstPaths): diff --git a/tests/test_dialogs/test_dlg_docsplit.py b/tests/test_dialogs/test_dlg_docsplit.py index 01ad8436..e8709d90 100644 --- a/tests/test_dialogs/test_dlg_docsplit.py +++ b/tests/test_dialogs/test_dlg_docsplit.py @@ -38,8 +38,6 @@ def testDlgSplit_Main(qtbot, monkeypatch, nwGUI, projPath, mockRnd): buildTestProject(nwGUI, projPath) project = SHARED.project - projTree = nwGUI.projView.projTree - docText = ( "Text\n\n" "##! Prologue\n\nText\n\n" @@ -58,7 +56,6 @@ def testDlgSplit_Main(qtbot, monkeypatch, nwGUI, projPath, mockRnd): hSplitDoc = project.newFile("Split Doc", C.hNovelRoot) assert hSplitDoc is not None project.writeNewFile(hSplitDoc, 1, True, docText) - projTree.revealNewTreeItem(hSplitDoc, nHandle=C.hNovelRoot, wordCount=True) docText = f"# Split Doc\n\n{docText}" diff --git a/tests/test_formats/test_fmt_todocx.py b/tests/test_formats/test_fmt_todocx.py index 53e9fd58..4acab27a 100644 --- a/tests/test_formats/test_fmt_todocx.py +++ b/tests/test_formats/test_fmt_todocx.py @@ -661,7 +661,7 @@ def testFmtToDocX_SaveDocument(mockGUI, prjLipsum, fncPath, tstPaths): (0, True), (1, True), (2, True), (3, True), (4, True), (5, False), (6, True), (7, True), (8, True), (9, False), (10, False), (11, True), (12, True), (13, True), (14, True), (15, True), (16, True), (17, True), - (18, True), (19, True), (20, True), + (18, True), (19, True), (20, True), (21, False), ] assert docPath.exists() diff --git a/tests/test_gui/test_gui_doceditor.py b/tests/test_gui/test_gui_doceditor.py index 0f1fc5c2..5ca249ae 100644 --- a/tests/test_gui/test_gui_doceditor.py +++ b/tests/test_gui/test_gui_doceditor.py @@ -1615,7 +1615,6 @@ def testGuiEditor_Tags(qtbot, nwGUI, projPath, ipsumText, mockRnd): assert nwGUI.openDocument(cHandle) is True docEditor.replaceText(text) nwGUI.saveDocument() - assert nwGUI.projView.projTree.revealNewTreeItem(cHandle) # Follow Tag # ========== @@ -1715,7 +1714,6 @@ def testGuiEditor_Completer(qtbot, nwGUI, projPath, mockRnd): assert nwGUI.openDocument(cHandle) is True docEditor.replaceText(text) nwGUI.saveDocument() - assert nwGUI.projView.projTree.revealNewTreeItem(cHandle) docEditor.replaceText("") completer = docEditor._completer diff --git a/tests/test_gui/test_gui_docviewer.py b/tests/test_gui/test_gui_docviewer.py index 4f391cd8..afcad9a2 100644 --- a/tests/test_gui/test_gui_docviewer.py +++ b/tests/test_gui/test_gui_docviewer.py @@ -52,8 +52,8 @@ def testGuiViewer_Main(qtbot, monkeypatch, nwGUI, prjLipsum): assert docViewer.loadText("b3643d0f92e32") is False # Middle-click the selected item - item = nwGUI.projView.projTree._getTreeItem("88243afbe5ed8") - rect = nwGUI.projView.projTree.visualItemRect(item) + index = SHARED.project.tree.model.indexFromHandle("88243afbe5ed8") + rect = nwGUI.projView.projTree.visualRect(index) qtbot.mouseClick(nwGUI.projView.projTree.viewport(), Qt.MidButton, pos=rect.center()) assert docViewer.docHandle == "88243afbe5ed8" diff --git a/tests/test_gui/test_gui_docviewerpanel.py b/tests/test_gui/test_gui_docviewerpanel.py index e6c1ca7e..5456a427 100644 --- a/tests/test_gui/test_gui_docviewerpanel.py +++ b/tests/test_gui/test_gui_docviewerpanel.py @@ -39,7 +39,7 @@ def testGuiViewerPanel_BackRefs(qtbot, monkeypatch, nwGUI, projPath, mockRnd): buildTestProject(nwGUI, projPath) projTree = nwGUI.projView.projTree - projTree._getTreeItem(C.hChapterDir).setExpanded(True) + projTree.expandAll() viewPanel = nwGUI.docViewerPanel tabBackRefs = viewPanel.tabBackRefs @@ -128,7 +128,7 @@ def testGuiViewerPanel_Tags(qtbot, monkeypatch, caplog, nwGUI, projPath, mockRnd buildTestProject(nwGUI, projPath) projTree = nwGUI.projView.projTree - projTree._getTreeItem(C.hChapterDir).setExpanded(True) + projTree.expandAll() viewPanel = nwGUI.docViewerPanel nwGUI.openDocument(C.hSceneDoc) diff --git a/tests/test_gui/test_gui_guimain.py b/tests/test_gui/test_gui_guimain.py index 8bdbc45e..596183f6 100644 --- a/tests/test_gui/test_gui_guimain.py +++ b/tests/test_gui/test_gui_guimain.py @@ -144,7 +144,7 @@ def testGuiMain_ProjectTreeItems(qtbot, monkeypatch, nwGUI, projPath, mockRnd): with monkeypatch.context() as mp: mp.setattr(GuiProjectTree, "hasFocus", lambda *a: True) assert nwGUI.docEditor.docHandle is None - nwGUI.projView.projTree._getTreeItem(sHandle).setSelected(True) + nwGUI.projView.projTree.setSelectedHandle(sHandle) nwGUI._keyPressReturn() assert nwGUI.docEditor.docHandle == sHandle nwGUI.closeDocument() @@ -711,7 +711,6 @@ def testGuiMain_Features(qtbot, monkeypatch, nwGUI, projPath, mockRnd): cHandle = SHARED.project.newFile("Jane", C.hCharRoot) newDoc = SHARED.project.storage.getDocument(cHandle) newDoc.writeDocument("# Jane\n\n@tag: Jane\n\n") - nwGUI.projView.projTree.revealNewTreeItem(cHandle) nwGUI.rebuildIndex(beQuiet=True) assert SHARED.focusMode is False diff --git a/tests/test_gui/test_gui_mainmenu.py b/tests/test_gui/test_gui_mainmenu.py index fced796e..507fad2a 100644 --- a/tests/test_gui/test_gui_mainmenu.py +++ b/tests/test_gui/test_gui_mainmenu.py @@ -374,7 +374,6 @@ def testGuiMainMenu_Insert(qtbot, monkeypatch, nwGUI, fncPath, projPath, mockRnd """Test the Insert menu.""" buildTestProject(nwGUI, projPath) - assert nwGUI.projView.projTree._getTreeItem(C.hSceneDoc) is not None assert nwGUI.openDocument(C.hSceneDoc) is True mainMenu = nwGUI.mainMenu docEditor = nwGUI.docEditor diff --git a/tests/test_gui/test_gui_noveltree.py b/tests/test_gui/test_gui_noveltree.py index f71c7e53..04c80b2e 100644 --- a/tests/test_gui/test_gui_noveltree.py +++ b/tests/test_gui/test_gui_noveltree.py @@ -46,7 +46,7 @@ def testGuiNovelTree_TreeItems(qtbot, monkeypatch, nwGUI, projPath, mockRnd): nwGUI._switchFocus(nwFocus.TREE) nwGUI.projView.projTree.clearSelection() - nwGUI.projView.projTree._getTreeItem(C.hCharRoot).setSelected(True) + nwGUI.projView.projTree.setSelectedHandle(C.hCharRoot) nwGUI.projView.projTree.newTreeItem(nwItemType.FILE) contentPath = SHARED.project.storage.contentPath diff --git a/tests/test_gui/test_gui_outline.py b/tests/test_gui/test_gui_outline.py index be762fc5..e92b5a01 100644 --- a/tests/test_gui/test_gui_outline.py +++ b/tests/test_gui/test_gui_outline.py @@ -198,7 +198,6 @@ def testGuiOutline_Content(qtbot, monkeypatch, nwGUI, prjLipsum, fncPath, tstPat # Add a second novel folder newHandle = SHARED.project.newRoot(nwItemClass.NOVEL) - nwGUI.projView.projTree.revealNewTreeItem(newHandle) # Check new values in dropdown list assert outlineBar.novelValue.itemData(0) == lipHandle @@ -217,7 +216,6 @@ def testGuiOutline_Content(qtbot, monkeypatch, nwGUI, prjLipsum, fncPath, tstPat aHandle = SHARED.project.newFile(dTitle, newHandle) hHash = "#"*hLevel writeFile(prjLipsum / "content" / f"{aHandle}.nwd", f"{hHash} {dTitle}\n\n") - nwGUI.projView.projTree.revealNewTreeItem(aHandle) nwGUI.rebuildIndex() diff --git a/tests/test_gui/test_gui_projtree.py b/tests/test_gui/test_gui_projtree.py index 903b5f80..f5c65a46 100644 --- a/tests/test_gui/test_gui_projtree.py +++ b/tests/test_gui/test_gui_projtree.py @@ -742,29 +742,28 @@ def testGuiProjTree_Duplicate(qtbot, monkeypatch, nwGUI: GuiMain, projPath, mock assert len(SHARED.project.tree) == 8 projTree = nwGUI.projView.projTree - projTree._getTreeItem(C.hNovelRoot).setExpanded(True) # type: ignore - projTree._getTreeItem(C.hChapterDir).setExpanded(True) # type: ignore + projTree.expandAll() # Nothing to do - assert projTree._duplicateFromHandle(C.hInvalid) is False + assert projTree.duplicateFromHandle(C.hInvalid) is False assert len(SHARED.project.tree) == 8 # Duplicate title page, but select no with monkeypatch.context() as mp: mp.setattr(QMessageBox, "result", lambda *a: QMessageBox.StandardButton.No) - assert projTree._duplicateFromHandle(C.hTitlePage) is False + assert projTree.duplicateFromHandle(C.hTitlePage) is False assert len(SHARED.project.tree) == 8 # Duplicate title page - assert projTree._duplicateFromHandle(C.hTitlePage) is True + assert projTree.duplicateFromHandle(C.hTitlePage) is True assert len(SHARED.project.tree) == 9 # Duplicate folder - assert projTree._duplicateFromHandle(C.hChapterDir) is True + assert projTree.duplicateFromHandle(C.hChapterDir) is True assert len(SHARED.project.tree) == 12 # Duplicate novel root - assert projTree._duplicateFromHandle(C.hNovelRoot) is True + assert projTree.duplicateFromHandle(C.hNovelRoot) is True assert len(SHARED.project.tree) == 21 # Check tree order that all items are next to each other @@ -783,7 +782,7 @@ def testGuiProjTree_Duplicate(qtbot, monkeypatch, nwGUI: GuiMain, projPath, mock # Should only create the folder, and skip the two files because the # next handle is already a file - assert projTree._duplicateFromHandle(C.hChapterDir) is True + assert projTree.duplicateFromHandle(C.hChapterDir) is True assert len(SHARED.project.tree) == 22 # qtbot.stop() @@ -801,7 +800,7 @@ def testGuiProjTree_AutoScroll(qtbot, monkeypatch, nwGUI: GuiMain, projPath, moc monkeypatch.setattr(QTimer, "start", lambda *a: None) projTree.setSelectedHandle(C.hChapterDir, True) - projTree._getTreeItem(C.hChapterDir).setExpanded(True) # type: ignore + projTree.expandAll() for i in range(100): projTree.newTreeItem(nwItemType.FILE, None, 3, False) diff --git a/tests/test_gui/test_gui_statusbar.py b/tests/test_gui/test_gui_statusbar.py index 15e66921..48649ba9 100644 --- a/tests/test_gui/test_gui_statusbar.py +++ b/tests/test_gui/test_gui_statusbar.py @@ -37,7 +37,6 @@ def testGuiStatusBar_Main(qtbot, nwGUI, projPath, mockRnd): cHandle = SHARED.project.newFile("A Note", C.hCharRoot) newDoc = SHARED.project.storage.getDocument(cHandle) newDoc.writeDocument("# A Note\n\n") - nwGUI.projView.projTree.revealNewTreeItem(cHandle) nwGUI.rebuildIndex(beQuiet=True) # Reference Time diff --git a/tests/test_tools/test_tools_manussettings.py b/tests/test_tools/test_tools_manussettings.py index fcbda573..354a731c 100644 --- a/tests/test_tools/test_tools_manussettings.py +++ b/tests/test_tools/test_tools_manussettings.py @@ -167,6 +167,7 @@ def testToolBuildSettings_Filter(qtbot, nwGUI, projPath, mockRnd): C.hCharRoot: (False, FilterMode.SKIPPED), hCharDoc: (False, FilterMode.FILTERED), C.hWorldRoot: (False, FilterMode.SKIPPED), + C.hTrashRoot: (False, FilterMode.SKIPPED), } # Switch on note docs @@ -182,6 +183,7 @@ def testToolBuildSettings_Filter(qtbot, nwGUI, projPath, mockRnd): C.hCharRoot: (False, FilterMode.SKIPPED), hCharDoc: (True, FilterMode.FILTERED), # Now enabled C.hWorldRoot: (False, FilterMode.SKIPPED), + C.hTrashRoot: (False, FilterMode.SKIPPED), } # Switch on inactive docs @@ -197,6 +199,7 @@ def testToolBuildSettings_Filter(qtbot, nwGUI, projPath, mockRnd): C.hCharRoot: (False, FilterMode.SKIPPED), hCharDoc: (True, FilterMode.FILTERED), C.hWorldRoot: (False, FilterMode.SKIPPED), + C.hTrashRoot: (False, FilterMode.SKIPPED), } # Set chapter and scene docs to included @@ -214,6 +217,7 @@ def testToolBuildSettings_Filter(qtbot, nwGUI, projPath, mockRnd): C.hCharRoot: (False, FilterMode.SKIPPED), hCharDoc: (True, FilterMode.FILTERED), C.hWorldRoot: (False, FilterMode.SKIPPED), + C.hTrashRoot: (False, FilterMode.SKIPPED), } # Set char and plot docs to excluded @@ -232,6 +236,7 @@ def testToolBuildSettings_Filter(qtbot, nwGUI, projPath, mockRnd): C.hCharRoot: (False, FilterMode.SKIPPED), hCharDoc: (False, FilterMode.EXCLUDED), # Now excluded C.hWorldRoot: (False, FilterMode.SKIPPED), + C.hTrashRoot: (False, FilterMode.SKIPPED), } # Switch on novel docs @@ -247,6 +252,7 @@ def testToolBuildSettings_Filter(qtbot, nwGUI, projPath, mockRnd): C.hCharRoot: (False, FilterMode.SKIPPED), hCharDoc: (False, FilterMode.EXCLUDED), C.hWorldRoot: (False, FilterMode.SKIPPED), + C.hTrashRoot: (False, FilterMode.SKIPPED), } # Selecting only novel root should iterate through all children @@ -264,6 +270,7 @@ def testToolBuildSettings_Filter(qtbot, nwGUI, projPath, mockRnd): C.hCharRoot: (False, FilterMode.SKIPPED), hCharDoc: (False, FilterMode.EXCLUDED), C.hWorldRoot: (False, FilterMode.SKIPPED), + C.hTrashRoot: (False, FilterMode.SKIPPED), } # Set everything back to filtered @@ -284,6 +291,7 @@ def testToolBuildSettings_Filter(qtbot, nwGUI, projPath, mockRnd): C.hCharRoot: (False, FilterMode.SKIPPED), hCharDoc: (True, FilterMode.FILTERED), C.hWorldRoot: (False, FilterMode.SKIPPED), + C.hTrashRoot: (False, FilterMode.SKIPPED), } # Check handling of invalid project items diff --git a/tests/tools.py b/tests/tools.py index bb34ada2..547c83e3 100644 --- a/tests/tools.py +++ b/tests/tools.py @@ -52,6 +52,7 @@ class C: hInvalid = "0000000000000" hNovelRoot = "0000000000008" hPlotRoot = "0000000000009" + hTrashRoot = "0000000000010" hCharRoot = "000000000000a" hWorldRoot = "000000000000b" hTitlePage = "000000000000c"