Standardise the save document call for all document classes
This commit is contained in:
@@ -644,12 +644,12 @@ def testFmtToHtml_Save(mockGUI, fncPath):
|
||||
)
|
||||
|
||||
saveFile = fncPath / "outFile.htm"
|
||||
html.saveHtml5(saveFile)
|
||||
html.saveDocument(saveFile, asJson=False)
|
||||
assert saveFile.read_text(encoding="utf-8") == htmlDoc
|
||||
|
||||
# JSON + HTML
|
||||
saveFile = fncPath / "outFile.json"
|
||||
html.saveHtmlJson(saveFile)
|
||||
html.saveDocument(saveFile, asJson=True)
|
||||
data = json.loads(saveFile.read_text(encoding="utf-8"))
|
||||
assert data["meta"]["projectName"] == ""
|
||||
assert data["meta"]["novelAuthor"] == ""
|
||||
|
||||
@@ -39,6 +39,9 @@ class BareTokenizer(Tokenizer):
|
||||
def doConvert(self):
|
||||
super().doConvert() # type: ignore (deliberate check)
|
||||
|
||||
def saveDocument(self, path) -> None:
|
||||
super().saveDocument(path) # type: ignore (deliberate check)
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testFmtToken_Setters(mockGUI):
|
||||
@@ -219,12 +222,12 @@ def testFmtToken_TextOps(monkeypatch, mockGUI, mockRnd, fncPath):
|
||||
|
||||
# Save File
|
||||
savePath = fncPath / "dump.nwd"
|
||||
tokens.saveRawMarkdown(savePath)
|
||||
tokens.saveRawDocument(savePath, asJson=False)
|
||||
assert readFile(savePath) == (
|
||||
"#! Notes: Plot\n\n"
|
||||
"#! Notes: Plot\n\n"
|
||||
)
|
||||
tokens.saveRawMarkdownJSON(savePath)
|
||||
tokens.saveRawDocument(savePath, asJson=True)
|
||||
assert json.loads(readFile(savePath))["text"] == {
|
||||
"nwd": [
|
||||
["#! Notes: Plot"],
|
||||
@@ -232,10 +235,13 @@ def testFmtToken_TextOps(monkeypatch, mockGUI, mockRnd, fncPath):
|
||||
]
|
||||
}
|
||||
|
||||
# Check abstract method
|
||||
# Check abstract methods
|
||||
with pytest.raises(NotImplementedError):
|
||||
tokens.doConvert()
|
||||
|
||||
with pytest.raises(NotImplementedError):
|
||||
tokens.saveDocument(fncPath)
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testFmtToken_StripEscape():
|
||||
|
||||
@@ -293,7 +293,7 @@ def testFmtToMarkdown_Save(mockGUI, fncPath):
|
||||
# ==========
|
||||
|
||||
saveFile = fncPath / "outFile.md"
|
||||
toMD.saveMarkdown(saveFile)
|
||||
toMD.saveDocument(saveFile)
|
||||
assert saveFile.read_text(encoding="utf-8") == "".join(resText)
|
||||
|
||||
|
||||
|
||||
@@ -802,7 +802,7 @@ def testFmtToOdt_SaveFlat(mockGUI, fncPath, tstPaths):
|
||||
testFile = tstPaths.outDir / "coreToOdt_SaveFlat_document.fodt"
|
||||
compFile = tstPaths.refDir / "coreToOdt_SaveFlat_document.fodt"
|
||||
|
||||
odt.saveFlatXML(flatFile)
|
||||
odt.saveDocument(flatFile)
|
||||
assert flatFile.exists()
|
||||
|
||||
copyfile(flatFile, testFile)
|
||||
@@ -837,7 +837,7 @@ def testFmtToOdt_SaveFull(mockGUI, fncPath, tstPaths):
|
||||
|
||||
fullFile = fncPath / "document.odt"
|
||||
|
||||
odt.saveOpenDocText(fullFile)
|
||||
odt.saveDocument(fullFile)
|
||||
assert fullFile.exists()
|
||||
assert zipfile.is_zipfile(fullFile)
|
||||
|
||||
|
||||
@@ -61,6 +61,7 @@ def testFmtToQTextDocument_ConvertHeaders(mockGUI):
|
||||
project = NWProject()
|
||||
qdoc = ToQTextDocument(project)
|
||||
qdoc.initDocument(CONFIG.textFont, THEME)
|
||||
qdoc.saveDocument("") # Doesn't do anything for this format
|
||||
|
||||
qdoc._isNovel = True
|
||||
qdoc._isFirst = True
|
||||
|
||||
Reference in New Issue
Block a user