Pull request #21: Feature/tooling improvements

Merge in FRAG/50ohm.de from feature/tooling-improvements to main

* commit 'c09c58a2764842ed57d06cc7832022e73fda8f63':
  ci: disable pytest importlib mode
  ci: run pytest command in parent directory
  fix: correct import paths
  test: mark test cases
  test: add latex test tag
  refactor: use paragraph test helper
  style: reformat code with ruff
  tooling: increase maximum line length
  tooling: auto-import libraries on use
  tooling: improve pytest setting
This commit is contained in:
Tim Grelka DA2TG
2024-12-11 00:24:19 +00:00
23 changed files with 202 additions and 155 deletions
+1 -1
View File
@@ -8,4 +8,4 @@ steps:
environment:
commands:
- uv pip install --system --break-system-packages --requirements requirements.txt
- cd test && pytest --junitxml=./test-reports/junit.xml
- pytest --junitxml=./test-reports/junit.xml
+2 -1
View File
@@ -10,5 +10,6 @@
"source.fixAll.ruff": "explicit",
"source.organizeImports.ruff": "explicit"
}
}
},
"python.analysis.autoImportCompletions": true
}
+5 -1
View File
@@ -7,7 +7,7 @@ requires-python = ">=3.12"
dependencies = []
[tool.ruff]
line-length = 88
line-length = 120
indent-width = 4
[tool.ruff.lint]
@@ -39,3 +39,7 @@ select = [
# ruff-specific: No unused noqa directives
"RUF100",
]
[tool.pytest.ini_options]
addopts = ["--color=yes"]
markers = ["html", "latex"]
+4 -2
View File
@@ -9,7 +9,9 @@ class SpanComment(SpanToken):
Coment span token (% Eiersalat).
Identifies a comment in text.
"""
pattern = re.compile(r'(%.*\n?)')
pattern = re.compile(r"(%.*\n?)")
class BlockComment(BlockToken):
@staticmethod
@@ -19,4 +21,4 @@ class BlockComment(BlockToken):
@classmethod
def read(cls, lines):
next(lines)
return None
return None
+2 -1
View File
@@ -8,4 +8,5 @@ class Dash(SpanToken):
Dash span token ( - ).
Identifies a dash in a text.
"""
pattern = re.compile(r'(\s-\s)')
pattern = re.compile(r"(\s-\s)")
+11 -13
View File
@@ -2,16 +2,16 @@ import textwrap
from mistletoe import HtmlRenderer
from renderer.comment import BlockComment, SpanComment
from renderer.dash import Dash
from renderer.halfwidth_spaces import HalfwidthSpaces
from renderer.morse import Morse
from renderer.nonbreaking_spaces import NonbreakingSpaces, NonbreakingSpacesDots
from renderer.quote import Quote
from renderer.references import References
from renderer.tag import Tag
from renderer.underline import Underline
from renderer.unit import Unit
from .comment import BlockComment, SpanComment
from .dash import Dash
from .halfwidth_spaces import HalfwidthSpaces
from .morse import Morse
from .nonbreaking_spaces import NonbreakingSpaces, NonbreakingSpacesDots
from .quote import Quote
from .references import References
from .tag import Tag
from .underline import Underline
from .unit import Unit
class FiftyOhmHtmlRenderer(HtmlRenderer):
@@ -146,9 +146,7 @@ class FiftyOhmHtmlRenderer(HtmlRenderer):
else:
type = token.tagtype
return self.render_tag_helper(
type, self.render_inner(token), self.margin_id, self.margin_anchor_id
)
return self.render_tag_helper(type, self.render_inner(token), self.margin_id, self.margin_anchor_id)
def render_halfwidth_spaces(self, token):
return f"{token.first}. {token.second}."
+16 -21
View File
@@ -1,16 +1,15 @@
from mistletoe.latex_renderer import LaTeXRenderer
from renderer.comment import BlockComment, SpanComment
from renderer.dash import Dash
from renderer.halfwidth_spaces import HalfwidthSpaces
from renderer.nonbreaking_spaces import NonbreakingSpaces, NonbreakingSpacesDots
from renderer.quote import Quote
from renderer.tag import Tag
from renderer.underline import Underline
from .comment import BlockComment, SpanComment
from .dash import Dash
from .halfwidth_spaces import HalfwidthSpaces
from .nonbreaking_spaces import NonbreakingSpaces, NonbreakingSpacesDots
from .quote import Quote
from .tag import Tag
from .underline import Underline
class FiftyOhmLaTeXRenderer(LaTeXRenderer):
def __init__(self):
super().__init__(
Dash,
@@ -23,7 +22,7 @@ class FiftyOhmLaTeXRenderer(LaTeXRenderer):
NonbreakingSpaces,
NonbreakingSpacesDots,
)
def render_document(self, token):
self.footnotes.update(token.footnotes)
return self.render_inner(token)
@@ -32,25 +31,24 @@ class FiftyOhmLaTeXRenderer(LaTeXRenderer):
return " -- "
def render_block_comment(self, token):
return "" # TODO propagate comments to the LaTeX document
return "" # TODO propagate comments to the LaTeX document
def render_span_comment(self, token):
return "" # TODO propagate comments to the LaTeX document
return "" # TODO propagate comments to the LaTeX document
def render_quote(self, token):
return fr"\enquote{{{self.render_inner(token)}}}"
return rf"\enquote{{{self.render_inner(token)}}}"
def render_emphasis(self, token):
return fr"\emph{{{self.render_inner(token)}}}"
return rf"\emph{{{self.render_inner(token)}}}"
def render_underline(self, token):
return fr"\underline{{{self.render_inner(token)}}}"
return rf"\underline{{{self.render_inner(token)}}}"
def render_thematic_break(self, token):
return ""
def render_tag(self, token): # noqa: C901
tagtype = None
match token.tagtype:
@@ -81,7 +79,7 @@ class FiftyOhmLaTeXRenderer(LaTeXRenderer):
case _:
tagtype = "Margin"
return fr"\{tagtype}{{{self.render_inner(token)}}}"
return rf"\{tagtype}{{{self.render_inner(token)}}}"
def render_halfwidth_spaces(self, token):
return f"{token.first}.\,{token.second}."
@@ -90,8 +88,5 @@ class FiftyOhmLaTeXRenderer(LaTeXRenderer):
return f"{token.first}~{token.second}"
def render_nonbreaking_spaces_dots(self, token):
lookup = {
"" : "",
" " : "~"
}
return f"{lookup[token.first]}{token.second}{lookup[token.third]}"
lookup = {"": "", " ": "~"}
return f"{lookup[token.first]}{token.second}{lookup[token.third]}"
+1 -3
View File
@@ -8,11 +8,9 @@ class HalfwidthSpaces(SpanToken):
Insert halfwidth space into span token (Z. B.)
Identifies "z.B.", "d.h." and "D.h." with and without space in between.
"""
pattern = re.compile(r"\b(z|Z|d|D)\.\s?(B|h)\.")
def __init__(self, match_object):
self.first = match_object.group(1)
self.second = match_object.group(2)
+6 -5
View File
@@ -8,8 +8,9 @@ class Morse(SpanToken):
Morse code span token ("[morse:moe]").
Generates morse code from a text.
"""
@staticmethod
def convert_to_morse_code(text):
def convert_to_morse_code(text):
dit = 1
dah = 2
space = 3
@@ -74,16 +75,16 @@ class Morse(SpanToken):
"bk": [dah, dit, dit, dit, dah, dit, dah],
"sk": [dit, dit, dit, dah, dit, dah],
"correction": [dit, dit, dit, dit, dit, dit, dit, dit],
" ": [space]
" ": [space],
}
result = []
for char in text:
if char.lower() in morse_code:
result.append(morse_code[char.lower()])
return result
parse_inner = False
pattern = re.compile(r'"\[morse:\s*(.+)\]"')
pattern = re.compile(r'"\[morse:\s*(.+)\]"')
+3 -3
View File
@@ -8,23 +8,23 @@ class NonbreakingSpaces(SpanToken):
Insert unbreakable space into span token (§ 3)
Identifies "§$number", "Abs.$number", "Klasse [A,E,N]" w/ and without space between.
"""
pattern = re.compile(r"(§|Abs\.|Klasse)\s?(\d|[NEA])")
def __init__(self, match_object):
self.first = match_object.group(1)
self.second = match_object.group(2)
class NonbreakingSpacesDots(SpanToken):
"""
Insert unbreakable space before and after "..." if there is a space
Identifies "..." with leading and/or trailing space
"""
pattern = re.compile(r"(\s?)(\.\.\.)(\s?)")
def __init__(self, match_object):
self.first = match_object.group(1)
self.second = match_object.group(2)
self.third = match_object.group(3)
+1
View File
@@ -8,4 +8,5 @@ class Quote(SpanToken):
Quote span token ("Eiersalat").
Identifies quoted text.
"""
pattern = re.compile(r'"([^"]+)"')
+1 -1
View File
@@ -8,8 +8,8 @@ class References(SpanToken):
Resolve references for html
Identifies "[ref:$]"
"""
pattern = re.compile(r"\[ref\:(\S+)\]")
def __init__(self, match_object):
self.first = match_object.group(1)
+2 -1
View File
@@ -8,4 +8,5 @@ class Underline(SpanToken):
Underline span token (<u>Untersrich</u>).
Identifies underlined text.
"""
pattern = re.compile(r'<u>(.+)</u>')
pattern = re.compile(r"<u>(.+)</u>")
+13 -10
View File
@@ -1,28 +1,31 @@
import mistletoe
import pytest
from renderer.fifty_ohm_html_renderer import FiftyOhmHtmlRenderer
from renderer.fifty_ohm_latex_renderer import FiftyOhmLaTeXRenderer
from test.util import paragraph
def test_comment_html() :
@pytest.mark.html
def test_comment_html():
assertions = {
"%Comment\nBar" : "<p>Bar</p>\n",
"%Comment\nBar": "Bar",
# TODO: This test is not working as expected. The comment should be removed
#"%Comment\n" : "a",
"Foo\n%Comment\nBar" : "<p>Foo\nBar</p>\n",
# "%Comment\n" : "a",
"Foo\n%Comment\nBar": "Foo\nBar",
}
for assertion in assertions:
assert mistletoe.markdown(assertion, FiftyOhmHtmlRenderer) == assertions[assertion]
assert mistletoe.markdown(assertion, FiftyOhmHtmlRenderer) == paragraph(assertions[assertion])
def test_comment_latex() :
@pytest.mark.latex
def test_comment_latex():
assertions = {
"%Comment\nBar" : "\nBar\n",
"%Comment\nBar": "\nBar\n",
# TODO: This test is not working as expected. The comment should be removed
#"%Comment\n" : "a",
"Foo\n%Comment\nBar" : "\nFoo\nBar\n",
# "%Comment\n" : "a",
"Foo\n%Comment\nBar": "\nFoo\nBar\n",
}
for assertion in assertions:
+7 -5
View File
@@ -1,23 +1,25 @@
import mistletoe
import pytest
from renderer.fifty_ohm_html_renderer import FiftyOhmHtmlRenderer
from renderer.fifty_ohm_latex_renderer import FiftyOhmLaTeXRenderer
from test.util import paragraph
def test_dash_html() :
@pytest.mark.html
def test_dash_html():
assertions = {
"Foo - Bar" : "Foo &ndash; Bar",
"Foo - Bar": "Foo &ndash; Bar",
}
for assertion in assertions:
assert mistletoe.markdown(assertion, FiftyOhmHtmlRenderer) == paragraph(assertions[assertion])
def test_dash_latex() :
@pytest.mark.latex
def test_dash_latex():
assertions = {
"Foo - Bar" : "\nFoo -- Bar\n",
"Foo - Bar": "\nFoo -- Bar\n",
}
for assertion in assertions:
+3
View File
@@ -1,10 +1,12 @@
import mistletoe
import pytest
from renderer.fifty_ohm_html_renderer import FiftyOhmHtmlRenderer
from renderer.fifty_ohm_latex_renderer import FiftyOhmLaTeXRenderer
from test.util import paragraph
@pytest.mark.html
def test_halfwidth_space_html():
input = "Dies ist z.B. ein Test. D.h. hier sollten d.h. Spaces ersetzt worden sein."
target = "Dies ist z.&#8239;B. ein Test. D.&#8239;h. hier sollten d.&#8239;h. Spaces ersetzt worden sein."
@@ -12,6 +14,7 @@ def test_halfwidth_space_html():
assert mistletoe.markdown(input, FiftyOhmHtmlRenderer) == paragraph(target)
@pytest.mark.latex
def test_halfwidth_space_latex():
input = "Dies ist z.B. ein Test. D.h. hier sollten d.h. Spaces ersetzt worden sein."
target = "\nDies ist z.\,B. ein Test. D.\,h. hier sollten d.\,h. Spaces ersetzt worden sein.\n"
+2 -4
View File
@@ -1,14 +1,12 @@
import mistletoe
from renderer.fifty_ohm_html_renderer import FiftyOhmHtmlRenderer
def test_html(capsys) :
def test_html(capsys):
with capsys.disabled():
with open("test/acceptanceTest.md") as file:
content = file.read()
output = mistletoe.markdown(content, FiftyOhmHtmlRenderer)
with open("test/acceptanceTest.html", "w") as output_file:
output_file.write(output)
output_file.write(output)
+10 -8
View File
@@ -1,17 +1,19 @@
import mistletoe
import pytest
from renderer.fifty_ohm_html_renderer import FiftyOhmHtmlRenderer
from test.util import paragraph
def test_morse_html() :
@pytest.mark.html
def test_morse_html():
assertions = {
'"[morse:a]"' : "<p>"+FiftyOhmHtmlRenderer.render_morse_helper([[1,2]])+"</p>\n",
'"[morse: a]"' : "<p>"+FiftyOhmHtmlRenderer.render_morse_helper([[1,2]])+"</p>\n",
'"[morse: aaa]"' : "<p>"+FiftyOhmHtmlRenderer.render_morse_helper([[1,2],[1,2],[1,2]])+"</p>\n",
'"[morse: a a]"' : "<p>"+FiftyOhmHtmlRenderer.render_morse_helper([[1,2],[3],[1,2]])+"</p>\n",
'"[morse: db0]"' : "<p>"+FiftyOhmHtmlRenderer.render_morse_helper([[2,1,1],[2,1,1,1],[2,2,2,2,2]])+"</p>\n",
'"[morse:a]"': FiftyOhmHtmlRenderer.render_morse_helper([[1, 2]]),
'"[morse: a]"': FiftyOhmHtmlRenderer.render_morse_helper([[1, 2]]),
'"[morse: aaa]"': FiftyOhmHtmlRenderer.render_morse_helper([[1, 2], [1, 2], [1, 2]]),
'"[morse: a a]"': FiftyOhmHtmlRenderer.render_morse_helper([[1, 2], [3], [1, 2]]),
'"[morse: db0]"': FiftyOhmHtmlRenderer.render_morse_helper([[2, 1, 1], [2, 1, 1, 1], [2, 2, 2, 2, 2]]),
}
for assertion in assertions:
assert mistletoe.markdown(assertion, FiftyOhmHtmlRenderer) == assertions[assertion]
assert mistletoe.markdown(assertion, FiftyOhmHtmlRenderer) == paragraph(assertions[assertion])
+23 -10
View File
@@ -1,67 +1,80 @@
import mistletoe
import pytest
from renderer.fifty_ohm_html_renderer import FiftyOhmHtmlRenderer
from renderer.fifty_ohm_latex_renderer import FiftyOhmLaTeXRenderer
from test.util import paragraph
@pytest.mark.html
def test_paragraph_html():
input = "Der Test befindet sich unter §2 vielleicht aber auch § 3."
target = "Der Test befindet sich unter §&#160;2 vielleicht aber auch §&#160;3."
assert mistletoe.markdown(input, FiftyOhmHtmlRenderer) == paragraph(target)
@pytest.mark.html
def test_three_points_html():
assertions = {
"Heute hatte ich ... zum Mittagessen." : "Heute hatte ich&#160;...&#160;zum Mittagessen.",
"Niemals hätte ich gedacht, dass...ich ...nicht kann." : "Niemals hätte ich gedacht, dass...ich&#160;...nicht kann.",
"Oh nein ...ein Pinguin." : "Oh nein&#160;...ein Pinguin.",
"Haha .. . Hahaha" : "Haha .. . Hahaha"
"Heute hatte ich ... zum Mittagessen.": "Heute hatte ich&#160;...&#160;zum Mittagessen.",
"Niemals hätte ich gedacht, dass...ich ...nicht kann.": "Niemals hätte ich gedacht, dass...ich&#160;...nicht kann.",
"Oh nein ...ein Pinguin.": "Oh nein&#160;...ein Pinguin.",
"Haha .. . Hahaha": "Haha .. . Hahaha",
}
for key, value in assertions.items():
assert mistletoe.markdown(key, FiftyOhmHtmlRenderer) == paragraph(value)
@pytest.mark.html
def test_absatz_html():
input = "Der Test befindet sich unter Abs.2 vielleicht aber auch Abs. 3."
target = "Der Test befindet sich unter Abs.&#160;2 vielleicht aber auch Abs.&#160;3."
assert mistletoe.markdown(input, FiftyOhmHtmlRenderer) == paragraph(target)
@pytest.mark.html
def test_class_html():
input = "Ich lerne für Klasse A, Klasse E und Klasse N."
target = "Ich lerne für Klasse&#160;A, Klasse&#160;E und Klasse&#160;N."
assert mistletoe.markdown(input, FiftyOhmHtmlRenderer) == paragraph(target)
@pytest.mark.latex
def test_paragraph_latex():
input = "Der Test befindet sich unter §2 vielleicht aber auch § 3."
target = "\nDer Test befindet sich unter §~2 vielleicht aber auch §~3.\n"
assert mistletoe.markdown(input, FiftyOhmLaTeXRenderer) == target
@pytest.mark.latex
def test_three_points_latex():
assertions = {
"Heute hatte ich ... zum Mittagessen." : "\nHeute hatte ich~...~zum Mittagessen.\n",
"Niemals hätte ich gedacht, dass...ich ...nicht kann." : "\nNiemals hätte ich gedacht, dass...ich~...nicht kann.\n",
"Oh nein ...ein Pinguin." : "\nOh nein~...ein Pinguin.\n",
"Haha .. . Hahaha" : "\nHaha .. . Hahaha\n"
"Heute hatte ich ... zum Mittagessen.": "\nHeute hatte ich~...~zum Mittagessen.\n",
"Niemals hätte ich gedacht, dass...ich ...nicht kann.": "\nNiemals hätte ich gedacht, dass...ich~...nicht kann.\n",
"Oh nein ...ein Pinguin.": "\nOh nein~...ein Pinguin.\n",
"Haha .. . Hahaha": "\nHaha .. . Hahaha\n",
}
for key, value in assertions.items():
assert mistletoe.markdown(key, FiftyOhmLaTeXRenderer) == value
@pytest.mark.latex
def test_absatz_latex():
input = "Der Test befindet sich unter Abs.2 vielleicht aber auch Abs. 3."
target = "\nDer Test befindet sich unter Abs.~2 vielleicht aber auch Abs.~3.\n"
assert mistletoe.markdown(input, FiftyOhmLaTeXRenderer) == target
@pytest.mark.latex
def test_class_latex():
input = "Ich lerne für Klasse A, Klasse E und Klasse N."
target = "\nIch lerne für Klasse~A, Klasse~E und Klasse~N.\n"
assert mistletoe.markdown(input, FiftyOhmLaTeXRenderer) == target
+17 -15
View File
@@ -1,33 +1,35 @@
import mistletoe
import pytest
from renderer.fifty_ohm_html_renderer import FiftyOhmHtmlRenderer
from renderer.fifty_ohm_latex_renderer import FiftyOhmLaTeXRenderer
from test.util import paragraph
def test_quote_html() :
@pytest.mark.html
def test_quote_html():
assertions = {
'"quote"' : '„quote“',
'" quote "' : '„ quote “',
'"quote" "' : '„quote“ "',
'"quo te1" filltext "qu ot e2"' : '„quo te1“ filltext „qu ot e2“',
'"quo *te1*" filltext "qu ot e2"' : '„quo <em>te1</em>“ filltext „qu ot e2“',
'""' : '""',
'"quote"': "„quote“",
'" quote "': "„ quote “",
'"quote" "': '„quote“ "',
'"quo te1" filltext "qu ot e2"': "„quo te1“ filltext „qu ot e2“",
'"quo *te1*" filltext "qu ot e2"': "„quo <em>te1</em>“ filltext „qu ot e2“",
'""': '""',
}
for assertion in assertions:
assert mistletoe.markdown(assertion, FiftyOhmHtmlRenderer) == paragraph(assertions[assertion])
def test_quote_latex() :
@pytest.mark.latex
def test_quote_latex():
assertions = {
'"quote"' : '\n\enquote{quote}\n',
'" quote "' : '\n\enquote{ quote }\n',
'"quote" "' : '\n\enquote{quote} "\n',
'"quo te1" filltext "qu ot e2"' : '\n\enquote{quo te1} filltext \enquote{qu ot e2}\n',
'"quo *te1*" filltext "qu ot e2"' : '\n\enquote{quo \emph{te1}} filltext \enquote{qu ot e2}\n',
'""' : '\n""\n',
'"quote"': "\n\enquote{quote}\n",
'" quote "': "\n\enquote{ quote }\n",
'"quote" "': '\n\enquote{quote} "\n',
'"quo te1" filltext "qu ot e2"': "\n\enquote{quo te1} filltext \enquote{qu ot e2}\n",
'"quo *te1*" filltext "qu ot e2"': "\n\enquote{quo \emph{te1}} filltext \enquote{qu ot e2}\n",
'""': '\n""\n',
}
for assertion in assertions:
+2
View File
@@ -1,9 +1,11 @@
import mistletoe
import pytest
from renderer.fifty_ohm_html_renderer import FiftyOhmHtmlRenderer
from test.util import paragraph
@pytest.mark.html
def test_references_html():
# Right now this tests only the default values.
# The correct behavior can be tested when the information is added to the renderer class
+59 -41
View File
@@ -1,85 +1,103 @@
import mistletoe
import pytest
from renderer.fifty_ohm_html_renderer import FiftyOhmHtmlRenderer
from renderer.fifty_ohm_latex_renderer import FiftyOhmLaTeXRenderer
def test_thematic_break_html() :
@pytest.mark.html
def test_thematic_break_html():
assertions = {
"---" : '<a id="margin_1"></a>\n',
"---\n---" : '<a id="margin_1"></a>\n<a id="margin_2"></a>\n',
"---": '<a id="margin_1"></a>\n',
"---\n---": '<a id="margin_1"></a>\n<a id="margin_2"></a>\n',
}
for assertion in assertions:
assert mistletoe.markdown(assertion, FiftyOhmHtmlRenderer) == assertions[assertion]
def test_tag_html() :
@pytest.mark.html
def test_tag_html():
assertions = {
"<margin>\nFoo\n</margin>" : FiftyOhmHtmlRenderer.render_tag_helper("margin","<p>Foo</p>",1,0)+'\n',
"<indepth>\nFoo\n</indepth>" : FiftyOhmHtmlRenderer.render_tag_helper("indepth","<p>Foo</p>",1,0)+'\n',
"<webmargin>\nFoo\n</webmargin>" : FiftyOhmHtmlRenderer.render_tag_helper("margin","<p>Foo</p>",1,0)+'\n',
"<tip>\nFoo\n</tip>" : FiftyOhmHtmlRenderer.render_tag_helper("tip","<p>Foo</p>",1,0)+'\n',
"<webtip>\nFoo\n</webtip>" : FiftyOhmHtmlRenderer.render_tag_helper("tip","<p>Foo</p>",1,0)+'\n',
"<webindepth>\nFoo\n</webindepth>" : FiftyOhmHtmlRenderer.render_tag_helper("indepth","<p>Foo</p>",1,0)+'\n',
"<unit>\nFoo\n</unit>" : FiftyOhmHtmlRenderer.render_tag_helper("unit","<p>Foo</p>",1,0)+'\n',
"<danger>\nFoo\n</danger>" : FiftyOhmHtmlRenderer.render_tag_helper("danger","<p>Foo</p>",1,0)+'\n',
"<webonly>\nFoo\n</webonly>" : '<p>Foo</p>\n',
"<latexonly>\nFoo\n</latexonly>" : "",
"<margin>\nFoo\n</margin>": FiftyOhmHtmlRenderer.render_tag_helper("margin", "<p>Foo</p>", 1, 0) + "\n",
"<indepth>\nFoo\n</indepth>": FiftyOhmHtmlRenderer.render_tag_helper("indepth", "<p>Foo</p>", 1, 0) + "\n",
"<webmargin>\nFoo\n</webmargin>": FiftyOhmHtmlRenderer.render_tag_helper("margin", "<p>Foo</p>", 1, 0) + "\n",
"<tip>\nFoo\n</tip>": FiftyOhmHtmlRenderer.render_tag_helper("tip", "<p>Foo</p>", 1, 0) + "\n",
"<webtip>\nFoo\n</webtip>": FiftyOhmHtmlRenderer.render_tag_helper("tip", "<p>Foo</p>", 1, 0) + "\n",
"<webindepth>\nFoo\n</webindepth>": FiftyOhmHtmlRenderer.render_tag_helper("indepth", "<p>Foo</p>", 1, 0)
+ "\n",
"<unit>\nFoo\n</unit>": FiftyOhmHtmlRenderer.render_tag_helper("unit", "<p>Foo</p>", 1, 0) + "\n",
"<danger>\nFoo\n</danger>": FiftyOhmHtmlRenderer.render_tag_helper("danger", "<p>Foo</p>", 1, 0) + "\n",
"<webonly>\nFoo\n</webonly>": "<p>Foo</p>\n",
"<latexonly>\nFoo\n</latexonly>": "",
}
for assertion in assertions:
assert mistletoe.markdown(assertion, FiftyOhmHtmlRenderer) == assertions[assertion]
def test_thematic_break_and_tag_html() :
@pytest.mark.html
def test_thematic_break_and_tag_html():
assertions = {
"---\n<margin>\nFoo\n</margin>" : '<a id="margin_1"></a>\n'+FiftyOhmHtmlRenderer.render_tag_helper("margin","<p>Foo</p>",1,1)+'\n',
"---\n<margin>\nFoo\n</margin>\n<margin>\nFoo\n</margin>" : '<a id="margin_1"></a>\n'+FiftyOhmHtmlRenderer.render_tag_helper("margin","<p>Foo</p>",1,1)+'\n'+FiftyOhmHtmlRenderer.render_tag_helper("margin","<p>Foo</p>",2,1)+'\n',
"---\n<margin>\nFoo\n</margin>\n---\n<margin>\nFoo\n</margin>" : '<a id="margin_1"></a>\n'+FiftyOhmHtmlRenderer.render_tag_helper("margin","<p>Foo</p>",1,1)+'\n<a id="margin_2"></a>\n'+FiftyOhmHtmlRenderer.render_tag_helper("margin","<p>Foo</p>",2,2)+'\n',
"---\n<margin>\nFoo\n</margin>": '<a id="margin_1"></a>\n'
+ FiftyOhmHtmlRenderer.render_tag_helper("margin", "<p>Foo</p>", 1, 1)
+ "\n",
"---\n<margin>\nFoo\n</margin>\n<margin>\nFoo\n</margin>": '<a id="margin_1"></a>\n'
+ FiftyOhmHtmlRenderer.render_tag_helper("margin", "<p>Foo</p>", 1, 1)
+ "\n"
+ FiftyOhmHtmlRenderer.render_tag_helper("margin", "<p>Foo</p>", 2, 1)
+ "\n",
"---\n<margin>\nFoo\n</margin>\n---\n<margin>\nFoo\n</margin>": '<a id="margin_1"></a>\n'
+ FiftyOhmHtmlRenderer.render_tag_helper("margin", "<p>Foo</p>", 1, 1)
+ '\n<a id="margin_2"></a>\n'
+ FiftyOhmHtmlRenderer.render_tag_helper("margin", "<p>Foo</p>", 2, 2)
+ "\n",
}
for assertion in assertions:
assert mistletoe.markdown(assertion, FiftyOhmHtmlRenderer) == assertions[assertion]
def test_thematic_break_latex() :
@pytest.mark.latex
def test_thematic_break_latex():
assertions = {
"---" : '',
"---\n---" : '',
"---": "",
"---\n---": "",
}
for assertion in assertions:
assert mistletoe.markdown(assertion, FiftyOhmLaTeXRenderer) == assertions[assertion]
def test_tag_latex() :
@pytest.mark.latex
def test_tag_latex():
assertions = {
"<margin>\nFoo\n</margin>" : "\Margin{\nFoo\n}",
"<danger>\nFoo\n</danger>" : "\MarginDanger{\nFoo\n}",
"<warning>\nFoo\n</warning>" : "\MarginWarning{\nFoo\n}",
"<attention>\nFoo\n</attention>" : "\MarginAttention{\nFoo\n}",
"<tip>\nFoo\n</tip>" : "\MarginTip{\nFoo\n}",
"<webtip>\nFoo\n</webtip>" : "\WebTip{\nFoo\n}",
"<unit>\nFoo\n</unit>" : "\MarginUnit{\nFoo\n}",
"<indepth>\nFoo\n</indepth>" : "\MarginInDepth{\nFoo\n}",
"<webindepth>\nFoo\n</webindepth>" : "\MarginWebInDepth{\nFoo\n}",
"<webmargin>\nFoo\n</webmargin>" : "\WebMargin{\nFoo\n}",
"<fullwidth>\nFoo\n</fullwidth>" : "\FullWidth{\nFoo\n}",
"<latexonly>\nFoo\n</latexonly>" : "\nFoo\n",
"<webonly>\nFoo\n</webonly>" : "",
"<margin>\nFoo\n</margin>": "\Margin{\nFoo\n}",
"<danger>\nFoo\n</danger>": "\MarginDanger{\nFoo\n}",
"<warning>\nFoo\n</warning>": "\MarginWarning{\nFoo\n}",
"<attention>\nFoo\n</attention>": "\MarginAttention{\nFoo\n}",
"<tip>\nFoo\n</tip>": "\MarginTip{\nFoo\n}",
"<webtip>\nFoo\n</webtip>": "\WebTip{\nFoo\n}",
"<unit>\nFoo\n</unit>": "\MarginUnit{\nFoo\n}",
"<indepth>\nFoo\n</indepth>": "\MarginInDepth{\nFoo\n}",
"<webindepth>\nFoo\n</webindepth>": "\MarginWebInDepth{\nFoo\n}",
"<webmargin>\nFoo\n</webmargin>": "\WebMargin{\nFoo\n}",
"<fullwidth>\nFoo\n</fullwidth>": "\FullWidth{\nFoo\n}",
"<latexonly>\nFoo\n</latexonly>": "\nFoo\n",
"<webonly>\nFoo\n</webonly>": "",
}
for assertion in assertions:
assert mistletoe.markdown(assertion, FiftyOhmLaTeXRenderer) == assertions[assertion]
def test_thematic_break_and_tag_latex() :
@pytest.mark.latex
def test_thematic_break_and_tag_latex():
assertions = {
"---\n<margin>\nFoo\n</margin>" : "\Margin{\nFoo\n}",
"---\n<margin>\nFoo\n</margin>\n<margin>\nFoo\n</margin>" : "\Margin{\nFoo\n}\Margin{\nFoo\n}",
"---\n<margin>\nFoo\n</margin>\n---\n<margin>\nFoo\n</margin>" : "\Margin{\nFoo\n}\Margin{\nFoo\n}",
"---\n<margin>\nFoo\n</margin>": "\Margin{\nFoo\n}",
"---\n<margin>\nFoo\n</margin>\n<margin>\nFoo\n</margin>": "\Margin{\nFoo\n}\Margin{\nFoo\n}",
"---\n<margin>\nFoo\n</margin>\n---\n<margin>\nFoo\n</margin>": "\Margin{\nFoo\n}\Margin{\nFoo\n}",
}
for assertion in assertions:
assert mistletoe.markdown(assertion, FiftyOhmLaTeXRenderer) == assertions[assertion]
assert mistletoe.markdown(assertion, FiftyOhmLaTeXRenderer) == assertions[assertion]
+11 -9
View File
@@ -1,27 +1,29 @@
import mistletoe
import pytest
from renderer.fifty_ohm_html_renderer import FiftyOhmHtmlRenderer
from renderer.fifty_ohm_latex_renderer import FiftyOhmLaTeXRenderer
from test.util import paragraph
def test_underline_html() :
@pytest.mark.html
def test_underline_html():
assertions = {
"<u>Text</u>" : "<u>Text</u>",
"<u> Text Text </u>" : "<u> Text Text </u>",
"<u> Text *Text* </u>" : "<u> Text <em>Text</em> </u>",
"<u>Text</u>": "<u>Text</u>",
"<u> Text Text </u>": "<u> Text Text </u>",
"<u> Text *Text* </u>": "<u> Text <em>Text</em> </u>",
}
for assertion in assertions:
assert mistletoe.markdown(assertion, FiftyOhmHtmlRenderer) == paragraph(assertions[assertion])
def test_underline_latex() :
@pytest.mark.latex
def test_underline_latex():
assertions = {
"<u>Text</u>" : "\n\\underline{Text}\n",
"<u> Text Text </u>" : "\n\\underline{ Text Text }\n",
"<u> Text *Text* </u>" : "\n\\underline{ Text \emph{Text} }\n",
"<u>Text</u>": "\n\\underline{Text}\n",
"<u> Text Text </u>": "\n\\underline{ Text Text }\n",
"<u> Text *Text* </u>": "\n\\underline{ Text \emph{Text} }\n",
}
for assertion in assertions: