diff --git a/nw/common.py b/nw/common.py
index febac7cc..68825f4d 100644
--- a/nw/common.py
+++ b/nw/common.py
@@ -243,8 +243,6 @@ def fuzzyTime(secDiff):
else:
return "%d years ago" % int(round(secDiff/31557600))
- return "beyond time and space"
-
def makeFileNameSafe(theText):
"""Returns a filename safe version of the text.
"""
diff --git a/tests/test_common.py b/tests/test_common.py
index 5a73ad45..41a81091 100644
--- a/tests/test_common.py
+++ b/tests/test_common.py
@@ -2,10 +2,12 @@
"""novelWriter Common Class Tester
"""
+import time
import pytest
+
from nw.common import (
checkString, checkBool, checkInt, colRange, formatInt, transferCase,
- fuzzyTime, checkHandle
+ fuzzyTime, checkHandle, formatTimeStamp
)
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]]
)
+@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
def testFormatInt():
assert formatInt(1000) == "1000"
diff --git a/tests/test_config.py b/tests/test_config.py
index b58e9697..612352cf 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -40,6 +40,7 @@ def testConfigSetDataPath(tmpConf, nwTemp):
def testConfigSetWinSize(tmpConf, nwTemp, nwRef):
refConf = path.join(nwRef, "novelwriter.conf")
testConf = path.join(tmpConf.confPath, "novelwriter.conf")
+ tmpConf.guiScale = 1.0
assert tmpConf.confPath == nwTemp
assert tmpConf.setWinSize(1105, 655)
@@ -58,10 +59,17 @@ def testConfigSetTreeColWidths(tmpConf, nwTemp, nwRef):
testConf = path.join(tmpConf.confPath, "novelwriter.conf")
assert tmpConf.confPath == nwTemp
- assert tmpConf.setTreeColWidths([0, 0, 0])
- assert tmpConf.confChanged
+ tmpConf.guiScale = 1.0
+
+ assert tmpConf.setTreeColWidths([10, 20, 30])
+ assert tmpConf.treeColWidth == [10, 20, 30]
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.confChanged
assert tmpConf.saveConfig()
assert cmpFiles(testConf, refConf, [2])
@@ -73,12 +81,31 @@ def testConfigSetPanePos(tmpConf, nwTemp, nwRef):
testConf = path.join(tmpConf.confPath, "novelwriter.conf")
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.setDocPanePos([400, 400])
assert tmpConf.setViewPanePos([500, 150])
assert tmpConf.setOutlinePanePos([500, 150])
+
+ assert tmpConf.confChanged
assert tmpConf.saveConfig()
assert cmpFiles(testConf, refConf, [2])
@@ -90,14 +117,37 @@ def testConfigFlags(tmpConf, nwTemp, nwRef):
testConf = path.join(tmpConf.confPath, "novelwriter.conf")
assert tmpConf.confPath == nwTemp
+
assert not tmpConf.setShowRefPanel(False)
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.saveConfig()
assert cmpFiles(testConf, refConf, [2])
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
def testConfigErrors(tmpConf):
nonPath = path.join("somewhere", "over", "the", "rainbow")
diff --git a/tests/test_gui.py b/tests/test_gui.py
index 012c8596..b7d34039 100644
--- a/tests/test_gui.py
+++ b/tests/test_gui.py
@@ -18,7 +18,7 @@ keyDelay = 2
stepDelay = 20
@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])
qtbot.addWidget(nwGUI)
diff --git a/tests/test_item.py b/tests/test_item.py
index a3280c14..d1097161 100644
--- a/tests/test_item.py
+++ b/tests/test_item.py
@@ -237,3 +237,34 @@ def testItemXMLPackUnpack(nwDummy):
assert theItem.itemClass == nwItemClass.NOVEL
assert theItem.itemType == nwItemType.FILE
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"value"
+ )
+
+ # 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""
+ )