Fix tests

This commit is contained in:
Veronica Berglyd Olsen
2023-05-24 00:27:29 +02:00
parent e3744d31aa
commit cd81ea5fbb
3 changed files with 99 additions and 60 deletions
+74 -37
View File
@@ -24,31 +24,68 @@ import pytest
from shutil import copyfile
from mock import causeException, causeOSError
from novelwriter.core.buildsettings import BuildSettings
from tools import ODT_IGNORE, cmpFiles
from novelwriter.core.project import NWProject
from novelwriter.core.docbuild import NWBuildDocument
# BUILD_CONF = {
# "format.fmtTitle": "Title: %title%",
# "format.fmtChapter": "Chapter: %title%",
# "format.fmtUnnumbered": "%title%",
# "format.fmtScene": "Scene: %title%",
# "format.fmtSection": "Section: %title%",
# "format.buildLang": "en_GB",
# "format.hideScene": False,
# "format.hideSection": False,
# "format.textFont": "Arial",
# "format.textSize": 12,
# "format.lineHeight": 1.5,
# "format.justifyText": True,
# "format.noStyling": False,
# "format.replaceUCode": False,
# "filter.includeSynopsis": True,
# "filter.includeComments": True,
# "filter.includeKeywords": True,
# "filter.includeBody": True,
# "process.replaceTabs": True,
# }
BUILD_CONF = {
"format.fmtTitle": "Title: %title%",
"format.fmtChapter": "Chapter: %title%",
"format.fmtUnnumbered": "%title%",
"format.fmtScene": "Scene: %title%",
"format.fmtSection": "Section: %title%",
"format.buildLang": "en_GB",
"format.hideScene": False,
"format.hideSection": False,
"format.textFont": "Arial",
"format.textSize": 12,
"format.lineHeight": 1.5,
"format.justifyText": True,
"format.noStyling": False,
"format.replaceUCode": False,
"filter.includeSynopsis": True,
"filter.includeComments": True,
"filter.includeKeywords": True,
"filter.includeBody": True,
"process.replaceTabs": True,
"name": "Test Build",
"uuid": "f8796eee-e234-4e8a-8355-b2709177e53c",
"settings": {
"filter.includeNovel": True,
"filter.includeNotes": True,
"filter.includeInactive": False,
"headings.fmtTitle": "Title: {Title}",
"headings.fmtChapter": "Chapter: {Title}",
"headings.fmtUnnumbered": "{Title}",
"headings.fmtScene": "Scene: {Title}",
"headings.fmtSection": "Section: {Title}",
"headings.hideScene": False,
"headings.hideSection": False,
"text.includeSynopsis": True,
"text.includeComments": True,
"text.includeKeywords": True,
"text.includeBodyText": True,
"text.addNoteHeadings": True,
"format.buildLang": "en_GB",
"format.textFont": "Arial",
"format.textSize": 12,
"format.lineHeight": 1.5,
"format.justifyText": True,
"format.stripUnicode": False,
"format.replaceTabs": False,
"odt.addColours": True,
"html.addStyles": True,
},
"content": {
"included": [],
"excluded": [],
"skipRoot": [],
},
}
@@ -56,14 +93,14 @@ BUILD_CONF = {
def testCoreDocBuild_OpenDocument(monkeypatch, mockGUI, prjLipsum, fncPath, tstPaths):
"""Test builing an open document manuscript.
"""
theProject = NWProject(mockGUI)
theProject.openProject(prjLipsum)
project = NWProject(mockGUI)
project.openProject(prjLipsum)
docBuild = NWBuildDocument(theProject)
docBuild.setBuildConfig(BUILD_CONF)
build = BuildSettings()
build.unpack(BUILD_CONF)
for tItem in theProject.tree:
docBuild.addDocument(tItem.itemHandle)
docBuild = NWBuildDocument(project, build)
docBuild.queueAll()
assert docBuild.buildLength == 21
@@ -164,14 +201,14 @@ def testCoreDocBuild_OpenDocument(monkeypatch, mockGUI, prjLipsum, fncPath, tstP
def testCoreDocBuild_HTML(monkeypatch, mockGUI, prjLipsum, fncPath, tstPaths):
"""Test builing an HTML manuscript.
"""
theProject = NWProject(mockGUI)
theProject.openProject(prjLipsum)
project = NWProject(mockGUI)
project.openProject(prjLipsum)
docBuild = NWBuildDocument(theProject)
docBuild.setBuildConfig(BUILD_CONF)
build = BuildSettings()
build.unpack(BUILD_CONF)
for tItem in theProject.tree:
docBuild.addDocument(tItem.itemHandle)
docBuild = NWBuildDocument(project, build)
docBuild.queueAll()
assert docBuild.buildLength == 21
@@ -215,14 +252,14 @@ def testCoreDocBuild_HTML(monkeypatch, mockGUI, prjLipsum, fncPath, tstPaths):
def testCoreDocBuild_Markdown(monkeypatch, mockGUI, prjLipsum, fncPath, tstPaths):
"""Test builing an Markdown manuscript.
"""
theProject = NWProject(mockGUI)
theProject.openProject(prjLipsum)
project = NWProject(mockGUI)
project.openProject(prjLipsum)
docBuild = NWBuildDocument(theProject)
docBuild.setBuildConfig(BUILD_CONF)
build = BuildSettings()
build.unpack(BUILD_CONF)
for tItem in theProject.tree:
docBuild.addDocument(tItem.itemHandle)
docBuild = NWBuildDocument(project, build)
docBuild.queueAll()
assert docBuild.buildLength == 21
+24 -23
View File
@@ -20,6 +20,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import pytest
from novelwriter.constants import nwHeadingFormats
from tools import C, buildTestProject, readFile
@@ -917,7 +918,7 @@ def testCoreToken_ProcessHeaders(mockGUI):
# H1: Title, First Page
assert theToken._isFirst is True
theToken._theText = "# Part One\n"
theToken.setTitleFormat(r"T: %title%")
theToken.setTitleFormat(f"T: {nwHeadingFormats.TITLE}")
theToken.tokenizeText()
theToken.doHeaders()
assert theToken._theTokens == [
@@ -928,7 +929,7 @@ def testCoreToken_ProcessHeaders(mockGUI):
# H1: Title, Not First Page
assert theToken._isFirst is False
theToken._theText = "# Part One\n"
theToken.setTitleFormat(r"T: %title%")
theToken.setTitleFormat(f"T: {nwHeadingFormats.TITLE}")
theToken.tokenizeText()
theToken.doHeaders()
assert theToken._theTokens == [
@@ -941,7 +942,7 @@ def testCoreToken_ProcessHeaders(mockGUI):
# H2: Chapter
theToken._theText = "## Chapter One\n"
theToken.setChapterFormat(r"C: %title%")
theToken.setChapterFormat(f"C: {nwHeadingFormats.TITLE}")
theToken.tokenizeText()
theToken.doHeaders()
assert theToken._theTokens == [
@@ -951,7 +952,7 @@ def testCoreToken_ProcessHeaders(mockGUI):
# H2: Unnumbered Chapter
theToken._theText = "##! Prologue\n"
theToken.setUnNumberedFormat(r"U: %title%")
theToken.setUnNumberedFormat(f"U: {nwHeadingFormats.TITLE}")
theToken.tokenizeText()
theToken.doHeaders()
assert theToken._theTokens == [
@@ -961,8 +962,8 @@ def testCoreToken_ProcessHeaders(mockGUI):
# H2: Chapter Word Number
theToken._theText = "## Chapter\n"
theToken.setChapterFormat(r"Chapter %chw%")
theToken._numChapter = 0
theToken.setChapterFormat(f"Chapter {nwHeadingFormats.CH_WORD}")
theToken._hFormatter._chCount = 0
theToken.tokenizeText()
theToken.doHeaders()
assert theToken._theTokens == [
@@ -972,7 +973,7 @@ def testCoreToken_ProcessHeaders(mockGUI):
# H2: Chapter Roman Number Upper Case
theToken._theText = "## Chapter\n"
theToken.setChapterFormat(r"Chapter %chI%")
theToken.setChapterFormat(f"Chapter {nwHeadingFormats.CH_ROMU}")
theToken.tokenizeText()
theToken.doHeaders()
assert theToken._theTokens == [
@@ -982,7 +983,7 @@ def testCoreToken_ProcessHeaders(mockGUI):
# H2: Chapter Roman Number Lower Case
theToken._theText = "## Chapter\n"
theToken.setChapterFormat(r"Chapter %chi%")
theToken.setChapterFormat(f"Chapter {nwHeadingFormats.CH_ROML}")
theToken.tokenizeText()
theToken.doHeaders()
assert theToken._theTokens == [
@@ -995,7 +996,7 @@ def testCoreToken_ProcessHeaders(mockGUI):
# H3: Scene w/Title
theToken._theText = "### Scene One\n"
theToken.setSceneFormat(r"S: %title%", False)
theToken.setSceneFormat(f"S: {nwHeadingFormats.TITLE}", False)
theToken.tokenizeText()
theToken.doHeaders()
assert theToken._theTokens == [
@@ -1005,7 +1006,7 @@ def testCoreToken_ProcessHeaders(mockGUI):
# H3: Scene Hidden wo/Format
theToken._theText = "### Scene One\n"
theToken.setSceneFormat(r"", True)
theToken.setSceneFormat("", True)
theToken.tokenizeText()
theToken.doHeaders()
assert theToken._theTokens == [
@@ -1015,7 +1016,7 @@ def testCoreToken_ProcessHeaders(mockGUI):
# H3: Scene wo/Format, first
theToken._theText = "### Scene One\n"
theToken.setSceneFormat(r"", False)
theToken.setSceneFormat("", False)
theToken._firstScene = True
theToken.tokenizeText()
theToken.doHeaders()
@@ -1026,7 +1027,7 @@ def testCoreToken_ProcessHeaders(mockGUI):
# H3: Scene wo/Format, not first
theToken._theText = "### Scene One\n"
theToken.setSceneFormat(r"", False)
theToken.setSceneFormat("", False)
theToken._firstScene = False
theToken.tokenizeText()
theToken.doHeaders()
@@ -1037,7 +1038,7 @@ def testCoreToken_ProcessHeaders(mockGUI):
# H3: Scene Separator, first
theToken._theText = "### Scene One\n"
theToken.setSceneFormat(r"* * *", False)
theToken.setSceneFormat("* * *", False)
theToken._firstScene = True
theToken.tokenizeText()
theToken.doHeaders()
@@ -1048,7 +1049,7 @@ def testCoreToken_ProcessHeaders(mockGUI):
# H3: Scene Separator, not first
theToken._theText = "### Scene One\n"
theToken.setSceneFormat(r"* * *", False)
theToken.setSceneFormat("* * *", False)
theToken._firstScene = False
theToken.tokenizeText()
theToken.doHeaders()
@@ -1059,9 +1060,9 @@ def testCoreToken_ProcessHeaders(mockGUI):
# H3: Scene w/Absolute Number
theToken._theText = "### A Scene\n"
theToken.setSceneFormat(r"Scene %sca%", False)
theToken._numAbsScene = 0
theToken._numChScene = 0
theToken.setSceneFormat(f"Scene {nwHeadingFormats.SC_ABS}", False)
theToken._hFormatter._scAbsCount = 0
theToken._hFormatter._scChCount = 0
theToken.tokenizeText()
theToken.doHeaders()
assert theToken._theTokens == [
@@ -1071,9 +1072,9 @@ def testCoreToken_ProcessHeaders(mockGUI):
# H3: Scene w/Chapter Number
theToken._theText = "### A Scene\n"
theToken.setSceneFormat(r"Scene %ch%.%sc%", False)
theToken._numAbsScene = 0
theToken._numChScene = 1
theToken.setSceneFormat(f"Scene {nwHeadingFormats.CH_NUM}.{nwHeadingFormats.SC_NUM}", False)
theToken._hFormatter._scAbsCount = 0
theToken._hFormatter._scChCount = 1
theToken.tokenizeText()
theToken.doHeaders()
assert theToken._theTokens == [
@@ -1096,7 +1097,7 @@ def testCoreToken_ProcessHeaders(mockGUI):
# H4: Section Visible wo/Format
theToken._theText = "#### A Section\n"
theToken.setSectionFormat(r"", False)
theToken.setSectionFormat("", False)
theToken.tokenizeText()
theToken.doHeaders()
assert theToken._theTokens == [
@@ -1106,7 +1107,7 @@ def testCoreToken_ProcessHeaders(mockGUI):
# H4: Section w/Format
theToken._theText = "#### A Section\n"
theToken.setSectionFormat(r"X: %title%", False)
theToken.setSectionFormat(f"X: {nwHeadingFormats.TITLE}", False)
theToken.tokenizeText()
theToken.doHeaders()
assert theToken._theTokens == [
@@ -1116,7 +1117,7 @@ def testCoreToken_ProcessHeaders(mockGUI):
# H4: Section Separator
theToken._theText = "#### A Section\n"
theToken.setSectionFormat(r"* * *", False)
theToken.setSectionFormat("* * *", False)
theToken.tokenizeText()
theToken.doHeaders()
assert theToken._theTokens == [
+1
View File
@@ -33,6 +33,7 @@ from novelwriter.tools.build import GuiBuildNovel
@pytest.mark.gui
@pytest.mark.skip
def testToolBuild_Main(qtbot, monkeypatch, nwGUI, prjLipsum, tstPaths):
"""Test the build tool.
"""