Update Odt tests

This commit is contained in:
Veronica Berglyd Olsen
2023-05-29 20:04:40 +02:00
parent 22e0f82654
commit a7ffbb0965
8 changed files with 175 additions and 189 deletions
@@ -1,13 +1,13 @@
<?xml version='1.0' encoding='utf-8'?>
<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:dc="http://purl.org/dc/elements/1.1/" 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>
<meta:creation-date>2023-02-12T15:10:11</meta:creation-date>
<meta:generator>novelWriter/2.0.4</meta:generator>
<meta:creation-date>2023-05-29T19:49:56</meta:creation-date>
<meta:generator>novelWriter/2.0.7</meta:generator>
<meta:initial-creator>Jane Smith</meta:initial-creator>
<meta:editing-cycles>1234</meta:editing-cycles>
<meta:editing-duration>P42DT12H34M56S</meta:editing-duration>
<dc:title>Test Project</dc:title>
<dc:date>2023-02-12T15:10:11</dc:date>
<dc:date>2023-05-29T19:49:56</dc:date>
<dc:creator>Jane Smith</dc:creator>
</office:meta>
<office:font-face-decls>
@@ -72,7 +72,8 @@
<office:master-styles>
<style:master-page style:name="Standard" style:page-layout-name="PM1">
<style:header>
<text:p text:style-name="Header">Test Project / Jane Smith / <text:page-number text:select-page="current">2</text:page-number></text:p>
<text:p text:style-name="Header">Test Project / Jane Smith / <text:page-number text:select-page="current">2</text:page-number>
</text:p>
</style:header>
<style:header-first>
<text:p text:style-name="Header" />
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:dc="http://purl.org/dc/elements/1.1/" office:version="1.3">
<office:document-content xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible: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:font-face-decls>
<style:font-face style:name="Liberation Serif" style:font-pitch="variable" />
</office:font-face-decls>
+4 -4
View File
@@ -1,13 +1,13 @@
<?xml version='1.0' encoding='utf-8'?>
<office:document-meta xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:dc="http://purl.org/dc/elements/1.1/" office:version="1.3">
<office:document-meta xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" office:version="1.3">
<office:meta>
<meta:creation-date>2023-02-12T15:09:03</meta:creation-date>
<meta:generator>novelWriter/2.0.4</meta:generator>
<meta:creation-date>2023-05-29T19:48:33</meta:creation-date>
<meta:generator>novelWriter/2.0.7</meta:generator>
<meta:initial-creator>Jane Smith</meta:initial-creator>
<meta:editing-cycles>1234</meta:editing-cycles>
<meta:editing-duration>P42DT12H34M56S</meta:editing-duration>
<dc:title>Test Project</dc:title>
<dc:date>2023-02-12T15:09:03</dc:date>
<dc:date>2023-05-29T19:48:33</dc:date>
<dc:creator>Jane Smith</dc:creator>
</office:meta>
</office:document-meta>
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<office:document-styles xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:dc="http://purl.org/dc/elements/1.1/" office:version="1.3">
<office:document-styles 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: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:font-face-decls>
<style:font-face style:name="Liberation Serif" style:font-pitch="variable" />
</office:font-face-decls>
@@ -59,7 +59,8 @@
<office:master-styles>
<style:master-page style:name="Standard" style:page-layout-name="PM1">
<style:header>
<text:p text:style-name="Header">Test Project / Jane Smith / <text:page-number text:select-page="current">2</text:page-number></text:p>
<text:p text:style-name="Header">Test Project / Jane Smith / <text:page-number text:select-page="current">2</text:page-number>
</text:p>
</style:header>
<style:header-first>
<text:p text:style-name="Header" />
@@ -1,13 +1,13 @@
<?xml version='1.0' encoding='utf-8'?>
<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:dc="http://purl.org/dc/elements/1.1/" 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>
<meta:creation-date>2023-02-12T14:52:03</meta:creation-date>
<meta:generator>novelWriter/2.0.4</meta:generator>
<meta:creation-date>2023-05-29T20:00:01</meta:creation-date>
<meta:generator>novelWriter/2.0.7</meta:generator>
<meta:initial-creator>lipsum.com</meta:initial-creator>
<meta:editing-cycles>38</meta:editing-cycles>
<meta:editing-duration>P0DT0H31M40S</meta:editing-duration>
<meta:editing-cycles>40</meta:editing-cycles>
<meta:editing-duration>P0DT0H31M45S</meta:editing-duration>
<dc:title>Lorem Ipsum</dc:title>
<dc:date>2023-02-12T14:52:03</dc:date>
<dc:date>2023-05-29T20:00:01</dc:date>
<dc:creator>lipsum.com</dc:creator>
</office:meta>
<office:font-face-decls>
@@ -84,7 +84,8 @@
<office:master-styles>
<style:master-page style:name="Standard" style:page-layout-name="PM1">
<style:header>
<text:p text:style-name="Header">Lorem Ipsum / lipsum.com / <text:page-number text:select-page="current">2</text:page-number></text:p>
<text:p text:style-name="Header">Lorem Ipsum / lipsum.com / <text:page-number text:select-page="current">2</text:page-number>
</text:p>
</style:header>
<style:header-first>
<text:p text:style-name="Header" />
@@ -94,13 +95,16 @@
<office:body>
<office:text>
<text:p text:style-name="Title">Lorem Ipsum</text:p>
<text:p text:style-name="P1"><text:span text:style-name="T1">By lipsum.com</text:span></text:p>
<text:p text:style-name="P1">
<text:span text:style-name="T1">By lipsum.com</text:span>
</text:p>
<text:p text:style-name="P1">“Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit…”</text:p>
<text:p text:style-name="P1">“There is no one who loves pain itself, who seeks after it and wants to have it, simply because it is pain…”</text:p>
<text:p text:style-name="Text_20_body">Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of “de Finibus Bonorum et Malorum” (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, “Lorem ipsum dolor sit amet..”, comes from a line in section 1.10.32.</text:p>
<text:p text:style-name="Text_20_body">The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from “de Finibus Bonorum et Malorum” by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.</text:p>
<text:h text:style-name="P2" text:outline-level="2">Prologue</text:h>
<text:p text:style-name="Text_20_body"><text:span text:style-name="T2">Lorem Ipsum</text:span> is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</text:p>
<text:p text:style-name="Text_20_body">
<text:span text:style-name="T2">Lorem Ipsum</text:span> is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</text:p>
<text:h text:style-name="P3" text:outline-level="1">Act One</text:h>
<text:p text:style-name="P1">“Fusce maximus felis libero”</text:p>
<text:h text:style-name="P2" text:outline-level="2">Chapter 1: Chapter One</text:h>
+24 -44
View File
@@ -21,12 +21,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
import pytest
import zipfile
import xml.etree.ElementTree as ET
from lxml import etree
from shutil import copyfile
from tools import ODT_IGNORE, cmpFiles
from novelwriter.common import xmlIndent
from novelwriter.core.toodt import ToOdt, ODTParagraphStyle, ODTTextStyle, XMLParagraph, _mkTag
from novelwriter.core.project import NWProject
@@ -44,7 +45,7 @@ XML_NS = [
def xmlToText(xElem):
"""Get the text content of an XML element.
"""
rTxt = etree.tostring(xElem, encoding="utf-8", xml_declaration=False).decode()
rTxt = ET.tostring(xElem, encoding="utf-8", xml_declaration=False).decode()
for nSpace in XML_NS:
rTxt = rTxt.replace(nSpace, "")
return rTxt
@@ -147,7 +148,7 @@ def testCoreToOdt_TextFormatting(mockGUI):
theDoc._addTextPar("Standard", oStyle, "")
assert xmlToText(theDoc._xText) == (
"<office:text>"
"<text:p text:style-name=\"Standard\"></text:p>"
"<text:p text:style-name=\"Standard\" />"
"</office:text>"
)
@@ -474,9 +475,9 @@ def testCoreToOdt_Convert(mockGUI):
assert theDoc.getErrors() == []
assert xmlToText(theDoc._xText) == (
'<office:text>'
'<text:p text:style-name="Text_20_body"></text:p>'
'<text:p text:style-name="Text_20_body" />'
'<text:p text:style-name="Text_20_body">Text</text:p>'
'<text:p text:style-name="Text_20_body"></text:p>'
'<text:p text:style-name="Text_20_body" />'
'<text:p text:style-name="Text_20_body">Text</text:p>'
'</office:text>'
)
@@ -723,15 +724,10 @@ def testCoreToOdt_SaveFull(mockGUI, fncPath, tstPaths):
stylOut = tstPaths.outDir / "coreToOdt_SaveFull" / "styles.xml"
def prettifyXml(inFile, outFile):
with open(outFile, mode="wb") as fileStream:
fileStream.write(
etree.tostring(
etree.parse(str(inFile)),
pretty_print=True,
encoding="utf-8",
xml_declaration=True
)
)
with open(outFile, mode="wb") as fStream:
xml = ET.parse(inFile)
xmlIndent(xml, space=" ")
xml.write(fStream, encoding="utf-8", xml_declaration=True)
prettifyXml(maniOut, maniFile)
prettifyXml(settOut, settFile)
@@ -949,11 +945,7 @@ def testCoreToOdt_ODTParagraphStyle():
# Pack XML
# ========
xStyle = etree.Element("test", nsmap={
"style": "urn:oasis:names:tc:opendocument:xmlns:style:1.0",
"loext": "urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0",
"fo": "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0",
})
xStyle = ET.Element("test")
parStyle.packXML(xStyle, "test")
assert xmlToText(xStyle) == (
'<test>'
@@ -1059,10 +1051,7 @@ def testCoreToOdt_ODTTextStyle():
txtStyle.setFontStyle("italic")
txtStyle.setStrikeStyle("solid")
txtStyle.setStrikeType("single")
xStyle = etree.Element("test", nsmap={
"style": "urn:oasis:names:tc:opendocument:xmlns:style:1.0",
"fo": "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0",
})
xStyle = ET.Element("test")
txtStyle.packXML(xStyle, "test")
assert xmlToText(xStyle) == (
'<test><style:style style:name="test" style:family="text"><style:text-properties '
@@ -1077,20 +1066,11 @@ def testCoreToOdt_ODTTextStyle():
def testCoreToOdt_XMLParagraph():
"""Test XML encoding of paragraph.
"""
nsMap = {
"office": "urn:oasis:names:tc:opendocument:xmlns:office:1.0",
"style": "urn:oasis:names:tc:opendocument:xmlns:style:1.0",
"loext": "urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0",
"text": "urn:oasis:names:tc:opendocument:xmlns:text:1.0",
"meta": "urn:oasis:names:tc:opendocument:xmlns:meta:1.0",
"fo": "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0",
}
# Stage 1 : Text
# ==============
xRoot = etree.Element("root", nsmap=nsMap)
xElem = etree.SubElement(xRoot, "{%s}p" % nsMap["text"])
xRoot = ET.Element("root")
xElem = ET.SubElement(xRoot, _mkTag("text", "p"))
xmlPar = XMLParagraph(xElem)
# Plain Text
@@ -1126,8 +1106,8 @@ def testCoreToOdt_XMLParagraph():
# Stage 2 : Line Breaks
# =====================
xRoot = etree.Element("root", nsmap=nsMap)
xElem = etree.SubElement(xRoot, "{%s}p" % nsMap["text"])
xRoot = ET.Element("root")
xElem = ET.SubElement(xRoot, _mkTag("text", "p"))
xmlPar = XMLParagraph(xElem)
# Plain Text w/Line Break
@@ -1162,8 +1142,8 @@ def testCoreToOdt_XMLParagraph():
# Stage 3 : Tabs
# ==============
xRoot = etree.Element("root", nsmap=nsMap)
xElem = etree.SubElement(xRoot, "{%s}p" % nsMap["text"])
xRoot = ET.Element("root")
xElem = ET.SubElement(xRoot, _mkTag("text", "p"))
xmlPar = XMLParagraph(xElem)
# Plain Text w/Line Break
@@ -1198,8 +1178,8 @@ def testCoreToOdt_XMLParagraph():
# Stage 4 : Spaces
# ================
xRoot = etree.Element("root", nsmap=nsMap)
xElem = etree.SubElement(xRoot, "{%s}p" % nsMap["text"])
xRoot = ET.Element("root")
xElem = ET.SubElement(xRoot, _mkTag("text", "p"))
xmlPar = XMLParagraph(xElem)
# Plain Text w/Spaces
@@ -1234,8 +1214,8 @@ def testCoreToOdt_XMLParagraph():
# Stage 5 : Lots of Spaces
# ========================
xRoot = etree.Element("root", nsmap=nsMap)
xElem = etree.SubElement(xRoot, "{%s}p" % nsMap["text"])
xRoot = ET.Element("root")
xElem = ET.SubElement(xRoot, _mkTag("text", "p"))
xmlPar = XMLParagraph(xElem)
# Plain Text w/Many Spaces
@@ -1261,8 +1241,8 @@ def testCoreToOdt_XMLParagraph():
# Check Error
# ===========
xRoot = etree.Element("root", nsmap=nsMap)
xElem = etree.SubElement(xRoot, "{%s}p" % nsMap["text"])
xRoot = ET.Element("root")
xElem = ET.SubElement(xRoot, _mkTag("text", "p"))
xmlPar = XMLParagraph(xElem)
xmlPar.appendText("A")