From 223db59e3ddf3401ed19d3d3c069b3f7a29ab018 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" Date: Sun, 12 May 2019 13:29:18 +0200 Subject: [PATCH] Added test framwork and two simple tests for the config class --- tests/nwtools.py | 34 ++++++++++++++++++++++++++++ tests/reference/novelwriter.conf | 38 ++++++++++++++++++++++++++++++++ tests/test_config.py | 35 +++++++++++++++++++++++++++++ 3 files changed, 107 insertions(+) create mode 100644 tests/nwtools.py create mode 100644 tests/reference/novelwriter.conf create mode 100644 tests/test_config.py diff --git a/tests/nwtools.py b/tests/nwtools.py new file mode 100644 index 00000000..b689a50e --- /dev/null +++ b/tests/nwtools.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +"""novelWriter Test Tools +""" + +def cmpFiles(fileOne, fileTwo, ignoreLines=[]): + foOne = open(fileOne,mode="r") + foTwo = open(fileTwo,mode="r") + + txtOne = foOne.readlines() + txtTwo = foTwo.readlines() + + if len(txtOne) != len(txtTwo): + print("Files are not the same length") + return False + + diffFound = False + for n in range(len(txtOne)): + lnOne = txtOne[n].strip() + lnTwo = txtTwo[n].strip() + + if n+1 in ignoreLines: + print("Ignoring line %d" % (n+1)) + continue + + if lnOne != lnTwo: + print("Diff on line %d:" % (n+1)) + print(" << '%s'" % lnOne) + print(" >> '%s'" % lnTwo) + diffFound = True + + foOne.close() + foTwo.close() + + return not diffFound diff --git a/tests/reference/novelwriter.conf b/tests/reference/novelwriter.conf new file mode 100644 index 00000000..00e800be --- /dev/null +++ b/tests/reference/novelwriter.conf @@ -0,0 +1,38 @@ +[Main] +timestamp = 2019-05-12 12:04:16 + +[Sizes] +geometry = 1100, 650 +treecols = 120, 30, 50 +mainpane = 300, 800 + +[Project] +autosaveproject = 60 +autosavedoc = 30 + +[Editor] +fixedwidth = True +width = 600 +margins = 40, 40 +textsize = 13 +justify = True +autoselect = True +autoreplace = True +repsquotes = True +repdquotes = True +repdash = True +repdots = True +spellcheck = en_GB + +[Path] +recent0 = +recent1 = +recent2 = +recent3 = +recent4 = +recent5 = +recent6 = +recent7 = +recent8 = +recent9 = + diff --git a/tests/test_config.py b/tests/test_config.py new file mode 100644 index 00000000..ce1c2ad2 --- /dev/null +++ b/tests/test_config.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +"""novelWriter Config Class Tester + + novelWriter – Config Class Tester +=================================== + +""" + +import nw +import filecmp + +from nwtools import cmpFiles + +from os import path, unlink + +from nw.config import Config + +theConf = Config() +testDir = path.dirname(__file__) +testTemp = path.join(testDir,"temp") +testRef = path.join(testDir,"reference") +tmpConf = path.join(testTemp,"novelwriter.conf") +refConf = path.join(testRef, "novelwriter.conf") + +# Clean out old stuff +if path.isfile(tmpConf): + unlink(tmpConf) + +def testConfigInit(): + assert theConf.initConfig(testTemp) + assert cmpFiles(tmpConf, refConf, [2]) + +def testConfigSave(): + assert theConf.saveConfig() + assert cmpFiles(tmpConf, refConf, [2])