From e0ca2e7fb5cd742fd4dcebffbbbcf74db77fbd2e Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Tue, 15 Nov 2022 16:50:41 +0100 Subject: [PATCH] Update tests and remove unused functions in viewer --- novelwriter/gui/docviewer.py | 39 +++---------------- .../guiEditor_Main_Final_nwProject.nwx | 16 +++----- tests/test_gui/test_gui_doceditor.py | 12 +++--- tests/test_gui/test_gui_docviewer.py | 17 +++----- tests/test_gui/test_gui_guimain.py | 11 ------ 5 files changed, 24 insertions(+), 71 deletions(-) diff --git a/novelwriter/gui/docviewer.py b/novelwriter/gui/docviewer.py index e498a100..a25fad6d 100644 --- a/novelwriter/gui/docviewer.py +++ b/novelwriter/gui/docviewer.py @@ -323,43 +323,10 @@ class GuiDocViewer(QTextBrowser): return - ## - # Properties - ## - - def docHandle(self): - """Return the handle of the currently open document. Returns - None if no document is open. - """ - return self._docHandle - ## # Setters ## - def setCursorPosition(self, thePosition): - """Move the cursor to a given position in the document. - """ - if not isinstance(thePosition, int): - return False - if thePosition >= 0: - theCursor = self.textCursor() - theCursor.setPosition(thePosition) - self.setTextCursor(theCursor) - return True - - def setCursorLine(self, theLine): - """Move the cursor to a given line in the document. - """ - if not isinstance(theLine, int): - return False - if theLine >= 0: - theBlock = self.document().findBlockByLineNumber(theLine) - if theBlock: - self.setCursorPosition(theBlock.position()) - logger.debug("Cursor moved to line %d", theLine) - return True - def setScrollPosition(self, thePos): """Set the scrollbar position. """ @@ -372,6 +339,12 @@ class GuiDocViewer(QTextBrowser): # Getters ## + def docHandle(self): + """Return the handle of the currently open document. Returns + None if no document is open. + """ + return self._docHandle + def getScrollPosition(self): """Get the scrollbar position. Returns 0 if no scrollbar. """ diff --git a/tests/reference/guiEditor_Main_Final_nwProject.nwx b/tests/reference/guiEditor_Main_Final_nwProject.nwx index e384ef9e..dc0456a7 100644 --- a/tests/reference/guiEditor_Main_Final_nwProject.nwx +++ b/tests/reference/guiEditor_Main_Final_nwProject.nwx @@ -1,6 +1,6 @@ - - + + New Project New Novel Jane Doe @@ -11,9 +11,9 @@ None 000000000000f - None + 000000000000f 0000000000008 - 0000000000008 + None @@ -30,13 +30,13 @@ Finished - New + New Minor Major Main - + Novel @@ -81,9 +81,5 @@ New Note - - - Trash - diff --git a/tests/test_gui/test_gui_doceditor.py b/tests/test_gui/test_gui_doceditor.py index 017c955c..3de027df 100644 --- a/tests/test_gui/test_gui_doceditor.py +++ b/tests/test_gui/test_gui_doceditor.py @@ -211,7 +211,7 @@ def testGuiEditor_MetaData(qtbot, nwGUI, projPath, mockRnd): assert nwGUI.theProject.tree[C.hSceneDoc].cursorPos == 10 assert nwGUI.docEditor.setCursorLine(None) is False - assert nwGUI.docEditor.setCursorLine(2) is True + assert nwGUI.docEditor.setCursorLine(3) is True assert nwGUI.docEditor.getCursorPosition() == 15 # Document Changed Signal @@ -510,7 +510,7 @@ def testGuiEditor_Insert(qtbot, monkeypatch, nwGUI, projPath, ipsumText, mockRnd theText = "### A Scene\n\n\n%s" % ipsumText[0] assert nwGUI.docEditor.replaceText(theText) is True - assert nwGUI.docEditor.setCursorLine(2) + assert nwGUI.docEditor.setCursorLine(3) # Invalid Keyword assert nwGUI.docEditor.insertKeyWord("stuff") is False @@ -1049,10 +1049,10 @@ def testGuiEditor_BlockFormatting(qtbot, monkeypatch, nwGUI, projPath, ipsumText assert nwGUI.docEditor.getText() == "Title\n\n" assert nwGUI.docEditor.getCursorPosition() == 5 - # Second Line + # Third Line # This also needs to add a new block assert nwGUI.docEditor.replaceText("#### Title\n\nThe Text\n\n") is True - assert nwGUI.docEditor.setCursorLine(2) is True + assert nwGUI.docEditor.setCursorLine(3) is True assert nwGUI.docEditor._formatBlock(nwDocAction.BLOCK_COM) is True assert nwGUI.docEditor.getText() == "#### Title\n\n% The Text\n\n" @@ -1086,11 +1086,11 @@ def testGuiEditor_Tags(qtbot, nwGUI, projPath, ipsumText, mockRnd): assert nwGUI.openDocument(C.hSceneDoc) is True # Empty Block - assert nwGUI.docEditor.setCursorLine(1) is True + assert nwGUI.docEditor.setCursorLine(2) is True assert nwGUI.docEditor._followTag() is False # Not On Tag - assert nwGUI.docEditor.setCursorLine(0) is True + assert nwGUI.docEditor.setCursorLine(1) is True assert nwGUI.docEditor._followTag() is False # On Tag Keyword diff --git a/tests/test_gui/test_gui_docviewer.py b/tests/test_gui/test_gui_docviewer.py index 22057e15..f7c2d766 100644 --- a/tests/test_gui/test_gui_docviewer.py +++ b/tests/test_gui/test_gui_docviewer.py @@ -57,17 +57,10 @@ def testGuiViewer_Main(qtbot, monkeypatch, nwGUI, nwLipsum): nwGUI.docViewer.docHeader._refreshDocument() assert nwGUI.docViewer.toPlainText() == origText - # Cursor line - assert nwGUI.docViewer.setCursorLine("not a number") is False - assert nwGUI.docViewer.setCursorLine(3) is True - theCursor = nwGUI.docViewer.textCursor() - assert theCursor.position() == 40 - - # Cursor position - assert nwGUI.docViewer.setCursorPosition("not a number") is False - assert nwGUI.docViewer.setCursorPosition(100) is True - # Select word + theCursor = nwGUI.docViewer.textCursor() + theCursor.setPosition(100) + nwGUI.docViewer.setTextCursor(theCursor) nwGUI.docViewer._makeSelection(QTextCursor.WordUnderCursor) qClip = qApp.clipboard() @@ -113,7 +106,9 @@ def testGuiViewer_Main(qtbot, monkeypatch, nwGUI, nwLipsum): nwGUI.mainMenu.aViewDoc.activate(QAction.Trigger) # Select "Bod" link - assert nwGUI.docViewer.setCursorPosition(27) is True + theCursor = nwGUI.docViewer.textCursor() + theCursor.setPosition(27) + nwGUI.docViewer.setTextCursor(theCursor) nwGUI.docViewer._makeSelection(QTextCursor.WordUnderCursor) theRect = nwGUI.docViewer.cursorRect() # qtbot.mouseClick(nwGUI.docViewer.viewport(), Qt.LeftButton, pos=theRect.center(), delay=100) diff --git a/tests/test_gui/test_gui_guimain.py b/tests/test_gui/test_gui_guimain.py index 43ac328f..da1902da 100644 --- a/tests/test_gui/test_gui_guimain.py +++ b/tests/test_gui/test_gui_guimain.py @@ -515,17 +515,6 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, projPath, tstPaths, mockRnd): assert nwGUI.saveProject() assert nwGUI.closeDocViewer() - # Check a Quick Create and Delete - assert nwGUI.projView.projTree.newTreeItem(nwItemType.FILE, None) - newHandle = nwGUI.projView.getSelectedHandle() - assert newHandle == "0000000000013" - assert nwGUI.theProject.tree[newHandle] is not None - assert nwGUI.projView.requestDeleteItem() - assert nwGUI.projView.setSelectedHandle(newHandle) - assert nwGUI.projView.requestDeleteItem() - assert nwGUI.theProject.tree["0000000000014"] is not None # Trash - assert nwGUI.saveProject() - # Check the files projFile = projPath / "nwProject.nwx" testFile = tstPaths.outDir / "guiEditor_Main_Final_nwProject.nwx"