Clean up GUI tests
This commit is contained in:
@@ -29,12 +29,9 @@ from novelwriter.dialogs.about import GuiAbout
|
||||
|
||||
|
||||
@pytest.mark.gui
|
||||
def testDlgAbout_NWDialog(qtbot, monkeypatch, nwGUI):
|
||||
def testDlgAbout_NWDialog(qtbot, nwGUI):
|
||||
"""Test the novelWriter about dialogs.
|
||||
"""
|
||||
# Block message box
|
||||
monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes)
|
||||
|
||||
# NW About
|
||||
nwGUI.mainTheme.themeName = "A Theme"
|
||||
nwGUI.mainTheme.themeAuthor = "An Author"
|
||||
@@ -74,8 +71,6 @@ def testDlgAbout_NWDialog(qtbot, monkeypatch, nwGUI):
|
||||
def testDlgAbout_QtDialog(monkeypatch, nwGUI):
|
||||
"""Test the Qt about dialogs.
|
||||
"""
|
||||
# Block message box
|
||||
monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes)
|
||||
monkeypatch.setattr(QMessageBox, "aboutQt", lambda *a, **k: None)
|
||||
|
||||
# Open About
|
||||
|
||||
@@ -22,7 +22,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import pytest
|
||||
|
||||
from PyQt5.QtCore import QItemSelectionModel
|
||||
from PyQt5.QtWidgets import QAction, QListWidgetItem, QDialog, QMessageBox
|
||||
from PyQt5.QtWidgets import QAction, QListWidgetItem, QDialog
|
||||
|
||||
from novelwriter.dialogs.quotes import GuiQuoteSelect
|
||||
from novelwriter.dialogs.updates import GuiUpdates
|
||||
@@ -30,12 +30,9 @@ from novelwriter.dialogs.editlabel import GuiEditLabel
|
||||
|
||||
|
||||
@pytest.mark.gui
|
||||
def testDlgOther_QuoteSelect(qtbot, monkeypatch, nwGUI):
|
||||
def testDlgOther_QuoteSelect(qtbot, nwGUI):
|
||||
"""Test the quote symbols dialog.
|
||||
"""
|
||||
# Block message box
|
||||
monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes)
|
||||
|
||||
nwQuot = GuiQuoteSelect(nwGUI)
|
||||
nwQuot.show()
|
||||
|
||||
@@ -52,7 +49,7 @@ def testDlgOther_QuoteSelect(qtbot, monkeypatch, nwGUI):
|
||||
assert nwQuot.result() == QDialog.Accepted
|
||||
assert nwQuot.selectedQuote == lastItem
|
||||
|
||||
# qtbot.stopForInteraction()
|
||||
# qtbot.stop()
|
||||
nwQuot._doReject()
|
||||
nwQuot.close()
|
||||
|
||||
@@ -63,9 +60,6 @@ def testDlgOther_QuoteSelect(qtbot, monkeypatch, nwGUI):
|
||||
def testDlgOther_Updates(qtbot, monkeypatch, nwGUI):
|
||||
"""Test the check for updates dialog.
|
||||
"""
|
||||
# Block message box
|
||||
monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes)
|
||||
|
||||
nwUpdate = GuiUpdates(nwGUI)
|
||||
nwUpdate.show()
|
||||
|
||||
@@ -95,7 +89,7 @@ def testDlgOther_Updates(qtbot, monkeypatch, nwGUI):
|
||||
# Trigger from Menu
|
||||
nwGUI.mainMenu.aUpdates.activate(QAction.Trigger)
|
||||
|
||||
# qtbot.stopForInteraction()
|
||||
# qtbot.stop()
|
||||
nwUpdate._doClose()
|
||||
|
||||
# END Test testDlgOther_Updates
|
||||
|
||||
@@ -24,19 +24,14 @@ import pytest
|
||||
from tools import buildTestProject, C
|
||||
|
||||
from PyQt5.QtCore import Qt
|
||||
from PyQt5.QtWidgets import QMessageBox
|
||||
|
||||
from novelwriter.dialogs.docmerge import GuiDocMerge
|
||||
|
||||
|
||||
@pytest.mark.gui
|
||||
def testDlgMerge_Main(qtbot, monkeypatch, nwGUI, fncProj, mockRnd):
|
||||
def testDlgMerge_Main(qtbot, nwGUI, fncProj, mockRnd):
|
||||
"""Test the merge documents tool.
|
||||
"""
|
||||
# Block message box
|
||||
monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes)
|
||||
monkeypatch.setattr(QMessageBox, "critical", lambda *a: QMessageBox.Ok)
|
||||
|
||||
# Create a new project
|
||||
buildTestProject(nwGUI, fncProj)
|
||||
|
||||
|
||||
@@ -23,8 +23,6 @@ import pytest
|
||||
|
||||
from tools import C, buildTestProject
|
||||
|
||||
from PyQt5.QtWidgets import QMessageBox
|
||||
|
||||
from novelwriter.dialogs.docsplit import GuiDocSplit
|
||||
from novelwriter.dialogs.editlabel import GuiEditLabel
|
||||
|
||||
@@ -33,9 +31,6 @@ from novelwriter.dialogs.editlabel import GuiEditLabel
|
||||
def testDlgSplit_Main(qtbot, monkeypatch, nwGUI, fncProj, mockRnd):
|
||||
"""Test the split document tool.
|
||||
"""
|
||||
# Block message box
|
||||
monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes)
|
||||
monkeypatch.setattr(QMessageBox, "critical", lambda *a: QMessageBox.Ok)
|
||||
monkeypatch.setattr(GuiEditLabel, "getLabel", lambda *a, text: (text, True))
|
||||
|
||||
# Create a new project
|
||||
|
||||
@@ -35,9 +35,7 @@ from novelwriter.config import Config
|
||||
from novelwriter.dialogs.quotes import GuiQuoteSelect
|
||||
from novelwriter.dialogs.preferences import GuiPreferences
|
||||
|
||||
keyDelay = 2
|
||||
typeDelay = 1
|
||||
stepDelay = 20
|
||||
KEY_DELAY = 1
|
||||
|
||||
|
||||
@pytest.mark.gui
|
||||
@@ -63,7 +61,6 @@ def testDlgPreferences_Main(qtbot, monkeypatch, fncDir, outDir, refDir):
|
||||
nwGUI = novelwriter.main(["--testmode", "--config=%s" % fncDir, "--data=%s" % fncDir])
|
||||
qtbot.addWidget(nwGUI)
|
||||
nwGUI.show()
|
||||
qtbot.wait(stepDelay)
|
||||
|
||||
theConf = nwGUI.mainConf
|
||||
assert theConf.confPath == fncDir
|
||||
@@ -81,21 +78,21 @@ def testDlgPreferences_Main(qtbot, monkeypatch, fncDir, outDir, refDir):
|
||||
assert nwPrefs.mainConf.confPath == fncDir
|
||||
|
||||
# General Settings
|
||||
qtbot.wait(keyDelay)
|
||||
qtbot.wait(KEY_DELAY)
|
||||
tabGeneral = nwPrefs.tabGeneral
|
||||
nwPrefs._tabBox.setCurrentWidget(tabGeneral)
|
||||
|
||||
qtbot.wait(keyDelay)
|
||||
qtbot.wait(KEY_DELAY)
|
||||
assert tabGeneral.showFullPath.isChecked()
|
||||
qtbot.mouseClick(tabGeneral.showFullPath, Qt.LeftButton)
|
||||
assert not tabGeneral.showFullPath.isChecked()
|
||||
|
||||
qtbot.wait(keyDelay)
|
||||
qtbot.wait(KEY_DELAY)
|
||||
assert not tabGeneral.hideVScroll.isChecked()
|
||||
qtbot.mouseClick(tabGeneral.hideVScroll, Qt.LeftButton)
|
||||
assert tabGeneral.hideVScroll.isChecked()
|
||||
|
||||
qtbot.wait(keyDelay)
|
||||
qtbot.wait(KEY_DELAY)
|
||||
assert not tabGeneral.hideHScroll.isChecked()
|
||||
qtbot.mouseClick(tabGeneral.hideHScroll, Qt.LeftButton)
|
||||
assert tabGeneral.hideHScroll.isChecked()
|
||||
@@ -104,21 +101,21 @@ def testDlgPreferences_Main(qtbot, monkeypatch, fncDir, outDir, refDir):
|
||||
monkeypatch.setattr(QFontDialog, "getFont", lambda font, obj: (font, True))
|
||||
qtbot.mouseClick(tabGeneral.fontButton, Qt.LeftButton)
|
||||
|
||||
qtbot.wait(keyDelay)
|
||||
qtbot.wait(KEY_DELAY)
|
||||
tabGeneral.guiFontSize.setValue(12)
|
||||
|
||||
# Projects Settings
|
||||
qtbot.wait(keyDelay)
|
||||
qtbot.wait(KEY_DELAY)
|
||||
tabProjects = nwPrefs.tabProjects
|
||||
nwPrefs._tabBox.setCurrentWidget(tabProjects)
|
||||
tabProjects.backupPath = "no/where"
|
||||
|
||||
qtbot.wait(keyDelay)
|
||||
qtbot.wait(KEY_DELAY)
|
||||
assert not tabProjects.backupOnClose.isChecked()
|
||||
qtbot.mouseClick(tabProjects.backupOnClose, Qt.LeftButton)
|
||||
assert tabProjects.backupOnClose.isChecked()
|
||||
|
||||
# qtbot.stopForInteraction()
|
||||
# qtbot.stop()
|
||||
|
||||
# Check Browse button
|
||||
monkeypatch.setattr(QFileDialog, "getExistingDirectory", lambda *a, **k: "")
|
||||
@@ -126,99 +123,99 @@ def testDlgPreferences_Main(qtbot, monkeypatch, fncDir, outDir, refDir):
|
||||
monkeypatch.setattr(QFileDialog, "getExistingDirectory", lambda *a, **k: "some/dir")
|
||||
qtbot.mouseClick(tabProjects.backupGetPath, Qt.LeftButton)
|
||||
|
||||
qtbot.wait(keyDelay)
|
||||
qtbot.wait(KEY_DELAY)
|
||||
tabProjects.autoSaveDoc.setValue(20)
|
||||
tabProjects.autoSaveProj.setValue(40)
|
||||
|
||||
# Document Settings
|
||||
qtbot.wait(keyDelay)
|
||||
qtbot.wait(KEY_DELAY)
|
||||
tabDocs = nwPrefs.tabDocs
|
||||
nwPrefs._tabBox.setCurrentWidget(tabDocs)
|
||||
|
||||
qtbot.wait(keyDelay)
|
||||
qtbot.wait(KEY_DELAY)
|
||||
qtbot.mouseClick(tabDocs.fontButton, Qt.LeftButton)
|
||||
|
||||
qtbot.wait(keyDelay)
|
||||
qtbot.wait(KEY_DELAY)
|
||||
tabDocs.textSize.setValue(13)
|
||||
tabDocs.textWidth.setValue(700)
|
||||
tabDocs.focusWidth.setValue(900)
|
||||
tabDocs.textMargin.setValue(45)
|
||||
tabDocs.tabWidth.setValue(45)
|
||||
|
||||
qtbot.wait(keyDelay)
|
||||
qtbot.wait(KEY_DELAY)
|
||||
assert not tabDocs.hideFocusFooter.isChecked()
|
||||
qtbot.mouseClick(tabDocs.hideFocusFooter, Qt.LeftButton)
|
||||
assert tabDocs.hideFocusFooter.isChecked()
|
||||
|
||||
qtbot.wait(keyDelay)
|
||||
qtbot.wait(KEY_DELAY)
|
||||
assert not tabDocs.doJustify.isChecked()
|
||||
qtbot.mouseClick(tabDocs.doJustify, Qt.LeftButton)
|
||||
assert tabDocs.doJustify.isChecked()
|
||||
|
||||
# Editor Settings
|
||||
qtbot.wait(keyDelay)
|
||||
qtbot.wait(KEY_DELAY)
|
||||
tabEditor = nwPrefs.tabEditor
|
||||
nwPrefs._tabBox.setCurrentWidget(tabEditor)
|
||||
|
||||
qtbot.wait(keyDelay)
|
||||
qtbot.wait(KEY_DELAY)
|
||||
assert not tabEditor.showTabsNSpaces.isChecked()
|
||||
qtbot.mouseClick(tabEditor.showTabsNSpaces, Qt.LeftButton)
|
||||
assert tabEditor.showTabsNSpaces.isChecked()
|
||||
|
||||
qtbot.wait(keyDelay)
|
||||
qtbot.wait(KEY_DELAY)
|
||||
assert not tabEditor.showLineEndings.isChecked()
|
||||
qtbot.mouseClick(tabEditor.showLineEndings, Qt.LeftButton)
|
||||
assert tabEditor.showLineEndings.isChecked()
|
||||
|
||||
qtbot.wait(keyDelay)
|
||||
qtbot.wait(KEY_DELAY)
|
||||
assert not tabEditor.autoScroll.isChecked()
|
||||
qtbot.mouseClick(tabEditor.autoScroll, Qt.LeftButton)
|
||||
assert tabEditor.autoScroll.isChecked()
|
||||
|
||||
qtbot.wait(keyDelay)
|
||||
qtbot.wait(KEY_DELAY)
|
||||
tabEditor.scrollPastEnd.setValue(0)
|
||||
|
||||
qtbot.wait(keyDelay)
|
||||
qtbot.wait(KEY_DELAY)
|
||||
tabEditor.bigDocLimit.setValue(500)
|
||||
|
||||
# Syntax Settings
|
||||
qtbot.wait(keyDelay)
|
||||
qtbot.wait(KEY_DELAY)
|
||||
tabSyntax = nwPrefs.tabSyntax
|
||||
nwPrefs._tabBox.setCurrentWidget(tabSyntax)
|
||||
|
||||
qtbot.wait(keyDelay)
|
||||
qtbot.wait(KEY_DELAY)
|
||||
assert tabSyntax.highlightQuotes.isChecked()
|
||||
qtbot.mouseClick(tabSyntax.highlightQuotes, Qt.LeftButton)
|
||||
assert not tabSyntax.highlightQuotes.isChecked()
|
||||
|
||||
qtbot.wait(keyDelay)
|
||||
qtbot.wait(KEY_DELAY)
|
||||
assert tabSyntax.highlightEmph.isChecked()
|
||||
qtbot.mouseClick(tabSyntax.highlightEmph, Qt.LeftButton)
|
||||
assert not tabSyntax.highlightEmph.isChecked()
|
||||
|
||||
# Automation Settings
|
||||
qtbot.wait(keyDelay)
|
||||
qtbot.wait(KEY_DELAY)
|
||||
tabAuto = nwPrefs.tabAuto
|
||||
nwPrefs._tabBox.setCurrentWidget(tabAuto)
|
||||
|
||||
qtbot.wait(keyDelay)
|
||||
qtbot.wait(KEY_DELAY)
|
||||
assert tabAuto.autoSelect.isChecked()
|
||||
qtbot.mouseClick(tabAuto.autoSelect, Qt.LeftButton)
|
||||
assert not tabAuto.autoSelect.isChecked()
|
||||
|
||||
qtbot.wait(keyDelay)
|
||||
qtbot.wait(KEY_DELAY)
|
||||
assert tabAuto.doReplace.isChecked()
|
||||
qtbot.mouseClick(tabAuto.doReplace, Qt.LeftButton)
|
||||
assert not tabAuto.doReplace.isChecked()
|
||||
|
||||
qtbot.wait(keyDelay)
|
||||
qtbot.wait(KEY_DELAY)
|
||||
assert not tabAuto.doReplaceSQuote.isEnabled()
|
||||
assert not tabAuto.doReplaceDQuote.isEnabled()
|
||||
assert not tabAuto.doReplaceDash.isEnabled()
|
||||
assert not tabAuto.doReplaceDots.isEnabled()
|
||||
|
||||
# Quotation Style
|
||||
qtbot.wait(keyDelay)
|
||||
qtbot.wait(KEY_DELAY)
|
||||
tabQuote = nwPrefs.tabQuote
|
||||
nwPrefs._tabBox.setCurrentWidget(tabQuote)
|
||||
|
||||
@@ -249,6 +246,6 @@ def testDlgPreferences_Main(qtbot, monkeypatch, fncDir, outDir, refDir):
|
||||
novelwriter.CONFIG = origConf
|
||||
nwGUI.closeMain()
|
||||
|
||||
# qtbot.stopForInteraction()
|
||||
# qtbot.stop()
|
||||
|
||||
# END Test testDlgPreferences_Main
|
||||
|
||||
@@ -23,25 +23,15 @@ import pytest
|
||||
|
||||
from tools import getGuiItem
|
||||
|
||||
from PyQt5.QtWidgets import QAction, QMessageBox
|
||||
from PyQt5.QtWidgets import QAction
|
||||
|
||||
from novelwriter.dialogs.projdetails import GuiProjectDetails
|
||||
|
||||
keyDelay = 2
|
||||
typeDelay = 1
|
||||
stepDelay = 20
|
||||
|
||||
|
||||
@pytest.mark.gui
|
||||
def testDlgProjDetails_Dialog(qtbot, monkeypatch, nwGUI, nwLipsum):
|
||||
def testDlgProjDetails_Dialog(qtbot, nwGUI, nwLipsum):
|
||||
"""Test the project details dialog.
|
||||
"""
|
||||
# Block message box
|
||||
monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes)
|
||||
monkeypatch.setattr(QMessageBox, "information", lambda *a: QMessageBox.Yes)
|
||||
monkeypatch.setattr(QMessageBox, "warning", lambda *a: QMessageBox.Yes)
|
||||
monkeypatch.setattr(QMessageBox, "critical", lambda *a: QMessageBox.Yes)
|
||||
|
||||
# Create a project to work on
|
||||
assert nwGUI.openProject(nwLipsum)
|
||||
assert nwGUI.rebuildIndex(beQuiet=True)
|
||||
@@ -54,7 +44,6 @@ def testDlgProjDetails_Dialog(qtbot, monkeypatch, nwGUI, nwLipsum):
|
||||
|
||||
projDet = getGuiItem("GuiProjectDetails")
|
||||
assert isinstance(projDet, GuiProjectDetails)
|
||||
qtbot.wait(stepDelay)
|
||||
|
||||
# Overview Page
|
||||
# =============
|
||||
@@ -105,7 +94,7 @@ def testDlgProjDetails_Dialog(qtbot, monkeypatch, nwGUI, nwLipsum):
|
||||
assert tocTree.topLevelItem(i).text(tocTab.C_PAGES) == thePages[i]
|
||||
assert tocTree.topLevelItem(i).text(tocTab.C_PAGE) == thePage[i]
|
||||
|
||||
# qtbot.stopForInteraction()
|
||||
# qtbot.stop()
|
||||
|
||||
# Clean Up
|
||||
projDet._doClose()
|
||||
|
||||
@@ -26,29 +26,19 @@ from tools import getGuiItem
|
||||
|
||||
from PyQt5.QtCore import Qt
|
||||
from PyQt5.QtWidgets import (
|
||||
QDialogButtonBox, QTreeWidgetItem, QDialog, QAction, QFileDialog,
|
||||
QMessageBox
|
||||
QDialogButtonBox, QTreeWidgetItem, QDialog, QAction, QFileDialog
|
||||
)
|
||||
|
||||
from novelwriter.dialogs.projload import GuiProjectLoad
|
||||
|
||||
keyDelay = 2
|
||||
typeDelay = 1
|
||||
stepDelay = 20
|
||||
|
||||
|
||||
@pytest.mark.gui
|
||||
def testDlgLoadProject_Main(qtbot, monkeypatch, nwGUI, nwMinimal):
|
||||
"""Test the load project wizard.
|
||||
"""
|
||||
# Block message box
|
||||
monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes)
|
||||
monkeypatch.setattr(QMessageBox, "information", lambda *a: QMessageBox.Yes)
|
||||
|
||||
assert nwGUI.openProject(nwMinimal)
|
||||
assert nwGUI.closeProject()
|
||||
|
||||
qtbot.wait(stepDelay)
|
||||
monkeypatch.setattr(GuiProjectLoad, "exec_", lambda *a: None)
|
||||
monkeypatch.setattr(GuiProjectLoad, "result", lambda *a: QDialog.Accepted)
|
||||
nwGUI.mainMenu.aOpenProject.activate(QAction.Trigger)
|
||||
@@ -58,22 +48,18 @@ def testDlgLoadProject_Main(qtbot, monkeypatch, nwGUI, nwMinimal):
|
||||
assert isinstance(nwLoad, GuiProjectLoad)
|
||||
nwLoad.show()
|
||||
|
||||
qtbot.wait(stepDelay)
|
||||
recentCount = nwLoad.listBox.topLevelItemCount()
|
||||
assert recentCount > 0
|
||||
|
||||
qtbot.wait(stepDelay)
|
||||
selItem = nwLoad.listBox.topLevelItem(0)
|
||||
selPath = selItem.data(nwLoad.C_NAME, Qt.UserRole)
|
||||
assert isinstance(selItem, QTreeWidgetItem)
|
||||
|
||||
qtbot.wait(stepDelay)
|
||||
nwLoad.selPath.setText("")
|
||||
nwLoad.listBox.setCurrentItem(selItem)
|
||||
nwLoad._doSelectRecent()
|
||||
assert nwLoad.selPath.text() == selPath
|
||||
|
||||
qtbot.wait(stepDelay)
|
||||
qtbot.mouseClick(nwLoad.buttonBox.button(QDialogButtonBox.Open), Qt.LeftButton)
|
||||
assert nwLoad.openPath == selPath
|
||||
assert nwLoad.openState == nwLoad.OPEN_STATE
|
||||
@@ -81,27 +67,22 @@ def testDlgLoadProject_Main(qtbot, monkeypatch, nwGUI, nwMinimal):
|
||||
# Just create a new project load from scratch for the rest of the test
|
||||
del nwLoad
|
||||
|
||||
qtbot.wait(stepDelay)
|
||||
nwGUI.mainMenu.aOpenProject.activate(QAction.Trigger)
|
||||
qtbot.waitUntil(lambda: getGuiItem("GuiProjectLoad") is not None, timeout=1000)
|
||||
|
||||
qtbot.wait(stepDelay)
|
||||
nwLoad = getGuiItem("GuiProjectLoad")
|
||||
assert isinstance(nwLoad, GuiProjectLoad)
|
||||
nwLoad.show()
|
||||
|
||||
qtbot.wait(stepDelay)
|
||||
qtbot.mouseClick(nwLoad.buttonBox.button(QDialogButtonBox.Cancel), Qt.LeftButton)
|
||||
assert nwLoad.openPath is None
|
||||
assert nwLoad.openState == nwLoad.NONE_STATE
|
||||
|
||||
qtbot.wait(stepDelay)
|
||||
nwLoad.show()
|
||||
qtbot.mouseClick(nwLoad.newButton, Qt.LeftButton)
|
||||
assert nwLoad.openPath is None
|
||||
assert nwLoad.openState == nwLoad.NEW_STATE
|
||||
|
||||
qtbot.wait(stepDelay)
|
||||
nwLoad.show()
|
||||
nwLoad._doDeleteRecent()
|
||||
assert nwLoad.listBox.topLevelItemCount() == recentCount - 1
|
||||
@@ -113,6 +94,6 @@ def testDlgLoadProject_Main(qtbot, monkeypatch, nwGUI, nwMinimal):
|
||||
assert nwLoad.openState == nwLoad.OPEN_STATE
|
||||
|
||||
nwLoad.close()
|
||||
# qtbot.stopForInteraction()
|
||||
# qtbot.stop()
|
||||
|
||||
# END Test testDlgLoadProject_Main
|
||||
|
||||
@@ -26,14 +26,12 @@ from tools import C, getGuiItem, buildTestProject
|
||||
|
||||
from PyQt5.QtGui import QColor
|
||||
from PyQt5.QtCore import Qt
|
||||
from PyQt5.QtWidgets import QDialog, QAction, QMessageBox, QColorDialog
|
||||
from PyQt5.QtWidgets import QDialog, QAction, QColorDialog
|
||||
|
||||
from novelwriter.dialogs.editlabel import GuiEditLabel
|
||||
from novelwriter.dialogs.projsettings import GuiProjectSettings
|
||||
|
||||
keyDelay = 2
|
||||
typeDelay = 1
|
||||
stepDelay = 20
|
||||
KEY_DELAY = 1
|
||||
|
||||
|
||||
@pytest.mark.gui
|
||||
@@ -41,10 +39,6 @@ def testDlgProjSettings_Dialog(qtbot, monkeypatch, nwGUI):
|
||||
"""Test the main dialog class. Saving settings is not tested in this
|
||||
test, but are instead tested in the individual tab tests.
|
||||
"""
|
||||
# Block message box
|
||||
monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes)
|
||||
monkeypatch.setattr(QMessageBox, "critical", lambda *a: QMessageBox.Yes)
|
||||
|
||||
# Block the GUI blocking thread
|
||||
monkeypatch.setattr(GuiProjectSettings, "exec_", lambda *a: None)
|
||||
monkeypatch.setattr(GuiProjectSettings, "result", lambda *a: QDialog.Accepted)
|
||||
@@ -91,10 +85,6 @@ def testDlgProjSettings_Dialog(qtbot, monkeypatch, nwGUI):
|
||||
def testDlgProjSettings_Main(qtbot, monkeypatch, nwGUI, fncDir, fncProj, mockRnd):
|
||||
"""Test the main tab of the project settings dialog.
|
||||
"""
|
||||
# Block message box
|
||||
monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes)
|
||||
monkeypatch.setattr(QMessageBox, "critical", lambda *a: QMessageBox.Yes)
|
||||
|
||||
# Mock components
|
||||
monkeypatch.setattr(nwGUI.docEditor.spEnchant, "listDictionaries", lambda: [("en", "none")])
|
||||
|
||||
@@ -125,23 +115,21 @@ def testDlgProjSettings_Main(qtbot, monkeypatch, nwGUI, fncDir, fncProj, mockRnd
|
||||
assert tabMain.spellLang.currentData() == "en"
|
||||
assert tabMain.doBackup.isChecked() is False
|
||||
|
||||
qtbot.wait(stepDelay)
|
||||
tabMain.editName.setText("")
|
||||
for c in "Project Name":
|
||||
qtbot.keyClick(tabMain.editName, c, delay=typeDelay)
|
||||
qtbot.keyClick(tabMain.editName, c, delay=KEY_DELAY)
|
||||
tabMain.editTitle.setText("")
|
||||
for c in "Project Title":
|
||||
qtbot.keyClick(tabMain.editTitle, c, delay=typeDelay)
|
||||
qtbot.keyClick(tabMain.editTitle, c, delay=KEY_DELAY)
|
||||
|
||||
tabMain.editAuthors.clear()
|
||||
for c in "Jane Doe":
|
||||
qtbot.keyClick(tabMain.editAuthors, c, delay=typeDelay)
|
||||
qtbot.keyClick(tabMain.editAuthors, Qt.Key_Return, delay=keyDelay)
|
||||
qtbot.keyClick(tabMain.editAuthors, c, delay=KEY_DELAY)
|
||||
qtbot.keyClick(tabMain.editAuthors, Qt.Key_Return, delay=KEY_DELAY)
|
||||
for c in "John Doh":
|
||||
qtbot.keyClick(tabMain.editAuthors, c, delay=typeDelay)
|
||||
qtbot.keyClick(tabMain.editAuthors, Qt.Key_Return, delay=keyDelay)
|
||||
qtbot.keyClick(tabMain.editAuthors, c, delay=KEY_DELAY)
|
||||
qtbot.keyClick(tabMain.editAuthors, Qt.Key_Return, delay=KEY_DELAY)
|
||||
|
||||
qtbot.wait(stepDelay)
|
||||
assert tabMain.editName.text() == "Project Name"
|
||||
assert tabMain.editTitle.text() == "Project Title"
|
||||
assert tabMain.editAuthors.toPlainText() == "Jane Doe\nJohn Doh\n"
|
||||
@@ -164,9 +152,6 @@ def testDlgProjSettings_StatusImport(qtbot, monkeypatch, nwGUI, fncDir, fncProj,
|
||||
"""Test the status and importance tabs of the project settings
|
||||
dialog.
|
||||
"""
|
||||
# Block message box
|
||||
monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes)
|
||||
monkeypatch.setattr(QMessageBox, "critical", lambda *a: QMessageBox.Yes)
|
||||
monkeypatch.setattr(GuiEditLabel, "getLabel", lambda *a, text: (text, True))
|
||||
|
||||
# Mock components
|
||||
@@ -230,9 +215,9 @@ def testDlgProjSettings_StatusImport(qtbot, monkeypatch, nwGUI, fncDir, fncProj,
|
||||
qtbot.mouseClick(tabStatus.addButton, Qt.LeftButton)
|
||||
tabStatus.listBox.setCurrentItem(tabStatus.listBox.topLevelItem(3))
|
||||
for _ in range(8):
|
||||
qtbot.keyClick(tabStatus.editName, Qt.Key_Backspace, delay=typeDelay)
|
||||
qtbot.keyClick(tabStatus.editName, Qt.Key_Backspace, delay=KEY_DELAY)
|
||||
for c in "Final":
|
||||
qtbot.keyClick(tabStatus.editName, c, delay=typeDelay)
|
||||
qtbot.keyClick(tabStatus.editName, c, delay=KEY_DELAY)
|
||||
qtbot.mouseClick(tabStatus.colButton, Qt.LeftButton)
|
||||
qtbot.mouseClick(tabStatus.saveButton, Qt.LeftButton)
|
||||
assert tabStatus.listBox.topLevelItemCount() == 4
|
||||
@@ -310,9 +295,9 @@ def testDlgProjSettings_StatusImport(qtbot, monkeypatch, nwGUI, fncDir, fncProj,
|
||||
tabImport.listBox.clearSelection()
|
||||
tabImport.listBox.setCurrentItem(tabImport.listBox.topLevelItem(3))
|
||||
for _ in range(8):
|
||||
qtbot.keyClick(tabImport.editName, Qt.Key_Backspace, delay=typeDelay)
|
||||
qtbot.keyClick(tabImport.editName, Qt.Key_Backspace, delay=KEY_DELAY)
|
||||
for c in "Final":
|
||||
qtbot.keyClick(tabImport.editName, c, delay=typeDelay)
|
||||
qtbot.keyClick(tabImport.editName, c, delay=KEY_DELAY)
|
||||
qtbot.mouseClick(tabImport.colButton, Qt.LeftButton)
|
||||
qtbot.mouseClick(tabImport.saveButton, Qt.LeftButton)
|
||||
assert tabImport.listBox.topLevelItemCount() == 4
|
||||
@@ -368,9 +353,6 @@ def testDlgProjSettings_StatusImport(qtbot, monkeypatch, nwGUI, fncDir, fncProj,
|
||||
def testDlgProjSettings_Replace(qtbot, monkeypatch, nwGUI, fncDir, fncProj, mockRnd):
|
||||
"""Test the auto-replace tab of the project settings dialog.
|
||||
"""
|
||||
# Block message box
|
||||
monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes)
|
||||
monkeypatch.setattr(QMessageBox, "critical", lambda *a: QMessageBox.Yes)
|
||||
monkeypatch.setattr(GuiEditLabel, "getLabel", lambda *a, text: (text, True))
|
||||
|
||||
# Mock components
|
||||
@@ -419,10 +401,10 @@ def testDlgProjSettings_Replace(qtbot, monkeypatch, nwGUI, fncDir, fncProj, mock
|
||||
tabReplace.listBox.setCurrentItem(tabReplace.listBox.topLevelItem(2))
|
||||
tabReplace.editKey.setText("")
|
||||
for c in "Th is ":
|
||||
qtbot.keyClick(tabReplace.editKey, c, delay=typeDelay)
|
||||
qtbot.keyClick(tabReplace.editKey, c, delay=KEY_DELAY)
|
||||
tabReplace.editValue.setText("")
|
||||
for c in "With This Stuff ":
|
||||
qtbot.keyClick(tabReplace.editValue, c, delay=typeDelay)
|
||||
qtbot.keyClick(tabReplace.editValue, c, delay=KEY_DELAY)
|
||||
qtbot.mouseClick(tabReplace.saveButton, Qt.LeftButton)
|
||||
assert tabReplace.listBox.topLevelItem(2).text(0) == "<This>"
|
||||
assert tabReplace.listBox.topLevelItem(2).text(1) == "With This Stuff "
|
||||
|
||||
@@ -23,7 +23,7 @@ import os
|
||||
import pytest
|
||||
|
||||
from PyQt5.QtCore import Qt
|
||||
from PyQt5.QtWidgets import QDialog, QMessageBox, QAction
|
||||
from PyQt5.QtWidgets import QDialog, QAction
|
||||
|
||||
from tools import writeFile, readFile, getGuiItem
|
||||
from mock import causeOSError
|
||||
@@ -31,25 +31,17 @@ from mock import causeOSError
|
||||
from novelwriter.constants import nwFiles
|
||||
from novelwriter.dialogs.wordlist import GuiWordList
|
||||
|
||||
keyDelay = 2
|
||||
typeDelay = 1
|
||||
stepDelay = 20
|
||||
|
||||
|
||||
@pytest.mark.gui
|
||||
def testDlgWordList_Dialog(qtbot, monkeypatch, nwGUI, nwMinimal):
|
||||
"""test the word list editor.
|
||||
"""
|
||||
monkeypatch.setattr(QMessageBox, "information", lambda *a: QMessageBox.Yes)
|
||||
monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes)
|
||||
monkeypatch.setattr(QMessageBox, "critical", lambda *a: QMessageBox.Yes)
|
||||
monkeypatch.setattr(GuiWordList, "exec_", lambda *a: None)
|
||||
monkeypatch.setattr(GuiWordList, "result", lambda *a: QDialog.Accepted)
|
||||
monkeypatch.setattr(GuiWordList, "accept", lambda *a: None)
|
||||
|
||||
# Open project
|
||||
nwGUI.openProject(nwMinimal)
|
||||
qtbot.wait(stepDelay)
|
||||
dictFile = os.path.join(nwMinimal, "meta", nwFiles.PROJ_DICT)
|
||||
|
||||
# Load the dialog
|
||||
@@ -59,7 +51,6 @@ def testDlgWordList_Dialog(qtbot, monkeypatch, nwGUI, nwMinimal):
|
||||
wList = getGuiItem("GuiWordList")
|
||||
assert isinstance(wList, GuiWordList)
|
||||
wList.show()
|
||||
qtbot.wait(stepDelay)
|
||||
|
||||
# List should be blank
|
||||
assert wList.listBox.count() == 0
|
||||
@@ -73,7 +64,6 @@ def testDlgWordList_Dialog(qtbot, monkeypatch, nwGUI, nwMinimal):
|
||||
"word_f\n"
|
||||
"word_b\n"
|
||||
))
|
||||
qtbot.wait(stepDelay)
|
||||
assert wList._loadWordList()
|
||||
|
||||
# Check that the content was loaded
|
||||
@@ -130,7 +120,7 @@ def testDlgWordList_Dialog(qtbot, monkeypatch, nwGUI, nwMinimal):
|
||||
monkeypatch.setattr("builtins.open", causeOSError)
|
||||
assert not wList._doSave()
|
||||
|
||||
# qtbot.stopForInteraction()
|
||||
# qtbot.stop()
|
||||
wList._doClose()
|
||||
|
||||
# END Test testDlgWordList_Dialog
|
||||
|
||||
Reference in New Issue
Block a user