Skip to content

Commit 07cf930

Browse files
committed
Fixed a bunch of tests
1 parent a90d2da commit 07cf930

File tree

3 files changed

+24
-25
lines changed

3 files changed

+24
-25
lines changed

core/builder/convertor.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ def __init__(self, output_format: str, locale_code: str, infile, outfile, **opti
115115
self.math = options.get('math', 'mathjax')
116116
self.file = None
117117

118-
assert output_format in ['html', 'latex'], "Output format is neither 'html' nor 'latex'!"
118+
assert output_format in ['html', 'latex'], \
119+
"Output format is neither 'html' nor 'latex'!"
119120

120121
# regexes = yaml.safe_load(open('core/builder/regexes.yaml', 'rb'))
121122

core/tests/test_convertor.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ class TestImages:
6262
def test_image_latex(self, convert):
6363
output = convert('latex', 'sk', '![Masívna ryba](ryba.svg){#fig:ryba height=47mm}')
6464
output = output.replace('\n', ' ')
65-
assert re.search(r'\\insertPicture\[width=\\textwidth,height=47mm]{.*}', output) is not None
65+
assert re.search(r'\\insertPicture\[width=\\textwidth,height=47mm]{.*}', output) is not None, \
66+
f"Got '{output}'"
6667
assert 'ryba.pdf' in output
6768

6869
def test_image_latex_multiline(self, convert):
@@ -72,7 +73,8 @@ def test_image_latex_multiline(self, convert):
7273
Aj s newlinami.](file.png){#fig:long height=53mm}
7374
""")
7475
output = output.replace('\n', ' ')
75-
assert re.search(r'\\insertPicture\[width=\\textwidth,height=53mm]{.*}', output) is not None
76+
assert re.search(r'\\insertPicture\[width=\\textwidth,height=53mm]{.*}', output) is not None, \
77+
f"Got '{output}'"
7678
assert 'file.png' in output
7779

7880
def test_image_html(self, convert):
@@ -97,23 +99,27 @@ def test_image_html_multiline(self, convert):
9799
class TestTags:
98100
def test_h_latex(self, convert):
99101
output = convert('latex', 'en', '@H this should not be seen!')
100-
assert output == '\n'
102+
assert output == '', \
103+
f"Got '{output}'"
101104

102105
def test_h_html(self, convert):
103106
output = convert('html', 'en', '@H this should not be seen!')
104-
assert output == '<p>this should not be seen!</p>\n'
107+
assert output == '<p>this should not be seen!</p>', \
108+
f"Got '{output}'"
105109

106110
def test_l_latex(self, convert):
107111
output = convert('latex', 'en', '@L this should not be seen!')
108-
assert output == 'this should not be seen!\n'
112+
assert output == 'this should not be seen!', \
113+
f"Got '{output}'"
109114

110115
def test_l_html(self, convert):
111116
output = convert('html', 'en', '@L this should not be seen!')
112-
assert output == '\n'
117+
assert output == '', \
118+
f"Got '{output}'"
113119

114120
def test_e_latex(self, convert):
115121
output = convert('latex', 'sk', '@E error')
116-
assert re.match(r'\\errorMessage\{error}\n', output) is not None
122+
assert re.match(r'\\errorMessage\{error}', output) is not None
117123

118124
def test_e_html(self, convert):
119125
output = convert('html', 'sk', '@E error')

core/tests/test_jinja.py

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,29 +41,21 @@ def create_temporary_file(string):
4141
return ntf
4242

4343

44-
def render_string_to_temporary(string, context) -> list[str]:
45-
renderer = MarkdownJinjaRenderer(template=string)
46-
output = SpooledTemporaryFile(0, 'r+')
47-
renderer.render(context, outfile=output)
48-
output.seek(0)
44+
def render_string_to_temporary(string, context) -> str:
45+
renderer = MarkdownJinjaRenderer()
46+
return renderer.render(string, context)
4947

50-
return output.readlines()
5148

52-
53-
def render_file_to_temporary(source, context) -> list[str]:
49+
def render_file_to_temporary(source, context) -> str:
50+
renderer = MarkdownJinjaRenderer()
5451
with open(source, 'r' ) as file:
55-
renderer = MarkdownJinjaRenderer(template=file.read())
56-
output = SpooledTemporaryFile(0, 'r+')
57-
renderer.render(context, outfile=output)
58-
output.seek(0)
59-
60-
return output.readlines()
52+
return renderer.render(file.read(), context)
6153

6254

6355
class TestConstant:
6456
@pytest.mark.parametrize("template,expected", [
6557
pytest.param('hello', 'hello', id='hello'),
66-
pytest.param(r'(§ large §) < (§ giga|g §)', r'123456789 < e\+?09\n', id='complex'),
58+
pytest.param(r'(§ large §) < (§ giga|g §)', r'123456789 < e\+?09', id='complex'),
6759
pytest.param('(§ your_mom|g5 §)', r'3.14e\+?15\n?', id='sci5'),
6860
pytest.param('(§ small|g4 §)', r'2.443e-19\n?', id='sci-small'),
6961
pytest.param('(§ (small * your_mom * five**5)|g5 §)', r'2.3975\n?', id='complex-expression'),
@@ -72,7 +64,7 @@ class TestConstant:
7264
])
7365
def test_render(self, template, expected, context_simple) -> None:
7466
rr = re.compile(expected)
75-
output = render_string_to_temporary(template, context_simple)[0]
67+
output = render_string_to_temporary(template, context_simple)
7668
assert rr.match(output), output
7769

7870
@pytest.mark.parametrize("source,expected", [
@@ -92,7 +84,7 @@ def test_render(self, template, expected, context_simple) -> None:
9284
])
9385
def test_does_it_render(self, source, expected, context_simple) -> None:
9486
result = render_file_to_temporary(Path('core/tests') / 'snippets' / source, context_simple)
95-
assert result == [f"{expected}\n"], \
87+
assert result == expected, \
9688
f"Expected {expected}, got {result}"
9789

9890
@pytest.mark.parametrize("name,expected,digits", [

0 commit comments

Comments
 (0)