Remove minimal project from test suite
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user