Merge pull request #11 from vkbo/test_coverage_2

Test Coverage - Part II
This commit is contained in:
Veronica K. Berglyd Olsen
2019-05-17 21:13:28 +02:00
committed by GitHub
3 changed files with 226 additions and 2 deletions
+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-17 21:06:41">
<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>Just a Page</name>
<type>FILE</type>
<class>NOVEL</class>
<status>1</status>
<expanded>False</expanded>
<layout>PAGE</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>
+60
View File
@@ -0,0 +1,60 @@
<?xml version='1.0' encoding='utf-8'?>
<novelWriterXML appVersion="0.1.2" fileVersion="1.0" timeStamp="2019-05-17 20:43:19">
<project>
<name>Project Name</name>
<title>Project Title</title>
<author>Jane Doe</author>
<author>John Doh</author>
</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>
+108 -2
View File
@@ -4,9 +4,14 @@
import nw, pytest
from nwtools import *
from os import path, unlink
from PyQt5.QtCore import Qt
from nw.gui.projecteditor import GuiProjectEditor
from nw.gui.itemeditor import GuiItemEditor
from nw.enum import *
keyDelay = 10
stepDelay = 50
testDir = path.dirname(__file__)
@@ -94,8 +99,8 @@ def testMainWindows(qtbot, tmpdir):
qtbot.keyClick(nwGUI.docEditor, Qt.Key_Return, delay=keyDelay)
qtbot.wait(stepDelay)
nwGUI.docEditor._runCounter()
qtbot.wait(1000)
nwGUI.docEditor.wCounter.run()
qtbot.wait(stepDelay)
# Save the document
assert nwGUI.docEditor.docChanged
@@ -109,3 +114,104 @@ def testMainWindows(qtbot, tmpdir):
assert cmpFiles(sceneFile, path.join(testRef,"gui_1489056e0916_main.nwd"))
# qtbot.stopForInteraction()
@pytest.mark.gui
def testProjectEditor(qtbot, tmpdir):
confDir = str(tmpdir.mkdir("conf"))
projDir = str(tmpdir.mkdir("project"))
nwGUI = nw.main(["--testmode","--config=%s" % confDir])
qtbot.addWidget(nwGUI)
nwGUI.show()
qtbot.waitForWindowShown(nwGUI)
qtbot.wait(stepDelay)
# Create new, save, open project
nwGUI.theProject.handleSeed = 42
assert nwGUI.theProject.setProjectPath(projDir)
assert nwGUI.newProject()
assert nwGUI.theProject.setProjectPath(projDir)
projEdit = GuiProjectEditor(nwGUI, nwGUI.theProject)
qtbot.addWidget(projEdit)
for c in "Project Name":
qtbot.keyClick(projEdit.editName, c, delay=keyDelay)
for c in "Project Title":
qtbot.keyClick(projEdit.editTitle, c, delay=keyDelay)
for c in "Jane Doe":
qtbot.keyClick(projEdit.editAuthors, c, delay=keyDelay)
qtbot.keyClick(projEdit.editAuthors, Qt.Key_Return, delay=keyDelay)
for c in "John Doh":
qtbot.keyClick(projEdit.editAuthors, c, delay=keyDelay)
qtbot.mouseClick(projEdit.saveButton, Qt.LeftButton)
projEdit = GuiProjectEditor(nwGUI, nwGUI.theProject)
qtbot.addWidget(projEdit)
assert projEdit.editName.text() == "Project Name"
assert projEdit.editTitle.text() == "Project Title"
theAuth = projEdit.editAuthors.toPlainText().strip().splitlines()
assert len(theAuth) == 2
assert theAuth[0] == "Jane Doe"
assert theAuth[1] == "John Doh"
qtbot.mouseClick(projEdit.closeButton, Qt.LeftButton)
qtbot.wait(stepDelay)
assert nwGUI.saveProject()
qtbot.wait(stepDelay)
# Check the files
projFile = path.join(projDir,"nwProject.nwx")
assert cmpFiles(projFile, path.join(testRef,"projedit_nwProject.nwx"), [2])
# qtbot.stopForInteraction()
@pytest.mark.gui
def testItemEditor(qtbot, tmpdir):
confDir = str(tmpdir.mkdir("conf"))
projDir = str(tmpdir.mkdir("project"))
nwGUI = nw.main(["--testmode","--config=%s" % confDir])
qtbot.addWidget(nwGUI)
nwGUI.show()
qtbot.waitForWindowShown(nwGUI)
qtbot.wait(stepDelay)
# Create new, save, open project
nwGUI.theProject.handleSeed = 42
assert nwGUI.theProject.setProjectPath(projDir)
assert nwGUI.newProject()
assert nwGUI.theProject.setProjectPath(projDir)
itemEdit = GuiItemEditor(nwGUI, nwGUI.theProject, "31489056e0916")
qtbot.addWidget(itemEdit)
assert itemEdit.editName.text() == "New Scene"
assert itemEdit.editStatus.currentData() == 0
assert itemEdit.editLayout.currentData() == nwItemLayout.SCENE
for c in "Just a Page":
qtbot.keyClick(itemEdit.editName, c, delay=keyDelay)
itemEdit.editStatus.setCurrentIndex(1)
layoutIdx = itemEdit.editLayout.findData(nwItemLayout.PAGE)
itemEdit.editLayout.setCurrentIndex(layoutIdx)
qtbot.mouseClick(itemEdit.saveButton, Qt.LeftButton)
itemEdit = GuiItemEditor(nwGUI, nwGUI.theProject, "31489056e0916")
qtbot.addWidget(itemEdit)
assert itemEdit.editName.text() == "Just a Page"
assert itemEdit.editStatus.currentData() == 1
assert itemEdit.editLayout.currentData() == nwItemLayout.PAGE
qtbot.mouseClick(itemEdit.closeButton, Qt.LeftButton)
qtbot.wait(stepDelay)
assert nwGUI.saveProject()
qtbot.wait(stepDelay)
# Check the files
projFile = path.join(projDir,"nwProject.nwx")
assert cmpFiles(projFile, path.join(testRef,"itemedit_nwProject.nwx"), [2])
# qtbot.stopForInteraction()