Add test for the main error handler

This commit is contained in:
Veronica K. B. Olsen
2020-09-19 13:06:58 +02:00
parent e9fd293689
commit 365e2676fb
7 changed files with 70 additions and 5 deletions
+4 -2
View File
@@ -26,12 +26,13 @@ jobs:
pip install --upgrade pip
pip install -r requirements.txt
pip install PyVirtualDisplay
pip install pytest-timeout
pip install pytest-cov
pip install pytest-xvfb
pip install pytest-qt
pip install codecov
- name: Run Tests
run: xvfb-run pytest -v --cov=nw
run: xvfb-run pytest -v --cov=nw --timeout=90
- name: Upload to Codecov
uses: codecov/codecov-action@v1
@@ -58,7 +59,8 @@ jobs:
pip install --upgrade pip
pip install -r requirements.txt
pip install PyVirtualDisplay
pip install pytest-timeout
pip install pytest-xvfb
pip install pytest-qt
- name: Run Tests
run: xvfb-run pytest -v
run: xvfb-run pytest -v --timeout=90
+1
View File
@@ -23,6 +23,7 @@ __pycache__
# PyTest
/prof/
/htmlcov/
/tests/temp
/tests/lipsum/cache
/tests/lipsum/meta
+2 -3
View File
@@ -35,6 +35,7 @@ class NWErrorMessage(QDialog):
def __init__(self, parent):
QDialog.__init__(self, parent=parent)
self.setObjectName("NWErrorMessage")
# Widgets
self.msgIcon = QLabel()
@@ -146,9 +147,6 @@ def exceptionHandler(exType, exValue, exTrace):
logger.critical("%s: %s" % (exType.__name__, str(exValue)))
print_tb(exTrace)
if not CONFIG.showGUI:
return
try:
nwGUI = None
for qWin in qApp.topLevelWidgets():
@@ -161,6 +159,7 @@ def exceptionHandler(exType, exValue, exTrace):
return
errMsg = NWErrorMessage(nwGUI)
nwGUI.activeDialog = errMsg
errMsg.setMessage(exType, exValue, exTrace)
errMsg.exec_()
+3
View File
@@ -74,6 +74,9 @@ class GuiMain(QMainWindow):
self.mainConf.verPyString, self.mainConf.verPyHexVal)
)
# Debug Tools
self.activeDialog = None
# Core Classes and settings
self.theTheme = GuiTheme(self)
self.theProject = NWProject(self)
+1
View File
@@ -1,6 +1,7 @@
[pytest]
markers =
project: Project classes tests
error: Thest various error handling scenarios
core: Core functionality tests
gui: Qt5 GUI tests
serial
+1
View File
@@ -67,3 +67,4 @@ def getGuiItem(theName):
for qWidget in qApp.topLevelWidgets():
if qWidget.objectName() == theName:
return qWidget
return None
+58
View File
@@ -0,0 +1,58 @@
# -*- coding: utf-8 -*-
"""novelWriter Error Tester
"""
import nw
import sys
import pytest
from nwtools import getGuiItem
from PyQt5.QtCore import Qt, QTimer
from PyQt5.QtWidgets import qApp, QDialogButtonBox
from nw.error import NWErrorMessage, exceptionHandler
@pytest.mark.error
def testErrorDialog(qtbot, nwFuncTemp, nwTemp):
nwGUI = nw.main(["--testmode", "--config=%s" % nwFuncTemp, "--data=%s" % nwTemp])
qtbot.addWidget(nwGUI)
nwGUI.show()
qtbot.waitForWindowShown(nwGUI)
nwErr = NWErrorMessage(nwGUI)
nwErr.show()
# Invalid Error
nwErr.setMessage(Exception, "Faulty Error", 123)
assert nwErr.msgBody.toPlainText() == "Failed to generate error report ..."
# Valid Error
nwErr.setMessage(Exception, "First Error", sys.last_traceback)
theMessage = nwErr.msgBody.toPlainText()
assert theMessage
assert "First Error" in theMessage
assert "Exception" in theMessage
nwErr._doClose()
nwErr.close()
del nwErr
# Exception Handler
def handleDialog():
while not isinstance(nwGUI.activeDialog, NWErrorMessage):
qApp.processEvents()
nwErr = nwGUI.activeDialog
theMessage = nwErr.msgBody.toPlainText()
assert theMessage
assert "Second Error" in theMessage
assert "Exception" in theMessage
btnClose = nwErr.btnBox.button(QDialogButtonBox.Close)
qtbot.mouseClick(btnClose, Qt.LeftButton, delay=1)
QTimer.singleShot(0, handleDialog)
exceptionHandler(Exception, "Second Error", sys.last_traceback)
nwGUI.closeMain()
# qtbot.stopForInteraction()