Refactor ODT writer class (#1796)
This commit is contained in:
+332
-355
File diff suppressed because it is too large
Load Diff
@@ -118,7 +118,7 @@ def testCoreToOdt_TextFormatting(mockGUI):
|
|||||||
|
|
||||||
# Paragraph Style
|
# Paragraph Style
|
||||||
# ===============
|
# ===============
|
||||||
oStyle = ODTParagraphStyle()
|
oStyle = ODTParagraphStyle("test")
|
||||||
|
|
||||||
assert odt._paraStyle("stuff", oStyle) == "Standard"
|
assert odt._paraStyle("stuff", oStyle) == "Standard"
|
||||||
assert odt._paraStyle("Text_20_body", oStyle) == "Text_20_body"
|
assert odt._paraStyle("Text_20_body", oStyle) == "Text_20_body"
|
||||||
@@ -136,12 +136,13 @@ def testCoreToOdt_TextFormatting(mockGUI):
|
|||||||
]
|
]
|
||||||
|
|
||||||
key = "55db6c1d22ff5aba93f0f67c8d4a857a26e2d3813dfbcba1ef7c0d424f501be5"
|
key = "55db6c1d22ff5aba93f0f67c8d4a857a26e2d3813dfbcba1ef7c0d424f501be5"
|
||||||
assert odt._autoPara[key][0] == "P1"
|
assert key in odt._autoPara
|
||||||
assert isinstance(odt._autoPara[key][1], ODTParagraphStyle)
|
assert isinstance(odt._autoPara[key], ODTParagraphStyle)
|
||||||
|
assert odt._autoPara[key].name == "P1"
|
||||||
|
|
||||||
# Paragraph Formatting
|
# Paragraph Formatting
|
||||||
# ====================
|
# ====================
|
||||||
oStyle = ODTParagraphStyle()
|
oStyle = ODTParagraphStyle("test")
|
||||||
|
|
||||||
# No Text
|
# No Text
|
||||||
odt.initDocument()
|
odt.initDocument()
|
||||||
@@ -333,9 +334,9 @@ def testCoreToOdt_ConvertParagraphs(mockGUI):
|
|||||||
odt._isNovel = True
|
odt._isNovel = True
|
||||||
|
|
||||||
def getStyle(styleName):
|
def getStyle(styleName):
|
||||||
for aSet in odt._autoPara.values():
|
for style in odt._autoPara.values():
|
||||||
if aSet[0] == styleName:
|
if style.name == styleName:
|
||||||
return aSet[1]
|
return style
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# Nested Markdown Text
|
# Nested Markdown Text
|
||||||
@@ -713,6 +714,8 @@ def testCoreToOdt_SaveFlat(mockGUI, fncPath, tstPaths):
|
|||||||
assert odt._colourHead is True
|
assert odt._colourHead is True
|
||||||
odt.setHeaderFormat(nwHeadFmt.ODT_AUTO, 1)
|
odt.setHeaderFormat(nwHeadFmt.ODT_AUTO, 1)
|
||||||
assert odt._headerFormat == nwHeadFmt.ODT_AUTO
|
assert odt._headerFormat == nwHeadFmt.ODT_AUTO
|
||||||
|
odt.setFirstLineIndent(True)
|
||||||
|
assert odt._firstIndent is True
|
||||||
|
|
||||||
odt.setPageLayout(148, 210, 20, 18, 17, 15)
|
odt.setPageLayout(148, 210, 20, 18, 17, 15)
|
||||||
assert odt._mDocWidth == "14.800cm"
|
assert odt._mDocWidth == "14.800cm"
|
||||||
@@ -856,7 +859,7 @@ def testCoreToOdt_Format(mockGUI):
|
|||||||
@pytest.mark.core
|
@pytest.mark.core
|
||||||
def testCoreToOdt_ODTParagraphStyle():
|
def testCoreToOdt_ODTParagraphStyle():
|
||||||
"""Test the ODTParagraphStyle class."""
|
"""Test the ODTParagraphStyle class."""
|
||||||
parStyle = ODTParagraphStyle()
|
parStyle = ODTParagraphStyle("test")
|
||||||
|
|
||||||
# Set Attributes
|
# Set Attributes
|
||||||
# ==============
|
# ==============
|
||||||
@@ -1023,7 +1026,7 @@ def testCoreToOdt_ODTParagraphStyle():
|
|||||||
assert parStyle._tAttr["color"] == ["fo", None]
|
assert parStyle._tAttr["color"] == ["fo", None]
|
||||||
assert parStyle._tAttr["opacity"] == ["loext", None]
|
assert parStyle._tAttr["opacity"] == ["loext", None]
|
||||||
|
|
||||||
parStyle.setColor("#000000")
|
parStyle.setColour("#000000")
|
||||||
parStyle.setOpacity("1.00")
|
parStyle.setOpacity("1.00")
|
||||||
|
|
||||||
assert parStyle._tAttr["color"] == ["fo", "#000000"]
|
assert parStyle._tAttr["color"] == ["fo", "#000000"]
|
||||||
@@ -1032,7 +1035,7 @@ def testCoreToOdt_ODTParagraphStyle():
|
|||||||
# Pack XML
|
# Pack XML
|
||||||
# ========
|
# ========
|
||||||
xStyle = ET.Element("test")
|
xStyle = ET.Element("test")
|
||||||
parStyle.packXML(xStyle, "test")
|
parStyle.packXML(xStyle)
|
||||||
assert xmlToText(xStyle) == (
|
assert xmlToText(xStyle) == (
|
||||||
'<test>'
|
'<test>'
|
||||||
'<style:style style:name="test" style:family="paragraph" style:display-name="Name" '
|
'<style:style style:name="test" style:family="paragraph" style:display-name="Name" '
|
||||||
@@ -1049,8 +1052,8 @@ def testCoreToOdt_ODTParagraphStyle():
|
|||||||
# Changes
|
# Changes
|
||||||
# =======
|
# =======
|
||||||
|
|
||||||
aStyle = ODTParagraphStyle()
|
aStyle = ODTParagraphStyle("test")
|
||||||
oStyle = ODTParagraphStyle()
|
oStyle = ODTParagraphStyle("test")
|
||||||
assert aStyle.checkNew(oStyle) is False
|
assert aStyle.checkNew(oStyle) is False
|
||||||
assert aStyle.getID() == oStyle.getID()
|
assert aStyle.getID() == oStyle.getID()
|
||||||
|
|
||||||
@@ -1059,17 +1062,17 @@ def testCoreToOdt_ODTParagraphStyle():
|
|||||||
assert aStyle.checkNew(oStyle) is True
|
assert aStyle.checkNew(oStyle) is True
|
||||||
assert aStyle.getID() != oStyle.getID()
|
assert aStyle.getID() != oStyle.getID()
|
||||||
|
|
||||||
aStyle = ODTParagraphStyle()
|
aStyle = ODTParagraphStyle("test")
|
||||||
oStyle = ODTParagraphStyle()
|
oStyle = ODTParagraphStyle("test")
|
||||||
aStyle.setMarginTop("0.000cm")
|
aStyle.setMarginTop("0.000cm")
|
||||||
oStyle.setMarginTop("1.000cm")
|
oStyle.setMarginTop("1.000cm")
|
||||||
assert aStyle.checkNew(oStyle) is True
|
assert aStyle.checkNew(oStyle) is True
|
||||||
assert aStyle.getID() != oStyle.getID()
|
assert aStyle.getID() != oStyle.getID()
|
||||||
|
|
||||||
aStyle = ODTParagraphStyle()
|
aStyle = ODTParagraphStyle("test")
|
||||||
oStyle = ODTParagraphStyle()
|
oStyle = ODTParagraphStyle("test")
|
||||||
aStyle.setColor("#000000")
|
aStyle.setColour("#000000")
|
||||||
oStyle.setColor("#111111")
|
oStyle.setColour("#111111")
|
||||||
assert aStyle.checkNew(oStyle) is True
|
assert aStyle.checkNew(oStyle) is True
|
||||||
assert aStyle.getID() != oStyle.getID()
|
assert aStyle.getID() != oStyle.getID()
|
||||||
|
|
||||||
@@ -1079,7 +1082,7 @@ def testCoreToOdt_ODTParagraphStyle():
|
|||||||
@pytest.mark.core
|
@pytest.mark.core
|
||||||
def testCoreToOdt_ODTTextStyle():
|
def testCoreToOdt_ODTTextStyle():
|
||||||
"""Test the ODTTextStyle class."""
|
"""Test the ODTTextStyle class."""
|
||||||
txtStyle = ODTTextStyle()
|
txtStyle = ODTTextStyle("test")
|
||||||
|
|
||||||
# Font Weight
|
# Font Weight
|
||||||
assert txtStyle._tAttr["font-weight"] == ["fo", None]
|
assert txtStyle._tAttr["font-weight"] == ["fo", None]
|
||||||
@@ -1109,13 +1112,13 @@ def testCoreToOdt_ODTTextStyle():
|
|||||||
|
|
||||||
# Background Color
|
# Background Color
|
||||||
assert txtStyle._tAttr["background-color"] == ["fo", None]
|
assert txtStyle._tAttr["background-color"] == ["fo", None]
|
||||||
txtStyle.setBackgroundColor("stuff")
|
txtStyle.setBackgroundColour("stuff")
|
||||||
assert txtStyle._tAttr["background-color"] == ["fo", None]
|
assert txtStyle._tAttr["background-color"] == ["fo", None]
|
||||||
txtStyle.setBackgroundColor("012345")
|
txtStyle.setBackgroundColour("012345")
|
||||||
assert txtStyle._tAttr["background-color"] == ["fo", None]
|
assert txtStyle._tAttr["background-color"] == ["fo", None]
|
||||||
txtStyle.setBackgroundColor("#012345")
|
txtStyle.setBackgroundColour("#012345")
|
||||||
assert txtStyle._tAttr["background-color"] == ["fo", "#012345"]
|
assert txtStyle._tAttr["background-color"] == ["fo", "#012345"]
|
||||||
txtStyle.setBackgroundColor("stuff")
|
txtStyle.setBackgroundColour("stuff")
|
||||||
assert txtStyle._tAttr["background-color"] == ["fo", None]
|
assert txtStyle._tAttr["background-color"] == ["fo", None]
|
||||||
|
|
||||||
# Text Position
|
# Text Position
|
||||||
@@ -1190,7 +1193,7 @@ def testCoreToOdt_ODTTextStyle():
|
|||||||
txtStyle.setStrikeStyle("solid")
|
txtStyle.setStrikeStyle("solid")
|
||||||
txtStyle.setStrikeType("single")
|
txtStyle.setStrikeType("single")
|
||||||
xStyle = ET.Element("test")
|
xStyle = ET.Element("test")
|
||||||
txtStyle.packXML(xStyle, "test")
|
txtStyle.packXML(xStyle)
|
||||||
assert xmlToText(xStyle) == (
|
assert xmlToText(xStyle) == (
|
||||||
'<test><style:style style:name="test" style:family="text"><style:text-properties '
|
'<test><style:style style:name="test" style:family="text"><style:text-properties '
|
||||||
'fo:font-weight="bold" fo:font-style="italic" style:text-position="super 58%" '
|
'fo:font-weight="bold" fo:font-style="italic" style:text-position="super 58%" '
|
||||||
|
|||||||
Reference in New Issue
Block a user