From f1100d44758985ae617d0d89ace5c13f2324300f Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Tue, 1 Nov 2022 18:32:29 +0100 Subject: [PATCH] Remove minimal project from test suite --- tests/conftest.py | 21 ---- tests/minimal/content/8c659a11cd429.nwd | 5 - tests/minimal/content/a35baf2e93843.nwd | 6 -- tests/minimal/content/f5ab3e30151e1.nwd | 5 - tests/minimal/nwProject.nwx | 81 --------------- tests/test_core/test_core_document.py | 41 ++++---- tests/test_core/test_core_tokenizer.py | 27 +++-- tests/test_dialogs/test_dlg_projload.py | 10 +- tests/test_dialogs/test_dlg_wordlist.py | 10 +- tests/test_gui/test_gui_doceditor.py | 119 ++++++++++------------ tests/test_tools/test_tools_projwizard.py | 8 +- 11 files changed, 98 insertions(+), 235 deletions(-) delete mode 100644 tests/minimal/content/8c659a11cd429.nwd delete mode 100644 tests/minimal/content/a35baf2e93843.nwd delete mode 100644 tests/minimal/content/f5ab3e30151e1.nwd delete mode 100644 tests/minimal/nwProject.nwx diff --git a/tests/conftest.py b/tests/conftest.py index 12842add..50955a31 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -214,27 +214,6 @@ def mockRnd(monkeypatch): # Temp Project Folders ## -@pytest.fixture(scope="function") -def nwMinimal(tmpDir): - """A minimal novelWriter example project. - """ - tstDir = os.path.dirname(__file__) - srcDir = os.path.join(tstDir, "minimal") - dstDir = os.path.join(tmpDir, "minimal") - if os.path.isdir(dstDir): - shutil.rmtree(dstDir) - - shutil.copytree(srcDir, dstDir) - cleanProject(dstDir) - - yield dstDir - - if os.path.isdir(dstDir): - shutil.rmtree(dstDir) - - return - - @pytest.fixture(scope="function") def nwLipsum(tmpDir): """A medium sized novelWriter example project with a lot of Lorem diff --git a/tests/minimal/content/8c659a11cd429.nwd b/tests/minimal/content/8c659a11cd429.nwd deleted file mode 100644 index 2d7072eb..00000000 --- a/tests/minimal/content/8c659a11cd429.nwd +++ /dev/null @@ -1,5 +0,0 @@ -%%~name: New Scene -%%~path: a6d311a93600a/8c659a11cd429 -%%~kind: NOVEL/DOCUMENT -### New Scene - diff --git a/tests/minimal/content/a35baf2e93843.nwd b/tests/minimal/content/a35baf2e93843.nwd deleted file mode 100644 index b328746c..00000000 --- a/tests/minimal/content/a35baf2e93843.nwd +++ /dev/null @@ -1,6 +0,0 @@ -%%~name: Title Page -%%~path: a508bb932959c/a35baf2e93843 -%%~kind: NOVEL/DOCUMENT -#! Minimal - ->> By Jane Doe, John Doh << diff --git a/tests/minimal/content/f5ab3e30151e1.nwd b/tests/minimal/content/f5ab3e30151e1.nwd deleted file mode 100644 index b4bbf9c6..00000000 --- a/tests/minimal/content/f5ab3e30151e1.nwd +++ /dev/null @@ -1,5 +0,0 @@ -%%~name: New Chapter -%%~path: a6d311a93600a/f5ab3e30151e1 -%%~kind: NOVEL/DOCUMENT -## New Chapter - diff --git a/tests/minimal/nwProject.nwx b/tests/minimal/nwProject.nwx deleted file mode 100644 index 19689fac..00000000 --- a/tests/minimal/nwProject.nwx +++ /dev/null @@ -1,81 +0,0 @@ - - - - Test Minimal - Minimal - Jane Doe - John Doh - 25 - 2 - 203 - - - True - en_GB - False - None - 10 - 10 - 0 - - None - None - a508bb932959c - None - - - - %title% - Chapter %ch%: %title% - %title% - * * * - - - - New - Note - Draft - Finished - - - New - Minor - Major - Main - - - - - - Novel - - - - Title Page - - - - New Chapter - - - - New Chapter - - - - New Scene - - - - Plot - - - - Characters - - - - World - - - diff --git a/tests/test_core/test_core_document.py b/tests/test_core/test_core_document.py index ecc23e9c..761859ef 100644 --- a/tests/test_core/test_core_document.py +++ b/tests/test_core/test_core_document.py @@ -23,7 +23,7 @@ import os import pytest from mock import causeOSError -from tools import readFile, writeFile +from tools import C, buildTestProject, readFile, writeFile from novelwriter.enum import nwItemClass, nwItemLayout from novelwriter.core.project import NWProject @@ -31,14 +31,12 @@ from novelwriter.core.document import NWDoc @pytest.mark.core -def testCoreDocument_LoadSave(monkeypatch, mockGUI, nwMinimal): +def testCoreDocument_LoadSave(monkeypatch, mockGUI, fncDir, mockRnd): """Test loading and saving a document with the NWDoc class. """ theProject = NWProject(mockGUI) - assert theProject.openProject(nwMinimal) is True - assert theProject.projPath == nwMinimal - - sHandle = "8c659a11cd429" + mockRnd.reset() + buildTestProject(theProject, fncDir) # Read Document # ============= @@ -49,25 +47,23 @@ def testCoreDocument_LoadSave(monkeypatch, mockGUI, nwMinimal): assert theDoc.readDocument() is None # Non-existent handle - theDoc = NWDoc(theProject, "0000000000000") + theDoc = NWDoc(theProject, C.hInvalid) assert theDoc.readDocument() is None assert theDoc._currHash is None # Cause open() to fail while loading with monkeypatch.context() as mp: mp.setattr("builtins.open", causeOSError) - theDoc = NWDoc(theProject, sHandle) + theDoc = NWDoc(theProject, C.hSceneDoc) assert theDoc.readDocument() is None assert theDoc.getError() == "OSError: Mock OSError" # Load the text - theDoc = NWDoc(theProject, sHandle) + theDoc = NWDoc(theProject, C.hSceneDoc) assert theDoc.readDocument() == "### New Scene\n\n" # Try to open a new (non-existent) file - nHandle = theProject.tree.findRoot(nwItemClass.NOVEL) - assert nHandle is not None - xHandle = theProject.newFile("New File", nHandle) + xHandle = theProject.newFile("New File", C.hNovelRoot) theDoc = NWDoc(theProject, xHandle) assert bool(theDoc) is True assert repr(theDoc) == f"" @@ -86,10 +82,10 @@ def testCoreDocument_LoadSave(monkeypatch, mockGUI, nwMinimal): assert theDoc.writeDocument(theText) # Check file content - docPath = os.path.join(nwMinimal, "content", xHandle+".nwd") + docPath = os.path.join(fncDir, "content", xHandle+".nwd") assert readFile(docPath) == ( "%%~name: New File\n" - f"%%~path: a508bb932959c/{xHandle}\n" + f"%%~path: {C.hNovelRoot}/{xHandle}\n" "%%~kind: NOVEL/DOCUMENT\n" "### Test File\n\n" "Text ...\n\n" @@ -153,16 +149,15 @@ def testCoreDocument_LoadSave(monkeypatch, mockGUI, nwMinimal): @pytest.mark.core -def testCoreDocument_Methods(mockGUI, nwMinimal): +def testCoreDocument_Methods(mockGUI, fncDir, mockRnd): """Test other methods of the NWDoc class. """ theProject = NWProject(mockGUI) - assert theProject.openProject(nwMinimal) - assert theProject.projPath == nwMinimal + mockRnd.reset() + buildTestProject(theProject, fncDir) - sHandle = "8c659a11cd429" - theDoc = NWDoc(theProject, sHandle) - docPath = os.path.join(nwMinimal, "content", sHandle+".nwd") + theDoc = NWDoc(theProject, C.hSceneDoc) + docPath = os.path.join(fncDir, "content", C.hSceneDoc+".nwd") assert theDoc.readDocument() == "### New Scene\n\n" @@ -171,12 +166,12 @@ def testCoreDocument_Methods(mockGUI, nwMinimal): # Check the item assert theDoc.getCurrentItem() is not None - assert theDoc.getCurrentItem().itemHandle == sHandle + assert theDoc.getCurrentItem().itemHandle == C.hSceneDoc # Check the meta theName, theParent, theClass, theLayout = theDoc.getMeta() assert theName == "New Scene" - assert theParent == "a6d311a93600a" + assert theParent == C.hChapterDir assert theClass == nwItemClass.NOVEL assert theLayout == nwItemLayout.DOCUMENT @@ -184,7 +179,7 @@ def testCoreDocument_Methods(mockGUI, nwMinimal): assert theDoc.writeDocument("%%~ stuff\n### Test File\n\nText ...\n\n") assert readFile(docPath) == ( "%%~name: New Scene\n" - f"%%~path: a6d311a93600a/{sHandle}\n" + f"%%~path: {C.hChapterDir}/{C.hSceneDoc}\n" "%%~kind: NOVEL/DOCUMENT\n" "%%~ stuff\n" "### Test File\n\n" diff --git a/tests/test_core/test_core_tokenizer.py b/tests/test_core/test_core_tokenizer.py index fa3035d2..a1cc796f 100644 --- a/tests/test_core/test_core_tokenizer.py +++ b/tests/test_core/test_core_tokenizer.py @@ -22,7 +22,7 @@ along with this program. If not, see . import os import pytest -from tools import readFile +from tools import C, buildTestProject, readFile from novelwriter.core.project import NWProject from novelwriter.core.document import NWDoc @@ -133,21 +133,20 @@ def testCoreToken_Setters(mockGUI): @pytest.mark.core -def testCoreToken_TextOps(monkeypatch, nwMinimal, mockGUI): +def testCoreToken_TextOps(monkeypatch, mockGUI, mockRnd, fncDir): """Test handling files and text in the Tokenizer class. """ theProject = NWProject(mockGUI) + mockRnd.reset() + buildTestProject(theProject, fncDir) + theProject.data.setLanguage("en") theProject._loadProjectLocalisation() theToken = BareTokenizer(theProject) theToken.setKeepMarkdown(True) - assert theProject.openProject(nwMinimal) - sHandle = "8c659a11cd429" - # Set some content to work with - docText = ( "### Scene Six\n\n" "This is text with _italic text_, some **bold text**, some ~~deleted text~~, " @@ -157,7 +156,7 @@ def testCoreToken_TextOps(monkeypatch, nwMinimal, mockGUI): ) docTextR = docText.replace("", "this").replace("", "that") - nDoc = NWDoc(theProject, sHandle) + nDoc = NWDoc(theProject, C.hSceneDoc) assert nDoc.writeDocument(docText) theProject.data.setAutoReplace({"A": "this", "B": "that"}) @@ -166,17 +165,17 @@ def testCoreToken_TextOps(monkeypatch, nwMinimal, mockGUI): # Root Heading assert theToken.addRootHeading("stuff") is False - assert theToken.addRootHeading(sHandle) is False + assert theToken.addRootHeading(C.hSceneDoc) is False # First Page - assert theToken.addRootHeading("7695ce551d265") is True + assert theToken.addRootHeading(C.hPlotRoot) is True assert theToken.theMarkdown[-1] == "# Notes: Plot\n\n" assert theToken._theTokens[-1] == ( Tokenizer.T_TITLE, 0, "Notes: Plot", None, Tokenizer.A_CENTRE ) # Not First Page - assert theToken.addRootHeading("7695ce551d265") is True + assert theToken.addRootHeading(C.hPlotRoot) is True assert theToken.theMarkdown[-1] == "# Notes: Plot\n\n" assert theToken._theTokens[-1] == ( Tokenizer.T_TITLE, 0, "Notes: Plot", None, Tokenizer.A_CENTRE | Tokenizer.A_PBB @@ -184,18 +183,18 @@ def testCoreToken_TextOps(monkeypatch, nwMinimal, mockGUI): # Set Text assert theToken.setText("stuff") is False - assert theToken.setText(sHandle) is True + assert theToken.setText(C.hSceneDoc) is True assert theToken._theText == docText with monkeypatch.context() as mp: mp.setattr("novelwriter.constants.nwConst.MAX_DOCSIZE", 100) - assert theToken.setText(sHandle, docText) is True + assert theToken.setText(C.hSceneDoc, docText) is True assert theToken._theText == ( "# ERROR\n\n" "Document 'New Scene' is too big (0.00 MB). Skipping.\n\n" ) - assert theToken.setText(sHandle, docText) is True + assert theToken.setText(C.hSceneDoc, docText) is True assert theToken._theText == docText assert theToken._isNone is False @@ -212,7 +211,7 @@ def testCoreToken_TextOps(monkeypatch, nwMinimal, mockGUI): assert theToken.theResult == "This is text with escapes: ** ~~ __" # Save File - savePath = os.path.join(nwMinimal, "dump.nwd") + savePath = os.path.join(fncDir, "dump.nwd") theToken.saveRawMarkdown(savePath) assert readFile(savePath) == ( "# Notes: Plot\n\n" diff --git a/tests/test_dialogs/test_dlg_projload.py b/tests/test_dialogs/test_dlg_projload.py index 6e81ffe2..7ccf683a 100644 --- a/tests/test_dialogs/test_dlg_projload.py +++ b/tests/test_dialogs/test_dlg_projload.py @@ -22,7 +22,7 @@ along with this program. If not, see . import pytest import os -from tools import getGuiItem +from tools import buildTestProject, getGuiItem from PyQt5.QtCore import Qt from PyQt5.QtWidgets import ( @@ -33,10 +33,10 @@ from novelwriter.dialogs.projload import GuiProjectLoad @pytest.mark.gui -def testDlgLoadProject_Main(qtbot, monkeypatch, nwGUI, nwMinimal): +def testDlgLoadProject_Main(qtbot, monkeypatch, nwGUI, fncProj): """Test the load project wizard. """ - assert nwGUI.openProject(nwMinimal) + buildTestProject(nwGUI, fncProj) assert nwGUI.closeProject() monkeypatch.setattr(GuiProjectLoad, "exec_", lambda *a: None) @@ -87,10 +87,10 @@ def testDlgLoadProject_Main(qtbot, monkeypatch, nwGUI, nwMinimal): nwLoad._doDeleteRecent() assert nwLoad.listBox.topLevelItemCount() == recentCount - 1 - getFile = os.path.join(nwMinimal, "nwProject.nwx") + getFile = os.path.join(fncProj, "nwProject.nwx") monkeypatch.setattr(QFileDialog, "getOpenFileName", lambda *a, **k: (getFile, None)) qtbot.mouseClick(nwLoad.browseButton, Qt.LeftButton) - assert nwLoad.openPath == nwMinimal + assert nwLoad.openPath == fncProj assert nwLoad.openState == nwLoad.OPEN_STATE nwLoad.close() diff --git a/tests/test_dialogs/test_dlg_wordlist.py b/tests/test_dialogs/test_dlg_wordlist.py index 24d61157..3a088934 100644 --- a/tests/test_dialogs/test_dlg_wordlist.py +++ b/tests/test_dialogs/test_dlg_wordlist.py @@ -25,7 +25,7 @@ import pytest from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QDialog, QAction -from tools import writeFile, readFile, getGuiItem +from tools import buildTestProject, writeFile, readFile, getGuiItem from mock import causeOSError from novelwriter.constants import nwFiles @@ -33,16 +33,18 @@ from novelwriter.dialogs.wordlist import GuiWordList @pytest.mark.gui -def testDlgWordList_Dialog(qtbot, monkeypatch, nwGUI, nwMinimal): +def testDlgWordList_Dialog(qtbot, monkeypatch, nwGUI, fncProj): """test the word list editor. """ + buildTestProject(nwGUI, fncProj) + monkeypatch.setattr(GuiWordList, "exec_", lambda *a: None) monkeypatch.setattr(GuiWordList, "result", lambda *a: QDialog.Accepted) monkeypatch.setattr(GuiWordList, "accept", lambda *a: None) # Open project - nwGUI.openProject(nwMinimal) - dictFile = os.path.join(nwMinimal, "meta", nwFiles.PROJ_DICT) + nwGUI.openProject(fncProj) + dictFile = os.path.join(fncProj, "meta", nwFiles.PROJ_DICT) # Load the dialog nwGUI.mainMenu.aEditWordList.activate(QAction.Trigger) diff --git a/tests/test_gui/test_gui_doceditor.py b/tests/test_gui/test_gui_doceditor.py index 22a960c2..193fda9e 100644 --- a/tests/test_gui/test_gui_doceditor.py +++ b/tests/test_gui/test_gui_doceditor.py @@ -22,6 +22,7 @@ along with this program. If not, see . import pytest from mock import causeOSError +from tools import C, buildTestProject from PyQt5.QtCore import Qt from PyQt5.QtGui import QTextBlock, QTextCursor, QTextOption @@ -36,12 +37,12 @@ KEY_DELAY = 1 @pytest.mark.gui -def testGuiEditor_Init(qtbot, nwGUI, nwMinimal, ipsumText): +def testGuiEditor_Init(qtbot, nwGUI, fncProj, ipsumText, mockRnd): """Test initialising the editor. """ # Open project - assert nwGUI.openProject(nwMinimal) - assert nwGUI.openDocument("8c659a11cd429") + buildTestProject(nwGUI, fncProj) + assert nwGUI.openDocument(C.hSceneDoc) nwGUI.docEditor.setText("### Lorem Ipsum\n\n%s" % ipsumText[0]) assert nwGUI.saveDocument() @@ -79,13 +80,11 @@ def testGuiEditor_Init(qtbot, nwGUI, nwMinimal, ipsumText): @pytest.mark.gui -def testGuiEditor_LoadText(qtbot, monkeypatch, caplog, nwGUI, nwMinimal, ipsumText): +def testGuiEditor_LoadText(qtbot, monkeypatch, caplog, nwGUI, fncProj, ipsumText, mockRnd): """Test loading text into the editor. """ - # Open project - sHandle = "8c659a11cd429" - assert nwGUI.openProject(nwMinimal) is True - assert nwGUI.openDocument(sHandle) is True + buildTestProject(nwGUI, fncProj) + assert nwGUI.openDocument(C.hSceneDoc) is True longText = "### Lorem Ipsum\n\n%s" % "\n\n".join(ipsumText*20) nwGUI.docEditor.replaceText(longText) @@ -101,11 +100,11 @@ def testGuiEditor_LoadText(qtbot, monkeypatch, caplog, nwGUI, nwMinimal, ipsumTe # Document too big with monkeypatch.context() as mp: mp.setattr("novelwriter.constants.nwConst.MAX_DOCSIZE", 100) - assert nwGUI.docEditor.loadText(sHandle) is False + assert nwGUI.docEditor.loadText(C.hSceneDoc) is False assert "The document you are trying to open is too big." in caplog.text # Regular open - assert nwGUI.docEditor.loadText(sHandle) is True + assert nwGUI.docEditor.loadText(C.hSceneDoc) is True assert nwGUI.docEditor._bigDoc is False # Reload too big text @@ -116,18 +115,18 @@ def testGuiEditor_LoadText(qtbot, monkeypatch, caplog, nwGUI, nwMinimal, ipsumTe # Big doc handling nwGUI.mainConf.bigDocLimit = 50 - assert nwGUI.docEditor.loadText(sHandle) is True + assert nwGUI.docEditor.loadText(C.hSceneDoc) is True assert nwGUI.docEditor._bigDoc is True # Regular open, with line number - assert nwGUI.docEditor.loadText(sHandle, tLine=4) is True + assert nwGUI.docEditor.loadText(C.hSceneDoc, tLine=4) is True cursPos = nwGUI.docEditor.getCursorPosition() assert nwGUI.docEditor.document().findBlock(cursPos).blockNumber() == 4 # Load empty document nwGUI.docEditor.replaceText("") assert nwGUI.saveDocument() is True - assert nwGUI.docEditor.loadText(sHandle) is True + assert nwGUI.docEditor.loadText(C.hSceneDoc) is True assert nwGUI.docEditor.toPlainText() == "" # qtbot.stop() @@ -136,13 +135,11 @@ def testGuiEditor_LoadText(qtbot, monkeypatch, caplog, nwGUI, nwMinimal, ipsumTe @pytest.mark.gui -def testGuiEditor_SaveText(qtbot, monkeypatch, caplog, nwGUI, nwMinimal, ipsumText): +def testGuiEditor_SaveText(qtbot, monkeypatch, caplog, nwGUI, fncProj, ipsumText, mockRnd): """Test saving text from the editor. """ - # Open project - sHandle = "8c659a11cd429" - assert nwGUI.openProject(nwMinimal) is True - assert nwGUI.openDocument(sHandle) is True + buildTestProject(nwGUI, fncProj) + assert nwGUI.openDocument(C.hSceneDoc) is True # Save Text # ========= @@ -159,7 +156,7 @@ def testGuiEditor_SaveText(qtbot, monkeypatch, caplog, nwGUI, nwMinimal, ipsumTe # Unkown handle nwGUI.docEditor._docHandle = "0123456789abcdef" assert nwGUI.docEditor.saveText() is False - nwGUI.docEditor._docHandle = sHandle + nwGUI.docEditor._docHandle = C.hSceneDoc # Cause error when saving with monkeypatch.context() as mp: @@ -168,10 +165,10 @@ def testGuiEditor_SaveText(qtbot, monkeypatch, caplog, nwGUI, nwMinimal, ipsumTe assert "Could not save document." in caplog.text # Change header level - assert nwGUI.theProject.tree[sHandle].itemLayout == nwItemLayout.DOCUMENT + assert nwGUI.theProject.tree[C.hSceneDoc].itemLayout == nwItemLayout.DOCUMENT nwGUI.docEditor.replaceText(longText[1:]) assert nwGUI.docEditor.saveText() is True - assert nwGUI.theProject.tree[sHandle].itemLayout == nwItemLayout.DOCUMENT + assert nwGUI.theProject.tree[C.hSceneDoc].itemLayout == nwItemLayout.DOCUMENT # Regular save assert nwGUI.docEditor.saveText() is True @@ -182,13 +179,11 @@ def testGuiEditor_SaveText(qtbot, monkeypatch, caplog, nwGUI, nwMinimal, ipsumTe @pytest.mark.gui -def testGuiEditor_MetaData(qtbot, nwGUI, nwMinimal): +def testGuiEditor_MetaData(qtbot, nwGUI, fncProj, mockRnd): """Test extracting various meta data and other values. """ - # Open project - sHandle = "8c659a11cd429" - assert nwGUI.openProject(nwMinimal) is True - assert nwGUI.openDocument(sHandle) is True + buildTestProject(nwGUI, fncProj) + assert nwGUI.openDocument(C.hSceneDoc) is True # Get Text # This should replace line and paragraph separators, but preserve @@ -203,7 +198,7 @@ def testGuiEditor_MetaData(qtbot, nwGUI, nwMinimal): # Check Propertoes assert nwGUI.docEditor.docChanged() is True - assert nwGUI.docEditor.docHandle() == sHandle + assert nwGUI.docEditor.docHandle() == C.hSceneDoc assert nwGUI.docEditor.lastActive() > 0.0 assert nwGUI.docEditor.isEmpty() is False @@ -211,9 +206,9 @@ def testGuiEditor_MetaData(qtbot, nwGUI, nwMinimal): assert nwGUI.docEditor.setCursorPosition(None) is False assert nwGUI.docEditor.setCursorPosition(10) is True assert nwGUI.docEditor.getCursorPosition() == 10 - assert nwGUI.theProject.tree[sHandle].cursorPos != 10 + assert nwGUI.theProject.tree[C.hSceneDoc].cursorPos != 10 nwGUI.docEditor.saveCursorPosition() - assert nwGUI.theProject.tree[sHandle].cursorPos == 10 + assert nwGUI.theProject.tree[C.hSceneDoc].cursorPos == 10 assert nwGUI.docEditor.setCursorLine(None) is False assert nwGUI.docEditor.setCursorLine(2) is True @@ -231,16 +226,14 @@ def testGuiEditor_MetaData(qtbot, nwGUI, nwMinimal): @pytest.mark.gui -def testGuiEditor_Actions(qtbot, nwGUI, nwMinimal, ipsumText): +def testGuiEditor_Actions(qtbot, nwGUI, fncProj, ipsumText, mockRnd): """Test the document actions. This is not an extensive test of the action features, just that the actions are actually called. The various action features are tested when their respective functions are tested. """ - # Open project - sHandle = "8c659a11cd429" - assert nwGUI.openProject(nwMinimal) is True - assert nwGUI.openDocument(sHandle) is True + buildTestProject(nwGUI, fncProj) + assert nwGUI.openDocument(C.hSceneDoc) is True theText = "### A Scene\n\n%s" % "\n\n".join(ipsumText) assert nwGUI.docEditor.replaceText(theText) is True @@ -452,7 +445,7 @@ def testGuiEditor_Actions(qtbot, nwGUI, nwMinimal, ipsumText): # No Document Handle nwGUI.docEditor._docHandle = None assert nwGUI.docEditor.docAction(nwDocAction.BLOCK_TXT) is False - nwGUI.docEditor._docHandle = sHandle + nwGUI.docEditor._docHandle = C.hSceneDoc # Wrong Action Type assert nwGUI.docEditor.docAction(None) is False @@ -466,13 +459,11 @@ def testGuiEditor_Actions(qtbot, nwGUI, nwMinimal, ipsumText): @pytest.mark.gui -def testGuiEditor_Insert(qtbot, monkeypatch, nwGUI, nwMinimal, ipsumText): +def testGuiEditor_Insert(qtbot, monkeypatch, nwGUI, fncProj, ipsumText, mockRnd): """Test the document insert functions. """ - # Open project - sHandle = "8c659a11cd429" - assert nwGUI.openProject(nwMinimal) is True - assert nwGUI.openDocument(sHandle) is True + buildTestProject(nwGUI, fncProj) + assert nwGUI.openDocument(C.hSceneDoc) is True theText = "### A Scene\n\n%s" % "\n\n".join(ipsumText) assert nwGUI.docEditor.replaceText(theText) is True @@ -487,7 +478,7 @@ def testGuiEditor_Insert(qtbot, monkeypatch, nwGUI, nwMinimal, ipsumText): nwGUI.docEditor._docHandle = None assert nwGUI.docEditor.setCursorPosition(24) is True assert nwGUI.docEditor.insertText("Stuff") is False - nwGUI.docEditor._docHandle = sHandle + nwGUI.docEditor._docHandle = C.hSceneDoc # Insert String assert nwGUI.docEditor.setCursorPosition(24) is True @@ -551,13 +542,11 @@ def testGuiEditor_Insert(qtbot, monkeypatch, nwGUI, nwMinimal, ipsumText): @pytest.mark.gui -def testGuiEditor_TextManipulation(qtbot, monkeypatch, nwGUI, nwMinimal, ipsumText): +def testGuiEditor_TextManipulation(qtbot, monkeypatch, nwGUI, fncProj, ipsumText, mockRnd): """Test the text manipulation functions. """ - # Open project - sHandle = "8c659a11cd429" - assert nwGUI.openProject(nwMinimal) is True - assert nwGUI.openDocument(sHandle) is True + buildTestProject(nwGUI, fncProj) + assert nwGUI.openDocument(C.hSceneDoc) is True theText = "### A Scene\n\n%s" % "\n\n".join(ipsumText) assert nwGUI.docEditor.replaceText(theText) is True @@ -760,13 +749,11 @@ def testGuiEditor_TextManipulation(qtbot, monkeypatch, nwGUI, nwMinimal, ipsumTe @pytest.mark.gui -def testGuiEditor_BlockFormatting(qtbot, monkeypatch, nwGUI, nwMinimal, ipsumText): +def testGuiEditor_BlockFormatting(qtbot, monkeypatch, nwGUI, fncProj, ipsumText, mockRnd): """Test the block formatting function. """ - # Open project - sHandle = "8c659a11cd429" - assert nwGUI.openProject(nwMinimal) is True - assert nwGUI.openDocument(sHandle) is True + buildTestProject(nwGUI, fncProj) + assert nwGUI.openDocument(C.hSceneDoc) is True theText = "### A Scene\n\n%s" % "\n\n".join(ipsumText) assert nwGUI.docEditor.replaceText(theText) is True @@ -1075,13 +1062,11 @@ def testGuiEditor_BlockFormatting(qtbot, monkeypatch, nwGUI, nwMinimal, ipsumTex @pytest.mark.gui -def testGuiEditor_Tags(qtbot, nwGUI, nwMinimal, ipsumText): +def testGuiEditor_Tags(qtbot, nwGUI, fncProj, ipsumText, mockRnd): """Test the document editor tags functionality. """ - # Open project - sHandle = "8c659a11cd429" - assert nwGUI.openProject(nwMinimal) is True - assert nwGUI.openDocument(sHandle) is True + buildTestProject(nwGUI, fncProj) + assert nwGUI.openDocument(C.hSceneDoc) is True # Create Scene theText = "### A Scene\n\n@char: Jane, John\n\n" + ipsumText[0] + "\n\n" @@ -1089,7 +1074,7 @@ def testGuiEditor_Tags(qtbot, nwGUI, nwMinimal, ipsumText): # Create Character theText = "### Jane Doe\n\n@tag: Jane\n\n" + ipsumText[1] + "\n\n" - cHandle = nwGUI.theProject.newFile("Jane Doe", "afb3043c7b2b3") + cHandle = nwGUI.theProject.newFile("Jane Doe", C.hCharRoot) assert nwGUI.openDocument(cHandle) is True assert nwGUI.docEditor.replaceText(theText) is True assert nwGUI.saveDocument() is True @@ -1098,7 +1083,7 @@ def testGuiEditor_Tags(qtbot, nwGUI, nwMinimal, ipsumText): # Follow Tag # ========== - assert nwGUI.openDocument(sHandle) is True + assert nwGUI.openDocument(C.hSceneDoc) is True # Empty Block assert nwGUI.docEditor.setCursorLine(1) is True @@ -1136,7 +1121,7 @@ def testGuiEditor_Tags(qtbot, nwGUI, nwMinimal, ipsumText): @pytest.mark.gui -def testGuiEditor_WordCounters(qtbot, monkeypatch, nwGUI, nwMinimal, ipsumText): +def testGuiEditor_WordCounters(qtbot, monkeypatch, nwGUI, fncProj, ipsumText, mockRnd): """Test saving text from the editor. """ class MockThreadPool: @@ -1153,7 +1138,8 @@ def testGuiEditor_WordCounters(qtbot, monkeypatch, nwGUI, nwMinimal, ipsumText): nwGUI.threadPool = MockThreadPool() nwGUI.docEditor.wcTimerDoc.blockSignals(True) nwGUI.docEditor.wcTimerSel.blockSignals(True) - assert nwGUI.openProject(nwMinimal) is True + + buildTestProject(nwGUI, fncProj) # Run on an empty document nwGUI.docEditor._runDocCounter() @@ -1167,10 +1153,9 @@ def testGuiEditor_WordCounters(qtbot, monkeypatch, nwGUI, nwMinimal, ipsumText): assert nwGUI.docEditor.docFooter.wordsText.text() == "Words: 0 (+0)" # Open a document and populate it - sHandle = "8c659a11cd429" - nwGUI.theProject.tree[sHandle]._initCount = 0 # Clear item's count - nwGUI.theProject.tree[sHandle]._wordCount = 0 # Clear item's count - assert nwGUI.openDocument(sHandle) is True + nwGUI.theProject.tree[C.hSceneDoc]._initCount = 0 # Clear item's count + nwGUI.theProject.tree[C.hSceneDoc]._wordCount = 0 # Clear item's count + assert nwGUI.openDocument(C.hSceneDoc) is True theText = "\n\n".join(ipsumText) cC, wC, pC = countWords(theText) @@ -1193,9 +1178,9 @@ def testGuiEditor_WordCounters(qtbot, monkeypatch, nwGUI, nwMinimal, ipsumText): nwGUI.docEditor.wCounterDoc.run() # nwGUI.docEditor._updateDocCounts(cC, wC, pC) - assert nwGUI.theProject.tree[sHandle]._charCount == cC - assert nwGUI.theProject.tree[sHandle]._wordCount == wC - assert nwGUI.theProject.tree[sHandle]._paraCount == pC + assert nwGUI.theProject.tree[C.hSceneDoc]._charCount == cC + assert nwGUI.theProject.tree[C.hSceneDoc]._wordCount == wC + assert nwGUI.theProject.tree[C.hSceneDoc]._paraCount == pC assert nwGUI.docEditor.docFooter.wordsText.text() == f"Words: {wC} (+{wC})" # Select all text diff --git a/tests/test_tools/test_tools_projwizard.py b/tests/test_tools/test_tools_projwizard.py index a2facf6e..5d598e6d 100644 --- a/tests/test_tools/test_tools_projwizard.py +++ b/tests/test_tools/test_tools_projwizard.py @@ -23,7 +23,7 @@ import os import sys import pytest -from tools import getGuiItem +from tools import buildTestProject, getGuiItem from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QFileDialog, QWizard, QDialog @@ -37,7 +37,7 @@ from novelwriter.tools.projwizard import ( @pytest.mark.gui @pytest.mark.skipif(sys.platform.startswith("darwin"), reason="Not running on Darwin") -def testToolProjectWizard_Handling(qtbot, monkeypatch, nwGUI, nwMinimal): +def testToolProjectWizard_Handling(qtbot, monkeypatch, nwGUI, fncProj): """Test the launch of the project wizard. Disabled for macOS because the test segfaults on QWizard.show() """ @@ -45,7 +45,7 @@ def testToolProjectWizard_Handling(qtbot, monkeypatch, nwGUI, nwMinimal): # ======================== # New with a project open should cause an error - assert nwGUI.openProject(nwMinimal) + buildTestProject(nwGUI, fncProj) with monkeypatch.context() as mp: mp.setattr(nwGUI, "closeProject", lambda *a: False) assert nwGUI.newProject() is False @@ -61,7 +61,7 @@ def testToolProjectWizard_Handling(qtbot, monkeypatch, nwGUI, nwMinimal): assert nwGUI.newProject() is False # Now, with a non-empty folder - mp.setattr(nwGUI, "showNewProjectDialog", lambda *a: {"projPath": nwMinimal}) + mp.setattr(nwGUI, "showNewProjectDialog", lambda *a: {"projPath": fncProj}) assert nwGUI.newProject() is False # Test the Wizard Launching