From 262a6c36b70599d9e18b94dc906812009cb3b419 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Mon, 7 Nov 2022 22:51:09 +0100 Subject: [PATCH] Rename NWDoc class to NWDocument --- novelwriter/core/document.py | 6 ++--- novelwriter/core/storage.py | 6 ++--- novelwriter/gui/doceditor.py | 4 ++-- tests/test_core/test_core_document.py | 32 +++++++++++++-------------- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/novelwriter/core/document.py b/novelwriter/core/document.py index 2f04c128..7fe7f8e5 100644 --- a/novelwriter/core/document.py +++ b/novelwriter/core/document.py @@ -34,7 +34,7 @@ from novelwriter.common import isHandle, sha256sum logger = logging.getLogger(__name__) -class NWDoc: +class NWDocument: def __init__(self, theProject, theHandle): @@ -58,7 +58,7 @@ class NWDoc: return def __repr__(self): - return f"" + return f"" def __bool__(self): return self._docHandle is not None and bool(self._theItem) @@ -277,4 +277,4 @@ class NWDoc: return -# END Class NWDoc +# END Class NWDocument diff --git a/novelwriter/core/storage.py b/novelwriter/core/storage.py index ad90126e..6cfa9ffa 100644 --- a/novelwriter/core/storage.py +++ b/novelwriter/core/storage.py @@ -30,7 +30,7 @@ from time import time from pathlib import Path from novelwriter.constants import nwFiles -from novelwriter.core.document import NWDoc +from novelwriter.core.document import NWDocument from novelwriter.core.projectxml import ProjectXMLReader, ProjectXMLWriter from novelwriter.error import logException @@ -159,8 +159,8 @@ class NWStorage: """Return a document wrapper object. """ if self._runtimePath is not None: - return NWDoc(self.theProject, tHandle) - return NWDoc(self.theProject, None) + return NWDocument(self.theProject, tHandle) + return NWDocument(self.theProject, None) def getMetaFile(self, fileName): """Return the path to a file in the project meta folder. diff --git a/novelwriter/gui/doceditor.py b/novelwriter/gui/doceditor.py index 27048fe9..3e53b897 100644 --- a/novelwriter/gui/doceditor.py +++ b/novelwriter/gui/doceditor.py @@ -470,8 +470,8 @@ class GuiDocEditor(QTextEdit): return True def saveText(self): - """Save the text currently in the editor to the NWDoc object, - and update the NWItem meta data. + """Save the text currently in the editor to the NWDocument + object, and update the NWItem meta data. """ if self._nwItem is None or self._nwDocument is None: logger.error("Cannot save text as no document is open") diff --git a/tests/test_core/test_core_document.py b/tests/test_core/test_core_document.py index 1923bc34..ba74afbd 100644 --- a/tests/test_core/test_core_document.py +++ b/tests/test_core/test_core_document.py @@ -1,6 +1,6 @@ """ -novelWriter – NWDoc Class Tester -================================ +novelWriter – NWDocument Class Tester +===================================== This file is a part of novelWriter Copyright 2018–2022, Veronica Berglyd Olsen @@ -27,12 +27,12 @@ from tools import C, buildTestProject, readFile, writeFile from novelwriter.enum import nwItemClass, nwItemLayout from novelwriter.core.project import NWProject -from novelwriter.core.document import NWDoc +from novelwriter.core.document import NWDocument @pytest.mark.core def testCoreDocument_LoadSave(monkeypatch, mockGUI, fncDir, mockRnd): - """Test loading and saving a document with the NWDoc class. + """Test loading and saving a document with the NWDocument class. """ theProject = NWProject(mockGUI) mockRnd.reset() @@ -42,31 +42,31 @@ def testCoreDocument_LoadSave(monkeypatch, mockGUI, fncDir, mockRnd): # ============= # Not a valid handle - theDoc = NWDoc(theProject, "stuff") + theDoc = NWDocument(theProject, "stuff") assert bool(theDoc) is False assert theDoc.readDocument() is None # Non-existent handle - theDoc = NWDoc(theProject, C.hInvalid) + theDoc = NWDocument(theProject, C.hInvalid) assert theDoc.readDocument() is None assert theDoc._currHash is None # Cause open() to fail while loading with monkeypatch.context() as mp: mp.setattr("builtins.open", causeOSError) - theDoc = NWDoc(theProject, C.hSceneDoc) + theDoc = NWDocument(theProject, C.hSceneDoc) assert theDoc.readDocument() is None assert theDoc.getError() == "OSError: Mock OSError" # Load the text - theDoc = NWDoc(theProject, C.hSceneDoc) + theDoc = NWDocument(theProject, C.hSceneDoc) assert theDoc.readDocument() == "### New Scene\n\n" # Try to open a new (non-existent) file xHandle = theProject.newFile("New File", C.hNovelRoot) - theDoc = NWDoc(theProject, xHandle) + theDoc = NWDocument(theProject, xHandle) assert bool(theDoc) is True - assert repr(theDoc) == f"" + assert repr(theDoc) == f"" assert theDoc.readDocument() == "" # Write Document @@ -74,7 +74,7 @@ def testCoreDocument_LoadSave(monkeypatch, mockGUI, fncDir, mockRnd): # Set handle and save again theText = "### Test File\n\nText ...\n\n" - theDoc = NWDoc(theProject, xHandle) + theDoc = NWDocument(theProject, xHandle) assert theDoc.readDocument(xHandle) == "" assert theDoc.writeDocument(theText) is True @@ -129,19 +129,19 @@ def testCoreDocument_LoadSave(monkeypatch, mockGUI, fncDir, mockRnd): # =============== # Delete the last document - theDoc = NWDoc(theProject, "stuff") + theDoc = NWDocument(theProject, "stuff") assert theDoc.deleteDocument() is False assert os.path.isfile(docPath) # Cause the delete to fail with monkeypatch.context() as mp: mp.setattr("pathlib.Path.unlink", causeOSError) - theDoc = NWDoc(theProject, xHandle) + theDoc = NWDocument(theProject, xHandle) assert theDoc.deleteDocument() is False assert theDoc.getError() == "OSError: Mock OSError" # Make the delete pass - theDoc = NWDoc(theProject, xHandle) + theDoc = NWDocument(theProject, xHandle) assert theDoc.deleteDocument() is True assert not os.path.isfile(docPath) @@ -150,13 +150,13 @@ def testCoreDocument_LoadSave(monkeypatch, mockGUI, fncDir, mockRnd): @pytest.mark.core def testCoreDocument_Methods(mockGUI, fncDir, mockRnd): - """Test other methods of the NWDoc class. + """Test other methods of the NWDocument class. """ theProject = NWProject(mockGUI) mockRnd.reset() buildTestProject(theProject, fncDir) - theDoc = NWDoc(theProject, C.hSceneDoc) + theDoc = NWDocument(theProject, C.hSceneDoc) docPath = os.path.join(fncDir, "content", C.hSceneDoc+".nwd") assert theDoc.readDocument() == "### New Scene\n\n"