Cleaned up error tests and removed testmode from error handler
This commit is contained in:
+2
-5
@@ -135,7 +135,7 @@ class NWErrorMessage(QDialog):
|
|||||||
# END Class NWErrorMessage
|
# END Class NWErrorMessage
|
||||||
|
|
||||||
|
|
||||||
def exceptionHandler(exType, exValue, exTrace, testMode=False):
|
def exceptionHandler(exType, exValue, exTrace):
|
||||||
"""Function to catch unhandled global exceptions.
|
"""Function to catch unhandled global exceptions.
|
||||||
"""
|
"""
|
||||||
import nw
|
import nw
|
||||||
@@ -173,10 +173,7 @@ def exceptionHandler(exType, exValue, exTrace, testMode=False):
|
|||||||
logger.critical("Could not close the project before exiting")
|
logger.critical("Could not close the project before exiting")
|
||||||
logger.critical(str(e))
|
logger.critical(str(e))
|
||||||
|
|
||||||
if testMode:
|
qApp.exit(1)
|
||||||
return errMsg.msgBody.toPlainText()
|
|
||||||
else:
|
|
||||||
qApp.exit(1)
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.critical(str(e))
|
logger.critical(str(e))
|
||||||
|
|||||||
+38
-24
@@ -13,6 +13,8 @@ from nw.error import NWErrorMessage, exceptionHandler
|
|||||||
|
|
||||||
@pytest.mark.base
|
@pytest.mark.base
|
||||||
def testBaseError_Dialog(qtbot, monkeypatch, fncDir, tmpDir):
|
def testBaseError_Dialog(qtbot, monkeypatch, fncDir, tmpDir):
|
||||||
|
"""Test the error dialog.
|
||||||
|
"""
|
||||||
qApp.closeAllWindows()
|
qApp.closeAllWindows()
|
||||||
nwGUI = nw.main(["--testmode", "--config=%s" % fncDir, "--data=%s" % tmpDir])
|
nwGUI = nw.main(["--testmode", "--config=%s" % fncDir, "--data=%s" % tmpDir])
|
||||||
qtbot.addWidget(nwGUI)
|
qtbot.addWidget(nwGUI)
|
||||||
@@ -28,60 +30,72 @@ def testBaseError_Dialog(qtbot, monkeypatch, fncDir, tmpDir):
|
|||||||
assert nwErr.msgBody.toPlainText() == "Failed to generate error report ..."
|
assert nwErr.msgBody.toPlainText() == "Failed to generate error report ..."
|
||||||
|
|
||||||
# Valid Error Message
|
# Valid Error Message
|
||||||
nwErr.setMessage(Exception, "First Error", None)
|
monkeypatch.setattr("PyQt5.QtCore.QSysInfo.kernelVersion", lambda: "1.2.3")
|
||||||
|
nwErr.setMessage(Exception, "Fine Error", None)
|
||||||
theMessage = nwErr.msgBody.toPlainText()
|
theMessage = nwErr.msgBody.toPlainText()
|
||||||
assert theMessage
|
assert theMessage
|
||||||
assert "First Error" in theMessage
|
assert "Fine Error" in theMessage
|
||||||
assert "Exception" in theMessage
|
|
||||||
nwErr._doClose()
|
|
||||||
nwErr.close()
|
|
||||||
|
|
||||||
# Valid Error
|
|
||||||
monkeypatch.setattr("PyQt5.QtCore.QSysInfo.kernelVersion", lambda: "1.2.3")
|
|
||||||
theMessage = exceptionHandler(Exception, "Second Error", None, testMode=True)
|
|
||||||
assert theMessage
|
|
||||||
assert "Second Error" in theMessage
|
|
||||||
assert "Exception" in theMessage
|
assert "Exception" in theMessage
|
||||||
assert "(1.2.3)" in theMessage
|
assert "(1.2.3)" in theMessage
|
||||||
monkeypatch.undo()
|
monkeypatch.undo()
|
||||||
|
|
||||||
# No kernel version retrieved
|
# No kernel version retrieved
|
||||||
monkeypatch.setattr("PyQt5.QtCore.QSysInfo.kernelVersion", causeException)
|
monkeypatch.setattr("PyQt5.QtCore.QSysInfo.kernelVersion", causeException)
|
||||||
theMessage = exceptionHandler(Exception, "Third Error", None, testMode=True)
|
nwErr.setMessage(Exception, "Almost Fine Error", None)
|
||||||
|
theMessage = nwErr.msgBody.toPlainText()
|
||||||
assert theMessage
|
assert theMessage
|
||||||
assert "Third Error" in theMessage
|
|
||||||
assert "Exception" in theMessage
|
|
||||||
assert "(Unknown)" in theMessage
|
assert "(Unknown)" in theMessage
|
||||||
monkeypatch.undo()
|
monkeypatch.undo()
|
||||||
|
|
||||||
# Normal shutdown, but not testmode
|
nwErr._doClose()
|
||||||
|
nwErr.close()
|
||||||
|
nwGUI.closeMain()
|
||||||
|
|
||||||
|
# END Test testBaseError_Dialog
|
||||||
|
|
||||||
|
@pytest.mark.base
|
||||||
|
def testBaseError_Handler(qtbot, monkeypatch, fncDir, tmpDir):
|
||||||
|
"""Test the error handler. This test doesn'thave any asserts, but it
|
||||||
|
checks that the error handler handles potential exceptions. The test
|
||||||
|
will fail if excpetions are not handled.
|
||||||
|
"""
|
||||||
|
qApp.closeAllWindows()
|
||||||
|
nwGUI = nw.main(["--testmode", "--config=%s" % fncDir, "--data=%s" % tmpDir])
|
||||||
|
qtbot.addWidget(nwGUI)
|
||||||
|
nwGUI.show()
|
||||||
|
qtbot.waitForWindowShown(nwGUI)
|
||||||
|
|
||||||
|
# Normal shutdown
|
||||||
monkeypatch.setattr("PyQt5.QtWidgets.qApp.exit", lambda x: None)
|
monkeypatch.setattr("PyQt5.QtWidgets.qApp.exit", lambda x: None)
|
||||||
nwGUI.mainConf.showGUI = True
|
nwGUI.mainConf.showGUI = True
|
||||||
exceptionHandler(Exception, "Third Error", None, testMode=False)
|
exceptionHandler(Exception, "Error Message", None)
|
||||||
nwGUI.mainConf.showGUI = False
|
nwGUI.mainConf.showGUI = False
|
||||||
monkeypatch.undo()
|
monkeypatch.undo()
|
||||||
|
|
||||||
# Disable blocking of GUI
|
# Disable blocking of GUI
|
||||||
monkeypatch.setattr("PyQt5.QtWidgets.QDialog.exec_", lambda: None)
|
monkeypatch.setattr("PyQt5.QtWidgets.QDialog.exec_", lambda: None)
|
||||||
exceptionHandler(Exception, "Third Error", None, testMode=True)
|
monkeypatch.setattr("PyQt5.QtWidgets.qApp.exit", lambda x: None)
|
||||||
|
exceptionHandler(Exception, "Error Message", None)
|
||||||
monkeypatch.undo()
|
monkeypatch.undo()
|
||||||
|
|
||||||
# Should handle qApp failing
|
# Should handle qApp failing
|
||||||
monkeypatch.setattr("PyQt5.QtWidgets.qApp.topLevelWidgets", causeException)
|
monkeypatch.setattr("PyQt5.QtWidgets.qApp.topLevelWidgets", causeException)
|
||||||
exceptionHandler(Exception, "Third Error", None, testMode=True)
|
monkeypatch.setattr("PyQt5.QtWidgets.qApp.exit", lambda x: None)
|
||||||
|
exceptionHandler(Exception, "Error Message", None)
|
||||||
monkeypatch.undo()
|
monkeypatch.undo()
|
||||||
|
|
||||||
# Should handle failing to close main GUI
|
# Should handle failing to close main GUI
|
||||||
monkeypatch.setattr(nwGUI, "closeMain", causeException)
|
monkeypatch.setattr(nwGUI, "closeMain", causeException)
|
||||||
exceptionHandler(Exception, "Third Error", None, testMode=True)
|
monkeypatch.setattr("PyQt5.QtWidgets.qApp.exit", lambda x: None)
|
||||||
|
exceptionHandler(Exception, "Error Message", None)
|
||||||
monkeypatch.undo()
|
monkeypatch.undo()
|
||||||
|
|
||||||
# Should not crash when no GUI is found
|
# Should not crash when no GUI is found
|
||||||
nwGUI.setObjectName("Stuff")
|
monkeypatch.setattr("PyQt5.QtWidgets.qApp.topLevelWidgets", lambda: [])
|
||||||
assert exceptionHandler(Exception, "Third Error", None, testMode=True) is None
|
monkeypatch.setattr("PyQt5.QtWidgets.qApp.exit", lambda x: None)
|
||||||
|
exceptionHandler(Exception, "Error Message", None)
|
||||||
|
monkeypatch.undo()
|
||||||
|
|
||||||
nwGUI.closeMain()
|
nwGUI.closeMain()
|
||||||
|
|
||||||
# qtbot.stopForInteraction()
|
# END Test testBaseError_Handler
|
||||||
|
|
||||||
# END Test testBaseError_Dialog
|
|
||||||
|
|||||||
Reference in New Issue
Block a user