Fix tests for core classes
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -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
@@ -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")
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user