Fixed coverage in actions and updated launch test

This commit is contained in:
Veronica K. B. Olsen
2020-10-01 22:01:41 +02:00
parent d63c741cfe
commit 4b1c45ddb4
5 changed files with 53 additions and 25 deletions
+1 -1
View File
@@ -32,6 +32,6 @@ jobs:
- name: Run Tests - name: Run Tests
run: | run: |
export QT_QPA_PLATFORM=offscreen export QT_QPA_PLATFORM=offscreen
pytest -v --timeout=60 pytest -v --cov-nw --timeout=60
- name: Upload to Codecov - name: Upload to Codecov
uses: codecov/codecov-action@v1 uses: codecov/codecov-action@v1
+1 -1
View File
@@ -31,6 +31,6 @@ jobs:
- name: Run Tests - name: Run Tests
run: | run: |
export QT_QPA_PLATFORM=offscreen export QT_QPA_PLATFORM=offscreen
pytest -v --timeout=60 pytest -v --cov-nw --timeout=60
- name: Upload to Codecov - name: Upload to Codecov
uses: codecov/codecov-action@v1 uses: codecov/codecov-action@v1
+1 -1
View File
@@ -27,6 +27,6 @@ jobs:
pip install codecov pip install codecov
- name: Run Tests - name: Run Tests
run: | run: |
pytest -v --timeout=60 pytest -v --cov-nw --timeout=60
- name: Upload to Codecov - name: Upload to Codecov
uses: codecov/codecov-action@v1 uses: codecov/codecov-action@v1
+16 -16
View File
@@ -28,7 +28,6 @@
import sys import sys
import getopt import getopt
import logging import logging
import os
from PyQt5.QtGui import QIcon from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QApplication, QErrorMessage from PyQt5.QtWidgets import QApplication, QErrorMessage
@@ -158,12 +157,12 @@ def main(sysArgs=None):
for inOpt, inArg in inOpts: for inOpt, inArg in inOpts:
if inOpt in ("-h", "--help"): if inOpt in ("-h", "--help"):
print(helpMsg) print(helpMsg)
sys.exit() sys.exit(0)
elif inOpt in ("-v", "--version"): elif inOpt in ("-v", "--version"):
print("novelWriter %s Version %s [%s]" % ( print("novelWriter %s Version %s [%s]" % (
__status__, __version__, __date__) __status__, __version__, __date__)
) )
sys.exit() sys.exit(0)
elif inOpt == "--info": elif inOpt == "--info":
debugLevel = logging.INFO debugLevel = logging.INFO
elif inOpt == "--debug": elif inOpt == "--debug":
@@ -224,19 +223,20 @@ def main(sysArgs=None):
errorData.append("Python module 'lxml' is missing.") errorData.append("Python module 'lxml' is missing.")
if errorData: if errorData:
errApp = QApplication([]) if not testMode:
errMsg = QErrorMessage() errApp = QApplication([])
errMsg.resize(500, 300) errMsg = QErrorMessage()
errMsg.showMessage(( errMsg.resize(500, 300)
"<h3>A critical error has been encountered</h3>" errMsg.showMessage((
"<p>novelWriter cannot start due to the following issues:<p>" "<h3>A critical error has been encountered</h3>"
"<p>&nbsp;-&nbsp;%s</p>" "<p>novelWriter cannot start due to the following issues:<p>"
"<p>Shutting down ...</p>" "<p>&nbsp;-&nbsp;%s</p>"
) % ( "<p>Shutting down ...</p>"
"<br>&nbsp;-&nbsp;".join(errorData) ) % (
)) "<br>&nbsp;-&nbsp;".join(errorData)
errApp.exec_() ))
sys.exit(1) errApp.exec_()
sys.exit(10 + len(errorData))
# Finish initialising config # Finish initialising config
CONFIG.initConfig(confPath, dataPath) CONFIG.initConfig(confPath, dataPath)
+34 -6
View File
@@ -6,6 +6,7 @@ import nw
import pytest import pytest
import logging import logging
import os import os
import sys
from shutil import copyfile from shutil import copyfile
from nwtools import cmpFiles from nwtools import cmpFiles
@@ -25,16 +26,17 @@ typeDelay = 1
stepDelay = 20 stepDelay = 20
@pytest.mark.gui @pytest.mark.gui
def testLaunch(qtbot, nwFuncTemp, nwTemp): def testLaunch(qtbot, monkeypatch, nwFuncTemp, nwTemp):
# Log Levels # Defaults
nwGUI = nw.main( 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 assert nw.logger.getEffectiveLevel() == logging.WARNING
nwGUI.closeMain() nwGUI.closeMain()
nwGUI.close() nwGUI.close()
# Log Levels
nwGUI = nw.main( nwGUI = nw.main(
["--testmode", "--info", "--config=%s" % nwFuncTemp, "--data=%s" % nwTemp] ["--testmode", "--info", "--config=%s" % nwFuncTemp, "--data=%s" % nwTemp]
) )
@@ -56,20 +58,46 @@ def testLaunch(qtbot, nwFuncTemp, nwTemp):
nwGUI.closeMain() nwGUI.closeMain()
nwGUI.close() nwGUI.close()
# Other options # Help and Version
with pytest.raises(SystemExit): with pytest.raises(SystemExit) as ex:
nwGUI = nw.main( nwGUI = nw.main(
["--testmode", "--help", "--config=%s" % nwFuncTemp, "--data=%s" % nwTemp] ["--testmode", "--help", "--config=%s" % nwFuncTemp, "--data=%s" % nwTemp]
) )
nwGUI.closeMain() nwGUI.closeMain()
nwGUI.close() 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( nwGUI = nw.main(
["--testmode", "--invalid", "--config=%s" % nwFuncTemp, "--data=%s" % nwTemp] ["--testmode", "--invalid", "--config=%s" % nwFuncTemp, "--data=%s" % nwTemp]
) )
nwGUI.closeMain() nwGUI.closeMain()
nwGUI.close() 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 @pytest.mark.gui
def testDocEditor(qtbot, yesToAll, nwFuncTemp, nwTempGUI, nwRef, nwTemp): def testDocEditor(qtbot, yesToAll, nwFuncTemp, nwTempGUI, nwRef, nwTemp):