Added test framwork and two simple tests for the config class
This commit is contained in:
@@ -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
|
||||||
@@ -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 =
|
||||||
|
|
||||||
@@ -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])
|
||||||
Reference in New Issue
Block a user