Moved the launch test from main to init

This commit is contained in:
Veronica K. B. Olsen
2020-12-06 13:27:31 +01:00
parent cdeee65505
commit ee7a5e1681
2 changed files with 87 additions and 78 deletions
+87
View File
@@ -0,0 +1,87 @@
# -*- coding: utf-8 -*-
"""novelWriter Main Init Tester
"""
import nw
import pytest
import logging
import sys
@pytest.mark.base
def testBaseInit_Launch(qtbot, monkeypatch, fncDir, tmpDir):
"""Test the main __init__.py file.
"""
# Defaults
nwGUI = nw.main(
["--testmode", "--config=%s" % fncDir, "--data=%s" % tmpDir, "--style=Fusion"]
)
assert nw.logger.getEffectiveLevel() == logging.WARNING
nwGUI.closeMain()
nwGUI.close()
# Log Levels
nwGUI = nw.main(
["--testmode", "--info", "--config=%s" % fncDir, "--data=%s" % tmpDir]
)
assert nw.logger.getEffectiveLevel() == logging.INFO
nwGUI.closeMain()
nwGUI.close()
nwGUI = nw.main(
["--testmode", "--debug", "--config=%s" % fncDir, "--data=%s" % tmpDir]
)
assert nw.logger.getEffectiveLevel() == logging.DEBUG
nwGUI.closeMain()
nwGUI.close()
nwGUI = nw.main(
["--testmode", "--verbose", "--config=%s" % fncDir, "--data=%s" % tmpDir]
)
assert nw.logger.getEffectiveLevel() == 5
nwGUI.closeMain()
nwGUI.close()
# Help and Version
with pytest.raises(SystemExit) as ex:
nwGUI = nw.main(
["--testmode", "--help", "--config=%s" % fncDir, "--data=%s" % tmpDir]
)
nwGUI.closeMain()
nwGUI.close()
assert ex.value.code == 0
with pytest.raises(SystemExit) as ex:
nwGUI = nw.main(
["--testmode", "--version", "--config=%s" % fncDir, "--data=%s" % tmpDir]
)
nwGUI.closeMain()
nwGUI.close()
assert ex.value.code == 0
# Invalid options
with pytest.raises(SystemExit) as ex:
nwGUI = nw.main(
["--testmode", "--invalid", "--config=%s" % fncDir, "--data=%s" % tmpDir]
)
nwGUI.closeMain()
nwGUI.close()
assert ex.value.code == 2
# Simulate import error
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" % fncDir, "--data=%s" % tmpDir]
)
nwGUI.closeMain()
nwGUI.close()
assert ex.value.code & 4 == 4 # Python version not satisfied
assert ex.value.code & 8 == 8 # Qt version not satisfied
assert ex.value.code & 16 == 16 # PyQt version not satisfied
assert ex.value.code & 32 == 32 # lxml package missing
monkeypatch.undo()
# END Test testBaseInit_Launch
-78
View File
@@ -4,9 +4,7 @@
import nw
import pytest
import logging
import os
import sys
from shutil import copyfile
from tools import cmpFiles
@@ -26,82 +24,6 @@ keyDelay = 2
typeDelay = 1
stepDelay = 20
@pytest.mark.gui
def testLaunch(qtbot, monkeypatch, fncDir, tmpDir):
# Defaults
nwGUI = nw.main(
["--testmode", "--config=%s" % fncDir, "--data=%s" % tmpDir, "--style=Fusion"]
)
assert nw.logger.getEffectiveLevel() == logging.WARNING
nwGUI.closeMain()
nwGUI.close()
# Log Levels
nwGUI = nw.main(
["--testmode", "--info", "--config=%s" % fncDir, "--data=%s" % tmpDir]
)
assert nw.logger.getEffectiveLevel() == logging.INFO
nwGUI.closeMain()
nwGUI.close()
nwGUI = nw.main(
["--testmode", "--debug", "--config=%s" % fncDir, "--data=%s" % tmpDir]
)
assert nw.logger.getEffectiveLevel() == logging.DEBUG
nwGUI.closeMain()
nwGUI.close()
nwGUI = nw.main(
["--testmode", "--verbose", "--config=%s" % fncDir, "--data=%s" % tmpDir]
)
assert nw.logger.getEffectiveLevel() == 5
nwGUI.closeMain()
nwGUI.close()
# Help and Version
with pytest.raises(SystemExit) as ex:
nwGUI = nw.main(
["--testmode", "--help", "--config=%s" % fncDir, "--data=%s" % tmpDir]
)
nwGUI.closeMain()
nwGUI.close()
assert ex.value.code == 0
with pytest.raises(SystemExit) as ex:
nwGUI = nw.main(
["--testmode", "--version", "--config=%s" % fncDir, "--data=%s" % tmpDir]
)
nwGUI.closeMain()
nwGUI.close()
assert ex.value.code == 0
# Invalid options
with pytest.raises(SystemExit) as ex:
nwGUI = nw.main(
["--testmode", "--invalid", "--config=%s" % fncDir, "--data=%s" % tmpDir]
)
nwGUI.closeMain()
nwGUI.close()
assert ex.value.code == 2
# Simulate import error
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" % fncDir, "--data=%s" % tmpDir]
)
nwGUI.closeMain()
nwGUI.close()
assert ex.value.code & 4 == 4 # Python version not satisfied
assert ex.value.code & 8 == 8 # Qt version not satisfied
assert ex.value.code & 16 == 16 # PyQt version not satisfied
assert ex.value.code & 32 == 32 # lxml package missing
monkeypatch.undo()
@pytest.mark.gui
def testDocEditor(qtbot, yesToAll, fncDir, nwTempGUI, refDir, tmpDir):