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