Skip to content

Commit

Permalink
Add test coverage of ODT dialogue
Browse files Browse the repository at this point in the history
  • Loading branch information
vkbo committed Jun 10, 2024
1 parent 416c580 commit 4b0ad6e
Showing 1 changed file with 49 additions and 2 deletions.
51 changes: 49 additions & 2 deletions tests/test_core/test_core_toodt.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,42 @@ def testCoreToOdt_TextFormatting(mockGUI):
)


@pytest.mark.core
def testCoreToOdt_DialogueFormatting(mockGUI):
"""Test formatting of dialogue."""
project = NWProject()
odt = ToOdt(project, isFlat=True)
odt.setDialogueHighlight(True)
odt.initDocument()
oStyle = ODTParagraphStyle("test")

# Regular dialogue
text = "Text with 'dialogue in it.'"
fmt = [(10, odt.FMT_DL_B, ""), (27, odt.FMT_DL_E, "")]
xTest = ET.Element(_mkTag("office", "text"))
odt._addTextPar(xTest, "Standard", oStyle, text, tFmt=fmt)
assert odt.errData == []
assert xmlToText(xTest) == (
'<office:text>'
'<text:p text:style-name="Standard">Text with '
'<text:span text:style-name="T1">\'dialogue in it.\'</text:span></text:p>'
'</office:text>'
)

# Alternative dialogue
text = "Text with ::dialogue in it.::"
fmt = [(10, odt.FMT_ADL_B, ""), (29, odt.FMT_ADL_E, "")]
xTest = ET.Element(_mkTag("office", "text"))
odt._addTextPar(xTest, "Standard", oStyle, text, tFmt=fmt)
assert odt.errData == []
assert xmlToText(xTest) == (
'<office:text>'
'<text:p text:style-name="Standard">Text with '
'<text:span text:style-name="T2">::dialogue in it.::</text:span></text:p>'
'</office:text>'
)


@pytest.mark.core
def testCoreToOdt_ConvertHeaders(mockGUI):
"""Test the converter of the ToOdt class."""
Expand Down Expand Up @@ -854,8 +890,8 @@ def prettifyXml(inFile, outFile):


@pytest.mark.core
def testCoreToOdt_Format(mockGUI):
"""Test the formatters for the ToOdt class."""
def testCoreToOdt_SpecialFormats(mockGUI):
"""Test the special formatters for the ToOdt class."""
project = NWProject()
odt = ToOdt(project, isFlat=True)

Expand Down Expand Up @@ -1168,6 +1204,17 @@ def testCoreToOdt_ODTTextStyle():
txtStyle.setFontStyle("stuff")
assert txtStyle._tAttr["font-style"] == ["fo", None]

# Text Color
assert txtStyle._tAttr["color"] == ["fo", None]
txtStyle.setColour("stuff")
assert txtStyle._tAttr["color"] == ["fo", None]
txtStyle.setColour("012345")
assert txtStyle._tAttr["color"] == ["fo", None]
txtStyle.setColour("#012345")
assert txtStyle._tAttr["color"] == ["fo", "#012345"]
txtStyle.setColour("stuff")
assert txtStyle._tAttr["color"] == ["fo", None]

# Background Color
assert txtStyle._tAttr["background-color"] == ["fo", None]
txtStyle.setBackgroundColour("stuff")
Expand Down

0 comments on commit 4b0ad6e

Please sign in to comment.