From 4033f7a47daacdce0ef5877e16f1c22328fe7779 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Tue, 16 Feb 2021 23:58:25 +0100 Subject: [PATCH] Fix tests --- novelWriter.pro | 1 + nw/core/project.py | 8 +++----- nw/core/tokenizer.py | 4 +++- tests/test_core/test_core_tokenizer.py | 9 +++++++-- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/novelWriter.pro b/novelWriter.pro index 92ba7def..b2da5800 100644 --- a/novelWriter.pro +++ b/novelWriter.pro @@ -2,6 +2,7 @@ SOURCES += \ nw/constants/constants.py \ nw/core/document.py \ nw/core/project.py \ + nw/core/tokenizer.py \ nw/gui/about.py \ nw/gui/build.py \ nw/gui/custom.py \ diff --git a/nw/core/project.py b/nw/core/project.py index dd55c173..02fa3fd3 100644 --- a/nw/core/project.py +++ b/nw/core/project.py @@ -1250,16 +1250,14 @@ class NWProject(): """ if theLang is None: theLang = self.mainConf.spellLanguage + if theLang is None: + theLang = "en" lngShort = theLang.split("_")[0] loadFile = os.path.join(self.mainConf.langPath, "project_en.json") chkFile1 = os.path.join(self.mainConf.langPath, "project_%s.json" % theLang) chkFile2 = os.path.join(self.mainConf.langPath, "project_%s.json" % lngShort) - print(theLang) - print(lngShort) - print(loadFile) - print(chkFile1) - print(chkFile2) + if os.path.isfile(chkFile1): loadFile = chkFile1 elif os.path.isfile(chkFile2): diff --git a/nw/core/tokenizer.py b/nw/core/tokenizer.py index fecb8767..260a230e 100644 --- a/nw/core/tokenizer.py +++ b/nw/core/tokenizer.py @@ -28,8 +28,9 @@ import logging import re from operator import itemgetter +from functools import partial -from PyQt5.QtCore import QRegularExpression +from PyQt5.QtCore import QCoreApplication, QRegularExpression from nw.core.document import NWDoc from nw.core.tools import numberToRoman @@ -144,6 +145,7 @@ class Tokenizer(): # Function Mapping self._localLookup = self.theProject.localLookup + self.tr = partial(QCoreApplication.translate, "Tokenizer") return diff --git a/tests/test_core/test_core_tokenizer.py b/tests/test_core/test_core_tokenizer.py index 8f8604f9..cad615fd 100644 --- a/tests/test_core/test_core_tokenizer.py +++ b/tests/test_core/test_core_tokenizer.py @@ -112,11 +112,14 @@ def testCoreToken_Setters(dummyGUI): # END Test testCoreToken_Setters @pytest.mark.core -def testCoreToken_TextOps(monkeypatch, nwMinimal, dummyGUI): +def testCoreToken_TextOps(monkeypatch, nwMinimal, dummyGUI, tmpConf): """Test handling files and text in the Tokenizer class. """ theProject = NWProject(dummyGUI) + theProject.mainConf = tmpConf theProject.projTree.setSeed(42) + theProject.loadProjectLocalisation("en") + theToken = Tokenizer(theProject, dummyGUI) theToken.setKeepMarkdown(True) @@ -408,10 +411,12 @@ def testCoreToken_Tokenize(dummyGUI): # END Test testCoreToken_Tokenize @pytest.mark.core -def testCoreToken_Headers(dummyGUI): +def testCoreToken_Headers(dummyGUI, tmpConf): """Test the header and page parser of the Tokenizer class. """ theProject = NWProject(dummyGUI) + theProject.mainConf = tmpConf + theProject.loadProjectLocalisation("en") theToken = Tokenizer(theProject, dummyGUI) # Nothing