Fix tests for core classes

This commit is contained in:
Veronica Berglyd Olsen
2022-11-08 19:48:06 +01:00
parent b024c0996d
commit ee79d3d6d6
9 changed files with 163 additions and 124 deletions
+2 -2
View File
@@ -138,7 +138,7 @@ class NWDocument:
contentPath = self.theProject.storage.contentPath
if not isinstance(contentPath, Path):
logger.error("No content path set")
return None
return False
docFile = self._docHandle+".nwd"
logger.debug("Saving document: %s", docFile)
@@ -195,7 +195,7 @@ class NWDocument:
contentPath = self.theProject.storage.contentPath
if not isinstance(contentPath, Path):
logger.error("No content path set")
return None
return False
docPath = contentPath / f"{self._docHandle}.nwd"
docTemp = docPath.with_suffix(".tmp")
-2
View File
@@ -820,8 +820,6 @@ class ItemIndex:
elif tItem.itemRoot == rootHandle:
for sTitle in self._items[tHandle].headings():
yield tHandle, sTitle, self._items[tHandle][sTitle]
else:
continue
return
+12 -18
View File
@@ -25,7 +25,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
from __future__ import annotations
import os
import json
import logging
import novelwriter
@@ -82,8 +81,7 @@ class NWProject(QObject):
self.lockedBy = None # Data on which computer has the project open
# Class Settings
self.projDict = None # The spell check dictionary
self.projFiles = [] # A list of all files in the content folder on load
self.projFiles = [] # A list of all files in the content folder on load
# Internal Mapping
self.tr = partial(QCoreApplication.translate, "NWProject")
@@ -248,7 +246,6 @@ class NWProject(QObject):
self._data = NWProjectData(self)
# Project Settings
self.projDict = None
self.projFiles = []
return
@@ -265,8 +262,6 @@ class NWProject(QObject):
logger.info("Opening project: %s", projPath)
self.projDict = str(self._storage.getMetaFile(nwFiles.PROJ_DICT))
# Project Lock
# ============
@@ -367,11 +362,12 @@ class NWProject(QObject):
# Check the project tree consistency
for tItem in self._tree:
tHandle = tItem.itemHandle
logger.debug("Checking item '%s'", tHandle)
if not self._tree.updateItemData(tHandle):
logger.error("There was a problem item '%s', and it has been removed", tHandle)
del self._tree[tHandle] # The file will be re-added as orphaned
if tItem:
tHandle = tItem.itemHandle
logger.debug("Checking item '%s'", tHandle)
if not self._tree.updateItemData(tHandle):
logger.error("There was a problem the item, and it has been removed")
del self._tree[tHandle] # The file will be re-added as orphaned
self._scanProjectFolder()
self._index.loadIndex()
@@ -694,20 +690,18 @@ class NWProject(QObject):
def _loadProjectLocalisation(self):
"""Load the language data for the current project language.
"""
if self._data.language is None:
if self._data.language is None or self.mainConf.nwLangPath is None:
self._langData = {}
return False
langFile = os.path.join(
self.mainConf.nwLangPath, "project_%s.json" % self._data.language
)
if not os.path.isfile(langFile):
langFile = os.path.join(self.mainConf.nwLangPath, "project_en_GB.json")
langFile = Path(self.mainConf.nwLangPath) / f"project_{self._data.language}.json"
if not langFile.is_file():
langFile = Path(self.mainConf.nwLangPath) / "project_en_GB.json"
try:
with open(langFile, mode="r", encoding="utf-8") as inFile:
self._langData = json.load(inFile)
logger.debug("Loaded project language file: %s", os.path.basename(langFile))
logger.debug("Loaded project language file: %s", langFile.name)
except Exception:
logger.error("Failed to project language file")
+3 -3
View File
@@ -23,10 +23,10 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import os
import logging
from collections import namedtuple
from pathlib import Path
from novelwriter.error import logException
@@ -173,10 +173,10 @@ class NWSpellEnchant:
self._projDict = set()
self._projectDict = projectDict
if projectDict is None:
if not isinstance(projectDict, Path):
return False
if not os.path.isfile(projectDict):
if not projectDict.exists():
return False
try:
+3 -2
View File
@@ -53,7 +53,7 @@ from PyQt5.QtWidgets import (
from novelwriter.core import NWSpellEnchant, countWords
from novelwriter.enum import nwAlert, nwDocAction, nwDocInsert, nwDocMode
from novelwriter.common import transferCase
from novelwriter.constants import nwConst, nwKeyWords, nwUnicode
from novelwriter.constants import nwConst, nwFiles, nwKeyWords, nwUnicode
from novelwriter.gui.dochighlight import GuiDocHighlighter
logger = logging.getLogger(__name__)
@@ -689,7 +689,8 @@ class GuiDocEditor(QTextEdit):
else:
theLang = self.theProject.data.spellLang
self.spEnchant.setLanguage(theLang, self.theProject.projDict)
projDict = self.theProject.storage.getMetaFile(nwFiles.PROJ_DICT)
self.spEnchant.setLanguage(theLang, projDict)
_, theProvider = self.spEnchant.describeDict()
self.spellDictionaryChanged.emit(str(theLang), str(theProvider))