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
+10 -11
View File
@@ -163,17 +163,16 @@ class GuiDocSplit(QDialog):
), nwAlert.ERROR) ), nwAlert.ERROR)
return return
if self.mainConf.showGUI: msgBox = QMessageBox()
msgBox = QMessageBox() msgRes = msgBox.question(
msgRes = msgBox.question( self, "Split Document", (
self, "Split Document", ( "The document will be split into %d file(s) in a new folder. "
"The document will be split into %d file(s) in a new folder. " "The original document will remain intact.<br><br>"
"The original document will remain intact.<br><br>" "Continue with the splitting process?"
"Continue with the splitting process?" ) % nFiles
) % nFiles )
) if msgRes != QMessageBox.Yes:
if msgRes != QMessageBox.Yes: return
return
# Create the folder # Create the folder
fHandle = self.theProject.newFolder( fHandle = self.theProject.newFolder(
+6 -12
View File
@@ -218,18 +218,12 @@ class GuiProjectLoad(QDialog):
""" """
selList = self.listBox.selectedItems() selList = self.listBox.selectedItems()
if selList: if selList:
doRemove = False msgBox = QMessageBox()
if self.mainConf.showGUI: msgRes = msgBox.question(
msgBox = QMessageBox() self, "Remove Entry",
msgRes = msgBox.question( "Remove the selected entry from the recent projects list?"
self, "Remove Entry", )
"Remove the selected entry from the recent projects list?" if msgRes == QMessageBox.Yes:
)
doRemove = (msgRes == QMessageBox.Yes)
else:
doRemove = True
if doRemove:
self.mainConf.removeFromRecentCache( self.mainConf.removeFromRecentCache(
selList[0].data(self.C_NAME, Qt.UserRole) selList[0].data(self.C_NAME, Qt.UserRole)
) )
+9 -10
View File
@@ -362,15 +362,14 @@ class GuiProjectTree(QTreeWidget):
self.makeAlert("The Trash folder is already empty.", nwAlert.INFO) self.makeAlert("The Trash folder is already empty.", nwAlert.INFO)
return False return False
if self.mainConf.showGUI: msgBox = QMessageBox()
msgBox = QMessageBox() msgRes = msgBox.question(
msgRes = msgBox.question( self, "Empty Trash", "Permanently delete %d file%s from Trash?" % (
self, "Empty Trash", "Permanently delete %d file%s from Trash?" % ( nTrash, "s" if nTrash > 1 else ""
nTrash, "s" if nTrash > 1 else ""
)
) )
if msgRes != QMessageBox.Yes: )
return False if msgRes != QMessageBox.Yes:
return False
logger.verbose("Deleting %d files from Trash" % nTrash) logger.verbose("Deleting %d files from Trash" % nTrash)
for tHandle in self.getTreeFromHandle(trashHandle): for tHandle in self.getTreeFromHandle(trashHandle):
@@ -416,7 +415,7 @@ class GuiProjectTree(QTreeWidget):
# If the file is in the trash folder already, as the # If the file is in the trash folder already, as the
# user if they want to permanently delete the file. # user if they want to permanently delete the file.
doPermanent = False doPermanent = False
if self.mainConf.showGUI and not alreadyAsked: if not alreadyAsked:
msgBox = QMessageBox() msgBox = QMessageBox()
msgRes = msgBox.question( msgRes = msgBox.question(
self, "Delete File", "Permanently delete file '%s'?" % nwItemS.itemName self, "Delete File", "Permanently delete file '%s'?" % nwItemS.itemName
@@ -445,7 +444,7 @@ class GuiProjectTree(QTreeWidget):
# The file is not already in the trash folder, so we # The file is not already in the trash folder, so we
# move it there. # move it there.
doTrash = False doTrash = False
if self.mainConf.showGUI and askForTrash: if askForTrash:
msgBox = QMessageBox() msgBox = QMessageBox()
msgRes = msgBox.question( msgRes = msgBox.question(
self, "Delete File", "Move file '%s' to Trash?" % nwItemS.itemName self, "Delete File", "Move file '%s' to Trash?" % nwItemS.itemName
+12 -13
View File
@@ -380,19 +380,18 @@ class GuiWritingStats(QDialog):
errMsg = str(e) errMsg = str(e)
# Report to user # Report to user
if self.mainConf.showGUI: if wSuccess:
if wSuccess: self.theParent.makeAlert(
self.theParent.makeAlert( "%s file successfully written to:<br> %s" % (
"%s file successfully written to:<br> %s" % ( textFmt, savePath
textFmt, savePath ), nwAlert.INFO
), nwAlert.INFO )
) else:
else: self.theParent.makeAlert(
self.theParent.makeAlert( "Failed to write %s file. %s" % (
"Failed to write %s file. %s" % ( textFmt, errMsg
textFmt, errMsg ), nwAlert.ERROR
), nwAlert.ERROR )
)
return True return True
+41 -44
View File
@@ -251,14 +251,13 @@ class GuiMain(QMainWindow):
The variable forceNew is used for testing. The variable forceNew is used for testing.
""" """
if self.hasProject: if self.hasProject:
msgBox = QMessageBox() self.makeAlert(
msgBox.warning( "Please close the current project before making a new one.",
self, "New Project", nwAlert.ERROR
"Please close the current project before making a new one."
) )
return False return False
if projData is None and self.mainConf.showGUI: if projData is None:
projData = self.showNewProjectDialog() projData = self.showNewProjectDialog()
if projData is None: if projData is None:
@@ -270,10 +269,9 @@ class GuiMain(QMainWindow):
return False return False
if path.isfile(path.join(projPath, self.theProject.projFile)) and not forceNew: if path.isfile(path.join(projPath, self.theProject.projFile)) and not forceNew:
msgBox = QMessageBox() self.makeAlert(
msgBox.critical( "A project already exists in that location. Please choose another folder.",
self, "New Project", nwAlert.ERROR
"A project already exists in that location. Please choose another folder."
) )
return False return False
@@ -299,7 +297,7 @@ class GuiMain(QMainWindow):
# There is no project loaded, everything OK # There is no project loaded, everything OK
return True return True
if self.mainConf.showGUI and not isYes: if not isYes:
msgBox = QMessageBox() msgBox = QMessageBox()
msgRes = msgBox.question( msgRes = msgBox.question(
self, "Close Project", "Save changes and close current project?" self, "Close Project", "Save changes and close current project?"
@@ -315,7 +313,7 @@ class GuiMain(QMainWindow):
doBackup = False doBackup = False
if self.theProject.doBackup and self.mainConf.backupOnClose: if self.theProject.doBackup and self.mainConf.backupOnClose:
doBackup = True doBackup = True
if self.mainConf.showGUI and self.mainConf.askBeforeBackup: if self.mainConf.askBeforeBackup:
msgBox = QMessageBox() msgBox = QMessageBox()
msgRes = msgBox.question( msgRes = msgBox.question(
self, "Backup Project", "Backup current project?" self, "Backup Project", "Backup current project?"
@@ -362,39 +360,38 @@ class GuiMain(QMainWindow):
# reason handled by the project class. # reason handled by the project class.
return False return False
if self.mainConf.showGUI: try:
try: lockDetails = (
lockDetails = ( "<br><br>The project was locked by the computer "
"<br><br>The project was locked by the computer " "'%s' (%s %s), last active on %s"
"'%s' (%s %s), last active on %s" ) % (
) % ( self.theProject.lockedBy[0],
self.theProject.lockedBy[0], self.theProject.lockedBy[1],
self.theProject.lockedBy[1], self.theProject.lockedBy[2],
self.theProject.lockedBy[2], datetime.fromtimestamp(
datetime.fromtimestamp( int(self.theProject.lockedBy[3])
int(self.theProject.lockedBy[3]) ).strftime("%x %X")
).strftime("%x %X")
)
except Exception:
lockDetails = ""
msgBox = QMessageBox()
msgRes = msgBox.warning(
self, "Project Locked", (
"The project is already open by another instance of novelWriter, and "
"is therefore locked. Override lock and continue anyway?<br><br>"
"Note: If the program or the computer previously crashed, the lock "
"can safely be overridden. If, however, another instance of "
"novelWriter has the project open, overriding the lock may corrupt "
"the project, and is not recommended.%s"
) % lockDetails,
QMessageBox.Yes | QMessageBox.No, QMessageBox.No
) )
if msgRes == QMessageBox.Yes: except Exception:
if not self.theProject.openProject(projFile, overrideLock=True): lockDetails = ""
return False
else: msgBox = QMessageBox()
msgRes = msgBox.warning(
self, "Project Locked", (
"The project is already open by another instance of novelWriter, and "
"is therefore locked. Override lock and continue anyway?<br><br>"
"Note: If the program or the computer previously crashed, the lock "
"can safely be overridden. If, however, another instance of "
"novelWriter has the project open, overriding the lock may corrupt "
"the project, and is not recommended.%s"
) % lockDetails,
QMessageBox.Yes | QMessageBox.No, QMessageBox.No
)
if msgRes == QMessageBox.Yes:
if not self.theProject.openProject(projFile, overrideLock=True):
return False return False
else:
return False
# Project is loaded # Project is loaded
self.hasProject = True self.hasProject = True
@@ -724,7 +721,7 @@ class GuiMain(QMainWindow):
qApp.restoreOverrideCursor() qApp.restoreOverrideCursor()
if self.mainConf.showGUI and not beQuiet: if not beQuiet:
self.makeAlert("The project index has been successfully rebuilt.", nwAlert.INFO) self.makeAlert("The project index has been successfully rebuilt.", nwAlert.INFO)
return True return True
@@ -909,7 +906,7 @@ class GuiMain(QMainWindow):
def closeMain(self): def closeMain(self):
"""Save everything, and close novelWriter. """Save everything, and close novelWriter.
""" """
if self.mainConf.showGUI and self.hasProject: if self.hasProject:
msgBox = QMessageBox() msgBox = QMessageBox()
msgRes = msgBox.question( msgRes = msgBox.question(
self, "Exit", "Do you want to save changes and exit?" self, "Exit", "Do you want to save changes and exit?"
+23 -1
View File
@@ -9,7 +9,7 @@ import shutil
from os import path, mkdir from os import path, mkdir
from nwdummy import DummyMain 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))) sys.path.insert(1, path.abspath(path.join(path.dirname(__file__), path.pardir)))
@@ -178,3 +178,25 @@ def nwOldProj(nwTemp):
if path.isdir(oldProjDir): if path.isdir(oldProjDir):
shutil.rmtree(oldProjDir) shutil.rmtree(oldProjDir)
return 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 stepDelay = 20
@pytest.mark.gui @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]) nwGUI = nw.main(["--testmode", "--config=%s" % nwFuncTemp, "--data=%s" % nwTemp])
qtbot.addWidget(nwGUI) qtbot.addWidget(nwGUI)
nwGUI.show() nwGUI.show()
@@ -139,7 +139,7 @@ def testProjectSettings(qtbot, monkeypatch, nwFuncTemp, nwTempGUI, nwRef, nwTemp
nwGUI.closeMain() nwGUI.closeMain()
@pytest.mark.gui @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]) nwGUI = nw.main(["--testmode", "--config=%s" % nwFuncTemp, "--data=%s" % nwTemp])
qtbot.addWidget(nwGUI) qtbot.addWidget(nwGUI)
nwGUI.show() nwGUI.show()
@@ -198,7 +198,7 @@ def testItemEditor(qtbot, nwFuncTemp, nwTempGUI, nwRef, nwTemp):
# qtbot.stopForInteraction() # qtbot.stopForInteraction()
@pytest.mark.gui @pytest.mark.gui
def testWritingStatsExport(qtbot, nwFuncTemp, nwTemp): def testWritingStatsExport(qtbot, yesToAll, nwFuncTemp, nwTemp):
nwGUI = nw.main(["--testmode", "--config=%s" % nwFuncTemp, "--data=%s" % nwTemp]) nwGUI = nw.main(["--testmode", "--config=%s" % nwFuncTemp, "--data=%s" % nwTemp])
qtbot.addWidget(nwGUI) qtbot.addWidget(nwGUI)
nwGUI.show() nwGUI.show()
@@ -385,7 +385,7 @@ def testAboutBox(qtbot, monkeypatch, nwFuncTemp, nwTemp):
nwGUI.closeMain() nwGUI.closeMain()
@pytest.mark.gui @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]) nwGUI = nw.main(["--testmode", "--config=%s" % nwLipsum, "--data=%s" % nwTemp])
qtbot.addWidget(nwGUI) qtbot.addWidget(nwGUI)
@@ -547,7 +547,7 @@ def testBuildTool(qtbot, nwTempBuild, nwLipsum, nwRef, nwTemp):
nwGUI.closeMain() nwGUI.closeMain()
@pytest.mark.gui @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]) nwGUI = nw.main(["--testmode", "--config=%s" % nwLipsum, "--data=%s" % nwTemp])
qtbot.addWidget(nwGUI) qtbot.addWidget(nwGUI)
@@ -690,7 +690,7 @@ def testMergeSplitTools(qtbot, monkeypatch, nwTempGUI, nwLipsum, nwRef, nwTemp):
nwGUI.closeMain() nwGUI.closeMain()
@pytest.mark.gui @pytest.mark.gui
def testNewProjectWizard(qtbot, nwLipsum, nwTemp): def testNewProjectWizard(qtbot, monkeypatch, yesToAll, nwMinimal, nwTemp):
from PyQt5.QtWidgets import QWizard from PyQt5.QtWidgets import QWizard
from nw.gui.projwizard import ( from nw.gui.projwizard import (
@@ -698,7 +698,47 @@ def testNewProjectWizard(qtbot, nwLipsum, nwTemp):
ProjWizardCustomPage, ProjWizardFinalPage 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) qtbot.addWidget(nwGUI)
nwGUI.show() nwGUI.show()
qtbot.waitForWindowShown(nwGUI) qtbot.waitForWindowShown(nwGUI)
@@ -817,9 +857,10 @@ def testNewProjectWizard(qtbot, nwLipsum, nwTemp):
# qtbot.stopForInteraction() # qtbot.stopForInteraction()
nwGUI.closeMain() nwGUI.closeMain()
nwGUI.close()
@pytest.mark.gui @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]) nwGUI = nw.main(["--testmode", "--config=%s" % nwMinimal, "--data=%s" % nwTemp])
qtbot.addWidget(nwGUI) qtbot.addWidget(nwGUI)
nwGUI.show() nwGUI.show()
@@ -877,7 +918,7 @@ def testLoadProject(qtbot, monkeypatch, nwMinimal, nwTemp):
nwGUI.closeMain() nwGUI.closeMain()
@pytest.mark.gui @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]) nwGUI = nw.main(["--testmode", "--config=%s" % nwMinimal, "--data=%s" % nwTemp])
qtbot.addWidget(nwGUI) qtbot.addWidget(nwGUI)
nwGUI.show() nwGUI.show()
@@ -1034,7 +1075,7 @@ def testPreferences(qtbot, monkeypatch, nwMinimal, nwTemp, nwRef, tmpConf):
assert cmpFiles(testConf, refConf, ignoreLines) assert cmpFiles(testConf, refConf, ignoreLines)
@pytest.mark.gui @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]) nwGUI = nw.main(["--testmode", "--config=%s" % nwMinimal, "--data=%s" % nwTemp, nwMinimal])
qtbot.addWidget(nwGUI) qtbot.addWidget(nwGUI)
nwGUI.show() nwGUI.show()
@@ -1064,7 +1105,7 @@ def testQuotesDialog(qtbot, nwMinimal, nwTemp):
nwGUI.close() nwGUI.close()
@pytest.mark.gui @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]) nwGUI = nw.main(["--testmode", "--config=%s" % nwMinimal, "--data=%s" % nwTemp, nwMinimal])
qtbot.addWidget(nwGUI) qtbot.addWidget(nwGUI)
nwGUI.show() nwGUI.show()
+54 -11
View File
@@ -88,7 +88,7 @@ def testLaunch(qtbot, nwFuncTemp, nwTemp):
nwGUI.close() nwGUI.close()
@pytest.mark.gui @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]) nwGUI = nw.main(["--testmode", "--config=%s" % nwFuncTemp, "--data=%s" % nwTemp])
qtbot.addWidget(nwGUI) qtbot.addWidget(nwGUI)
@@ -392,7 +392,7 @@ def testDocEditor(qtbot, nwFuncTemp, nwTempGUI, nwRef, nwTemp):
nwGUI.close() nwGUI.close()
@pytest.mark.gui @pytest.mark.gui
def testDocViewer(qtbot, nwLipsum, nwTemp): def testDocViewer(qtbot, yesToAll, nwLipsum, nwTemp):
nwGUI = nw.main(["--testmode", "--config=%s" % nwLipsum, "--data=%s" % nwTemp]) nwGUI = nw.main(["--testmode", "--config=%s" % nwLipsum, "--data=%s" % nwTemp])
qtbot.addWidget(nwGUI) qtbot.addWidget(nwGUI)
@@ -544,7 +544,7 @@ def testDocViewer(qtbot, nwLipsum, nwTemp):
nwGUI.close() nwGUI.close()
@pytest.mark.gui @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]) nwGUI = nw.main(["--testmode", "--config=%s" % nwMinimal, "--data=%s" % nwTemp, nwMinimal])
qtbot.addWidget(nwGUI) qtbot.addWidget(nwGUI)
@@ -678,7 +678,7 @@ def testProjectTree(qtbot, nwMinimal, nwTemp):
nwGUI.close() nwGUI.close()
@pytest.mark.gui @pytest.mark.gui
def testEditFormatMenu(qtbot, nwLipsum, nwTemp): def testEditFormatMenu(qtbot, yesToAll, nwLipsum, nwTemp):
nwGUI = nw.main(["--testmode", "--config=%s" % nwLipsum, "--data=%s" % nwTemp]) nwGUI = nw.main(["--testmode", "--config=%s" % nwLipsum, "--data=%s" % nwTemp])
qtbot.addWidget(nwGUI) qtbot.addWidget(nwGUI)
@@ -915,7 +915,7 @@ def testEditFormatMenu(qtbot, nwLipsum, nwTemp):
nwGUI.close() nwGUI.close()
@pytest.mark.gui @pytest.mark.gui
def testContextMenu(qtbot, nwLipsum, nwTemp): def testContextMenu(qtbot, yesToAll, nwLipsum, nwTemp):
nwGUI = nw.main(["--testmode", "--config=%s" % nwLipsum, "--data=%s" % nwTemp]) nwGUI = nw.main(["--testmode", "--config=%s" % nwLipsum, "--data=%s" % nwTemp])
qtbot.addWidget(nwGUI) qtbot.addWidget(nwGUI)
@@ -1087,7 +1087,9 @@ def testInsertMenu(qtbot, monkeypatch, nwFuncTemp, nwTemp):
assert nwGUI.docEditor.getText() == " " assert nwGUI.docEditor.getText() == " "
nwGUI.docEditor.clear() nwGUI.docEditor.clear()
# Insert text from file ##
# Insert text from file
##
nwGUI.closeDocument() nwGUI.closeDocument()
# First, with no path # First, with no path
@@ -1123,12 +1125,33 @@ def testInsertMenu(qtbot, monkeypatch, nwFuncTemp, nwTemp):
nwGUI.mainMenu.aImportFile.activate(QAction.Trigger) nwGUI.mainMenu.aImportFile.activate(QAction.Trigger)
assert nwGUI.docEditor.getText() == "Foo" 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() # qtbot.stopForInteraction()
nwGUI.closeMain() nwGUI.closeMain()
nwGUI.close() nwGUI.close()
@pytest.mark.gui @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]) nwGUI = nw.main(["--testmode", "--config=%s" % nwLipsum, "--data=%s" % nwTemp])
qtbot.addWidget(nwGUI) qtbot.addWidget(nwGUI)
@@ -1153,8 +1176,9 @@ def testTextSearch(qtbot, nwLipsum, nwTemp):
assert nwGUI.docEditor.docSearch.isVisible() assert nwGUI.docEditor.docSearch.isVisible()
assert nwGUI.docEditor.docSearch.getSearchText() == "est" assert nwGUI.docEditor.docSearch.getSearchText() == "est"
# Find Next by Menu # Find Next by Enter
nwGUI.mainMenu.aFindNext.activate(QAction.Trigger) 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 assert abs(nwGUI.docEditor.getCursorPosition() - 1272) < 3
# Find Next by Button # Find Next by Button
@@ -1283,12 +1307,31 @@ def testTextSearch(qtbot, nwLipsum, nwTemp):
nwGUI.mainMenu.aFindNext.activate(QAction.Trigger) nwGUI.mainMenu.aFindNext.activate(QAction.Trigger)
assert abs(nwGUI.docEditor.getCursorPosition() - 1127) < 3 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() # qtbot.stopForInteraction()
nwGUI.closeMain() nwGUI.closeMain()
nwGUI.close() nwGUI.close()
@pytest.mark.gui @pytest.mark.gui
def testOutline(qtbot, nwLipsum, nwTemp): def testOutline(qtbot, yesToAll, nwLipsum, nwTemp):
nwGUI = nw.main(["--testmode", "--config=%s" % nwLipsum, "--data=%s" % nwTemp]) nwGUI = nw.main(["--testmode", "--config=%s" % nwLipsum, "--data=%s" % nwTemp])
qtbot.addWidget(nwGUI) qtbot.addWidget(nwGUI)
@@ -1349,7 +1392,7 @@ def testOutline(qtbot, nwLipsum, nwTemp):
nwGUI.close() nwGUI.close()
@pytest.mark.gui @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]) nwGUI = nw.main(["--testmode", "--config=%s" % nwMinimal, "--data=%s" % nwTemp, nwMinimal])
qtbot.addWidget(nwGUI) qtbot.addWidget(nwGUI)