Change lastPath to a Path object
This commit is contained in:
+5
-5
@@ -166,7 +166,7 @@ def tmpConf(tmpPath):
|
||||
confFile.unlink()
|
||||
theConf = Config()
|
||||
theConf.initConfig(tmpPath, tmpPath)
|
||||
theConf.setLastPath("")
|
||||
theConf.setLastPath(tmpPath)
|
||||
theConf.guiLang = "en_GB"
|
||||
return theConf
|
||||
|
||||
@@ -180,7 +180,7 @@ def fncConf(fncPath):
|
||||
confFile.unlink()
|
||||
theConf = Config()
|
||||
theConf.initConfig(fncPath, fncPath)
|
||||
theConf.setLastPath("")
|
||||
theConf.setLastPath(fncPath)
|
||||
theConf.guiLang = "en_GB"
|
||||
return theConf
|
||||
|
||||
@@ -196,7 +196,7 @@ def mockGUI(monkeypatch, tmpConf):
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def nwGUI(qtbot, monkeypatch, fncDir, fncConf):
|
||||
def nwGUI(qtbot, monkeypatch, fncPath, fncConf):
|
||||
"""Create an instance of the novelWriter GUI.
|
||||
"""
|
||||
monkeypatch.setattr(QMessageBox, "warning", lambda *a: QMessageBox.Ok)
|
||||
@@ -205,12 +205,12 @@ def nwGUI(qtbot, monkeypatch, fncDir, fncConf):
|
||||
monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes)
|
||||
|
||||
monkeypatch.setattr("novelwriter.CONFIG", fncConf)
|
||||
nwGUI = novelwriter.main(["--testmode", "--config=%s" % fncDir, "--data=%s" % fncDir])
|
||||
nwGUI = novelwriter.main(["--testmode", f"--config={fncPath}", f"--data={fncPath}"])
|
||||
qtbot.addWidget(nwGUI)
|
||||
nwGUI.show()
|
||||
qtbot.wait(20)
|
||||
|
||||
nwGUI.mainConf.lastPath = fncDir
|
||||
nwGUI.mainConf.setLastPath(fncPath)
|
||||
|
||||
yield nwGUI
|
||||
|
||||
|
||||
@@ -444,7 +444,8 @@ def testBaseConfig_SettersGetters(tmpConf, tmpDir, outDir, refDir):
|
||||
assert tmpConf.confChanged is False
|
||||
|
||||
copyfile(confFile, testFile)
|
||||
assert cmpFiles(testFile, compFile, ignoreStart=("timestamp", "lastnotes", "guilang"))
|
||||
ignore = ("timestamp", "lastnotes", "guilang", "lastpath")
|
||||
assert cmpFiles(testFile, compFile, ignoreStart=ignore)
|
||||
|
||||
# END Test testBaseConfig_SettersGetters
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import pytest
|
||||
|
||||
from shutil import copyfile
|
||||
|
||||
from tools import cmpFiles, getGuiItem
|
||||
|
||||
from PyQt5.QtCore import Qt
|
||||
@@ -215,7 +216,6 @@ def testDlgPreferences_Main(qtbot, monkeypatch, nwGUI, fncPath, tstPaths):
|
||||
nwPrefs._doClose()
|
||||
|
||||
assert theConf.confChanged
|
||||
theConf.lastPath = ""
|
||||
|
||||
assert nwGUI.mainConf.saveConfig()
|
||||
projFile = fncPath / "novelwriter.conf"
|
||||
@@ -225,7 +225,7 @@ def testDlgPreferences_Main(qtbot, monkeypatch, nwGUI, fncPath, tstPaths):
|
||||
ignTuple = (
|
||||
"timestamp", "guifont", "lastnotes", "guilang", "geometry",
|
||||
"preferences", "projcols", "mainpane", "docpane", "viewpane",
|
||||
"outlinepane", "textfont", "textsize"
|
||||
"outlinepane", "textfont", "textsize", "lastpath"
|
||||
)
|
||||
assert cmpFiles(testFile, compFile, ignoreStart=ignTuple)
|
||||
|
||||
|
||||
@@ -38,7 +38,6 @@ def testDlgProjDetails_Dialog(qtbot, nwGUI, nwLipsum):
|
||||
qtbot.wait(100)
|
||||
|
||||
# Open the Writing Stats dialog
|
||||
nwGUI.mainConf.lastPath = ""
|
||||
nwGUI.mainMenu.aProjectDetails.activate(QAction.Trigger)
|
||||
qtbot.waitUntil(lambda: getGuiItem("GuiProjectDetails") is not None, timeout=1000)
|
||||
|
||||
|
||||
@@ -156,7 +156,6 @@ def testGuiOutline_Content(qtbot, nwGUI, nwLipsum):
|
||||
"""Test the outline view.
|
||||
"""
|
||||
assert nwGUI.openProject(nwLipsum)
|
||||
nwGUI.mainConf.lastPath = nwLipsum
|
||||
|
||||
nwGUI.rebuildIndex()
|
||||
nwGUI._changeView(nwView.OUTLINE)
|
||||
|
||||
@@ -23,6 +23,8 @@ import pytest
|
||||
import os
|
||||
|
||||
from shutil import copyfile
|
||||
from pathlib import Path
|
||||
|
||||
from tools import cmpFiles, getGuiItem
|
||||
|
||||
from PyQt5.QtCore import Qt
|
||||
@@ -61,21 +63,13 @@ def testToolBuild_Main(qtbot, monkeypatch, nwGUI, nwLipsum, refDir, outDir):
|
||||
# Invalid file format
|
||||
assert not nwBuild._saveDocument(-1)
|
||||
|
||||
# Non-existent path
|
||||
with monkeypatch.context() as mp:
|
||||
mp.setattr("os.path.expanduser", lambda *a, **k: nwLipsum)
|
||||
assert nwGUI.mainConf.lastPath != nwLipsum
|
||||
nwGUI.mainConf.lastPath = "no_such_path"
|
||||
assert nwBuild._saveDocument(nwBuild.FMT_NWD)
|
||||
assert nwGUI.mainConf.lastPath == nwLipsum
|
||||
|
||||
# No path selected
|
||||
with monkeypatch.context() as mp:
|
||||
mp.setattr(QFileDialog, "getSaveFileName", lambda *a, **k: ("", ""))
|
||||
assert not nwBuild._saveDocument(nwBuild.FMT_NWD)
|
||||
|
||||
# Default Settings
|
||||
nwGUI.mainConf.lastPath = nwLipsum
|
||||
nwGUI.mainConf._lastPath = Path(nwLipsum)
|
||||
qtbot.mouseClick(nwBuild.buildNovel, Qt.LeftButton)
|
||||
|
||||
assert nwBuild._saveDocument(nwBuild.FMT_NWD)
|
||||
|
||||
@@ -67,7 +67,6 @@ def testToolProjectWizard_Handling(qtbot, monkeypatch, nwGUI, fncProj):
|
||||
# Test the Wizard Launching
|
||||
# =========================
|
||||
|
||||
nwGUI.mainConf.lastPath = " "
|
||||
monkeypatch.setattr(GuiProjectWizard, "exec_", lambda *a: None)
|
||||
|
||||
result = nwGUI.showNewProjectDialog()
|
||||
@@ -102,7 +101,6 @@ def testToolProjectWizard_Run(qtbot, monkeypatch, nwGUI, fncDir, prjType):
|
||||
"""
|
||||
monkeypatch.setattr(GuiProjectWizard, "exec_", lambda *a: None)
|
||||
|
||||
nwGUI.mainConf.lastPath = " "
|
||||
nwWiz = GuiProjectWizard(nwGUI)
|
||||
nwWiz.show()
|
||||
qtbot.addWidget(nwWiz)
|
||||
|
||||
@@ -44,7 +44,6 @@ def testToolWritingStats_Main(qtbot, monkeypatch, nwGUI, fncDir, fncProj):
|
||||
sessFile = os.path.join(fncProj, "meta", nwFiles.SESS_STATS)
|
||||
|
||||
# Open the Writing Stats dialog
|
||||
nwGUI.mainConf.lastPath = ""
|
||||
nwGUI.mainMenu.aWritingStats.activate(QAction.Trigger)
|
||||
qtbot.waitUntil(lambda: getGuiItem("GuiWritingStats") is not None, timeout=1000)
|
||||
|
||||
@@ -135,8 +134,6 @@ def testToolWritingStats_Main(qtbot, monkeypatch, nwGUI, fncDir, fncProj):
|
||||
assert sessLog._saveData(sessLog.FMT_JSON)
|
||||
qtbot.wait(100)
|
||||
|
||||
assert nwGUI.mainConf.lastPath == fncDir
|
||||
|
||||
# Check the exported files
|
||||
jsonStats = os.path.join(fncDir, "sessionStats.json")
|
||||
with open(jsonStats, mode="r", encoding="utf-8") as inFile:
|
||||
|
||||
Reference in New Issue
Block a user