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