All message box questions are now handled in test suite, so no need to check for showGUI

This commit is contained in:
Veronica K. B. Olsen
2020-09-28 22:22:29 +02:00
parent 678a31855f
commit 28ef1d12b0
8 changed files with 207 additions and 113 deletions
+23 -1
View File
@@ -9,7 +9,7 @@ import shutil
from os import path, mkdir
from nwdummy import DummyMain
from PyQt5.QtWidgets import QFileDialog, QMessageBox
from PyQt5.QtWidgets import QMessageBox
sys.path.insert(1, path.abspath(path.join(path.dirname(__file__), path.pardir)))
@@ -178,3 +178,25 @@ def nwOldProj(nwTemp):
if path.isdir(oldProjDir):
shutil.rmtree(oldProjDir)
return
##
# Monkey Patch Dialogs
##
@pytest.fixture(scope="function")
def yesToAll(monkeypatch):
"""Make the message boxes/questions always say yes to the dress!
"""
monkeypatch.setattr(
QMessageBox, "question", lambda *args, **kwargs: QMessageBox.Yes
)
monkeypatch.setattr(
QMessageBox, "information", lambda *args, **kwargs: QMessageBox.Yes
)
monkeypatch.setattr(
QMessageBox, "warning", lambda *args, **kwargs: QMessageBox.Yes
)
monkeypatch.setattr(
QMessageBox, "critical", lambda *args, **kwargs: QMessageBox.Yes
)
return
+52 -11
View File
@@ -29,7 +29,7 @@ keyDelay = 2
stepDelay = 20
@pytest.mark.gui
def testProjectSettings(qtbot, monkeypatch, nwFuncTemp, nwTempGUI, nwRef, nwTemp):
def testProjectSettings(qtbot, monkeypatch, yesToAll, nwFuncTemp, nwTempGUI, nwRef, nwTemp):
nwGUI = nw.main(["--testmode", "--config=%s" % nwFuncTemp, "--data=%s" % nwTemp])
qtbot.addWidget(nwGUI)
nwGUI.show()
@@ -139,7 +139,7 @@ def testProjectSettings(qtbot, monkeypatch, nwFuncTemp, nwTempGUI, nwRef, nwTemp
nwGUI.closeMain()
@pytest.mark.gui
def testItemEditor(qtbot, nwFuncTemp, nwTempGUI, nwRef, nwTemp):
def testItemEditor(qtbot, yesToAll, nwFuncTemp, nwTempGUI, nwRef, nwTemp):
nwGUI = nw.main(["--testmode", "--config=%s" % nwFuncTemp, "--data=%s" % nwTemp])
qtbot.addWidget(nwGUI)
nwGUI.show()
@@ -198,7 +198,7 @@ def testItemEditor(qtbot, nwFuncTemp, nwTempGUI, nwRef, nwTemp):
# qtbot.stopForInteraction()
@pytest.mark.gui
def testWritingStatsExport(qtbot, nwFuncTemp, nwTemp):
def testWritingStatsExport(qtbot, yesToAll, nwFuncTemp, nwTemp):
nwGUI = nw.main(["--testmode", "--config=%s" % nwFuncTemp, "--data=%s" % nwTemp])
qtbot.addWidget(nwGUI)
nwGUI.show()
@@ -385,7 +385,7 @@ def testAboutBox(qtbot, monkeypatch, nwFuncTemp, nwTemp):
nwGUI.closeMain()
@pytest.mark.gui
def testBuildTool(qtbot, nwTempBuild, nwLipsum, nwRef, nwTemp):
def testBuildTool(qtbot, yesToAll, nwTempBuild, nwLipsum, nwRef, nwTemp):
nwGUI = nw.main(["--testmode", "--config=%s" % nwLipsum, "--data=%s" % nwTemp])
qtbot.addWidget(nwGUI)
@@ -547,7 +547,7 @@ def testBuildTool(qtbot, nwTempBuild, nwLipsum, nwRef, nwTemp):
nwGUI.closeMain()
@pytest.mark.gui
def testMergeSplitTools(qtbot, monkeypatch, nwTempGUI, nwLipsum, nwRef, nwTemp):
def testMergeSplitTools(qtbot, monkeypatch, yesToAll, nwTempGUI, nwLipsum, nwRef, nwTemp):
nwGUI = nw.main(["--testmode", "--config=%s" % nwLipsum, "--data=%s" % nwTemp])
qtbot.addWidget(nwGUI)
@@ -690,7 +690,7 @@ def testMergeSplitTools(qtbot, monkeypatch, nwTempGUI, nwLipsum, nwRef, nwTemp):
nwGUI.closeMain()
@pytest.mark.gui
def testNewProjectWizard(qtbot, nwLipsum, nwTemp):
def testNewProjectWizard(qtbot, monkeypatch, yesToAll, nwMinimal, nwTemp):
from PyQt5.QtWidgets import QWizard
from nw.gui.projwizard import (
@@ -698,7 +698,47 @@ def testNewProjectWizard(qtbot, nwLipsum, nwTemp):
ProjWizardCustomPage, ProjWizardFinalPage
)
nwGUI = nw.main(["--testmode", "--config=%s" % nwLipsum, "--data=%s" % nwTemp])
nwGUI = nw.main(["--testmode", "--config=%s" % nwMinimal, "--data=%s" % nwTemp])
qtbot.addWidget(nwGUI)
nwGUI.show()
qtbot.waitForWindowShown(nwGUI)
qtbot.wait(stepDelay)
##
# Test New Project Function
##
# New with a project open should cause an error
assert nwGUI.openProject(nwMinimal)
assert not nwGUI.newProject()
# Close project, but call with invalid path
assert nwGUI.closeProject()
monkeypatch.setattr(nwGUI, "showNewProjectDialog", lambda *args: None)
assert not nwGUI.newProject()
# Now, with an empty dictionary
monkeypatch.setattr(nwGUI, "showNewProjectDialog", lambda *args: {})
assert not nwGUI.newProject()
# Now, with a non-empty folder
monkeypatch.setattr(nwGUI, "showNewProjectDialog", lambda *args: {"projPath": nwMinimal})
assert not nwGUI.newProject()
# Force overwrite
monkeypatch.setattr(nwGUI, "showNewProjectDialog", lambda *args: {"projPath": nwMinimal})
assert nwGUI.newProject(forceNew=True)
nwGUI.closeMain()
nwGUI.close()
# qtbot.stopForInteraction()
##
# Test the Wizard
##
nwGUI = nw.main(["--testmode", "--config=%s" % nwMinimal, "--data=%s" % nwTemp])
qtbot.addWidget(nwGUI)
nwGUI.show()
qtbot.waitForWindowShown(nwGUI)
@@ -817,9 +857,10 @@ def testNewProjectWizard(qtbot, nwLipsum, nwTemp):
# qtbot.stopForInteraction()
nwGUI.closeMain()
nwGUI.close()
@pytest.mark.gui
def testLoadProject(qtbot, monkeypatch, nwMinimal, nwTemp):
def testLoadProject(qtbot, monkeypatch, yesToAll, nwMinimal, nwTemp):
nwGUI = nw.main(["--testmode", "--config=%s" % nwMinimal, "--data=%s" % nwTemp])
qtbot.addWidget(nwGUI)
nwGUI.show()
@@ -877,7 +918,7 @@ def testLoadProject(qtbot, monkeypatch, nwMinimal, nwTemp):
nwGUI.closeMain()
@pytest.mark.gui
def testPreferences(qtbot, monkeypatch, nwMinimal, nwTemp, nwRef, tmpConf):
def testPreferences(qtbot, monkeypatch, yesToAll, nwMinimal, nwTemp, nwRef, tmpConf):
nwGUI = nw.main(["--testmode", "--config=%s" % nwMinimal, "--data=%s" % nwTemp])
qtbot.addWidget(nwGUI)
nwGUI.show()
@@ -1034,7 +1075,7 @@ def testPreferences(qtbot, monkeypatch, nwMinimal, nwTemp, nwRef, tmpConf):
assert cmpFiles(testConf, refConf, ignoreLines)
@pytest.mark.gui
def testQuotesDialog(qtbot, nwMinimal, nwTemp):
def testQuotesDialog(qtbot, yesToAll, nwMinimal, nwTemp):
nwGUI = nw.main(["--testmode", "--config=%s" % nwMinimal, "--data=%s" % nwTemp, nwMinimal])
qtbot.addWidget(nwGUI)
nwGUI.show()
@@ -1064,7 +1105,7 @@ def testQuotesDialog(qtbot, nwMinimal, nwTemp):
nwGUI.close()
@pytest.mark.gui
def testDialogsOpenClose(qtbot, monkeypatch, nwMinimal, nwTemp):
def testDialogsOpenClose(qtbot, monkeypatch, yesToAll, nwMinimal, nwTemp):
nwGUI = nw.main(["--testmode", "--config=%s" % nwMinimal, "--data=%s" % nwTemp, nwMinimal])
qtbot.addWidget(nwGUI)
nwGUI.show()
+54 -11
View File
@@ -88,7 +88,7 @@ def testLaunch(qtbot, nwFuncTemp, nwTemp):
nwGUI.close()
@pytest.mark.gui
def testDocEditor(qtbot, nwFuncTemp, nwTempGUI, nwRef, nwTemp):
def testDocEditor(qtbot, yesToAll, nwFuncTemp, nwTempGUI, nwRef, nwTemp):
nwGUI = nw.main(["--testmode", "--config=%s" % nwFuncTemp, "--data=%s" % nwTemp])
qtbot.addWidget(nwGUI)
@@ -392,7 +392,7 @@ def testDocEditor(qtbot, nwFuncTemp, nwTempGUI, nwRef, nwTemp):
nwGUI.close()
@pytest.mark.gui
def testDocViewer(qtbot, nwLipsum, nwTemp):
def testDocViewer(qtbot, yesToAll, nwLipsum, nwTemp):
nwGUI = nw.main(["--testmode", "--config=%s" % nwLipsum, "--data=%s" % nwTemp])
qtbot.addWidget(nwGUI)
@@ -544,7 +544,7 @@ def testDocViewer(qtbot, nwLipsum, nwTemp):
nwGUI.close()
@pytest.mark.gui
def testProjectTree(qtbot, nwMinimal, nwTemp):
def testProjectTree(qtbot, yesToAll, nwMinimal, nwTemp):
nwGUI = nw.main(["--testmode", "--config=%s" % nwMinimal, "--data=%s" % nwTemp, nwMinimal])
qtbot.addWidget(nwGUI)
@@ -678,7 +678,7 @@ def testProjectTree(qtbot, nwMinimal, nwTemp):
nwGUI.close()
@pytest.mark.gui
def testEditFormatMenu(qtbot, nwLipsum, nwTemp):
def testEditFormatMenu(qtbot, yesToAll, nwLipsum, nwTemp):
nwGUI = nw.main(["--testmode", "--config=%s" % nwLipsum, "--data=%s" % nwTemp])
qtbot.addWidget(nwGUI)
@@ -915,7 +915,7 @@ def testEditFormatMenu(qtbot, nwLipsum, nwTemp):
nwGUI.close()
@pytest.mark.gui
def testContextMenu(qtbot, nwLipsum, nwTemp):
def testContextMenu(qtbot, yesToAll, nwLipsum, nwTemp):
nwGUI = nw.main(["--testmode", "--config=%s" % nwLipsum, "--data=%s" % nwTemp])
qtbot.addWidget(nwGUI)
@@ -1087,7 +1087,9 @@ def testInsertMenu(qtbot, monkeypatch, nwFuncTemp, nwTemp):
assert nwGUI.docEditor.getText() == " "
nwGUI.docEditor.clear()
# Insert text from file
##
# Insert text from file
##
nwGUI.closeDocument()
# First, with no path
@@ -1123,12 +1125,33 @@ def testInsertMenu(qtbot, monkeypatch, nwFuncTemp, nwTemp):
nwGUI.mainMenu.aImportFile.activate(QAction.Trigger)
assert nwGUI.docEditor.getText() == "Foo"
##
# Reveal file location
##
theMessage = ""
def recordMsg(*args):
nonlocal theMessage
theMessage = args[3]
return None
assert not theMessage
monkeypatch.setattr(QMessageBox, "information", recordMsg)
nwGUI.mainMenu.aFileDetails.activate(QAction.Trigger)
theBits = theMessage.split("<br>")
assert len(theBits) == 3
assert theBits[0] == "File details for the currently open file"
assert theBits[1] == "Handle: 0e17daca5f3e1"
assert theBits[2] == "Location: %s" % path.join(nwFuncTemp, "content", "0e17daca5f3e1.nwd")
# qtbot.stopForInteraction()
nwGUI.closeMain()
nwGUI.close()
@pytest.mark.gui
def testTextSearch(qtbot, nwLipsum, nwTemp):
def testTextSearch(qtbot, monkeypatch, yesToAll, nwLipsum, nwTemp):
nwGUI = nw.main(["--testmode", "--config=%s" % nwLipsum, "--data=%s" % nwTemp])
qtbot.addWidget(nwGUI)
@@ -1153,8 +1176,9 @@ def testTextSearch(qtbot, nwLipsum, nwTemp):
assert nwGUI.docEditor.docSearch.isVisible()
assert nwGUI.docEditor.docSearch.getSearchText() == "est"
# Find Next by Menu
nwGUI.mainMenu.aFindNext.activate(QAction.Trigger)
# Find Next by Enter
monkeypatch.setattr(nwGUI.docEditor.docSearch.searchBox, "hasFocus", lambda: True)
qtbot.keyClick(nwGUI.docEditor.docSearch.searchBox, Qt.Key_Return, delay=keyDelay)
assert abs(nwGUI.docEditor.getCursorPosition() - 1272) < 3
# Find Next by Button
@@ -1283,12 +1307,31 @@ def testTextSearch(qtbot, nwLipsum, nwTemp):
nwGUI.mainMenu.aFindNext.activate(QAction.Trigger)
assert abs(nwGUI.docEditor.getCursorPosition() - 1127) < 3
# Toggle Replace
nwGUI.docEditor._beginReplace()
# MonkeyPatch the focus cycle. We can't really test this very well, other than
# check that the tabs aren't captured when the main editor has focus
monkeypatch.setattr(nwGUI.docEditor, "hasFocus", lambda: True)
monkeypatch.setattr(nwGUI.docEditor.docSearch.searchBox, "hasFocus", lambda: False)
monkeypatch.setattr(nwGUI.docEditor.docSearch.replaceBox, "hasFocus", lambda: False)
assert not nwGUI.docEditor.focusNextPrevChild(True)
monkeypatch.setattr(nwGUI.docEditor, "hasFocus", lambda: False)
monkeypatch.setattr(nwGUI.docEditor.docSearch.searchBox, "hasFocus", lambda: True)
monkeypatch.setattr(nwGUI.docEditor.docSearch.replaceBox, "hasFocus", lambda: False)
assert nwGUI.docEditor.focusNextPrevChild(True)
monkeypatch.setattr(nwGUI.docEditor.docSearch.searchBox, "hasFocus", lambda: False)
monkeypatch.setattr(nwGUI.docEditor.docSearch.replaceBox, "hasFocus", lambda: True)
assert nwGUI.docEditor.focusNextPrevChild(True)
# qtbot.stopForInteraction()
nwGUI.closeMain()
nwGUI.close()
@pytest.mark.gui
def testOutline(qtbot, nwLipsum, nwTemp):
def testOutline(qtbot, yesToAll, nwLipsum, nwTemp):
nwGUI = nw.main(["--testmode", "--config=%s" % nwLipsum, "--data=%s" % nwTemp])
qtbot.addWidget(nwGUI)
@@ -1349,7 +1392,7 @@ def testOutline(qtbot, nwLipsum, nwTemp):
nwGUI.close()
@pytest.mark.gui
def testThemes(qtbot, nwMinimal, nwTemp):
def testThemes(qtbot, yesToAll, nwMinimal, nwTemp):
nwGUI = nw.main(["--testmode", "--config=%s" % nwMinimal, "--data=%s" % nwTemp, nwMinimal])
qtbot.addWidget(nwGUI)