diff --git a/novelwriter/core/document.py b/novelwriter/core/document.py index 769892a7..1586ac46 100644 --- a/novelwriter/core/document.py +++ b/novelwriter/core/document.py @@ -29,11 +29,11 @@ import logging from time import time from typing import TYPE_CHECKING from pathlib import Path -from novelwriter.core.item import NWItem from novelwriter.enum import nwItemLayout, nwItemClass from novelwriter.error import formatException from novelwriter.common import formatTimeStamp, isHandle +from novelwriter.core.item import NWItem if TYPE_CHECKING: # pragma: no cover from novelwriter.core.project import NWProject @@ -199,9 +199,8 @@ class NWDocument: updatedDate = currTime # DocMeta Line - if self._item is None: - docMeta = "" - else: + docMeta = "" + if self._item: docMeta = ( f"%%~name: {self._item.itemName}\n" f"%%~path: {self._item.itemParent}/{self._item.itemHandle}\n" @@ -328,7 +327,7 @@ class NWDocument: self._docMeta["updated"] = metaBits[1].strip() else: - logger.debug("Ignoring meta data: '%s'", metaLine.strip()) + logger.debug("Unknown meta data: '%s'", metaLine.strip()) return diff --git a/tests/conftest.py b/tests/conftest.py index 4d6e6e72..1969567e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -226,8 +226,7 @@ def prjLipsum(): @pytest.fixture(scope="session") def ipsumText(): - """Return five paragraphs of Lorem Ipsum text. - """ + """Return five paragraphs of Lorem Ipsum text.""" thatIpsum = [( "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc maximus justo non dictum co" "mmodo. Curabitur lacinia tempor orci vel luctus. Phasellus porta metus eu massa luctus, e" diff --git a/tests/lipsum/content/04468803b92e1.nwd b/tests/lipsum/content/04468803b92e1.nwd index 6d706890..f1735bb7 100644 --- a/tests/lipsum/content/04468803b92e1.nwd +++ b/tests/lipsum/content/04468803b92e1.nwd @@ -1,6 +1,8 @@ %%~name: Ancient Europe %%~path: 60bdf227455cc/04468803b92e1 %%~kind: WORLD/NOTE +%%~hash: b4318c2de40a1fc4055d18f8d02696b9cf171ea2 +%%~date: Unknown/Unknown # Ancient Europe @tag: Europe diff --git a/tests/lipsum/content/2426c6f0ca922.nwd b/tests/lipsum/content/2426c6f0ca922.nwd index ad926141..e6d5dd54 100644 --- a/tests/lipsum/content/2426c6f0ca922.nwd +++ b/tests/lipsum/content/2426c6f0ca922.nwd @@ -1,6 +1,8 @@ %%~name: Main %%~path: 6c6afb1247750/2426c6f0ca922 %%~kind: PLOT/NOTE +%%~hash: db3897d166e246acdb5e25e9bd98c5a40a699ed0 +%%~date: Unknown/Unknown # Main Plot @tag: Main diff --git a/tests/lipsum/content/441420a886d82.nwd b/tests/lipsum/content/441420a886d82.nwd index 15eeb3d8..05881160 100644 --- a/tests/lipsum/content/441420a886d82.nwd +++ b/tests/lipsum/content/441420a886d82.nwd @@ -1,6 +1,8 @@ %%~name: Chapter Two %%~path: 6bd935d2490cd/441420a886d82 %%~kind: NOVEL/DOCUMENT +%%~hash: fd6d46708faa1333f8f7ba0442fc5b35bf1e3f85 +%%~date: Unknown/Unknown ## Chapter Two @pov: Bod diff --git a/tests/lipsum/content/47666c91c7ccf.nwd b/tests/lipsum/content/47666c91c7ccf.nwd index 0d3692fb..e551a0e3 100644 --- a/tests/lipsum/content/47666c91c7ccf.nwd +++ b/tests/lipsum/content/47666c91c7ccf.nwd @@ -1,6 +1,8 @@ %%~name: Scene Five %%~path: 6bd935d2490cd/47666c91c7ccf %%~kind: NOVEL/DOCUMENT +%%~hash: d210c26966da6f9edea8726567abf4860b7bb9b7 +%%~date: Unknown/Unknown ### Scene Five @pov: Bod diff --git a/tests/lipsum/content/4c4f28287af27.nwd b/tests/lipsum/content/4c4f28287af27.nwd index 29d8c61a..e7071bb1 100644 --- a/tests/lipsum/content/4c4f28287af27.nwd +++ b/tests/lipsum/content/4c4f28287af27.nwd @@ -1,6 +1,8 @@ %%~name: Mr. Nobody %%~path: 67a8707f2f249/4c4f28287af27 %%~kind: CHARACTER/NOTE +%%~hash: 07a86c2001669de7d7a7545286c22b963e3ccf63 +%%~date: Unknown/Unknown # Nobody Owens @tag: Bod diff --git a/tests/lipsum/content/7a992350f3eb6.nwd b/tests/lipsum/content/7a992350f3eb6.nwd index b8de881c..f36d5e4d 100644 --- a/tests/lipsum/content/7a992350f3eb6.nwd +++ b/tests/lipsum/content/7a992350f3eb6.nwd @@ -1,6 +1,8 @@ %%~name: Lorem Ipsum %%~path: b3643d0f92e32/7a992350f3eb6 %%~kind: NOVEL/DOCUMENT +%%~hash: 8efda028000b70be0d7dbe9647b6026082ef05c9 +%%~date: Unknown/Unknown #! Lorem Ipsum >> **By lipsum.com** << diff --git a/tests/lipsum/content/846352075de7d.nwd b/tests/lipsum/content/846352075de7d.nwd index c181e0e9..6a06fe22 100644 --- a/tests/lipsum/content/846352075de7d.nwd +++ b/tests/lipsum/content/846352075de7d.nwd @@ -1,6 +1,8 @@ %%~name: Interlude %%~path: b3643d0f92e32/846352075de7d %%~kind: NOVEL/DOCUMENT +%%~hash: ac0e16c65142b9f1e0fa281bdc9b954e44026740 +%%~date: Unknown/Unknown ##! Why do we use it? % Exctracted from the lipsum.com website. diff --git a/tests/lipsum/content/88243afbe5ed8.nwd b/tests/lipsum/content/88243afbe5ed8.nwd index 63f376be..3f40135a 100644 --- a/tests/lipsum/content/88243afbe5ed8.nwd +++ b/tests/lipsum/content/88243afbe5ed8.nwd @@ -1,6 +1,8 @@ %%~name: Scene One %%~path: 45e6b01ca35c1/88243afbe5ed8 %%~kind: NOVEL/DOCUMENT +%%~hash: a09245a7a772bbe02850b5db109977e336cd9cc1 +%%~date: Unknown/Unknown ### Scene One @pov: Bod diff --git a/tests/lipsum/content/88d59a277361b.nwd b/tests/lipsum/content/88d59a277361b.nwd index af6b3a48..d057e90a 100644 --- a/tests/lipsum/content/88d59a277361b.nwd +++ b/tests/lipsum/content/88d59a277361b.nwd @@ -1,6 +1,8 @@ %%~name: Prologue %%~path: b3643d0f92e32/88d59a277361b %%~kind: NOVEL/DOCUMENT +%%~hash: 19a2aa95b07ce10eaea753c46569929439648c63 +%%~date: Unknown/Unknown ##! Prologue % Synopsis:Explanation from the lipsum.com website. diff --git a/tests/lipsum/content/8c58a65414c23.nwd b/tests/lipsum/content/8c58a65414c23.nwd index 15140e3b..388608dc 100644 --- a/tests/lipsum/content/8c58a65414c23.nwd +++ b/tests/lipsum/content/8c58a65414c23.nwd @@ -1,6 +1,8 @@ %%~name: Front Matter %%~path: b3643d0f92e32/8c58a65414c23 %%~kind: NOVEL/DOCUMENT +%%~hash: 5c3961cb7616ef2b378010f38a89ed268ef15d92 +%%~date: Unknown/Unknown [NEW PAGE] % Exctracted from the lipsum.com website. diff --git a/tests/lipsum/content/db7e733775d4d.nwd b/tests/lipsum/content/db7e733775d4d.nwd index 15678925..8fe1e52e 100644 --- a/tests/lipsum/content/db7e733775d4d.nwd +++ b/tests/lipsum/content/db7e733775d4d.nwd @@ -1,6 +1,8 @@ %%~name: Act One %%~path: b3643d0f92e32/db7e733775d4d %%~kind: NOVEL/DOCUMENT +%%~hash: d93cd4c96d49e4afd93c82cca29d413a35012108 +%%~date: Unknown/Unknown # Act One >> “Fusce maximus felis libero” << \ No newline at end of file diff --git a/tests/lipsum/content/eb103bc70c90c.nwd b/tests/lipsum/content/eb103bc70c90c.nwd index ec090623..bdfac437 100644 --- a/tests/lipsum/content/eb103bc70c90c.nwd +++ b/tests/lipsum/content/eb103bc70c90c.nwd @@ -1,6 +1,8 @@ %%~name: Scene Three %%~path: 6bd935d2490cd/eb103bc70c90c %%~kind: NOVEL/DOCUMENT +%%~hash: c4eda49e4fe81dc450d547eee0bdabe77fdaaa98 +%%~date: Unknown/Unknown ### Scene Three @pov: Bod diff --git a/tests/lipsum/content/f8c0562e50f1b.nwd b/tests/lipsum/content/f8c0562e50f1b.nwd index e61e52fe..73bedd5f 100644 --- a/tests/lipsum/content/f8c0562e50f1b.nwd +++ b/tests/lipsum/content/f8c0562e50f1b.nwd @@ -1,6 +1,8 @@ %%~name: Scene Four %%~path: 6bd935d2490cd/f8c0562e50f1b %%~kind: NOVEL/DOCUMENT +%%~hash: 9461a279b9fb6ef005ee4d432fcda77ff5bfbd42 +%%~date: Unknown/Unknown ### Scene Four @pov: Bod diff --git a/tests/lipsum/content/f96ec11c6a3da.nwd b/tests/lipsum/content/f96ec11c6a3da.nwd index e7fb3054..b6434395 100644 --- a/tests/lipsum/content/f96ec11c6a3da.nwd +++ b/tests/lipsum/content/f96ec11c6a3da.nwd @@ -1,6 +1,8 @@ %%~name: Scene Two %%~path: 45e6b01ca35c1/f96ec11c6a3da %%~kind: NOVEL/DOCUMENT +%%~hash: ebe3fbaa16d9d81bc1a139822e3bf39bb357866d +%%~date: Unknown/Unknown ### Scene Two @pov: Bod diff --git a/tests/lipsum/content/fb609cd8319dc.nwd b/tests/lipsum/content/fb609cd8319dc.nwd index 394d4bbc..1ae2272f 100644 --- a/tests/lipsum/content/fb609cd8319dc.nwd +++ b/tests/lipsum/content/fb609cd8319dc.nwd @@ -1,6 +1,8 @@ %%~name: Chapter One %%~path: 45e6b01ca35c1/fb609cd8319dc %%~kind: NOVEL/DOCUMENT +%%~hash: 5dabeaa7a58238a6ad99ce73176b1bdfad1a71b7 +%%~date: Unknown/Unknown ## Chapter One @pov: Bod diff --git a/tests/lipsum/nwProject.nwx b/tests/lipsum/nwProject.nwx index d789716c..1c643caf 100644 --- a/tests/lipsum/nwProject.nwx +++ b/tests/lipsum/nwProject.nwx @@ -1,6 +1,6 @@ - - + + Lorem Ipsum Lorem Ipsum lipsum.com diff --git a/tests/reference/coreDocTools_DocMerger_0000000000010.nwd b/tests/reference/coreDocTools_DocMerger_0000000000010.nwd index eb13ead2..fbeb598d 100644 --- a/tests/reference/coreDocTools_DocMerger_0000000000010.nwd +++ b/tests/reference/coreDocTools_DocMerger_0000000000010.nwd @@ -1,6 +1,8 @@ %%~name: Chapter 1 %%~path: 0000000000008/0000000000010 %%~kind: NOVEL/DOCUMENT +%%~hash: 25af8567c8a3b3b49a27dcda2999ed1f8811955a +%%~date: 2023-08-25 18:32:30/2023-08-25 18:32:30 ## Chapter 1 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc maximus justo non dictum commodo. Curabitur lacinia tempor orci vel luctus. Phasellus porta metus eu massa luctus, eget euismod risus rhoncus. Vestibulum sed arcu nisi. Maecenas pretium facilisis velit, vel semper lacus aliquam sit amet. Vestibulum vulputate neque ligula, rhoncus blandit turpis consequat id. Mauris sagittis vehicula imperdiet. Duis sed nunc pretium, ornare purus vel, sodales augue. Maecenas a suscipit risus. Quisque volutpat justo eleifend est ullamcorper fermentum. Donec ullamcorper et tortor a laoreet. Nam id risus nisi. Vivamus non imperdiet erat, sit amet imperdiet felis. Mauris vitae neque et est aliquam scelerisque non non ipsum. diff --git a/tests/reference/coreDocTools_DocMerger_0000000000014.nwd b/tests/reference/coreDocTools_DocMerger_0000000000014.nwd index 199454dc..b33c1905 100644 --- a/tests/reference/coreDocTools_DocMerger_0000000000014.nwd +++ b/tests/reference/coreDocTools_DocMerger_0000000000014.nwd @@ -1,6 +1,8 @@ %%~name: All of Chapter 1 %%~path: 0000000000008/0000000000014 %%~kind: NOVEL/DOCUMENT +%%~hash: 9e632e7e29860572c685da8501b92bf99825ac3b +%%~date: 2023-08-25 18:29:39/2023-08-25 18:29:39 % Merge Novel Chapter: Chapter 1 [New] ## Chapter 1 diff --git a/tests/reference/guiEditor_Main_Final_000000000000f.nwd b/tests/reference/guiEditor_Main_Final_000000000000f.nwd index b45a9dca..840d78eb 100644 --- a/tests/reference/guiEditor_Main_Final_000000000000f.nwd +++ b/tests/reference/guiEditor_Main_Final_000000000000f.nwd @@ -1,6 +1,8 @@ %%~name: New Scene %%~path: 000000000000d/000000000000f %%~kind: NOVEL/DOCUMENT +%%~hash: fd5dc2f0c9767cb124b1bf2300d7a33b7780045e +%%~date: 2023-08-25 18:08:01/2023-08-25 18:08:04 # Novel ## Chapter diff --git a/tests/reference/guiEditor_Main_Final_0000000000010.nwd b/tests/reference/guiEditor_Main_Final_0000000000010.nwd index bc255b88..eb6ce774 100644 --- a/tests/reference/guiEditor_Main_Final_0000000000010.nwd +++ b/tests/reference/guiEditor_Main_Final_0000000000010.nwd @@ -1,6 +1,8 @@ %%~name: New Note %%~path: 000000000000a/0000000000010 %%~kind: CHARACTER/NOTE +%%~hash: 9fae6dfdd3d1c0822d3a3cf90c0142e65ad8e557 +%%~date: 2023-08-25 18:14:24/2023-08-25 18:14:24 # Jane Doe @tag: Jane diff --git a/tests/reference/guiEditor_Main_Final_0000000000011.nwd b/tests/reference/guiEditor_Main_Final_0000000000011.nwd index 99705061..ed7002ab 100644 --- a/tests/reference/guiEditor_Main_Final_0000000000011.nwd +++ b/tests/reference/guiEditor_Main_Final_0000000000011.nwd @@ -1,6 +1,8 @@ %%~name: New Note %%~path: 0000000000009/0000000000011 %%~kind: PLOT/NOTE +%%~hash: 8ff26f8a18ad6390c2ce725c441ab0c792a125cf +%%~date: 2023-08-25 18:15:35/2023-08-25 18:15:35 # Main Plot @tag: MainPlot diff --git a/tests/reference/guiEditor_Main_Final_0000000000012.nwd b/tests/reference/guiEditor_Main_Final_0000000000012.nwd index ea19dae5..2c624eca 100644 --- a/tests/reference/guiEditor_Main_Final_0000000000012.nwd +++ b/tests/reference/guiEditor_Main_Final_0000000000012.nwd @@ -1,6 +1,8 @@ %%~name: New Note %%~path: 000000000000b/0000000000012 %%~kind: WORLD/NOTE +%%~hash: 3f5c3c6c3ba1c27c30b8ac9e59c222fb9a1bd775 +%%~date: 2023-08-25 18:17:45/2023-08-25 18:17:45 # Main Location @tag: Home diff --git a/tests/test_core/test_core_coretools.py b/tests/test_core/test_core_coretools.py index c5c90023..a3f4e11c 100644 --- a/tests/test_core/test_core_coretools.py +++ b/tests/test_core/test_core_coretools.py @@ -26,8 +26,8 @@ from shutil import copyfile from pathlib import Path from zipfile import ZipFile +from tools import C, NWD_IGNORE, buildTestProject, cmpFiles, XML_IGNORE from mocked import causeOSError -from tools import C, buildTestProject, cmpFiles, XML_IGNORE from novelwriter import CONFIG from novelwriter.constants import nwItemClass @@ -46,19 +46,19 @@ def testCoreTools_DocMerger(monkeypatch, mockGUI, fncPath, tstPaths, mockRnd, ip # ===================== hChapter1 = theProject.newFile("Chapter 1", C.hNovelRoot) - hSceneOne11 = theProject.newFile("Scene 1.1", hChapter1) - hSceneOne12 = theProject.newFile("Scene 1.2", hChapter1) - hSceneOne13 = theProject.newFile("Scene 1.3", hChapter1) + hSceneOne11 = theProject.newFile("Scene 1.1", hChapter1) # type: ignore + hSceneOne12 = theProject.newFile("Scene 1.2", hChapter1) # type: ignore + hSceneOne13 = theProject.newFile("Scene 1.3", hChapter1) # type: ignore docText1 = "\n\n".join(ipsumText[0:2]) + "\n\n" docText2 = "\n\n".join(ipsumText[1:3]) + "\n\n" docText3 = "\n\n".join(ipsumText[2:4]) + "\n\n" docText4 = "\n\n".join(ipsumText[3:5]) + "\n\n" - theProject.writeNewFile(hChapter1, 2, True, docText1) - theProject.writeNewFile(hSceneOne11, 3, True, docText2) - theProject.writeNewFile(hSceneOne12, 3, True, docText3) - theProject.writeNewFile(hSceneOne13, 3, True, docText4) + theProject.writeNewFile(hChapter1, 2, True, docText1) # type: ignore + theProject.writeNewFile(hSceneOne11, 3, True, docText2) # type: ignore + theProject.writeNewFile(hSceneOne12, 3, True, docText3) # type: ignore + theProject.writeNewFile(hSceneOne13, 3, True, docText4) # type: ignore # Basic Checks # ============ @@ -81,12 +81,12 @@ def testCoreTools_DocMerger(monkeypatch, mockGUI, fncPath, tstPaths, mockRnd, ip testFile = tstPaths.outDir / "coreDocTools_DocMerger_0000000000014.nwd" compFile = tstPaths.refDir / "coreDocTools_DocMerger_0000000000014.nwd" - assert docMerger.newTargetDoc(hChapter1, "All of Chapter 1") == "0000000000014" + assert docMerger.newTargetDoc(hChapter1, "All of Chapter 1") == "0000000000014" # type: ignore - assert docMerger.appendText(hChapter1, True, "Merge") is True - assert docMerger.appendText(hSceneOne11, True, "Merge") is True - assert docMerger.appendText(hSceneOne12, True, "Merge") is True - assert docMerger.appendText(hSceneOne13, True, "Merge") is True + assert docMerger.appendText(hChapter1, True, "Merge") is True # type: ignore + assert docMerger.appendText(hSceneOne11, True, "Merge") is True # type: ignore + assert docMerger.appendText(hSceneOne12, True, "Merge") is True # type: ignore + assert docMerger.appendText(hSceneOne13, True, "Merge") is True # type: ignore # Block writing and check error handling with monkeypatch.context() as mp: @@ -98,7 +98,7 @@ def testCoreTools_DocMerger(monkeypatch, mockGUI, fncPath, tstPaths, mockRnd, ip # Write properly, and compare assert docMerger.writeTargetDoc() is True copyfile(saveFile, testFile) - assert cmpFiles(testFile, compFile) + assert cmpFiles(testFile, compFile, ignoreStart=NWD_IGNORE) # Merge into Existing # =================== @@ -107,15 +107,15 @@ def testCoreTools_DocMerger(monkeypatch, mockGUI, fncPath, tstPaths, mockRnd, ip testFile = tstPaths.outDir / "coreDocTools_DocMerger_0000000000010.nwd" compFile = tstPaths.refDir / "coreDocTools_DocMerger_0000000000010.nwd" - docMerger.setTargetDoc(hChapter1) + docMerger.setTargetDoc(hChapter1) # type: ignore - assert docMerger.appendText(hSceneOne11, True, "Merge") is True - assert docMerger.appendText(hSceneOne12, True, "Merge") is True - assert docMerger.appendText(hSceneOne13, True, "Merge") is True + assert docMerger.appendText(hSceneOne11, True, "Merge") is True # type: ignore + assert docMerger.appendText(hSceneOne12, True, "Merge") is True # type: ignore + assert docMerger.appendText(hSceneOne13, True, "Merge") is True # type: ignore assert docMerger.writeTargetDoc() is True copyfile(saveFile, testFile) - assert cmpFiles(testFile, compFile) + assert cmpFiles(testFile, compFile, ignoreStart=NWD_IGNORE) # Just for debugging docMerger.writeTargetDoc() @@ -163,11 +163,11 @@ def testCoreTools_DocSplitter(monkeypatch, mockGUI, fncPath, mockRnd, ipsumText) docText = "\n\n".join(docData) docRaw = docText.splitlines() assert theProject.storage.getDocument(hSplitDoc).writeDocument(docText) is True - theProject.tree[hSplitDoc].setStatus(C.sFinished) - theProject.tree[hSplitDoc].setImport(C.iMain) + theProject.tree[hSplitDoc].setStatus(C.sFinished) # type: ignore + theProject.tree[hSplitDoc].setImport(C.iMain) # type: ignore - docSplitter = DocSplitter(theProject, hSplitDoc) - assert docSplitter._srcItem.isFileType() + docSplitter = DocSplitter(theProject, hSplitDoc) # type: ignore + assert docSplitter._srcItem.isFileType() # type: ignore assert docSplitter.getError() == "" # Run the split algorithm @@ -247,8 +247,8 @@ def testCoreTools_DocSplitter(monkeypatch, mockGUI, fncPath, mockRnd, ipsumText) # Check that status and importance has been preserved for rHandle in resDocHandle: - assert theProject.tree[rHandle].itemStatus == C.sFinished - assert theProject.tree[rHandle].itemImport == C.iMain + assert theProject.tree[rHandle].itemStatus == C.sFinished # type: ignore + assert theProject.tree[rHandle].itemImport == C.iMain # type: ignore # Check handling of improper initialisation docSplitter = DocSplitter(theProject, C.hInvalid) @@ -416,7 +416,7 @@ def testCoreTools_NewMinimal(monkeypatch, fncPath, tstPaths, mockGUI, mockRnd): assert projBuild.buildProject({}) is False # Wrong type should also fail - assert projBuild.buildProject("stuff") is False + assert projBuild.buildProject("stuff") is False # type: ignore # Try again with a proper path assert projBuild.buildProject({"projPath": fncPath}) is True @@ -508,7 +508,7 @@ def testCoreTools_NewCustomB(monkeypatch, fncPath, tstPaths, mockRnd): @pytest.mark.core -def testCoreTools_NewSample(monkeypatch, fncPath, tstPaths): +def testCoreTools_NewSample(monkeypatch, mockGUI, fncPath, tstPaths): """Check that we can create a new project can be created from the provided sample project via a zip file. """ diff --git a/tests/test_core/test_core_document.py b/tests/test_core/test_core_document.py index 80f1fb44..e7488668 100644 --- a/tests/test_core/test_core_document.py +++ b/tests/test_core/test_core_document.py @@ -21,8 +21,8 @@ along with this program. If not, see . import pytest +from tools import C, MOCK_TIME, buildTestProject, readFile, writeFile from mocked import causeOSError -from tools import C, buildTestProject, readFile, writeFile from novelwriter.enum import nwItemClass, nwItemLayout from novelwriter.core.project import NWProject @@ -32,6 +32,8 @@ 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.""" + monkeypatch.setattr("novelwriter.core.document.time", lambda: MOCK_TIME) + theProject = NWProject() mockRnd.reset() buildTestProject(theProject, fncPath) @@ -48,7 +50,7 @@ def testCoreDocument_LoadSave(monkeypatch, mockGUI, fncPath, mockRnd): # Non-existent handle theDoc = NWDocument(theProject, C.hInvalid) assert theDoc.readDocument() is None - assert theDoc._currHash is None + assert theDoc._lastHash == "" assert theDoc.fileExists() is False # No content path @@ -90,7 +92,7 @@ def testCoreDocument_LoadSave(monkeypatch, mockGUI, fncPath, mockRnd): # Set handle and save theText = "### Test File\n\nText ...\n\n" theDoc = NWDocument(theProject, xHandle) - assert theDoc.readDocument(xHandle) == "" + assert theDoc.readDocument(xHandle) == "" # type: ignore assert theDoc.writeDocument(theText) is True # Save again to ensure temp file and previous file is handled @@ -102,6 +104,8 @@ def testCoreDocument_LoadSave(monkeypatch, mockGUI, fncPath, mockRnd): "%%~name: New File\n" f"%%~path: {C.hNovelRoot}/{xHandle}\n" "%%~kind: NOVEL/DOCUMENT\n" + "%%~hash: b288c3ab03181027d9a16d7fd2291262f5de9ac8\n" + "%%~date: 2019-05-10 18:52:00/2019-05-10 18:52:00\n" "### Test File\n\n" "Text ...\n\n" ) @@ -170,9 +174,10 @@ def testCoreDocument_LoadSave(monkeypatch, mockGUI, fncPath, mockRnd): @pytest.mark.core -def testCoreDocument_Methods(mockGUI, fncPath, mockRnd): - """Test other methods of the NWDocument class. - """ +def testCoreDocument_Methods(monkeypatch, mockGUI, fncPath, mockRnd): + """Test other methods of the NWDocument class.""" + monkeypatch.setattr("novelwriter.core.document.time", lambda: MOCK_TIME) + theProject = NWProject() mockRnd.reset() buildTestProject(theProject, fncPath) @@ -187,7 +192,7 @@ def testCoreDocument_Methods(mockGUI, fncPath, mockRnd): # Check the item assert theDoc.getCurrentItem() is not None - assert theDoc.getCurrentItem().itemHandle == C.hSceneDoc + assert theDoc.getCurrentItem().itemHandle == C.hSceneDoc # type: ignore # Check the meta theName, theParent, theClass, theLayout = theDoc.getMeta() @@ -202,6 +207,8 @@ def testCoreDocument_Methods(mockGUI, fncPath, mockRnd): "%%~name: New Scene\n" f"%%~path: {C.hChapterDir}/{C.hSceneDoc}\n" "%%~kind: NOVEL/DOCUMENT\n" + "%%~hash: dd350c602de803554b2a7c17f191ae25dea1df63\n" + "%%~date: 2019-05-10 18:52:00/2019-05-10 18:52:00\n" "%%~ stuff\n" "### Test File\n\n" "Text ...\n\n" diff --git a/tests/test_gui/test_gui_guimain.py b/tests/test_gui/test_gui_guimain.py index e3025931..0716214e 100644 --- a/tests/test_gui/test_gui_guimain.py +++ b/tests/test_gui/test_gui_guimain.py @@ -24,7 +24,7 @@ import pytest from shutil import copyfile from tools import ( - C, cmpFiles, buildTestProject, XML_IGNORE, getGuiItem, writeFile + C, NWD_IGNORE, cmpFiles, buildTestProject, XML_IGNORE, getGuiItem, writeFile ) from PyQt5.QtCore import Qt @@ -529,25 +529,25 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, projPath, tstPaths, mockRnd): testFile = tstPaths.outDir / "guiEditor_Main_Final_000000000000f.nwd" compFile = tstPaths.refDir / "guiEditor_Main_Final_000000000000f.nwd" copyfile(projFile, testFile) - assert cmpFiles(testFile, compFile) + assert cmpFiles(testFile, compFile, ignoreStart=NWD_IGNORE) projFile = projPath / "content" / "0000000000010.nwd" testFile = tstPaths.outDir / "guiEditor_Main_Final_0000000000010.nwd" compFile = tstPaths.refDir / "guiEditor_Main_Final_0000000000010.nwd" copyfile(projFile, testFile) - assert cmpFiles(testFile, compFile) + assert cmpFiles(testFile, compFile, ignoreStart=NWD_IGNORE) projFile = projPath / "content" / "0000000000011.nwd" testFile = tstPaths.outDir / "guiEditor_Main_Final_0000000000011.nwd" compFile = tstPaths.refDir / "guiEditor_Main_Final_0000000000011.nwd" copyfile(projFile, testFile) - assert cmpFiles(testFile, compFile) + assert cmpFiles(testFile, compFile, ignoreStart=NWD_IGNORE) projFile = projPath / "content" / "0000000000012.nwd" testFile = tstPaths.outDir / "guiEditor_Main_Final_0000000000012.nwd" compFile = tstPaths.refDir / "guiEditor_Main_Final_0000000000012.nwd" copyfile(projFile, testFile) - assert cmpFiles(testFile, compFile) + assert cmpFiles(testFile, compFile, ignoreStart=NWD_IGNORE) # qtbot.stop() diff --git a/tests/tools.py b/tests/tools.py index 6230d1a2..1eb4e11c 100644 --- a/tests/tools.py +++ b/tests/tools.py @@ -23,11 +23,14 @@ from __future__ import annotations import shutil from pathlib import Path +from datetime import datetime from PyQt5.QtWidgets import qApp XML_IGNORE = (" bool: - """Compare two files, but optionally ignore lines given by a list. - """ + """Compare two files, with optional line ignore.""" if ignoreLines is None: ignoreLines = []