Save both status and importance flags (#1030)

* Put the status icons in the status object itself
* Allow saving both status and importance values
* Update current tests
* Improve test coverage
* Update sample project file
This commit is contained in:
Veronica Berglyd Olsen
2022-04-03 22:43:11 +02:00
committed by GitHub
parent a04b44d890
commit 23fd6b815f
29 changed files with 481 additions and 418 deletions
+60 -15
View File
@@ -23,6 +23,8 @@ import pytest
from lxml import etree
from PyQt5.QtGui import QIcon
from novelwriter.core import NWProject
from novelwriter.core.item import NWItem
from novelwriter.enum import nwItemClass, nwItemType, nwItemLayout
@@ -74,16 +76,17 @@ def testCoreItem_Setters(mockGUI):
assert theItem.itemOrder == 1
# Importance
theItem.setStatus("Nonsense")
assert theItem.itemStatus == "New"
theItem.setStatus("New")
assert theItem.itemStatus == "New"
theItem.setStatus("Minor")
assert theItem.itemStatus == "Minor"
theItem.setStatus("Major")
assert theItem.itemStatus == "Major"
theItem.setStatus("Main")
assert theItem.itemStatus == "Main"
theItem._class = nwItemClass.CHARACTER
theItem.setImport("Nonsense")
assert theItem.itemImport == "New"
theItem.setImport("New")
assert theItem.itemImport == "New"
theItem.setImport("Minor")
assert theItem.itemImport == "Minor"
theItem.setImport("Major")
assert theItem.itemImport == "Major"
theItem.setImport("Main")
assert theItem.itemImport == "Main"
# Status
theItem._class = nwItemClass.NOVEL
@@ -98,6 +101,27 @@ def testCoreItem_Setters(mockGUI):
theItem.setStatus("Finished")
assert theItem.itemStatus == "Finished"
# Status/Importance Wrapper
theItem._class = nwItemClass.CHARACTER
theItem.setImportStatus("New")
assert theItem.itemImport == "New"
theItem.setImportStatus("Minor")
assert theItem.itemImport == "Minor"
theItem.setImportStatus("Note")
assert theItem.itemImport == "New"
theItem.setImportStatus("Draft")
assert theItem.itemImport == "New"
theItem._class = nwItemClass.NOVEL
theItem.setImportStatus("New")
assert theItem.itemStatus == "New"
theItem.setImportStatus("Minor")
assert theItem.itemStatus == "New"
theItem.setImportStatus("Note")
assert theItem.itemStatus == "Note"
theItem.setImportStatus("Draft")
assert theItem.itemStatus == "Draft"
# Expanded
theItem.setExpanded(8)
assert theItem.isExpanded is False
@@ -196,6 +220,22 @@ def testCoreItem_Methods(mockGUI):
theItem.setLayout("NOTE")
assert theItem.describeMe() == "Project Note"
# Status + Icon
# =============
theItem.setType("FILE")
theItem.setStatus("Note")
theItem.setImport("Minor")
theItem.setClass("NOVEL")
stT, stI = theItem.getImportStatus()
assert stT == "Note"
assert isinstance(stI, QIcon)
theItem.setClass("CHARACTER")
stT, stI = theItem.getImportStatus()
assert stT == "Minor"
assert isinstance(stI, QIcon)
# Representation
# ==============
@@ -342,9 +382,11 @@ def testCoreItem_XMLPackUnpack(mockGUI, caplog):
xContent = etree.SubElement(nwXML, "content")
theItem.packXML(xContent)
assert etree.tostring(xContent, pretty_print=False, encoding="utf-8") == (
b'<content><item handle="0123456789abc" parent="0123456789abc" order="1" type="FILE" '
b'class="NOVEL" layout="NOTE"><meta charCount="7" wordCount="5" paraCount="3" '
b'cursorPos="11"/><name status="New" exported="False">A Name</name></item></content>'
b'<content>'
b'<item handle="0123456789abc" parent="0123456789abc" order="1" type="FILE" class="NOVEL" '
b'layout="NOTE"><meta charCount="7" wordCount="5" paraCount="3" cursorPos="11"/>'
b'<name status="New" import="None" exported="False">A Name</name></item>'
b'</content>'
)
# Unpack
@@ -385,8 +427,11 @@ def testCoreItem_XMLPackUnpack(mockGUI, caplog):
xContent = etree.SubElement(nwXML, "content")
theItem.packXML(xContent)
assert etree.tostring(xContent, pretty_print=False, encoding="utf-8") == (
b'<content><item handle="0123456789abc" parent="0123456789abc" order="1" type="FOLDER" '
b'class="NOVEL"><meta expanded="True"/><name status="New">A Name</name></item></content>'
b'<content>'
b'<item handle="0123456789abc" parent="0123456789abc" order="1" type="FOLDER" '
b'class="NOVEL"><meta expanded="True"/><name status="New" import="None">A Name</name>'
b'</item>'
b'</content>'
)
# Unpack
+2 -6
View File
@@ -61,10 +61,6 @@ def testCoreProject_NewMinimal(fncDir, outDir, refDir, mockGUI):
# Creating the project once more should fail
assert theProject.newProject({"projPath": fncDir}) is False
# Check the new project
copyfile(projFile, testFile)
assert cmpFiles(testFile, compFile, [2, 6, 7, 8])
# Open again
assert theProject.openProject(projFile) is True
@@ -857,7 +853,7 @@ def testCoreProject_Methods(monkeypatch, nwMinimal, mockGUI, tmpDir):
# Change importance
fHandle = theProject.newFile("Jane Doe", nwItemClass.CHARACTER, "afb3043c7b2b3")
theProject.projTree[fHandle].setStatus("Main")
theProject.projTree[fHandle].setImport("Main")
newList = [
("New", 1, 1, 1, "New"),
("Minor", 2, 2, 2, "Minor"),
@@ -872,7 +868,7 @@ def testCoreProject_Methods(monkeypatch, nwMinimal, mockGUI, tmpDir):
assert theProject.importItems._theColours == [
(1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4), (5, 5, 5)
]
assert theProject.projTree[fHandle].itemStatus == "Min"
assert theProject.projTree[fHandle].itemImport == "Min"
# Check status counts
assert theProject.statusItems._theCounts == [0, 0, 0, 0, 0]
+22 -11
View File
@@ -23,6 +23,8 @@ import pytest
from lxml import etree
from PyQt5.QtGui import QIcon
from novelwriter.core.status import NWStatus
@@ -48,9 +50,9 @@ def testCoreStatus_Entries():
assert theStatus._theLength == 4
# Lookups
assert theStatus.lookupEntry(None) is None
assert theStatus.lookupEntry("stuff") is None
assert theStatus.lookupEntry("Main") == 3
assert theStatus._getIndex(None) is None
assert theStatus._getIndex("stuff") is None
assert theStatus._getIndex("Main") == 3
# Checks
assert theStatus.checkEntry(123) == "New"
@@ -58,6 +60,10 @@ def testCoreStatus_Entries():
assert theStatus.checkEntry("New ") == "New"
assert theStatus.checkEntry(" Main ") == "Main"
# Icons
assert isinstance(theStatus.getIcon("Stuff"), QIcon)
assert isinstance(theStatus.getIcon("New"), QIcon)
# Set new list
newList = [
("New", 1, 1, 1, "New"),
@@ -87,12 +93,17 @@ def testCoreStatus_Entries():
assert theStatus._theCounts == countTo
# Iterate
for i, (sA, sB, sC) in enumerate(theStatus):
for i, (sA, sB, sC, sD) in enumerate(theStatus):
assert sA == theStatus._theLabels[i]
assert sB == theStatus._theColours[i]
assert sC == theStatus._theCounts[i]
assert sD == theStatus._theIcons[i]
assert theStatus[9] == (None, None, None)
sA, sB, sC, sD = theStatus[9]
assert sA is None
assert sB is None
assert sC is None
assert isinstance(sD, QIcon)
# Clear counts
theStatus.resetCounts()
@@ -122,12 +133,12 @@ def testCoreStatus_XMLPackUnpack():
xStatus = etree.SubElement(nwXML, "status")
theStatus.packXML(xStatus)
assert etree.tostring(xStatus, pretty_print=False, encoding="utf-8") == (
b"<status>"
b"<entry blue=\"100\" green=\"100\" red=\"100\">New</entry>"
b"<entry blue=\"0\" green=\"50\" red=\"200\">Minor</entry>"
b"<entry blue=\"0\" green=\"150\" red=\"200\">Major</entry>"
b"<entry blue=\"0\" green=\"200\" red=\"50\">Main</entry>"
b"</status>"
b'<status>'
b'<entry red="100" green="100" blue="100">New</entry>'
b'<entry red="200" green="50" blue="0">Minor</entry>'
b'<entry red="200" green="150" blue="0">Major</entry>'
b'<entry red="50" green="200" blue="0">Main</entry>'
b'</status>'
)
# Unpack
+5 -1
View File
@@ -30,7 +30,7 @@ from novelwriter.core.tokenizer import Tokenizer
class BareTokenizer(Tokenizer):
def doConvert(self):
pass
super().doConvert()
@pytest.mark.core
@@ -219,6 +219,10 @@ def testCoreToken_TextOps(monkeypatch, nwMinimal, mockGUI):
"# Notes: Plot\n\n"
)
# Ckeck abstract method
with pytest.raises(NotImplementedError):
theToken.doConvert()
# END Test testCoreToken_TextOps
+12 -11
View File
@@ -387,25 +387,26 @@ def testCoreTree_XMLPackUnpack(mockGUI, mockItems):
assert etree.tostring(nwXML, pretty_print=False, encoding="utf-8") == (
b'<novelWriterXML>'
b'<content count="8">'
b'<item handle="a000000000001" parent="None" order="0" type="ROOT" class="NOVEL">'
b'<meta expanded="True"/><name status="None">Novel</name></item>'
b'<item handle="a000000000001" parent="None" order="0" type="ROOT" class="NOVEL"><meta '
b'expanded="True"/><name status="None" import="None">Novel</name></item>'
b'<item handle="b000000000001" parent="a000000000001" order="0" type="FOLDER" '
b'class="NOVEL"><meta expanded="True"/><name status="None">Act One</name></item>'
b'class="NOVEL"><meta expanded="True"/><name status="None" import="None">Act One</name>'
b'</item>'
b'<item handle="c000000000001" parent="b000000000001" order="0" type="FILE" class="NOVEL" '
b'layout="DOCUMENT"><meta charCount="300" wordCount="50" paraCount="2" cursorPos="0"/>'
b'<name status="None" exported="True">Chapter One</name></item>'
b'<name status="None" import="None" exported="True">Chapter One</name></item>'
b'<item handle="c000000000002" parent="b000000000001" order="0" type="FILE" class="NOVEL" '
b'layout="DOCUMENT"><meta charCount="3000" wordCount="500" paraCount="20" cursorPos="0"/>'
b'<name status="None" exported="True">Scene One</name></item>'
b'<item handle="a000000000002" parent="None" order="0" type="ROOT" class="ARCHIVE">'
b'<meta expanded="False"/><name status="None">Outtakes</name></item>'
b'<item handle="a000000000003" parent="None" order="0" type="TRASH" class="TRASH">'
b'<meta expanded="False"/><name status="None">Trash</name></item>'
b'<name status="None" import="None" exported="True">Scene One</name></item>'
b'<item handle="a000000000002" parent="None" order="0" type="ROOT" class="ARCHIVE"><meta '
b'expanded="False"/><name status="None" import="None">Outtakes</name></item>'
b'<item handle="a000000000003" parent="None" order="0" type="TRASH" class="TRASH"><meta '
b'expanded="False"/><name status="None" import="None">Trash</name></item>'
b'<item handle="a000000000004" parent="None" order="0" type="ROOT" class="CHARACTER">'
b'<meta expanded="True"/><name status="None">Characters</name></item>'
b'<meta expanded="True"/><name status="None" import="None">Characters</name></item>'
b'<item handle="b000000000002" parent="a000000000002" order="0" type="FILE" '
b'class="CHARACTER" layout="NOTE"><meta charCount="2000" wordCount="400" paraCount="16" '
b'cursorPos="0"/><name status="None" exported="True">Jane Doe</name></item>'
b'cursorPos="0"/><name status="None" import="None" exported="True">Jane Doe</name></item>'
b'</content>'
b'</novelWriterXML>'
)