From a7ffbb0965e31fcd839d590bc9fd8205dbcb69ff Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Mon, 29 May 2023 20:04:40 +0200 Subject: [PATCH] Update Odt tests --- .../coreToOdt_SaveFlat_document.fodt | 63 ++++---- .../reference/coreToOdt_SaveFull_content.xml | 6 +- .../reference/coreToOdt_SaveFull_manifest.xml | 10 +- tests/reference/coreToOdt_SaveFull_meta.xml | 8 +- .../reference/coreToOdt_SaveFull_settings.xml | 2 +- tests/reference/coreToOdt_SaveFull_styles.xml | 55 +++---- .../guiBuild_Tool_Step1_Lorem_Ipsum.fodt | 82 ++++++----- tests/test_core/test_core_toodt.py | 138 ++++++++---------- 8 files changed, 175 insertions(+), 189 deletions(-) diff --git a/tests/reference/coreToOdt_SaveFlat_document.fodt b/tests/reference/coreToOdt_SaveFlat_document.fodt index 6e879a5c..dd64cb33 100644 --- a/tests/reference/coreToOdt_SaveFlat_document.fodt +++ b/tests/reference/coreToOdt_SaveFlat_document.fodt @@ -1,81 +1,82 @@ - + - 2023-02-12T15:10:11 - novelWriter/2.0.4 + 2023-05-29T19:49:56 + novelWriter/2.0.7 Jane Smith 1234 P42DT12H34M56S Test Project - 2023-02-12T15:10:11 + 2023-05-29T19:49:56 Jane Smith - + - - + + - + - - + + - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + - + - + - + - Test Project / Jane Smith / 2 + Test Project / Jane Smith / 2 + - + diff --git a/tests/reference/coreToOdt_SaveFull_content.xml b/tests/reference/coreToOdt_SaveFull_content.xml index 4e191f7c..0654b0f3 100644 --- a/tests/reference/coreToOdt_SaveFull_content.xml +++ b/tests/reference/coreToOdt_SaveFull_content.xml @@ -1,11 +1,11 @@ - + - + - + diff --git a/tests/reference/coreToOdt_SaveFull_manifest.xml b/tests/reference/coreToOdt_SaveFull_manifest.xml index f939a7b3..858f5ff8 100644 --- a/tests/reference/coreToOdt_SaveFull_manifest.xml +++ b/tests/reference/coreToOdt_SaveFull_manifest.xml @@ -1,8 +1,8 @@ - - - - - + + + + + diff --git a/tests/reference/coreToOdt_SaveFull_meta.xml b/tests/reference/coreToOdt_SaveFull_meta.xml index 79930faa..8791d9d7 100644 --- a/tests/reference/coreToOdt_SaveFull_meta.xml +++ b/tests/reference/coreToOdt_SaveFull_meta.xml @@ -1,13 +1,13 @@ - + - 2023-02-12T15:09:03 - novelWriter/2.0.4 + 2023-05-29T19:48:33 + novelWriter/2.0.7 Jane Smith 1234 P42DT12H34M56S Test Project - 2023-02-12T15:09:03 + 2023-05-29T19:48:33 Jane Smith diff --git a/tests/reference/coreToOdt_SaveFull_settings.xml b/tests/reference/coreToOdt_SaveFull_settings.xml index 7b5218f2..53e43d1f 100644 --- a/tests/reference/coreToOdt_SaveFull_settings.xml +++ b/tests/reference/coreToOdt_SaveFull_settings.xml @@ -1,2 +1,2 @@ - + diff --git a/tests/reference/coreToOdt_SaveFull_styles.xml b/tests/reference/coreToOdt_SaveFull_styles.xml index 5319adf2..6c5f9bd2 100644 --- a/tests/reference/coreToOdt_SaveFull_styles.xml +++ b/tests/reference/coreToOdt_SaveFull_styles.xml @@ -1,68 +1,69 @@ - + - + - - + + - + - - + + - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + - + - + - Test Project / Jane Smith / 2 + Test Project / Jane Smith / 2 + - + diff --git a/tests/reference/guiBuild_Tool_Step1_Lorem_Ipsum.fodt b/tests/reference/guiBuild_Tool_Step1_Lorem_Ipsum.fodt index d327ee5b..ce4afc35 100644 --- a/tests/reference/guiBuild_Tool_Step1_Lorem_Ipsum.fodt +++ b/tests/reference/guiBuild_Tool_Step1_Lorem_Ipsum.fodt @@ -1,106 +1,110 @@ - + - 2023-02-12T14:52:03 - novelWriter/2.0.4 + 2023-05-29T20:00:01 + novelWriter/2.0.7 lipsum.com - 38 - P0DT0H31M40S + 40 + P0DT0H31M45S Lorem Ipsum - 2023-02-12T14:52:03 + 2023-05-29T20:00:01 lipsum.com - + - - + + - + - - + + - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + - + - + - + - + - + - + - + - Lorem Ipsum / lipsum.com / 2 + Lorem Ipsum / lipsum.com / 2 + - + Lorem Ipsum - By lipsum.com + + By lipsum.com + “Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit…” “There is no one who loves pain itself, who seeks after it and wants to have it, simply because it is pain…” 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. 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. Prologue - Lorem Ipsum 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. + + Lorem Ipsum 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. Act One “Fusce maximus felis libero” Chapter 1: Chapter One diff --git a/tests/test_core/test_core_toodt.py b/tests/test_core/test_core_toodt.py index 6e3ea446..c85e473f 100644 --- a/tests/test_core/test_core_toodt.py +++ b/tests/test_core/test_core_toodt.py @@ -21,12 +21,13 @@ along with this program. If not, see . 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 @@ -113,7 +114,7 @@ def testCoreToOdt_TextFormatting(mockGUI): theDoc = ToOdt(theProject, isFlat=True) theDoc.initDocument() - assert xmlToText(theDoc._xText) == "" + assert xmlToText(theDoc._xText) == "" # Paragraph Style # =============== @@ -147,7 +148,7 @@ def testCoreToOdt_TextFormatting(mockGUI): theDoc._addTextPar("Standard", oStyle, "") assert xmlToText(theDoc._xText) == ( "" - "" + "" "" ) @@ -217,7 +218,7 @@ def testCoreToOdt_TextFormatting(mockGUI): assert theDoc.getErrors() == [] assert xmlToText(theDoc._xText) == ( "" - "HelloWorld" + "HelloWorld" "" ) @@ -366,7 +367,7 @@ def testCoreToOdt_Convert(mockGUI): assert theDoc.getErrors() == [] assert xmlToText(theDoc._xText) == ( '' - 'Some text.Next line' + 'Some text.Next line' '' ) @@ -379,7 +380,7 @@ def testCoreToOdt_Convert(mockGUI): assert theDoc.getErrors() == [] assert xmlToText(theDoc._xText) == ( '' - 'Item 1Item 2' + 'Item 1Item 2' '' ) @@ -393,7 +394,7 @@ def testCoreToOdt_Convert(mockGUI): assert xmlToText(theDoc._xText) == ( '' 'Some ' - 'boldtext' + 'boldtext' '' ) @@ -413,8 +414,8 @@ def testCoreToOdt_Convert(mockGUI): '' 'Scene' 'Hello World' - 'Hello World' - 'Hello World' + 'Hello World' + 'Hello World' '' ) @@ -474,9 +475,9 @@ def testCoreToOdt_Convert(mockGUI): assert theDoc.getErrors() == [] assert xmlToText(theDoc._xText) == ( '' - '' + '' 'Text' - '' + '' 'Text' '' ) @@ -540,7 +541,7 @@ def testCoreToOdt_Convert(mockGUI): '' 'Scene' 'Regular paragraph' - 'withbreak' + 'withbreak' 'Left Align' '' ) @@ -592,7 +593,7 @@ def testCoreToOdt_ConvertDirect(mockGUI): assert ( '' - '' + '' '' ) in xmlToText(theDoc._xAuto) assert xmlToText(theDoc._xText) == ( @@ -613,7 +614,7 @@ def testCoreToOdt_ConvertDirect(mockGUI): assert ( '' - '' + '' '' ) in xmlToText(theDoc._xAuto) assert xmlToText(theDoc._xText) == ( @@ -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,20 +945,16 @@ 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) == ( '' '' '' + 'fo:margin-left="0.000cm" fo:margin-right="0.000cm" fo:line-height="1.15" />' '' + 'fo:font-size="12pt" fo:color="#000000" loext:opacity="1.00" />' '' '' ) @@ -1059,15 +1051,12 @@ 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) == ( '' + 'style:text-line-through-type="single" />' ) # END Test testCoreToOdt_ODTTextStyle @@ -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,15 +1106,15 @@ 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 xmlPar.appendText("Hello\nWorld\n!!") assert xmlToText(xRoot) == ( '' - 'HelloWorld!!' + 'HelloWorld!!' '' ) @@ -1142,8 +1122,8 @@ def testCoreToOdt_XMLParagraph(): xmlPar.appendSpan("spanned\ntext", "T1") assert xmlToText(xRoot) == ( '' - 'HelloWorld!!' - 'spannedtext' + 'HelloWorld!!' + 'spannedtext' '' ) @@ -1151,9 +1131,9 @@ def testCoreToOdt_XMLParagraph(): xmlPar.appendText("more\ntext") assert xmlToText(xRoot) == ( '' - 'HelloWorld!!' - 'spannedtext' - 'moretext' + 'HelloWorld!!' + 'spannedtext' + 'moretext' '' ) @@ -1162,15 +1142,15 @@ 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 xmlPar.appendText("Hello\tWorld\t!!") assert xmlToText(xRoot) == ( '' - 'HelloWorld!!' + 'HelloWorld!!' '' ) @@ -1178,8 +1158,8 @@ def testCoreToOdt_XMLParagraph(): xmlPar.appendSpan("spanned\ttext", "T1") assert xmlToText(xRoot) == ( '' - 'HelloWorld!!' - 'spannedtext' + 'HelloWorld!!' + 'spannedtext' '' ) @@ -1187,9 +1167,9 @@ def testCoreToOdt_XMLParagraph(): xmlPar.appendText("more\ttext") assert xmlToText(xRoot) == ( '' - 'HelloWorld!!' - 'spannedtext' - 'moretext' + 'HelloWorld!!' + 'spannedtext' + 'moretext' '' ) @@ -1198,15 +1178,15 @@ 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 xmlPar.appendText("Hello World !!") assert xmlToText(xRoot) == ( '' - 'Hello World !!' + 'Hello World !!' '' ) @@ -1214,8 +1194,8 @@ def testCoreToOdt_XMLParagraph(): xmlPar.appendSpan("spanned text", "T1") assert xmlToText(xRoot) == ( '' - 'Hello World !!' - 'spanned text' + 'Hello World !!' + 'spanned text' '' ) @@ -1223,9 +1203,9 @@ def testCoreToOdt_XMLParagraph(): xmlPar.appendText("more text") assert xmlToText(xRoot) == ( '' - 'Hello World !!' - 'spanned text' - 'more text' + 'Hello World !!' + 'spanned text' + 'more text' '' ) @@ -1234,15 +1214,15 @@ 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 xmlPar.appendText(" \t A \n B ") assert xmlToText(xRoot) == ( '' - ' A B ' + ' A B ' '' ) @@ -1250,9 +1230,9 @@ def testCoreToOdt_XMLParagraph(): xmlPar.appendSpan(" C \t D \n E ", "T1") assert xmlToText(xRoot) == ( '' - ' A B ' - ' C D ' - ' E ' + ' A B ' + ' C D ' + ' E ' '' ) @@ -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")