* Update instructions and readmes
* Cleanup in base files
* Cleanup in core files
* Cleanup in gui files
* Cleanup in dialog files
* Cleanup in tools files
* Cleanup in test files
This commit is contained in:
Veronica Berglyd Olsen
2021-07-04 17:57:54 +02:00
committed by GitHub
parent 1881b3d32c
commit 6d7ca2bb86
51 changed files with 583 additions and 580 deletions
+1 -1
View File
@@ -143,7 +143,7 @@ def fncConf(fncDir):
@pytest.fixture(scope="function")
def dummyGUI(monkeypatch, tmpConf):
def mockGUI(monkeypatch, tmpConf):
"""Create a mock instance of novelWriter's main GUI class.
"""
monkeypatch.setattr("nw.CONFIG", tmpConf)
+21 -24
View File
@@ -23,16 +23,17 @@ import os
import pytest
from mock import causeOSError
from tools import readFile
from nw.core import NWProject, NWDoc
from nw.enum import nwItemClass, nwItemLayout
@pytest.mark.core
def testCoreDocument_LoadSave(monkeypatch, dummyGUI, nwMinimal):
def testCoreDocument_LoadSave(monkeypatch, mockGUI, nwMinimal):
"""Test loading and saving a document with the NWDoc class.
"""
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
assert theProject.openProject(nwMinimal)
assert theProject.projPath == nwMinimal
@@ -75,21 +76,18 @@ def testCoreDocument_LoadSave(monkeypatch, dummyGUI, nwMinimal):
# Check file content
docPath = os.path.join(nwMinimal, "content", xHandle+".nwd")
with open(docPath, mode="r", encoding="utf8") as inFile:
assert inFile.read() == (
"%%~name: New File\n"
f"%%~path: a508bb932959c/{xHandle}\n"
"%%~kind: NOVEL/SCENE\n"
"### Test File\n\n"
"Text ...\n\n"
)
assert readFile(docPath) == (
"%%~name: New File\n"
f"%%~path: a508bb932959c/{xHandle}\n"
"%%~kind: NOVEL/SCENE\n"
"### Test File\n\n"
"Text ...\n\n"
)
# Force no meta data
theDoc._theItem = None
assert theDoc.writeDocument(theText)
with open(docPath, mode="r", encoding="utf8") as inFile:
assert inFile.read() == theText
assert readFile(docPath) == theText
# Cause open() to fail while saving
with monkeypatch.context() as mp:
@@ -122,10 +120,10 @@ def testCoreDocument_LoadSave(monkeypatch, dummyGUI, nwMinimal):
@pytest.mark.core
def testCoreDocument_Methods(dummyGUI, nwMinimal):
def testCoreDocument_Methods(mockGUI, nwMinimal):
"""Test other methods of the NWDoc class.
"""
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
assert theProject.openProject(nwMinimal)
assert theProject.projPath == nwMinimal
@@ -151,15 +149,14 @@ def testCoreDocument_Methods(dummyGUI, nwMinimal):
# Add meta data garbage
assert theDoc.writeDocument("%%~ stuff\n### Test File\n\nText ...\n\n")
with open(docPath, mode="r", encoding="utf8") as inFile:
assert inFile.read() == (
"%%~name: New Scene\n"
f"%%~path: a6d311a93600a/{sHandle}\n"
"%%~kind: NOVEL/SCENE\n"
"%%~ stuff\n"
"### Test File\n\n"
"Text ...\n\n"
)
assert readFile(docPath) == (
"%%~name: New Scene\n"
f"%%~path: a6d311a93600a/{sHandle}\n"
"%%~kind: NOVEL/SCENE\n"
"%%~ stuff\n"
"### Test File\n\n"
"Text ...\n\n"
)
assert theDoc.readDocument() == "### Test File\n\nText ...\n\n"
+18 -18
View File
@@ -34,7 +34,7 @@ from nw.enum import nwItemClass, nwItemLayout
@pytest.mark.core
def testCoreIndex_LoadSave(monkeypatch, nwLipsum, dummyGUI, outDir, refDir):
def testCoreIndex_LoadSave(monkeypatch, nwLipsum, mockGUI, outDir, refDir):
"""Test core functionality of scaning, saving, loading and checking
the index cache file.
"""
@@ -42,7 +42,7 @@ def testCoreIndex_LoadSave(monkeypatch, nwLipsum, dummyGUI, outDir, refDir):
testFile = os.path.join(outDir, "coreIndex_LoadSave_tagsIndex.json")
compFile = os.path.join(refDir, "coreIndex_LoadSave_tagsIndex.json")
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
theProject.projTree.setSeed(42)
assert theProject.openProject(nwLipsum)
@@ -126,10 +126,10 @@ def testCoreIndex_LoadSave(monkeypatch, nwLipsum, dummyGUI, outDir, refDir):
@pytest.mark.core
def testCoreIndex_ScanThis(nwMinimal, dummyGUI):
def testCoreIndex_ScanThis(nwMinimal, mockGUI):
"""Test the tag scanner function scanThis.
"""
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
theProject.projTree.setSeed(42)
assert theProject.openProject(nwMinimal)
@@ -178,10 +178,10 @@ def testCoreIndex_ScanThis(nwMinimal, dummyGUI):
@pytest.mark.core
def testCoreIndex_CheckThese(nwMinimal, dummyGUI):
def testCoreIndex_CheckThese(nwMinimal, mockGUI):
"""Test the tag checker function checkThese.
"""
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
theProject.projTree.setSeed(42)
assert theProject.openProject(nwMinimal)
@@ -240,10 +240,10 @@ def testCoreIndex_CheckThese(nwMinimal, dummyGUI):
@pytest.mark.core
def testCoreIndex_ScanText(nwMinimal, dummyGUI):
def testCoreIndex_ScanText(nwMinimal, mockGUI):
"""Check the index text scanner.
"""
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
theProject.projTree.setSeed(42)
assert theProject.openProject(nwMinimal)
@@ -446,10 +446,10 @@ def testCoreIndex_ScanText(nwMinimal, dummyGUI):
@pytest.mark.core
def testCoreIndex_ExtractData(nwMinimal, dummyGUI):
def testCoreIndex_ExtractData(nwMinimal, mockGUI):
"""Check the index data extraction functions.
"""
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
theProject.projTree.setSeed(42)
assert theProject.openProject(nwMinimal)
@@ -679,10 +679,10 @@ def testCoreIndex_ExtractData(nwMinimal, dummyGUI):
@pytest.mark.core
def testCoreIndex_CheckTagIndex(dummyGUI):
def testCoreIndex_CheckTagIndex(mockGUI):
"""Test the tag index checker.
"""
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
theIndex = NWIndex(theProject)
# Valid Index
@@ -744,10 +744,10 @@ def testCoreIndex_CheckTagIndex(dummyGUI):
@pytest.mark.core
def testCoreIndex_CheckRefIndex(dummyGUI):
def testCoreIndex_CheckRefIndex(mockGUI):
"""Test the reference index checker.
"""
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
theIndex = NWIndex(theProject)
# Valid Index
@@ -867,10 +867,10 @@ def testCoreIndex_CheckRefIndex(dummyGUI):
@pytest.mark.core
def testCoreIndex_CheckNovelNoteIndex(dummyGUI):
def testCoreIndex_CheckNovelNoteIndex(mockGUI):
"""Test the novel and note index checkers.
"""
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
theIndex = NWIndex(theProject)
# Valid Index
@@ -1126,10 +1126,10 @@ def testCoreIndex_CheckNovelNoteIndex(dummyGUI):
@pytest.mark.core
def testCoreIndex_CheckTextCounts(dummyGUI):
def testCoreIndex_CheckTextCounts(mockGUI):
"""Test the text counts checker.
"""
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
theIndex = NWIndex(theProject)
# Valid Index
+10 -10
View File
@@ -29,10 +29,10 @@ from nw.enum import nwItemClass, nwItemType, nwItemLayout
@pytest.mark.core
def testCoreItem_Setters(dummyGUI):
def testCoreItem_Setters(mockGUI):
"""Test all the simple setters for the NWItem class.
"""
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
theItem = NWItem(theProject)
# Name
@@ -167,11 +167,11 @@ def testCoreItem_Setters(dummyGUI):
@pytest.mark.core
def testCoreItem_TypeSetter(dummyGUI):
def testCoreItem_TypeSetter(mockGUI):
"""Test the setter for all the nwItemType values for the NWItem
class.
"""
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
theItem = NWItem(theProject)
# Type
@@ -196,11 +196,11 @@ def testCoreItem_TypeSetter(dummyGUI):
@pytest.mark.core
def testCoreItem_ClassSetter(dummyGUI):
def testCoreItem_ClassSetter(mockGUI):
"""Test the setter for all the nwItemClass values for the NWItem
class.
"""
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
theItem = NWItem(theProject)
# Class
@@ -237,11 +237,11 @@ def testCoreItem_ClassSetter(dummyGUI):
@pytest.mark.core
def testCoreItem_LayoutSetter(dummyGUI):
def testCoreItem_LayoutSetter(mockGUI):
"""Test the setter for all the nwItemLayout values for the NWItem
class.
"""
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
theItem = NWItem(theProject)
# Layout
@@ -274,10 +274,10 @@ def testCoreItem_LayoutSetter(dummyGUI):
@pytest.mark.core
def testCoreItem_XMLPackUnpack(dummyGUI, caplog):
def testCoreItem_XMLPackUnpack(mockGUI, caplog):
"""Test packing and unpacking XML objects for the NWItem class.
"""
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
nwXML = etree.Element("novelWriterXML")
# File
+18 -18
View File
@@ -24,6 +24,7 @@ import json
import pytest
from mock import causeOSError
from tools import writeFile
from nw.core import NWProject
from nw.core.options import OptionState
@@ -31,28 +32,27 @@ from nw.constants import nwFiles
@pytest.mark.core
def testCoreOptions_LoadSave(monkeypatch, dummyGUI, tmpDir):
def testCoreOptions_LoadSave(monkeypatch, mockGUI, tmpDir):
"""Test loading and saving from the OptionState class.
"""
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
theOpts = OptionState(theProject)
# Write a test file
optFile = os.path.join(tmpDir, nwFiles.OPTS_FILE)
with open(optFile, mode="w+", encoding="utf8") as outFile:
json.dump({
"GuiBuildNovel": {
"winWidth": 1000,
"winHeight": 700,
"addNovel": True,
"addNotes": False,
"textFont": "Cantarell",
"dummyItem": None,
},
"DummyGroup": {
"dummyItem": None,
},
}, outFile)
writeFile(optFile, json.dumps({
"GuiBuildNovel": {
"winWidth": 1000,
"winHeight": 700,
"addNovel": True,
"addNotes": False,
"textFont": "Cantarell",
"dummyItem": None,
},
"DummyGroup": {
"dummyItem": None,
},
}))
# Load and save with no path set
theProject.projMeta = None
@@ -102,10 +102,10 @@ def testCoreOptions_LoadSave(monkeypatch, dummyGUI, tmpDir):
@pytest.mark.core
def testCoreOptions_SetGet(dummyGUI):
def testCoreOptions_SetGet(mockGUI):
"""Test setting and getting values from the OptionState class.
"""
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
theOpts = OptionState(theProject)
# Set invalid values
+56 -59
View File
@@ -36,7 +36,7 @@ from nw.constants import nwFiles
@pytest.mark.core
def testCoreProject_NewMinimal(fncDir, outDir, refDir, dummyGUI):
def testCoreProject_NewMinimal(fncDir, outDir, refDir, mockGUI):
"""Create a new project from a project wizard dictionary. With
default setting, creating a Minimal project.
"""
@@ -44,7 +44,7 @@ def testCoreProject_NewMinimal(fncDir, outDir, refDir, dummyGUI):
testFile = os.path.join(outDir, "coreProject_NewMinimal_nwProject.nwx")
compFile = os.path.join(refDir, "coreProject_NewMinimal_nwProject.nwx")
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
theProject.projTree.setSeed(42)
# Setting no data should fail
@@ -85,7 +85,7 @@ def testCoreProject_NewMinimal(fncDir, outDir, refDir, dummyGUI):
@pytest.mark.core
def testCoreProject_NewCustomA(fncDir, outDir, refDir, dummyGUI):
def testCoreProject_NewCustomA(fncDir, outDir, refDir, mockGUI):
"""Create a new project from a project wizard dictionary.
Custom type with chapters and scenes.
"""
@@ -113,7 +113,7 @@ def testCoreProject_NewCustomA(fncDir, outDir, refDir, dummyGUI):
"numScenes": 3,
"chFolders": True,
}
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
theProject.projTree.setSeed(42)
assert theProject.newProject(projData)
@@ -127,7 +127,7 @@ def testCoreProject_NewCustomA(fncDir, outDir, refDir, dummyGUI):
@pytest.mark.core
def testCoreProject_NewCustomB(fncDir, outDir, refDir, dummyGUI):
def testCoreProject_NewCustomB(fncDir, outDir, refDir, mockGUI):
"""Create a new project from a project wizard dictionary.
Custom type without chapters, but with scenes.
"""
@@ -155,7 +155,7 @@ def testCoreProject_NewCustomB(fncDir, outDir, refDir, dummyGUI):
"numScenes": 6,
"chFolders": True,
}
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
theProject.projTree.setSeed(42)
assert theProject.newProject(projData)
@@ -169,7 +169,7 @@ def testCoreProject_NewCustomB(fncDir, outDir, refDir, dummyGUI):
@pytest.mark.core
def testCoreProject_NewSampleA(fncDir, tmpConf, dummyGUI, tmpDir):
def testCoreProject_NewSampleA(fncDir, tmpConf, mockGUI, tmpDir):
"""Check that we can create a new project can be created from the
provided sample project via a zip file.
"""
@@ -182,7 +182,7 @@ def testCoreProject_NewSampleA(fncDir, tmpConf, dummyGUI, tmpDir):
"popMinimal": False,
"popCustom": False,
}
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
theProject.projTree.setSeed(42)
# Sample set, but no path
@@ -218,7 +218,7 @@ def testCoreProject_NewSampleA(fncDir, tmpConf, dummyGUI, tmpDir):
@pytest.mark.core
def testCoreProject_NewSampleB(monkeypatch, fncDir, tmpConf, dummyGUI, tmpDir):
def testCoreProject_NewSampleB(monkeypatch, fncDir, tmpConf, mockGUI, tmpDir):
"""Check that we can create a new project can be created from the
provided sample project folder.
"""
@@ -231,7 +231,7 @@ def testCoreProject_NewSampleB(monkeypatch, fncDir, tmpConf, dummyGUI, tmpDir):
"popMinimal": False,
"popCustom": False,
}
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
theProject.projTree.setSeed(42)
# Make sure we do not pick up the nw/assets/sample.zip file
@@ -256,14 +256,14 @@ def testCoreProject_NewSampleB(monkeypatch, fncDir, tmpConf, dummyGUI, tmpDir):
@pytest.mark.core
def testCoreProject_NewRoot(fncDir, outDir, refDir, dummyGUI):
def testCoreProject_NewRoot(fncDir, outDir, refDir, mockGUI):
"""Check that new root folders can be added to the project.
"""
projFile = os.path.join(fncDir, "nwProject.nwx")
testFile = os.path.join(outDir, "coreProject_NewRoot_nwProject.nwx")
compFile = os.path.join(refDir, "coreProject_NewRoot_nwProject.nwx")
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
theProject.projTree.setSeed(42)
assert theProject.newProject({"projPath": fncDir})
@@ -293,14 +293,14 @@ def testCoreProject_NewRoot(fncDir, outDir, refDir, dummyGUI):
@pytest.mark.core
def testCoreProject_NewFile(fncDir, outDir, refDir, dummyGUI):
def testCoreProject_NewFile(fncDir, outDir, refDir, mockGUI):
"""Check that new files can be added to the project.
"""
projFile = os.path.join(fncDir, "nwProject.nwx")
testFile = os.path.join(outDir, "coreProject_NewFile_nwProject.nwx")
compFile = os.path.join(refDir, "coreProject_NewFile_nwProject.nwx")
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
theProject.projTree.setSeed(42)
assert theProject.newProject({"projPath": fncDir})
@@ -323,10 +323,10 @@ def testCoreProject_NewFile(fncDir, outDir, refDir, dummyGUI):
@pytest.mark.core
def testCoreProject_Open(monkeypatch, nwMinimal, dummyGUI):
def testCoreProject_Open(monkeypatch, nwMinimal, mockGUI):
"""Test opening a project.
"""
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
# Rename the project file to check handling
rName = os.path.join(nwMinimal, nwFiles.PROJ_FILE)
@@ -382,9 +382,9 @@ def testCoreProject_Open(monkeypatch, nwMinimal, dummyGUI):
"timeStamp=\"2020-01-01 00:00:00\">\n"
"</novelWriterXML>\n"
))
dummyGUI.askResponse = False
mockGUI.askResponse = False
assert theProject.openProject(nwMinimal) is False
dummyGUI.undo()
mockGUI.undo()
# Future file version
writeFile(rName, (
@@ -408,9 +408,9 @@ def testCoreProject_Open(monkeypatch, nwMinimal, dummyGUI):
"timeStamp=\"2020-01-01 00:00:00\">\n"
"</novelWriterXML>\n"
))
dummyGUI.askResponse = False
mockGUI.askResponse = False
assert theProject.openProject(nwMinimal) is False
dummyGUI.undo()
mockGUI.undo()
# Test skipping XML entries
writeFile(rName, (
@@ -436,19 +436,19 @@ def testCoreProject_Open(monkeypatch, nwMinimal, dummyGUI):
writeFile(os.path.join(nwMinimal, "junk"), "stuff")
os.mkdir(os.path.join(nwMinimal, "data_0"))
writeFile(os.path.join(nwMinimal, "data_0", "junk"), "stuff")
dummyGUI.clear()
mockGUI.clear()
assert theProject.openProject(nwMinimal) is True
assert "data_0" in dummyGUI.lastAlert
assert "data_0" in mockGUI.lastAlert
assert theProject.closeProject()
# END Test testCoreProject_Open
@pytest.mark.core
def testCoreProject_Save(monkeypatch, nwMinimal, dummyGUI, refDir):
def testCoreProject_Save(monkeypatch, nwMinimal, mockGUI, refDir):
"""Test saving a project.
"""
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
testFile = os.path.join(nwMinimal, "nwProject.nwx")
compFile = os.path.join(refDir, os.path.pardir, "minimal", "nwProject.nwx")
@@ -491,10 +491,10 @@ def testCoreProject_Save(monkeypatch, nwMinimal, dummyGUI, refDir):
@pytest.mark.core
def testCoreProject_LockFile(monkeypatch, fncDir, dummyGUI):
def testCoreProject_LockFile(monkeypatch, fncDir, mockGUI):
"""Test lock file functions for the project folder.
"""
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
lockFile = os.path.join(fncDir, nwFiles.PROJ_LOCK)
@@ -551,10 +551,10 @@ def testCoreProject_LockFile(monkeypatch, fncDir, dummyGUI):
@pytest.mark.core
def testCoreProject_Helpers(monkeypatch, fncDir, dummyGUI):
def testCoreProject_Helpers(monkeypatch, fncDir, mockGUI):
"""Test helper functions for the project folder.
"""
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
# No path
assert theProject.ensureFolderStructure() is False
@@ -595,10 +595,10 @@ def testCoreProject_Helpers(monkeypatch, fncDir, dummyGUI):
@pytest.mark.core
def testCoreProject_AccessItems(nwMinimal, dummyGUI):
def testCoreProject_AccessItems(nwMinimal, mockGUI):
"""Test helper functions for the project folder.
"""
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
theProject.openProject(nwMinimal)
# Move Novel ROOT to after its files
@@ -655,10 +655,10 @@ def testCoreProject_AccessItems(nwMinimal, dummyGUI):
@pytest.mark.core
def testCoreProject_Methods(monkeypatch, nwMinimal, dummyGUI, tmpDir):
def testCoreProject_Methods(monkeypatch, nwMinimal, mockGUI, tmpDir):
"""Test other project class methods and functions.
"""
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
theProject.projTree.setSeed(42)
assert theProject.openProject(nwMinimal)
assert theProject.projPath == nwMinimal
@@ -906,13 +906,13 @@ def testCoreProject_Methods(monkeypatch, nwMinimal, dummyGUI, tmpDir):
@pytest.mark.core
def testCoreProject_OrphanedFiles(dummyGUI, nwLipsum):
def testCoreProject_OrphanedFiles(mockGUI, nwLipsum):
"""Check that files in the content folder that are not tracked in
the project XML file are handled correctly by the orphaned files
function. It should also restore as much meta data as possible from
the meta line at the top of the document file.
"""
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
assert theProject.openProject(nwLipsum)
assert theProject.projTree["636b6aa9b697b"] is None
@@ -920,32 +920,29 @@ def testCoreProject_OrphanedFiles(dummyGUI, nwLipsum):
# First Item with Meta Data
orphPath = os.path.join(nwLipsum, "content", "636b6aa9b697b.nwd")
with open(orphPath, mode="w", encoding="utf8") as outFile:
outFile.write("%%~name:[Recovered] Mars\n")
outFile.write("%%~path:5eaea4e8cdee8/636b6aa9b697b\n")
outFile.write("%%~kind:WORLD/NOTE\n")
outFile.write("%%~invalid\n")
outFile.write("\n")
writeFile(orphPath, (
"%%~name:[Recovered] Mars\n"
"%%~path:5eaea4e8cdee8/636b6aa9b697b\n"
"%%~kind:WORLD/NOTE\n"
"%%~invalid\n"
"\n"
))
# Second Item without Meta Data
orphPath = os.path.join(nwLipsum, "content", "736b6aa9b697b.nwd")
with open(orphPath, mode="w", encoding="utf8") as outFile:
outFile.write("\n")
writeFile(orphPath, "\n")
# Invalid File Name
dummyPath = os.path.join(nwLipsum, "content", "636b6aa9b697b.txt")
with open(dummyPath, mode="w", encoding="utf8") as outFile:
outFile.write("\n")
tstPath = os.path.join(nwLipsum, "content", "636b6aa9b697b.txt")
writeFile(tstPath, "\n")
# Invalid File Name
dummyPath = os.path.join(nwLipsum, "content", "636b6aa9b697bb.nwd")
with open(dummyPath, mode="w", encoding="utf8") as outFile:
outFile.write("\n")
tstPath = os.path.join(nwLipsum, "content", "636b6aa9b697bb.nwd")
writeFile(tstPath, "\n")
# Invalid File Name
dummyPath = os.path.join(nwLipsum, "content", "abcdefghijklm.nwd")
with open(dummyPath, mode="w", encoding="utf8") as outFile:
outFile.write("\n")
tstPath = os.path.join(nwLipsum, "content", "abcdefghijklm.nwd")
writeFile(tstPath, "\n")
assert theProject.openProject(nwLipsum)
assert theProject.projPath is not None
@@ -983,13 +980,13 @@ def testCoreProject_OrphanedFiles(dummyGUI, nwLipsum):
@pytest.mark.core
def testCoreProject_OldFormat(dummyGUI, nwOldProj):
def testCoreProject_OldFormat(mockGUI, nwOldProj):
"""Test that a project folder structure of version 1.0 can be
converted to the latest folder structure. Version 1.0 split the
documents into 'data_0' ... 'data_f' folders, which are now all
contained in a single 'content' folder.
"""
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
# Create mock files for known legacy files
deleteFiles = [
@@ -1073,11 +1070,11 @@ def testCoreProject_OldFormat(dummyGUI, nwOldProj):
@pytest.mark.core
def testCoreProject_LegacyData(monkeypatch, dummyGUI, fncDir):
def testCoreProject_LegacyData(monkeypatch, mockGUI, fncDir):
"""Test the functins that handle legacy data folders and structure
with additional tests of failure handling.
"""
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
theProject.setProjectPath(fncDir)
# assert theProject.newProject({"projPath": fncDir})
@@ -1179,21 +1176,21 @@ def testCoreProject_LegacyData(monkeypatch, dummyGUI, fncDir):
@pytest.mark.core
def testCoreProject_Backup(monkeypatch, dummyGUI, nwMinimal, tmpDir):
def testCoreProject_Backup(monkeypatch, mockGUI, nwMinimal, tmpDir):
"""Test the automated backup feature of the project class. The test
creates a backup of the Minimal test project, and then unzips the
backupd file and checks that the project XML file is identical to
the original file.
"""
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
assert theProject.openProject(nwMinimal)
# Test faulty settings
# No project
dummyGUI.hasProject = False
mockGUI.hasProject = False
assert not theProject.zipIt(doNotify=False)
dummyGUI.hasProject = True
mockGUI.hasProject = True
# Invalid path
theProject.mainConf.backupPath = None
+10 -10
View File
@@ -28,11 +28,11 @@ from nw.core import NWProject, NWIndex, ToHtml
@pytest.mark.core
def testCoreToHtml_Format(dummyGUI):
def testCoreToHtml_Format(mockGUI):
"""Test all the formatters for the ToHtml class.
"""
theProject = NWProject(dummyGUI)
dummyGUI.theIndex = NWIndex(theProject)
theProject = NWProject(mockGUI)
mockGUI.theIndex = NWIndex(theProject)
theHtml = ToHtml(theProject)
# Export Mode
@@ -81,11 +81,11 @@ def testCoreToHtml_Format(dummyGUI):
@pytest.mark.core
def testCoreToHtml_Convert(dummyGUI):
def testCoreToHtml_Convert(mockGUI):
"""Test the converter of the ToHtml class.
"""
theProject = NWProject(dummyGUI)
dummyGUI.theIndex = NWIndex(theProject)
theProject = NWProject(mockGUI)
mockGUI.theIndex = NWIndex(theProject)
theHtml = ToHtml(theProject)
# Export Mode
@@ -347,10 +347,10 @@ def testCoreToHtml_Convert(dummyGUI):
@pytest.mark.core
def testCoreToHtml_Complex(dummyGUI, fncDir):
def testCoreToHtml_Complex(mockGUI, fncDir):
"""Test the ave method of the ToHtml class.
"""
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
theHtml = ToHtml(theProject)
# Build Project
@@ -421,10 +421,10 @@ def testCoreToHtml_Complex(dummyGUI, fncDir):
@pytest.mark.core
def testCoreToHtml_Methods(dummyGUI):
def testCoreToHtml_Methods(mockGUI):
"""Test all the other methods of the ToHtml class.
"""
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
theHtml = ToHtml(theProject)
theHtml.setKeepMarkdown(True)
+8 -8
View File
@@ -29,10 +29,10 @@ from nw.core.tokenizer import Tokenizer
@pytest.mark.core
def testCoreToken_Setters(dummyGUI):
def testCoreToken_Setters(mockGUI):
"""Test all the setters for the Tokenizer class.
"""
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
theToken = Tokenizer(theProject)
# Verify defaults
@@ -113,10 +113,10 @@ def testCoreToken_Setters(dummyGUI):
@pytest.mark.core
def testCoreToken_TextOps(monkeypatch, nwMinimal, dummyGUI):
def testCoreToken_TextOps(monkeypatch, nwMinimal, mockGUI):
"""Test handling files and text in the Tokenizer class.
"""
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
theProject.projTree.setSeed(42)
theProject.projLang = "en"
theProject._loadProjectLocalisation()
@@ -196,10 +196,10 @@ def testCoreToken_TextOps(monkeypatch, nwMinimal, dummyGUI):
@pytest.mark.core
def testCoreToken_Tokenize(dummyGUI):
def testCoreToken_Tokenize(mockGUI):
"""Test the tokenization of the Tokenizer class.
"""
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
theToken = Tokenizer(theProject)
theToken.setKeepMarkdown(True)
@@ -498,10 +498,10 @@ def testCoreToken_Tokenize(dummyGUI):
@pytest.mark.core
def testCoreToken_Headers(dummyGUI):
def testCoreToken_Headers(mockGUI):
"""Test the header and page parser of the Tokenizer class.
"""
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
theProject.projLang = "en"
theProject._loadProjectLocalisation()
theToken = Tokenizer(theProject)
+3 -3
View File
@@ -45,11 +45,11 @@ def xmlToText(xElem):
@pytest.mark.core
def testCoreToOdt_Convert(dummyGUI):
def testCoreToOdt_Convert(mockGUI):
"""Test the converter of the ToHtml class.
"""
theProject = NWProject(dummyGUI)
dummyGUI.theIndex = NWIndex(theProject)
theProject = NWProject(mockGUI)
mockGUI.theIndex = NWIndex(theProject)
theDoc = ToOdt(theProject, isFlat=True)
# Export Mode
+31 -30
View File
@@ -25,16 +25,18 @@ import pytest
from lxml import etree
from hashlib import sha256
from tools import readFile
from nw.core.project import NWProject, NWItem, NWTree
from nw.enum import nwItemClass, nwItemType, nwItemLayout
from nw.constants import nwFiles
@pytest.fixture(scope="function")
def dummyItems(dummyGUI):
def dummyItems(mockGUI):
"""Create a list of mock items.
"""
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
itemA = NWItem(theProject)
itemA.itemName = "Novel"
@@ -108,10 +110,10 @@ def dummyItems(dummyGUI):
@pytest.mark.core
def testCoreTree_BuildTree(dummyGUI, dummyItems):
def testCoreTree_BuildTree(mockGUI, dummyItems):
"""Test building a project tree from a list of items.
"""
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
theTree = NWTree(theProject)
theTree.setSeed(42)
@@ -205,10 +207,10 @@ def testCoreTree_BuildTree(dummyGUI, dummyItems):
@pytest.mark.core
def testCoreTree_Methods(dummyGUI, dummyItems):
def testCoreTree_Methods(mockGUI, dummyItems):
"""Test bvarious class methods.
"""
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
theTree = NWTree(theProject)
for tHandle, pHandle, nwItem in dummyItems:
@@ -262,10 +264,10 @@ def testCoreTree_Methods(dummyGUI, dummyItems):
@pytest.mark.core
def testCoreTree_UpdateItemLayout(dummyGUI, dummyItems):
def testCoreTree_UpdateItemLayout(mockGUI, dummyItems):
"""Test building a project tree from a list of items.
"""
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
theTree = NWTree(theProject)
for tHandle, pHandle, nwItem in dummyItems:
@@ -388,10 +390,10 @@ def testCoreTree_UpdateItemLayout(dummyGUI, dummyItems):
@pytest.mark.core
def testCoreTree_MakeHandles(monkeypatch, dummyGUI):
def testCoreTree_MakeHandles(monkeypatch, mockGUI):
"""Test generating item handles.
"""
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
theTree = NWTree(theProject)
theTree.setSeed(42)
@@ -431,10 +433,10 @@ def testCoreTree_MakeHandles(monkeypatch, dummyGUI):
@pytest.mark.core
def testCoreTree_Stats(dummyGUI, dummyItems):
def testCoreTree_Stats(mockGUI, dummyItems):
"""Test project stats methods.
"""
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
theTree = NWTree(theProject)
for tHandle, pHandle, nwItem in dummyItems:
@@ -458,10 +460,10 @@ def testCoreTree_Stats(dummyGUI, dummyItems):
@pytest.mark.core
def testCoreTree_Reorder(dummyGUI, dummyItems):
def testCoreTree_Reorder(mockGUI, dummyItems):
"""Test changing tree order.
"""
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
theTree = NWTree(theProject)
aHandle = []
@@ -490,10 +492,10 @@ def testCoreTree_Reorder(dummyGUI, dummyItems):
@pytest.mark.core
def testCoreTree_XMLPackUnpack(dummyGUI, dummyItems):
def testCoreTree_XMLPackUnpack(mockGUI, dummyItems):
"""Test packing and unpacking the tree to and from XML.
"""
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
theTree = NWTree(theProject)
for tHandle, pHandle, nwItem in dummyItems:
@@ -546,10 +548,10 @@ def testCoreTree_XMLPackUnpack(dummyGUI, dummyItems):
@pytest.mark.core
def testCoreTree_ToCFile(monkeypatch, dummyGUI, dummyItems, tmpDir):
def testCoreTree_ToCFile(monkeypatch, mockGUI, dummyItems, tmpDir):
"""Test writing the ToC.txt file.
"""
theProject = NWProject(dummyGUI)
theProject = NWProject(mockGUI)
theTree = NWTree(theProject)
for tHandle, pHandle, nwItem in dummyItems:
@@ -579,17 +581,16 @@ def testCoreTree_ToCFile(monkeypatch, dummyGUI, dummyItems, tmpDir):
pathB = os.path.join("content", "c000000000002.nwd")
pathC = os.path.join("content", "b000000000002.nwd")
with open(os.path.join(tmpDir, nwFiles.TOC_TXT), mode="r", encoding="utf8") as inFile:
assert inFile.read() == (
"\n"
"Table of Contents\n"
"=================\n"
"\n"
"File Name Class Layout Document Label\n"
"-------------------------------------------------------------\n"
f"{pathA} NOVEL CHAPTER Chapter One\n"
f"{pathB} NOVEL SCENE Scene One\n"
f"{pathC} CHARACTER NOTE Jane Doe\n"
)
assert readFile(os.path.join(tmpDir, nwFiles.TOC_TXT)) == (
"\n"
"Table of Contents\n"
"=================\n"
"\n"
"File Name Class Layout Document Label\n"
"-------------------------------------------------------------\n"
f"{pathA} NOVEL CHAPTER Chapter One\n"
f"{pathB} NOVEL SCENE Scene One\n"
f"{pathC} CHARACTER NOTE Jane Doe\n"
)
# END Test testCoreTree_ToCFile
+3 -2
View File
@@ -26,6 +26,8 @@ from PyQt5.QtCore import Qt
from PyQt5.QtGui import QTextCursor, QTextBlock
from PyQt5.QtWidgets import QAction, QFileDialog, QMessageBox
from tools import writeFile
from nw.gui.doceditor import GuiDocEditor
from nw.enum import nwDocAction, nwDocInsert, nwWidget
from nw.constants import nwKeyWords, nwUnicode
@@ -659,8 +661,7 @@ def testGuiMenu_Insert(qtbot, monkeypatch, nwGUI, fncDir, fncProj):
assert not nwGUI.importDocument()
# Create the file and try again, but with no target document open
with open(theFile, mode="w+", encoding="utf8") as outFile:
outFile.write("Foo")
writeFile(theFile, "Foo")
assert not nwGUI.importDocument()
# Open the document from before, and add some text to it
+1 -1
View File
@@ -54,7 +54,7 @@ def testGuiOutline_Main(qtbot, monkeypatch, nwGUI, nwLipsum):
qtbot.mouseClick(nwGUI.projView, Qt.LeftButton)
nwGUI.projView._loadHeaderState()
assert not nwGUI.projView.colHidden[nwOutline.CCOUNT]
assert not nwGUI.projView._colHidden[nwOutline.CCOUNT]
# First Item
nwGUI.rebuildOutline()
+4 -4
View File
@@ -32,13 +32,13 @@ def cmpFiles(fileOne, fileTwo, ignoreLines=None):
ignoreLines = []
try:
foOne = open(fileOne, mode="r", encoding="utf8")
foOne = open(fileOne, mode="r", encoding="utf-8")
except Exception as e:
print(str(e))
return False
try:
foTwo = open(fileTwo, mode="r", encoding="utf8")
foTwo = open(fileTwo, mode="r", encoding="utf-8")
except Exception as e:
print(str(e))
return False
@@ -83,14 +83,14 @@ def getGuiItem(theName):
def readFile(fileName):
"""Returns the content of a file as a string.
"""
with open(fileName, mode="r", encoding="utf8") as inFile:
with open(fileName, mode="r", encoding="utf-8") as inFile:
return inFile.read()
def writeFile(fileName, fileData):
"""Write the contents of a string to a file.
"""
with open(fileName, mode="w", encoding="utf8") as outFile:
with open(fileName, mode="w", encoding="utf-8") as outFile:
outFile.write(fileData)