Monkeypatched a couple more file dialogs

This commit is contained in:
Veronica K. B. Olsen
2020-09-28 23:40:49 +02:00
parent 5152d80ac4
commit 9f8dd4abf3
5 changed files with 58 additions and 34 deletions
+2
View File
@@ -443,6 +443,8 @@ class VerticalTabBar(QTabBar):
class QuotesDialog(QDialog):
selectedQuote = ""
def __init__(self, theParent=None, currentQuote="\""):
QDialog.__init__(self, parent=theParent)
+13 -14
View File
@@ -178,20 +178,19 @@ class GuiProjectLoad(QDialog):
"""Browse for a folder path.
"""
logger.verbose("GuiProjectLoad browse button clicked")
if self.mainConf.showGUI:
dlgOpt = QFileDialog.Options()
dlgOpt |= QFileDialog.DontUseNativeDialog
projFile, _ = QFileDialog.getOpenFileName(
self, "Open novelWriter Project", "",
"novelWriter Project File (%s);;All Files (*)" % nwFiles.PROJ_FILE,
options=dlgOpt
)
if projFile:
thePath = path.abspath(path.dirname(projFile))
self.selPath.setText(thePath)
self.openPath = thePath
self.openState = self.OPEN_STATE
self.accept()
dlgOpt = QFileDialog.Options()
dlgOpt |= QFileDialog.DontUseNativeDialog
projFile, _ = QFileDialog.getOpenFileName(
self, "Open novelWriter Project", "",
"novelWriter Project File (%s);;All Files (*)" % nwFiles.PROJ_FILE,
options=dlgOpt
)
if projFile:
thePath = path.abspath(path.dirname(projFile))
self.selPath.setText(thePath)
self.openPath = thePath
self.openState = self.OPEN_STATE
self.accept()
return
+9 -10
View File
@@ -326,16 +326,15 @@ class GuiWritingStats(QDialog):
if not path.isdir(saveDir):
saveDir = self.mainConf.homePath
if self.mainConf.showGUI:
dlgOpt = QFileDialog.Options()
dlgOpt |= QFileDialog.DontUseNativeDialog
saveTo = QFileDialog.getSaveFileName(
self, "Save Document As", savePath, options=dlgOpt
)
if saveTo[0]:
savePath = saveTo[0]
else:
return False
dlgOpt = QFileDialog.Options()
dlgOpt |= QFileDialog.DontUseNativeDialog
saveTo = QFileDialog.getSaveFileName(
self, "Save Document As", savePath, options=dlgOpt
)
if saveTo:
savePath = saveTo[0]
else:
return False
self.mainConf.setLastPath(savePath)
+1 -1
View File
@@ -49,7 +49,7 @@ highlightquotes = False
highlightemph = False
[Backup]
backuppath =
backuppath = some/dir
backuponclose = True
askbeforebackup = True
+33 -9
View File
@@ -14,7 +14,7 @@ from os import path
from PyQt5.QtCore import Qt, QItemSelectionModel
from PyQt5.QtWidgets import (
QDialogButtonBox, QTreeWidgetItem, QListWidgetItem, QDialog, QAction,
QMessageBox, QFileDialog
QMessageBox, QFileDialog, QFontDialog
)
from nw.gui import (
@@ -198,7 +198,7 @@ def testItemEditor(qtbot, yesToAll, nwFuncTemp, nwTempGUI, nwRef, nwTemp):
# qtbot.stopForInteraction()
@pytest.mark.gui
def testWritingStatsExport(qtbot, yesToAll, nwFuncTemp, nwTemp):
def testWritingStatsExport(qtbot, monkeypatch, yesToAll, nwFuncTemp, nwTemp):
nwGUI = nw.main(["--testmode", "--config=%s" % nwFuncTemp, "--data=%s" % nwTemp])
qtbot.addWidget(nwGUI)
nwGUI.show()
@@ -263,6 +263,10 @@ def testWritingStatsExport(qtbot, yesToAll, nwFuncTemp, nwTemp):
assert isinstance(sessLog, GuiWritingStats)
qtbot.wait(stepDelay)
monkeypatch.setattr(QFileDialog, "getSaveFileName", lambda *args, **kwargs: [])
assert not sessLog._saveData(sessLog.FMT_CSV)
monkeypatch.setattr(QFileDialog, "getSaveFileName", lambda ss, tt, pp, options: [pp])
assert sessLog._saveData(sessLog.FMT_CSV)
qtbot.wait(stepDelay)
assert sessLog._saveData(sessLog.FMT_JSON)
@@ -913,9 +917,16 @@ def testLoadProject(qtbot, monkeypatch, yesToAll, nwMinimal, nwTemp):
nwLoad._keyPressDelete()
assert nwLoad.listBox.topLevelItemCount() == recentCount - 1
nwLoad.close()
getFile = path.join(nwMinimal, "nwProject.nwx")
monkeypatch.setattr(QFileDialog, "getOpenFileName", lambda *args, **kwargs: (getFile, None))
qtbot.mouseClick(nwLoad.browseButton, Qt.LeftButton)
assert nwLoad.openPath == nwMinimal
assert nwLoad.openState == nwLoad.OPEN_STATE
# qtbot.stopForInteraction()
nwLoad.close()
nwGUI.closeMain()
nwGUI.close()
@pytest.mark.gui
def testPreferences(qtbot, monkeypatch, yesToAll, nwMinimal, nwTemp, nwRef, tmpConf):
@@ -927,8 +938,6 @@ def testPreferences(qtbot, monkeypatch, yesToAll, nwMinimal, nwTemp, nwRef, tmpC
assert nwGUI.openProject(nwMinimal)
monkeypatch.setattr(QMessageBox, "information", lambda *args, **kwargs: None)
monkeypatch.setattr(GuiPreferences, "exec_", lambda *args: None)
monkeypatch.setattr(GuiPreferences, "result", lambda *args: QDialog.Accepted)
nwGUI.mainMenu.aPreferences.activate(QAction.Trigger)
@@ -952,7 +961,7 @@ def testPreferences(qtbot, monkeypatch, yesToAll, nwMinimal, nwTemp, nwRef, tmpC
qtbot.wait(keyDelay)
tabGeneral = nwPrefs.tabGeneral
nwPrefs._tabBox.setCurrentWidget(tabGeneral)
tabGeneral.backupPath = nwTemp
tabGeneral.backupPath = "no/where"
qtbot.wait(keyDelay)
assert not tabGeneral.preferDarkIcons.isChecked()
@@ -964,6 +973,16 @@ def testPreferences(qtbot, monkeypatch, yesToAll, nwMinimal, nwTemp, nwRef, tmpC
qtbot.mouseClick(tabGeneral.showFullPath, Qt.LeftButton)
assert not tabGeneral.showFullPath.isChecked()
# Check Browse button
monkeypatch.setattr(QFileDialog, "getExistingDirectory", lambda *args, **kwargs: "")
assert not tabGeneral._backupFolder()
monkeypatch.setattr(QFileDialog, "getExistingDirectory", lambda *args, **kwargs: "some/dir")
qtbot.mouseClick(tabGeneral.backupGetPath, Qt.LeftButton)
# Check font button
monkeypatch.setattr(QFontDialog, "getFont", lambda font, obj: (font, True))
qtbot.mouseClick(tabGeneral.fontButton, Qt.LeftButton)
qtbot.wait(keyDelay)
assert not tabGeneral.backupOnClose.isChecked()
qtbot.mouseClick(tabGeneral.backupOnClose, Qt.LeftButton)
@@ -979,6 +998,9 @@ def testPreferences(qtbot, monkeypatch, yesToAll, nwMinimal, nwTemp, nwRef, tmpC
tabLayout = nwPrefs.tabLayout
nwPrefs._tabBox.setCurrentWidget(tabLayout)
qtbot.wait(keyDelay)
qtbot.mouseClick(tabLayout.fontButton, Qt.LeftButton)
qtbot.wait(keyDelay)
tabLayout.textStyleSize.setValue(13)
tabLayout.textFlowMax.setValue(700)
@@ -1050,12 +1072,14 @@ def testPreferences(qtbot, monkeypatch, yesToAll, nwMinimal, nwTemp, nwRef, tmpC
assert not tabAutoRep.autoReplaceDash.isEnabled()
assert not tabAutoRep.autoReplaceDots.isEnabled()
monkeypatch.setattr(QuotesDialog, "selectedQuote", "'")
monkeypatch.setattr(QuotesDialog, "exec_", lambda *args: QDialog.Accepted)
qtbot.mouseClick(tabAutoRep.btnDoubleStyleC, Qt.LeftButton)
# Save and Check Config
qtbot.mouseClick(nwPrefs.buttonBox.button(QDialogButtonBox.Ok), Qt.LeftButton)
assert tmpConf.confChanged
assert tmpConf.backupPath == nwTemp
tmpConf.backupPath = ""
tmpConf.lastPath = ""
assert nwGUI.mainConf.saveConfig()
@@ -1070,7 +1094,7 @@ def testPreferences(qtbot, monkeypatch, yesToAll, nwMinimal, nwTemp, nwRef, tmpC
ignoreLines = [
2, # Timestamp
11, 12, 13, 14, 15, 16, 17, # Window sizes
7, 25, # Fonts (depends in system default)
7, 25, # Fonts (depends on system default)
]
assert cmpFiles(testConf, refConf, ignoreLines)