Let the shared class handle project open/save/close and recreating the project instance

This commit is contained in:
Veronica Berglyd Olsen
2023-08-13 20:16:37 +02:00
parent 8154293d92
commit 150f6603cd
10 changed files with 79 additions and 86 deletions
+6 -5
View File
@@ -176,7 +176,7 @@ def testCoreProject_Open(monkeypatch, caplog, mockGUI, fncPath, mockRnd):
theProject.storage._lockFilePath = fncPath / nwFiles.PROJ_LOCK
assert theProject.storage.writeLockFile() is True
assert theProject.openProject(fncPath) is False
assert isinstance(theProject.getLockStatus(), list)
assert isinstance(theProject.lockStatus, list)
# Fail to read lockfile (which still opens the project)
with monkeypatch.context() as mp:
@@ -189,9 +189,10 @@ def testCoreProject_Open(monkeypatch, caplog, mockGUI, fncPath, mockRnd):
# Force open with lockfile
theProject.storage._lockFilePath = fncPath / nwFiles.PROJ_LOCK
assert theProject.storage.writeLockFile() is True
assert theProject.openProject(fncPath, overrideLock=True) is True
theProject.storage.clearLockFile()
assert theProject.openProject(fncPath) is True
theProject.closeProject()
assert theProject.getLockStatus() is None
assert theProject.lockStatus is None
# Fail getting xml reader
with monkeypatch.context() as mp:
@@ -331,7 +332,7 @@ def testCoreProject_AccessItems(mockGUI, fncPath, mockRnd):
assert theProject.tree[nHandle].itemParent == "cba9876543210"
retOrder = []
for tItem in theProject.getProjectItems():
for tItem in theProject.iterProjectItems():
retOrder.append(tItem.itemHandle)
assert retOrder == [
@@ -482,7 +483,7 @@ def testCoreProject_Methods(monkeypatch, mockGUI, fncPath, mockRnd):
theProject._session._start = 1600000000
with monkeypatch.context() as mp:
mp.setattr("novelwriter.core.project.time", lambda: 1600005600)
assert theProject.getCurrentEditTime() == 6834
assert theProject.currentEditTime == 6834
# Trash folder
# Should create on first call, and just returned on later calls
+3 -3
View File
@@ -104,9 +104,8 @@ def testGuiMain_Launch(qtbot, monkeypatch, nwGUI, prjLipsum):
@pytest.mark.gui
def testGuiMain_NewProject(monkeypatch, nwGUI, projPath):
"""Test creating a new project.
"""
# No data
"""Test creating a new project."""
# Open wizard, but return no data
with monkeypatch.context() as mp:
mp.setattr(GuiProjectWizard, "exec_", lambda *a: None)
assert nwGUI.newProject(projData=None) is False
@@ -116,6 +115,7 @@ def testGuiMain_NewProject(monkeypatch, nwGUI, projPath):
SHARED.project._valid = True
mp.setattr(QMessageBox, "result", lambda *a: QMessageBox.No)
assert nwGUI.newProject(projData={"projPath": projPath}) is False
SHARED.project._valid = False
# No project path
assert nwGUI.newProject(projData={}) is False
+5 -4
View File
@@ -377,13 +377,14 @@ def testToolWritingStats_Main(qtbot, monkeypatch, nwGUI, projPath, tstPaths):
# IOError
# =======
monkeypatch.setattr("builtins.open", causeOSError)
assert not sessLog._loadLogFile()
assert not sessLog._saveData(sessLog.FMT_CSV)
with monkeypatch.context() as mp:
mp.setattr("builtins.open", causeOSError)
assert not sessLog._loadLogFile()
assert not sessLog._saveData(sessLog.FMT_CSV)
# qtbot.stop()
sessLog._doClose()
assert nwGUI.closeProject()
assert nwGUI.closeProject() is True
# END Test testToolWritingStats_Main
-1
View File
@@ -168,7 +168,6 @@ def buildTestProject(obj, projPath):
nwGUI = obj
project = obj.project
project.clearProject()
project.storage.openProjectInPlace(projPath)
project.setDefaultStatusImport()