Commit a8623c58 by amateyna

latex code generation init

parent 8d773384
import jinja2
from pathlib import Path
def generate_code(analysis_dict, output_path):
jinja_env = _set_jinja_env()
def _set_jinja_env(templates_to_use='default'):
template_directory = Path(Path(__file__).parent.parent, 'templates', templates_to_use)
return jinja2.Environment(
block_start_string='\BLOCK{',
block_end_string='}',
variable_start_string='\VAR{',
variable_end_string='}',
comment_start_string='\#{',
comment_end_string='}',
line_statement_prefix='%%',
line_comment_prefix='%#',
trim_blocks=True,
autoescape=False,
loader=jinja2.FileSystemLoader(str(template_directory))
)
def _render_template(data, jinja_env, template):
output = jinja_env.get_template('{}.tex'.format(template))
return output.render(analysis=data['analysis'], meta_data=data['meta_data'])
def _write_file(raw_data, file_path):
with open(file_path, 'w') as fp:
fp.write(raw_data)
Test \VAR{meta_data} - \VAR{analysis}
\ No newline at end of file
from common_helper_process.fail_safe_subprocess import execute_shell_command_get_return_code
import os
import pytest
SRC_DIR = os.path.dirname(os.path.abspath(__file__)) + '/../../pdf_generator.py'
@pytest.mark.parametrize('arguments, expected_output, expected_return_code', [
('-V', 'FACT', 0),
('-h', 'usag', 0)
])
def test_main_program(arguments, expected_output, expected_return_code):
command_line = SRC_DIR + ' ' + arguments
output, return_code = execute_shell_command_get_return_code(command_line)
assert output[0:4] == expected_output
assert return_code == expected_return_code
from tempfile import TemporaryDirectory
from pathlib import Path
from ..data.test_dict import test_dict
from latex_code_generation.code_generation import generate_code
def test_latex_code_generation():
output_dir = TemporaryDirectory()
main_tex_path = Path(output_dir.name, 'main.tex')
generate_code(test_dict, Path(output_dir.name))
assert main_tex_path.exists()
from tempfile import TemporaryDirectory
from pathlib import Path
from latex_code_generation.code_generation import _set_jinja_env, _render_template, _write_file
def test_render_template():
test_data = {'meta_data': '123', 'analysis': '456'}
jinja_env = _set_jinja_env(templates_to_use='test')
output = _render_template(test_data, jinja_env, 'render_test')
assert output == 'Test 123 - 456'
def test_write_file():
tmp_dir = TemporaryDirectory()
file_path = Path(tmp_dir.name, 'test.tex')
_write_file('test', file_path)
assert file_path.exists()
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