Update tests
This commit is contained in:
@@ -43,7 +43,6 @@ def testCoreIndex_LoadSave(monkeypatch, nwLipsum, mockGUI, outDir, refDir):
|
||||
compFile = os.path.join(refDir, "coreIndex_LoadSave_tagsIndex.json")
|
||||
|
||||
theProject = NWProject(mockGUI)
|
||||
theProject.projTree.setSeed(42)
|
||||
assert theProject.openProject(nwLipsum)
|
||||
|
||||
theIndex = NWIndex(theProject)
|
||||
@@ -125,7 +124,6 @@ def testCoreIndex_ScanThis(nwMinimal, mockGUI):
|
||||
"""Test the tag scanner function scanThis.
|
||||
"""
|
||||
theProject = NWProject(mockGUI)
|
||||
theProject.projTree.setSeed(42)
|
||||
assert theProject.openProject(nwMinimal) is True
|
||||
|
||||
theIndex = NWIndex(theProject)
|
||||
@@ -177,7 +175,6 @@ def testCoreIndex_CheckThese(nwMinimal, mockGUI):
|
||||
"""Test the tag checker function checkThese.
|
||||
"""
|
||||
theProject = NWProject(mockGUI)
|
||||
theProject.projTree.setSeed(42)
|
||||
assert theProject.openProject(nwMinimal) is True
|
||||
|
||||
theIndex = NWIndex(theProject)
|
||||
@@ -254,7 +251,6 @@ def testCoreIndex_ScanText(nwMinimal, mockGUI):
|
||||
"""Check the index text scanner.
|
||||
"""
|
||||
theProject = NWProject(mockGUI)
|
||||
theProject.projTree.setSeed(42)
|
||||
assert theProject.openProject(nwMinimal) is True
|
||||
|
||||
theIndex = NWIndex(theProject)
|
||||
@@ -473,7 +469,6 @@ def testCoreIndex_ExtractData(nwMinimal, mockGUI):
|
||||
"""Check the index data extraction functions.
|
||||
"""
|
||||
theProject = NWProject(mockGUI)
|
||||
theProject.projTree.setSeed(42)
|
||||
assert theProject.openProject(nwMinimal) is True
|
||||
|
||||
theIndex = NWIndex(theProject)
|
||||
|
||||
@@ -20,7 +20,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
import random
|
||||
|
||||
from lxml import etree
|
||||
|
||||
@@ -32,13 +31,15 @@ from novelwriter.enum import nwItemClass, nwItemType, nwItemLayout
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testCoreItem_Setters(mockGUI, constData):
|
||||
def testCoreItem_Setters(mockGUI, mockRnd):
|
||||
"""Test all the simple setters for the NWItem class.
|
||||
"""
|
||||
random.seed(42)
|
||||
theProject = NWProject(mockGUI)
|
||||
theItem = NWItem(theProject)
|
||||
|
||||
statusKeys = ["s000000", "s000001", "s000002", "s000003"]
|
||||
importKeys = ["i000004", "i000005", "i000006", "i000007"]
|
||||
|
||||
# Name
|
||||
theItem.setName("A Name")
|
||||
assert theItem.itemName == "A Name"
|
||||
@@ -94,30 +95,30 @@ def testCoreItem_Setters(mockGUI, constData):
|
||||
# Importance
|
||||
theItem._class = nwItemClass.CHARACTER
|
||||
theItem.setImport("Word")
|
||||
assert theItem.itemImport == constData.importKeys[0] # Default
|
||||
for key in constData.importKeys:
|
||||
assert theItem.itemImport == importKeys[0] # Default
|
||||
for key in importKeys:
|
||||
theItem.setImport(key)
|
||||
assert theItem.itemImport == key
|
||||
|
||||
# Status
|
||||
theItem._class = nwItemClass.NOVEL
|
||||
theItem.setStatus("Word")
|
||||
assert theItem.itemStatus == constData.statusKeys[0] # Default
|
||||
for key in constData.statusKeys:
|
||||
assert theItem.itemStatus == statusKeys[0] # Default
|
||||
for key in statusKeys:
|
||||
theItem.setStatus(key)
|
||||
assert theItem.itemStatus == key
|
||||
|
||||
# Status/Importance Wrapper
|
||||
theItem._class = nwItemClass.CHARACTER
|
||||
for key in constData.importKeys:
|
||||
for key in importKeys:
|
||||
theItem.setImport(key)
|
||||
assert theItem.itemImport == key
|
||||
assert theItem.itemStatus == constData.statusKeys[3] # Should not change
|
||||
assert theItem.itemStatus == statusKeys[3] # Should not change
|
||||
|
||||
theItem._class = nwItemClass.NOVEL
|
||||
for key in constData.statusKeys:
|
||||
for key in statusKeys:
|
||||
theItem.setStatus(key)
|
||||
assert theItem.itemImport == constData.importKeys[3] # Should not change
|
||||
assert theItem.itemImport == importKeys[3] # Should not change
|
||||
assert theItem.itemStatus == key
|
||||
|
||||
# Expanded
|
||||
@@ -465,13 +466,15 @@ def testCoreItem_ClassDefaults(mockGUI):
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testCoreItem_XMLPackUnpack(mockGUI, caplog, constData):
|
||||
def testCoreItem_XMLPackUnpack(mockGUI, caplog, mockRnd):
|
||||
"""Test packing and unpacking XML objects for the NWItem class.
|
||||
"""
|
||||
random.seed(42)
|
||||
theProject = NWProject(mockGUI)
|
||||
nwXML = etree.Element("novelWriterXML")
|
||||
|
||||
statusKeys = ["s000000", "s000001", "s000002", "s000003"]
|
||||
importKeys = ["i000004", "i000005", "i000006", "i000007"]
|
||||
|
||||
# File
|
||||
# ====
|
||||
|
||||
@@ -483,7 +486,7 @@ def testCoreItem_XMLPackUnpack(mockGUI, caplog, constData):
|
||||
theItem.setName("A Name")
|
||||
theItem.setClass("NOVEL")
|
||||
theItem.setType("FILE")
|
||||
theItem.setImport(constData.importKeys[3])
|
||||
theItem.setImport(importKeys[3])
|
||||
theItem.setLayout("NOTE")
|
||||
theItem.setExported(False)
|
||||
theItem.setParaCount(3)
|
||||
@@ -500,7 +503,7 @@ def testCoreItem_XMLPackUnpack(mockGUI, caplog, constData):
|
||||
b'type="FILE" class="NOVEL" layout="NOTE"><meta charCount="7" wordCount="5" paraCount="3" '
|
||||
b'cursorPos="11"/><name status="None" import="%s" exported="False">A Name</name></item>'
|
||||
b'</content>'
|
||||
) % bytes(constData.importKeys[3], encoding="utf8")
|
||||
) % bytes(importKeys[3], encoding="utf8")
|
||||
|
||||
# Unpack
|
||||
theItem = NWItem(theProject)
|
||||
@@ -517,8 +520,8 @@ def testCoreItem_XMLPackUnpack(mockGUI, caplog, constData):
|
||||
assert theItem.itemClass == nwItemClass.NOVEL
|
||||
assert theItem.itemType == nwItemType.FILE
|
||||
assert theItem.itemLayout == nwItemLayout.NOTE
|
||||
assert theItem.itemStatus == constData.statusKeys[0] # Was None, should now be default
|
||||
assert theItem.itemImport == constData.importKeys[3]
|
||||
assert theItem.itemStatus == statusKeys[0] # Was None, should now be default
|
||||
assert theItem.itemImport == importKeys[3]
|
||||
|
||||
# Folder
|
||||
# ======
|
||||
@@ -531,7 +534,7 @@ def testCoreItem_XMLPackUnpack(mockGUI, caplog, constData):
|
||||
theItem.setName("A Name")
|
||||
theItem.setClass("NOVEL")
|
||||
theItem.setType("FOLDER")
|
||||
theItem.setStatus(constData.statusKeys[1])
|
||||
theItem.setStatus(statusKeys[1])
|
||||
theItem.setLayout("NOTE")
|
||||
theItem.setExpanded(True)
|
||||
theItem.setExported(False)
|
||||
@@ -549,7 +552,7 @@ def testCoreItem_XMLPackUnpack(mockGUI, caplog, constData):
|
||||
b'type="FOLDER" class="NOVEL"><meta expanded="True"/><name status="%s" '
|
||||
b'import="None">A Name</name></item>'
|
||||
b'</content>'
|
||||
) % bytes(constData.statusKeys[1], encoding="utf8")
|
||||
) % bytes(statusKeys[1], encoding="utf8")
|
||||
|
||||
# Unpack
|
||||
theItem = NWItem(theProject)
|
||||
@@ -567,8 +570,8 @@ def testCoreItem_XMLPackUnpack(mockGUI, caplog, constData):
|
||||
assert theItem.itemClass == nwItemClass.NOVEL
|
||||
assert theItem.itemType == nwItemType.FOLDER
|
||||
assert theItem.itemLayout == nwItemLayout.NO_LAYOUT
|
||||
assert theItem.itemStatus == constData.statusKeys[1]
|
||||
assert theItem.itemImport == constData.importKeys[0] # Was None, should now be default
|
||||
assert theItem.itemStatus == statusKeys[1]
|
||||
assert theItem.itemImport == importKeys[0] # Was None, should now be default
|
||||
|
||||
# Errors
|
||||
# ======
|
||||
|
||||
@@ -21,7 +21,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import os
|
||||
import pytest
|
||||
import random
|
||||
|
||||
from shutil import copyfile
|
||||
from zipfile import ZipFile
|
||||
@@ -37,7 +36,7 @@ from novelwriter.constants import nwFiles
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testCoreProject_NewMinimal(fncDir, outDir, refDir, mockGUI):
|
||||
def testCoreProject_NewMinimal(fncDir, outDir, refDir, mockGUI, mockRnd):
|
||||
"""Create a new project from a project wizard dictionary. With
|
||||
default setting, creating a Minimal project.
|
||||
"""
|
||||
@@ -45,9 +44,7 @@ def testCoreProject_NewMinimal(fncDir, outDir, refDir, mockGUI):
|
||||
testFile = os.path.join(outDir, "coreProject_NewMinimal_nwProject.nwx")
|
||||
compFile = os.path.join(refDir, "coreProject_NewMinimal_nwProject.nwx")
|
||||
|
||||
random.seed(42)
|
||||
theProject = NWProject(mockGUI)
|
||||
theProject.projTree.setSeed(42)
|
||||
|
||||
# Setting no data should fail
|
||||
assert theProject.newProject({}) is False
|
||||
@@ -86,7 +83,7 @@ def testCoreProject_NewMinimal(fncDir, outDir, refDir, mockGUI):
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testCoreProject_NewCustomA(fncDir, outDir, refDir, mockGUI):
|
||||
def testCoreProject_NewCustomA(fncDir, outDir, refDir, mockGUI, mockRnd):
|
||||
"""Create a new project from a project wizard dictionary.
|
||||
Custom type with chapters and scenes.
|
||||
"""
|
||||
@@ -114,9 +111,7 @@ def testCoreProject_NewCustomA(fncDir, outDir, refDir, mockGUI):
|
||||
"numScenes": 3,
|
||||
"chFolders": True,
|
||||
}
|
||||
random.seed(42)
|
||||
theProject = NWProject(mockGUI)
|
||||
theProject.projTree.setSeed(42)
|
||||
|
||||
assert theProject.newProject(projData) is True
|
||||
assert theProject.saveProject() is True
|
||||
@@ -129,7 +124,7 @@ def testCoreProject_NewCustomA(fncDir, outDir, refDir, mockGUI):
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testCoreProject_NewCustomB(fncDir, outDir, refDir, mockGUI):
|
||||
def testCoreProject_NewCustomB(fncDir, outDir, refDir, mockGUI, mockRnd):
|
||||
"""Create a new project from a project wizard dictionary.
|
||||
Custom type without chapters, but with scenes.
|
||||
"""
|
||||
@@ -157,9 +152,7 @@ def testCoreProject_NewCustomB(fncDir, outDir, refDir, mockGUI):
|
||||
"numScenes": 6,
|
||||
"chFolders": True,
|
||||
}
|
||||
random.seed(42)
|
||||
theProject = NWProject(mockGUI)
|
||||
theProject.projTree.setSeed(42)
|
||||
|
||||
assert theProject.newProject(projData) is True
|
||||
assert theProject.saveProject() is True
|
||||
@@ -186,7 +179,6 @@ def testCoreProject_NewSampleA(fncDir, tmpConf, mockGUI, tmpDir):
|
||||
"popCustom": False,
|
||||
}
|
||||
theProject = NWProject(mockGUI)
|
||||
theProject.projTree.setSeed(42)
|
||||
|
||||
# Sample set, but no path
|
||||
assert not theProject.newProject({"popSample": True})
|
||||
@@ -235,7 +227,6 @@ def testCoreProject_NewSampleB(monkeypatch, fncDir, tmpConf, mockGUI, tmpDir):
|
||||
"popCustom": False,
|
||||
}
|
||||
theProject = NWProject(mockGUI)
|
||||
theProject.projTree.setSeed(42)
|
||||
|
||||
# Make sure we do not pick up the novelwriter/assets/sample.zip file
|
||||
tmpConf.assetPath = tmpDir
|
||||
@@ -259,16 +250,14 @@ def testCoreProject_NewSampleB(monkeypatch, fncDir, tmpConf, mockGUI, tmpDir):
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testCoreProject_NewRoot(fncDir, outDir, refDir, mockGUI):
|
||||
def testCoreProject_NewRoot(fncDir, outDir, refDir, mockGUI, mockRnd):
|
||||
"""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")
|
||||
|
||||
random.seed(42)
|
||||
theProject = NWProject(mockGUI)
|
||||
theProject.projTree.setSeed(42)
|
||||
|
||||
assert theProject.newProject({"projPath": fncDir}) is True
|
||||
assert theProject.setProjectPath(fncDir) is True
|
||||
@@ -297,16 +286,14 @@ def testCoreProject_NewRoot(fncDir, outDir, refDir, mockGUI):
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testCoreProject_NewFile(fncDir, outDir, refDir, mockGUI):
|
||||
def testCoreProject_NewFile(fncDir, outDir, refDir, mockGUI, mockRnd):
|
||||
"""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")
|
||||
|
||||
random.seed(42)
|
||||
theProject = NWProject(mockGUI)
|
||||
theProject.projTree.setSeed(42)
|
||||
|
||||
assert theProject.newProject({"projPath": fncDir}) is True
|
||||
assert theProject.setProjectPath(fncDir) is True
|
||||
@@ -686,50 +673,51 @@ def testCoreProject_AccessItems(nwMinimal, mockGUI):
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testCoreProject_StatusImport(mockGUI, fncDir, constData):
|
||||
def testCoreProject_StatusImport(mockGUI, fncDir, mockRnd):
|
||||
"""Test the status and importance flag handling.
|
||||
"""
|
||||
theProject = NWProject(mockGUI)
|
||||
random.seed(42)
|
||||
theProject.projTree.setSeed(42)
|
||||
assert theProject.newProject({"projPath": fncDir}) is True
|
||||
|
||||
statusKeys = ["s000008", "s000009", "s00000a", "s00000b"]
|
||||
importKeys = ["i00000c", "i00000d", "i00000e", "i00000f"]
|
||||
|
||||
# Change Status
|
||||
# =============
|
||||
|
||||
theProject.projTree["44cb730c42048"].setStatus("Finished")
|
||||
theProject.projTree["71ee45a3c0db9"].setStatus("Draft")
|
||||
theProject.projTree["811786ad1ae74"].setStatus("Note")
|
||||
theProject.projTree["25fc0e7096fc6"].setStatus("Finished")
|
||||
theProject.projTree["0000000000014"].setStatus("Finished")
|
||||
theProject.projTree["0000000000015"].setStatus("Draft")
|
||||
theProject.projTree["0000000000016"].setStatus("Note")
|
||||
theProject.projTree["0000000000017"].setStatus("Finished")
|
||||
|
||||
assert theProject.projTree["44cb730c42048"].itemStatus == constData.statusKeys[3]
|
||||
assert theProject.projTree["71ee45a3c0db9"].itemStatus == constData.statusKeys[2]
|
||||
assert theProject.projTree["811786ad1ae74"].itemStatus == constData.statusKeys[1]
|
||||
assert theProject.projTree["25fc0e7096fc6"].itemStatus == constData.statusKeys[3]
|
||||
assert theProject.projTree["0000000000014"].itemStatus == statusKeys[3]
|
||||
assert theProject.projTree["0000000000015"].itemStatus == statusKeys[2]
|
||||
assert theProject.projTree["0000000000016"].itemStatus == statusKeys[1]
|
||||
assert theProject.projTree["0000000000017"].itemStatus == statusKeys[3]
|
||||
|
||||
newList = [
|
||||
{"key": constData.statusKeys[0], "name": "New", "cols": (1, 1, 1)},
|
||||
{"key": constData.statusKeys[1], "name": "Draft", "cols": (2, 2, 2)}, # These are swapped
|
||||
{"key": constData.statusKeys[2], "name": "Note", "cols": (3, 3, 3)}, # These are swapped
|
||||
{"key": constData.statusKeys[3], "name": "Edited", "cols": (4, 4, 4)}, # Renamed
|
||||
{"key": None, "name": "Finished", "cols": (5, 5, 5)}, # New, reused name
|
||||
{"key": statusKeys[0], "name": "New", "cols": (1, 1, 1)},
|
||||
{"key": statusKeys[1], "name": "Draft", "cols": (2, 2, 2)}, # These are swapped
|
||||
{"key": statusKeys[2], "name": "Note", "cols": (3, 3, 3)}, # These are swapped
|
||||
{"key": statusKeys[3], "name": "Edited", "cols": (4, 4, 4)}, # Renamed
|
||||
{"key": None, "name": "Finished", "cols": (5, 5, 5)}, # New, reused name
|
||||
]
|
||||
assert theProject.setStatusColours(None, None) is False
|
||||
assert theProject.setStatusColours([], []) is False
|
||||
assert theProject.setStatusColours(newList, []) is True
|
||||
|
||||
assert theProject.statusItems.name(constData.statusKeys[0]) == "New"
|
||||
assert theProject.statusItems.name(constData.statusKeys[1]) == "Draft"
|
||||
assert theProject.statusItems.name(constData.statusKeys[2]) == "Note"
|
||||
assert theProject.statusItems.name(constData.statusKeys[3]) == "Edited"
|
||||
assert theProject.statusItems.cols(constData.statusKeys[0]) == (1, 1, 1)
|
||||
assert theProject.statusItems.cols(constData.statusKeys[1]) == (2, 2, 2)
|
||||
assert theProject.statusItems.cols(constData.statusKeys[2]) == (3, 3, 3)
|
||||
assert theProject.statusItems.cols(constData.statusKeys[3]) == (4, 4, 4)
|
||||
assert theProject.statusItems.name(statusKeys[0]) == "New"
|
||||
assert theProject.statusItems.name(statusKeys[1]) == "Draft"
|
||||
assert theProject.statusItems.name(statusKeys[2]) == "Note"
|
||||
assert theProject.statusItems.name(statusKeys[3]) == "Edited"
|
||||
assert theProject.statusItems.cols(statusKeys[0]) == (1, 1, 1)
|
||||
assert theProject.statusItems.cols(statusKeys[1]) == (2, 2, 2)
|
||||
assert theProject.statusItems.cols(statusKeys[2]) == (3, 3, 3)
|
||||
assert theProject.statusItems.cols(statusKeys[3]) == (4, 4, 4)
|
||||
|
||||
# Check the new entry
|
||||
lastKey = theProject.statusItems.check("Finished")
|
||||
assert lastKey == "sbc8960"
|
||||
assert lastKey == "s000018"
|
||||
assert theProject.statusItems.name(lastKey) == "Finished"
|
||||
assert theProject.statusItems.cols(lastKey) == (5, 5, 5)
|
||||
|
||||
@@ -740,33 +728,33 @@ def testCoreProject_StatusImport(mockGUI, fncDir, constData):
|
||||
# Change Importance
|
||||
# =================
|
||||
|
||||
fHandle = theProject.newFile("Jane Doe", "73475cb40a568")
|
||||
fHandle = theProject.newFile("Jane Doe", "8b9d2e465e150")
|
||||
theProject.projTree[fHandle].setImport("Main")
|
||||
|
||||
assert theProject.projTree[fHandle].itemImport == constData.importKeys[3]
|
||||
assert theProject.projTree[fHandle].itemImport == importKeys[3]
|
||||
newList = [
|
||||
{"key": constData.importKeys[0], "name": "New", "cols": (1, 1, 1)},
|
||||
{"key": constData.importKeys[1], "name": "Minor", "cols": (2, 2, 2)},
|
||||
{"key": constData.importKeys[2], "name": "Major", "cols": (3, 3, 3)},
|
||||
{"key": constData.importKeys[3], "name": "Min", "cols": (4, 4, 4)},
|
||||
{"key": importKeys[0], "name": "New", "cols": (1, 1, 1)},
|
||||
{"key": importKeys[1], "name": "Minor", "cols": (2, 2, 2)},
|
||||
{"key": importKeys[2], "name": "Major", "cols": (3, 3, 3)},
|
||||
{"key": importKeys[3], "name": "Min", "cols": (4, 4, 4)},
|
||||
{"key": None, "name": "Max", "cols": (5, 5, 5)},
|
||||
]
|
||||
assert theProject.setImportColours(None, None) is False
|
||||
assert theProject.setImportColours([], []) is False
|
||||
assert theProject.setImportColours(newList, []) is True
|
||||
|
||||
assert theProject.importItems.name(constData.importKeys[0]) == "New"
|
||||
assert theProject.importItems.name(constData.importKeys[1]) == "Minor"
|
||||
assert theProject.importItems.name(constData.importKeys[2]) == "Major"
|
||||
assert theProject.importItems.name(constData.importKeys[3]) == "Min"
|
||||
assert theProject.importItems.cols(constData.importKeys[0]) == (1, 1, 1)
|
||||
assert theProject.importItems.cols(constData.importKeys[1]) == (2, 2, 2)
|
||||
assert theProject.importItems.cols(constData.importKeys[2]) == (3, 3, 3)
|
||||
assert theProject.importItems.cols(constData.importKeys[3]) == (4, 4, 4)
|
||||
assert theProject.importItems.name(importKeys[0]) == "New"
|
||||
assert theProject.importItems.name(importKeys[1]) == "Minor"
|
||||
assert theProject.importItems.name(importKeys[2]) == "Major"
|
||||
assert theProject.importItems.name(importKeys[3]) == "Min"
|
||||
assert theProject.importItems.cols(importKeys[0]) == (1, 1, 1)
|
||||
assert theProject.importItems.cols(importKeys[1]) == (2, 2, 2)
|
||||
assert theProject.importItems.cols(importKeys[2]) == (3, 3, 3)
|
||||
assert theProject.importItems.cols(importKeys[3]) == (4, 4, 4)
|
||||
|
||||
# Check the new entry
|
||||
lastKey = theProject.importItems.check("Max")
|
||||
assert lastKey == "i1a3d1f"
|
||||
assert lastKey == "i00001a"
|
||||
assert theProject.importItems.name(lastKey) == "Max"
|
||||
assert theProject.importItems.cols(lastKey) == (5, 5, 5)
|
||||
|
||||
@@ -791,21 +779,25 @@ def testCoreProject_StatusImport(mockGUI, fncDir, constData):
|
||||
assert theProject.closeProject() is True
|
||||
|
||||
# This should restore the default status/import labels
|
||||
random.seed(42)
|
||||
assert theProject.openProject(fncDir) is True
|
||||
assert theProject.saveProject() is True
|
||||
assert list(theProject.statusItems.keys()) == constData.statusKeys
|
||||
assert list(theProject.importItems.keys()) == constData.importKeys
|
||||
assert theProject.statusItems.name("s000023") == "New"
|
||||
assert theProject.statusItems.name("s000024") == "Note"
|
||||
assert theProject.statusItems.name("s000025") == "Draft"
|
||||
assert theProject.statusItems.name("s000026") == "Finished"
|
||||
assert theProject.importItems.name("i000027") == "New"
|
||||
assert theProject.importItems.name("i000028") == "Minor"
|
||||
assert theProject.importItems.name("i000029") == "Major"
|
||||
assert theProject.importItems.name("i00002a") == "Main"
|
||||
|
||||
# END Test testCoreProject_StatusImport
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testCoreProject_Methods(monkeypatch, mockGUI, tmpDir, fncDir):
|
||||
def testCoreProject_Methods(monkeypatch, mockGUI, tmpDir, fncDir, mockRnd):
|
||||
"""Test other project class methods and functions.
|
||||
"""
|
||||
theProject = NWProject(mockGUI)
|
||||
theProject.projTree.setSeed(42)
|
||||
assert theProject.newProject({"projPath": fncDir}) is True
|
||||
|
||||
# Setting project path
|
||||
@@ -864,7 +856,7 @@ def testCoreProject_Methods(monkeypatch, mockGUI, tmpDir, fncDir):
|
||||
|
||||
# Trash folder
|
||||
# Should create on first call, and just returned on later calls
|
||||
hTrash = "1a6562590ef19"
|
||||
hTrash = "0000000000018"
|
||||
assert theProject.projTree[hTrash] is None
|
||||
assert theProject.trashFolder() == hTrash
|
||||
assert theProject.trashFolder() == hTrash
|
||||
@@ -934,14 +926,14 @@ def testCoreProject_Methods(monkeypatch, mockGUI, tmpDir, fncDir):
|
||||
|
||||
# Change project tree order
|
||||
oldOrder = [
|
||||
"73475cb40a568", "44cb730c42048", "71ee45a3c0db9",
|
||||
"811786ad1ae74", "25fc0e7096fc6", "31489056e0916",
|
||||
"98010bd9270f9", "0e17daca5f3e1", "1a6562590ef19",
|
||||
"0000000000010", "0000000000011", "0000000000012",
|
||||
"0000000000013", "0000000000014", "0000000000015",
|
||||
"0000000000016", "0000000000017", "0000000000018",
|
||||
]
|
||||
newOrder = [
|
||||
"811786ad1ae74", "25fc0e7096fc6", "31489056e0916",
|
||||
"73475cb40a568", "44cb730c42048", "71ee45a3c0db9",
|
||||
"98010bd9270f9", "0e17daca5f3e1",
|
||||
"0000000000013", "0000000000014", "0000000000015",
|
||||
"0000000000010", "0000000000011", "0000000000012",
|
||||
"0000000000016", "0000000000017",
|
||||
]
|
||||
assert theProject.projTree.handles() == oldOrder
|
||||
assert theProject.setTreeOrder(newOrder)
|
||||
|
||||
@@ -28,9 +28,12 @@ from PyQt5.QtGui import QIcon
|
||||
|
||||
from novelwriter.core.status import NWStatus
|
||||
|
||||
statusKeys = ["sa3b179", "s1c8031", "s06671a", "sbdd640"]
|
||||
importKeys = ["i466852", "i3eb13b", "i392456", "i23b8c1"]
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testCoreStatus_Internal(constData):
|
||||
def testCoreStatus_Internal():
|
||||
"""Test all the internal functions of the NWStatus class.
|
||||
"""
|
||||
random.seed(42)
|
||||
@@ -43,19 +46,19 @@ def testCoreStatus_Internal(constData):
|
||||
# Generate Key
|
||||
# ============
|
||||
|
||||
assert theStatus._newKey() == constData.statusKeys[0]
|
||||
assert theStatus._newKey() == constData.statusKeys[1]
|
||||
assert theStatus._newKey() == statusKeys[0]
|
||||
assert theStatus._newKey() == statusKeys[1]
|
||||
|
||||
# Key collision, should move to key 3
|
||||
theStatus.write(constData.statusKeys[2], "Crash", (0, 0, 0))
|
||||
assert theStatus._newKey() == constData.statusKeys[3]
|
||||
theStatus.write(statusKeys[2], "Crash", (0, 0, 0))
|
||||
assert theStatus._newKey() == statusKeys[3]
|
||||
|
||||
assert theImport._newKey() == constData.importKeys[0]
|
||||
assert theImport._newKey() == constData.importKeys[1]
|
||||
assert theImport._newKey() == importKeys[0]
|
||||
assert theImport._newKey() == importKeys[1]
|
||||
|
||||
# Key collision, should move to key 3
|
||||
theImport.write(constData.importKeys[2], "Crash", (0, 0, 0))
|
||||
assert theImport._newKey() == constData.importKeys[3]
|
||||
theImport.write(importKeys[2], "Crash", (0, 0, 0))
|
||||
assert theImport._newKey() == importKeys[3]
|
||||
|
||||
# Check Key
|
||||
# =========
|
||||
@@ -84,18 +87,19 @@ def testCoreStatus_Internal(constData):
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testCoreStatus_Iterator(constData):
|
||||
def testCoreStatus_Iterator():
|
||||
"""Test the iterator functions of the NWStatus class.
|
||||
"""
|
||||
random.seed(42)
|
||||
theStatus = NWStatus(NWStatus.STATUS)
|
||||
|
||||
theStatus.write(None, "New", (100, 100, 100))
|
||||
theStatus.write(None, "Note", (200, 50, 0))
|
||||
theStatus.write(None, "Draft", (200, 150, 0))
|
||||
theStatus.write(None, "Finished", (50, 200, 0))
|
||||
|
||||
# Direct access
|
||||
entry = theStatus[constData.statusKeys[0]]
|
||||
entry = theStatus[statusKeys[0]]
|
||||
assert entry["cols"] == (100, 100, 100)
|
||||
assert entry["name"] == "New"
|
||||
assert entry["count"] == 0
|
||||
@@ -107,11 +111,11 @@ def testCoreStatus_Iterator(constData):
|
||||
assert len(theStatus) == 4
|
||||
|
||||
# Keys
|
||||
assert list(theStatus.keys()) == constData.statusKeys
|
||||
assert list(theStatus.keys()) == statusKeys
|
||||
|
||||
# Items
|
||||
for index, (key, entry) in enumerate(theStatus.items()):
|
||||
assert key == constData.statusKeys[index]
|
||||
assert key == statusKeys[index]
|
||||
assert "cols" in entry
|
||||
assert "name" in entry
|
||||
assert "count" in entry
|
||||
@@ -128,7 +132,7 @@ def testCoreStatus_Iterator(constData):
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testCoreStatus_Entries(constData):
|
||||
def testCoreStatus_Entries():
|
||||
"""Test all the simple setters for the NWStatus class.
|
||||
"""
|
||||
random.seed(42)
|
||||
@@ -138,74 +142,74 @@ def testCoreStatus_Entries(constData):
|
||||
# =====
|
||||
|
||||
# Have a key
|
||||
theStatus.write(constData.statusKeys[0], "Entry 1", (200, 100, 50))
|
||||
assert theStatus[constData.statusKeys[0]]["name"] == "Entry 1"
|
||||
assert theStatus[constData.statusKeys[0]]["cols"] == (200, 100, 50)
|
||||
theStatus.write(statusKeys[0], "Entry 1", (200, 100, 50))
|
||||
assert theStatus[statusKeys[0]]["name"] == "Entry 1"
|
||||
assert theStatus[statusKeys[0]]["cols"] == (200, 100, 50)
|
||||
|
||||
# Don't have a key
|
||||
theStatus.write(None, "Entry 2", (210, 110, 60))
|
||||
assert theStatus[constData.statusKeys[1]]["name"] == "Entry 2"
|
||||
assert theStatus[constData.statusKeys[1]]["cols"] == (210, 110, 60)
|
||||
assert theStatus[statusKeys[1]]["name"] == "Entry 2"
|
||||
assert theStatus[statusKeys[1]]["cols"] == (210, 110, 60)
|
||||
|
||||
# Wrong colour spec
|
||||
theStatus.write(None, "Entry 3", "what?")
|
||||
assert theStatus[constData.statusKeys[2]]["name"] == "Entry 3"
|
||||
assert theStatus[constData.statusKeys[2]]["cols"] == (100, 100, 100)
|
||||
assert theStatus[statusKeys[2]]["name"] == "Entry 3"
|
||||
assert theStatus[statusKeys[2]]["cols"] == (100, 100, 100)
|
||||
|
||||
# Wrong colour count
|
||||
theStatus.write(None, "Entry 4", (10, 20))
|
||||
assert theStatus[constData.statusKeys[3]]["name"] == "Entry 4"
|
||||
assert theStatus[constData.statusKeys[3]]["cols"] == (100, 100, 100)
|
||||
assert theStatus[statusKeys[3]]["name"] == "Entry 4"
|
||||
assert theStatus[statusKeys[3]]["cols"] == (100, 100, 100)
|
||||
|
||||
# Check reverse map
|
||||
assert theStatus._reverse == {
|
||||
"Entry 1": constData.statusKeys[0],
|
||||
"Entry 2": constData.statusKeys[1],
|
||||
"Entry 3": constData.statusKeys[2],
|
||||
"Entry 4": constData.statusKeys[3],
|
||||
"Entry 1": statusKeys[0],
|
||||
"Entry 2": statusKeys[1],
|
||||
"Entry 3": statusKeys[2],
|
||||
"Entry 4": statusKeys[3],
|
||||
}
|
||||
|
||||
# Check
|
||||
# =====
|
||||
|
||||
# Normal lookup
|
||||
for key in constData.statusKeys:
|
||||
for key in statusKeys:
|
||||
assert theStatus.check(key) == key
|
||||
|
||||
# Reverse map lookup
|
||||
assert theStatus.check("Entry 1") == constData.statusKeys[0]
|
||||
assert theStatus.check("Entry 2") == constData.statusKeys[1]
|
||||
assert theStatus.check("Entry 3") == constData.statusKeys[2]
|
||||
assert theStatus.check("Entry 4") == constData.statusKeys[3]
|
||||
assert theStatus.check("Entry 1") == statusKeys[0]
|
||||
assert theStatus.check("Entry 2") == statusKeys[1]
|
||||
assert theStatus.check("Entry 3") == statusKeys[2]
|
||||
assert theStatus.check("Entry 4") == statusKeys[3]
|
||||
|
||||
# Non-existing name
|
||||
assert theStatus.check("Entry 5") == constData.statusKeys[0]
|
||||
assert theStatus.check("Entry 5") == statusKeys[0]
|
||||
|
||||
# Name Access
|
||||
# ===========
|
||||
|
||||
assert theStatus.name(constData.statusKeys[0]) == "Entry 1"
|
||||
assert theStatus.name(constData.statusKeys[1]) == "Entry 2"
|
||||
assert theStatus.name(constData.statusKeys[2]) == "Entry 3"
|
||||
assert theStatus.name(constData.statusKeys[3]) == "Entry 4"
|
||||
assert theStatus.name(statusKeys[0]) == "Entry 1"
|
||||
assert theStatus.name(statusKeys[1]) == "Entry 2"
|
||||
assert theStatus.name(statusKeys[2]) == "Entry 3"
|
||||
assert theStatus.name(statusKeys[3]) == "Entry 4"
|
||||
assert theStatus.name("blablabla") == "Entry 1"
|
||||
|
||||
# Colour Access
|
||||
# =============
|
||||
|
||||
assert theStatus.cols(constData.statusKeys[0]) == (200, 100, 50)
|
||||
assert theStatus.cols(constData.statusKeys[1]) == (210, 110, 60)
|
||||
assert theStatus.cols(constData.statusKeys[2]) == (100, 100, 100)
|
||||
assert theStatus.cols(constData.statusKeys[3]) == (100, 100, 100)
|
||||
assert theStatus.cols(statusKeys[0]) == (200, 100, 50)
|
||||
assert theStatus.cols(statusKeys[1]) == (210, 110, 60)
|
||||
assert theStatus.cols(statusKeys[2]) == (100, 100, 100)
|
||||
assert theStatus.cols(statusKeys[3]) == (100, 100, 100)
|
||||
assert theStatus.cols("blablabla") == (200, 100, 50)
|
||||
|
||||
# Icon Access
|
||||
# ===========
|
||||
|
||||
assert isinstance(theStatus.icon(constData.statusKeys[0]), QIcon)
|
||||
assert isinstance(theStatus.icon(constData.statusKeys[1]), QIcon)
|
||||
assert isinstance(theStatus.icon(constData.statusKeys[2]), QIcon)
|
||||
assert isinstance(theStatus.icon(constData.statusKeys[3]), QIcon)
|
||||
assert isinstance(theStatus.icon(statusKeys[0]), QIcon)
|
||||
assert isinstance(theStatus.icon(statusKeys[1]), QIcon)
|
||||
assert isinstance(theStatus.icon(statusKeys[2]), QIcon)
|
||||
assert isinstance(theStatus.icon(statusKeys[3]), QIcon)
|
||||
assert isinstance(theStatus.icon("blablabla"), QIcon)
|
||||
|
||||
# Increment and Count Access
|
||||
@@ -214,26 +218,26 @@ def testCoreStatus_Entries(constData):
|
||||
countTo = [3, 5, 7, 9]
|
||||
for i, n in enumerate(countTo):
|
||||
for _ in range(n):
|
||||
theStatus.increment(constData.statusKeys[i])
|
||||
theStatus.increment(statusKeys[i])
|
||||
|
||||
assert theStatus.count(constData.statusKeys[0]) == countTo[0]
|
||||
assert theStatus.count(constData.statusKeys[1]) == countTo[1]
|
||||
assert theStatus.count(constData.statusKeys[2]) == countTo[2]
|
||||
assert theStatus.count(constData.statusKeys[3]) == countTo[3]
|
||||
assert theStatus.count(statusKeys[0]) == countTo[0]
|
||||
assert theStatus.count(statusKeys[1]) == countTo[1]
|
||||
assert theStatus.count(statusKeys[2]) == countTo[2]
|
||||
assert theStatus.count(statusKeys[3]) == countTo[3]
|
||||
assert theStatus.count("blablabla") == countTo[0]
|
||||
|
||||
theStatus.resetCounts()
|
||||
|
||||
assert theStatus.count(constData.statusKeys[0]) == 0
|
||||
assert theStatus.count(constData.statusKeys[1]) == 0
|
||||
assert theStatus.count(constData.statusKeys[2]) == 0
|
||||
assert theStatus.count(constData.statusKeys[3]) == 0
|
||||
assert theStatus.count(statusKeys[0]) == 0
|
||||
assert theStatus.count(statusKeys[1]) == 0
|
||||
assert theStatus.count(statusKeys[2]) == 0
|
||||
assert theStatus.count(statusKeys[3]) == 0
|
||||
|
||||
# Reorder
|
||||
# =======
|
||||
|
||||
cOrder = list(theStatus.keys())
|
||||
assert cOrder == constData.statusKeys
|
||||
assert cOrder == statusKeys
|
||||
|
||||
# Wrong length
|
||||
assert theStatus.reorder([]) is False
|
||||
@@ -243,10 +247,10 @@ def testCoreStatus_Entries(constData):
|
||||
|
||||
# Actual reaorder
|
||||
nOrder = [
|
||||
constData.statusKeys[0],
|
||||
constData.statusKeys[2],
|
||||
constData.statusKeys[1],
|
||||
constData.statusKeys[3],
|
||||
statusKeys[0],
|
||||
statusKeys[2],
|
||||
statusKeys[1],
|
||||
statusKeys[3],
|
||||
]
|
||||
assert theStatus.reorder(nOrder) is True
|
||||
assert list(theStatus.keys()) == nOrder
|
||||
@@ -282,15 +286,15 @@ def testCoreStatus_Entries(constData):
|
||||
assert theStatus.remove("blablabla") is False
|
||||
|
||||
# Non-zero entry
|
||||
theStatus.increment(constData.statusKeys[3])
|
||||
assert theStatus.remove(constData.statusKeys[3]) is False
|
||||
theStatus.increment(statusKeys[3])
|
||||
assert theStatus.remove(statusKeys[3]) is False
|
||||
|
||||
# Delete last entry
|
||||
theStatus.resetCounts()
|
||||
lastName = theStatus.name(constData.statusKeys[3])
|
||||
lastName = theStatus.name(statusKeys[3])
|
||||
assert lastName == "Entry 4"
|
||||
assert theStatus.remove(constData.statusKeys[3]) is True
|
||||
assert theStatus.check(constData.statusKeys[3]) == theStatus._default
|
||||
assert theStatus.remove(statusKeys[3]) is True
|
||||
assert theStatus.check(statusKeys[3]) == theStatus._default
|
||||
assert theStatus.check(lastName) == theStatus._default
|
||||
|
||||
# Delete default entry, Entry 2 is new default
|
||||
@@ -300,8 +304,8 @@ def testCoreStatus_Entries(constData):
|
||||
assert theStatus.name(firstName) == "Entry 2"
|
||||
|
||||
# Remove remaining entries
|
||||
assert theStatus.remove(constData.statusKeys[1]) is True
|
||||
assert theStatus.remove(constData.statusKeys[2]) is True
|
||||
assert theStatus.remove(statusKeys[1]) is True
|
||||
assert theStatus.remove(statusKeys[2]) is True
|
||||
|
||||
assert len(theStatus) == 0
|
||||
assert theStatus._default is None
|
||||
@@ -310,7 +314,7 @@ def testCoreStatus_Entries(constData):
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testCoreStatus_XMLPackUnpack(constData):
|
||||
def testCoreStatus_XMLPackUnpack():
|
||||
"""Test all the XML pack/unpack of the NWStatus class.
|
||||
"""
|
||||
random.seed(42)
|
||||
@@ -323,7 +327,7 @@ def testCoreStatus_XMLPackUnpack(constData):
|
||||
countTo = [3, 5, 7, 9]
|
||||
for i, n in enumerate(countTo):
|
||||
for _ in range(n):
|
||||
theStatus.increment(constData.statusKeys[i])
|
||||
theStatus.increment(statusKeys[i])
|
||||
|
||||
nwXML = etree.Element("novelWriterXML")
|
||||
|
||||
@@ -343,18 +347,18 @@ def testCoreStatus_XMLPackUnpack(constData):
|
||||
theStatus = NWStatus(NWStatus.STATUS)
|
||||
assert theStatus.unpackXML(xStatus)
|
||||
assert len(theStatus._store) == 4
|
||||
assert list(theStatus._store.keys()) == constData.statusKeys
|
||||
assert theStatus._store[constData.statusKeys[0]]["name"] == "New"
|
||||
assert theStatus._store[constData.statusKeys[1]]["name"] == "Note"
|
||||
assert theStatus._store[constData.statusKeys[2]]["name"] == "Draft"
|
||||
assert theStatus._store[constData.statusKeys[3]]["name"] == "Finished"
|
||||
assert theStatus._store[constData.statusKeys[0]]["cols"] == (100, 100, 100)
|
||||
assert theStatus._store[constData.statusKeys[1]]["cols"] == (200, 50, 0)
|
||||
assert theStatus._store[constData.statusKeys[2]]["cols"] == (200, 150, 0)
|
||||
assert theStatus._store[constData.statusKeys[3]]["cols"] == (50, 200, 0)
|
||||
assert theStatus._store[constData.statusKeys[0]]["count"] == countTo[0]
|
||||
assert theStatus._store[constData.statusKeys[1]]["count"] == countTo[1]
|
||||
assert theStatus._store[constData.statusKeys[2]]["count"] == countTo[2]
|
||||
assert theStatus._store[constData.statusKeys[3]]["count"] == countTo[3]
|
||||
assert list(theStatus._store.keys()) == statusKeys
|
||||
assert theStatus._store[statusKeys[0]]["name"] == "New"
|
||||
assert theStatus._store[statusKeys[1]]["name"] == "Note"
|
||||
assert theStatus._store[statusKeys[2]]["name"] == "Draft"
|
||||
assert theStatus._store[statusKeys[3]]["name"] == "Finished"
|
||||
assert theStatus._store[statusKeys[0]]["cols"] == (100, 100, 100)
|
||||
assert theStatus._store[statusKeys[1]]["cols"] == (200, 50, 0)
|
||||
assert theStatus._store[statusKeys[2]]["cols"] == (200, 150, 0)
|
||||
assert theStatus._store[statusKeys[3]]["cols"] == (50, 200, 0)
|
||||
assert theStatus._store[statusKeys[0]]["count"] == countTo[0]
|
||||
assert theStatus._store[statusKeys[1]]["count"] == countTo[1]
|
||||
assert theStatus._store[statusKeys[2]]["count"] == countTo[2]
|
||||
assert theStatus._store[statusKeys[3]]["count"] == countTo[3]
|
||||
|
||||
# END Test testCoreStatus_XMLPackUnpack
|
||||
|
||||
@@ -136,7 +136,6 @@ def testCoreToken_TextOps(monkeypatch, nwMinimal, mockGUI):
|
||||
"""Test handling files and text in the Tokenizer class.
|
||||
"""
|
||||
theProject = NWProject(mockGUI)
|
||||
theProject.projTree.setSeed(42)
|
||||
theProject.projLang = "en"
|
||||
theProject._loadProjectLocalisation()
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@ import pytest
|
||||
import random
|
||||
|
||||
from lxml import etree
|
||||
from hashlib import sha256
|
||||
|
||||
from tools import readFile
|
||||
|
||||
@@ -34,10 +33,9 @@ from novelwriter.constants import nwFiles
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def mockItems(mockGUI):
|
||||
def mockItems(mockGUI, mockRnd):
|
||||
"""Create a list of mock items.
|
||||
"""
|
||||
random.seed(42)
|
||||
theProject = NWProject(mockGUI)
|
||||
|
||||
itemA = NWItem(theProject)
|
||||
@@ -118,9 +116,6 @@ def testCoreTree_BuildTree(mockGUI, mockItems):
|
||||
theProject = NWProject(mockGUI)
|
||||
theTree = NWTree(theProject)
|
||||
|
||||
theTree.setSeed(42)
|
||||
assert theTree._handleSeed == 42
|
||||
|
||||
# Check that tree is empty (calls NWTree.__bool__)
|
||||
assert bool(theTree) is False
|
||||
|
||||
@@ -196,10 +191,11 @@ def testCoreTree_BuildTree(mockGUI, mockItems):
|
||||
assert len(theTree) == len(mockItems) + 1
|
||||
|
||||
theList = theTree.handles()
|
||||
assert theList[-1] == "73475cb40a568"
|
||||
nHandle = "0000000000010"
|
||||
assert theList[-1] == nHandle
|
||||
|
||||
# Try to add existing handle
|
||||
assert theTree.append("73475cb40a568", None, itemT) is False
|
||||
assert theTree.append(nHandle, None, itemT) is False
|
||||
assert len(theTree) == len(mockItems) + 1
|
||||
|
||||
# Delete a non-existing item
|
||||
@@ -207,9 +203,9 @@ def testCoreTree_BuildTree(mockGUI, mockItems):
|
||||
assert len(theTree) == len(mockItems) + 1
|
||||
|
||||
# Delete the last item
|
||||
del theTree["73475cb40a568"]
|
||||
del theTree[nHandle]
|
||||
assert len(theTree) == len(mockItems)
|
||||
assert "73475cb40a568" not in theTree
|
||||
assert nHandle not in theTree
|
||||
|
||||
# Delete the Novel, Archive and Trash folders
|
||||
del theTree["a000000000001"]
|
||||
@@ -310,44 +306,31 @@ def testCoreTree_Methods(mockGUI, mockItems):
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testCoreTree_MakeHandles(monkeypatch, mockGUI):
|
||||
def testCoreTree_MakeHandles(mockGUI):
|
||||
"""Test generating item handles.
|
||||
"""
|
||||
random.seed(42)
|
||||
theProject = NWProject(mockGUI)
|
||||
theTree = NWTree(theProject)
|
||||
|
||||
theTree.setSeed(42)
|
||||
handles = ["1c803a3b1799d", "bdd6406671ad1", "3eb1346685257", "23b8c392456de"]
|
||||
|
||||
random.seed(42)
|
||||
tHandle = theTree._makeHandle()
|
||||
assert tHandle == "73475cb40a568"
|
||||
assert tHandle == handles[0]
|
||||
theTree._projTree[handles[0]] = None
|
||||
|
||||
# Add the next in line to the project to force duplicate
|
||||
theTree._projTree["44cb730c42048"] = None
|
||||
theTree._projTree[handles[1]] = None
|
||||
tHandle = theTree._makeHandle()
|
||||
assert tHandle == "71ee45a3c0db9"
|
||||
|
||||
# Fix the time() function and force a handle collission
|
||||
theTree.setSeed(None)
|
||||
theTree._handleCount = 0
|
||||
monkeypatch.setattr("novelwriter.core.tree.time", lambda: 123.4)
|
||||
assert tHandle == handles[2]
|
||||
theTree._projTree[handles[2]] = None
|
||||
|
||||
# Reset the seed to force collissions, which should still end up
|
||||
# returning the next handle in the sequence
|
||||
random.seed(42)
|
||||
tHandle = theTree._makeHandle()
|
||||
theTree._projTree[tHandle] = None
|
||||
newSeed = "123.4_0_"
|
||||
assert tHandle == sha256(newSeed.encode()).hexdigest()[0:13]
|
||||
|
||||
tHandle = theTree._makeHandle()
|
||||
theTree._projTree[tHandle] = None
|
||||
newSeed = "123.4_1_"
|
||||
assert tHandle == sha256(newSeed.encode()).hexdigest()[0:13]
|
||||
|
||||
# Reset the count and the handle for 0 and 1 should be duplicates
|
||||
# which forces the function to add the '!'
|
||||
theTree._handleCount = 0
|
||||
tHandle = theTree._makeHandle()
|
||||
theTree._projTree[tHandle] = None
|
||||
newSeed = "123.4_1_!"
|
||||
assert tHandle == sha256(newSeed.encode()).hexdigest()[0:13]
|
||||
assert tHandle == handles[3]
|
||||
|
||||
# END Test testCoreTree_MakeHandles
|
||||
|
||||
@@ -412,7 +395,7 @@ def testCoreTree_Reorder(mockGUI, mockItems):
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testCoreTree_XMLPackUnpack(mockGUI, mockItems, constData):
|
||||
def testCoreTree_XMLPackUnpack(mockGUI, mockItems):
|
||||
"""Test packing and unpacking the tree to and from XML.
|
||||
"""
|
||||
theProject = NWProject(mockGUI)
|
||||
@@ -426,41 +409,39 @@ def testCoreTree_XMLPackUnpack(mockGUI, mockItems, constData):
|
||||
|
||||
nwXML = etree.Element("novelWriterXML")
|
||||
theTree.packXML(nwXML)
|
||||
assert etree.tostring(nwXML, pretty_print=False, encoding="utf-8") == bytes((
|
||||
'<novelWriterXML>'
|
||||
'<content count="8">'
|
||||
'<item handle="a000000000001" parent="None" root="a000000000001" order="0" type="ROOT" '
|
||||
'class="NOVEL"><meta expanded="True"/><name status="{s0}" '
|
||||
'import="{i0}">Novel</name></item>'
|
||||
'<item handle="b000000000001" parent="a000000000001" root="a000000000001" order="0" '
|
||||
'type="FOLDER" class="NOVEL"><meta expanded="True"/><name status="{s0}" '
|
||||
'import="{i0}">Act One</name></item>'
|
||||
'<item handle="c000000000001" parent="b000000000001" root="a000000000001" order="0" '
|
||||
'type="FILE" class="NOVEL" layout="DOCUMENT"><meta charCount="300" wordCount="50" '
|
||||
'paraCount="2" cursorPos="0"/><name status="{s0}" import="{i0}" '
|
||||
'exported="True">Chapter One</name></item>'
|
||||
'<item handle="c000000000002" parent="b000000000001" root="a000000000001" order="0" '
|
||||
'type="FILE" class="NOVEL" layout="DOCUMENT"><meta charCount="3000" wordCount="500" '
|
||||
'paraCount="20" cursorPos="0"/><name status="{s0}" import="{i0}" '
|
||||
'exported="True">Scene One</name></item>'
|
||||
'<item handle="a000000000002" parent="None" root="a000000000002" order="0" type="ROOT" '
|
||||
'class="ARCHIVE"><meta expanded="False"/><name status="{s0}" '
|
||||
'import="{i0}">Outtakes</name></item>'
|
||||
'<item handle="a000000000003" parent="None" root="a000000000003" order="0" type="TRASH" '
|
||||
'class="TRASH"><meta expanded="False"/><name status="{s0}" '
|
||||
'import="{i0}">Trash</name></item>'
|
||||
'<item handle="a000000000004" parent="None" root="a000000000004" order="0" type="ROOT" '
|
||||
'class="CHARACTER"><meta expanded="True"/><name status="{s0}" '
|
||||
'import="{i0}">Characters</name></item>'
|
||||
'<item handle="b000000000002" parent="a000000000004" root="a000000000004" order="0" '
|
||||
'type="FILE" class="CHARACTER" layout="NOTE"><meta charCount="2000" wordCount="400" '
|
||||
'paraCount="16" cursorPos="0"/><name status="{s0}" import="{i0}" '
|
||||
'exported="True">Jane Doe</name></item>'
|
||||
'</content>'
|
||||
'</novelWriterXML>'
|
||||
).format(
|
||||
s0=constData.statusKeys[0], i0=constData.importKeys[0]
|
||||
), encoding="utf8")
|
||||
assert etree.tostring(nwXML, pretty_print=False, encoding="utf-8") == (
|
||||
b'<novelWriterXML>'
|
||||
b'<content count="8">'
|
||||
b'<item handle="a000000000001" parent="None" root="a000000000001" order="0" type="ROOT" '
|
||||
b'class="NOVEL"><meta expanded="True"/><name status="s000000" '
|
||||
b'import="i000004">Novel</name></item>'
|
||||
b'<item handle="b000000000001" parent="a000000000001" root="a000000000001" order="0" '
|
||||
b'type="FOLDER" class="NOVEL"><meta expanded="True"/><name status="s000000" '
|
||||
b'import="i000004">Act One</name></item>'
|
||||
b'<item handle="c000000000001" parent="b000000000001" root="a000000000001" order="0" '
|
||||
b'type="FILE" class="NOVEL" layout="DOCUMENT"><meta charCount="300" wordCount="50" '
|
||||
b'paraCount="2" cursorPos="0"/><name status="s000000" import="i000004" '
|
||||
b'exported="True">Chapter One</name></item>'
|
||||
b'<item handle="c000000000002" parent="b000000000001" root="a000000000001" order="0" '
|
||||
b'type="FILE" class="NOVEL" layout="DOCUMENT"><meta charCount="3000" wordCount="500" '
|
||||
b'paraCount="20" cursorPos="0"/><name status="s000000" import="i000004" '
|
||||
b'exported="True">Scene One</name></item>'
|
||||
b'<item handle="a000000000002" parent="None" root="a000000000002" order="0" type="ROOT" '
|
||||
b'class="ARCHIVE"><meta expanded="False"/><name status="s000000" '
|
||||
b'import="i000004">Outtakes</name></item>'
|
||||
b'<item handle="a000000000003" parent="None" root="a000000000003" order="0" type="TRASH" '
|
||||
b'class="TRASH"><meta expanded="False"/><name status="s000000" '
|
||||
b'import="i000004">Trash</name></item>'
|
||||
b'<item handle="a000000000004" parent="None" root="a000000000004" order="0" type="ROOT" '
|
||||
b'class="CHARACTER"><meta expanded="True"/><name status="s000000" '
|
||||
b'import="i000004">Characters</name></item>'
|
||||
b'<item handle="b000000000002" parent="a000000000004" root="a000000000004" order="0" '
|
||||
b'type="FILE" class="CHARACTER" layout="NOTE"><meta charCount="2000" wordCount="400" '
|
||||
b'paraCount="16" cursorPos="0"/><name status="s000000" import="i000004" '
|
||||
b'exported="True">Jane Doe</name></item>'
|
||||
b'</content>'
|
||||
b'</novelWriterXML>'
|
||||
)
|
||||
|
||||
theTree.clear()
|
||||
assert len(theTree) == 0
|
||||
|
||||
Reference in New Issue
Block a user