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