Added a basic test of the GUI

This commit is contained in:
Veronica K. B. Olsen
2019-05-16 23:20:44 +02:00
parent 63c3182a0e
commit 66f6494894
11 changed files with 176 additions and 50 deletions
+6 -5
View File
@@ -1,4 +1,4 @@
dist: xenial # required for Python >= 3.7 dist: bionic
language: python language: python
sudo: required sudo: required
addons: addons:
@@ -6,15 +6,16 @@ addons:
packages: packages:
- libenchant-dev - libenchant-dev
python: python:
# - "3.5" # - "3.5"
# - "3.6" # - "3.6"
- "3.7" - "3.7"
# - "3.8-dev" # - "3.8-dev"
install: install:
- pip install -r requirements.txt - pip install -r requirements.txt
- pip install pytest-cov - pip install pytest-cov
# - pip install pytest-qt
- pip install codecov - pip install codecov
script: script:
- python -m pytest --cov=nw -v - python -m pytest --cov=nw -m "project|core" -v
after_success: after_success:
- codecov - codecov
+13 -9
View File
@@ -15,7 +15,7 @@ import getopt
from os import path, remove, rename from os import path, remove, rename
from PyQt5.QtWidgets import QApplication from PyQt5.QtWidgets import QApplication
from nw.main import NovelWriter from nw.gui.winmain import GuiMain
from nw.config import Config from nw.config import Config
__package__ = "novelWriter" __package__ = "novelWriter"
@@ -78,7 +78,7 @@ def main(sysArgs):
"logfile=", "logfile=",
"version", "version",
"config=", "config=",
"headless", "testmode",
] ]
helpMsg = ( helpMsg = (
@@ -111,7 +111,7 @@ def main(sysArgs):
toStd = True toStd = True
showTime = False showTime = False
confPath = None confPath = None
showGUI = True testMode = False
debugGUI = False debugGUI = False
# Parse Options # Parse Options
@@ -143,15 +143,15 @@ def main(sysArgs):
showTime = True showTime = True
elif inOpt in ("--config"): elif inOpt in ("--config"):
confPath = inArg confPath = inArg
elif inOpt in ("--headless"): elif inOpt in ("--testmode"):
showGUI = False testMode = True
elif inOpt in ("-D","--debuggui"): elif inOpt in ("-D","--debuggui"):
debugLevel = logging.DEBUG debugLevel = logging.DEBUG
debugStr = "{name:>20}:{lineno:<4d} {levelname:8} {message:}" debugStr = "{name:>20}:{lineno:<4d} {levelname:8} {message:}"
debugGUI = True debugGUI = True
# Set Config Options # Set Config Options
CONFIG.showGUI = showGUI CONFIG.showGUI = not testMode
CONFIG.debugGUI = debugGUI CONFIG.debugGUI = debugGUI
# Set Logging # Set Logging
@@ -179,8 +179,12 @@ def main(sysArgs):
CONFIG.initConfig(confPath) CONFIG.initConfig(confPath)
nwApp = QApplication([]) if testMode:
nwGUI = NovelWriter() nwGUI = GuiMain()
exit(nwApp.exec_()) return nwGUI
else:
nwApp = QApplication([])
nwGUI = GuiMain()
exit(nwApp.exec_())
return return
+1 -1
View File
@@ -170,7 +170,7 @@ class GuiMain(QMainWindow):
if self.saveProject(): if self.saveProject():
self.theProject.newProject() self.theProject.newProject()
self.treeView.buildTree() self.treeView.buildTree()
return return True
def openProject(self, projFile=None): def openProject(self, projFile=None):
if projFile is None: if projFile is None:
-29
View File
@@ -1,29 +0,0 @@
# -*- coding: utf-8 -*-
"""novelWriter Main Class
novelWriter Main Class
==========================
Sets up the main GUI and holds action and event functions
File History:
Created: 2018-09-22 [0.0.1]
"""
import logging
import nw
from nw.gui.winmain import GuiMain
logger = logging.getLogger(__name__)
class NovelWriter():
def __init__(self):
super().__init__()
self.winMain = GuiMain()
return
# END Class NovelWriter
+12 -2
View File
@@ -11,8 +11,18 @@ def ensureDir(theDir):
return return
def cmpFiles(fileOne, fileTwo, ignoreLines=[]): def cmpFiles(fileOne, fileTwo, ignoreLines=[]):
foOne = open(fileOne,mode="r")
foTwo = open(fileTwo,mode="r") try:
foOne = open(fileOne,mode="r")
except Exception as e:
print(str(e))
return False
try:
foTwo = open(fileTwo,mode="r")
except Exception as e:
print(str(e))
return False
txtOne = foOne.readlines() txtOne = foOne.readlines()
txtTwo = foTwo.readlines() txtTwo = foTwo.readlines()
@@ -0,0 +1,5 @@
# Hello World!
This is a paragraph of dummy text.
This is another paragraph of much longer dummy text. It is in fact very very dum dummy text! We can also try replacing “quotes”, even singles quotes are replaced. We can hyphen-ate, make dashes and even longer dashes — if we want. Ellipsis? Not a problem either …
+58
View File
@@ -0,0 +1,58 @@
<?xml version='1.0' encoding='utf-8'?>
<novelWriterXML appVersion="0.1.2" fileVersion="1.0" timeStamp="2019-05-16 22:37:13">
<project>
<name></name>
<title></title>
</project>
<settings>
<spellCheck>False</spellCheck>
</settings>
<content count="6">
<item handle="73475cb40a568" order="0" parent="None">
<name>Novel</name>
<type>ROOT</type>
<class>NOVEL</class>
<status>0</status>
<expanded>False</expanded>
</item>
<item handle="25fc0e7096fc6" order="0" parent="73475cb40a568">
<name>New Chapter</name>
<type>FOLDER</type>
<class>NOVEL</class>
<status>0</status>
<expanded>False</expanded>
</item>
<item handle="31489056e0916" order="0" parent="25fc0e7096fc6">
<name>New Scene</name>
<type>FILE</type>
<class>NOVEL</class>
<status>0</status>
<expanded>False</expanded>
<layout>SCENE</layout>
<charCount>0</charCount>
<wordCount>0</wordCount>
<paraCount>0</paraCount>
</item>
<item handle="44cb730c42048" order="1" parent="None">
<name>Characters</name>
<type>ROOT</type>
<class>CHARACTER</class>
<status>0</status>
<expanded>False</expanded>
</item>
<item handle="71ee45a3c0db9" order="2" parent="None">
<name>Plot</name>
<type>ROOT</type>
<class>PLOT</class>
<status>0</status>
<expanded>False</expanded>
</item>
<item handle="811786ad1ae74" order="3" parent="None">
<name>World</name>
<type>ROOT</type>
<class>WORLD</class>
<status>0</status>
<expanded>False</expanded>
</item>
</content>
</novelWriterXML>
+5 -1
View File
@@ -2,10 +2,11 @@
"""novelWriter Common Class Tester """novelWriter Common Class Tester
""" """
import nw import nw, pytest
from nw.common import * from nw.common import *
from nwtools import cmpList from nwtools import cmpList
@pytest.mark.core
def testCheckString(): def testCheckString():
assert checkString(None, "NotNone",True) is None assert checkString(None, "NotNone",True) is None
assert checkString("None","NotNone",True) is None assert checkString("None","NotNone",True) is None
@@ -15,6 +16,7 @@ def testCheckString():
assert checkString(1.0, "NotNone",False) == "NotNone" assert checkString(1.0, "NotNone",False) == "NotNone"
assert checkString(True, "NotNone",False) == "NotNone" assert checkString(True, "NotNone",False) == "NotNone"
@pytest.mark.core
def testCheckInt(): def testCheckInt():
assert checkInt(None, 3,True) is None assert checkInt(None, 3,True) is None
assert checkInt("None",3,True) is None assert checkInt("None",3,True) is None
@@ -23,6 +25,7 @@ def testCheckInt():
assert checkInt(1.0, 3,False) == 1 assert checkInt(1.0, 3,False) == 1
assert checkInt(True, 3,False) == 1 assert checkInt(True, 3,False) == 1
@pytest.mark.core
def testCheckBool(): def testCheckBool():
assert checkBool(None, 3, True) is None assert checkBool(None, 3, True) is None
assert checkBool("None", 3, True) is None assert checkBool("None", 3, True) is None
@@ -36,6 +39,7 @@ def testCheckBool():
assert checkBool(1.0, None, False) is None assert checkBool(1.0, None, False) is None
assert checkBool(2.0, None, False) is None assert checkBool(2.0, None, False) is None
@pytest.mark.core
def testColRange(): def testColRange():
assert colRange([0,0], [0,0], 0) is None assert colRange([0,0], [0,0], 0) is None
assert cmpList(colRange([200,50,0], [50,200,0], 1), [200,50,0]) assert cmpList(colRange([200,50,0], [50,200,0], 1), [200,50,0])
+8 -1
View File
@@ -2,7 +2,7 @@
"""novelWriter Config Class Tester """novelWriter Config Class Tester
""" """
import nw import nw, pytest
from nwtools import * from nwtools import *
from os import path, unlink from os import path, unlink
from nw.config import Config from nw.config import Config
@@ -20,16 +20,19 @@ ensureDir(testTemp)
if path.isfile(tmpConf): if path.isfile(tmpConf):
unlink(tmpConf) unlink(tmpConf)
@pytest.mark.core
def testConfigInit(): def testConfigInit():
assert theConf.initConfig(testTemp) assert theConf.initConfig(testTemp)
assert cmpFiles(tmpConf, refConf, [2]) assert cmpFiles(tmpConf, refConf, [2])
assert not theConf.confChanged assert not theConf.confChanged
@pytest.mark.core
def testConfigSave(): def testConfigSave():
assert theConf.saveConfig() assert theConf.saveConfig()
assert cmpFiles(tmpConf, refConf, [2]) assert cmpFiles(tmpConf, refConf, [2])
assert not theConf.confChanged assert not theConf.confChanged
@pytest.mark.core
def testConfigSetConfPath(): def testConfigSetConfPath():
assert theConf.setConfPath(None) assert theConf.setConfPath(None)
assert not theConf.setConfPath(path.join("somewhere","over","the","rainbow")) assert not theConf.setConfPath(path.join("somewhere","over","the","rainbow"))
@@ -38,10 +41,12 @@ def testConfigSetConfPath():
assert theConf.confFile == "novelwriter.conf" assert theConf.confFile == "novelwriter.conf"
assert not theConf.confChanged assert not theConf.confChanged
@pytest.mark.core
def testConfigLoad(): def testConfigLoad():
assert theConf.loadConfig() assert theConf.loadConfig()
assert not theConf.confChanged assert not theConf.confChanged
@pytest.mark.core
def testConfigSetWinSize(): def testConfigSetWinSize():
assert theConf.setWinSize(1105, 655) assert theConf.setWinSize(1105, 655)
assert not theConf.confChanged assert not theConf.confChanged
@@ -52,6 +57,7 @@ def testConfigSetWinSize():
assert cmpFiles(tmpConf, refConf, [2]) assert cmpFiles(tmpConf, refConf, [2])
assert not theConf.confChanged assert not theConf.confChanged
@pytest.mark.core
def testConfigSetTreeColWidths(): def testConfigSetTreeColWidths():
assert theConf.setTreeColWidths([0, 0, 0]) assert theConf.setTreeColWidths([0, 0, 0])
assert theConf.confChanged assert theConf.confChanged
@@ -60,6 +66,7 @@ def testConfigSetTreeColWidths():
assert cmpFiles(tmpConf, refConf, [2]) assert cmpFiles(tmpConf, refConf, [2])
assert not theConf.confChanged assert not theConf.confChanged
@pytest.mark.core
def testConfigSetMainPanePos(): def testConfigSetMainPanePos():
assert theConf.setMainPanePos([0, 0]) assert theConf.setMainPanePos([0, 0])
assert theConf.confChanged assert theConf.confChanged
+63
View File
@@ -0,0 +1,63 @@
# -*- coding: utf-8 -*-
"""novelWriter Main GUI Class Tester
"""
import nw, pytest
from nwtools import *
from os import path, unlink
from PyQt5.QtCore import Qt
keyDelay = 10
testDir = path.dirname(__file__)
testRef = path.join(testDir,"reference")
@pytest.mark.gui
def testMainWindows(qtbot, tmpdir):
confDir = tmpdir.mkdir("conf")
projDir = tmpdir.mkdir("project")
nwGUI = nw.main(["--testmode","--config=%s" % confDir])
qtbot.addWidget(nwGUI)
nwGUI.show()
qtbot.waitForWindowShown(nwGUI)
qtbot.wait(500)
nwGUI.theProject.handleSeed = 42
assert nwGUI.theProject.setProjectPath(projDir)
assert nwGUI.newProject()
assert nwGUI.theProject.setProjectPath(projDir)
assert nwGUI.saveProject()
qtbot.wait(500)
assert nwGUI.openProject(projDir)
qtbot.keyClick(nwGUI.treeView, Qt.Key_1, modifier=Qt.ControlModifier, delay=keyDelay)
qtbot.keyClick(nwGUI.treeView, Qt.Key_Down, delay=keyDelay)
qtbot.keyClick(nwGUI.treeView, Qt.Key_Right, delay=keyDelay)
qtbot.keyClick(nwGUI.treeView, Qt.Key_Down, delay=keyDelay)
qtbot.keyClick(nwGUI.treeView, Qt.Key_Right, delay=keyDelay)
qtbot.keyClick(nwGUI.treeView, Qt.Key_Down, delay=keyDelay)
qtbot.keyClick(nwGUI.treeView, Qt.Key_Return, delay=keyDelay)
qtbot.keyClick(nwGUI.treeView, Qt.Key_2, modifier=Qt.ControlModifier, delay=keyDelay)
for c in "# Hello World!":
qtbot.keyClick(nwGUI.docEditor, c, delay=keyDelay)
qtbot.keyClick(nwGUI.docEditor, Qt.Key_Return, delay=keyDelay)
qtbot.keyClick(nwGUI.docEditor, Qt.Key_Return, delay=keyDelay)
for c in "This is a paragraph of dummy text.":
qtbot.keyClick(nwGUI.docEditor, c, delay=keyDelay)
qtbot.keyClick(nwGUI.docEditor, Qt.Key_Return, delay=keyDelay)
qtbot.keyClick(nwGUI.docEditor, Qt.Key_Return, delay=keyDelay)
for c in "This is another paragraph of much longer dummy text. It is in fact very very dum dummy text! ":
qtbot.keyClick(nwGUI.docEditor, c, delay=keyDelay)
for c in "We can also try replacing \"quotes\", even single's quotes are replaced. ":
qtbot.keyClick(nwGUI.docEditor, c, delay=keyDelay)
for c in "We can hyphen-ate, make dashes -- and even longer dashes --- if we want. ":
qtbot.keyClick(nwGUI.docEditor, c, delay=keyDelay)
for c in "Ellipsis? Not a problem either ... ":
qtbot.keyClick(nwGUI.docEditor, c, delay=keyDelay)
qtbot.wait(500)
qtbot.keyClick(nwGUI, "s", modifier=Qt.ControlModifier, delay=keyDelay)
qtbot.wait(500)
projFile = projDir.join("nwProject.nwx")
assert cmpFiles(projFile, path.join(testRef,"gui_nwProject.nwx"), [2])
sceneFile = projDir.join("data_3","1489056e0916_main.nwd")
assert cmpFiles(sceneFile, path.join(testRef,"gui_1489056e0916_main.nwd"))
# qtbot.stopForInteraction()
+5 -2
View File
@@ -2,8 +2,7 @@
"""novelWriter Project Class Tester """novelWriter Project Class Tester
""" """
import nw import nw, pytest, types
import types
from os import path, unlink from os import path, unlink
from nwtools import * from nwtools import *
@@ -31,20 +30,24 @@ theProject.handleSeed = 42
projFile = path.join(testProj,"nwProject.nwx") projFile = path.join(testProj,"nwProject.nwx")
@pytest.mark.project
def testProjectNew(): def testProjectNew():
assert theProject.newProject() assert theProject.newProject()
assert theProject.setProjectPath(testProj) assert theProject.setProjectPath(testProj)
assert theProject.saveProject() assert theProject.saveProject()
assert cmpFiles(projFile, path.join(testRef,"new_nwProject.nwx"), [2]) assert cmpFiles(projFile, path.join(testRef,"new_nwProject.nwx"), [2])
@pytest.mark.project
def testProjectOpen(): def testProjectOpen():
assert theProject.openProject(projFile) assert theProject.openProject(projFile)
@pytest.mark.project
def testProjectSave(): def testProjectSave():
assert theProject.saveProject() assert theProject.saveProject()
assert cmpFiles(projFile, path.join(testRef,"new_nwProject.nwx"), [2]) assert cmpFiles(projFile, path.join(testRef,"new_nwProject.nwx"), [2])
assert not theProject.projChanged assert not theProject.projChanged
@pytest.mark.project
def testProjectNewRoot(): def testProjectNewRoot():
assert theProject.openProject(projFile) assert theProject.openProject(projFile)
assert isinstance(theProject.newRoot("Novel", nwItemClass.NOVEL), type(None)) assert isinstance(theProject.newRoot("Novel", nwItemClass.NOVEL), type(None))