Commit c096ab8d by dorp

fixed 3.5 backwards compatibility (order of dict included)

parent 3db084f6
import logging
from base64 import decodebytes
from collections import OrderedDict
from pathlib import Path
from time import localtime, strftime
......@@ -42,26 +43,26 @@ def nice_number_filter(number):
def filter_latex_special_chars(data):
latex_character_escapes = {
'\\': '',
'$': '\\$',
'(': '$($',
')': '$)$',
'[': '$[$',
']': '$]$',
'#': '\\#',
'%': '\\%',
'&': '\\&',
'_': '\\_',
'{': '\\{',
'}': '\\}',
'^': '\\textasciicircum{}',
'~': '\\textasciitilde{}',
'>': '\\textgreater{}',
'<': '\\textless{}',
'\n': '\\newline ',
'\'': ''
}
latex_character_escapes = OrderedDict()
latex_character_escapes['\\'] = ''
latex_character_escapes['\''] = ''
latex_character_escapes['$'] = '\\$'
latex_character_escapes['('] = '$($'
latex_character_escapes[')'] = '$)$'
latex_character_escapes['['] = '$[$',
latex_character_escapes[']'] = '$]$',
latex_character_escapes['#'] = '\\#'
latex_character_escapes['%'] = '\\%'
latex_character_escapes['&'] = '\\&'
latex_character_escapes['_'] = '\\_'
latex_character_escapes['{'] = '\\{'
latex_character_escapes['}'] = '\\}'
latex_character_escapes['^'] = '\\textasciicircum{}'
latex_character_escapes['~'] = '\\textasciitilde{}'
latex_character_escapes['>'] = '\\textgreater{}'
latex_character_escapes['<'] = '\\textless{}'
latex_character_escapes['\n'] = '\\newline '
for character, replacement in latex_character_escapes.items():
if character in data:
data = data.replace(character, replacement)
......
......@@ -31,13 +31,13 @@ def test_execute_latex(monkeypatch, tmpdir):
monkeypatch.setattr('pdf_generator.generator.execute_shell_command_get_return_code', exec_mock)
execute_latex(str(tmpdir))
assert Path(tmpdir, 'test').exists()
assert Path(tmpdir, 'test').read_text() == 'works'
assert Path(str(tmpdir), 'test').exists()
assert Path(str(tmpdir), 'test').read_text() == 'works'
def test_copy_fact_image(tmpdir):
copy_fact_image(str(tmpdir))
assert Path(tmpdir, 'fact_logo.png').exists()
assert Path(str(tmpdir), 'fact_logo.png').exists()
def test_create_report_filename():
......@@ -60,8 +60,8 @@ def test_create_templates(monkeypatch, tmpdir):
monkeypatch.setattr('pdf_generator.generator.Engine', MockEngine)
create_templates(analysis={'test': {'result': 'data'}}, meta_data={}, tmp_dir=str(tmpdir))
assert Path(tmpdir, 'main.tex').exists()
assert Path(tmpdir, 'meta.tex').exists()
assert Path(tmpdir, 'test.tex').exists()
assert Path(str(tmpdir), 'main.tex').exists()
assert Path(str(tmpdir), 'meta.tex').exists()
assert Path(str(tmpdir), 'test.tex').exists()
assert Path(tmpdir, 'test.tex').read_text() == '{"result": "data"}'
assert Path(str(tmpdir), 'test.tex').read_text() == '{"result": "data"}'
Markdown is supported
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