diff --git a/.github/workflows/test_linux_3.8.yml b/.github/workflows/test_linux_3.8.yml
index 502de464..dd27ce70 100644
--- a/.github/workflows/test_linux_3.8.yml
+++ b/.github/workflows/test_linux_3.8.yml
@@ -32,6 +32,6 @@ jobs:
- name: Run Tests
run: |
export QT_QPA_PLATFORM=offscreen
- pytest -v --timeout=60
+ pytest -v --cov-nw --timeout=60
- name: Upload to Codecov
uses: codecov/codecov-action@v1
diff --git a/.github/workflows/test_mac.yml b/.github/workflows/test_mac.yml
index 0478bf71..d409f81e 100644
--- a/.github/workflows/test_mac.yml
+++ b/.github/workflows/test_mac.yml
@@ -31,6 +31,6 @@ jobs:
- name: Run Tests
run: |
export QT_QPA_PLATFORM=offscreen
- pytest -v --timeout=60
+ pytest -v --cov-nw --timeout=60
- name: Upload to Codecov
uses: codecov/codecov-action@v1
diff --git a/.github/workflows/test_win.yml b/.github/workflows/test_win.yml
index aa9ef284..ebdee693 100644
--- a/.github/workflows/test_win.yml
+++ b/.github/workflows/test_win.yml
@@ -27,6 +27,6 @@ jobs:
pip install codecov
- name: Run Tests
run: |
- pytest -v --timeout=60
+ pytest -v --cov-nw --timeout=60
- name: Upload to Codecov
uses: codecov/codecov-action@v1
diff --git a/nw/__init__.py b/nw/__init__.py
index 199d20ca..aa755a2e 100644
--- a/nw/__init__.py
+++ b/nw/__init__.py
@@ -28,7 +28,6 @@
import sys
import getopt
import logging
-import os
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QApplication, QErrorMessage
@@ -158,12 +157,12 @@ def main(sysArgs=None):
for inOpt, inArg in inOpts:
if inOpt in ("-h", "--help"):
print(helpMsg)
- sys.exit()
+ sys.exit(0)
elif inOpt in ("-v", "--version"):
print("novelWriter %s Version %s [%s]" % (
__status__, __version__, __date__)
)
- sys.exit()
+ sys.exit(0)
elif inOpt == "--info":
debugLevel = logging.INFO
elif inOpt == "--debug":
@@ -224,19 +223,20 @@ def main(sysArgs=None):
errorData.append("Python module 'lxml' is missing.")
if errorData:
- errApp = QApplication([])
- errMsg = QErrorMessage()
- errMsg.resize(500, 300)
- errMsg.showMessage((
- "
A critical error has been encountered
"
- "novelWriter cannot start due to the following issues:
"
- "
- %s
"
- "Shutting down ...
"
- ) % (
- "
- ".join(errorData)
- ))
- errApp.exec_()
- sys.exit(1)
+ if not testMode:
+ errApp = QApplication([])
+ errMsg = QErrorMessage()
+ errMsg.resize(500, 300)
+ errMsg.showMessage((
+ "A critical error has been encountered
"
+ "novelWriter cannot start due to the following issues:
"
+ "
- %s
"
+ "Shutting down ...
"
+ ) % (
+ "
- ".join(errorData)
+ ))
+ errApp.exec_()
+ sys.exit(10 + len(errorData))
# Finish initialising config
CONFIG.initConfig(confPath, dataPath)
diff --git a/tests/test_gui.py b/tests/test_gui.py
index 0334cf2d..3bffd372 100644
--- a/tests/test_gui.py
+++ b/tests/test_gui.py
@@ -6,6 +6,7 @@ import nw
import pytest
import logging
import os
+import sys
from shutil import copyfile
from nwtools import cmpFiles
@@ -25,16 +26,17 @@ typeDelay = 1
stepDelay = 20
@pytest.mark.gui
-def testLaunch(qtbot, nwFuncTemp, nwTemp):
+def testLaunch(qtbot, monkeypatch, nwFuncTemp, nwTemp):
- # Log Levels
+ # Defaults
nwGUI = nw.main(
- ["--testmode", "--config=%s" % nwFuncTemp, "--data=%s" % nwTemp]
+ ["--testmode", "--config=%s" % nwFuncTemp, "--data=%s" % nwTemp, "--style=Fusion"]
)
assert nw.logger.getEffectiveLevel() == logging.WARNING
nwGUI.closeMain()
nwGUI.close()
+ # Log Levels
nwGUI = nw.main(
["--testmode", "--info", "--config=%s" % nwFuncTemp, "--data=%s" % nwTemp]
)
@@ -56,20 +58,46 @@ def testLaunch(qtbot, nwFuncTemp, nwTemp):
nwGUI.closeMain()
nwGUI.close()
- # Other options
- with pytest.raises(SystemExit):
+ # Help and Version
+ with pytest.raises(SystemExit) as ex:
nwGUI = nw.main(
["--testmode", "--help", "--config=%s" % nwFuncTemp, "--data=%s" % nwTemp]
)
nwGUI.closeMain()
nwGUI.close()
+ assert ex.value.code == 0
- with pytest.raises(SystemExit):
+ with pytest.raises(SystemExit) as ex:
+ nwGUI = nw.main(
+ ["--testmode", "--version", "--config=%s" % nwFuncTemp, "--data=%s" % nwTemp]
+ )
+ nwGUI.closeMain()
+ nwGUI.close()
+ assert ex.value.code == 0
+
+ # Invalid options
+ with pytest.raises(SystemExit) as ex:
nwGUI = nw.main(
["--testmode", "--invalid", "--config=%s" % nwFuncTemp, "--data=%s" % nwTemp]
)
nwGUI.closeMain()
nwGUI.close()
+ assert ex.value.code == 2
+
+ # Simulate import error
+ monkeypatch.setitem(sys.modules, "PyQt5.QtSvg", None)
+ monkeypatch.setitem(sys.modules, "lxml", None)
+ monkeypatch.setattr("sys.hexversion", 0x0)
+ monkeypatch.setattr("nw.CONFIG.verQtValue", 50000)
+ monkeypatch.setattr("nw.CONFIG.verPyQtValue", 50000)
+ with pytest.raises(SystemExit) as ex:
+ nwGUI = nw.main(
+ ["--testmode", "--config=%s" % nwFuncTemp, "--data=%s" % nwTemp]
+ )
+ nwGUI.closeMain()
+ nwGUI.close()
+ assert ex.value.code == 15
+ monkeypatch.undo()
@pytest.mark.gui
def testDocEditor(qtbot, yesToAll, nwFuncTemp, nwTempGUI, nwRef, nwTemp):