Feat: e2e test on default planner

This commit is contained in:
Bertrand Benjamin 2022-04-13 22:14:27 +02:00
parent 1bcbf2a9a6
commit 1fdf223689
4 changed files with 148 additions and 14 deletions

View File

@ -68,7 +68,7 @@ def default_tasks_builder(
for subject in subjects: for subject in subjects:
source = naming.template2source(template, subject) source = naming.template2source(template, subject)
tasks.append(generate(template, subject, source)) tasks.append(generate(template, {**subject, **opt}, source))
if not no_pdf: if not no_pdf:
pdf = naming.source2pdf(source) pdf = naming.source2pdf(source)

View File

@ -1,4 +1,6 @@
import subprocess import subprocess
from bopytex.message import Message
from ..message import SubprocessMessage from ..message import SubprocessMessage
@ -9,5 +11,6 @@ def latexmk(args: dict, deps, output):
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
universal_newlines=True universal_newlines=True
) )
return SubprocessMessage(compile_process) #return SubprocessMessage(compile_process)
return Message(compile_process.wait(), list(compile_process.stdout), list(compile_process.stderr))

61
test/test_e2e.py Normal file
View File

@ -0,0 +1,61 @@
import os
import jinja2
from pathlib import Path
from bopytex.message import Message
from bopytex.planner.default_planner import default_planner
from bopytex.service import orcherstrator
from bopytex.worker import Dispatcher
from bopytex.worker.clean import clean
from bopytex.worker.compile import latexmk
from bopytex.worker.generate import generate
from bopytex.worker.join_pdf import pdfjam
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.
Subject {{ subject }}
\\end{document}
"""
)
return template
@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,
},
}
dispatcher = Dispatcher(
{"GENERATE": generate, "COMPILE": latexmk, "JOIN": pdfjam, "CLEAN": clean}
)
orcherstre = orcherstrator(options, planner=default_planner, dispatcher=dispatcher)
messages = []
for message in orcherstre:
assert message.status == 0
assert Path("joined_source.pdf").exists()

View File

@ -14,13 +14,27 @@ def test_tasks_builder_generate():
assert tasks == [ assert tasks == [
Task( Task(
action="GENERATE", action="GENERATE",
args={"number": "01"}, args={
"number": "01",
"corr": False,
"no_join": False,
"no_pdf": True,
"template": "tpl_source.tex",
"subjects": [{"number": "01"}, {"number": "02"}],
},
deps=["tpl_source.tex"], deps=["tpl_source.tex"],
output="01_source.tex", output="01_source.tex",
), ),
Task( Task(
action="GENERATE", action="GENERATE",
args={"number": "02"}, args={
"number": "02",
"corr": False,
"no_join": False,
"no_pdf": True,
"template": "tpl_source.tex",
"subjects": [{"number": "01"}, {"number": "02"}],
},
deps=["tpl_source.tex"], deps=["tpl_source.tex"],
output="02_source.tex", output="02_source.tex",
), ),
@ -38,7 +52,14 @@ def test_tasks_builder_generate_compile():
assert tasks == [ assert tasks == [
Task( Task(
action="GENERATE", action="GENERATE",
args={"number": "01"}, args={
"number": "01",
"corr": False,
"no_join": True,
"no_pdf": False,
"template": "tpl_source.tex",
"subjects": [{"number": "01"}, {"number": "02"}],
},
deps=["tpl_source.tex"], deps=["tpl_source.tex"],
output="01_source.tex", output="01_source.tex",
), ),
@ -50,7 +71,14 @@ def test_tasks_builder_generate_compile():
), ),
Task( Task(
action="GENERATE", action="GENERATE",
args={"number": "02"}, args={
"number": "02",
"corr": False,
"no_join": True,
"no_pdf": False,
"template": "tpl_source.tex",
"subjects": [{"number": "01"}, {"number": "02"}],
},
deps=["tpl_source.tex"], deps=["tpl_source.tex"],
output="02_source.tex", output="02_source.tex",
), ),
@ -73,7 +101,14 @@ def test_tasks_builder_generate_compile_join():
assert tasks == [ assert tasks == [
Task( Task(
action="GENERATE", action="GENERATE",
args={"number": "01"}, args={
"number": "01",
"corr": False,
"no_join": False,
"no_pdf": False,
"template": "tpl_source.tex",
"subjects": [{"number": "01"}, {"number": "02"}],
},
deps=["tpl_source.tex"], deps=["tpl_source.tex"],
output="01_source.tex", output="01_source.tex",
), ),
@ -85,7 +120,14 @@ def test_tasks_builder_generate_compile_join():
), ),
Task( Task(
action="GENERATE", action="GENERATE",
args={"number": "02"}, args={
"number": "02",
"corr": False,
"no_join": False,
"no_pdf": False,
"template": "tpl_source.tex",
"subjects": [{"number": "01"}, {"number": "02"}],
},
deps=["tpl_source.tex"], deps=["tpl_source.tex"],
output="02_source.tex", output="02_source.tex",
), ),
@ -109,14 +151,21 @@ def test_tasks_builder_generate_compile_corr():
options={ options={
"template": "tpl_source.tex", "template": "tpl_source.tex",
"subjects": [{"number": "01"}, {"number": "02"}], "subjects": [{"number": "01"}, {"number": "02"}],
"corr": 1, "corr": True,
"no_join": 1, "no_join": True,
} }
) )
assert tasks == [ assert tasks == [
Task( Task(
action="GENERATE", action="GENERATE",
args={"number": "01"}, args={
"number": "01",
"corr": True,
"no_join": True,
"no_pdf": False,
"template": "tpl_source.tex",
"subjects": [{"number": "01"}, {"number": "02"}],
},
deps=["tpl_source.tex"], deps=["tpl_source.tex"],
output="01_source.tex", output="01_source.tex",
), ),
@ -140,7 +189,14 @@ def test_tasks_builder_generate_compile_corr():
), ),
Task( Task(
action="GENERATE", action="GENERATE",
args={"number": "02"}, args={
"number": "02",
"corr": True,
"no_join": True,
"no_pdf": False,
"template": "tpl_source.tex",
"subjects": [{"number": "01"}, {"number": "02"}],
},
deps=["tpl_source.tex"], deps=["tpl_source.tex"],
output="02_source.tex", output="02_source.tex",
), ),
@ -177,7 +233,14 @@ def test_tasks_builder_generate_compile_corr_joined():
assert tasks == [ assert tasks == [
Task( Task(
action="GENERATE", action="GENERATE",
args={"number": "01"}, args={
"number": "01",
"corr": True,
"no_join": False,
"no_pdf": False,
"template": "tpl_source.tex",
"subjects": [{"number": "01"}, {"number": "02"}],
},
deps=["tpl_source.tex"], deps=["tpl_source.tex"],
output="01_source.tex", output="01_source.tex",
), ),
@ -201,7 +264,14 @@ def test_tasks_builder_generate_compile_corr_joined():
), ),
Task( Task(
action="GENERATE", action="GENERATE",
args={"number": "02"}, args={
"number": "02",
"corr": True,
"no_join": False,
"no_pdf": False,
"template": "tpl_source.tex",
"subjects": [{"number": "01"}, {"number": "02"}],
},
deps=["tpl_source.tex"], deps=["tpl_source.tex"],
output="02_source.tex", output="02_source.tex",
), ),