New test for NWItem class
This commit is contained in:
+9
-5
@@ -96,20 +96,21 @@ class NWItem():
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
if "handle" in xItem.attrib:
|
if "handle" in xItem.attrib:
|
||||||
self.itemHandle = xItem.attrib["handle"]
|
self.setHandle(xItem.attrib["handle"])
|
||||||
else:
|
else:
|
||||||
logger.error("XML item entry does not have a handle")
|
logger.error("XML item entry does not have a handle")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if "parent" in xItem.attrib:
|
if "parent" in xItem.attrib:
|
||||||
self.itemParent = xItem.attrib["parent"]
|
self.setParent(xItem.attrib["parent"])
|
||||||
|
|
||||||
|
if "order" in xItem.attrib:
|
||||||
|
self.setOrder(xItem.attrib["order"])
|
||||||
|
|
||||||
retStatus = True
|
retStatus = True
|
||||||
for xValue in xItem:
|
for xValue in xItem:
|
||||||
if xValue.tag == "name":
|
if xValue.tag == "name":
|
||||||
self.setName(xValue.text)
|
self.setName(xValue.text)
|
||||||
elif xValue.tag == "order":
|
|
||||||
self.setOrder(xValue.text)
|
|
||||||
elif xValue.tag == "type":
|
elif xValue.tag == "type":
|
||||||
self.setType(xValue.text)
|
self.setType(xValue.text)
|
||||||
elif xValue.tag == "class":
|
elif xValue.tag == "class":
|
||||||
@@ -156,7 +157,10 @@ class NWItem():
|
|||||||
def setName(self, theName):
|
def setName(self, theName):
|
||||||
"""Set the item name.
|
"""Set the item name.
|
||||||
"""
|
"""
|
||||||
self.itemName = theName.strip()
|
if isinstance(theName, str):
|
||||||
|
self.itemName = theName.strip()
|
||||||
|
else:
|
||||||
|
self.itemName = ""
|
||||||
return
|
return
|
||||||
|
|
||||||
def setHandle(self, theHandle):
|
def setHandle(self, theHandle):
|
||||||
|
|||||||
+140
-131
@@ -9,7 +9,7 @@ import os
|
|||||||
|
|
||||||
from nwdummy import DummyMain
|
from nwdummy import DummyMain
|
||||||
|
|
||||||
from PyQt5.QtWidgets import QMessageBox
|
# from PyQt5.QtWidgets import QMessageBox
|
||||||
|
|
||||||
sys.path.insert(1, os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
|
sys.path.insert(1, os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ from nw.config import Config # noqa: E402
|
|||||||
##
|
##
|
||||||
|
|
||||||
@pytest.fixture(scope="session")
|
@pytest.fixture(scope="session")
|
||||||
def nwTemp():
|
def tmpDir():
|
||||||
"""A temporary folder for the test session. This folder is
|
"""A temporary folder for the test session. This folder is
|
||||||
presistent after the test so that the status of generated files can
|
presistent after the test so that the status of generated files can
|
||||||
be checked. The folder is instead cleared before a new test session.
|
be checked. The folder is instead cleared before a new test session.
|
||||||
@@ -33,170 +33,179 @@ def nwTemp():
|
|||||||
os.mkdir(tempDir)
|
os.mkdir(tempDir)
|
||||||
return tempDir
|
return tempDir
|
||||||
|
|
||||||
@pytest.fixture(scope="session")
|
# @pytest.fixture(scope="session")
|
||||||
def nwRef():
|
# def nwRef():
|
||||||
"""The folder where all the reference files are stored for verifying
|
# """The folder where all the reference files are stored for verifying
|
||||||
the results of tests.
|
# the results of tests.
|
||||||
"""
|
# """
|
||||||
testDir = os.path.dirname(__file__)
|
# testDir = os.path.dirname(__file__)
|
||||||
refDir = os.path.join(testDir, "reference")
|
# refDir = os.path.join(testDir, "reference")
|
||||||
return refDir
|
# return refDir
|
||||||
|
|
||||||
##
|
##
|
||||||
# novelWriter Objects
|
# novelWriter Objects
|
||||||
##
|
##
|
||||||
|
|
||||||
|
# @pytest.fixture(scope="session")
|
||||||
|
# def tmpConf(nwTemp):
|
||||||
|
# """Create a temporary novelWriter configuration object.
|
||||||
|
# """
|
||||||
|
# theConf = Config()
|
||||||
|
# theConf.initConfig(nwTemp, nwTemp)
|
||||||
|
# theConf.setLastPath("")
|
||||||
|
# return theConf
|
||||||
|
|
||||||
@pytest.fixture(scope="session")
|
@pytest.fixture(scope="session")
|
||||||
def tmpConf(nwTemp):
|
def tmpConf(tmpDir):
|
||||||
"""Create a temporary novelWriter configuration object.
|
"""Create a temporary novelWriter configuration object.
|
||||||
"""
|
"""
|
||||||
theConf = Config()
|
theConf = Config()
|
||||||
theConf.initConfig(nwTemp, nwTemp)
|
theConf.initConfig(tmpDir, tmpDir)
|
||||||
theConf.setLastPath("")
|
theConf.setLastPath("")
|
||||||
return theConf
|
return theConf
|
||||||
|
|
||||||
@pytest.fixture(scope="session")
|
# @pytest.fixture(scope="session")
|
||||||
def nwConf(nwRef, nwTemp):
|
# def nwConf(nwRef, nwTemp):
|
||||||
"""Temporary novelWriter configuration used for the dummy instance
|
# """Temporary novelWriter configuration used for the dummy instance
|
||||||
of novelWriter's main GUI.
|
# of novelWriter's main GUI.
|
||||||
"""
|
# """
|
||||||
theConf = Config()
|
# theConf = Config()
|
||||||
theConf.initConfig(nwRef, nwTemp)
|
# theConf.initConfig(nwRef, nwTemp)
|
||||||
return theConf
|
# return theConf
|
||||||
|
|
||||||
@pytest.fixture(scope="session")
|
@pytest.fixture(scope="session")
|
||||||
def nwDummy(nwRef, nwTemp, nwConf):
|
def dummyGUI(tmpConf):
|
||||||
"""Create a dummy instance of novelWriter's main GUI class.
|
"""Create a dummy instance of novelWriter's main GUI class.
|
||||||
"""
|
"""
|
||||||
theDummy = DummyMain()
|
theDummy = DummyMain()
|
||||||
theDummy.mainConf = nwConf
|
theDummy.mainConf = tmpConf
|
||||||
return theDummy
|
return theDummy
|
||||||
|
|
||||||
##
|
##
|
||||||
# Temporary Test Folders
|
# Temporary Test Folders
|
||||||
##
|
##
|
||||||
|
|
||||||
@pytest.fixture(scope="session")
|
# @pytest.fixture(scope="session")
|
||||||
def nwTempProj(nwTemp):
|
# def nwTempProj(nwTemp):
|
||||||
"""A temporary folder for project tests.
|
# """A temporary folder for project tests.
|
||||||
"""
|
# """
|
||||||
projDir = os.path.join(nwTemp, "proj")
|
# projDir = os.path.join(nwTemp, "proj")
|
||||||
if not os.path.isdir(projDir):
|
# if not os.path.isdir(projDir):
|
||||||
os.mkdir(projDir)
|
# os.mkdir(projDir)
|
||||||
return projDir
|
# return projDir
|
||||||
|
|
||||||
@pytest.fixture(scope="session")
|
# @pytest.fixture(scope="session")
|
||||||
def nwTempGUI(nwTemp):
|
# def nwTempGUI(nwTemp):
|
||||||
"""A temporary folder for GUI tests.
|
# """A temporary folder for GUI tests.
|
||||||
"""
|
# """
|
||||||
guiDir = os.path.join(nwTemp, "gui")
|
# guiDir = os.path.join(nwTemp, "gui")
|
||||||
if not os.path.isdir(guiDir):
|
# if not os.path.isdir(guiDir):
|
||||||
os.mkdir(guiDir)
|
# os.mkdir(guiDir)
|
||||||
return guiDir
|
# return guiDir
|
||||||
|
|
||||||
@pytest.fixture(scope="session")
|
# @pytest.fixture(scope="session")
|
||||||
def nwTempBuild(nwTemp):
|
# def nwTempBuild(nwTemp):
|
||||||
"""A temporary folder for build tests.
|
# """A temporary folder for build tests.
|
||||||
"""
|
# """
|
||||||
buildDir = os.path.join(nwTemp, "build")
|
# buildDir = os.path.join(nwTemp, "build")
|
||||||
if not os.path.isdir(buildDir):
|
# if not os.path.isdir(buildDir):
|
||||||
os.mkdir(buildDir)
|
# os.mkdir(buildDir)
|
||||||
return buildDir
|
# return buildDir
|
||||||
|
|
||||||
@pytest.fixture(scope="function")
|
# @pytest.fixture(scope="function")
|
||||||
def nwFuncTemp(nwTemp):
|
# def nwFuncTemp(nwTemp):
|
||||||
"""A temporary folder for a single test function.
|
# """A temporary folder for a single test function.
|
||||||
"""
|
# """
|
||||||
funcDir = os.path.join(nwTemp, "ftemp")
|
# funcDir = os.path.join(nwTemp, "ftemp")
|
||||||
if os.path.isdir(funcDir):
|
# if os.path.isdir(funcDir):
|
||||||
shutil.rmtree(funcDir)
|
# shutil.rmtree(funcDir)
|
||||||
if not os.path.isdir(funcDir):
|
# if not os.path.isdir(funcDir):
|
||||||
os.mkdir(funcDir)
|
# os.mkdir(funcDir)
|
||||||
yield funcDir
|
# yield funcDir
|
||||||
if os.path.isdir(funcDir):
|
# if os.path.isdir(funcDir):
|
||||||
shutil.rmtree(funcDir)
|
# shutil.rmtree(funcDir)
|
||||||
return
|
# return
|
||||||
|
|
||||||
##
|
##
|
||||||
# Temp Folders for Projects
|
# Temp Folders for Projects
|
||||||
##
|
##
|
||||||
|
|
||||||
@pytest.fixture(scope="function")
|
# @pytest.fixture(scope="function")
|
||||||
def nwMinimal(nwTemp):
|
# def nwMinimal(nwTemp):
|
||||||
"""A minimal novelWriter example project.
|
# """A minimal novelWriter example project.
|
||||||
"""
|
# """
|
||||||
testDir = os.path.dirname(__file__)
|
# testDir = os.path.dirname(__file__)
|
||||||
minimalStore = os.path.join(testDir, "minimal")
|
# minimalStore = os.path.join(testDir, "minimal")
|
||||||
minimalDir = os.path.join(nwTemp, "minimal")
|
# minimalDir = os.path.join(nwTemp, "minimal")
|
||||||
if os.path.isdir(minimalDir):
|
# if os.path.isdir(minimalDir):
|
||||||
shutil.rmtree(minimalDir)
|
# shutil.rmtree(minimalDir)
|
||||||
shutil.copytree(minimalStore, minimalDir)
|
# shutil.copytree(minimalStore, minimalDir)
|
||||||
cacheDir = os.path.join(minimalDir, "cache")
|
# cacheDir = os.path.join(minimalDir, "cache")
|
||||||
if os.path.isdir(cacheDir):
|
# if os.path.isdir(cacheDir):
|
||||||
shutil.rmtree(cacheDir)
|
# shutil.rmtree(cacheDir)
|
||||||
metaDir = os.path.join(minimalDir, "meta")
|
# metaDir = os.path.join(minimalDir, "meta")
|
||||||
if os.path.isdir(metaDir):
|
# if os.path.isdir(metaDir):
|
||||||
shutil.rmtree(metaDir)
|
# shutil.rmtree(metaDir)
|
||||||
yield minimalDir
|
# yield minimalDir
|
||||||
if os.path.isdir(minimalDir):
|
# if os.path.isdir(minimalDir):
|
||||||
shutil.rmtree(minimalDir)
|
# shutil.rmtree(minimalDir)
|
||||||
return
|
# return
|
||||||
|
|
||||||
@pytest.fixture(scope="function")
|
# @pytest.fixture(scope="function")
|
||||||
def nwLipsum(nwTemp):
|
# def nwLipsum(nwTemp):
|
||||||
"""A medium sized novelWriter example project with a lot of Lorem
|
# """A medium sized novelWriter example project with a lot of Lorem
|
||||||
Ipsum dummy text.
|
# Ipsum dummy text.
|
||||||
"""
|
# """
|
||||||
testDir = os.path.dirname(__file__)
|
# testDir = os.path.dirname(__file__)
|
||||||
lipsumStore = os.path.join(testDir, "lipsum")
|
# lipsumStore = os.path.join(testDir, "lipsum")
|
||||||
lipsumDir = os.path.join(nwTemp, "lipsum")
|
# lipsumDir = os.path.join(nwTemp, "lipsum")
|
||||||
if os.path.isdir(lipsumDir):
|
# if os.path.isdir(lipsumDir):
|
||||||
shutil.rmtree(lipsumDir)
|
# shutil.rmtree(lipsumDir)
|
||||||
shutil.copytree(lipsumStore, lipsumDir)
|
# shutil.copytree(lipsumStore, lipsumDir)
|
||||||
cacheDir = os.path.join(lipsumDir, "cache")
|
# cacheDir = os.path.join(lipsumDir, "cache")
|
||||||
if os.path.isdir(cacheDir):
|
# if os.path.isdir(cacheDir):
|
||||||
shutil.rmtree(cacheDir)
|
# shutil.rmtree(cacheDir)
|
||||||
metaDir = os.path.join(lipsumDir, "meta")
|
# metaDir = os.path.join(lipsumDir, "meta")
|
||||||
if os.path.isdir(metaDir):
|
# if os.path.isdir(metaDir):
|
||||||
shutil.rmtree(metaDir)
|
# shutil.rmtree(metaDir)
|
||||||
yield lipsumDir
|
# yield lipsumDir
|
||||||
if os.path.isdir(lipsumDir):
|
# if os.path.isdir(lipsumDir):
|
||||||
shutil.rmtree(lipsumDir)
|
# shutil.rmtree(lipsumDir)
|
||||||
return
|
# return
|
||||||
|
|
||||||
@pytest.fixture(scope="function")
|
# @pytest.fixture(scope="function")
|
||||||
def nwOldProj(nwTemp):
|
# def nwOldProj(nwTemp):
|
||||||
"""A minimal movelWriter project using the old folder structure.
|
# """A minimal movelWriter project using the old folder structure.
|
||||||
"""
|
# """
|
||||||
testDir = os.path.dirname(__file__)
|
# testDir = os.path.dirname(__file__)
|
||||||
oldProjStore = os.path.join(testDir, "oldproj")
|
# oldProjStore = os.path.join(testDir, "oldproj")
|
||||||
oldProjDir = os.path.join(nwTemp, "oldproj")
|
# oldProjDir = os.path.join(nwTemp, "oldproj")
|
||||||
if os.path.isdir(oldProjDir):
|
# if os.path.isdir(oldProjDir):
|
||||||
shutil.rmtree(oldProjDir)
|
# shutil.rmtree(oldProjDir)
|
||||||
shutil.copytree(oldProjStore, oldProjDir)
|
# shutil.copytree(oldProjStore, oldProjDir)
|
||||||
yield oldProjDir
|
# yield oldProjDir
|
||||||
if os.path.isdir(oldProjDir):
|
# if os.path.isdir(oldProjDir):
|
||||||
shutil.rmtree(oldProjDir)
|
# shutil.rmtree(oldProjDir)
|
||||||
return
|
# return
|
||||||
|
|
||||||
##
|
##
|
||||||
# Monkey Patch Dialogs
|
# Monkey Patch Dialogs
|
||||||
##
|
##
|
||||||
|
|
||||||
@pytest.fixture(scope="function")
|
# @pytest.fixture(scope="function")
|
||||||
def yesToAll(monkeypatch):
|
# def yesToAll(monkeypatch):
|
||||||
"""Make the message boxes/questions always say yes.
|
# """Make the message boxes/questions always say yes.
|
||||||
"""
|
# """
|
||||||
monkeypatch.setattr(
|
# monkeypatch.setattr(
|
||||||
QMessageBox, "question", lambda *args, **kwargs: QMessageBox.Yes
|
# QMessageBox, "question", lambda *args, **kwargs: QMessageBox.Yes
|
||||||
)
|
# )
|
||||||
monkeypatch.setattr(
|
# monkeypatch.setattr(
|
||||||
QMessageBox, "information", lambda *args, **kwargs: QMessageBox.Yes
|
# QMessageBox, "information", lambda *args, **kwargs: QMessageBox.Yes
|
||||||
)
|
# )
|
||||||
monkeypatch.setattr(
|
# monkeypatch.setattr(
|
||||||
QMessageBox, "warning", lambda *args, **kwargs: QMessageBox.Yes
|
# QMessageBox, "warning", lambda *args, **kwargs: QMessageBox.Yes
|
||||||
)
|
# )
|
||||||
monkeypatch.setattr(
|
# monkeypatch.setattr(
|
||||||
QMessageBox, "critical", lambda *args, **kwargs: QMessageBox.Yes
|
# QMessageBox, "critical", lambda *args, **kwargs: QMessageBox.Yes
|
||||||
)
|
# )
|
||||||
return
|
# return
|
||||||
|
|||||||
@@ -9,10 +9,11 @@ from lxml import etree
|
|||||||
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
|
||||||
|
|
||||||
@pytest.mark.project
|
@pytest.mark.core
|
||||||
def testItemSettersSimple(nwDummy):
|
def testCoreItemSetters(dummyGUI):
|
||||||
|
"""Test all the simple setter classes for the NWItem class.
|
||||||
theProject = NWProject(nwDummy)
|
"""
|
||||||
|
theProject = NWProject(dummyGUI)
|
||||||
theItem = NWItem(theProject)
|
theItem = NWItem(theProject)
|
||||||
|
|
||||||
# Name
|
# Name
|
||||||
@@ -20,12 +21,16 @@ def testItemSettersSimple(nwDummy):
|
|||||||
assert theItem.itemName == "A Name"
|
assert theItem.itemName == "A Name"
|
||||||
theItem.setName("\t A Name ")
|
theItem.setName("\t A Name ")
|
||||||
assert theItem.itemName == "A Name"
|
assert theItem.itemName == "A Name"
|
||||||
|
theItem.setName(123)
|
||||||
|
assert theItem.itemName == ""
|
||||||
|
|
||||||
# Handle
|
# Handle
|
||||||
theItem.setHandle(123)
|
theItem.setHandle(123)
|
||||||
assert theItem.itemHandle is None
|
assert theItem.itemHandle is None
|
||||||
theItem.setHandle("0123456789abcdef")
|
theItem.setHandle("0123456789abcdef")
|
||||||
assert theItem.itemHandle is None
|
assert theItem.itemHandle is None
|
||||||
|
theItem.setHandle("0123456789abg")
|
||||||
|
assert theItem.itemHandle is None
|
||||||
theItem.setHandle("0123456789abc")
|
theItem.setHandle("0123456789abc")
|
||||||
assert theItem.itemHandle == "0123456789abc"
|
assert theItem.itemHandle == "0123456789abc"
|
||||||
|
|
||||||
@@ -36,6 +41,8 @@ def testItemSettersSimple(nwDummy):
|
|||||||
assert theItem.itemParent is None
|
assert theItem.itemParent is None
|
||||||
theItem.setParent("0123456789abcdef")
|
theItem.setParent("0123456789abcdef")
|
||||||
assert theItem.itemParent is None
|
assert theItem.itemParent is None
|
||||||
|
theItem.setParent("0123456789abg")
|
||||||
|
assert theItem.itemParent is None
|
||||||
theItem.setParent("0123456789abc")
|
theItem.setParent("0123456789abc")
|
||||||
assert theItem.itemParent == "0123456789abc"
|
assert theItem.itemParent == "0123456789abc"
|
||||||
|
|
||||||
@@ -59,6 +66,19 @@ def testItemSettersSimple(nwDummy):
|
|||||||
theItem.setStatus("Main")
|
theItem.setStatus("Main")
|
||||||
assert theItem.itemStatus == "Main"
|
assert theItem.itemStatus == "Main"
|
||||||
|
|
||||||
|
# Importance
|
||||||
|
theItem.itemClass = nwItemClass.NOVEL
|
||||||
|
theItem.setStatus("Nonsense")
|
||||||
|
assert theItem.itemStatus == "New"
|
||||||
|
theItem.setStatus("New")
|
||||||
|
assert theItem.itemStatus == "New"
|
||||||
|
theItem.setStatus("Note")
|
||||||
|
assert theItem.itemStatus == "Note"
|
||||||
|
theItem.setStatus("Draft")
|
||||||
|
assert theItem.itemStatus == "Draft"
|
||||||
|
theItem.setStatus("Finished")
|
||||||
|
assert theItem.itemStatus == "Finished"
|
||||||
|
|
||||||
# Expanded
|
# Expanded
|
||||||
theItem.setExpanded(8)
|
theItem.setExpanded(8)
|
||||||
assert not theItem.isExpanded
|
assert not theItem.isExpanded
|
||||||
@@ -73,6 +93,20 @@ def testItemSettersSimple(nwDummy):
|
|||||||
theItem.setExpanded(True)
|
theItem.setExpanded(True)
|
||||||
assert theItem.isExpanded
|
assert theItem.isExpanded
|
||||||
|
|
||||||
|
# Exported
|
||||||
|
theItem.setExported(8)
|
||||||
|
assert not theItem.isExported
|
||||||
|
theItem.setExported(None)
|
||||||
|
assert not theItem.isExported
|
||||||
|
theItem.setExported("None")
|
||||||
|
assert not theItem.isExported
|
||||||
|
theItem.setExported("What?")
|
||||||
|
assert not theItem.isExported
|
||||||
|
theItem.setExported("True")
|
||||||
|
assert theItem.isExported
|
||||||
|
theItem.setExported(True)
|
||||||
|
assert theItem.isExported
|
||||||
|
|
||||||
# CharCount
|
# CharCount
|
||||||
theItem.setCharCount(None)
|
theItem.setCharCount(None)
|
||||||
assert theItem.charCount == 0
|
assert theItem.charCount == 0
|
||||||
@@ -105,10 +139,47 @@ def testItemSettersSimple(nwDummy):
|
|||||||
theItem.setCursorPos(1)
|
theItem.setCursorPos(1)
|
||||||
assert theItem.cursorPos == 1
|
assert theItem.cursorPos == 1
|
||||||
|
|
||||||
@pytest.mark.project
|
# Initial Count
|
||||||
def testItemClassSetter(nwDummy):
|
theItem.setWordCount(234)
|
||||||
|
theItem.saveInitialCount()
|
||||||
|
assert theItem.initCount == 234
|
||||||
|
|
||||||
theProject = NWProject(nwDummy)
|
# END Test testCoreItemSetters
|
||||||
|
|
||||||
|
@pytest.mark.core
|
||||||
|
def testCoreItemTypeSetter(dummyGUI):
|
||||||
|
"""Test the setter for all the nwItemType values for the NWItem
|
||||||
|
class.
|
||||||
|
"""
|
||||||
|
theProject = NWProject(dummyGUI)
|
||||||
|
theItem = NWItem(theProject)
|
||||||
|
|
||||||
|
# Type
|
||||||
|
theItem.setType(None)
|
||||||
|
assert theItem.itemType == nwItemType.NO_TYPE
|
||||||
|
theItem.setType("NONSENSE")
|
||||||
|
assert theItem.itemType == nwItemType.NO_TYPE
|
||||||
|
theItem.setType("NO_TYPE")
|
||||||
|
assert theItem.itemType == nwItemType.NO_TYPE
|
||||||
|
theItem.setType("ROOT")
|
||||||
|
assert theItem.itemType == nwItemType.ROOT
|
||||||
|
theItem.setType("FOLDER")
|
||||||
|
assert theItem.itemType == nwItemType.FOLDER
|
||||||
|
theItem.setType("FILE")
|
||||||
|
assert theItem.itemType == nwItemType.FILE
|
||||||
|
theItem.setType("TRASH")
|
||||||
|
assert theItem.itemType == nwItemType.TRASH
|
||||||
|
theItem.setType(nwItemType.ROOT)
|
||||||
|
assert theItem.itemType == nwItemType.ROOT
|
||||||
|
|
||||||
|
# END Test testCoreItemTypeSetter
|
||||||
|
|
||||||
|
@pytest.mark.core
|
||||||
|
def testCoreItemClassSetter(dummyGUI):
|
||||||
|
"""Test the setter for all the nwItemClass values for the NWItem
|
||||||
|
class.
|
||||||
|
"""
|
||||||
|
theProject = NWProject(dummyGUI)
|
||||||
theItem = NWItem(theProject)
|
theItem = NWItem(theProject)
|
||||||
|
|
||||||
# Class
|
# Class
|
||||||
@@ -138,33 +209,17 @@ def testItemClassSetter(nwDummy):
|
|||||||
assert theItem.itemClass == nwItemClass.ARCHIVE
|
assert theItem.itemClass == nwItemClass.ARCHIVE
|
||||||
theItem.setClass("TRASH")
|
theItem.setClass("TRASH")
|
||||||
assert theItem.itemClass == nwItemClass.TRASH
|
assert theItem.itemClass == nwItemClass.TRASH
|
||||||
|
theItem.setClass(nwItemClass.NOVEL)
|
||||||
|
assert theItem.itemClass == nwItemClass.NOVEL
|
||||||
|
|
||||||
@pytest.mark.project
|
# END Test testCoreItemClassSetter
|
||||||
def testItemTypeSetter(nwDummy):
|
|
||||||
|
|
||||||
theProject = NWProject(nwDummy)
|
@pytest.mark.core
|
||||||
theItem = NWItem(theProject)
|
def testCoreItemLayoutSetter(dummyGUI):
|
||||||
|
"""Test the setter for all the nwItemLayout values for the NWItem
|
||||||
# Type
|
class.
|
||||||
theItem.setType(None)
|
"""
|
||||||
assert theItem.itemType == nwItemType.NO_TYPE
|
theProject = NWProject(dummyGUI)
|
||||||
theItem.setType("NONSENSE")
|
|
||||||
assert theItem.itemType == nwItemType.NO_TYPE
|
|
||||||
theItem.setType("NO_TYPE")
|
|
||||||
assert theItem.itemType == nwItemType.NO_TYPE
|
|
||||||
theItem.setType("ROOT")
|
|
||||||
assert theItem.itemType == nwItemType.ROOT
|
|
||||||
theItem.setType("FOLDER")
|
|
||||||
assert theItem.itemType == nwItemType.FOLDER
|
|
||||||
theItem.setType("FILE")
|
|
||||||
assert theItem.itemType == nwItemType.FILE
|
|
||||||
theItem.setType("TRASH")
|
|
||||||
assert theItem.itemType == nwItemType.TRASH
|
|
||||||
|
|
||||||
@pytest.mark.project
|
|
||||||
def testItemLayoutSetter(nwDummy):
|
|
||||||
|
|
||||||
theProject = NWProject(nwDummy)
|
|
||||||
theItem = NWItem(theProject)
|
theItem = NWItem(theProject)
|
||||||
|
|
||||||
# Layout
|
# Layout
|
||||||
@@ -190,14 +245,22 @@ def testItemLayoutSetter(nwDummy):
|
|||||||
assert theItem.itemLayout == nwItemLayout.SCENE
|
assert theItem.itemLayout == nwItemLayout.SCENE
|
||||||
theItem.setLayout("NOTE")
|
theItem.setLayout("NOTE")
|
||||||
assert theItem.itemLayout == nwItemLayout.NOTE
|
assert theItem.itemLayout == nwItemLayout.NOTE
|
||||||
|
theItem.setLayout(nwItemLayout.NOTE)
|
||||||
|
assert theItem.itemLayout == nwItemLayout.NOTE
|
||||||
|
|
||||||
@pytest.mark.project
|
# END Test testCoreItemLayoutSetter
|
||||||
def testItemXMLPackUnpack(nwDummy):
|
|
||||||
|
|
||||||
theProject = NWProject(nwDummy)
|
@pytest.mark.core
|
||||||
theItem = NWItem(theProject)
|
def testCoreItemXMLPackUnpack(dummyGUI):
|
||||||
|
"""Test packing and unpacking XML objects for the NWItem class.
|
||||||
|
"""
|
||||||
|
theProject = NWProject(dummyGUI)
|
||||||
nwXML = etree.Element("novelWriterXML")
|
nwXML = etree.Element("novelWriterXML")
|
||||||
|
|
||||||
|
# File
|
||||||
|
# ====
|
||||||
|
|
||||||
|
theItem = NWItem(theProject)
|
||||||
theItem.setHandle("0123456789abc")
|
theItem.setHandle("0123456789abc")
|
||||||
theItem.setParent("0123456789abc")
|
theItem.setParent("0123456789abc")
|
||||||
theItem.setOrder(1)
|
theItem.setOrder(1)
|
||||||
@@ -206,7 +269,7 @@ def testItemXMLPackUnpack(nwDummy):
|
|||||||
theItem.setType("FILE")
|
theItem.setType("FILE")
|
||||||
theItem.setStatus("Main")
|
theItem.setStatus("Main")
|
||||||
theItem.setLayout("NOTE")
|
theItem.setLayout("NOTE")
|
||||||
theItem.setExpanded(True)
|
theItem.setExported(False)
|
||||||
theItem.setParaCount(3)
|
theItem.setParaCount(3)
|
||||||
theItem.setWordCount(5)
|
theItem.setWordCount(5)
|
||||||
theItem.setCharCount(7)
|
theItem.setCharCount(7)
|
||||||
@@ -219,17 +282,18 @@ def testItemXMLPackUnpack(nwDummy):
|
|||||||
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>FILE</type><class>NOVEL</class><status>New</status>"
|
b"<name>A Name</name><type>FILE</type><class>NOVEL</class><status>New</status>"
|
||||||
b"<exported>True</exported><layout>NOTE</layout><charCount>7</charCount>"
|
b"<exported>False</exported><layout>NOTE</layout><charCount>7</charCount>"
|
||||||
b"<wordCount>5</wordCount><paraCount>3</paraCount><cursorPos>11</cursorPos></item>"
|
b"<wordCount>5</wordCount><paraCount>3</paraCount><cursorPos>11</cursorPos></item>"
|
||||||
b"</content>"
|
b"</content>"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Unpack
|
# Unpack
|
||||||
|
theItem = NWItem(theProject)
|
||||||
assert theItem.unpackXML(xContent[0])
|
assert theItem.unpackXML(xContent[0])
|
||||||
assert theItem.itemHandle == "0123456789abc"
|
assert theItem.itemHandle == "0123456789abc"
|
||||||
assert theItem.itemParent == "0123456789abc"
|
assert theItem.itemParent == "0123456789abc"
|
||||||
assert theItem.itemOrder == 1
|
assert theItem.itemOrder == 1
|
||||||
assert theItem.isExpanded
|
assert theItem.isExported is False
|
||||||
assert theItem.paraCount == 3
|
assert theItem.paraCount == 3
|
||||||
assert theItem.wordCount == 5
|
assert theItem.wordCount == 5
|
||||||
assert theItem.charCount == 7
|
assert theItem.charCount == 7
|
||||||
@@ -238,6 +302,52 @@ def testItemXMLPackUnpack(nwDummy):
|
|||||||
assert theItem.itemType == nwItemType.FILE
|
assert theItem.itemType == nwItemType.FILE
|
||||||
assert theItem.itemLayout == nwItemLayout.NOTE
|
assert theItem.itemLayout == nwItemLayout.NOTE
|
||||||
|
|
||||||
|
# Folder
|
||||||
|
# ======
|
||||||
|
|
||||||
|
theItem = NWItem(theProject)
|
||||||
|
theItem.setHandle("0123456789abc")
|
||||||
|
theItem.setParent("0123456789abc")
|
||||||
|
theItem.setOrder(1)
|
||||||
|
theItem.setName("A Name")
|
||||||
|
theItem.setClass("NOVEL")
|
||||||
|
theItem.setType("FOLDER")
|
||||||
|
theItem.setStatus("Main")
|
||||||
|
theItem.setLayout("NOTE")
|
||||||
|
theItem.setExpanded(True)
|
||||||
|
theItem.setExported(False)
|
||||||
|
theItem.setParaCount(3)
|
||||||
|
theItem.setWordCount(5)
|
||||||
|
theItem.setCharCount(7)
|
||||||
|
theItem.setCursorPos(11)
|
||||||
|
|
||||||
|
# Pack
|
||||||
|
xContent = etree.SubElement(nwXML, "content")
|
||||||
|
theItem.packXML(xContent)
|
||||||
|
assert etree.tostring(xContent, pretty_print=False, encoding="utf-8") == (
|
||||||
|
b"<content>"
|
||||||
|
b"<item handle=\"0123456789abc\" order=\"1\" parent=\"0123456789abc\">"
|
||||||
|
b"<name>A Name</name><type>FOLDER</type><class>NOVEL</class><status>New</status>"
|
||||||
|
b"<expanded>True</expanded></item>"
|
||||||
|
b"</content>"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Unpack
|
||||||
|
theItem = NWItem(theProject)
|
||||||
|
assert theItem.unpackXML(xContent[0])
|
||||||
|
assert theItem.itemHandle == "0123456789abc"
|
||||||
|
assert theItem.itemParent == "0123456789abc"
|
||||||
|
assert theItem.itemOrder == 1
|
||||||
|
assert theItem.isExpanded is True
|
||||||
|
assert theItem.isExported is True
|
||||||
|
assert theItem.paraCount == 0
|
||||||
|
assert theItem.wordCount == 0
|
||||||
|
assert theItem.charCount == 0
|
||||||
|
assert theItem.cursorPos == 0
|
||||||
|
assert theItem.itemClass == nwItemClass.NOVEL
|
||||||
|
assert theItem.itemType == nwItemType.FOLDER
|
||||||
|
assert theItem.itemLayout == nwItemLayout.NO_LAYOUT
|
||||||
|
|
||||||
# Errors
|
# Errors
|
||||||
|
|
||||||
## Not an Item
|
## Not an Item
|
||||||
@@ -268,3 +378,5 @@ def testItemXMLPackUnpack(nwDummy):
|
|||||||
assert etree.tostring(xDummy, pretty_print=False, encoding="utf-8") == (
|
assert etree.tostring(xDummy, pretty_print=False, encoding="utf-8") == (
|
||||||
b"<group/>"
|
b"<group/>"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# END Test testCoreItemXMLPackUnpack
|
||||||
Reference in New Issue
Block a user