Fix tests
This commit is contained in:
@@ -575,10 +575,10 @@ def testCoreDocBuild_IterBuild(mockGUI, fncPath: Path, mockRnd):
|
||||
"By Jane Doe\n\n"
|
||||
"## New Chapter\n\n\n"
|
||||
"### New Scene\n\n\n"
|
||||
"# Notes: Plot\n\n"
|
||||
"#! Notes: Plot\n\n"
|
||||
"# Main Plot\n"
|
||||
"**Text**\n\n"
|
||||
"# Notes: Characters\n\n"
|
||||
"#! Notes: Characters\n\n"
|
||||
"# Jane Doe\n"
|
||||
"~~Text~~\n\n"
|
||||
)
|
||||
|
||||
@@ -1194,6 +1194,7 @@ def testCoreIndex_ItemIndex(mockGUI, fncPath, mockRnd):
|
||||
# Add a second novel
|
||||
mHandle = project.newRoot(nwItemClass.NOVEL)
|
||||
uHandle = project.newFile("Title Page", mHandle)
|
||||
assert uHandle is not None
|
||||
itemIndex.add(uHandle, project.tree[uHandle]) # type: ignore
|
||||
itemIndex.addItemHeading(uHandle, "T0001", "H1", "Novel 2") # type: ignore
|
||||
assert uHandle in itemIndex
|
||||
|
||||
@@ -227,7 +227,6 @@ def testCoreToHtml_ConvertParagraphs(mockGUI):
|
||||
|
||||
# Multiple Keywords
|
||||
html._isFirst = False
|
||||
html._noBreak = False
|
||||
html.setKeywords(True)
|
||||
html._text = "## Chapter\n\n@pov: Bod\n@plot: Main\n@location: Europe\n\n"
|
||||
html.tokenizeText()
|
||||
@@ -275,8 +274,8 @@ def testCoreToHtml_ConvertDirect(mockGUI):
|
||||
|
||||
# Title
|
||||
html._tokens = [
|
||||
(html.T_TITLE, 1, "A Title", None, html.A_PBB | html.A_CENTRE),
|
||||
(html.T_EMPTY, 1, "", None, html.A_NONE),
|
||||
(html.T_TITLE, 1, "A Title", [], html.A_PBB | html.A_CENTRE),
|
||||
(html.T_EMPTY, 1, "", [], html.A_NONE),
|
||||
]
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
@@ -286,8 +285,8 @@ def testCoreToHtml_ConvertDirect(mockGUI):
|
||||
|
||||
# Unnumbered
|
||||
html._tokens = [
|
||||
(html.T_HEAD2, 1, "Prologue", None, html.A_PBB),
|
||||
(html.T_EMPTY, 1, "", None, html.A_NONE),
|
||||
(html.T_HEAD2, 1, "Prologue", [], html.A_PBB),
|
||||
(html.T_EMPTY, 1, "", [], html.A_NONE),
|
||||
]
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
@@ -300,16 +299,16 @@ def testCoreToHtml_ConvertDirect(mockGUI):
|
||||
|
||||
# Separator
|
||||
html._tokens = [
|
||||
(html.T_SEP, 1, "* * *", None, html.A_CENTRE),
|
||||
(html.T_EMPTY, 1, "", None, html.A_NONE),
|
||||
(html.T_SEP, 1, "* * *", [], html.A_CENTRE),
|
||||
(html.T_EMPTY, 1, "", [], html.A_NONE),
|
||||
]
|
||||
html.doConvert()
|
||||
assert html.result == "<p class='sep' style='text-align: center;'>* * *</p>\n"
|
||||
|
||||
# Skip
|
||||
html._tokens = [
|
||||
(html.T_SKIP, 1, "", None, html.A_NONE),
|
||||
(html.T_EMPTY, 1, "", None, html.A_NONE),
|
||||
(html.T_SKIP, 1, "", [], html.A_NONE),
|
||||
(html.T_EMPTY, 1, "", [], html.A_NONE),
|
||||
]
|
||||
html.doConvert()
|
||||
assert html.result == "<p class='skip'> </p>\n"
|
||||
@@ -322,7 +321,7 @@ def testCoreToHtml_ConvertDirect(mockGUI):
|
||||
# Align Left
|
||||
html.setStyles(False)
|
||||
html._tokens = [
|
||||
(html.T_HEAD1, 1, "A Title", None, html.A_LEFT),
|
||||
(html.T_HEAD1, 1, "A Title", [], html.A_LEFT),
|
||||
]
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
@@ -333,7 +332,7 @@ def testCoreToHtml_ConvertDirect(mockGUI):
|
||||
|
||||
# Align Left
|
||||
html._tokens = [
|
||||
(html.T_HEAD1, 1, "A Title", None, html.A_LEFT),
|
||||
(html.T_HEAD1, 1, "A Title", [], html.A_LEFT),
|
||||
]
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
@@ -342,7 +341,7 @@ def testCoreToHtml_ConvertDirect(mockGUI):
|
||||
|
||||
# Align Right
|
||||
html._tokens = [
|
||||
(html.T_HEAD1, 1, "A Title", None, html.A_RIGHT),
|
||||
(html.T_HEAD1, 1, "A Title", [], html.A_RIGHT),
|
||||
]
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
@@ -351,7 +350,7 @@ def testCoreToHtml_ConvertDirect(mockGUI):
|
||||
|
||||
# Align Centre
|
||||
html._tokens = [
|
||||
(html.T_HEAD1, 1, "A Title", None, html.A_CENTRE),
|
||||
(html.T_HEAD1, 1, "A Title", [], html.A_CENTRE),
|
||||
]
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
@@ -360,7 +359,7 @@ def testCoreToHtml_ConvertDirect(mockGUI):
|
||||
|
||||
# Align Justify
|
||||
html._tokens = [
|
||||
(html.T_HEAD1, 1, "A Title", None, html.A_JUSTIFY),
|
||||
(html.T_HEAD1, 1, "A Title", [], html.A_JUSTIFY),
|
||||
]
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
@@ -372,7 +371,7 @@ def testCoreToHtml_ConvertDirect(mockGUI):
|
||||
|
||||
# Page Break Always
|
||||
html._tokens = [
|
||||
(html.T_HEAD1, 1, "A Title", None, html.A_PBB | html.A_PBA),
|
||||
(html.T_HEAD1, 1, "A Title", [], html.A_PBB | html.A_PBA),
|
||||
]
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
@@ -386,7 +385,7 @@ def testCoreToHtml_ConvertDirect(mockGUI):
|
||||
# Indent Left
|
||||
html._tokens = [
|
||||
(html.T_TEXT, 1, "Some text ...", [], html.A_IND_L),
|
||||
(html.T_EMPTY, 2, "", None, html.A_NONE),
|
||||
(html.T_EMPTY, 2, "", [], html.A_NONE),
|
||||
]
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
@@ -396,7 +395,7 @@ def testCoreToHtml_ConvertDirect(mockGUI):
|
||||
# Indent Right
|
||||
html._tokens = [
|
||||
(html.T_TEXT, 1, "Some text ...", [], html.A_IND_R),
|
||||
(html.T_EMPTY, 2, "", None, html.A_NONE),
|
||||
(html.T_EMPTY, 2, "", [], html.A_NONE),
|
||||
]
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
@@ -459,7 +458,6 @@ def testCoreToHtml_SpecialCases(mockGUI):
|
||||
)
|
||||
|
||||
html._isFirst = False
|
||||
html._noBreak = False
|
||||
html._text = "## Heading <1>\n"
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
|
||||
@@ -33,7 +33,7 @@ from novelwriter.core.tokenizer import HeadingFormatter, Tokenizer, stripEscape
|
||||
|
||||
class BareTokenizer(Tokenizer):
|
||||
def doConvert(self):
|
||||
super().doConvert()
|
||||
super().doConvert() # type: ignore (deliberate check)
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
@@ -181,21 +181,23 @@ def testCoreToken_TextOps(monkeypatch, mockGUI, mockRnd, fncPath):
|
||||
assert project.saveProject()
|
||||
|
||||
# Root Heading
|
||||
assert tokens.addRootHeading("stuff") is False
|
||||
assert tokens.addRootHeading(C.hSceneDoc) is False
|
||||
assert len(tokens._tokens) == 0
|
||||
tokens.addRootHeading("stuff")
|
||||
tokens.addRootHeading(C.hSceneDoc)
|
||||
assert len(tokens._tokens) == 0
|
||||
|
||||
# First Page
|
||||
assert tokens.addRootHeading(C.hPlotRoot) is True
|
||||
assert tokens.allMarkdown[-1] == "# Notes: Plot\n\n"
|
||||
tokens.addRootHeading(C.hPlotRoot)
|
||||
assert tokens.allMarkdown[-1] == "#! Notes: Plot\n\n"
|
||||
assert tokens._tokens[-1] == (
|
||||
Tokenizer.T_TITLE, 0, "Notes: Plot", [], Tokenizer.A_CENTRE
|
||||
Tokenizer.T_TITLE, 1, "Notes: Plot", [], Tokenizer.A_CENTRE
|
||||
)
|
||||
|
||||
# Not First Page
|
||||
assert tokens.addRootHeading(C.hPlotRoot) is True
|
||||
assert tokens.allMarkdown[-1] == "# Notes: Plot\n\n"
|
||||
tokens.addRootHeading(C.hPlotRoot)
|
||||
assert tokens.allMarkdown[-1] == "#! Notes: Plot\n\n"
|
||||
assert tokens._tokens[-1] == (
|
||||
Tokenizer.T_TITLE, 0, "Notes: Plot", [], Tokenizer.A_CENTRE | Tokenizer.A_PBB
|
||||
Tokenizer.T_TITLE, 1, "Notes: Plot", [], Tokenizer.A_CENTRE | Tokenizer.A_PBB
|
||||
)
|
||||
|
||||
# Set Text
|
||||
@@ -218,14 +220,14 @@ def testCoreToken_TextOps(monkeypatch, mockGUI, mockRnd, fncPath):
|
||||
savePath = fncPath / "dump.nwd"
|
||||
tokens.saveRawMarkdown(savePath)
|
||||
assert readFile(savePath) == (
|
||||
"# Notes: Plot\n\n"
|
||||
"# Notes: Plot\n\n"
|
||||
"#! Notes: Plot\n\n"
|
||||
"#! Notes: Plot\n\n"
|
||||
)
|
||||
tokens.saveRawMarkdownJSON(savePath)
|
||||
assert json.loads(readFile(savePath))["text"] == {
|
||||
"nwd": [
|
||||
["# Notes: Plot"],
|
||||
["# Notes: Plot"]
|
||||
["#! Notes: Plot"],
|
||||
["#! Notes: Plot"]
|
||||
]
|
||||
}
|
||||
|
||||
@@ -313,7 +315,6 @@ def testCoreToken_HeaderFormat(mockGUI):
|
||||
|
||||
# Story File
|
||||
tokens._isNovel = True
|
||||
tokens._noBreak = False
|
||||
tokens._text = "## Chapter One\n"
|
||||
|
||||
tokens.tokenizeText()
|
||||
@@ -448,7 +449,6 @@ def testCoreToken_HeaderStyle(mockGUI):
|
||||
def processStyle(text: str, first: bool) -> int:
|
||||
tokens._text = text
|
||||
tokens._isFirst = first
|
||||
tokens._noBreak = first
|
||||
tokens.tokenizeText()
|
||||
return tokens._tokens[0][4]
|
||||
|
||||
|
||||
@@ -204,8 +204,8 @@ def testCoreToMarkdown_ConvertDirect(mockGUI):
|
||||
|
||||
# Title
|
||||
toMD._tokens = [
|
||||
(toMD.T_TITLE, 1, "A Title", None, toMD.A_PBB | toMD.A_CENTRE),
|
||||
(toMD.T_EMPTY, 1, "", None, toMD.A_NONE),
|
||||
(toMD.T_TITLE, 1, "A Title", [], toMD.A_PBB | toMD.A_CENTRE),
|
||||
(toMD.T_EMPTY, 1, "", [], toMD.A_NONE),
|
||||
]
|
||||
toMD.doConvert()
|
||||
assert toMD.result == "# A Title\n\n"
|
||||
@@ -215,16 +215,16 @@ def testCoreToMarkdown_ConvertDirect(mockGUI):
|
||||
|
||||
# Separator
|
||||
toMD._tokens = [
|
||||
(toMD.T_SEP, 1, "* * *", None, toMD.A_CENTRE),
|
||||
(toMD.T_EMPTY, 1, "", None, toMD.A_NONE),
|
||||
(toMD.T_SEP, 1, "* * *", [], toMD.A_CENTRE),
|
||||
(toMD.T_EMPTY, 1, "", [], toMD.A_NONE),
|
||||
]
|
||||
toMD.doConvert()
|
||||
assert toMD.result == "* * *\n\n"
|
||||
|
||||
# Skip
|
||||
toMD._tokens = [
|
||||
(toMD.T_SKIP, 1, "", None, toMD.A_NONE),
|
||||
(toMD.T_EMPTY, 1, "", None, toMD.A_NONE),
|
||||
(toMD.T_SKIP, 1, "", [], toMD.A_NONE),
|
||||
(toMD.T_EMPTY, 1, "", [], toMD.A_NONE),
|
||||
]
|
||||
toMD.doConvert()
|
||||
assert toMD.result == "\n\n"
|
||||
|
||||
@@ -652,7 +652,7 @@ def testCoreToOdt_ConvertDirect(mockGUI):
|
||||
doc = ToOdt(project, isFlat=True)
|
||||
doc._tokens = [
|
||||
(doc.T_TEXT, 1, "This is a paragraph", [], doc.A_JUSTIFY),
|
||||
(doc.T_EMPTY, 1, "", None, doc.A_NONE),
|
||||
(doc.T_EMPTY, 1, "", [], doc.A_NONE),
|
||||
]
|
||||
doc.initDocument()
|
||||
doc.doConvert()
|
||||
@@ -673,7 +673,7 @@ def testCoreToOdt_ConvertDirect(mockGUI):
|
||||
doc = ToOdt(project, isFlat=True)
|
||||
doc._tokens = [
|
||||
(doc.T_TEXT, 1, "This is a paragraph", [], doc.A_PBA),
|
||||
(doc.T_EMPTY, 1, "", None, doc.A_NONE),
|
||||
(doc.T_EMPTY, 1, "", [], doc.A_NONE),
|
||||
]
|
||||
doc.initDocument()
|
||||
doc.doConvert()
|
||||
|
||||
Reference in New Issue
Block a user