Standardise the save document call for all document classes

This commit is contained in:
Veronica Berglyd Olsen
2024-10-15 21:25:36 +02:00
parent 759a8e84f0
commit fc27078954
11 changed files with 131 additions and 123 deletions
+2 -2
View File
@@ -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"] == ""
+9 -3
View File
@@ -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():
+1 -1
View File
@@ -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)
+2 -2
View File
@@ -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)
+1
View File
@@ -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