feat: parse questions von @dl9mj

This commit is contained in:
Tim Grelka
2025-02-16 21:44:45 +01:00
parent 04a20e6121
commit 9ea98a941d
5 changed files with 87 additions and 6 deletions
+9 -4
View File
@@ -1,12 +1,17 @@
import mistletoe
from mistletoe import Document
from renderer.fifty_ohm_html_renderer import FiftyOhmHtmlRenderer
def question_stub(input):
return f"<question>{input}</question>" # TODO implement this stub
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)
with FiftyOhmHtmlRenderer(question_stub) as renderer:
output = renderer.render(Document(content))
with open("test/acceptanceTest.html", "w") as output_file:
output_file.write(output)
+40
View File
@@ -0,0 +1,40 @@
import pytest
from mistletoe import Document
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_comment_html():
assertions = {
"[question:123]": "123\n",
"\n[question:123]\n": "123\n",
"\n[question:123]\n[question:123]": "123\n123\n",
"Foo\n[question:123]\nBar": paragraph("Foo") + "123\n" + paragraph("Bar"),
}
def test_function(input):
return f"{input}"
with FiftyOhmHtmlRenderer(test_function) as renderer:
for assertion in assertions:
assert renderer.render(Document(assertion)) == assertions[assertion]
@pytest.mark.latex
def test_comment_latex():
assertions = {
"[question:123]": "123",
"\n[question:123]\n": "123",
"\n[question:123]\n[question:123]": "123123",
"Foo\n[question:123]\nBar": "\nFoo\n123\nBar\n",
}
def test_function(input):
return f"{input}"
with FiftyOhmLaTeXRenderer(test_function) as renderer:
for assertion in assertions:
assert renderer.render(Document(assertion)) == assertions[assertion]