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
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
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
+16 -16
View File
@@ -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((
"<h3>A critical error has been encountered</h3>"
"<p>novelWriter cannot start due to the following issues:<p>"
"<p>&nbsp;-&nbsp;%s</p>"
"<p>Shutting down ...</p>"
) % (
"<br>&nbsp;-&nbsp;".join(errorData)
))
errApp.exec_()
sys.exit(1)
if not testMode:
errApp = QApplication([])
errMsg = QErrorMessage()
errMsg.resize(500, 300)
errMsg.showMessage((
"<h3>A critical error has been encountered</h3>"
"<p>novelWriter cannot start due to the following issues:<p>"
"<p>&nbsp;-&nbsp;%s</p>"
"<p>Shutting down ...</p>"
) % (
"<br>&nbsp;-&nbsp;".join(errorData)
))
errApp.exec_()
sys.exit(10 + len(errorData))
# Finish initialising config
CONFIG.initConfig(confPath, dataPath)
+34 -6
View File
@@ -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):