Add a quick document read function in the storage class

This commit is contained in:
Veronica Berglyd Olsen
2024-03-26 11:45:29 +01:00
parent 9081380255
commit 738f022212
2 changed files with 34 additions and 6 deletions
+13 -4
View File
@@ -26,15 +26,15 @@ import pytest
from pathlib import Path
from zipfile import ZipFile
from tools import C, buildTestProject
from mocked import causeOSError
from tools import C, buildTestProject
from novelwriter import CONFIG
from novelwriter.constants import nwFiles
from novelwriter.core.project import NWProject
from novelwriter.core.storage import NWStorage, NWStorageOpen, NWStorageCreate, _LegacyStorage
from novelwriter.core.document import NWDocument
from novelwriter.core.project import NWProject
from novelwriter.core.projectxml import ProjectXMLReader, ProjectXMLWriter
from novelwriter.core.storage import NWStorage, NWStorageOpen, NWStorageCreate, _LegacyStorage
class MockProject:
@@ -85,7 +85,7 @@ def testCoreStorage_CreateNewProject(mockGUI, fncPath):
@pytest.mark.core
def testCoreStorage_InitProjectStorage(mockGUI, fncPath, mockRnd):
def testCoreStorage_InitProjectStorage(monkeypatch, mockGUI, fncPath, mockRnd):
"""Test initialising a project in a folder."""
project = NWProject()
@@ -157,6 +157,15 @@ def testCoreStorage_InitProjectStorage(mockGUI, fncPath, mockRnd):
assert isinstance(storage.getDocument(C.hSceneDoc), NWDocument)
assert repr(storage.getDocument(C.hSceneDoc)) == f"<NWDocument handle={C.hSceneDoc}>"
# 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