From 538b722bdf7750921df9668d2e2ab40ba2c98b09 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Tue, 14 Jun 2022 19:33:12 +0200 Subject: [PATCH] Fix tests and a few other bits --- novelwriter/gui/doceditor.py | 2 + novelwriter/gui/noveltree.py | 1 - sample/content/a520879ca0b45.nwd | 2 +- sample/content/edca4be2fcaf8.nwd | 2 +- tests/test_core/test_core_project.py | 2 +- tests/test_gui/test_gui_guimain.py | 12 ++--- tests/test_gui/test_gui_noveltree.py | 66 +++++----------------------- 7 files changed, 22 insertions(+), 65 deletions(-) diff --git a/novelwriter/gui/doceditor.py b/novelwriter/gui/doceditor.py index 25552037..0d32689e 100644 --- a/novelwriter/gui/doceditor.py +++ b/novelwriter/gui/doceditor.py @@ -511,11 +511,13 @@ class GuiDocEditor(QTextEdit): self.theProject.index.scanText(tHandle, docText) newHeader = self.theProject.index.getHandleHeaderLevel(tHandle) + # ToDo: This should be a signal if self._updateHeaders(checkLevel=True): self.mainGui.requestNovelTreeRefresh() else: self.mainGui.novelView.updateWordCounts(tHandle) + # ToDo: This should be a signal if oldHeader != newHeader: self.mainGui.projView.setTreeItemValues(tHandle) self.mainGui.itemDetails.updateViewBox(tHandle) diff --git a/novelwriter/gui/noveltree.py b/novelwriter/gui/noveltree.py index 33981243..336058a5 100644 --- a/novelwriter/gui/noveltree.py +++ b/novelwriter/gui/noveltree.py @@ -254,7 +254,6 @@ class GuiNovelToolBar(QWidget): """Build the novel root menu. """ self.mRoot.clear() - agRoot = QActionGroup(self.mRoot) for n, (tHandle, nwItem) in enumerate(self.theProject.tree.iterRoots(nwItemClass.NOVEL)): aRoot = self.mRoot.addAction(nwItem.itemName) diff --git a/sample/content/a520879ca0b45.nwd b/sample/content/a520879ca0b45.nwd index 12d7a62a..75ba39c8 100644 --- a/sample/content/a520879ca0b45.nwd +++ b/sample/content/a520879ca0b45.nwd @@ -1,7 +1,7 @@ %%~name: Chapter One %%~path: e5e47ebf63b1c/a520879ca0b45 %%~kind: NOVEL/DOCUMENT -### Chapter One +## Chapter One @pov: Jane diff --git a/sample/content/edca4be2fcaf8.nwd b/sample/content/edca4be2fcaf8.nwd index 3028b3fd..8b3efc78 100644 --- a/sample/content/edca4be2fcaf8.nwd +++ b/sample/content/edca4be2fcaf8.nwd @@ -3,4 +3,4 @@ %%~kind: NOVEL/DOCUMENT # Part One ->> In the beginning … << \ No newline at end of file +>> In the beginning … << diff --git a/tests/test_core/test_core_project.py b/tests/test_core/test_core_project.py index bdc27771..a6409b98 100644 --- a/tests/test_core/test_core_project.py +++ b/tests/test_core/test_core_project.py @@ -470,7 +470,7 @@ def testCoreProject_Open(monkeypatch, nwMinimal, mockGUI): writeFile(os.path.join(nwMinimal, "data_0", "123456789abc_main.bak"), "stuff") mockGUI.clear() assert theProject.openProject(nwMinimal) is True - assert "version 1.0" in mockGUI.lastAlert + assert "There was an error updating the project." in mockGUI.lastAlert assert theProject.closeProject() diff --git a/tests/test_gui/test_gui_guimain.py b/tests/test_gui/test_gui_guimain.py index b197885e..c308451b 100644 --- a/tests/test_gui/test_gui_guimain.py +++ b/tests/test_gui/test_gui_guimain.py @@ -29,7 +29,7 @@ from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QMessageBox, QInputDialog from novelwriter.gui import GuiDocEditor, GuiNovelView, GuiOutlineView -from novelwriter.enum import nwItemType, nwWidget +from novelwriter.enum import nwItemType, nwView, nwWidget from novelwriter.tools import GuiProjectWizard from novelwriter.gui.projtree import GuiProjectTree from novelwriter.dialogs import GuiEditLabel @@ -120,6 +120,7 @@ def testGuiMain_ProjectTreeItems(qtbot, monkeypatch, nwGUI, fncProj, mockRnd): assert nwGUI.openSelectedItem() is False # Project Tree has focus + nwGUI._changeView(nwView.PROJECT) nwGUI.switchFocus(nwWidget.TREE) nwGUI.projStack.setCurrentIndex(0) with monkeypatch.context() as mp: @@ -131,20 +132,19 @@ def testGuiMain_ProjectTreeItems(qtbot, monkeypatch, nwGUI, fncProj, mockRnd): assert nwGUI.closeDocument() is True # Novel Tree has focus - nwGUI.projStack.setCurrentIndex(1) + nwGUI._changeView(nwView.NOVEL) nwGUI.novelView.refreshTree(rootHandle=None, overRide=True) with monkeypatch.context() as mp: mp.setattr(GuiNovelView, "treeFocus", lambda *a: True) assert nwGUI.docEditor.docHandle() is None - actItem = nwGUI.novelView.novelTree.topLevelItem(0) - chpItem = actItem.child(0) - selItem = chpItem.child(0) + selItem = nwGUI.novelView.novelTree.topLevelItem(2) nwGUI.novelView.novelTree.setCurrentItem(selItem) nwGUI._keyPressReturn() assert nwGUI.docEditor.docHandle() == sHandle assert nwGUI.closeDocument() is True # Project Outline has focus + nwGUI._changeView(nwView.OUTLINE) nwGUI.switchFocus(nwWidget.OUTLINE) with monkeypatch.context() as mp: mp.setattr(GuiOutlineView, "treeFocus", lambda *a: True) @@ -157,7 +157,7 @@ def testGuiMain_ProjectTreeItems(qtbot, monkeypatch, nwGUI, fncProj, mockRnd): assert nwGUI.docEditor.docHandle() == sHandle assert nwGUI.closeDocument() is True - # qtbot.stopForInteraction() + # qtbot.stop() # END Test testGuiMain_ProjectTreeItems diff --git a/tests/test_gui/test_gui_noveltree.py b/tests/test_gui/test_gui_noveltree.py index b1e223cf..ea8b49bc 100644 --- a/tests/test_gui/test_gui_noveltree.py +++ b/tests/test_gui/test_gui_noveltree.py @@ -20,9 +20,6 @@ along with this program. If not, see . """ import pytest -import os - -from tools import writeFile from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QMessageBox @@ -40,9 +37,8 @@ def testGuiNovelTree_TreeItems(qtbot, monkeypatch, nwGUI, nwMinimal): novelView = nwGUI.novelView novelTree = novelView.novelTree - ## - # Show/Hide Scrollbars - ## + # Show/Hide Scrollbars + # ==================== nwGUI.mainConf.hideVScroll = True nwGUI.mainConf.hideHScroll = True @@ -56,14 +52,13 @@ def testGuiNovelTree_TreeItems(qtbot, monkeypatch, nwGUI, nwMinimal): assert novelTree.verticalScrollBar().isEnabled() assert novelTree.horizontalScrollBar().isEnabled() - ## - # Populate Tree - ## + # Populate Tree + # ============= nwGUI.projStack.setCurrentIndex(nwGUI.idxNovelView) nwGUI.rebuildIndex() novelTree._populateTree(rootHandle=None) - assert novelTree.topLevelItemCount() == 1 + assert novelTree.topLevelItemCount() == 3 # Rebuild should preserve selection topItem = novelTree.topLevelItem(0) @@ -75,13 +70,12 @@ def testGuiNovelTree_TreeItems(qtbot, monkeypatch, nwGUI, nwMinimal): novelView.refreshTree() assert novelTree.topLevelItem(0).isSelected() - ## - # Open Items - ## + # Open Items + # ========== # Clear selection novelTree.clearSelection() - scItem = novelTree.topLevelItem(0).child(0).child(0) + scItem = novelTree.topLevelItem(2) scItem.setSelected(True) assert scItem.isSelected() @@ -114,48 +108,10 @@ def testGuiNovelTree_TreeItems(qtbot, monkeypatch, nwGUI, nwMinimal): qtbot.mouseClick(vPort, Qt.MiddleButton, pos=scRect.center(), delay=10) assert nwGUI.docViewer.docHandle() == "8c659a11cd429" - ## - # Populate Tree - ## + # Close + # ===== - # Add weird titles to first file to check hnadling of non-standard - # order of title levels. - writeFile(os.path.join(nwMinimal, "content", "a35baf2e93843.nwd"), ( - "#### Section wo/Scene\n\n" - "### Scene wo/Chapter\n\n" - "## Chapter wo/Title\n\n" - "# Title\n\n" - "#### Section w/Title, wo/Scene\n\n" - "### Scene w/Title, wo/Chapter\n\n" - "## Chapter\n\n" - "#### Section w/Chapter, wo/Scene\n\n" - "### Scene\n\n" - "#### Section\n\n" - )) - nwGUI.rebuildIndex() - novelTree._populateTree(None) - assert novelTree.topLevelItem(0).text(novelTree.C_TITLE) == "Section wo/Scene" - assert novelTree.topLevelItem(1).text(novelTree.C_TITLE) == "Scene wo/Chapter" - assert novelTree.topLevelItem(2).text(novelTree.C_TITLE) == "Chapter wo/Title" - assert novelTree.topLevelItem(3).text(novelTree.C_TITLE) == "Title" - - tTitle = novelTree.topLevelItem(3) - assert tTitle.child(0).text(novelTree.C_TITLE) == "Section w/Title, wo/Scene" - assert tTitle.child(1).text(novelTree.C_TITLE) == "Scene w/Title, wo/Chapter" - assert tTitle.child(2).text(novelTree.C_TITLE) == "Chapter" - - tChap = tTitle.child(2) - assert tChap.child(0).text(novelTree.C_TITLE) == "Section w/Chapter, wo/Scene" - assert tChap.child(1).text(novelTree.C_TITLE) == "Scene" - - tScene = tChap.child(1) - assert tScene.child(0).text(novelTree.C_TITLE) == "Section" - - ## - # Close - ## - - # qtbot.stopForInteraction() + # qtbot.stop() nwGUI.closeProject() # END Test testGuiNovelTree_TreeItems