Add test for the main error handler
This commit is contained in:
@@ -26,12 +26,13 @@ jobs:
|
|||||||
pip install --upgrade pip
|
pip install --upgrade pip
|
||||||
pip install -r requirements.txt
|
pip install -r requirements.txt
|
||||||
pip install PyVirtualDisplay
|
pip install PyVirtualDisplay
|
||||||
|
pip install pytest-timeout
|
||||||
pip install pytest-cov
|
pip install pytest-cov
|
||||||
pip install pytest-xvfb
|
pip install pytest-xvfb
|
||||||
pip install pytest-qt
|
pip install pytest-qt
|
||||||
pip install codecov
|
pip install codecov
|
||||||
- name: Run Tests
|
- name: Run Tests
|
||||||
run: xvfb-run pytest -v --cov=nw
|
run: xvfb-run pytest -v --cov=nw --timeout=90
|
||||||
- name: Upload to Codecov
|
- name: Upload to Codecov
|
||||||
uses: codecov/codecov-action@v1
|
uses: codecov/codecov-action@v1
|
||||||
|
|
||||||
@@ -58,7 +59,8 @@ jobs:
|
|||||||
pip install --upgrade pip
|
pip install --upgrade pip
|
||||||
pip install -r requirements.txt
|
pip install -r requirements.txt
|
||||||
pip install PyVirtualDisplay
|
pip install PyVirtualDisplay
|
||||||
|
pip install pytest-timeout
|
||||||
pip install pytest-xvfb
|
pip install pytest-xvfb
|
||||||
pip install pytest-qt
|
pip install pytest-qt
|
||||||
- name: Run Tests
|
- name: Run Tests
|
||||||
run: xvfb-run pytest -v
|
run: xvfb-run pytest -v --timeout=90
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ __pycache__
|
|||||||
|
|
||||||
# PyTest
|
# PyTest
|
||||||
/prof/
|
/prof/
|
||||||
|
/htmlcov/
|
||||||
/tests/temp
|
/tests/temp
|
||||||
/tests/lipsum/cache
|
/tests/lipsum/cache
|
||||||
/tests/lipsum/meta
|
/tests/lipsum/meta
|
||||||
|
|||||||
+2
-3
@@ -35,6 +35,7 @@ class NWErrorMessage(QDialog):
|
|||||||
|
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
QDialog.__init__(self, parent=parent)
|
QDialog.__init__(self, parent=parent)
|
||||||
|
self.setObjectName("NWErrorMessage")
|
||||||
|
|
||||||
# Widgets
|
# Widgets
|
||||||
self.msgIcon = QLabel()
|
self.msgIcon = QLabel()
|
||||||
@@ -146,9 +147,6 @@ def exceptionHandler(exType, exValue, exTrace):
|
|||||||
logger.critical("%s: %s" % (exType.__name__, str(exValue)))
|
logger.critical("%s: %s" % (exType.__name__, str(exValue)))
|
||||||
print_tb(exTrace)
|
print_tb(exTrace)
|
||||||
|
|
||||||
if not CONFIG.showGUI:
|
|
||||||
return
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
nwGUI = None
|
nwGUI = None
|
||||||
for qWin in qApp.topLevelWidgets():
|
for qWin in qApp.topLevelWidgets():
|
||||||
@@ -161,6 +159,7 @@ def exceptionHandler(exType, exValue, exTrace):
|
|||||||
return
|
return
|
||||||
|
|
||||||
errMsg = NWErrorMessage(nwGUI)
|
errMsg = NWErrorMessage(nwGUI)
|
||||||
|
nwGUI.activeDialog = errMsg
|
||||||
errMsg.setMessage(exType, exValue, exTrace)
|
errMsg.setMessage(exType, exValue, exTrace)
|
||||||
errMsg.exec_()
|
errMsg.exec_()
|
||||||
|
|
||||||
|
|||||||
@@ -74,6 +74,9 @@ class GuiMain(QMainWindow):
|
|||||||
self.mainConf.verPyString, self.mainConf.verPyHexVal)
|
self.mainConf.verPyString, self.mainConf.verPyHexVal)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Debug Tools
|
||||||
|
self.activeDialog = None
|
||||||
|
|
||||||
# Core Classes and settings
|
# Core Classes and settings
|
||||||
self.theTheme = GuiTheme(self)
|
self.theTheme = GuiTheme(self)
|
||||||
self.theProject = NWProject(self)
|
self.theProject = NWProject(self)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
[pytest]
|
[pytest]
|
||||||
markers =
|
markers =
|
||||||
project: Project classes tests
|
project: Project classes tests
|
||||||
|
error: Thest various error handling scenarios
|
||||||
core: Core functionality tests
|
core: Core functionality tests
|
||||||
gui: Qt5 GUI tests
|
gui: Qt5 GUI tests
|
||||||
serial
|
serial
|
||||||
|
|||||||
@@ -67,3 +67,4 @@ def getGuiItem(theName):
|
|||||||
for qWidget in qApp.topLevelWidgets():
|
for qWidget in qApp.topLevelWidgets():
|
||||||
if qWidget.objectName() == theName:
|
if qWidget.objectName() == theName:
|
||||||
return qWidget
|
return qWidget
|
||||||
|
return None
|
||||||
|
|||||||
@@ -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()
|
||||||
Reference in New Issue
Block a user