Remove more redundant code

This commit is contained in:
Veronica Berglyd Olsen
2024-10-23 17:20:07 +02:00
parent 3712b2e93f
commit b01c91c0a3
2 changed files with 2 additions and 51 deletions
+1 -33
View File
@@ -24,21 +24,17 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
""" """
from __future__ import annotations from __future__ import annotations
import json
import logging import logging
import re import re
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from functools import partial
from pathlib import Path from pathlib import Path
from time import time
from typing import NamedTuple from typing import NamedTuple
from PyQt5.QtCore import QCoreApplication
from PyQt5.QtGui import QColor, QFont from PyQt5.QtGui import QColor, QFont
from novelwriter import CONFIG from novelwriter import CONFIG
from novelwriter.common import checkInt, formatTimeStamp, numberToRoman from novelwriter.common import checkInt, numberToRoman
from novelwriter.constants import ( from novelwriter.constants import (
nwHeadFmt, nwKeyWords, nwLabels, nwShortcode, nwStyles, nwUnicode, trConst nwHeadFmt, nwKeyWords, nwLabels, nwShortcode, nwStyles, nwUnicode, trConst
) )
@@ -179,7 +175,6 @@ class Tokenizer(ABC):
# Function Mapping # Function Mapping
self._localLookup = self._project.localLookup self._localLookup = self._project.localLookup
self.tr = partial(QCoreApplication.translate, "Tokenizer")
# Format RegEx # Format RegEx
self._rxMarkdown = [ self._rxMarkdown = [
@@ -1024,33 +1019,6 @@ class Tokenizer(ABC):
return return
def saveRawDocument(self, path: str | Path, asJson: bool = False) -> None:
"""Save the raw text to a plain text file."""
if asJson:
ts = time()
data = {
"meta": {
"projectName": self._project.data.name,
"novelAuthor": self._project.data.author,
"buildTime": int(ts),
"buildTimeStr": formatTimeStamp(ts),
},
"text": {
"nwd": [page.rstrip("\n").split("\n") for page in self._raw],
}
}
with open(path, mode="w", encoding="utf-8") as fObj:
json.dump(data, fObj, indent=2)
else:
with open(path, mode="w", encoding="utf-8") as outFile:
for nwdPage in self._raw:
outFile.write(nwdPage)
logger.info("Wrote file: %s", path)
return
## ##
# Internal Functions # Internal Functions
## ##
+1 -18
View File
@@ -20,8 +20,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
""" """
from __future__ import annotations from __future__ import annotations
import json
import pytest import pytest
from PyQt5.QtGui import QFont from PyQt5.QtGui import QFont
@@ -35,7 +33,7 @@ from novelwriter.formats.tokenizer import COMMENT_STYLE, HeadingFormatter, Token
from novelwriter.formats.tomarkdown import ToMarkdown from novelwriter.formats.tomarkdown import ToMarkdown
from novelwriter.formats.toraw import ToRaw from novelwriter.formats.toraw import ToRaw
from tests.tools import C, buildTestProject, readFile from tests.tools import C, buildTestProject
TMH = "0123456789abc" TMH = "0123456789abc"
TM1 = f"{TMH}:T0001" TM1 = f"{TMH}:T0001"
@@ -237,21 +235,6 @@ def testFmtToken_TextOps(monkeypatch, mockGUI, mockRnd, fncPath):
tokens.doPreProcessing() tokens.doPreProcessing()
assert tokens._text == docTextR assert tokens._text == docTextR
# Save File
savePath = fncPath / "dump.nwd"
tokens.saveRawDocument(savePath, asJson=False)
assert readFile(savePath) == (
"#! Notes: Plot\n\n"
"#! Notes: Plot\n\n"
)
tokens.saveRawDocument(savePath, asJson=True)
assert json.loads(readFile(savePath))["text"] == {
"nwd": [
["#! Notes: Plot"],
["#! Notes: Plot"]
]
}
@pytest.mark.core @pytest.mark.core
def testFmtToken_StripEscape(): def testFmtToken_StripEscape():