From 4b0ad6ec48526e893a10335a7a8070a79fb831aa Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Tue, 11 Jun 2024 00:03:54 +0200 Subject: [PATCH] Add test coverage of ODT dialogue --- tests/test_core/test_core_toodt.py | 51 ++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/tests/test_core/test_core_toodt.py b/tests/test_core/test_core_toodt.py index 4a341165..77f17a0d 100644 --- a/tests/test_core/test_core_toodt.py +++ b/tests/test_core/test_core_toodt.py @@ -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) == ( + '' + 'Text with ' + '\'dialogue in it.\'' + '' + ) + + # 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) == ( + '' + 'Text with ' + '::dialogue in it.::' + '' + ) + + @pytest.mark.core def testCoreToOdt_ConvertHeaders(mockGUI): """Test the converter of the ToOdt class.""" @@ -854,8 +890,8 @@ def testCoreToOdt_SaveFull(mockGUI, fncPath, tstPaths): @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) @@ -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")