GUI tests working locally when headless.

This commit is contained in:
Veronica K. B. Olsen
2019-05-17 01:55:37 +02:00
parent 13cb526ff5
commit bc39ec7886
4 changed files with 53 additions and 32 deletions
+4 -3
View File
@@ -1,4 +1,6 @@
dist: xenial
# services:
# - xvfb
language: python
sudo: required
addons:
@@ -6,16 +8,15 @@ addons:
packages:
- libenchant-dev
python:
# - "3.5"
# - "3.6"
- "3.7"
# - "3.8-dev"
install:
- pip install -r requirements.txt
# - pip install pytest-faulthandler
- pip install pytest-cov
# - pip install pytest-qt
- pip install codecov
script:
# - xvfb-run -a python -m pytest --cov=nw -m "project|core|gui" -v -s
- python -m pytest --cov=nw -m "project|core" -v
after_success:
- codecov
+10 -9
View File
@@ -282,15 +282,16 @@ class GuiDocTree(QTreeWidget):
def propagateCount(self, tHandle, theCount, nDepth=0):
tItem = self._getTreeItem(tHandle)
tItem.setText(self.C_COUNT,str(theCount))
pItem = tItem.parent()
if pItem is not None:
pCount = 0
for i in range(pItem.childCount()):
pCount += int(pItem.child(i).text(self.C_COUNT))
pHandle = pItem.text(self.C_HANDLE)
if not nDepth > 200 and pHandle != "":
self.propagateCount(pHandle, pCount, nDepth+1)
if tItem is not None:
tItem.setText(self.C_COUNT,str(theCount))
pItem = tItem.parent()
if pItem is not None:
pCount = 0
for i in range(pItem.childCount()):
pCount += int(pItem.child(i).text(self.C_COUNT))
pHandle = pItem.text(self.C_HANDLE)
if not nDepth > 200 and pHandle != "":
self.propagateCount(pHandle, pCount, nDepth+1)
return
def buildTree(self):
+5 -4
View File
@@ -207,7 +207,7 @@ class GuiMain(QMainWindow):
self.stackPane.setCurrentIndex(self.stackDoc)
self.docEditor.setText(self.theDocument.openDocument(tHandle))
self.docEditor.changeWidth()
return
return True
def saveDocument(self):
if self.theDocument.theItem is not None:
@@ -217,7 +217,7 @@ class GuiMain(QMainWindow):
self.theDocument.theItem.setParaCount(self.docEditor.paraCount)
self.theDocument.saveDocument(docHtml)
self.docEditor.setDocumentChanged(False)
return
return True
def _previewDocument(self):
@@ -246,7 +246,7 @@ class GuiMain(QMainWindow):
tHandle = self.treeView.getSelectedHandle()
if tHandle is None:
logger.warning("No item selected")
return
return False
logger.verbose("Opening item %s" % tHandle)
nwItem = self.theProject.getItem(tHandle)
@@ -255,7 +255,8 @@ class GuiMain(QMainWindow):
self.openDocument(tHandle)
else:
logger.verbose("Requested item %s is not a file" % tHandle)
return
return True
def editItem(self):
tHandle = self.treeView.getSelectedHandle()
+34 -16
View File
@@ -7,9 +7,10 @@ from nwtools import *
from os import path, unlink
from PyQt5.QtCore import Qt
keyDelay = 10
testDir = path.dirname(__file__)
testRef = path.join(testDir,"reference")
keyDelay = 10
stepDelay = 100
testDir = path.dirname(__file__)
testRef = path.join(testDir,"reference")
@pytest.mark.gui
def testMainWindows(qtbot, tmpdir):
@@ -19,22 +20,35 @@ def testMainWindows(qtbot, tmpdir):
qtbot.addWidget(nwGUI)
nwGUI.show()
qtbot.waitForWindowShown(nwGUI)
qtbot.wait(500)
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)
assert nwGUI.saveProject()
qtbot.wait(500)
qtbot.wait(stepDelay)
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)
qtbot.wait(stepDelay)
# Check that tree items have been created
assert nwGUI.treeView._getTreeItem("73475cb40a568") is not None
assert nwGUI.treeView._getTreeItem("25fc0e7096fc6") is not None
assert nwGUI.treeView._getTreeItem("31489056e0916") is not None
assert nwGUI.treeView._getTreeItem("44cb730c42048") is not None
assert nwGUI.treeView._getTreeItem("71ee45a3c0db9") is not None
assert nwGUI.treeView._getTreeItem("811786ad1ae74") is not None
# Select the 'New Scene' file
nwGUI.treeView.setFocus()
nwGUI.treeView._getTreeItem("73475cb40a568").setExpanded(True)
nwGUI.treeView._getTreeItem("25fc0e7096fc6").setExpanded(True)
nwGUI.treeView._getTreeItem("31489056e0916").setSelected(True)
assert nwGUI.openSelectedItem()
# Type something into the document
nwGUI.docEditor.setFocus()
for c in "# Hello World!":
qtbot.keyClick(nwGUI.docEditor, c, delay=keyDelay)
qtbot.keyClick(nwGUI.docEditor, Qt.Key_Return, delay=keyDelay)
@@ -51,10 +65,14 @@ def testMainWindows(qtbot, tmpdir):
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)
qtbot.wait(stepDelay)
# Save the document
assert nwGUI.docEditor.docChanged
assert nwGUI.saveDocument()
qtbot.wait(stepDelay)
# Check the files
projFile = projDir.join("nwProject.nwx")
assert cmpFiles(projFile, path.join(testRef,"gui_nwProject.nwx"), [2])
sceneFile = projDir.join("data_3","1489056e0916_main.nwd")