Remove pre-generatiopn of status and importance items
This commit is contained in:
@@ -25,7 +25,7 @@ from lxml import etree
|
||||
|
||||
from PyQt5.QtGui import QIcon
|
||||
|
||||
from tools import C
|
||||
from tools import C, buildTestProject
|
||||
|
||||
from novelwriter.core.item import NWItem
|
||||
from novelwriter.core.project import NWProject
|
||||
@@ -33,10 +33,12 @@ from novelwriter.enum import nwItemClass, nwItemType, nwItemLayout
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testCoreItem_Setters(mockGUI, mockRnd):
|
||||
def testCoreItem_Setters(mockGUI, mockRnd, fncDir):
|
||||
"""Test all the simple setters for the NWItem class.
|
||||
"""
|
||||
theProject = NWProject(mockGUI)
|
||||
mockRnd.reset()
|
||||
buildTestProject(theProject, fncDir)
|
||||
theItem = NWItem(theProject)
|
||||
|
||||
statusKeys = ["s000000", "s000001", "s000002", "s000003"]
|
||||
@@ -192,11 +194,12 @@ def testCoreItem_Setters(mockGUI, mockRnd):
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testCoreItem_Methods(mockGUI, mockRnd):
|
||||
def testCoreItem_Methods(mockGUI, mockRnd, fncDir):
|
||||
"""Test the simple methods of the NWItem class.
|
||||
"""
|
||||
mockRnd.reset()
|
||||
theProject = NWProject(mockGUI)
|
||||
mockRnd.reset()
|
||||
buildTestProject(theProject, fncDir)
|
||||
theItem = NWItem(theProject)
|
||||
|
||||
# Describe Me
|
||||
|
||||
@@ -263,14 +263,14 @@ def testCoreProject_NewRoot(fncDir, outDir, refDir, mockGUI, mockRnd):
|
||||
assert theProject.closeProject() is True
|
||||
assert theProject.openProject(projFile) is True
|
||||
|
||||
assert theProject.newRoot(nwItemClass.NOVEL) == "0000000000020"
|
||||
assert theProject.newRoot(nwItemClass.PLOT) == "0000000000021"
|
||||
assert theProject.newRoot(nwItemClass.CHARACTER) == "0000000000022"
|
||||
assert theProject.newRoot(nwItemClass.WORLD) == "0000000000023"
|
||||
assert theProject.newRoot(nwItemClass.TIMELINE) == "0000000000024"
|
||||
assert theProject.newRoot(nwItemClass.OBJECT) == "0000000000025"
|
||||
assert theProject.newRoot(nwItemClass.CUSTOM) == "0000000000026"
|
||||
assert theProject.newRoot(nwItemClass.CUSTOM) == "0000000000027"
|
||||
assert theProject.newRoot(nwItemClass.NOVEL) == "0000000000010"
|
||||
assert theProject.newRoot(nwItemClass.PLOT) == "0000000000011"
|
||||
assert theProject.newRoot(nwItemClass.CHARACTER) == "0000000000012"
|
||||
assert theProject.newRoot(nwItemClass.WORLD) == "0000000000013"
|
||||
assert theProject.newRoot(nwItemClass.TIMELINE) == "0000000000014"
|
||||
assert theProject.newRoot(nwItemClass.OBJECT) == "0000000000015"
|
||||
assert theProject.newRoot(nwItemClass.CUSTOM) == "0000000000016"
|
||||
assert theProject.newRoot(nwItemClass.CUSTOM) == "0000000000017"
|
||||
|
||||
assert theProject.projChanged is True
|
||||
assert theProject.saveProject() is True
|
||||
@@ -281,23 +281,23 @@ def testCoreProject_NewRoot(fncDir, outDir, refDir, mockGUI, mockRnd):
|
||||
assert theProject.projChanged is False
|
||||
|
||||
# Delete the new items
|
||||
assert theProject.removeItem("0000000000020") is True
|
||||
assert theProject.removeItem("0000000000021") is True
|
||||
assert theProject.removeItem("0000000000022") is True
|
||||
assert theProject.removeItem("0000000000023") is True
|
||||
assert theProject.removeItem("0000000000024") is True
|
||||
assert theProject.removeItem("0000000000025") is True
|
||||
assert theProject.removeItem("0000000000026") is True
|
||||
assert theProject.removeItem("0000000000027") is True
|
||||
assert theProject.removeItem("0000000000010") is True
|
||||
assert theProject.removeItem("0000000000011") is True
|
||||
assert theProject.removeItem("0000000000012") is True
|
||||
assert theProject.removeItem("0000000000013") is True
|
||||
assert theProject.removeItem("0000000000014") is True
|
||||
assert theProject.removeItem("0000000000015") is True
|
||||
assert theProject.removeItem("0000000000016") is True
|
||||
assert theProject.removeItem("0000000000017") is True
|
||||
|
||||
assert "0000000000020" not in theProject.tree
|
||||
assert "0000000000021" not in theProject.tree
|
||||
assert "0000000000022" not in theProject.tree
|
||||
assert "0000000000023" not in theProject.tree
|
||||
assert "0000000000024" not in theProject.tree
|
||||
assert "0000000000025" not in theProject.tree
|
||||
assert "0000000000026" not in theProject.tree
|
||||
assert "0000000000027" not in theProject.tree
|
||||
assert "0000000000010" not in theProject.tree
|
||||
assert "0000000000011" not in theProject.tree
|
||||
assert "0000000000012" not in theProject.tree
|
||||
assert "0000000000013" not in theProject.tree
|
||||
assert "0000000000014" not in theProject.tree
|
||||
assert "0000000000015" not in theProject.tree
|
||||
assert "0000000000016" not in theProject.tree
|
||||
assert "0000000000017" not in theProject.tree
|
||||
|
||||
# END Test testCoreProject_NewRoot
|
||||
|
||||
@@ -324,26 +324,26 @@ def testCoreProject_NewFileFolder(monkeypatch, fncDir, outDir, refDir, mockGUI,
|
||||
assert theProject.newFile("New File", "1234567890abc") is None
|
||||
|
||||
# Add files properly
|
||||
assert theProject.newFolder("Stuff", C.hNovelRoot) == "0000000000020"
|
||||
assert theProject.newFile("Hello", "0000000000020") == "0000000000021"
|
||||
assert theProject.newFile("Jane", C.hCharRoot) == "0000000000022"
|
||||
assert theProject.newFolder("Stuff", C.hNovelRoot) == "0000000000010"
|
||||
assert theProject.newFile("Hello", "0000000000010") == "0000000000011"
|
||||
assert theProject.newFile("Jane", C.hCharRoot) == "0000000000012"
|
||||
|
||||
assert "0000000000020" in theProject.tree
|
||||
assert "0000000000021" in theProject.tree
|
||||
assert "0000000000022" in theProject.tree
|
||||
assert "0000000000010" in theProject.tree
|
||||
assert "0000000000011" in theProject.tree
|
||||
assert "0000000000012" in theProject.tree
|
||||
|
||||
# Write to file, failed
|
||||
assert theProject.writeNewFile("blabla", 1, True) is False # Not a handle
|
||||
assert theProject.writeNewFile("0000000000020", 1, True) is False # Not a file
|
||||
assert theProject.writeNewFile("0000000000010", 1, True) is False # Not a file
|
||||
assert theProject.writeNewFile(C.hTitlePage, 1, True) is False # Already has content
|
||||
|
||||
# Write to file, success
|
||||
assert theProject.writeNewFile("0000000000021", 2, True) is True
|
||||
assert NWDoc(theProject, "0000000000021").readDocument() == "## Hello\n\n"
|
||||
assert theProject.writeNewFile("0000000000011", 2, True) is True
|
||||
assert NWDoc(theProject, "0000000000011").readDocument() == "## Hello\n\n"
|
||||
|
||||
# Write to file with additional text, success
|
||||
assert theProject.writeNewFile("0000000000022", 1, False, "Hi Jane\n\n") is True
|
||||
assert NWDoc(theProject, "0000000000022").readDocument() == "# Jane\n\nHi Jane\n\n"
|
||||
assert theProject.writeNewFile("0000000000012", 1, False, "Hi Jane\n\n") is True
|
||||
assert NWDoc(theProject, "0000000000012").readDocument() == "# Jane\n\nHi Jane\n\n"
|
||||
|
||||
# Save, close and check
|
||||
assert theProject.projChanged is True
|
||||
@@ -356,23 +356,23 @@ def testCoreProject_NewFileFolder(monkeypatch, fncDir, outDir, refDir, mockGUI,
|
||||
# Delete new file, but block access
|
||||
with monkeypatch.context() as mp:
|
||||
mp.setattr("os.unlink", causeOSError)
|
||||
assert theProject.removeItem("0000000000021") is False
|
||||
assert "0000000000021" in theProject.tree
|
||||
assert theProject.removeItem("0000000000011") is False
|
||||
assert "0000000000011" in theProject.tree
|
||||
|
||||
# Delete new files and folders
|
||||
assert os.path.isfile(os.path.join(fncDir, "content", "0000000000022.nwd"))
|
||||
assert os.path.isfile(os.path.join(fncDir, "content", "0000000000021.nwd"))
|
||||
assert os.path.isfile(os.path.join(fncDir, "content", "0000000000012.nwd"))
|
||||
assert os.path.isfile(os.path.join(fncDir, "content", "0000000000011.nwd"))
|
||||
|
||||
assert theProject.removeItem("0000000000022") is True
|
||||
assert theProject.removeItem("0000000000021") is True
|
||||
assert theProject.removeItem("0000000000020") is True
|
||||
assert theProject.removeItem("0000000000012") is True
|
||||
assert theProject.removeItem("0000000000011") is True
|
||||
assert theProject.removeItem("0000000000010") is True
|
||||
|
||||
assert not os.path.isfile(os.path.join(fncDir, "content", "0000000000022.nwd"))
|
||||
assert not os.path.isfile(os.path.join(fncDir, "content", "0000000000021.nwd"))
|
||||
assert not os.path.isfile(os.path.join(fncDir, "content", "0000000000012.nwd"))
|
||||
assert not os.path.isfile(os.path.join(fncDir, "content", "0000000000011.nwd"))
|
||||
|
||||
assert "0000000000020" not in theProject.tree
|
||||
assert "0000000000021" not in theProject.tree
|
||||
assert "0000000000022" not in theProject.tree
|
||||
assert "0000000000010" not in theProject.tree
|
||||
assert "0000000000011" not in theProject.tree
|
||||
assert "0000000000012" not in theProject.tree
|
||||
|
||||
assert theProject.closeProject() is True
|
||||
|
||||
@@ -933,7 +933,7 @@ def testCoreProject_Methods(monkeypatch, mockGUI, tmpDir, fncDir, mockRnd):
|
||||
|
||||
# Trash folder
|
||||
# Should create on first call, and just returned on later calls
|
||||
hTrash = "0000000000018"
|
||||
hTrash = "0000000000010"
|
||||
assert theProject.tree[hTrash] is None
|
||||
assert theProject.trashFolder() == hTrash
|
||||
assert theProject.trashFolder() == hTrash
|
||||
@@ -987,14 +987,14 @@ def testCoreProject_Methods(monkeypatch, mockGUI, tmpDir, fncDir, mockRnd):
|
||||
|
||||
# Change project tree order
|
||||
oldOrder = [
|
||||
"0000000000010", "0000000000011", "0000000000012",
|
||||
"0000000000013", "0000000000014", "0000000000015",
|
||||
"0000000000016", "0000000000017", "0000000000018",
|
||||
"0000000000008", "0000000000009", "000000000000a",
|
||||
"000000000000b", "000000000000c", "000000000000d",
|
||||
"000000000000e", "000000000000f", "0000000000010",
|
||||
]
|
||||
newOrder = [
|
||||
"0000000000013", "0000000000014", "0000000000015",
|
||||
"0000000000010", "0000000000011", "0000000000012",
|
||||
"0000000000016", "0000000000017",
|
||||
"000000000000b", "000000000000c", "000000000000d",
|
||||
"0000000000008", "0000000000009", "000000000000a",
|
||||
"000000000000e", "000000000000f",
|
||||
]
|
||||
assert theProject.tree.handles() == oldOrder
|
||||
assert theProject.setTreeOrder(newOrder)
|
||||
|
||||
@@ -23,8 +23,6 @@ import os
|
||||
import pytest
|
||||
import random
|
||||
|
||||
from lxml import etree
|
||||
|
||||
from tools import readFile
|
||||
|
||||
from novelwriter.enum import nwItemClass, nwItemType, nwItemLayout
|
||||
@@ -198,7 +196,7 @@ def testCoreTree_BuildTree(mockGUI, mockItems):
|
||||
assert len(theTree) == len(mockItems) + 1
|
||||
|
||||
theList = theTree.handles()
|
||||
nHandle = "0000000000010"
|
||||
nHandle = "0000000000000"
|
||||
assert theList[-1] == nHandle
|
||||
|
||||
# Try to add existing handle
|
||||
@@ -395,65 +393,6 @@ def testCoreTree_Reorder(mockGUI, mockItems):
|
||||
# END Test testCoreTree_Reorder
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
@pytest.mark.skip
|
||||
def testCoreTree_XMLPackUnpack(mockGUI, mockItems):
|
||||
"""Test packing and unpacking the tree to and from XML.
|
||||
"""
|
||||
theProject = NWProject(mockGUI)
|
||||
theTree = NWTree(theProject)
|
||||
|
||||
for tHandle, pHandle, nwItem in mockItems:
|
||||
theTree.append(tHandle, pHandle, nwItem)
|
||||
theTree.updateItemData(tHandle)
|
||||
|
||||
assert len(theTree) == len(mockItems)
|
||||
|
||||
nwXML = etree.Element("novelWriterXML")
|
||||
theTree.packXML(nwXML)
|
||||
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 expanded="False" mainHeading="H0" '
|
||||
b'charCount="300" wordCount="50" paraCount="2" cursorPos="0"/><name status="s000000" '
|
||||
b'import="i000004" active="True">Chapter One</name></item>'
|
||||
b'<item handle="c000000000002" parent="b000000000001" root="a000000000001" order="0" '
|
||||
b'type="FILE" class="NOVEL" layout="DOCUMENT"><meta expanded="False" mainHeading="H0" '
|
||||
b'charCount="3000" wordCount="500" paraCount="20" cursorPos="0"/><name status="s000000" '
|
||||
b'import="i000004" active="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="ROOT" '
|
||||
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 expanded="False" mainHeading="H0" '
|
||||
b'charCount="2000" wordCount="400" paraCount="16" cursorPos="0"/><name status="s000000" '
|
||||
b'import="i000004" active="True">Jane Doe</name></item>'
|
||||
b'</content>'
|
||||
b'</novelWriterXML>'
|
||||
)
|
||||
|
||||
theTree.clear()
|
||||
assert len(theTree) == 0
|
||||
assert not theTree.unpackXML(nwXML)
|
||||
assert theTree.unpackXML(nwXML[0])
|
||||
assert len(theTree) == len(mockItems)
|
||||
|
||||
# END Test testCoreTree_XMLPackUnpack
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testCoreTree_ToCFile(monkeypatch, mockGUI, mockItems, tmpDir):
|
||||
"""Test writing the ToC.txt file.
|
||||
|
||||
Reference in New Issue
Block a user