2022-04-13 20:14:27 +00:00
|
|
|
import os
|
|
|
|
import jinja2
|
|
|
|
from pathlib import Path
|
2022-05-04 19:16:27 +00:00
|
|
|
from bopytex.service import main
|
2022-04-13 20:14:27 +00:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def template_path(tmp_path):
|
|
|
|
template = tmp_path / "tpl_source.tex"
|
|
|
|
with open(template, "w") as tpl:
|
|
|
|
tpl.write(
|
|
|
|
"""
|
|
|
|
\\documentclass{article}
|
|
|
|
|
|
|
|
\\begin{document}
|
|
|
|
First document.
|
|
|
|
|
2022-05-04 16:00:54 +00:00
|
|
|
Subject {{ number }}
|
2022-04-13 20:14:27 +00:00
|
|
|
\\end{document}
|
|
|
|
"""
|
|
|
|
)
|
|
|
|
return template
|
|
|
|
|
2022-05-04 19:21:26 +00:00
|
|
|
@pytest.fixture
|
|
|
|
def bad_template_path(tmp_path):
|
|
|
|
template = tmp_path / "tpl_source.tex"
|
|
|
|
with open(template, "w") as tpl:
|
|
|
|
tpl.write(
|
|
|
|
"""
|
|
|
|
\\documentclass{article}
|
|
|
|
|
|
|
|
\\begin{document}
|
|
|
|
First document.
|
|
|
|
|
|
|
|
Subject {{ number }}
|
|
|
|
"""
|
|
|
|
)
|
|
|
|
return template
|
|
|
|
|
2022-04-13 20:14:27 +00:00
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def jinja2_env(tmp_path):
|
|
|
|
templateEnv = jinja2.Environment(loader=jinja2.FileSystemLoader(tmp_path))
|
|
|
|
return templateEnv
|
|
|
|
|
|
|
|
|
|
|
|
def test_with_default_planner(template_path, jinja2_env, tmp_path):
|
|
|
|
os.chdir(tmp_path)
|
|
|
|
|
|
|
|
options = {
|
|
|
|
"template": str(template_path.name),
|
|
|
|
"quantity_subjects": 3,
|
|
|
|
"corr": False,
|
|
|
|
"no_join": False,
|
|
|
|
"no_pdf": False,
|
|
|
|
"jinja2": {
|
|
|
|
"environment": jinja2_env,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-05-04 19:16:27 +00:00
|
|
|
for message in main(**options):
|
2022-05-08 07:15:13 +00:00
|
|
|
assert message.status == 0
|
2022-04-13 20:14:27 +00:00
|
|
|
|
|
|
|
assert Path("joined_source.pdf").exists()
|
2022-05-04 09:39:28 +00:00
|
|
|
|
2022-05-04 19:21:26 +00:00
|
|
|
def test_with_default_planner_bad_template(bad_template_path, jinja2_env, tmp_path):
|
|
|
|
os.chdir(tmp_path)
|
|
|
|
|
|
|
|
options = {
|
|
|
|
"template": str(bad_template_path.name),
|
|
|
|
"quantity_subjects": 3,
|
|
|
|
"corr": False,
|
|
|
|
"no_join": False,
|
|
|
|
"no_pdf": False,
|
|
|
|
"jinja2": {
|
|
|
|
"environment": jinja2_env,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for message in main(**options):
|
|
|
|
pass
|
|
|
|
|
|
|
|
assert not Path("joined_source.pdf").exists()
|
|
|
|
|