Remove minimal project from test suite

This commit is contained in:
Veronica Berglyd Olsen
2022-11-01 18:32:29 +01:00
parent 494b94430c
commit f1100d4475
11 changed files with 98 additions and 235 deletions
-21
View File
@@ -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
-5
View File
@@ -1,5 +0,0 @@
%%~name: New Scene
%%~path: a6d311a93600a/8c659a11cd429
%%~kind: NOVEL/DOCUMENT
### New Scene
-6
View File
@@ -1,6 +0,0 @@
%%~name: Title Page
%%~path: a508bb932959c/a35baf2e93843
%%~kind: NOVEL/DOCUMENT
#! Minimal
>> By Jane Doe, John Doh <<
-5
View File
@@ -1,5 +0,0 @@
%%~name: New Chapter
%%~path: a6d311a93600a/f5ab3e30151e1
%%~kind: NOVEL/DOCUMENT
## New Chapter
-81
View File
@@ -1,81 +0,0 @@
<?xml version='1.0' encoding='utf-8'?>
<novelWriterXML appVersion="2.0-rc1" hexVersion="0x020000c1" fileVersion="1.4" timeStamp="2022-10-31 22:17:45">
<project>
<name>Test Minimal</name>
<title>Minimal</title>
<author>Jane Doe</author>
<author>John Doh</author>
<saveCount>25</saveCount>
<autoCount>2</autoCount>
<editTime>203</editTime>
</project>
<settings>
<doBackup>True</doBackup>
<language>en_GB</language>
<spellCheck>False</spellCheck>
<spellLang>None</spellLang>
<totalWordCount>10</totalWordCount>
<novelWordCount>10</novelWordCount>
<notesWordCount>0</notesWordCount>
<lastHandle>
<entry key="editor">None</entry>
<entry key="viewer">None</entry>
<entry key="novelTree">a508bb932959c</entry>
<entry key="outline">None</entry>
</lastHandle>
<autoReplace/>
<titleFormat>
<entry key="title">%title%</entry>
<entry key="chapter">Chapter %ch%: %title%</entry>
<entry key="unnumbered">%title%</entry>
<entry key="scene">* * *</entry>
<entry key="section"></entry>
</titleFormat>
<status>
<entry key="s72322d" count="5" red="100" green="100" blue="100">New</entry>
<entry key="sb6adc7" count="0" red="200" green="50" blue="0">Note</entry>
<entry key="s2ae76d" count="0" red="200" green="150" blue="0">Draft</entry>
<entry key="s541953" count="0" red="50" green="200" blue="0">Finished</entry>
</status>
<importance>
<entry key="iffcacb" count="3" red="100" green="100" blue="100">New</entry>
<entry key="i6b130b" count="0" red="200" green="50" blue="0">Minor</entry>
<entry key="iece803" count="0" red="200" green="150" blue="0">Major</entry>
<entry key="i5ba06e" count="0" red="50" green="200" blue="0">Main</entry>
</importance>
</settings>
<content count="8">
<item handle="a508bb932959c" parent="None" root="a508bb932959c" order="0" type="ROOT" class="NOVEL">
<meta expanded="True"/>
<name status="s72322d" import="iffcacb">Novel</name>
</item>
<item handle="a35baf2e93843" parent="a508bb932959c" root="a508bb932959c" order="0" type="FILE" class="NOVEL" layout="DOCUMENT">
<meta expanded="False" heading="H1" charCount="28" wordCount="6" paraCount="1" cursorPos="33"/>
<name status="s72322d" import="iffcacb" active="True">Title Page</name>
</item>
<item handle="a6d311a93600a" parent="a508bb932959c" root="a508bb932959c" order="1" type="FOLDER" class="NOVEL">
<meta expanded="True"/>
<name status="s72322d" import="iffcacb">New Chapter</name>
</item>
<item handle="f5ab3e30151e1" parent="a6d311a93600a" root="a508bb932959c" order="0" type="FILE" class="NOVEL" layout="DOCUMENT">
<meta expanded="False" heading="H2" charCount="11" wordCount="2" paraCount="0" cursorPos="16"/>
<name status="s72322d" import="iffcacb" active="True">New Chapter</name>
</item>
<item handle="8c659a11cd429" parent="a6d311a93600a" root="a508bb932959c" order="1" type="FILE" class="NOVEL" layout="DOCUMENT">
<meta expanded="False" heading="H3" charCount="9" wordCount="2" paraCount="0" cursorPos="15"/>
<name status="s72322d" import="iffcacb" active="True">New Scene</name>
</item>
<item handle="7695ce551d265" parent="None" root="7695ce551d265" order="1" type="ROOT" class="PLOT">
<meta expanded="False"/>
<name status="s72322d" import="iffcacb">Plot</name>
</item>
<item handle="afb3043c7b2b3" parent="None" root="afb3043c7b2b3" order="2" type="ROOT" class="CHARACTER">
<meta expanded="False"/>
<name status="s72322d" import="iffcacb">Characters</name>
</item>
<item handle="9d5247ab588e0" parent="None" root="9d5247ab588e0" order="3" type="ROOT" class="WORLD">
<meta expanded="False"/>
<name status="s72322d" import="iffcacb">World</name>
</item>
</content>
</novelWriterXML>
+18 -23
View File
@@ -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"<NWDoc handle={xHandle}>"
@@ -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"
+13 -14
View File
@@ -22,7 +22,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
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("<A>", "this").replace("<B>", "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"
+5 -5
View File
@@ -22,7 +22,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
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()
+6 -4
View File
@@ -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)
+52 -67
View File
@@ -22,6 +22,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
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
+4 -4
View File
@@ -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