Fix issues discovered when testing

This commit is contained in:
Veronica Berglyd Olsen
2023-09-01 17:34:34 +02:00
parent 03c4b91682
commit 9c7663996c
4 changed files with 23 additions and 12 deletions
+1 -1
View File
@@ -600,7 +600,7 @@ class NWProject:
self._langData = json.load(inFile) self._langData = json.load(inFile)
logger.debug("Loaded project language file: %s", langFile.name) logger.debug("Loaded project language file: %s", langFile.name)
except Exception: except Exception:
logger.error("Failed to project language file") logger.error("Failed to load project language file")
logException() logException()
return False return False
+4 -4
View File
@@ -36,7 +36,6 @@ from functools import partial
from PyQt5.QtCore import QCoreApplication, QRegularExpression from PyQt5.QtCore import QCoreApplication, QRegularExpression
from novelwriter import SHARED
from novelwriter.enum import nwItemLayout from novelwriter.enum import nwItemLayout
from novelwriter.common import formatTimeStamp, numberToRoman, checkInt from novelwriter.common import formatTimeStamp, numberToRoman, checkInt
from novelwriter.constants import nwConst, nwHeadFmt, nwRegEx, nwUnicode from novelwriter.constants import nwConst, nwHeadFmt, nwRegEx, nwUnicode
@@ -148,7 +147,7 @@ class Tokenizer(ABC):
self._linkHeaders = False # Add an anchor before headers self._linkHeaders = False # Add an anchor before headers
# Instance Variables # Instance Variables
self._hFormatter = HeadingFormatter() self._hFormatter = HeadingFormatter(self._project)
self._firstScene = False # Flag to indicate that the first scene of the chapter self._firstScene = False # Flag to indicate that the first scene of the chapter
# This File # This File
@@ -772,7 +771,8 @@ class Tokenizer(ABC):
class HeadingFormatter: class HeadingFormatter:
def __init__(self) -> None: def __init__(self, project: NWProject) -> None:
self._project = project
self._chCount = 0 self._chCount = 0
self._scChCount = 0 self._scChCount = 0
self._scAbsCount = 0 self._scAbsCount = 0
@@ -801,7 +801,7 @@ class HeadingFormatter:
hFormat = hFormat.replace(nwHeadFmt.SC_NUM, str(self._scChCount)) hFormat = hFormat.replace(nwHeadFmt.SC_NUM, str(self._scChCount))
hFormat = hFormat.replace(nwHeadFmt.SC_ABS, str(self._scAbsCount)) hFormat = hFormat.replace(nwHeadFmt.SC_ABS, str(self._scAbsCount))
if nwHeadFmt.CH_WORD in hFormat: if nwHeadFmt.CH_WORD in hFormat:
chWord = SHARED.project.localLookup(self._chCount) chWord = self._project.localLookup(self._chCount)
hFormat = hFormat.replace(nwHeadFmt.CH_WORD, chWord) hFormat = hFormat.replace(nwHeadFmt.CH_WORD, chWord)
if nwHeadFmt.CH_ROML in hFormat: if nwHeadFmt.CH_ROML in hFormat:
chRom = numberToRoman(self._chCount, toLower=True) chRom = numberToRoman(self._chCount, toLower=True)
+5 -4
View File
@@ -290,9 +290,10 @@ class GuiManuscript(QDialog):
@pyqtSlot("QListWidgetItem*", "QListWidgetItem*") @pyqtSlot("QListWidgetItem*", "QListWidgetItem*")
def _updateBuildDetails(self, current: QListWidgetItem, previous: QListWidgetItem) -> None: def _updateBuildDetails(self, current: QListWidgetItem, previous: QListWidgetItem) -> None:
"""Process change of build selection to update the details.""" """Process change of build selection to update the details."""
build = self._builds.getBuild(current.data(self.D_KEY)) if isinstance(current, QListWidgetItem):
if build is not None: build = self._builds.getBuild(current.data(self.D_KEY))
self.buildDetails.updateInfo(build) if build is not None:
self.buildDetails.updateInfo(build)
return return
@pyqtSlot() @pyqtSlot()
@@ -586,7 +587,7 @@ class _DetailsWidget(QWidget):
item.addChild(sub) item.addChild(sub)
# Headings # Headings
hFmt = HeadingFormatter() hFmt = HeadingFormatter(SHARED.project)
hFmt.incChapter() hFmt.incChapter()
hFmt.incScene() hFmt.incScene()
hFmt.resetScene() hFmt.resetScene()
+13 -3
View File
@@ -377,6 +377,8 @@ def testCoreBuildSettings_Collection(monkeypatch, mockGUI, fncPath: Path, mockRn
builds = BuildCollection(project) builds = BuildCollection(project)
assert len(builds) == 0 assert len(builds) == 0
assert not buildsFile.exists() assert not buildsFile.exists()
assert builds.lastBuild == ""
assert builds.defaultBuild == ""
# Create a default build # Create a default build
buildOne = BuildSettings() buildOne = BuildSettings()
@@ -412,7 +414,9 @@ def testCoreBuildSettings_Collection(monkeypatch, mockGUI, fncPath: Path, mockRn
# Check the file content # Check the file content
data = json.loads(buildsFile.read_text(encoding="utf-8")) data = json.loads(buildsFile.read_text(encoding="utf-8"))
assert list(data["novelWriter.builds"].keys()) == [buildIDOne, buildIDTwo] assert list(data["novelWriter.builds"].keys()) == [
"lastBuild", "defaultBuild", buildIDOne, buildIDTwo
]
# Remove a build # Remove a build
builds.removeBuild(buildIDOne) builds.removeBuild(buildIDOne)
@@ -423,12 +427,16 @@ def testCoreBuildSettings_Collection(monkeypatch, mockGUI, fncPath: Path, mockRn
# Check the file content # Check the file content
data = json.loads(buildsFile.read_text(encoding="utf-8")) data = json.loads(buildsFile.read_text(encoding="utf-8"))
assert list(data["novelWriter.builds"].keys()) == [buildIDTwo] assert list(data["novelWriter.builds"].keys()) == [
"lastBuild", "defaultBuild", buildIDTwo
]
builds.setBuild(buildOne) builds.setBuild(buildOne)
assert list(builds.builds()) == [ assert list(builds.builds()) == [
(buildIDTwo, "Build Two"), (buildIDTwo, "Build Two"),
(buildIDOne, "Build One"), (buildIDOne, "Build One"),
] ]
builds.setLastBuild(buildIDOne)
builds.setDefaultBuild(buildIDTwo)
# Check errors: No valid path # Check errors: No valid path
with monkeypatch.context() as mp: with monkeypatch.context() as mp:
@@ -447,7 +455,7 @@ def testCoreBuildSettings_Collection(monkeypatch, mockGUI, fncPath: Path, mockRn
buildsFile.write_text("foobar") buildsFile.write_text("foobar")
assert builds._loadCollection() is False assert builds._loadCollection() is False
# Check errors: Valid jason file, but list instead of object # Check errors: Valid json file, but list instead of object
buildsFile.write_text("[]") buildsFile.write_text("[]")
assert builds._loadCollection() is False assert builds._loadCollection() is False
buildsFile.unlink() buildsFile.unlink()
@@ -459,5 +467,7 @@ def testCoreBuildSettings_Collection(monkeypatch, mockGUI, fncPath: Path, mockRn
(buildIDTwo, "Build Two"), (buildIDTwo, "Build Two"),
(buildIDOne, "Build One"), (buildIDOne, "Build One"),
] ]
assert another.lastBuild == buildIDOne
assert another.defaultBuild == buildIDTwo
# END Test testCoreBuildSettings_Collection # END Test testCoreBuildSettings_Collection