Fix ODT tests
This commit is contained in:
@@ -1,13 +1,13 @@
|
|||||||
<?xml version='1.0' encoding='utf-8'?>
|
<?xml version='1.0' encoding='utf-8'?>
|
||||||
<office:document xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text">
|
<office:document xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text">
|
||||||
<office:meta>
|
<office:meta>
|
||||||
<meta:creation-date>2024-03-14T23:26:28</meta:creation-date>
|
<meta:creation-date>2024-04-24T18:30:38</meta:creation-date>
|
||||||
<meta:generator>novelWriter/2.4a2</meta:generator>
|
<meta:generator>novelWriter/2.5a2</meta:generator>
|
||||||
<meta:initial-creator>Jane Smith</meta:initial-creator>
|
<meta:initial-creator>Jane Smith</meta:initial-creator>
|
||||||
<meta:editing-cycles>1234</meta:editing-cycles>
|
<meta:editing-cycles>1234</meta:editing-cycles>
|
||||||
<meta:editing-duration>P42DT12H34M56S</meta:editing-duration>
|
<meta:editing-duration>P42DT12H34M56S</meta:editing-duration>
|
||||||
<dc:title>Test Project</dc:title>
|
<dc:title>Test Project</dc:title>
|
||||||
<dc:date>2024-03-14T23:26:28</dc:date>
|
<dc:date>2024-04-24T18:30:38</dc:date>
|
||||||
<dc:creator>Jane Smith</dc:creator>
|
<dc:creator>Jane Smith</dc:creator>
|
||||||
</office:meta>
|
</office:meta>
|
||||||
<office:font-face-decls>
|
<office:font-face-decls>
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
<style:text-properties style:font-name="Liberation Serif" fo:font-family="'Liberation Serif'" fo:font-size="12pt" />
|
<style:text-properties style:font-name="Liberation Serif" fo:font-family="'Liberation Serif'" fo:font-size="12pt" />
|
||||||
</style:style>
|
</style:style>
|
||||||
<style:style style:name="First_20_line_20_indent" style:family="paragraph" style:display-name="First line indent" style:parent-style-name="Text_20_body" style:class="text">
|
<style:style style:name="First_20_line_20_indent" style:family="paragraph" style:display-name="First line indent" style:parent-style-name="Text_20_body" style:class="text">
|
||||||
<style:paragraph-properties fo:text-indent="0.499cm" />
|
<style:paragraph-properties fo:text-indent="0.593cm" />
|
||||||
</style:style>
|
</style:style>
|
||||||
<style:style style:name="Text_20_Meta" style:family="paragraph" style:display-name="Text Meta" style:parent-style-name="Standard" style:class="text">
|
<style:style style:name="Text_20_Meta" style:family="paragraph" style:display-name="Text Meta" style:parent-style-name="Standard" style:class="text">
|
||||||
<style:paragraph-properties fo:margin-top="0.000cm" fo:margin-bottom="0.247cm" fo:line-height="115%" />
|
<style:paragraph-properties fo:margin-top="0.000cm" fo:margin-bottom="0.247cm" fo:line-height="115%" />
|
||||||
@@ -64,10 +64,14 @@
|
|||||||
<style:style style:name="Header" style:family="paragraph" style:display-name="Header" style:parent-style-name="Header_20_and_20_Footer">
|
<style:style style:name="Header" style:family="paragraph" style:display-name="Header" style:parent-style-name="Header_20_and_20_Footer">
|
||||||
<style:paragraph-properties fo:text-align="right" />
|
<style:paragraph-properties fo:text-align="right" />
|
||||||
</style:style>
|
</style:style>
|
||||||
|
<style:style style:name="Footnote" style:family="paragraph" style:display-name="Footnote" style:parent-style-name="Standard" style:class="extra">
|
||||||
|
<style:paragraph-properties fo:margin-bottom="0.198cm" fo:margin-left="0.600cm" fo:text-indent="-0.600cm" />
|
||||||
|
<style:text-properties fo:font-size="10pt" />
|
||||||
|
</style:style>
|
||||||
</office:styles>
|
</office:styles>
|
||||||
<office:automatic-styles>
|
<office:automatic-styles>
|
||||||
<style:page-layout style:name="PM1">
|
<style:page-layout style:name="PM1">
|
||||||
<style:page-layout-properties fo:page-width="14.800cm" fo:page-height="21.000cm" fo:margin-top="2.000cm" fo:margin-bottom="1.800cm" fo:margin-left="1.700cm" fo:margin-right="1.500cm" fo:print-orientation="portrait" />
|
<style:page-layout-properties fo:page-width="14.800cm" fo:page-height="21.000cm" fo:margin-top="2.000cm" fo:margin-bottom="1.800cm" fo:margin-left="1.700cm" fo:margin-right="1.500cm" />
|
||||||
<style:header-style>
|
<style:header-style>
|
||||||
<style:header-footer-properties fo:min-height="0.600cm" fo:margin-left="0.000cm" fo:margin-right="0.000cm" fo:margin-bottom="0.500cm" />
|
<style:header-footer-properties fo:min-height="0.600cm" fo:margin-left="0.000cm" fo:margin-right="0.000cm" fo:margin-bottom="0.500cm" />
|
||||||
</style:header-style>
|
</style:header-style>
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
<style:text-properties style:font-name="Liberation Serif" fo:font-family="'Liberation Serif'" fo:font-size="12pt" />
|
<style:text-properties style:font-name="Liberation Serif" fo:font-family="'Liberation Serif'" fo:font-size="12pt" />
|
||||||
</style:style>
|
</style:style>
|
||||||
<style:style style:name="First_20_line_20_indent" style:family="paragraph" style:display-name="First line indent" style:parent-style-name="Text_20_body" style:class="text">
|
<style:style style:name="First_20_line_20_indent" style:family="paragraph" style:display-name="First line indent" style:parent-style-name="Text_20_body" style:class="text">
|
||||||
<style:paragraph-properties fo:text-indent="0.499cm" />
|
<style:paragraph-properties fo:text-indent="0.593cm" />
|
||||||
</style:style>
|
</style:style>
|
||||||
<style:style style:name="Text_20_Meta" style:family="paragraph" style:display-name="Text Meta" style:parent-style-name="Standard" style:class="text">
|
<style:style style:name="Text_20_Meta" style:family="paragraph" style:display-name="Text Meta" style:parent-style-name="Standard" style:class="text">
|
||||||
<style:paragraph-properties fo:margin-top="0.000cm" fo:margin-bottom="0.247cm" fo:line-height="115%" />
|
<style:paragraph-properties fo:margin-top="0.000cm" fo:margin-bottom="0.247cm" fo:line-height="115%" />
|
||||||
@@ -54,10 +54,14 @@
|
|||||||
<style:style style:name="Header" style:family="paragraph" style:display-name="Header" style:parent-style-name="Header_20_and_20_Footer">
|
<style:style style:name="Header" style:family="paragraph" style:display-name="Header" style:parent-style-name="Header_20_and_20_Footer">
|
||||||
<style:paragraph-properties fo:text-align="right" />
|
<style:paragraph-properties fo:text-align="right" />
|
||||||
</style:style>
|
</style:style>
|
||||||
|
<style:style style:name="Footnote" style:family="paragraph" style:display-name="Footnote" style:parent-style-name="Standard" style:class="extra">
|
||||||
|
<style:paragraph-properties fo:margin-bottom="0.198cm" fo:margin-left="0.600cm" fo:text-indent="-0.600cm" />
|
||||||
|
<style:text-properties fo:font-size="10pt" />
|
||||||
|
</style:style>
|
||||||
</office:styles>
|
</office:styles>
|
||||||
<office:automatic-styles>
|
<office:automatic-styles>
|
||||||
<style:page-layout style:name="PM1">
|
<style:page-layout style:name="PM1">
|
||||||
<style:page-layout-properties fo:page-width="21.0cm" fo:page-height="29.7cm" fo:margin-top="2.000cm" fo:margin-bottom="2.000cm" fo:margin-left="2.000cm" fo:margin-right="2.000cm" fo:print-orientation="portrait" />
|
<style:page-layout-properties fo:page-width="21.0cm" fo:page-height="29.7cm" fo:margin-top="2.000cm" fo:margin-bottom="2.000cm" fo:margin-left="2.000cm" fo:margin-right="2.000cm" />
|
||||||
<style:header-style>
|
<style:header-style>
|
||||||
<style:header-footer-properties fo:min-height="0.600cm" fo:margin-left="0.000cm" fo:margin-right="0.000cm" fo:margin-bottom="0.500cm" />
|
<style:header-footer-properties fo:min-height="0.600cm" fo:margin-left="0.000cm" fo:margin-right="0.000cm" fo:margin-bottom="0.500cm" />
|
||||||
</style:header-style>
|
</style:header-style>
|
||||||
|
|||||||
@@ -20,18 +20,19 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||||||
"""
|
"""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import pytest
|
|
||||||
import zipfile
|
|
||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
|
import zipfile
|
||||||
|
|
||||||
from shutil import copyfile
|
from shutil import copyfile
|
||||||
|
|
||||||
from tools import ODT_IGNORE, cmpFiles
|
import pytest
|
||||||
|
|
||||||
from novelwriter.common import xmlIndent
|
from novelwriter.common import xmlIndent
|
||||||
from novelwriter.constants import nwHeadFmt
|
from novelwriter.constants import nwHeadFmt
|
||||||
from novelwriter.core.toodt import ToOdt, ODTParagraphStyle, ODTTextStyle, XMLParagraph, _mkTag
|
|
||||||
from novelwriter.core.project import NWProject
|
from novelwriter.core.project import NWProject
|
||||||
|
from novelwriter.core.toodt import ODTParagraphStyle, ODTTextStyle, ToOdt, XMLParagraph, _mkTag
|
||||||
|
|
||||||
|
from tests.tools import ODT_IGNORE, cmpFiles
|
||||||
|
|
||||||
XML_NS = [
|
XML_NS = [
|
||||||
' xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"',
|
' xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"',
|
||||||
@@ -132,7 +133,7 @@ def testCoreToOdt_TextFormatting(mockGUI):
|
|||||||
|
|
||||||
assert list(odt._mainPara.keys()) == [
|
assert list(odt._mainPara.keys()) == [
|
||||||
"Text_20_body", "First_20_line_20_indent", "Text_20_Meta", "Title", "Separator",
|
"Text_20_body", "First_20_line_20_indent", "Text_20_Meta", "Title", "Separator",
|
||||||
"Heading_20_1", "Heading_20_2", "Heading_20_3", "Heading_20_4", "Header",
|
"Heading_20_1", "Heading_20_2", "Heading_20_3", "Heading_20_4", "Header", "Footnote",
|
||||||
]
|
]
|
||||||
|
|
||||||
key = "55db6c1d22ff5aba93f0f67c8d4a857a26e2d3813dfbcba1ef7c0d424f501be5"
|
key = "55db6c1d22ff5aba93f0f67c8d4a857a26e2d3813dfbcba1ef7c0d424f501be5"
|
||||||
@@ -145,51 +146,51 @@ def testCoreToOdt_TextFormatting(mockGUI):
|
|||||||
oStyle = ODTParagraphStyle("test")
|
oStyle = ODTParagraphStyle("test")
|
||||||
|
|
||||||
# No Text
|
# No Text
|
||||||
odt.initDocument()
|
xTest = ET.Element(_mkTag("office", "text"))
|
||||||
odt._addTextPar("Standard", oStyle, "")
|
odt._addTextPar(xTest, "Standard", oStyle, "")
|
||||||
assert xmlToText(odt._xText) == (
|
assert xmlToText(xTest) == (
|
||||||
'<office:text>'
|
'<office:text>'
|
||||||
'<text:p text:style-name="Standard" />'
|
'<text:p text:style-name="Standard" />'
|
||||||
'</office:text>'
|
'</office:text>'
|
||||||
)
|
)
|
||||||
|
|
||||||
# No Format
|
# No Format
|
||||||
odt.initDocument()
|
xTest = ET.Element(_mkTag("office", "text"))
|
||||||
odt._addTextPar("Standard", oStyle, "Hello World")
|
odt._addTextPar(xTest, "Standard", oStyle, "Hello World")
|
||||||
assert odt.errData == []
|
assert odt.errData == []
|
||||||
assert xmlToText(odt._xText) == (
|
assert xmlToText(xTest) == (
|
||||||
'<office:text>'
|
'<office:text>'
|
||||||
'<text:p text:style-name="Standard">Hello World</text:p>'
|
'<text:p text:style-name="Standard">Hello World</text:p>'
|
||||||
'</office:text>'
|
'</office:text>'
|
||||||
)
|
)
|
||||||
|
|
||||||
# Heading Level None
|
# Heading Level None
|
||||||
odt.initDocument()
|
xTest = ET.Element(_mkTag("office", "text"))
|
||||||
odt._addTextPar("Standard", oStyle, "Hello World", isHead=True)
|
odt._addTextPar(xTest, "Standard", oStyle, "Hello World", isHead=True)
|
||||||
assert odt.errData == []
|
assert odt.errData == []
|
||||||
assert xmlToText(odt._xText) == (
|
assert xmlToText(xTest) == (
|
||||||
'<office:text>'
|
'<office:text>'
|
||||||
'<text:h text:style-name="Standard">Hello World</text:h>'
|
'<text:h text:style-name="Standard">Hello World</text:h>'
|
||||||
'</office:text>'
|
'</office:text>'
|
||||||
)
|
)
|
||||||
|
|
||||||
# Heading Level 1
|
# Heading Level 1
|
||||||
odt.initDocument()
|
xTest = ET.Element(_mkTag("office", "text"))
|
||||||
odt._addTextPar("Standard", oStyle, "Hello World", isHead=True, oLevel="1")
|
odt._addTextPar(xTest, "Standard", oStyle, "Hello World", isHead=True, oLevel="1")
|
||||||
assert odt.errData == []
|
assert odt.errData == []
|
||||||
assert xmlToText(odt._xText) == (
|
assert xmlToText(xTest) == (
|
||||||
'<office:text>'
|
'<office:text>'
|
||||||
'<text:h text:style-name="Standard" text:outline-level="1">Hello World</text:h>'
|
'<text:h text:style-name="Standard" text:outline-level="1">Hello World</text:h>'
|
||||||
'</office:text>'
|
'</office:text>'
|
||||||
)
|
)
|
||||||
|
|
||||||
# Formatted Text
|
# Formatted Text
|
||||||
odt.initDocument()
|
|
||||||
text = "A bold word"
|
text = "A bold word"
|
||||||
fmt = [(2, odt.FMT_B_B), (6, odt.FMT_B_E)]
|
fmt = [(2, odt.FMT_B_B, ""), (6, odt.FMT_B_E, "")]
|
||||||
odt._addTextPar("Standard", oStyle, text, tFmt=fmt)
|
xTest = ET.Element(_mkTag("office", "text"))
|
||||||
|
odt._addTextPar(xTest, "Standard", oStyle, text, tFmt=fmt)
|
||||||
assert odt.errData == []
|
assert odt.errData == []
|
||||||
assert xmlToText(odt._xText) == (
|
assert xmlToText(xTest) == (
|
||||||
'<office:text>'
|
'<office:text>'
|
||||||
'<text:p text:style-name="Standard">A <text:span text:style-name="T1">bold</text:span> '
|
'<text:p text:style-name="Standard">A <text:span text:style-name="T1">bold</text:span> '
|
||||||
'word</text:p>'
|
'word</text:p>'
|
||||||
@@ -197,25 +198,26 @@ def testCoreToOdt_TextFormatting(mockGUI):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Incorrectly Formatted Text
|
# Incorrectly Formatted Text
|
||||||
odt.initDocument()
|
|
||||||
text = "A few words"
|
text = "A few words"
|
||||||
fmt = [(2, odt.FMT_B_B), (5, odt.FMT_B_E), (7, 99999)]
|
fmt = [(2, odt.FMT_B_B, ""), (5, odt.FMT_B_E, ""), (7, 99999, "")]
|
||||||
odt._addTextPar("Standard", oStyle, text, tFmt=fmt)
|
xTest = ET.Element(_mkTag("office", "text"))
|
||||||
|
odt._addTextPar(xTest, "Standard", oStyle, text, tFmt=fmt)
|
||||||
assert odt.errData == ["Unknown format tag encountered"]
|
assert odt.errData == ["Unknown format tag encountered"]
|
||||||
assert xmlToText(odt._xText) == (
|
assert xmlToText(xTest) == (
|
||||||
'<office:text>'
|
'<office:text>'
|
||||||
'<text:p text:style-name="Standard">A <text:span text:style-name="T1">few</text:span> '
|
'<text:p text:style-name="Standard">A <text:span text:style-name="T1">few</text:span> '
|
||||||
'words</text:p>'
|
'words</text:p>'
|
||||||
'</office:text>'
|
'</office:text>'
|
||||||
)
|
)
|
||||||
|
odt._errData = []
|
||||||
|
|
||||||
# Unclosed format
|
# Unclosed format
|
||||||
odt.initDocument()
|
|
||||||
text = "A bold word"
|
text = "A bold word"
|
||||||
fmt = [(2, odt.FMT_B_B)]
|
fmt = [(2, odt.FMT_B_B, "")]
|
||||||
odt._addTextPar("Standard", oStyle, text, tFmt=fmt)
|
xTest = ET.Element(_mkTag("office", "text"))
|
||||||
|
odt._addTextPar(xTest, "Standard", oStyle, text, tFmt=fmt)
|
||||||
assert odt.errData == []
|
assert odt.errData == []
|
||||||
assert xmlToText(odt._xText) == (
|
assert xmlToText(xTest) == (
|
||||||
'<office:text>'
|
'<office:text>'
|
||||||
'<text:p text:style-name="Standard">A '
|
'<text:p text:style-name="Standard">A '
|
||||||
'<text:span text:style-name="T1">bold word</text:span></text:p>'
|
'<text:span text:style-name="T1">bold word</text:span></text:p>'
|
||||||
@@ -223,12 +225,12 @@ def testCoreToOdt_TextFormatting(mockGUI):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Tabs and Breaks
|
# Tabs and Breaks
|
||||||
odt.initDocument()
|
|
||||||
text = "Hello\n\tWorld"
|
text = "Hello\n\tWorld"
|
||||||
fmt = []
|
fmt = []
|
||||||
odt._addTextPar("Standard", oStyle, text, tFmt=fmt)
|
xTest = ET.Element(_mkTag("office", "text"))
|
||||||
|
odt._addTextPar(xTest, "Standard", oStyle, text, tFmt=fmt)
|
||||||
assert odt.errData == []
|
assert odt.errData == []
|
||||||
assert xmlToText(odt._xText) == (
|
assert xmlToText(xTest) == (
|
||||||
'<office:text>'
|
'<office:text>'
|
||||||
'<text:p text:style-name="Standard">Hello<text:line-break /><text:tab />World</text:p>'
|
'<text:p text:style-name="Standard">Hello<text:line-break /><text:tab />World</text:p>'
|
||||||
'</office:text>'
|
'</office:text>'
|
||||||
@@ -835,22 +837,28 @@ def testCoreToOdt_Format(mockGUI):
|
|||||||
project = NWProject()
|
project = NWProject()
|
||||||
odt = ToOdt(project, isFlat=True)
|
odt = ToOdt(project, isFlat=True)
|
||||||
|
|
||||||
assert odt._formatSynopsis("synopsis text", True) == (
|
assert odt._formatSynopsis("synopsis text", [(9, ToOdt.FMT_STRIP, "")], True) == (
|
||||||
"Synopsis: synopsis text", [(0, ToOdt.FMT_B_B), (9, ToOdt.FMT_B_E)]
|
"Synopsis: synopsis text", [
|
||||||
|
(0, ToOdt.FMT_B_B, ""), (9, ToOdt.FMT_B_E, ""), (19, ToOdt.FMT_STRIP, "")
|
||||||
|
]
|
||||||
)
|
)
|
||||||
assert odt._formatSynopsis("short text", False) == (
|
assert odt._formatSynopsis("short text", [(6, ToOdt.FMT_STRIP, "")], False) == (
|
||||||
"Short Description: short text", [(0, ToOdt.FMT_B_B), (18, ToOdt.FMT_B_E)]
|
"Short Description: short text", [
|
||||||
|
(0, ToOdt.FMT_B_B, ""), (18, ToOdt.FMT_B_E, ""), (25, ToOdt.FMT_STRIP, "")
|
||||||
|
]
|
||||||
)
|
)
|
||||||
assert odt._formatComments("comment text") == (
|
assert odt._formatComments("comment text", [(8, ToOdt.FMT_STRIP, "")]) == (
|
||||||
"Comment: comment text", [(0, ToOdt.FMT_B_B), (8, ToOdt.FMT_B_E)]
|
"Comment: comment text", [
|
||||||
|
(0, ToOdt.FMT_B_B, ""), (8, ToOdt.FMT_B_E, ""), (17, ToOdt.FMT_STRIP, "")
|
||||||
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
assert odt._formatKeywords("") == ("", [])
|
assert odt._formatKeywords("") == ("", [])
|
||||||
assert odt._formatKeywords("tag: Jane") == (
|
assert odt._formatKeywords("tag: Jane") == (
|
||||||
"Tag: Jane", [(0, ToOdt.FMT_B_B), (4, ToOdt.FMT_B_E)]
|
"Tag: Jane", [(0, ToOdt.FMT_B_B, ""), (4, ToOdt.FMT_B_E, "")]
|
||||||
)
|
)
|
||||||
assert odt._formatKeywords("char: Bod, Jane") == (
|
assert odt._formatKeywords("char: Bod, Jane") == (
|
||||||
"Characters: Bod, Jane", [(0, ToOdt.FMT_B_B), (11, ToOdt.FMT_B_E)]
|
"Characters: Bod, Jane", [(0, ToOdt.FMT_B_B, ""), (11, ToOdt.FMT_B_E, "")]
|
||||||
)
|
)
|
||||||
|
|
||||||
# END Test testCoreToOdt_Format
|
# END Test testCoreToOdt_Format
|
||||||
|
|||||||
Reference in New Issue
Block a user