Added a basic test of the GUI
This commit is contained in:
+12
-2
@@ -11,8 +11,18 @@ def ensureDir(theDir):
|
||||
return
|
||||
|
||||
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()
|
||||
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 single’s quotes are replaced. We can hyphen-ate, make dashes – and even longer dashes — if we want. Ellipsis? Not a problem either …
|
||||
@@ -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>
|
||||
@@ -2,10 +2,11 @@
|
||||
"""novelWriter Common Class Tester
|
||||
"""
|
||||
|
||||
import nw
|
||||
import nw, pytest
|
||||
from nw.common import *
|
||||
from nwtools import cmpList
|
||||
|
||||
@pytest.mark.core
|
||||
def testCheckString():
|
||||
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(True, "NotNone",False) == "NotNone"
|
||||
|
||||
@pytest.mark.core
|
||||
def testCheckInt():
|
||||
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(True, 3,False) == 1
|
||||
|
||||
@pytest.mark.core
|
||||
def testCheckBool():
|
||||
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(2.0, None, False) is None
|
||||
|
||||
@pytest.mark.core
|
||||
def testColRange():
|
||||
assert colRange([0,0], [0,0], 0) is None
|
||||
assert cmpList(colRange([200,50,0], [50,200,0], 1), [200,50,0])
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"""novelWriter Config Class Tester
|
||||
"""
|
||||
|
||||
import nw
|
||||
import nw, pytest
|
||||
from nwtools import *
|
||||
from os import path, unlink
|
||||
from nw.config import Config
|
||||
@@ -20,16 +20,19 @@ ensureDir(testTemp)
|
||||
if path.isfile(tmpConf):
|
||||
unlink(tmpConf)
|
||||
|
||||
@pytest.mark.core
|
||||
def testConfigInit():
|
||||
assert theConf.initConfig(testTemp)
|
||||
assert cmpFiles(tmpConf, refConf, [2])
|
||||
assert not theConf.confChanged
|
||||
|
||||
@pytest.mark.core
|
||||
def testConfigSave():
|
||||
assert theConf.saveConfig()
|
||||
assert cmpFiles(tmpConf, refConf, [2])
|
||||
assert not theConf.confChanged
|
||||
|
||||
@pytest.mark.core
|
||||
def testConfigSetConfPath():
|
||||
assert theConf.setConfPath(None)
|
||||
assert not theConf.setConfPath(path.join("somewhere","over","the","rainbow"))
|
||||
@@ -38,10 +41,12 @@ def testConfigSetConfPath():
|
||||
assert theConf.confFile == "novelwriter.conf"
|
||||
assert not theConf.confChanged
|
||||
|
||||
@pytest.mark.core
|
||||
def testConfigLoad():
|
||||
assert theConf.loadConfig()
|
||||
assert not theConf.confChanged
|
||||
|
||||
@pytest.mark.core
|
||||
def testConfigSetWinSize():
|
||||
assert theConf.setWinSize(1105, 655)
|
||||
assert not theConf.confChanged
|
||||
@@ -52,6 +57,7 @@ def testConfigSetWinSize():
|
||||
assert cmpFiles(tmpConf, refConf, [2])
|
||||
assert not theConf.confChanged
|
||||
|
||||
@pytest.mark.core
|
||||
def testConfigSetTreeColWidths():
|
||||
assert theConf.setTreeColWidths([0, 0, 0])
|
||||
assert theConf.confChanged
|
||||
@@ -60,6 +66,7 @@ def testConfigSetTreeColWidths():
|
||||
assert cmpFiles(tmpConf, refConf, [2])
|
||||
assert not theConf.confChanged
|
||||
|
||||
@pytest.mark.core
|
||||
def testConfigSetMainPanePos():
|
||||
assert theConf.setMainPanePos([0, 0])
|
||||
assert theConf.confChanged
|
||||
|
||||
@@ -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()
|
||||
@@ -2,8 +2,7 @@
|
||||
"""novelWriter Project Class Tester
|
||||
"""
|
||||
|
||||
import nw
|
||||
import types
|
||||
import nw, pytest, types
|
||||
from os import path, unlink
|
||||
|
||||
from nwtools import *
|
||||
@@ -31,20 +30,24 @@ theProject.handleSeed = 42
|
||||
|
||||
projFile = path.join(testProj,"nwProject.nwx")
|
||||
|
||||
@pytest.mark.project
|
||||
def testProjectNew():
|
||||
assert theProject.newProject()
|
||||
assert theProject.setProjectPath(testProj)
|
||||
assert theProject.saveProject()
|
||||
assert cmpFiles(projFile, path.join(testRef,"new_nwProject.nwx"), [2])
|
||||
|
||||
@pytest.mark.project
|
||||
def testProjectOpen():
|
||||
assert theProject.openProject(projFile)
|
||||
|
||||
@pytest.mark.project
|
||||
def testProjectSave():
|
||||
assert theProject.saveProject()
|
||||
assert cmpFiles(projFile, path.join(testRef,"new_nwProject.nwx"), [2])
|
||||
assert not theProject.projChanged
|
||||
|
||||
@pytest.mark.project
|
||||
def testProjectNewRoot():
|
||||
assert theProject.openProject(projFile)
|
||||
assert isinstance(theProject.newRoot("Novel", nwItemClass.NOVEL), type(None))
|
||||
|
||||
Reference in New Issue
Block a user