From 3a161e90f90eb9d674fa29a3602d643582d00529 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Mon, 31 Oct 2022 18:11:46 +0100 Subject: [PATCH] Complete loading project xml via data class --- novelwriter/core/project.py | 78 ++------------------- novelwriter/core/projectdata.py | 37 ++++++++++ novelwriter/core/projectxml.py | 54 +++++++------- novelwriter/core/tokenizer.py | 5 +- novelwriter/dialogs/projsettings.py | 10 +-- novelwriter/gui/doceditor.py | 6 +- novelwriter/gui/mainmenu.py | 2 +- novelwriter/guimain.py | 2 +- novelwriter/tools/build.py | 12 ++-- sample/nwProject.nwx | 44 ++++++------ tests/test_core/test_core_project.py | 22 +++--- tests/test_core/test_core_tokenizer.py | 2 +- tests/test_dialogs/test_dlg_projsettings.py | 12 ++-- tests/test_gui/test_gui_guimain.py | 4 +- 14 files changed, 129 insertions(+), 161 deletions(-) diff --git a/novelwriter/core/project.py b/novelwriter/core/project.py index a7741a13..df300ae4 100644 --- a/novelwriter/core/project.py +++ b/novelwriter/core/project.py @@ -38,8 +38,8 @@ from PyQt5.QtCore import QCoreApplication from novelwriter.enum import nwItemType, nwItemClass, nwItemLayout, nwAlert from novelwriter.error import logException from novelwriter.common import ( - checkString, checkStringNone, isHandle, formatTimeStamp, makeFileNameSafe, - hexToInt, minmax, simplified + checkStringNone, isHandle, formatTimeStamp, makeFileNameSafe, hexToInt, + minmax, simplified ) from novelwriter.constants import trConst, nwFiles, nwLabels from novelwriter.core.tree import NWTree @@ -63,8 +63,8 @@ class NWProject: self.mainConf = novelwriter.CONFIG self.mainGui = mainGui + # Project Data self._data = NWProjectData() - self._raw = {} # Core Elements self._optState = OptionState(self) # Project-specific GUI options @@ -84,14 +84,8 @@ class NWProject: self.projCache = None # The full path to the project's cache folder self.projContent = None # The full path to the project's content folder self.projDict = None # The spell check dictionary - self.projSpell = None # The spell check language, if different than default self.projFiles = [] # A list of all files in the content folder on load - # Project Settings - self.autoReplace = {} # Text to auto-replace on exports - self.titleFormat = {} # The formatting of titles for exports - self.spellCheck = False # Controls the spellcheck-as-you-type feature - # Internal Mapping self.tr = partial(QCoreApplication.translate, "NWProject") @@ -255,17 +249,7 @@ class NWProject: self.projCache = None self.projContent = None self.projDict = None - self.projSpell = None self.projFiles = [] - self.autoReplace = {} - self.titleFormat = { - "title": "%title%", - "chapter": "%title%", - "unnumbered": "%title%", - "scene": "* * *", - "section": "", - } - self.spellCheck = False self._data.itemStatus.write(None, self.tr("New"), (100, 100, 100)) self._data.itemStatus.write(None, self.tr("Note"), (200, 50, 0)) self._data.itemStatus.write(None, self.tr("Draft"), (200, 150, 0)) @@ -466,9 +450,6 @@ class NWProject: self._data = NWProjectData() xmlReader = ProjectXMLReader(fileName) xmlParsed = xmlReader.read(self._data) - xmlData = xmlReader.data - - # print(json.dumps(xmlData, indent=2)) nwxRoot = xmlReader.xmlRoot appVersion = xmlReader.appVersion or self.tr("Unknown") @@ -494,8 +475,6 @@ class NWProject: self.clearProject() return False - self._raw = xmlData - logger.debug("XML root is '%s'", nwxRoot) logger.debug("File version is '%s'", xmlVersion) @@ -539,15 +518,7 @@ class NWProject: logger.info("Project Name: '%s'", self._data.name) logger.info("Project Title: '%s'", self._data.title) - xmlSettings = xmlData.get("settings", {}) - - self.spellCheck = self._data.spellCheck - self.projSpell = self._data.spellLang - self.autoReplace = xmlSettings.get("autoReplace", {}) - self.titleFormat.update(xmlSettings.get("titleFormat", {})) - - self._projTree.unpack(xmlData.get("content", [])) - + self._projTree.unpack(xmlReader.content) self._optState.loadSettings() # Sort out old file locations @@ -648,10 +619,10 @@ class NWProject: self._packProjectValue(xSettings, "lastWordCount", self._data.getCurrCount("total")) self._packProjectValue(xSettings, "novelWordCount", self._data.getCurrCount("novel")) self._packProjectValue(xSettings, "notesWordCount", self._data.getCurrCount("notes")) - self._packProjectKeyValue(xSettings, "autoReplace", self.autoReplace) + self._packProjectKeyValue(xSettings, "autoReplace", self._data.autoReplace) xTitleFmt = etree.SubElement(xSettings, "titleFormat") - for aKey, aValue in self.titleFormat.items(): + for aKey, aValue in self._data.titleFormat.items(): if len(aKey) > 0: self._packProjectValue(xTitleFmt, aKey, aValue) @@ -921,24 +892,6 @@ class NWProject: return True - def setSpellCheck(self, theMode): - """Enable/disable spell checking. - """ - if self.spellCheck != theMode: - self.spellCheck = theMode - self.setProjectChanged(True) - return self.spellCheck - - def setSpellLang(self, theLang): - """Set the project-specific spell check language. - """ - theLang = checkStringNone(theLang, None) - if self.projSpell != theLang: - self.projSpell = theLang - self.setProjectChanged(True) - return True - return False - def setProjectLang(self, theLang): """Set the project-specific language. """ @@ -970,25 +923,6 @@ class NWProject: """ return self._setStatusImport(newCols, delCols, self._data.itemImport) - def setAutoReplace(self, autoReplace): - """Update the auto-replace dictionary. - """ - self.autoReplace = {} - for key, entry in autoReplace.items(): - self.autoReplace[key] = simplified(entry) - self.setProjectChanged(True) - return True - - def setTitleFormat(self, titleFormat): - """Set the formatting of titles in the project. - """ - for valKey, valEntry in titleFormat.items(): - if valKey in self.titleFormat: - self.titleFormat[valKey] = checkString( - simplified(valEntry), self.titleFormat[valKey] - ) - return True - def setProjectChanged(self, bValue): """Toggle the project changed flag, and propagate the information to the GUI statusbar. diff --git a/novelwriter/core/projectdata.py b/novelwriter/core/projectdata.py index 10988104..d91c39c7 100644 --- a/novelwriter/core/projectdata.py +++ b/novelwriter/core/projectdata.py @@ -54,6 +54,15 @@ class NWProjectData: self._lastCount = {} self._currCount = {} + self._autoReplace = {} + self._titleFormat = { + "title": "%title%", + "chapter": "%title%", + "unnumbered": "%title%", + "scene": "* * *", + "section": "", + } + self._status = NWStatus(NWStatus.STATUS) self._import = NWStatus(NWStatus.IMPORT) @@ -106,6 +115,14 @@ class NWProjectData: def spellLang(self): return self._spellLang + @property + def autoReplace(self): + return self._autoReplace + + @property + def titleFormat(self): + return self._titleFormat + @property def itemStatus(self): return self._status @@ -153,6 +170,9 @@ class NWProjectData: def getCurrCount(self, type): return self._currCount.get(type, 0) + def getTitleFormat(self, kind): + return self._titleFormat.get(kind, "%title%") + ## # Setters ## @@ -231,4 +251,21 @@ class NWProjectData: self._changed = True return + def setAutoReplace(self, value): + if isinstance(value, dict): + self._autoReplace = {} + for key, entry in value.items(): + if isinstance(entry, str): + self._autoReplace[key] = simplified(entry) + self._changed = True + return + + def setTitleFormat(self, value): + if isinstance(value, dict): + for key, entry in value.items(): + if key in self._titleFormat and isinstance(entry, str): + self._titleFormat[key] = simplified(entry) + self._changed = True + return + # END Class NWProjectData diff --git a/novelwriter/core/projectxml.py b/novelwriter/core/projectxml.py index eb8506b2..fe241efa 100644 --- a/novelwriter/core/projectxml.py +++ b/novelwriter/core/projectxml.py @@ -68,7 +68,6 @@ class ProjectXMLReader: self._path = path self._state = XMLReadState.NO_ACTION - self._data = {} self._content = [] self._statusData = {} self._statusMap = {} @@ -85,10 +84,6 @@ class ProjectXMLReader: # Properties ## - @property - def data(self): - return self._data - @property def content(self): return self._content @@ -124,7 +119,6 @@ class ProjectXMLReader: def read(self, projData): """Read and parse the project XML file. """ - self._data = {} self._content = [] try: @@ -231,6 +225,7 @@ class ProjectXMLReader: projData.setEditTime(xItem.text) else: logger.warning("Ignored in xml", xItem.tag) + return True def _parseProjectSettings(self, xSection, projData): @@ -238,9 +233,6 @@ class ProjectXMLReader: """ logger.debug("Parsing xml ") - data = {} - autoReplace = {} - titleFormat = {} for xItem in xSection: if xItem.tag == "doBackup": projData.setDoBackup(xItem.text) @@ -270,22 +262,14 @@ class ProjectXMLReader: self._parseStatusImport(xItem, projData.itemImport) elif xItem.tag == "autoReplace": if self._version >= 0x0102: - for xEntry in xItem: - if xEntry.tag == "entry" and "key" in xEntry.attrib: - autoReplace[xEntry.attrib["key"]] = checkString(xEntry.text, "ERROR") + projData.setAutoReplace(self._parseDictKeyText(xItem)) else: # Pre 1.2 format - for xEntry in xItem: - autoReplace[xEntry.tag] = checkString(xEntry.text, "ERROR") + projData.setAutoReplace(self._parseDictTagText(xItem)) elif xItem.tag == "titleFormat": - for xEntry in xItem: - titleFormat[xEntry.tag] = checkString(xEntry.text, "") + projData.setTitleFormat(self._parseDictTagText(xItem)) else: logger.warning("Ignored in xml", xItem.tag) - data["autoReplace"] = autoReplace - data["titleFormat"] = titleFormat - self._data["settings"] = data - return True def _parseProjectContent(self, xSection): @@ -293,7 +277,6 @@ class ProjectXMLReader: """ logger.debug("Parsing xml ") - data = [] for xItem in xSection: if xItem.tag == "item": item = {} @@ -323,21 +306,20 @@ class ProjectXMLReader: item["active"] = checkBool(xVal.attrib.get("exported", False), False) else: logger.warning("Ignored in xml", xVal.tag) - data.append(item) + self._content.append(item) + else: logger.warning("Ignored item in xml", xItem.tag) - self._data["content"] = data - return True def _parseProjectContentLegacy(self, xSection): - """Parse the content section of the XML file for version before 1.4. + """Parse the content section of the XML file for older version. """ logger.debug("Parsing xml (legacy format)") depLayout = ("TITLE", "PAGE", "BOOK", "PARTITION", "UNNUMBERED", "CHAPTER", "SCENE") - data = [] + for xItem in xSection: item = {} if xItem.tag == "item": @@ -388,13 +370,11 @@ class ProjectXMLReader: if item.get("type", "") == "TRASH": item["type"] = "ROOT" - data.append(item) self._content.append(item) + else: logger.warning("Ignored in xml", xItem.tag) - self._data["content"] = data - return True def _parseStatusImport(self, xItem, sObject): @@ -417,6 +397,22 @@ class ProjectXMLReader: self._importMap = {entry["name"]: key for key, entry in projData.itemImport.items()} return + def _parseDictKeyText(self, xItem): + """Parse a dictionary stored with key as an attribute and the + value as the text porperty. + """ + result = {} + for xEntry in xItem: + if xEntry.tag == "entry" and "key" in xEntry.attrib: + result[xEntry.attrib["key"]] = checkString(xEntry.text, "") + return result + + def _parseDictTagText(self, xItem): + """Parse a dictionary stored with key as the tag and the value + as the text porperty. + """ + return {n.tag: checkString(n.text, "") for n in xItem} + # END Class ProjectXMLReader diff --git a/novelwriter/core/tokenizer.py b/novelwriter/core/tokenizer.py index c55e3659..e81fe2a6 100644 --- a/novelwriter/core/tokenizer.py +++ b/novelwriter/core/tokenizer.py @@ -327,9 +327,10 @@ class Tokenizer(ABC): """Run trough the various replace doctionaries. """ # Process the user's auto-replace dictionary - if len(self.theProject.autoReplace) > 0: + autoReplace = self.theProject.data.autoReplace + if len(autoReplace) > 0: repDict = {} - for aKey, aVal in self.theProject.autoReplace.items(): + for aKey, aVal in autoReplace.items(): repDict[f"<{aKey}>"] = aVal xRep = re.compile("|".join([re.escape(k) for k in repDict.keys()]), flags=re.DOTALL) self._theText = xRep.sub(lambda x: repDict[x.group(0)], self._theText) diff --git a/novelwriter/dialogs/projsettings.py b/novelwriter/dialogs/projsettings.py index 18e905a0..77da0860 100644 --- a/novelwriter/dialogs/projsettings.py +++ b/novelwriter/dialogs/projsettings.py @@ -120,7 +120,7 @@ class GuiProjectSettings(PagedDialog): self.theProject.data.setDoBackup(doBackup) # Remember this as updating spell dictionary can be expensive - self._spellChanged = self.theProject.setSpellLang(spellLang) + self._spellChanged = self.theProject.data.setSpellLang(spellLang) if self.tabStatus.colChanged: newList, delList = self.tabStatus.getNewList() @@ -135,7 +135,7 @@ class GuiProjectSettings(PagedDialog): if self.tabReplace.arChanged: newList = self.tabReplace.getNewList() - self.theProject.setAutoReplace(newList) + self.theProject.data.setAutoReplace(newList) self._saveGuiSettings() self.accept() @@ -252,8 +252,8 @@ class GuiProjectEditMain(QWidget): ) spellIdx = 0 - if self.theProject.projSpell is not None: - spellIdx = self.spellLang.findData(self.theProject.projSpell) + if self.theProject.data.spellLang is not None: + spellIdx = self.spellLang.findData(self.theProject.data.spellLang) if spellIdx != -1: self.spellLang.setCurrentIndex(spellIdx) @@ -578,7 +578,7 @@ class GuiProjectEditReplace(QWidget): self.listBox.setColumnWidth(self.COL_KEY, wCol0) self.listBox.setIndentation(0) - for aKey, aVal in self.theProject.autoReplace.items(): + for aKey, aVal in self.theProject.data.autoReplace.items(): newItem = QTreeWidgetItem(["<%s>" % aKey, aVal]) self.listBox.addTopLevelItem(newItem) diff --git a/novelwriter/gui/doceditor.py b/novelwriter/gui/doceditor.py index 0bde6d8c..b59829bc 100644 --- a/novelwriter/gui/doceditor.py +++ b/novelwriter/gui/doceditor.py @@ -684,10 +684,10 @@ class GuiDocEditor(QTextEdit): """Set the spell checker dictionary language, and emit the dictionary changed signal. """ - if self.theProject.projSpell is None: + if self.theProject.data.spellLang is None: theLang = self.mainConf.spellLanguage else: - theLang = self.theProject.projSpell + theLang = self.theProject.data.spellLang self.spEnchant.setLanguage(theLang, self.theProject.projDict) _, theProvider = self.spEnchant.describeDict() @@ -721,7 +721,7 @@ class GuiDocEditor(QTextEdit): self._spellCheck = theMode self.mainGui.mainMenu.setSpellCheck(theMode) - self.theProject.setSpellCheck(theMode) + self.theProject.data.setSpellCheck(theMode) self.highLight.setSpellCheck(theMode) if not self._bigDoc: self.spellCheckDocument() diff --git a/novelwriter/gui/mainmenu.py b/novelwriter/gui/mainmenu.py index 8a74035e..51a74bae 100644 --- a/novelwriter/gui/mainmenu.py +++ b/novelwriter/gui/mainmenu.py @@ -794,7 +794,7 @@ class GuiMainMenu(QMenuBar): # Tools > Check Spelling self.aSpellCheck = QAction(self.tr("Check Spelling"), self) self.aSpellCheck.setCheckable(True) - self.aSpellCheck.setChecked(self.theProject.spellCheck) + self.aSpellCheck.setChecked(self.theProject.data.spellCheck) self.aSpellCheck.triggered.connect(self._toggleSpellCheck) # triggered, not toggled! self.aSpellCheck.setShortcut("Ctrl+F7") self.toolsMenu.addAction(self.aSpellCheck) diff --git a/novelwriter/guimain.py b/novelwriter/guimain.py index a3e4d295..553667f6 100644 --- a/novelwriter/guimain.py +++ b/novelwriter/guimain.py @@ -524,7 +524,7 @@ class GuiMain(QMainWindow): self._updateWindowTitle(self.theProject.data.name) self.rebuildTrees() self.docEditor.setDictionaries() - self.docEditor.toggleSpellCheck(self.theProject.spellCheck) + self.docEditor.toggleSpellCheck(self.theProject.data.spellCheck) self.mainStatus.setRefTime(self.theProject.projOpened) self.projView.openProjectTasks() self.novelView.openProjectTasks() diff --git a/novelwriter/tools/build.py b/novelwriter/tools/build.py index 979e3e98..8278fb95 100644 --- a/novelwriter/tools/build.py +++ b/novelwriter/tools/build.py @@ -126,7 +126,7 @@ class GuiBuildNovel(QDialog): self.fmtTitle.setMinimumWidth(xFmt) self.fmtTitle.setToolTip(fmtHelp) self.fmtTitle.setText( - self._reFmtCodes(self.theProject.titleFormat["title"]) + self._reFmtCodes(self.theProject.data.getTitleFormat("title")) ) self.fmtChapter = QLineEdit() @@ -134,7 +134,7 @@ class GuiBuildNovel(QDialog): self.fmtChapter.setMinimumWidth(xFmt) self.fmtChapter.setToolTip(fmtHelp) self.fmtChapter.setText( - self._reFmtCodes(self.theProject.titleFormat["chapter"]) + self._reFmtCodes(self.theProject.data.getTitleFormat("chapter")) ) self.fmtUnnumbered = QLineEdit() @@ -142,7 +142,7 @@ class GuiBuildNovel(QDialog): self.fmtUnnumbered.setMinimumWidth(xFmt) self.fmtUnnumbered.setToolTip(fmtHelp) self.fmtUnnumbered.setText( - self._reFmtCodes(self.theProject.titleFormat["unnumbered"]) + self._reFmtCodes(self.theProject.data.getTitleFormat("unnumbered")) ) self.fmtScene = QLineEdit() @@ -150,7 +150,7 @@ class GuiBuildNovel(QDialog): self.fmtScene.setMinimumWidth(xFmt) self.fmtScene.setToolTip(fmtHelp + fmtScHelp) self.fmtScene.setText( - self._reFmtCodes(self.theProject.titleFormat["scene"]) + self._reFmtCodes(self.theProject.data.getTitleFormat("scene")) ) self.fmtSection = QLineEdit() @@ -158,7 +158,7 @@ class GuiBuildNovel(QDialog): self.fmtSection.setMinimumWidth(xFmt) self.fmtSection.setToolTip(fmtHelp + fmtScHelp) self.fmtSection.setText( - self._reFmtCodes(self.theProject.titleFormat["section"]) + self._reFmtCodes(self.theProject.data.getTitleFormat("section")) ) self.buildLang = QComboBox() @@ -1159,7 +1159,7 @@ class GuiBuildNovel(QDialog): logger.debug("Saving GuiBuildNovel settings") # Formatting - self.theProject.setTitleFormat({ + self.theProject.data.setTitleFormat({ "title": self.fmtTitle.text().strip(), "chapter": self.fmtChapter.text().strip(), "unnumbered": self.fmtUnnumbered.text().strip(), diff --git a/sample/nwProject.nwx b/sample/nwProject.nwx index 535b6d18..6b8d929d 100644 --- a/sample/nwProject.nwx +++ b/sample/nwProject.nwx @@ -1,13 +1,13 @@ - + Sample Project Sample Project Jane Smith Jay Doh - 1386 + 1387 236 - 69352 + 69358 False @@ -55,43 +55,43 @@ Novel - + Title Page - + Page - + Part One - + Chapter One - + Making a Scene - + Another Scene - + Interlude - + A Note on Structure - + Chapter Two - + We Found John! @@ -99,11 +99,11 @@ Sequel - + Title Page - + Chapter One @@ -115,11 +115,11 @@ Main Characters - + John Smith - + Jane Smith @@ -127,15 +127,15 @@ Locations - + Earth - + Space - + Mars @@ -147,7 +147,7 @@ Scenes - + Old File @@ -155,7 +155,7 @@ Trash - + Delete Me! diff --git a/tests/test_core/test_core_project.py b/tests/test_core/test_core_project.py index 23598f8b..8acf751c 100644 --- a/tests/test_core/test_core_project.py +++ b/tests/test_core/test_core_project.py @@ -941,19 +941,19 @@ def testCoreProject_Methods(monkeypatch, mockGUI, tmpDir, fncDir, mockRnd): # Spell check theProject.setProjectChanged(False) - assert theProject.setSpellCheck(True) - assert not theProject.setSpellCheck(False) + theProject.data.setSpellCheck(True) + theProject.data.setSpellCheck(False) assert theProject.projChanged # Spell language theProject.setProjectChanged(False) - assert theProject.projSpell is None - assert theProject.setSpellLang(None) is False - assert theProject.projSpell is None - assert theProject.setSpellLang("None") is False # Should be interpreded as None - assert theProject.projSpell is None - assert theProject.setSpellLang("en_GB") - assert theProject.projSpell == "en_GB" + assert theProject.data.spellLang is None + theProject.data.setSpellLang(None) + assert theProject.data.spellLang is None + theProject.data.setSpellLang("None") # Should be interpreded as None + assert theProject.data.spellLang is None + theProject.data.setSpellLang("en_GB") + assert theProject.data.spellLang == "en_GB" assert theProject.projChanged # Project Language @@ -982,8 +982,8 @@ def testCoreProject_Methods(monkeypatch, mockGUI, tmpDir, fncDir, mockRnd): # Autoreplace theProject.setProjectChanged(False) - assert theProject.setAutoReplace({"A": "B", "C": "D"}) - assert theProject.autoReplace == {"A": "B", "C": "D"} + theProject.data.setAutoReplace({"A": "B", "C": "D"}) + assert theProject.data.autoReplace == {"A": "B", "C": "D"} assert theProject.projChanged # Change project tree order diff --git a/tests/test_core/test_core_tokenizer.py b/tests/test_core/test_core_tokenizer.py index 23f47565..fa3035d2 100644 --- a/tests/test_core/test_core_tokenizer.py +++ b/tests/test_core/test_core_tokenizer.py @@ -160,7 +160,7 @@ def testCoreToken_TextOps(monkeypatch, nwMinimal, mockGUI): nDoc = NWDoc(theProject, sHandle) assert nDoc.writeDocument(docText) - theProject.setAutoReplace({"A": "this", "B": "that"}) + theProject.data.setAutoReplace({"A": "this", "B": "that"}) assert theProject.saveProject() diff --git a/tests/test_dialogs/test_dlg_projsettings.py b/tests/test_dialogs/test_dlg_projsettings.py index 08121c6b..085e5398 100644 --- a/tests/test_dialogs/test_dlg_projsettings.py +++ b/tests/test_dialogs/test_dlg_projsettings.py @@ -50,7 +50,7 @@ def testDlgProjSettings_Dialog(qtbot, monkeypatch, nwGUI): # Pretend we have a project nwGUI.hasProject = True - nwGUI.theProject.setSpellLang("en") + nwGUI.theProject.data.setSpellLang("en") # Get the dialog object nwGUI.mainMenu.aProjectSettings.activate(QAction.Trigger) @@ -95,9 +95,9 @@ def testDlgProjSettings_Main(qtbot, monkeypatch, nwGUI, fncDir, fncProj, mockRnd # Set some values theProject = nwGUI.theProject - theProject.setSpellLang("en") + theProject.data.setSpellLang("en") theProject.data.setAuthors("Jane Smith\nJohn Smith") - theProject.setAutoReplace({"A": "B", "C": "D"}) + theProject.data.setAutoReplace({"A": "B", "C": "D"}) # Create Dialog projSettings = GuiProjectSettings(nwGUI, GuiProjectSettings.TAB_MAIN) @@ -365,9 +365,9 @@ def testDlgProjSettings_Replace(qtbot, monkeypatch, nwGUI, fncDir, fncProj, mock # Set some values theProject = nwGUI.theProject - theProject.autoReplace = { + theProject.data.setAutoReplace({ "A": "B", "C": "D" - } + }) # Create Dialog projSettings = GuiProjectSettings(nwGUI, GuiProjectSettings.TAB_REPLACE) @@ -429,7 +429,7 @@ def testDlgProjSettings_Replace(qtbot, monkeypatch, nwGUI, fncDir, fncProj, mock # Check Project projSettings._doSave() - assert theProject.autoReplace == { + assert theProject.data.autoReplace == { "A": "B", "C": "D", "This": "With This Stuff" } diff --git a/tests/test_gui/test_gui_guimain.py b/tests/test_gui/test_gui_guimain.py index fda4edea..28b5b729 100644 --- a/tests/test_gui/test_gui_guimain.py +++ b/tests/test_gui/test_gui_guimain.py @@ -175,7 +175,7 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, fncProj, refDir, outDir, mock assert nwGUI.theProject.data.name == "" assert nwGUI.theProject.data.title == "" assert nwGUI.theProject.data.authors == [] - assert not nwGUI.theProject.spellCheck + assert nwGUI.theProject.data.spellCheck is False # Check the files projFile = os.path.join(fncProj, "nwProject.nwx") @@ -197,7 +197,7 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, fncProj, refDir, outDir, mock assert nwGUI.theProject.data.name == "New Project" assert nwGUI.theProject.data.title == "New Novel" assert nwGUI.theProject.data.authors == ["Jane Doe"] - assert nwGUI.theProject.spellCheck is False + assert nwGUI.theProject.data.spellCheck is False # Check that tree items have been created assert nwGUI.projView.projTree._getTreeItem(C.hNovelRoot) is not None