Move the quick read function to the document class where it belongs

This commit is contained in:
Veronica Berglyd Olsen
2024-03-26 12:14:07 +01:00
parent 6a7262b817
commit 147d6b95d7
4 changed files with 46 additions and 25 deletions
+19 -1
View File
@@ -47,6 +47,9 @@ def testCoreDocument_LoadSave(monkeypatch, mockGUI, fncPath, mockRnd):
assert bool(doc) is False
assert doc.readDocument() is None
assert doc.fileExists() is False
assert doc.hashError is False
assert doc.createdDate == "Unknown"
assert doc.updatedDate == "Unknown"
# Non-existent handle
doc = NWDocument(project, C.hInvalid)
@@ -76,6 +79,7 @@ def testCoreDocument_LoadSave(monkeypatch, mockGUI, fncPath, mockRnd):
# Try to open a new (non-existent) file
xHandle = project.newFile("New File", C.hNovelRoot)
assert xHandle is not None
doc = NWDocument(project, xHandle)
assert bool(doc) is True
assert repr(doc) == f"<NWDocument handle={xHandle}>"
@@ -93,7 +97,6 @@ def testCoreDocument_LoadSave(monkeypatch, mockGUI, fncPath, mockRnd):
# Set handle and save
text = "### Test File\n\nText ...\n\n"
doc = NWDocument(project, xHandle)
assert doc.readDocument(xHandle) == "" # type: ignore
assert doc.writeDocument(text) is True
# Save again to ensure temp file and previous file is handled
@@ -145,6 +148,21 @@ def testCoreDocument_LoadSave(monkeypatch, mockGUI, fncPath, mockRnd):
doc._handle = None
assert doc.writeDocument(text) is False
# Quick Read
# ==========
contPath = fncPath / "content"
assert NWDocument.quickReadText(contPath, xHandle) == (
"### Test File\n\n"
"Text ...\n\n"
)
# Check read text fallback
assert NWDocument.quickReadText(contPath, "0000000000000") == ""
with monkeypatch.context() as mp:
mp.setattr("builtins.open", causeOSError)
assert NWDocument.quickReadText(contPath, xHandle) == ""
# Delete Document
# ===============
+1 -6
View File
@@ -64,6 +64,7 @@ def testCoreStorage_CreateNewProject(mockGUI, fncPath):
assert bool(storage.getDocument(C.hSceneDoc)) is False
assert storage.getMetaFile("file") is None
assert storage.scanContent() == []
assert storage.getDocumentText(C.hSceneDoc) == ""
# Cannot prepare a non-empty folder
(fncPath / "foobar.txt").touch()
@@ -160,12 +161,6 @@ def testCoreStorage_InitProjectStorage(monkeypatch, mockGUI, fncPath, mockRnd):
# We can directly access the content of a document
assert storage.getDocumentText(C.hSceneDoc) == "### New Scene\n\n"
# Check read text fallback
assert storage.getDocumentText(C.hInvalid) == ""
with monkeypatch.context() as mp:
mp.setattr("builtins.open", causeOSError)
assert storage.getDocumentText(C.hSceneDoc) == ""
project.closeProject()
# END Test testCoreStorage_InitProjectStorage