Commit b21f976a authored by Etienne Nadji's avatar Etienne Nadji
Browse files

Tests: Black reformat

	modifié :         test-html-stories.py
	modifié :         test-metopes.py
	modifié :         test-new.py
	modifié :         test-onix.py
	modifié :         test-tables.py
	modifié :         test-templating.py
	modifié :         test-wireframe.py
parent 0888a49e
......@@ -22,8 +22,7 @@ if __name__ == "__main__":
b = stories.sequencefromhtml(
"<em>So the <em>interview</em> did well.</em>.",
alternate_emphasis=True
alternate_emphasis=True,
)
for i in b:
......@@ -69,26 +68,20 @@ if __name__ == "__main__":
[
{"text": "A title", "style": "Title1"},
{"text": "Foreword", "style": "Foreword"},
{
"text": "First paragraph of content.",
"style": "Normal"
},
{"text": "First paragraph of content.", "style": "Normal"},
{
"text": "<em>Second</em> paragraph of content.",
"inherit_style": True
"inherit_style": True,
},
{
"text": "Third paragraph<note id='1'>A footnote text.</note>.",
"inherit_style": True
"inherit_style": True,
},
{
"text": "Fourth paragraph<span class='note' id='2'>A footnote text.</span>.",
"inherit_style": True
"inherit_style": True,
},
{
"text": "03/01/2020",
"ending": False
}
{"text": "03/01/2020", "ending": False},
]
)
......
......@@ -30,16 +30,14 @@ BOLD_ITAL_FONT = FONT + "Bold Italic"
# Classes ===============================================================#
class MetopesUE:
"""
"""
""""""
def __init__(self, filepath, fonts={"normal": "Arial"}):
self.filepath = filepath
self.parts = {
"body": None, "front": None, "back": None
}
self.parts = {"body": None, "front": None, "back": None}
self.fonts = fonts
......@@ -47,10 +45,9 @@ class MetopesUE:
self.parse()
def parse(self):
def get_contents(xml, content_section):
xp = '{http://www.tei-c.org/ns/1.0}text/'
xp += '{http://www.tei-c.org/ns/1.0}' + content_section
xp = "{http://www.tei-c.org/ns/1.0}text/"
xp += "{http://www.tei-c.org/ns/1.0}" + content_section
is_section = xml.findall(xp)
......@@ -99,18 +96,21 @@ class MetopesUE:
ET.tostring(
self.parts["body"].toxml(),
encoding="unicode",
pretty_print=True
pretty_print=True,
)
)
with open(filepath, "w", encoding="utf8") as to:
to.write(text)
# Fonctions =============================================================#
def teitag(tag):
return "{http://www.tei-c.org/ns/1.0}" + tag
def analyse_hi(xml):
global BOLD_FONT
global ITALIC_FONT
......@@ -153,12 +153,11 @@ def analyse_hi(xml):
frags += sub_hi
if xml.tail:
frags.append(
stories.StoryFragment(text=xml.tail)
)
frags.append(stories.StoryFragment(text=xml.tail))
return frags
def analyse_p(xml, notes, check_notes=True, check_hi=True, check_links=True):
p_frags = []
......@@ -206,9 +205,11 @@ def analyse_p(xml, notes, check_notes=True, check_hi=True, check_links=True):
return p_frags, notes
def analyse_quote(xml, notes):
return analyse_p(xml, notes)
def analyse_list_item(xml, notes):
li_frags = []
......@@ -259,6 +260,7 @@ def analyse_list_item(xml, notes):
return li_frags, notes
def analyse_list(xml, notes):
list_frags = []
......@@ -271,6 +273,7 @@ def analyse_list(xml, notes):
return list_frags, notes
def analyse_note(frags, xml, notes):
# Faire une marque
......@@ -282,23 +285,15 @@ def analyse_note(frags, xml, notes):
for note_para in xml:
if note_para.tag == teitag("p"):
note_para_frags,_ = analyse_p(
note_para,
notes,
check_notes=False
)
note_para_frags, _ = analyse_p(note_para, notes, check_notes=False)
note_frags += note_para_frags
notes.append(
{
"n": xml.attrib["n"],
"content": note_frags
}
)
notes.append({"n": xml.attrib["n"], "content": note_frags})
return frags, notes
def analyse_head(xml, notes, check_notes=True, check_hi=True):
head_frags = []
......@@ -331,6 +326,7 @@ def analyse_head(xml, notes, check_notes=True, check_hi=True):
return head_frags, notes
def analyse_div(xml, notes):
div_frags = []
......@@ -341,9 +337,12 @@ def analyse_div(xml, notes):
found = False
for case in [
["quote", analyse_quote], ["list", analyse_list],
["p", analyse_p], ["head", analyse_head],
["div", analyse_div]]:
["quote", analyse_quote],
["list", analyse_list],
["p", analyse_p],
["head", analyse_head],
["div", analyse_div],
]:
if element.tag == teitag(case[0]):
case_frags, notes = case[1](element, notes)
......@@ -358,6 +357,7 @@ def analyse_div(xml, notes):
return div_frags, notes
# Programme =============================================================#
if __name__ == "__main__":
......@@ -368,7 +368,7 @@ if __name__ == "__main__":
"bold": "Linux Libertine Bold",
"italic": "Linux Libertine Italic",
"bold-italic": "Linux Libertine Bold Italic",
}
},
)
ue.save("tests-outputs/metopes-story.xml")
......
......@@ -13,8 +13,6 @@ if __name__ == "__main__":
testfile = sla.SLA(version="1.5.5")
testfile.fromdefault()
testfile.save(
os.sep.join(["tests-outputs", "test-fromdefault.sla"])
)
testfile.save(os.sep.join(["tests-outputs", "test-fromdefault.sla"]))
# vim:set shiftwidth=4 softtabstop=4:
......@@ -21,7 +21,9 @@ if __name__ == "__main__":
onix = ET.parse("tests/onix_3_imprimerie.xml").getroot()
publishers = onix.findall("Product/PublishingDetail/Publisher/PublisherName")
publishers = onix.findall(
"Product/PublishingDetail/Publisher/PublisherName"
)
publishers = ", ".join([i.text for i in publishers])
isbns = []
......@@ -79,16 +81,11 @@ if __name__ == "__main__":
titles.append(
{
"text": "{}{}".format(prefix, content),
"level": level
"level": level,
}
)
else:
titles.append(
{
"text": content,
"level": level
}
)
titles.append({"text": content, "level": level})
summary, toc = False, False
record = False
......@@ -128,7 +125,9 @@ if __name__ == "__main__":
toc = text
collection = []
collections = onix.findall("Product/DescriptiveDetail/Collection/TitleDetail")
collections = onix.findall(
"Product/DescriptiveDetail/Collection/TitleDetail"
)
for coll in collections:
coll_name = False
......@@ -175,33 +174,50 @@ if __name__ == "__main__":
title_style = pstyles.ParagraphStyle(
slafile.document,
name="Title", fontsize=18, alignment="center", spaceafter=10,
name="Title",
fontsize=18,
alignment="center",
spaceafter=10,
)
title_h2 = pstyles.ParagraphStyle(
slafile.document,
name="H2", fontsize=14, spacebefore=5, spaceafter=10,
name="H2",
fontsize=14,
spacebefore=5,
spaceafter=10,
)
normal_style = pstyles.ParagraphStyle(
slafile.document,
name="Normal", fontsize=12, alignment="left",
name="Normal",
fontsize=12,
alignment="left",
)
summary_style = pstyles.ParagraphStyle(
slafile.document,
name="Summary", font="Arial Italic", fontsize=12,
name="Summary",
font="Arial Italic",
fontsize=12,
alignment="justify-left",
)
detail_style = pstyles.ParagraphStyle(
slafile.document,
name="Detail", fontsize=10,
name="Detail",
fontsize=10,
)
# We add the styles via the general SLA.append() method
for s in [title_style, title_h2, normal_style, summary_style, detail_style]:
for s in [
title_style,
title_h2,
normal_style,
summary_style,
detail_style,
]:
slafile.append(s)
# --- Text frame -------------------------------------------
......@@ -210,7 +226,8 @@ if __name__ == "__main__":
text_frame = pobjects.TextObject(
default=True,
posx=140, posy=60,
posx=140,
posy=60,
width=float(A4.WIDTH) - margins,
height=float(A4.HEIGHT) - margins,
)
......@@ -218,14 +235,14 @@ if __name__ == "__main__":
text_frame.stories[0].append_paragraphs(
[
{"style":"Title", "text": titles[0]["text"]},
{"style":"Summary", "text": summary},
{"style":"H2", "text": "Sommaire"},
{"style":"Normal", "text": toc},
{"style":"H2", "text": "Détails"},
{"style":"Detail", "text": "; ".join(collection)},
{"style":"Detail", "text": "{} €".format(price[0]["amount"])},
{"style":"Detail", "text": isbns[0]}
{"style": "Title", "text": titles[0]["text"]},
{"style": "Summary", "text": summary},
{"style": "H2", "text": "Sommaire"},
{"style": "Normal", "text": toc},
{"style": "H2", "text": "Détails"},
{"style": "Detail", "text": "; ".join(collection)},
{"style": "Detail", "text": "{} €".format(price[0]["amount"])},
{"style": "Detail", "text": isbns[0]},
]
)
......
......@@ -38,14 +38,10 @@ if __name__ == "__main__":
row_cells = last.append_row()
for case in zip(column_cells, ["D", "E", "F"]):
case[0].story.append_paragraph(
text=case[1]
)
case[0].story.append_paragraph(text=case[1])
for case in zip(row_cells, ["G", "H"]):
case[0].story.append_paragraph(
text=case[1]
)
case[0].story.append_paragraph(text=case[1])
# ---------------------------------------------------------------
......
......@@ -13,11 +13,7 @@ import pyscribus.sla as sla
if __name__ == "__main__":
# templating=True activate templating functions
template = sla.SLA(
"tests/templating.sla",
"1.5.5",
templating=True
)
template = sla.SLA("tests/templating.sla", "1.5.5", templating=True)
# The data that will be injected into the document
......@@ -26,19 +22,19 @@ if __name__ == "__main__":
"%Title%": "An editorial",
"%Lead%": "I know better than everyone of you",
"%Text%": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
"%Following%": "p. 4"
"%Following%": "p. 4",
},
{
"%Title%": "First article title",
"%Lead%": "This article is about stuff.",
"%Text%": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
"%Following%": "p. 5"
"%Following%": "p. 5",
},
{
"%Title%": "Second article title",
"%Lead%": "This is fake news.",
"%Text%": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
"%Following%": "p. 5"
"%Following%": "p. 5",
},
{"%Cell1%": "First line"},
{"%Cell2%": "Second line"},
......
......@@ -17,7 +17,7 @@ if __name__ == "__main__":
wireframe.draw(
output="tests-outputs/test_wireframe.png",
stylesheet=True,
margins=[10, 10]
margins=[10, 10],
)
# vim:set shiftwidth=4 softtabstop=4:
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment