Add coverage of some missed lines

This commit is contained in:
Veronica Berglyd Olsen
2023-12-30 16:52:24 +01:00
parent bc17305c4f
commit 05e9729c22
5 changed files with 20 additions and 12 deletions
+2 -1
View File
@@ -333,7 +333,8 @@ class ProjectBuilder:
self._path = Path(path).resolve() self._path = Path(path).resolve()
if data.get("sample", False): if data.get("sample", False):
return self._extractSampleProject(self._path) return self._extractSampleProject(self._path)
elif data.get("template"): elif data.get("template"): # pragma: no cover
# Not implemented yet
return True return True
else: else:
return self._buildAndPopulate(self._path, data) return self._buildAndPopulate(self._path, data)
+8 -7
View File
@@ -216,16 +216,17 @@ class SharedData(QObject):
QThreadPool.globalInstance().start(runnable, priority=priority) QThreadPool.globalInstance().start(runnable, priority=priority)
return return
def getProjectPath(self, parent: QWidget, allowZip: bool = False) -> Path | None: def getProjectPath(self, parent: QWidget, path: str | Path | None = None,
allowZip: bool = False) -> Path | None:
"""Open the file dialog and select a novelWriter project file.""" """Open the file dialog and select a novelWriter project file."""
ext = [] ext = [
ext.append(self.tr("novelWriter Project File ({0})").format(nwFiles.PROJ_FILE)) self.tr("novelWriter Project File ({0})").format(nwFiles.PROJ_FILE),
self.tr("All files ({0})").format("*"),
]
if allowZip: if allowZip:
ext.append(self.tr("Zip Archives ({0})").format("*.zip")) ext.insert(1, self.tr("Zip Archives ({0})").format("*.zip"))
ext.append(self.tr("All files ({0})").format("*"))
projFile, _ = QFileDialog.getOpenFileName( projFile, _ = QFileDialog.getOpenFileName(
parent, self.tr("Open Project"), "", filter=";;".join(ext) parent, self.tr("Open Project"), str(path or ""), filter=";;".join(ext)
) )
return Path(projFile) if projFile else None return Path(projFile) if projFile else None
+2 -1
View File
@@ -189,7 +189,8 @@ class GuiWelcome(QDialog):
@pyqtSlot() @pyqtSlot()
def _browseForProject(self) -> None: def _browseForProject(self) -> None:
"""Browse for a project to open.""" """Browse for a project to open."""
if path := SHARED.getProjectPath(self, allowZip=False): if path := SHARED.getProjectPath(self, path=CONFIG.lastPath(), allowZip=False):
CONFIG.setLastPath(path)
self._openProjectPath(path) self._openProjectPath(path)
return return
+7 -2
View File
@@ -25,7 +25,7 @@ import pytest
from tools import buildTestProject from tools import buildTestProject
from mocked import MockGuiMain, MockTheme from mocked import MockGuiMain, MockTheme
from PyQt5.QtWidgets import QMessageBox from PyQt5.QtWidgets import QFileDialog, QMessageBox, QWidget
from novelwriter.shared import SharedData from novelwriter.shared import SharedData
from novelwriter.core.project import NWProject from novelwriter.core.project import NWProject
@@ -66,7 +66,7 @@ def testBaseSharedData_Init():
@pytest.mark.base @pytest.mark.base
def testBaseSharedData_Projects(fncPath, caplog): def testBaseSharedData_Projects(monkeypatch, caplog, fncPath):
"""Test SharedData handling of projects.""" """Test SharedData handling of projects."""
project = NWProject() project = NWProject()
buildTestProject(project, fncPath) buildTestProject(project, fncPath)
@@ -118,6 +118,11 @@ def testBaseSharedData_Projects(fncPath, caplog):
assert shared.hasProject is False assert shared.hasProject is False
assert isinstance(shared.projectLock, list) assert isinstance(shared.projectLock, list)
# Test browsing for projects
with monkeypatch.context() as mp:
mp.setattr(QFileDialog, "getOpenFileName", lambda *a, **k: (a[2], ""))
assert shared.getProjectPath(QWidget(), fncPath, allowZip=True) == fncPath
# END Test testBaseSharedData_Projects # END Test testBaseSharedData_Projects
+1 -1
View File
@@ -30,8 +30,8 @@ from PyQt5.QtCore import QPoint, Qt
from PyQt5.QtWidgets import QAction, QFileDialog, QMenu from PyQt5.QtWidgets import QAction, QFileDialog, QMenu
from novelwriter import CONFIG, SHARED from novelwriter import CONFIG, SHARED
from novelwriter.constants import nwFiles
from novelwriter.enum import nwItemClass from novelwriter.enum import nwItemClass
from novelwriter.constants import nwFiles
from novelwriter.tools.welcome import GuiWelcome from novelwriter.tools.welcome import GuiWelcome