Minor improvements to existing tests to increase coverage

This commit is contained in:
Veronica K. B. Olsen
2020-09-19 18:51:45 +02:00
parent 149fc1a9c5
commit 4338580d2c
5 changed files with 95 additions and 8 deletions
-2
View File
@@ -243,8 +243,6 @@ def fuzzyTime(secDiff):
else: else:
return "%d years ago" % int(round(secDiff/31557600)) return "%d years ago" % int(round(secDiff/31557600))
return "beyond time and space"
def makeFileNameSafe(theText): def makeFileNameSafe(theText):
"""Returns a filename safe version of the text. """Returns a filename safe version of the text.
""" """
+9 -1
View File
@@ -2,10 +2,12 @@
"""novelWriter Common Class Tester """novelWriter Common Class Tester
""" """
import time
import pytest import pytest
from nw.common import ( from nw.common import (
checkString, checkBool, checkInt, colRange, formatInt, transferCase, checkString, checkBool, checkInt, colRange, formatInt, transferCase,
fuzzyTime, checkHandle fuzzyTime, checkHandle, formatTimeStamp
) )
from nwtools import cmpList from nwtools import cmpList
@@ -75,6 +77,12 @@ def testColRange():
[[200, 50, 0], [162, 87, 0], [124, 124, 0], [86, 161, 0], [50, 200, 0]] [[200, 50, 0], [162, 87, 0], [124, 124, 0], [86, 161, 0], [50, 200, 0]]
) )
@pytest.mark.core
def testFormatTime():
tTime = time.mktime(time.gmtime(0))
assert formatTimeStamp(tTime, False) == "1970-01-01 00:00:00"
assert formatTimeStamp(tTime, True) == "1970-01-01 00.00.00"
@pytest.mark.core @pytest.mark.core
def testFormatInt(): def testFormatInt():
assert formatInt(1000) == "1000" assert formatInt(1000) == "1000"
+54 -4
View File
@@ -40,6 +40,7 @@ def testConfigSetDataPath(tmpConf, nwTemp):
def testConfigSetWinSize(tmpConf, nwTemp, nwRef): def testConfigSetWinSize(tmpConf, nwTemp, nwRef):
refConf = path.join(nwRef, "novelwriter.conf") refConf = path.join(nwRef, "novelwriter.conf")
testConf = path.join(tmpConf.confPath, "novelwriter.conf") testConf = path.join(tmpConf.confPath, "novelwriter.conf")
tmpConf.guiScale = 1.0
assert tmpConf.confPath == nwTemp assert tmpConf.confPath == nwTemp
assert tmpConf.setWinSize(1105, 655) assert tmpConf.setWinSize(1105, 655)
@@ -58,10 +59,17 @@ def testConfigSetTreeColWidths(tmpConf, nwTemp, nwRef):
testConf = path.join(tmpConf.confPath, "novelwriter.conf") testConf = path.join(tmpConf.confPath, "novelwriter.conf")
assert tmpConf.confPath == nwTemp assert tmpConf.confPath == nwTemp
assert tmpConf.setTreeColWidths([0, 0, 0]) tmpConf.guiScale = 1.0
assert tmpConf.confChanged
assert tmpConf.setTreeColWidths([10, 20, 30])
assert tmpConf.treeColWidth == [10, 20, 30]
assert tmpConf.setTreeColWidths([120, 30, 50]) assert tmpConf.setTreeColWidths([120, 30, 50])
assert tmpConf.setProjColWidths([10, 20, 30])
assert tmpConf.projColWidth == [10, 20, 30]
assert tmpConf.setProjColWidths([140, 55, 140]) assert tmpConf.setProjColWidths([140, 55, 140])
assert tmpConf.confChanged
assert tmpConf.saveConfig() assert tmpConf.saveConfig()
assert cmpFiles(testConf, refConf, [2]) assert cmpFiles(testConf, refConf, [2])
@@ -73,12 +81,31 @@ def testConfigSetPanePos(tmpConf, nwTemp, nwRef):
testConf = path.join(tmpConf.confPath, "novelwriter.conf") testConf = path.join(tmpConf.confPath, "novelwriter.conf")
assert tmpConf.confPath == nwTemp assert tmpConf.confPath == nwTemp
assert tmpConf.setMainPanePos([0, 0])
assert tmpConf.confChanged tmpConf.guiScale = 2.0
assert tmpConf.setMainPanePos([200, 700])
assert tmpConf.mainPanePos == [100, 350]
assert tmpConf.getMainPanePos() == [200, 700]
assert tmpConf.setDocPanePos([300, 300])
assert tmpConf.docPanePos == [150, 150]
assert tmpConf.getDocPanePos() == [300, 300]
assert tmpConf.setViewPanePos([400, 250])
assert tmpConf.viewPanePos == [200, 125]
assert tmpConf.getViewPanePos() == [400, 250]
assert tmpConf.setOutlinePanePos([400, 250])
assert tmpConf.outlnPanePos == [200, 125]
assert tmpConf.getOutlinePanePos() == [400, 250]
tmpConf.guiScale = 1.0
assert tmpConf.setMainPanePos([300, 800]) assert tmpConf.setMainPanePos([300, 800])
assert tmpConf.setDocPanePos([400, 400]) assert tmpConf.setDocPanePos([400, 400])
assert tmpConf.setViewPanePos([500, 150]) assert tmpConf.setViewPanePos([500, 150])
assert tmpConf.setOutlinePanePos([500, 150]) assert tmpConf.setOutlinePanePos([500, 150])
assert tmpConf.confChanged
assert tmpConf.saveConfig() assert tmpConf.saveConfig()
assert cmpFiles(testConf, refConf, [2]) assert cmpFiles(testConf, refConf, [2])
@@ -90,14 +117,37 @@ def testConfigFlags(tmpConf, nwTemp, nwRef):
testConf = path.join(tmpConf.confPath, "novelwriter.conf") testConf = path.join(tmpConf.confPath, "novelwriter.conf")
assert tmpConf.confPath == nwTemp assert tmpConf.confPath == nwTemp
assert not tmpConf.setShowRefPanel(False) assert not tmpConf.setShowRefPanel(False)
assert tmpConf.setShowRefPanel(True) assert tmpConf.setShowRefPanel(True)
assert not tmpConf.setViewComments(False)
assert not tmpConf.viewComments
assert tmpConf.setViewComments(True)
assert not tmpConf.setViewSynopsis(False)
assert not tmpConf.viewSynopsis
assert tmpConf.setViewSynopsis(True)
assert tmpConf.confChanged assert tmpConf.confChanged
assert tmpConf.saveConfig() assert tmpConf.saveConfig()
assert cmpFiles(testConf, refConf, [2]) assert cmpFiles(testConf, refConf, [2])
assert not tmpConf.confChanged assert not tmpConf.confChanged
@pytest.mark.core
def testTextSizes(tmpConf, nwTemp, nwRef):
assert tmpConf.confPath == nwTemp
tmpConf.guiScale = 2.0
assert tmpConf.getTextWidth() == 1200
assert tmpConf.getTextMargin() == 80
assert tmpConf.getTabWidth() == 80
assert tmpConf.getFocusWidth() == 1600
tmpConf.guiScale = 1.0
assert not tmpConf.confChanged
@pytest.mark.core @pytest.mark.core
def testConfigErrors(tmpConf): def testConfigErrors(tmpConf):
nonPath = path.join("somewhere", "over", "the", "rainbow") nonPath = path.join("somewhere", "over", "the", "rainbow")
+1 -1
View File
@@ -18,7 +18,7 @@ keyDelay = 2
stepDelay = 20 stepDelay = 20
@pytest.mark.gui @pytest.mark.gui
def testMainWindows(qtbot, nwFuncTemp, nwTempGUI, nwRef, nwTemp): def testMainWindow(qtbot, nwFuncTemp, nwTempGUI, nwRef, nwTemp):
nwGUI = nw.main(["--testmode", "--config=%s" % nwFuncTemp, "--data=%s" % nwTemp]) nwGUI = nw.main(["--testmode", "--config=%s" % nwFuncTemp, "--data=%s" % nwTemp])
qtbot.addWidget(nwGUI) qtbot.addWidget(nwGUI)
+31
View File
@@ -237,3 +237,34 @@ def testItemXMLPackUnpack(nwDummy):
assert theItem.itemClass == nwItemClass.NOVEL assert theItem.itemClass == nwItemClass.NOVEL
assert theItem.itemType == nwItemType.FILE assert theItem.itemType == nwItemType.FILE
assert theItem.itemLayout == nwItemLayout.NOTE assert theItem.itemLayout == nwItemLayout.NOTE
# Errors
## Not an Item
xDummy = etree.SubElement(nwXML, "stuff")
assert not theItem.unpackXML(xDummy)
## Item without Handle
xDummy = etree.SubElement(nwXML, "item", attrib={"stuff": "nah"})
assert not theItem.unpackXML(xDummy)
## Item with Invalid SubElement
xDummy = etree.SubElement(nwXML, "item", attrib={"handle": "0123456789abc"})
xParam = etree.SubElement(xDummy, "invalid")
xParam.text = "stuff"
assert theItem.unpackXML(xDummy) # Passes, but not saved
# Pack Valid Item
xDummy = etree.SubElement(nwXML, "group")
theItem._subPack(xDummy, "subGroup", {"one": "two"}, "value", False)
assert etree.tostring(xDummy, pretty_print=False, encoding="utf-8") == (
b"<group><subGroup one=\"two\">value</subGroup></group>"
)
# Pack Not Allowed None
xDummy = etree.SubElement(nwXML, "group")
assert theItem._subPack(xDummy, "subGroup", {}, None, False) is None
assert theItem._subPack(xDummy, "subGroup", {}, "None", False) is None
assert etree.tostring(xDummy, pretty_print=False, encoding="utf-8") == (
b"<group/>"
)