Fix tests and added --data option to command line

This commit is contained in:
Veronica K. B. Olsen
2020-02-26 18:27:07 +01:00
parent 0587099d36
commit 0696ef79e4
6 changed files with 39 additions and 31 deletions
+6 -1
View File
@@ -87,6 +87,7 @@ def main(sysArgs=None):
"logfile=", "logfile=",
"version", "version",
"config=", "config=",
"data=",
"testmode", "testmode",
"style=", "style=",
] ]
@@ -105,6 +106,7 @@ def main(sysArgs=None):
" -l, --logfile= Specify log file.\n" " -l, --logfile= Specify log file.\n"
" --style= Set Qt5 style flag. Defaults to 'Fusion'.\n" " --style= Set Qt5 style flag. Defaults to 'Fusion'.\n"
" --config= Alternative config file.\n" " --config= Alternative config file.\n"
" --data= Alternative user data path.\n"
" --headless Do not display GUI. Useful for testing scripts.\n" " --headless Do not display GUI. Useful for testing scripts.\n"
).format( ).format(
appname = __package__, appname = __package__,
@@ -120,6 +122,7 @@ def main(sysArgs=None):
toFile = False toFile = False
toStd = True toStd = True
confPath = None confPath = None
dataPath = None
testMode = False testMode = False
qtStyle = "Fusion" qtStyle = "Fusion"
cmdOpen = None cmdOpen = None
@@ -157,6 +160,8 @@ def main(sysArgs=None):
qtStyle = inArg qtStyle = inArg
elif inOpt in ("--config"): elif inOpt in ("--config"):
confPath = inArg confPath = inArg
elif inOpt in ("--data"):
dataPath = inArg
elif inOpt in ("--testmode"): elif inOpt in ("--testmode"):
testMode = True testMode = True
@@ -187,7 +192,7 @@ def main(sysArgs=None):
logger.setLevel(debugLevel) logger.setLevel(debugLevel)
CONFIG.initConfig(confPath) CONFIG.initConfig(confPath, dataPath)
if testMode: if testMode:
nwGUI = GuiMain() nwGUI = GuiMain()
+21 -8
View File
@@ -117,9 +117,6 @@ class Config:
self.showRefPanel = True self.showRefPanel = True
self.viewComments = True self.viewComments = True
## Path
self.recentList = [""]*10
# Check Qt5 Versions # Check Qt5 Versions
verQt = splitVersionNumber(QT_VERSION_STR) verQt = splitVersionNumber(QT_VERSION_STR)
self.verQtString = QT_VERSION_STR self.verQtString = QT_VERSION_STR
@@ -172,7 +169,10 @@ class Config:
# Actions # Actions
## ##
def initConfig(self, confPath=None): def initConfig(self, confPath=None, dataPath=None):
"""Initialise the config class. The manual setting of confPath
and dataPath is mainly intended for the test suite.
"""
if confPath is None: if confPath is None:
confRoot = QStandardPaths.writableLocation(QStandardPaths.ConfigLocation) confRoot = QStandardPaths.writableLocation(QStandardPaths.ConfigLocation)
@@ -181,11 +181,15 @@ class Config:
logger.info("Setting config from alternative path: %s" % confPath) logger.info("Setting config from alternative path: %s" % confPath)
self.confPath = confPath self.confPath = confPath
if self.verQtValue >= 50400: if dataPath is None:
dataRoot = QStandardPaths.writableLocation(QStandardPaths.AppDataLocation) if self.verQtValue >= 50400:
dataRoot = QStandardPaths.writableLocation(QStandardPaths.AppDataLocation)
else:
dataRoot = QStandardPaths.writableLocation(QStandardPaths.DataLocation)
self.dataPath = path.join(path.abspath(dataRoot), self.appHandle)
else: else:
dataRoot = QStandardPaths.writableLocation(QStandardPaths.DataLocation) logger.info("Setting data path from alternative path: %s" % dataPath)
self.dataPath = path.join(path.abspath(dataRoot), self.appHandle) self.dataPath = dataPath
logger.verbose("Config path: %s" % self.confPath) logger.verbose("Config path: %s" % self.confPath)
logger.verbose("Data path: %s" % self.dataPath) logger.verbose("Data path: %s" % self.dataPath)
@@ -571,6 +575,15 @@ class Config:
self.confFile = path.basename(newPath) self.confFile = path.basename(newPath)
return True return True
def setDataPath(self, newPath):
if newPath is None:
return True
if not path.isdir(newPath):
logger.error("Config: Path not found. Using default data path instead.")
return False
self.dataPath = path.dirname(newPath)
return True
def setLastPath(self, lastPath): def setLastPath(self, lastPath):
if lastPath is None or lastPath == "": if lastPath is None or lastPath == "":
self.lastPath = "" self.lastPath = ""
+1 -11
View File
@@ -1,5 +1,5 @@
[Main] [Main]
timestamp = 2019-11-19 21:49:29 timestamp = 2020-02-26 18:10:35
theme = default theme = default
syntax = default_light syntax = default_light
guidark = False guidark = False
@@ -49,14 +49,4 @@ viewcomments = True
[Path] [Path]
lastpath = lastpath =
recent0 =
recent1 =
recent2 =
recent3 =
recent4 =
recent5 =
recent6 =
recent7 =
recent8 =
recent9 =
+1 -1
View File
@@ -13,7 +13,7 @@ theConf = Config()
def testConfigInit(nwTemp,nwRef): def testConfigInit(nwTemp,nwRef):
tmpConf = path.join(nwTemp,"novelwriter.conf") tmpConf = path.join(nwTemp,"novelwriter.conf")
refConf = path.join(nwRef, "novelwriter.conf") refConf = path.join(nwRef, "novelwriter.conf")
assert theConf.initConfig(nwTemp) assert theConf.initConfig(nwTemp, nwTemp)
assert theConf.setLastPath("") assert theConf.setLastPath("")
assert theConf.saveConfig() assert theConf.saveConfig()
assert cmpFiles(tmpConf, refConf, [2]) assert cmpFiles(tmpConf, refConf, [2])
+8 -8
View File
@@ -18,8 +18,8 @@ keyDelay = 10
stepDelay = 50 stepDelay = 50
@pytest.mark.gui @pytest.mark.gui
def testMainWindows(qtbot, nwTempGUI, nwRef): def testMainWindows(qtbot, nwTempGUI, nwRef, nwTemp):
nwGUI = nw.main(["--testmode","--config=%s" % nwTempGUI]) nwGUI = nw.main(["--testmode","--config=%s" % nwTempGUI, "--data=%s" % nwTemp])
qtbot.addWidget(nwGUI) qtbot.addWidget(nwGUI)
nwGUI.show() nwGUI.show()
qtbot.waitForWindowShown(nwGUI) qtbot.waitForWindowShown(nwGUI)
@@ -254,8 +254,8 @@ def testMainWindows(qtbot, nwTempGUI, nwRef):
# qtbot.stopForInteraction() # qtbot.stopForInteraction()
@pytest.mark.gui @pytest.mark.gui
def testTimeLineView(qtbot, nwTempGUI, nwRef): def testTimeLineView(qtbot, nwTempGUI, nwRef, nwTemp):
nwGUI = nw.main(["--testmode","--config=%s" % nwTempGUI]) nwGUI = nw.main(["--testmode","--config=%s" % nwTempGUI, "--data=%s" % nwTemp])
qtbot.addWidget(nwGUI) qtbot.addWidget(nwGUI)
nwGUI.show() nwGUI.show()
qtbot.waitForWindowShown(nwGUI) qtbot.waitForWindowShown(nwGUI)
@@ -276,8 +276,8 @@ def testTimeLineView(qtbot, nwTempGUI, nwRef):
nwGUI.closeMain() nwGUI.closeMain()
@pytest.mark.gui @pytest.mark.gui
def testProjectEditor(qtbot, nwTempGUI, nwRef): def testProjectEditor(qtbot, nwTempGUI, nwRef, nwTemp):
nwGUI = nw.main(["--testmode","--config=%s" % nwTempGUI]) nwGUI = nw.main(["--testmode","--config=%s" % nwTempGUI, "--data=%s" % nwTemp])
qtbot.addWidget(nwGUI) qtbot.addWidget(nwGUI)
nwGUI.show() nwGUI.show()
qtbot.waitForWindowShown(nwGUI) qtbot.waitForWindowShown(nwGUI)
@@ -363,8 +363,8 @@ def testProjectEditor(qtbot, nwTempGUI, nwRef):
# qtbot.stopForInteraction() # qtbot.stopForInteraction()
@pytest.mark.gui @pytest.mark.gui
def testItemEditor(qtbot, nwTempGUI, nwRef): def testItemEditor(qtbot, nwTempGUI, nwRef, nwTemp):
nwGUI = nw.main(["--testmode","--config=%s" % nwTempGUI]) nwGUI = nw.main(["--testmode","--config=%s" % nwTempGUI, "--data=%s" % nwTemp])
qtbot.addWidget(nwGUI) qtbot.addWidget(nwGUI)
nwGUI.show() nwGUI.show()
qtbot.waitForWindowShown(nwGUI) qtbot.waitForWindowShown(nwGUI)
+2 -2
View File
@@ -22,10 +22,10 @@ theProject = NWProject(theMain)
theProject.handleSeed = 42 theProject.handleSeed = 42
@pytest.mark.project @pytest.mark.project
def testProjectNew(nwTempProj,nwRef): def testProjectNew(nwTempProj,nwRef,nwTemp):
projFile = path.join(nwTempProj,"nwProject.nwx") projFile = path.join(nwTempProj,"nwProject.nwx")
refFile = path.join(nwRef,"proj","1_nwProject.nwx") refFile = path.join(nwRef,"proj","1_nwProject.nwx")
assert theConf.initConfig(nwRef) assert theConf.initConfig(nwRef, nwTemp)
assert theProject.newProject() assert theProject.newProject()
assert theProject.setProjectPath(nwTempProj) assert theProject.setProjectPath(nwTempProj)
assert theProject.saveProject() assert theProject.saveProject()