Decouple item tests

This commit is contained in:
Veronica K. B. Olsen
2020-08-28 13:16:22 +02:00
parent b065e4d52b
commit 3869d8670c
+54 -22
View File
@@ -11,16 +11,19 @@ from nw.config import Config
from nw.core.project import NWProject, NWItem from nw.core.project import NWProject, NWItem
from nw.constants import nwItemClass, nwItemType, nwItemLayout from nw.constants import nwItemClass, nwItemType, nwItemLayout
theConf = Config() # theConf = Config()
theMain = DummyMain() # theMain = DummyMain()
theMain.mainConf = theConf # theMain.mainConf = theConf
theProject = NWProject(theMain) # theProject = NWProject(theMain)
theItem = NWItem(theProject) # theItem = NWItem(theProject)
nwXML = etree.Element("novelWriterXML") # nwXML = etree.Element("novelWriterXML")
@pytest.mark.project @pytest.mark.project
def testItemSettersSimple(): def testItemSettersSimple(nwDummy):
theProject = NWProject(nwDummy)
theItem = NWItem(theProject)
# Name # Name
theItem.setName("A Name") theItem.setName("A Name")
@@ -113,7 +116,10 @@ def testItemSettersSimple():
assert theItem.cursorPos == 1 assert theItem.cursorPos == 1
@pytest.mark.project @pytest.mark.project
def testItemClassSetter(): def testItemClassSetter(nwDummy):
theProject = NWProject(nwDummy)
theItem = NWItem(theProject)
# Class # Class
theItem.setClass(None) theItem.setClass(None)
@@ -138,13 +144,18 @@ def testItemClassSetter():
assert theItem.itemClass == nwItemClass.ENTITY assert theItem.itemClass == nwItemClass.ENTITY
theItem.setClass("CUSTOM") theItem.setClass("CUSTOM")
assert theItem.itemClass == nwItemClass.CUSTOM assert theItem.itemClass == nwItemClass.CUSTOM
theItem.setClass("ARCHIVE")
assert theItem.itemClass == nwItemClass.ARCHIVE
theItem.setClass("TRASH") theItem.setClass("TRASH")
assert theItem.itemClass == nwItemClass.TRASH assert theItem.itemClass == nwItemClass.TRASH
@pytest.mark.project @pytest.mark.project
def testItemTypeSetter(): def testItemTypeSetter(nwDummy):
# Class theProject = NWProject(nwDummy)
theItem = NWItem(theProject)
# Type
theItem.setType(None) theItem.setType(None)
assert theItem.itemType == nwItemType.NO_TYPE assert theItem.itemType == nwItemType.NO_TYPE
theItem.setType("NONSENSE") theItem.setType("NONSENSE")
@@ -161,9 +172,12 @@ def testItemTypeSetter():
assert theItem.itemType == nwItemType.TRASH assert theItem.itemType == nwItemType.TRASH
@pytest.mark.project @pytest.mark.project
def testItemLayoutSetter(): def testItemLayoutSetter(nwDummy):
# Class theProject = NWProject(nwDummy)
theItem = NWItem(theProject)
# Layout
theItem.setLayout(None) theItem.setLayout(None)
assert theItem.itemLayout == nwItemLayout.NO_LAYOUT assert theItem.itemLayout == nwItemLayout.NO_LAYOUT
theItem.setLayout("NONSENSE") theItem.setLayout("NONSENSE")
@@ -188,7 +202,25 @@ def testItemLayoutSetter():
assert theItem.itemLayout == nwItemLayout.NOTE assert theItem.itemLayout == nwItemLayout.NOTE
@pytest.mark.project @pytest.mark.project
def testItemXMLPackUnpack(): def testItemXMLPackUnpack(nwDummy):
theProject = NWProject(nwDummy)
theItem = NWItem(theProject)
nwXML = etree.Element("novelWriterXML")
theItem.setHandle("0123456789abc")
theItem.setParent("0123456789abc")
theItem.setOrder(1)
theItem.setName("A Name")
theItem.setClass("NOVEL")
theItem.setType("FILE")
theItem.setStatus("Main")
theItem.setLayout("NOTE")
theItem.setExpanded(True)
theItem.setParaCount(3)
theItem.setWordCount(5)
theItem.setCharCount(7)
theItem.setCursorPos(11)
# Pack # Pack
xContent = etree.SubElement(nwXML, "content") xContent = etree.SubElement(nwXML, "content")
@@ -196,9 +228,9 @@ def testItemXMLPackUnpack():
assert etree.tostring(xContent, pretty_print=False, encoding="utf-8") == ( assert etree.tostring(xContent, pretty_print=False, encoding="utf-8") == (
b"<content>" b"<content>"
b"<item handle=\"0123456789abc\" order=\"1\" parent=\"0123456789abc\">" b"<item handle=\"0123456789abc\" order=\"1\" parent=\"0123456789abc\">"
b"<name>A Name</name><type>TRASH</type><class>TRASH</class>" b"<name>A Name</name><type>FILE</type><class>NOVEL</class><status>New</status>"
b"<status>Main</status><expanded>True</expanded>" b"<exported>True</exported><layout>NOTE</layout><charCount>7</charCount>"
b"</item>" b"<wordCount>5</wordCount><paraCount>3</paraCount><cursorPos>11</cursorPos></item>"
b"</content>" b"</content>"
) )
@@ -208,10 +240,10 @@ def testItemXMLPackUnpack():
assert theItem.parHandle == "0123456789abc" assert theItem.parHandle == "0123456789abc"
assert theItem.itemOrder == 1 assert theItem.itemOrder == 1
assert theItem.isExpanded assert theItem.isExpanded
assert theItem.charCount == 1 assert theItem.paraCount == 3
assert theItem.wordCount == 1 assert theItem.wordCount == 5
assert theItem.paraCount == 1 assert theItem.charCount == 7
assert theItem.cursorPos == 1 assert theItem.cursorPos == 11
assert theItem.itemClass == nwItemClass.TRASH assert theItem.itemClass == nwItemClass.NOVEL
assert theItem.itemType == nwItemType.TRASH assert theItem.itemType == nwItemType.FILE
assert theItem.itemLayout == nwItemLayout.NOTE assert theItem.itemLayout == nwItemLayout.NOTE