Working error test, but cannot properly test exception handler
This commit is contained in:
+3
-1
@@ -54,9 +54,11 @@ class Config:
|
|||||||
# Set Application Variables
|
# Set Application Variables
|
||||||
self.appName = "novelWriter"
|
self.appName = "novelWriter"
|
||||||
self.appHandle = self.appName.lower()
|
self.appHandle = self.appName.lower()
|
||||||
|
self.cmdOpen = None
|
||||||
|
|
||||||
|
# Debug Settings
|
||||||
self.showGUI = True
|
self.showGUI = True
|
||||||
self.debugInfo = False
|
self.debugInfo = False
|
||||||
self.cmdOpen = None
|
|
||||||
|
|
||||||
# Config Error Handling
|
# Config Error Handling
|
||||||
self.hasError = False
|
self.hasError = False
|
||||||
|
|||||||
+3
-2
@@ -138,6 +138,7 @@ class NWErrorMessage(QDialog):
|
|||||||
def exceptionHandler(exType, exValue, exTrace):
|
def exceptionHandler(exType, exValue, exTrace):
|
||||||
"""Function to catch unhandled global exceptions.
|
"""Function to catch unhandled global exceptions.
|
||||||
"""
|
"""
|
||||||
|
import nw
|
||||||
import logging
|
import logging
|
||||||
from traceback import print_tb
|
from traceback import print_tb
|
||||||
from PyQt5.QtWidgets import qApp
|
from PyQt5.QtWidgets import qApp
|
||||||
@@ -158,9 +159,9 @@ 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_()
|
if nw.CONFIG.showGUI:
|
||||||
|
errMsg.exec_()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Try a controlled shudown
|
# Try a controlled shudown
|
||||||
|
|||||||
@@ -17,9 +17,7 @@ from nw.gui import (
|
|||||||
GuiDocMerge, GuiDocSplit, GuiWritingStats, GuiProjectWizard,
|
GuiDocMerge, GuiDocSplit, GuiWritingStats, GuiProjectWizard,
|
||||||
GuiProjectLoad
|
GuiProjectLoad
|
||||||
)
|
)
|
||||||
from nw.constants import (
|
from nw.constants import nwItemType, nwItemLayout, nwItemClass
|
||||||
nwItemType, nwItemLayout, nwItemClass
|
|
||||||
)
|
|
||||||
|
|
||||||
keyDelay = 2
|
keyDelay = 2
|
||||||
stepDelay = 20
|
stepDelay = 20
|
||||||
|
|||||||
+4
-22
@@ -6,21 +6,20 @@ import nw
|
|||||||
import sys
|
import sys
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from nwtools import getGuiItem
|
from PyQt5.QtWidgets import qApp
|
||||||
|
|
||||||
from PyQt5.QtCore import Qt, QTimer
|
from nw.error import NWErrorMessage
|
||||||
from PyQt5.QtWidgets import qApp, QDialogButtonBox
|
|
||||||
|
|
||||||
from nw.error import NWErrorMessage, exceptionHandler
|
|
||||||
|
|
||||||
@pytest.mark.error
|
@pytest.mark.error
|
||||||
def testErrorDialog(qtbot, nwFuncTemp, nwTemp):
|
def testErrorDialog(qtbot, nwFuncTemp, nwTemp):
|
||||||
|
qApp.closeAllWindows()
|
||||||
nwGUI = nw.main(["--testmode", "--config=%s" % nwFuncTemp, "--data=%s" % nwTemp])
|
nwGUI = nw.main(["--testmode", "--config=%s" % nwFuncTemp, "--data=%s" % nwTemp])
|
||||||
qtbot.addWidget(nwGUI)
|
qtbot.addWidget(nwGUI)
|
||||||
nwGUI.show()
|
nwGUI.show()
|
||||||
qtbot.waitForWindowShown(nwGUI)
|
qtbot.waitForWindowShown(nwGUI)
|
||||||
|
|
||||||
nwErr = NWErrorMessage(nwGUI)
|
nwErr = NWErrorMessage(nwGUI)
|
||||||
|
qtbot.addWidget(nwErr)
|
||||||
nwErr.show()
|
nwErr.show()
|
||||||
|
|
||||||
# Invalid Error
|
# Invalid Error
|
||||||
@@ -35,23 +34,6 @@ def testErrorDialog(qtbot, nwFuncTemp, nwTemp):
|
|||||||
assert "Exception" in theMessage
|
assert "Exception" in theMessage
|
||||||
nwErr._doClose()
|
nwErr._doClose()
|
||||||
nwErr.close()
|
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()
|
nwGUI.closeMain()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user