Cover missing lines in error module

This commit is contained in:
Veronica Berglyd Olsen
2024-10-31 00:18:16 +01:00
parent ca2b509d54
commit f2e36d9974
+11 -2
View File
@@ -20,6 +20,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
""" """
from __future__ import annotations from __future__ import annotations
import sys
import pytest import pytest
from novelwriter.error import NWErrorMessage, exceptionHandler from novelwriter.error import NWErrorMessage, exceptionHandler
@@ -29,8 +31,7 @@ from tests.mocked import causeException
@pytest.mark.base @pytest.mark.base
def testBaseError_Dialog(qtbot, monkeypatch, nwGUI): def testBaseError_Dialog(qtbot, monkeypatch, nwGUI):
"""Test the error dialog. """Test the error dialog."""
"""
nwErr = NWErrorMessage(nwGUI) nwErr = NWErrorMessage(nwGUI)
qtbot.addWidget(nwErr) qtbot.addWidget(nwErr)
nwErr.show() nwErr.show()
@@ -57,6 +58,14 @@ def testBaseError_Dialog(qtbot, monkeypatch, nwGUI):
assert message != "" assert message != ""
assert "(Unknown)" in message assert "(Unknown)" in message
# No enchant version retrieved
with monkeypatch.context() as mp:
mp.setitem(sys.modules, "enchant", None)
nwErr.setMessage(Exception, "Almost Fine Error", None) # type: ignore
message = nwErr.msgBody.toPlainText()
assert message != ""
assert "enchant: Unknown" in message
nwErr._doClose() nwErr._doClose()
nwErr.close() nwErr.close()
nwGUI.closeMain() nwGUI.closeMain()