Remove titleFormat from project XML and rename mock test file

This commit is contained in:
Veronica Berglyd Olsen
2023-06-03 18:13:02 +02:00
parent db8140418e
commit 0704812376
24 changed files with 30 additions and 91 deletions
-18
View File
@@ -170,11 +170,6 @@ class NWProjectData:
"""Return the autoreplace dictionary.""" """Return the autoreplace dictionary."""
return self._autoReplace return self._autoReplace
@property
def titleFormat(self):
"""Delete"""
return self._titleFormat
@property @property
def itemStatus(self) -> NWStatus: def itemStatus(self) -> NWStatus:
"""Return the status settings object.""" """Return the status settings object."""
@@ -209,10 +204,6 @@ class NWProjectData:
"""Retrieve the last used handle for a given component.""" """Retrieve the last used handle for a given component."""
return self._lastHandle.get(component, None) return self._lastHandle.get(component, None)
def getTitleFormat(self, kind):
"""Retrieve the title format string for a given kind of header."""
return self._titleFormat.get(kind, "%title%")
## ##
# Setters # Setters
## ##
@@ -337,13 +328,4 @@ class NWProjectData:
self.theProject.setProjectChanged(True) self.theProject.setProjectChanged(True)
return return
def setTitleFormat(self, value):
"""Set the title formats."""
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.theProject.setProjectChanged(True)
return
# END Class NWProjectData # END Class NWProjectData
-6
View File
@@ -280,11 +280,6 @@ class ProjectXMLReader:
data.setAutoReplace(self._parseDictKeyText(xItem)) data.setAutoReplace(self._parseDictKeyText(xItem))
else: # Pre 1.2 format else: # Pre 1.2 format
data.setAutoReplace(self._parseDictTagText(xItem)) data.setAutoReplace(self._parseDictTagText(xItem))
elif xItem.tag == "titleFormat":
if self._version >= 0x0105:
data.setTitleFormat(self._parseDictKeyText(xItem))
else: # Pre 1.4 format
data.setTitleFormat(self._parseDictTagText(xItem))
else: else:
logger.warning("Ignored <root/settings/%s> in XML", xItem.tag) logger.warning("Ignored <root/settings/%s> in XML", xItem.tag)
@@ -523,7 +518,6 @@ class ProjectXMLWriter:
}) })
self._packDictKeyValue(xSettings, "lastHandle", data.lastHandle) self._packDictKeyValue(xSettings, "lastHandle", data.lastHandle)
self._packDictKeyValue(xSettings, "autoReplace", data.autoReplace) self._packDictKeyValue(xSettings, "autoReplace", data.autoReplace)
self._packDictKeyValue(xSettings, "titleFormat", data.titleFormat)
# Save Status/Importance # Save Status/Importance
xStatus = ET.SubElement(xSettings, "status") xStatus = ET.SubElement(xSettings, "status")
+1 -1
View File
@@ -25,7 +25,7 @@ import shutil
from pathlib import Path from pathlib import Path
from mock import MockGuiMain from mocked import MockGuiMain
from tools import cleanProject from tools import cleanProject
from PyQt5.QtWidgets import QMessageBox from PyQt5.QtWidgets import QMessageBox
View File
+1 -1
View File
@@ -25,7 +25,7 @@ import hashlib
from pathlib import Path from pathlib import Path
from mock import causeOSError from mocked import causeOSError
from tools import writeFile from tools import writeFile
from novelwriter.guimain import GuiMain from novelwriter.guimain import GuiMain
+1 -1
View File
@@ -25,7 +25,7 @@ import pytest
from shutil import copyfile from shutil import copyfile
from pathlib import Path from pathlib import Path
from mock import causeOSError, MockApp from mocked import causeOSError, MockApp
from tools import cmpFiles, writeFile from tools import cmpFiles, writeFile
from novelwriter import CONFIG from novelwriter import CONFIG
+1 -1
View File
@@ -21,7 +21,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
import pytest import pytest
from mock import causeException from mocked import causeException
from novelwriter.error import NWErrorMessage, exceptionHandler from novelwriter.error import NWErrorMessage, exceptionHandler
+1 -1
View File
@@ -23,7 +23,7 @@ import sys
import pytest import pytest
import logging import logging
from mock import MockGuiMain from mocked import MockGuiMain
from novelwriter import CONFIG, main, logger from novelwriter import CONFIG, main, logger
+1 -1
View File
@@ -25,7 +25,7 @@ import pytest
from shutil import copyfile from shutil import copyfile
from zipfile import ZipFile from zipfile import ZipFile
from mock import causeOSError from mocked import causeOSError
from tools import C, buildTestProject, cmpFiles, XML_IGNORE from tools import C, buildTestProject, cmpFiles, XML_IGNORE
from novelwriter import CONFIG from novelwriter import CONFIG
+1 -1
View File
@@ -23,7 +23,7 @@ import pytest
from shutil import copyfile from shutil import copyfile
from mock import causeException, causeOSError from mocked import causeException, causeOSError
from novelwriter.core.buildsettings import BuildSettings from novelwriter.core.buildsettings import BuildSettings
from tools import ODT_IGNORE, cmpFiles from tools import ODT_IGNORE, cmpFiles
+1 -1
View File
@@ -21,7 +21,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
import pytest import pytest
from mock import causeOSError from mocked import causeOSError
from tools import C, buildTestProject, readFile, writeFile from tools import C, buildTestProject, readFile, writeFile
from novelwriter.enum import nwItemClass, nwItemLayout from novelwriter.enum import nwItemClass, nwItemLayout
+1 -1
View File
@@ -24,7 +24,7 @@ import pytest
from shutil import copyfile from shutil import copyfile
from mock import causeException from mocked import causeException
from tools import C, buildTestProject, cmpFiles, writeFile from tools import C, buildTestProject, cmpFiles, writeFile
from novelwriter.enum import nwItemClass, nwItemLayout from novelwriter.enum import nwItemClass, nwItemLayout
+1 -1
View File
@@ -22,7 +22,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
import json import json
import pytest import pytest
from mock import causeOSError from mocked import causeOSError
from novelwriter.constants import nwFiles from novelwriter.constants import nwFiles
from novelwriter.core.options import OptionState from novelwriter.core.options import OptionState
+1 -1
View File
@@ -26,7 +26,7 @@ from shutil import copyfile
from pathlib import Path from pathlib import Path
from zipfile import ZipFile from zipfile import ZipFile
from mock import causeOSError from mocked import causeOSError
from tools import C, cmpFiles, writeFile, buildTestProject, XML_IGNORE from tools import C, cmpFiles, writeFile, buildTestProject, XML_IGNORE
from novelwriter import CONFIG from novelwriter import CONFIG
+10 -47
View File
@@ -25,8 +25,8 @@ import pytest
from shutil import copyfile from shutil import copyfile
from datetime import datetime from datetime import datetime
from mock import causeOSError
from tools import cmpFiles, writeFile from tools import cmpFiles, writeFile
from mocked import causeOSError
from novelwriter.core.item import NWItem from novelwriter.core.item import NWItem
from novelwriter.core.projectxml import ProjectXMLReader, ProjectXMLWriter, XMLReadState from novelwriter.core.projectxml import ProjectXMLReader, ProjectXMLWriter, XMLReadState
@@ -34,12 +34,16 @@ from novelwriter.core.projectdata import NWProjectData
class MockProject: class MockProject:
"""Fake project object."""
def setProjectChanged(self, *a): def setProjectChanged(self, *a):
"""Fake project method."""
pass pass
@pytest.fixture(scope="function", autouse=True) @pytest.fixture(scope="function", autouse=True)
def mockVersion(monkeypatch): def mockVersion(monkeypatch):
"""Mock the version info to prevent diff from failing."""
monkeypatch.setattr("novelwriter.core.projectxml.__version__", "2.0-rc1") monkeypatch.setattr("novelwriter.core.projectxml.__version__", "2.0-rc1")
monkeypatch.setattr("novelwriter.core.projectxml.__hexversion__", "0x020000c1") monkeypatch.setattr("novelwriter.core.projectxml.__hexversion__", "0x020000c1")
return return
@@ -47,8 +51,7 @@ def mockVersion(monkeypatch):
@pytest.mark.core @pytest.mark.core
def testCoreProjectXML_ReadCurrent(monkeypatch, tstPaths, fncPath): def testCoreProjectXML_ReadCurrent(monkeypatch, tstPaths, fncPath):
"""Test reading the current XML file format. """Test reading the current XML file format."""
"""
refFile = tstPaths.filesDir / "nwProject-1.5.nwx" refFile = tstPaths.filesDir / "nwProject-1.5.nwx"
tstFile = tstPaths.outDir / "ProjectXML_ReadCurrent.nwx" tstFile = tstPaths.outDir / "ProjectXML_ReadCurrent.nwx"
xmlFile = fncPath / "nwProject-1.5.nwx" xmlFile = fncPath / "nwProject-1.5.nwx"
@@ -160,12 +163,6 @@ def testCoreProjectXML_ReadCurrent(monkeypatch, tstPaths, fncPath):
assert data.getLastHandle("novelTree") == "7031beac91f75" assert data.getLastHandle("novelTree") == "7031beac91f75"
assert data.getLastHandle("outline") == "7031beac91f75" assert data.getLastHandle("outline") == "7031beac91f75"
assert data.getTitleFormat("title") == "%title%"
assert data.getTitleFormat("chapter") == "Chapter %chw%: %title%"
assert data.getTitleFormat("unnumbered") == "%title%"
assert data.getTitleFormat("scene") == "Scene %ch%.%sc%: %title%"
assert data.getTitleFormat("section") == ""
assert data.itemStatus.name("sf12341") == "New" assert data.itemStatus.name("sf12341") == "New"
assert data.itemStatus.name("sf24ce6") == "Notes" assert data.itemStatus.name("sf24ce6") == "Notes"
assert data.itemStatus.name("sc24b8f") == "Started" assert data.itemStatus.name("sc24b8f") == "Started"
@@ -286,12 +283,6 @@ def testCoreProjectXML_ReadLegacy10(tstPaths, fncPath, mockRnd):
assert data.getLastHandle("novelTree") is None # Doesn't exist in 1.0 assert data.getLastHandle("novelTree") is None # Doesn't exist in 1.0
assert data.getLastHandle("outline") is None # Doesn't exist in 1.0 assert data.getLastHandle("outline") is None # Doesn't exist in 1.0
assert data.getTitleFormat("title") == "%title%"
assert data.getTitleFormat("chapter") == "Chapter %ch%: %title%"
assert data.getTitleFormat("unnumbered") == "%title%"
assert data.getTitleFormat("scene") == "Scene %ch%.%sc%: %title%"
assert data.getTitleFormat("section") == ""
assert data.itemStatus.name("s000000") == "New" assert data.itemStatus.name("s000000") == "New"
assert data.itemStatus.name("s000001") == "Notes" assert data.itemStatus.name("s000001") == "Notes"
assert data.itemStatus.name("s000002") == "Started" assert data.itemStatus.name("s000002") == "Started"
@@ -388,8 +379,7 @@ def testCoreProjectXML_ReadLegacy10(tstPaths, fncPath, mockRnd):
@pytest.mark.core @pytest.mark.core
def testCoreProjectXML_ReadLegacy11(tstPaths, fncPath, mockRnd): def testCoreProjectXML_ReadLegacy11(tstPaths, fncPath, mockRnd):
"""Test reading the version 1.1 XML file format. """Test reading the version 1.1 XML file format."""
"""
refFile = tstPaths.filesDir / "nwProject-1.1.nwx" refFile = tstPaths.filesDir / "nwProject-1.1.nwx"
xmlFile = fncPath / "nwProject-1.1.nwx" xmlFile = fncPath / "nwProject-1.1.nwx"
outFile = fncPath / "nwProject.nwx" outFile = fncPath / "nwProject.nwx"
@@ -428,12 +418,6 @@ def testCoreProjectXML_ReadLegacy11(tstPaths, fncPath, mockRnd):
assert data.getLastHandle("novelTree") is None # Doesn't exist in 1.1 assert data.getLastHandle("novelTree") is None # Doesn't exist in 1.1
assert data.getLastHandle("outline") is None # Doesn't exist in 1.1 assert data.getLastHandle("outline") is None # Doesn't exist in 1.1
assert data.getTitleFormat("title") == "%title%"
assert data.getTitleFormat("chapter") == "Chapter %ch%: %title%"
assert data.getTitleFormat("unnumbered") == "%title%"
assert data.getTitleFormat("scene") == "Scene %ch%.%sc%: %title%"
assert data.getTitleFormat("section") == ""
assert data.itemStatus.name("s000000") == "New" assert data.itemStatus.name("s000000") == "New"
assert data.itemStatus.name("s000001") == "Notes" assert data.itemStatus.name("s000001") == "Notes"
assert data.itemStatus.name("s000002") == "Started" assert data.itemStatus.name("s000002") == "Started"
@@ -530,8 +514,7 @@ def testCoreProjectXML_ReadLegacy11(tstPaths, fncPath, mockRnd):
@pytest.mark.core @pytest.mark.core
def testCoreProjectXML_ReadLegacy12(tstPaths, fncPath, mockRnd): def testCoreProjectXML_ReadLegacy12(tstPaths, fncPath, mockRnd):
"""Test reading the version 1.2 XML file format. """Test reading the version 1.2 XML file format."""
"""
refFile = tstPaths.filesDir / "nwProject-1.2.nwx" refFile = tstPaths.filesDir / "nwProject-1.2.nwx"
xmlFile = fncPath / "nwProject-1.2.nwx" xmlFile = fncPath / "nwProject-1.2.nwx"
outFile = fncPath / "nwProject.nwx" outFile = fncPath / "nwProject.nwx"
@@ -570,12 +553,6 @@ def testCoreProjectXML_ReadLegacy12(tstPaths, fncPath, mockRnd):
assert data.getLastHandle("novelTree") is None # Doesn't exist in 1.2 assert data.getLastHandle("novelTree") is None # Doesn't exist in 1.2
assert data.getLastHandle("outline") is None # Doesn't exist in 1.2 assert data.getLastHandle("outline") is None # Doesn't exist in 1.2
assert data.getTitleFormat("title") == "%title%"
assert data.getTitleFormat("chapter") == "Chapter %chw%: %title%"
assert data.getTitleFormat("unnumbered") == "%title%"
assert data.getTitleFormat("scene") == "Scene %ch%.%sc%: %title%"
assert data.getTitleFormat("section") == ""
assert data.itemStatus.name("s000000") == "New" assert data.itemStatus.name("s000000") == "New"
assert data.itemStatus.name("s000001") == "Notes" assert data.itemStatus.name("s000001") == "Notes"
assert data.itemStatus.name("s000002") == "Started" assert data.itemStatus.name("s000002") == "Started"
@@ -675,8 +652,7 @@ def testCoreProjectXML_ReadLegacy12(tstPaths, fncPath, mockRnd):
@pytest.mark.core @pytest.mark.core
def testCoreProjectXML_ReadLegacy13(tstPaths, fncPath, mockRnd): def testCoreProjectXML_ReadLegacy13(tstPaths, fncPath, mockRnd):
"""Test reading the version 1.3 XML file format. """Test reading the version 1.3 XML file format."""
"""
refFile = tstPaths.filesDir / "nwProject-1.3.nwx" refFile = tstPaths.filesDir / "nwProject-1.3.nwx"
xmlFile = fncPath / "nwProject-1.3.nwx" xmlFile = fncPath / "nwProject-1.3.nwx"
outFile = fncPath / "nwProject.nwx" outFile = fncPath / "nwProject.nwx"
@@ -715,12 +691,6 @@ def testCoreProjectXML_ReadLegacy13(tstPaths, fncPath, mockRnd):
assert data.getLastHandle("novelTree") is None # Doesn't exist in 1.3 assert data.getLastHandle("novelTree") is None # Doesn't exist in 1.3
assert data.getLastHandle("outline") is None # Doesn't exist in 1.3 assert data.getLastHandle("outline") is None # Doesn't exist in 1.3
assert data.getTitleFormat("title") == "%title%"
assert data.getTitleFormat("chapter") == "Chapter %chw%: %title%"
assert data.getTitleFormat("unnumbered") == "%title%"
assert data.getTitleFormat("scene") == "Scene %ch%.%sc%: %title%"
assert data.getTitleFormat("section") == ""
assert data.itemStatus.name("s000000") == "New" assert data.itemStatus.name("s000000") == "New"
assert data.itemStatus.name("s000001") == "Notes" assert data.itemStatus.name("s000001") == "Notes"
assert data.itemStatus.name("s000002") == "Started" assert data.itemStatus.name("s000002") == "Started"
@@ -820,8 +790,7 @@ def testCoreProjectXML_ReadLegacy13(tstPaths, fncPath, mockRnd):
@pytest.mark.core @pytest.mark.core
def testCoreProjectXML_ReadLegacy14(tstPaths, fncPath, mockRnd): def testCoreProjectXML_ReadLegacy14(tstPaths, fncPath, mockRnd):
"""Test reading the version 1.4 XML file format. """Test reading the version 1.4 XML file format."""
"""
refFile = tstPaths.filesDir / "nwProject-1.4.nwx" refFile = tstPaths.filesDir / "nwProject-1.4.nwx"
xmlFile = fncPath / "nwProject-1.4.nwx" xmlFile = fncPath / "nwProject-1.4.nwx"
outFile = fncPath / "nwProject.nwx" outFile = fncPath / "nwProject.nwx"
@@ -860,12 +829,6 @@ def testCoreProjectXML_ReadLegacy14(tstPaths, fncPath, mockRnd):
assert data.getLastHandle("novelTree") is None # Doesn't exist in 1.3 assert data.getLastHandle("novelTree") is None # Doesn't exist in 1.3
assert data.getLastHandle("outline") is None # Doesn't exist in 1.3 assert data.getLastHandle("outline") is None # Doesn't exist in 1.3
assert data.getTitleFormat("title") == "%title%"
assert data.getTitleFormat("chapter") == "Chapter %chw%: %title%"
assert data.getTitleFormat("unnumbered") == "%title%"
assert data.getTitleFormat("scene") == "Scene %ch%.%sc%: %title%"
assert data.getTitleFormat("section") == ""
assert data.itemStatus.name("sf12341") == "New" assert data.itemStatus.name("sf12341") == "New"
assert data.itemStatus.name("sf24ce6") == "Notes" assert data.itemStatus.name("sf24ce6") == "Notes"
assert data.itemStatus.name("sc24b8f") == "Started" assert data.itemStatus.name("sc24b8f") == "Started"
+1 -1
View File
@@ -22,7 +22,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
import sys import sys
import pytest import pytest
from mock import causeOSError from mocked import causeOSError
from tools import readFile, writeFile from tools import readFile, writeFile
from novelwriter.core.spellcheck import FakeEnchant, NWSpellEnchant from novelwriter.core.spellcheck import FakeEnchant, NWSpellEnchant
+1 -1
View File
@@ -22,7 +22,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
from zipfile import ZipFile from zipfile import ZipFile
import pytest import pytest
from mock import causeOSError from mocked import causeOSError
from tools import C, buildTestProject, writeFile from tools import C, buildTestProject, writeFile
from novelwriter import CONFIG from novelwriter import CONFIG
+1 -1
View File
@@ -24,7 +24,7 @@ import random
from pathlib import Path from pathlib import Path
from mock import causeOSError from mocked import causeOSError
from tools import readFile from tools import readFile
from novelwriter.enum import nwItemClass, nwItemType, nwItemLayout from novelwriter.enum import nwItemClass, nwItemType, nwItemLayout
+1 -1
View File
@@ -25,7 +25,7 @@ from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QDialog, QAction from PyQt5.QtWidgets import QDialog, QAction
from tools import buildTestProject, writeFile, readFile, getGuiItem from tools import buildTestProject, writeFile, readFile, getGuiItem
from mock import causeOSError from mocked import causeOSError
from novelwriter.constants import nwFiles from novelwriter.constants import nwFiles
from novelwriter.dialogs.wordlist import GuiWordList from novelwriter.dialogs.wordlist import GuiWordList
+1 -1
View File
@@ -21,7 +21,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
import pytest import pytest
from mock import causeOSError from mocked import causeOSError
from tools import C, buildTestProject from tools import C, buildTestProject
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt
+1 -1
View File
@@ -21,7 +21,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
import pytest import pytest
from mock import causeException from mocked import causeException
from PyQt5.QtCore import Qt, QUrl from PyQt5.QtCore import Qt, QUrl
from PyQt5.QtGui import QTextCursor from PyQt5.QtGui import QTextCursor
+1 -1
View File
@@ -21,7 +21,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
import pytest import pytest
from mock import causeOSError from mocked import causeOSError
from tools import C, buildTestProject from tools import C, buildTestProject
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt
+1 -1
View File
@@ -24,7 +24,7 @@ import pytest
from pathlib import Path from pathlib import Path
from configparser import ConfigParser from configparser import ConfigParser
from mock import causeOSError from mocked import causeOSError
from tools import writeFile from tools import writeFile
from PyQt5.QtGui import QIcon, QPalette, QPixmap from PyQt5.QtGui import QIcon, QPalette, QPixmap
+1 -1
View File
@@ -22,7 +22,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
import json import json
import pytest import pytest
from mock import causeOSError from mocked import causeOSError
from tools import getGuiItem, writeFile, buildTestProject from tools import getGuiItem, writeFile, buildTestProject
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt