Use storage class to return document objects
This commit is contained in:
@@ -31,7 +31,6 @@ from tools import C, buildTestProject, cmpFiles, XML_IGNORE
|
||||
|
||||
from novelwriter.constants import nwItemClass
|
||||
from novelwriter.core.project import NWProject
|
||||
from novelwriter.core.document import NWDoc
|
||||
from novelwriter.core.coretools import DocMerger, DocSplitter, ProjectBuilder
|
||||
|
||||
|
||||
@@ -164,7 +163,7 @@ def testCoreTools_DocSplitter(monkeypatch, mockGUI, fncDir, outDir, refDir, mock
|
||||
|
||||
docText = "\n\n".join(docData)
|
||||
docRaw = docText.splitlines()
|
||||
assert NWDoc(theProject, hSplitDoc).writeDocument(docText) is True
|
||||
assert theProject.storage.getDocument(hSplitDoc).writeDocument(docText) is True
|
||||
theProject.tree[hSplitDoc].setStatus(C.sFinished)
|
||||
theProject.tree[hSplitDoc].setImport(C.iMain)
|
||||
|
||||
|
||||
@@ -38,7 +38,6 @@ from novelwriter.core.tree import NWTree
|
||||
from novelwriter.core.index import NWIndex
|
||||
from novelwriter.core.project import NWProject
|
||||
from novelwriter.core.options import OptionState
|
||||
from novelwriter.core.document import NWDoc
|
||||
from novelwriter.core.projectxml import ProjectXMLReader, ProjectXMLWriter, XMLReadState
|
||||
|
||||
|
||||
@@ -125,11 +124,13 @@ def testCoreProject_NewFileFolder(monkeypatch, fncDir, outDir, refDir, mockGUI,
|
||||
|
||||
# Write to file, success
|
||||
assert theProject.writeNewFile("0000000000011", 2, True) is True
|
||||
assert NWDoc(theProject, "0000000000011").readDocument() == "## Hello\n\n"
|
||||
assert theProject.storage.getDocument("0000000000011").readDocument() == "## Hello\n\n"
|
||||
|
||||
# Write to file with additional text, success
|
||||
assert theProject.writeNewFile("0000000000012", 1, False, "Hi Jane\n\n") is True
|
||||
assert NWDoc(theProject, "0000000000012").readDocument() == "# Jane\n\nHi Jane\n\n"
|
||||
assert theProject.storage.getDocument("0000000000012").readDocument() == (
|
||||
"# Jane\n\nHi Jane\n\n"
|
||||
)
|
||||
|
||||
# Save, close and check
|
||||
assert theProject.projChanged is True
|
||||
|
||||
@@ -25,7 +25,6 @@ import pytest
|
||||
from tools import C, buildTestProject, readFile
|
||||
|
||||
from novelwriter.core.project import NWProject
|
||||
from novelwriter.core.document import NWDoc
|
||||
from novelwriter.core.tokenizer import Tokenizer
|
||||
|
||||
|
||||
@@ -156,7 +155,7 @@ def testCoreToken_TextOps(monkeypatch, mockGUI, mockRnd, fncDir):
|
||||
)
|
||||
docTextR = docText.replace("<A>", "this").replace("<B>", "that")
|
||||
|
||||
nDoc = NWDoc(theProject, C.hSceneDoc)
|
||||
nDoc = theProject.storage.getDocument(C.hSceneDoc)
|
||||
assert nDoc.writeDocument(docText)
|
||||
|
||||
theProject.data.setAutoReplace({"A": "this", "B": "that"})
|
||||
|
||||
@@ -29,7 +29,6 @@ from PyQt5.QtCore import Qt
|
||||
from PyQt5.QtWidgets import QMessageBox, QMenu, QTreeWidgetItem, QDialog
|
||||
|
||||
from novelwriter.enum import nwItemLayout, nwItemType, nwItemClass
|
||||
from novelwriter.core import NWDoc
|
||||
from novelwriter.gui.projtree import GuiProjectTree
|
||||
from novelwriter.dialogs.docmerge import GuiDocMerge
|
||||
from novelwriter.dialogs.docsplit import GuiDocSplit
|
||||
@@ -714,7 +713,7 @@ def testGuiProjTree_MergeDocuments(qtbot, monkeypatch, nwGUI, fncDir, mockRnd, i
|
||||
|
||||
# The merge goes through
|
||||
assert projTree._mergeDocuments(hChapter1, True) is True
|
||||
assert len(NWDoc(theProject, mergedDoc1).readDocument()) > lenAll
|
||||
assert len(theProject.storage.getDocument(mergedDoc1).readDocument()) > lenAll
|
||||
|
||||
# Merge to Existing Doc
|
||||
# =====================
|
||||
@@ -733,9 +732,9 @@ def testGuiProjTree_MergeDocuments(qtbot, monkeypatch, nwGUI, fncDir, mockRnd, i
|
||||
|
||||
# Successful merge, and move to trash
|
||||
mergeData["moveToTrash"] = True
|
||||
assert len(NWDoc(theProject, hChapter1).readDocument()) < lenAll
|
||||
assert len(theProject.storage.getDocument(hChapter1).readDocument()) < lenAll
|
||||
assert projTree._mergeDocuments(hChapter1, False) is True
|
||||
assert len(NWDoc(theProject, hChapter1).readDocument()) > lenAll
|
||||
assert len(theProject.storage.getDocument(hChapter1).readDocument()) > lenAll
|
||||
|
||||
assert theProject.tree.isTrash(hSceneOne11)
|
||||
assert theProject.tree.isTrash(hSceneOne12)
|
||||
|
||||
@@ -25,7 +25,6 @@ import pytest
|
||||
from tools import C, buildTestProject
|
||||
|
||||
from novelwriter.enum import nwState
|
||||
from novelwriter.core.document import NWDoc
|
||||
|
||||
|
||||
@pytest.mark.gui
|
||||
@@ -34,7 +33,7 @@ def testGuiStatusBar_Main(qtbot, nwGUI, fncProj, mockRnd):
|
||||
"""
|
||||
buildTestProject(nwGUI, fncProj)
|
||||
cHandle = nwGUI.theProject.newFile("A Note", C.hCharRoot)
|
||||
newDoc = NWDoc(nwGUI.theProject, cHandle)
|
||||
newDoc = nwGUI.theProject.storage.getDocument(cHandle)
|
||||
newDoc.writeDocument("# A Note\n\n")
|
||||
nwGUI.projView.projTree.revealNewTreeItem(cHandle)
|
||||
nwGUI.rebuildIndex(beQuiet=True)
|
||||
|
||||
+4
-4
@@ -156,7 +156,7 @@ def buildTestProject(theObject, projPath):
|
||||
object as the parent.
|
||||
"""
|
||||
from novelwriter.enum import nwItemClass
|
||||
from novelwriter.core import NWProject, NWDoc
|
||||
from novelwriter.core import NWProject
|
||||
|
||||
if isinstance(theObject, NWProject):
|
||||
theGUI = None
|
||||
@@ -187,15 +187,15 @@ def buildTestProject(theObject, projPath):
|
||||
xHandle[7] = theProject.newFile("New Chapter", xHandle[6])
|
||||
xHandle[8] = theProject.newFile("New Scene", xHandle[6])
|
||||
|
||||
aDoc = NWDoc(theProject, xHandle[5])
|
||||
aDoc = theProject.storage.getDocument(xHandle[5])
|
||||
aDoc.writeDocument("#! New Novel\n\n>> By Jane Doe <<\n")
|
||||
theProject.index.reIndexHandle(xHandle[5])
|
||||
|
||||
aDoc = NWDoc(theProject, xHandle[7])
|
||||
aDoc = theProject.storage.getDocument(xHandle[7])
|
||||
aDoc.writeDocument("## %s\n\n" % theProject.tr("New Chapter"))
|
||||
theProject.index.reIndexHandle(xHandle[7])
|
||||
|
||||
aDoc = NWDoc(theProject, xHandle[8])
|
||||
aDoc = theProject.storage.getDocument(xHandle[8])
|
||||
aDoc.writeDocument("### %s\n\n" % theProject.tr("New Scene"))
|
||||
theProject.index.reIndexHandle(xHandle[8])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user