From 4e448134fcba113313b4790765296b21b954a8fb Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Thu, 20 Jul 2023 21:14:10 +0200 Subject: [PATCH] Add test coverage of new function in Document class --- tests/test_core/test_core_document.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/test_core/test_core_document.py b/tests/test_core/test_core_document.py index 319e2ef8..9ab3a495 100644 --- a/tests/test_core/test_core_document.py +++ b/tests/test_core/test_core_document.py @@ -31,8 +31,7 @@ from novelwriter.core.document import NWDocument @pytest.mark.core def testCoreDocument_LoadSave(monkeypatch, mockGUI, fncPath, mockRnd): - """Test loading and saving a document with the NWDocument class. - """ + """Test loading and saving a document with the NWDocument class.""" theProject = NWProject(mockGUI) mockRnd.reset() buildTestProject(theProject, fncPath) @@ -44,27 +43,32 @@ def testCoreDocument_LoadSave(monkeypatch, mockGUI, fncPath, mockRnd): theDoc = NWDocument(theProject, "stuff") assert bool(theDoc) is False assert theDoc.readDocument() is None + assert theDoc.fileExists() is False # Non-existent handle theDoc = NWDocument(theProject, C.hInvalid) assert theDoc.readDocument() is None assert theDoc._currHash is None + assert theDoc.fileExists() is False # No content path with monkeypatch.context() as mp: mp.setattr("novelwriter.core.storage.NWStorage.contentPath", property(lambda *a: None)) theDoc = NWDocument(theProject, C.hSceneDoc) assert theDoc.readDocument() is None + assert theDoc.fileExists() is False # Cause open() to fail while loading with monkeypatch.context() as mp: mp.setattr("builtins.open", causeOSError) theDoc = NWDocument(theProject, C.hSceneDoc) + assert theDoc.fileExists() is True assert theDoc.readDocument() is None assert theDoc.getError() == "OSError: Mock OSError" # Load the text theDoc = NWDocument(theProject, C.hSceneDoc) + assert theDoc.fileExists() is True assert theDoc.readDocument() == "### New Scene\n\n" # Try to open a new (non-existent) file