Replace exec_ with exec

This commit is contained in:
Veronica Berglyd Olsen
2024-04-03 18:41:39 +02:00
parent c8fe5e6620
commit f95bbb8760
28 changed files with 49 additions and 49 deletions
+2 -2
View File
@@ -187,7 +187,7 @@ def main(sysArgs: list | None = None):
)) ))
for errLine in errorData: for errLine in errorData:
logger.critical(errLine) logger.critical(errLine)
errApp.exec_() errApp.exec()
sys.exit(errorCode) sys.exit(errorCode)
# Finish initialising config # Finish initialising config
@@ -237,6 +237,6 @@ def main(sysArgs: list | None = None):
nwGUI = GuiMain() nwGUI = GuiMain()
nwGUI.postLaunchTasks(cmdOpen) nwGUI.postLaunchTasks(cmdOpen)
sys.exit(nwApp.exec_()) sys.exit(nwApp.exec())
# END Function main # END Function main
+1 -1
View File
@@ -88,7 +88,7 @@ class GuiEditLabel(QDialog):
def getLabel(cls, parent: QWidget, text: str) -> tuple[str, bool]: def getLabel(cls, parent: QWidget, text: str) -> tuple[str, bool]:
"""Pop the dialog and return the result.""" """Pop the dialog and return the result."""
cls = GuiEditLabel(parent, text=text) cls = GuiEditLabel(parent, text=text)
cls.exec_() cls.exec()
label = cls.itemLabel label = cls.itemLabel
accepted = cls.result() == QDialog.Accepted accepted = cls.result() == QDialog.Accepted
cls.deleteLater() cls.deleteLater()
+1 -1
View File
@@ -123,7 +123,7 @@ class GuiQuoteSelect(QDialog):
def getQuote(cls, parent: QWidget, current: str = "") -> tuple[str, bool]: def getQuote(cls, parent: QWidget, current: str = "") -> tuple[str, bool]:
"""Pop the dialog and return the result.""" """Pop the dialog and return the result."""
cls = GuiQuoteSelect(parent, current=current) cls = GuiQuoteSelect(parent, current=current)
cls.exec_() cls.exec()
quote = cls._selected quote = cls._selected
accepted = cls.result() == QDialog.DialogCode.Accepted accepted = cls.result() == QDialog.DialogCode.Accepted
cls.deleteLater() cls.deleteLater()
+1 -1
View File
@@ -197,7 +197,7 @@ def exceptionHandler(exType: type, exValue: BaseException, exTrace: TracebackTyp
errMsg = NWErrorMessage(nwGUI) errMsg = NWErrorMessage(nwGUI)
errMsg.setMessage(exType, exValue, exTrace) errMsg.setMessage(exType, exValue, exTrace)
errMsg.exec_() errMsg.exec()
try: try:
# Try a controlled shutdown # Try a controlled shutdown
+1 -1
View File
@@ -1171,7 +1171,7 @@ class GuiDocEditor(QPlainTextEdit):
action.triggered.connect(lambda: self._addWord(word, block)) action.triggered.connect(lambda: self._addWord(word, block))
# Execute the context menu # Execute the context menu
ctxMenu.exec_(self.viewport().mapToGlobal(pos)) ctxMenu.exec(self.viewport().mapToGlobal(pos))
ctxMenu.deleteLater() ctxMenu.deleteLater()
return return
+1 -1
View File
@@ -410,7 +410,7 @@ class GuiDocViewer(QTextBrowser):
ctxMenu.addAction(mnuSelPara) ctxMenu.addAction(mnuSelPara)
# Open the context menu # Open the context menu
ctxMenu.exec_(self.viewport().mapToGlobal(point)) ctxMenu.exec(self.viewport().mapToGlobal(point))
ctxMenu.deleteLater() ctxMenu.deleteLater()
return return
+3 -3
View File
@@ -1230,7 +1230,7 @@ class GuiProjectTree(QTreeWidget):
else: else:
ctxMenu.buildSingleSelectMenu(hasChild) ctxMenu.buildSingleSelectMenu(hasChild)
ctxMenu.exec_(self.viewport().mapToGlobal(clickPos)) ctxMenu.exec(self.viewport().mapToGlobal(clickPos))
ctxMenu.deleteLater() ctxMenu.deleteLater()
return True return True
@@ -1410,7 +1410,7 @@ class GuiProjectTree(QTreeWidget):
itemList.remove(tHandle) itemList.remove(tHandle)
dlgMerge = GuiDocMerge(self.mainGui, tHandle, itemList) dlgMerge = GuiDocMerge(self.mainGui, tHandle, itemList)
dlgMerge.exec_() dlgMerge.exec()
if dlgMerge.result() == QDialog.DialogCode.Accepted: if dlgMerge.result() == QDialog.DialogCode.Accepted:
@@ -1480,7 +1480,7 @@ class GuiProjectTree(QTreeWidget):
return False return False
dlgSplit = GuiDocSplit(self.mainGui, tHandle) dlgSplit = GuiDocSplit(self.mainGui, tHandle)
dlgSplit.exec_() dlgSplit.exec()
if dlgSplit.result() == QDialog.DialogCode.Accepted: if dlgSplit.result() == QDialog.DialogCode.Accepted:
+4 -4
View File
@@ -768,7 +768,7 @@ class GuiMain(QMainWindow):
"""Open the welcome dialog.""" """Open the welcome dialog."""
dialog = GuiWelcome(self) dialog = GuiWelcome(self)
dialog.openProjectRequest.connect(self._openProjectFromWelcome) dialog.openProjectRequest.connect(self._openProjectFromWelcome)
dialog.exec_() dialog.exec()
return return
@pyqtSlot() @pyqtSlot()
@@ -776,7 +776,7 @@ class GuiMain(QMainWindow):
"""Open the preferences dialog.""" """Open the preferences dialog."""
dialog = GuiPreferences(self) dialog = GuiPreferences(self)
dialog.newPreferencesReady.connect(self._processConfigChanges) dialog.newPreferencesReady.connect(self._processConfigChanges)
dialog.exec_() dialog.exec()
return return
@pyqtSlot() @pyqtSlot()
@@ -786,7 +786,7 @@ class GuiMain(QMainWindow):
if SHARED.hasProject: if SHARED.hasProject:
dialog = GuiProjectSettings(self, gotoPage=focusTab) dialog = GuiProjectSettings(self, gotoPage=focusTab)
dialog.newProjectSettingsReady.connect(self._processProjectSettingsChanges) dialog.newProjectSettingsReady.connect(self._processProjectSettingsChanges)
dialog.exec_() dialog.exec()
return return
@pyqtSlot() @pyqtSlot()
@@ -820,7 +820,7 @@ class GuiMain(QMainWindow):
if SHARED.hasProject: if SHARED.hasProject:
dialog = GuiWordList(self) dialog = GuiWordList(self)
dialog.newWordListReady.connect(self._processWordListChanges) dialog.newWordListReady.connect(self._processWordListChanges)
dialog.exec_() dialog.exec()
return return
@pyqtSlot() @pyqtSlot()
+4 -4
View File
@@ -292,7 +292,7 @@ class SharedData(QObject):
self._lastAlert = alert.logMessage self._lastAlert = alert.logMessage
if log: if log:
logger.info(self._lastAlert, stacklevel=2) logger.info(self._lastAlert, stacklevel=2)
alert.exec_() alert.exec()
alert.deleteLater() alert.deleteLater()
return return
@@ -304,7 +304,7 @@ class SharedData(QObject):
self._lastAlert = alert.logMessage self._lastAlert = alert.logMessage
if log: if log:
logger.warning(self._lastAlert, stacklevel=2) logger.warning(self._lastAlert, stacklevel=2)
alert.exec_() alert.exec()
alert.deleteLater() alert.deleteLater()
return return
@@ -319,7 +319,7 @@ class SharedData(QObject):
self._lastAlert = alert.logMessage self._lastAlert = alert.logMessage
if log: if log:
logger.error(self._lastAlert, stacklevel=2) logger.error(self._lastAlert, stacklevel=2)
alert.exec_() alert.exec()
alert.deleteLater() alert.deleteLater()
return return
@@ -329,7 +329,7 @@ class SharedData(QObject):
alert.setMessage(text, info, details) alert.setMessage(text, info, details)
alert.setAlertType(_GuiAlert.WARN if warn else _GuiAlert.ASK, True) alert.setAlertType(_GuiAlert.WARN if warn else _GuiAlert.ASK, True)
self._lastAlert = alert.logMessage self._lastAlert = alert.logMessage
alert.exec_() alert.exec()
isYes = alert.result() == QMessageBox.StandardButton.Yes isYes = alert.result() == QMessageBox.StandardButton.Yes
alert.deleteLater() alert.deleteLater()
return isYes return isYes
+1 -1
View File
@@ -129,7 +129,7 @@ class GuiLipsum(QDialog):
def getLipsum(cls, parent: QWidget) -> str: def getLipsum(cls, parent: QWidget) -> str:
"""Pop the dialog and return the lipsum text.""" """Pop the dialog and return the lipsum text."""
cls = GuiLipsum(parent) cls = GuiLipsum(parent)
cls.exec_() cls.exec()
text = cls.lipsumText text = cls.lipsumText
cls.deleteLater() cls.deleteLater()
return text return text
+2 -2
View File
@@ -385,7 +385,7 @@ class GuiManuscript(QDialog):
build = self._getSelectedBuild() build = self._getSelectedBuild()
if isinstance(build, BuildSettings): if isinstance(build, BuildSettings):
dlgBuild = GuiManuscriptBuild(self, build) dlgBuild = GuiManuscriptBuild(self, build)
dlgBuild.exec_() dlgBuild.exec()
# After the build is done, save build settings changes # After the build is done, save build settings changes
if build.changed: if build.changed:
@@ -398,7 +398,7 @@ class GuiManuscript(QDialog):
"""Open the print preview dialog.""" """Open the print preview dialog."""
preview = QPrintPreviewDialog(self) preview = QPrintPreviewDialog(self)
preview.paintRequested.connect(self.docPreview.printPreview) preview.paintRequested.connect(self.docPreview.printPreview)
preview.exec_() preview.exec()
return return
## ##
+1 -1
View File
@@ -377,7 +377,7 @@ class _OpenProjectPage(QWidget):
action.triggered.connect(self.openSelectedItem) action.triggered.connect(self.openSelectedItem)
action = ctxMenu.addAction(self.tr("Remove Project")) action = ctxMenu.addAction(self.tr("Remove Project"))
action.triggered.connect(self._deleteSelectedItem) action.triggered.connect(self._deleteSelectedItem)
ctxMenu.exec_(self.mapToGlobal(pos)) ctxMenu.exec(self.mapToGlobal(pos))
ctxMenu.deleteLater() ctxMenu.deleteLater()
return return
+2 -2
View File
@@ -142,7 +142,7 @@ def projPath(fncPath):
@pytest.fixture(scope="function") @pytest.fixture(scope="function")
def mockGUI(qtbot, monkeypatch): def mockGUI(qtbot, monkeypatch):
"""Create a mock instance of novelWriter's main GUI class.""" """Create a mock instance of novelWriter's main GUI class."""
monkeypatch.setattr(QMessageBox, "exec_", lambda *a: None) monkeypatch.setattr(QMessageBox, "exec", lambda *a: None)
monkeypatch.setattr(QMessageBox, "result", lambda *a: QMessageBox.Yes) monkeypatch.setattr(QMessageBox, "result", lambda *a: QMessageBox.Yes)
gui = MockGuiMain() gui = MockGuiMain()
theme = MockTheme() theme = MockTheme()
@@ -154,7 +154,7 @@ def mockGUI(qtbot, monkeypatch):
@pytest.fixture(scope="function") @pytest.fixture(scope="function")
def nwGUI(qtbot, monkeypatch, functionFixture): def nwGUI(qtbot, monkeypatch, functionFixture):
"""Create an instance of the novelWriter GUI.""" """Create an instance of the novelWriter GUI."""
monkeypatch.setattr(QMessageBox, "exec_", lambda *a: None) monkeypatch.setattr(QMessageBox, "exec", lambda *a: None)
monkeypatch.setattr(QMessageBox, "result", lambda *a: QMessageBox.Yes) monkeypatch.setattr(QMessageBox, "result", lambda *a: QMessageBox.Yes)
nwGUI = main(["--testmode", f"--config={_TMP_CONF}", f"--data={_TMP_CONF}"]) nwGUI = main(["--testmode", f"--config={_TMP_CONF}", f"--data={_TMP_CONF}"])
+4 -4
View File
@@ -72,27 +72,27 @@ def testBaseError_Handler(qtbot, monkeypatch, nwGUI):
""" """
# Normal shutdown # Normal shutdown
with monkeypatch.context() as mp: with monkeypatch.context() as mp:
mp.setattr(NWErrorMessage, "exec_", lambda *a: None) mp.setattr(NWErrorMessage, "exec", lambda *a: None)
mp.setattr("PyQt5.QtWidgets.QApplication.exit", lambda *a: None) mp.setattr("PyQt5.QtWidgets.QApplication.exit", lambda *a: None)
exceptionHandler(Exception, "Error Message", None) # type: ignore exceptionHandler(Exception, "Error Message", None) # type: ignore
# Should not crash when no GUI is found # Should not crash when no GUI is found
with monkeypatch.context() as mp: with monkeypatch.context() as mp:
mp.setattr(NWErrorMessage, "exec_", lambda *a: None) mp.setattr(NWErrorMessage, "exec", lambda *a: None)
mp.setattr("PyQt5.QtWidgets.QApplication.exit", lambda *a: None) mp.setattr("PyQt5.QtWidgets.QApplication.exit", lambda *a: None)
mp.setattr("PyQt5.QtWidgets.QApplication.topLevelWidgets", lambda: []) mp.setattr("PyQt5.QtWidgets.QApplication.topLevelWidgets", lambda: [])
exceptionHandler(Exception, "Error Message", None) # type: ignore exceptionHandler(Exception, "Error Message", None) # type: ignore
# Should handle QApplication failing # Should handle QApplication failing
with monkeypatch.context() as mp: with monkeypatch.context() as mp:
mp.setattr(NWErrorMessage, "exec_", lambda *a: None) mp.setattr(NWErrorMessage, "exec", lambda *a: None)
mp.setattr("PyQt5.QtWidgets.QApplication.exit", lambda *a: None) mp.setattr("PyQt5.QtWidgets.QApplication.exit", lambda *a: None)
mp.setattr("PyQt5.QtWidgets.QApplication.topLevelWidgets", causeException) mp.setattr("PyQt5.QtWidgets.QApplication.topLevelWidgets", causeException)
exceptionHandler(Exception, "Error Message", None) # type: ignore exceptionHandler(Exception, "Error Message", None) # type: ignore
# Should handle failing to close main GUI # Should handle failing to close main GUI
with monkeypatch.context() as mp: with monkeypatch.context() as mp:
mp.setattr(NWErrorMessage, "exec_", lambda *a: None) mp.setattr(NWErrorMessage, "exec", lambda *a: None)
mp.setattr("PyQt5.QtWidgets.QApplication.exit", lambda *a: None) mp.setattr("PyQt5.QtWidgets.QApplication.exit", lambda *a: None)
mp.setattr(nwGUI, "closeMain", causeException) mp.setattr(nwGUI, "closeMain", causeException)
exceptionHandler(Exception, "Error Message", None) # type: ignore exceptionHandler(Exception, "Error Message", None) # type: ignore
+2 -2
View File
@@ -70,7 +70,7 @@ def testBaseInit_Launch(caplog, monkeypatch, fncPath):
monkeypatch.setattr("PyQt5.QtWidgets.QApplication.setApplicationVersion", lambda *a: None) monkeypatch.setattr("PyQt5.QtWidgets.QApplication.setApplicationVersion", lambda *a: None)
monkeypatch.setattr("PyQt5.QtWidgets.QApplication.setWindowIcon", lambda *a: None) monkeypatch.setattr("PyQt5.QtWidgets.QApplication.setWindowIcon", lambda *a: None)
monkeypatch.setattr("PyQt5.QtWidgets.QApplication.setOrganizationDomain", lambda *a: None) monkeypatch.setattr("PyQt5.QtWidgets.QApplication.setOrganizationDomain", lambda *a: None)
monkeypatch.setattr("PyQt5.QtWidgets.QApplication.exec_", lambda *a: 0) monkeypatch.setattr("PyQt5.QtWidgets.QApplication.exec", lambda *a: 0)
with pytest.raises(SystemExit) as ex: with pytest.raises(SystemExit) as ex:
main([f"--config={fncPath}", f"--data={fncPath}"]) main([f"--config={fncPath}", f"--data={fncPath}"])
assert ex.value.code == 0 assert ex.value.code == 0
@@ -148,7 +148,7 @@ def testBaseInit_Imports(caplog, monkeypatch, fncPath):
"""Check import error handling.""" """Check import error handling."""
monkeypatch.setattr("novelwriter.guimain.GuiMain", MockGuiMain) monkeypatch.setattr("novelwriter.guimain.GuiMain", MockGuiMain)
monkeypatch.setattr("PyQt5.QtWidgets.QApplication.__init__", lambda *a: None) monkeypatch.setattr("PyQt5.QtWidgets.QApplication.__init__", lambda *a: None)
monkeypatch.setattr("PyQt5.QtWidgets.QApplication.exec_", lambda *a: 0) monkeypatch.setattr("PyQt5.QtWidgets.QApplication.exec", lambda *a: 0)
monkeypatch.setattr("PyQt5.QtWidgets.QErrorMessage.__init__", lambda *a: None) monkeypatch.setattr("PyQt5.QtWidgets.QErrorMessage.__init__", lambda *a: None)
monkeypatch.setattr("PyQt5.QtWidgets.QErrorMessage.resize", lambda *a: None) monkeypatch.setattr("PyQt5.QtWidgets.QErrorMessage.resize", lambda *a: None)
monkeypatch.setattr("PyQt5.QtWidgets.QErrorMessage.showMessage", lambda *a: None) monkeypatch.setattr("PyQt5.QtWidgets.QErrorMessage.showMessage", lambda *a: None)
+1 -1
View File
@@ -129,7 +129,7 @@ def testBaseSharedData_Projects(monkeypatch, caplog, fncPath):
@pytest.mark.base @pytest.mark.base
def testBaseSharedData_Alerts(qtbot, monkeypatch, caplog): def testBaseSharedData_Alerts(qtbot, monkeypatch, caplog):
"""Test SharedData class alert helper functions.""" """Test SharedData class alert helper functions."""
monkeypatch.setattr(QMessageBox, "exec_", lambda *a: None) monkeypatch.setattr(QMessageBox, "exec", lambda *a: None)
monkeypatch.setattr(QMessageBox, "result", lambda *a: QMessageBox.Yes) monkeypatch.setattr(QMessageBox, "result", lambda *a: QMessageBox.Yes)
shared = SharedData() shared = SharedData()
+2 -2
View File
@@ -32,7 +32,7 @@ from novelwriter.dialogs.editlabel import GuiEditLabel
@pytest.mark.gui @pytest.mark.gui
def testDlgOther_QuoteSelect(qtbot, monkeypatch, nwGUI): def testDlgOther_QuoteSelect(qtbot, monkeypatch, nwGUI):
"""Test the quote symbols dialog.""" """Test the quote symbols dialog."""
monkeypatch.setattr(GuiQuoteSelect, "exec_", lambda *a: None) monkeypatch.setattr(GuiQuoteSelect, "exec", lambda *a: None)
nwQuot = GuiQuoteSelect(nwGUI) nwQuot = GuiQuoteSelect(nwGUI)
nwQuot.show() nwQuot.show()
@@ -68,7 +68,7 @@ def testDlgOther_QuoteSelect(qtbot, monkeypatch, nwGUI):
@pytest.mark.gui @pytest.mark.gui
def testDlgOther_EditLabel(qtbot, monkeypatch): def testDlgOther_EditLabel(qtbot, monkeypatch):
"""Test the label editor dialog.""" """Test the label editor dialog."""
monkeypatch.setattr(GuiEditLabel, "exec_", lambda *a: None) monkeypatch.setattr(GuiEditLabel, "exec", lambda *a: None)
with monkeypatch.context() as mp: with monkeypatch.context() as mp:
mp.setattr(GuiEditLabel, "result", lambda *a: QDialog.Accepted) mp.setattr(GuiEditLabel, "result", lambda *a: QDialog.Accepted)
+1 -1
View File
@@ -38,7 +38,7 @@ KEY_DELAY = 1
def testDlgPreferences_Main(qtbot, monkeypatch, nwGUI, tstPaths): def testDlgPreferences_Main(qtbot, monkeypatch, nwGUI, tstPaths):
"""Test the preferences dialog loading.""" """Test the preferences dialog loading."""
monkeypatch.setattr(SHARED._spelling, "listDictionaries", lambda: [("en", "English [en]")]) monkeypatch.setattr(SHARED._spelling, "listDictionaries", lambda: [("en", "English [en]")])
monkeypatch.setattr(GuiPreferences, "exec_", lambda *a: None) monkeypatch.setattr(GuiPreferences, "exec", lambda *a: None)
# Load GUI with standard values # Load GUI with standard values
nwGUI.mainMenu.aPreferences.activate(QAction.ActionEvent.Trigger) nwGUI.mainMenu.aPreferences.activate(QAction.ActionEvent.Trigger)
@@ -42,7 +42,7 @@ def testDlgProjSettings_Dialog(qtbot, monkeypatch, nwGUI):
test, but are instead tested in the individual tab tests. test, but are instead tested in the individual tab tests.
""" """
# Block the GUI blocking thread # Block the GUI blocking thread
monkeypatch.setattr(GuiProjectSettings, "exec_", lambda *a: None) monkeypatch.setattr(GuiProjectSettings, "exec", lambda *a: None)
monkeypatch.setattr(GuiProjectSettings, "result", lambda *a: QDialog.Accepted) monkeypatch.setattr(GuiProjectSettings, "result", lambda *a: QDialog.Accepted)
# Check that we cannot open when there is no project # Check that we cannot open when there is no project
+1 -1
View File
@@ -38,7 +38,7 @@ def testDlgWordList_Dialog(qtbot, monkeypatch, nwGUI, fncPath, projPath):
"""test the word list editor.""" """test the word list editor."""
buildTestProject(nwGUI, projPath) buildTestProject(nwGUI, projPath)
monkeypatch.setattr(GuiWordList, "exec_", lambda *a: None) monkeypatch.setattr(GuiWordList, "exec", lambda *a: None)
monkeypatch.setattr(GuiWordList, "result", lambda *a: QDialog.Accepted) monkeypatch.setattr(GuiWordList, "result", lambda *a: QDialog.Accepted)
monkeypatch.setattr(GuiWordList, "accept", lambda *a: None) monkeypatch.setattr(GuiWordList, "accept", lambda *a: None)
+1 -1
View File
@@ -244,7 +244,7 @@ def testGuiEditor_MetaData(qtbot, nwGUI, projPath, mockRnd):
@pytest.mark.gui @pytest.mark.gui
def testGuiEditor_ContextMenu(monkeypatch, qtbot, nwGUI, projPath, mockRnd): def testGuiEditor_ContextMenu(monkeypatch, qtbot, nwGUI, projPath, mockRnd):
"""Test the editor context menu.""" """Test the editor context menu."""
monkeypatch.setattr(QMenu, "exec_", lambda *a: None) monkeypatch.setattr(QMenu, "exec", lambda *a: None)
buildTestProject(nwGUI, projPath) buildTestProject(nwGUI, projPath)
assert nwGUI.openDocument(C.hSceneDoc) is True assert nwGUI.openDocument(C.hSceneDoc) is True
+1 -1
View File
@@ -146,7 +146,7 @@ def testGuiViewer_Main(qtbot, monkeypatch, nwGUI, prjLipsum):
docViewer.setTextCursor(cursor) docViewer.setTextCursor(cursor)
docViewer._makeSelection(QTextCursor.WordUnderCursor) docViewer._makeSelection(QTextCursor.WordUnderCursor)
with monkeypatch.context() as mp: with monkeypatch.context() as mp:
mp.setattr(QMenu, "exec_", mockExec) mp.setattr(QMenu, "exec", mockExec)
docViewer._openContextMenu(docViewer.cursorRect().center()) docViewer._openContextMenu(docViewer.cursorRect().center())
assert menuOpened assert menuOpened
+2 -2
View File
@@ -60,7 +60,7 @@ def testGuiMain_ProjectBlocker(nwGUI):
@pytest.mark.gui @pytest.mark.gui
def testGuiMain_Launch(qtbot, monkeypatch, nwGUI, projPath): def testGuiMain_Launch(qtbot, monkeypatch, nwGUI, projPath):
"""Test the handling of launch tasks.""" """Test the handling of launch tasks."""
monkeypatch.setattr(GuiWelcome, "exec_", lambda *a: None) monkeypatch.setattr(GuiWelcome, "exec", lambda *a: None)
CONFIG.lastNotes = "0x0" CONFIG.lastNotes = "0x0"
buildTestProject(nwGUI, projPath) buildTestProject(nwGUI, projPath)
@@ -511,7 +511,7 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, projPath, tstPaths, mockRnd):
assert "test" in suggest assert "test" in suggest
with monkeypatch.context() as mp: with monkeypatch.context() as mp:
mp.setattr(QMenu, "exec_", lambda *a: None) mp.setattr(QMenu, "exec", lambda *a: None)
docEditor.setCursorPosition(errPos) docEditor.setCursorPosition(errPos)
docEditor._openContextFromCursor() docEditor._openContextFromCursor()
+2 -2
View File
@@ -47,8 +47,8 @@ LANG_DATA = CONFIG.listLanguages(CONFIG.LANG_NW)
@pytest.mark.parametrize("language", [a for a, b in LANG_DATA]) @pytest.mark.parametrize("language", [a for a, b in LANG_DATA])
def testGuiI18n_Localisation(qtbot, monkeypatch, language, nwGUI, projPath): def testGuiI18n_Localisation(qtbot, monkeypatch, language, nwGUI, projPath):
"""Test loading the gui with a specific language.""" """Test loading the gui with a specific language."""
monkeypatch.setattr(QDialog, "exec_", lambda *a: None) monkeypatch.setattr(QDialog, "exec", lambda *a: None)
monkeypatch.setattr(QMessageBox, "exec_", lambda *a: None) monkeypatch.setattr(QMessageBox, "exec", lambda *a: None)
monkeypatch.setattr(QMessageBox, "result", lambda *a: QMessageBox.Yes) monkeypatch.setattr(QMessageBox, "result", lambda *a: QMessageBox.Yes)
# Set the test language # Set the test language
+3 -3
View File
@@ -539,7 +539,7 @@ def testGuiProjTree_MergeDocuments(qtbot, monkeypatch, nwGUI, projPath, mockRnd,
mergeData = {} mergeData = {}
monkeypatch.setattr(GuiDocMerge, "__init__", lambda *a: None) monkeypatch.setattr(GuiDocMerge, "__init__", lambda *a: None)
monkeypatch.setattr(GuiDocMerge, "exec_", lambda *a: None) monkeypatch.setattr(GuiDocMerge, "exec", lambda *a: None)
monkeypatch.setattr(GuiDocMerge, "result", lambda *a: QDialog.Accepted) monkeypatch.setattr(GuiDocMerge, "result", lambda *a: QDialog.Accepted)
monkeypatch.setattr(GuiDocMerge, "getData", lambda *a: mergeData) monkeypatch.setattr(GuiDocMerge, "getData", lambda *a: mergeData)
@@ -640,7 +640,7 @@ def testGuiProjTree_SplitDocument(qtbot, monkeypatch, nwGUI, projPath, mockRnd,
splitText = [] splitText = []
monkeypatch.setattr(GuiDocSplit, "__init__", lambda *a: None) monkeypatch.setattr(GuiDocSplit, "__init__", lambda *a: None)
monkeypatch.setattr(GuiDocSplit, "exec_", lambda *a: None) monkeypatch.setattr(GuiDocSplit, "exec", lambda *a: None)
monkeypatch.setattr(GuiDocSplit, "result", lambda *a: QDialog.Accepted) monkeypatch.setattr(GuiDocSplit, "result", lambda *a: QDialog.Accepted)
monkeypatch.setattr(GuiDocSplit, "getData", lambda *a: (splitData, splitText)) monkeypatch.setattr(GuiDocSplit, "getData", lambda *a: (splitData, splitText))
@@ -1162,7 +1162,7 @@ def testGuiProjTree_ContextMenu(qtbot, monkeypatch, nwGUI, projPath, mockRnd):
# Pop the menu # Pop the menu
with monkeypatch.context() as mp: with monkeypatch.context() as mp:
mp.setattr(QMenu, "exec_", lambda *a: None) mp.setattr(QMenu, "exec", lambda *a: None)
projTree.clearSelection() projTree.clearSelection()
# No item under menu # No item under menu
+1 -1
View File
@@ -60,7 +60,7 @@ def testToolLipsum_Main(qtbot, monkeypatch, nwGUI, projPath, mockRnd):
assert nwGUI.openDocument(C.hSceneDoc) is True assert nwGUI.openDocument(C.hSceneDoc) is True
nwGUI.docEditor.setCursorLine(3) nwGUI.docEditor.setCursorLine(3)
with monkeypatch.context() as mp: with monkeypatch.context() as mp:
mp.setattr(GuiLipsum, "exec_", lambda *a: None) mp.setattr(GuiLipsum, "exec", lambda *a: None)
mp.setattr(GuiLipsum, "lipsumText", "FooBar") mp.setattr(GuiLipsum, "lipsumText", "FooBar")
nwGUI.mainMenu.aLipsumText.activate(QAction.Trigger) nwGUI.mainMenu.aLipsumText.activate(QAction.Trigger)
assert nwGUI.docEditor.getText() == "### New Scene\n\nFooBar" assert nwGUI.docEditor.getText() == "### New Scene\n\nFooBar"
+2 -2
View File
@@ -278,7 +278,7 @@ def testManuscript_Features(monkeypatch, qtbot, nwGUI, projPath, mockRnd):
build._changed = True build._changed = True
manus.buildList.clearSelection() manus.buildList.clearSelection()
with monkeypatch.context() as mp: with monkeypatch.context() as mp:
mp.setattr("novelwriter.tools.manusbuild.GuiManuscriptBuild.exec_", lambda *a: None) mp.setattr("novelwriter.tools.manusbuild.GuiManuscriptBuild.exec", lambda *a: None)
manus.buildList.setCurrentRow(0) manus.buildList.setCurrentRow(0)
manus.btnBuild.click() manus.btnBuild.click()
@@ -313,7 +313,7 @@ def testManuscript_Print(monkeypatch, qtbot: QtBot, nwGUI: GuiMain, projPath: Pa
assert manus.docPreview.toPlainText().strip() != "" assert manus.docPreview.toPlainText().strip() != ""
with monkeypatch.context() as mp: with monkeypatch.context() as mp:
mp.setattr(QPrintPreviewDialog, "exec_", lambda *a: None) mp.setattr(QPrintPreviewDialog, "exec", lambda *a: None)
manus.btnPrint.click() manus.btnPrint.click()
for obj in manus.children(): for obj in manus.children():
if isinstance(obj, QPrintPreviewDialog): if isinstance(obj, QPrintPreviewDialog):
+1 -1
View File
@@ -70,7 +70,7 @@ def testToolWelcome_Main(qtbot: QtBot, monkeypatch, nwGUI, fncPath):
@pytest.mark.gui @pytest.mark.gui
def testToolWelcome_Open(qtbot: QtBot, monkeypatch, nwGUI, fncPath): def testToolWelcome_Open(qtbot: QtBot, monkeypatch, nwGUI, fncPath):
"""Test the open tab in the Welcome window.""" """Test the open tab in the Welcome window."""
monkeypatch.setattr(QMenu, "exec_", lambda *a: None) monkeypatch.setattr(QMenu, "exec", lambda *a: None)
monkeypatch.setattr(QMenu, "deleteLater", lambda *a: None) monkeypatch.setattr(QMenu, "deleteLater", lambda *a: None)
CONFIG.recentProjects.update("/stuff/project_one", "Project One", 12345, 1690000000) CONFIG.recentProjects.update("/stuff/project_one", "Project One", 12345, 1690000000)