Feat: remise sur pieds pour les tests

This commit is contained in:
Bertrand Benjamin 2022-04-16 07:30:47 +02:00
parent ca2a47f82a
commit 04db450ceb
5 changed files with 28 additions and 47 deletions

View File

@ -1,2 +0,0 @@
from .default_planner import default_planner
from .only_corr_planner import only_corr_planner

View File

@ -11,16 +11,16 @@ def list_files(dir=".", accept=lambda _: True, reject=lambda _: False):
return files
def only_corr_planner(options: dict) -> list[Task]:
def planner(options: dict) -> list[Task]:
sources = list_files(
accept=lambda x: x.endswith(".tex"),
reject=lambda x: x.startswith("tpl_"),
)
options["sources"] = sources
return only_corr_tasks_builder(options)
return tasks_builder(options)
def only_corr_tasks_builder(
def tasks_builder(
options: dict,
) -> list[Task]:
opt = {

View File

@ -20,7 +20,7 @@ def build_subject_list_from_qty(qty: int) -> list[dict]:
return subjects
def default_planner(options: dict) -> list[Task]:
def planner(options: dict) -> list[Task]:
try:
students_csv = options["students_csv"]
@ -37,10 +37,10 @@ def default_planner(options: dict) -> list[Task]:
infos = csv.DictReader(csv_file)
options["subjects"] = build_subject_list_from_infos(infos)
return default_tasks_builder(options)
return tasks_builder(options)
def default_tasks_builder(
def tasks_builder(
options: dict,
) -> list[Task]:
@ -67,8 +67,9 @@ def default_tasks_builder(
for subject in subjects:
source = naming.template2source(template, subject)
args = {**subject, **options}
tasks.append(generate(template, {**subject, **opt}, source))
tasks.append(generate(template, args, source))
if not no_pdf:
pdf = naming.source2pdf(source)

View File

@ -2,7 +2,7 @@ import os
import jinja2
from pathlib import Path
from bopytex.message import Message
from bopytex.planner.default_planner import default_planner
from bopytex.planner.generate_compile_join_planner import planner
from bopytex.service import orcherstrator
from bopytex.worker import Dispatcher
from bopytex.worker.clean import clean
@ -52,7 +52,7 @@ def test_with_default_planner(template_path, jinja2_env, tmp_path):
dispatcher = Dispatcher(
{"GENERATE": generate, "COMPILE": latexmk, "JOIN": pdfjam, "CLEAN": clean}
)
orcherstre = orcherstrator(options, planner=default_planner, dispatcher=dispatcher)
orcherstre = orcherstrator(options, planner=planner, dispatcher=dispatcher)
messages = []
for message in orcherstre:

View File

@ -1,10 +1,10 @@
from bopytex.planner.default_planner import default_tasks_builder
from bopytex.planner.only_corr_planner import only_corr_tasks_builder
from bopytex.planner.generate_compile_join_planner import tasks_builder as gcj_task_builder
from bopytex.planner.activate_corr_compile_join_planner import tasks_builder as accj_task_builder
from bopytex.tasks import Task
def test_tasks_builder_generate():
tasks = default_tasks_builder(
tasks = gcj_task_builder(
options={
"template": "tpl_source.tex",
"subjects": [{"number": "01"}, {"number": "02"}],
@ -16,11 +16,9 @@ def test_tasks_builder_generate():
action="GENERATE",
args={
"number": "01",
"corr": False,
"no_join": False,
"no_pdf": True,
"template": "tpl_source.tex",
"subjects": [{"number": "01"}, {"number": "02"}],
"no_pdf": True,
},
deps=["tpl_source.tex"],
output="01_source.tex",
@ -29,11 +27,9 @@ def test_tasks_builder_generate():
action="GENERATE",
args={
"number": "02",
"corr": False,
"no_join": False,
"no_pdf": True,
"template": "tpl_source.tex",
"subjects": [{"number": "01"}, {"number": "02"}],
"no_pdf": True,
},
deps=["tpl_source.tex"],
output="02_source.tex",
@ -42,7 +38,7 @@ def test_tasks_builder_generate():
def test_tasks_builder_generate_compile():
tasks = default_tasks_builder(
tasks = gcj_task_builder(
options={
"template": "tpl_source.tex",
"subjects": [{"number": "01"}, {"number": "02"}],
@ -54,11 +50,9 @@ def test_tasks_builder_generate_compile():
action="GENERATE",
args={
"number": "01",
"corr": False,
"no_join": True,
"no_pdf": False,
"template": "tpl_source.tex",
"subjects": [{"number": "01"}, {"number": "02"}],
"no_join": True,
},
deps=["tpl_source.tex"],
output="01_source.tex",
@ -73,11 +67,9 @@ def test_tasks_builder_generate_compile():
action="GENERATE",
args={
"number": "02",
"corr": False,
"no_join": True,
"no_pdf": False,
"template": "tpl_source.tex",
"subjects": [{"number": "01"}, {"number": "02"}],
"no_join": True,
},
deps=["tpl_source.tex"],
output="02_source.tex",
@ -92,7 +84,7 @@ def test_tasks_builder_generate_compile():
def test_tasks_builder_generate_compile_join():
tasks = default_tasks_builder(
tasks = gcj_task_builder(
options={
"template": "tpl_source.tex",
"subjects": [{"number": "01"}, {"number": "02"}],
@ -103,9 +95,6 @@ def test_tasks_builder_generate_compile_join():
action="GENERATE",
args={
"number": "01",
"corr": False,
"no_join": False,
"no_pdf": False,
"template": "tpl_source.tex",
"subjects": [{"number": "01"}, {"number": "02"}],
},
@ -122,9 +111,6 @@ def test_tasks_builder_generate_compile_join():
action="GENERATE",
args={
"number": "02",
"corr": False,
"no_join": False,
"no_pdf": False,
"template": "tpl_source.tex",
"subjects": [{"number": "01"}, {"number": "02"}],
},
@ -147,7 +133,7 @@ def test_tasks_builder_generate_compile_join():
def test_tasks_builder_generate_compile_corr():
tasks = default_tasks_builder(
tasks = gcj_task_builder(
options={
"template": "tpl_source.tex",
"subjects": [{"number": "01"}, {"number": "02"}],
@ -160,11 +146,10 @@ def test_tasks_builder_generate_compile_corr():
action="GENERATE",
args={
"number": "01",
"corr": True,
"no_join": True,
"no_pdf": False,
"template": "tpl_source.tex",
"subjects": [{"number": "01"}, {"number": "02"}],
"corr": True,
"no_join": True,
},
deps=["tpl_source.tex"],
output="01_source.tex",
@ -191,11 +176,10 @@ def test_tasks_builder_generate_compile_corr():
action="GENERATE",
args={
"number": "02",
"corr": True,
"no_join": True,
"no_pdf": False,
"template": "tpl_source.tex",
"subjects": [{"number": "01"}, {"number": "02"}],
"corr": True,
"no_join": True,
},
deps=["tpl_source.tex"],
output="02_source.tex",
@ -222,7 +206,7 @@ def test_tasks_builder_generate_compile_corr():
def test_tasks_builder_generate_compile_corr_joined():
tasks = default_tasks_builder(
tasks = gcj_task_builder(
options={
"template": "tpl_source.tex",
"subjects": [{"number": "01"}, {"number": "02"}],
@ -237,7 +221,6 @@ def test_tasks_builder_generate_compile_corr_joined():
"number": "01",
"corr": True,
"no_join": False,
"no_pdf": False,
"template": "tpl_source.tex",
"subjects": [{"number": "01"}, {"number": "02"}],
},
@ -266,11 +249,10 @@ def test_tasks_builder_generate_compile_corr_joined():
action="GENERATE",
args={
"number": "02",
"corr": True,
"no_join": False,
"no_pdf": False,
"template": "tpl_source.tex",
"subjects": [{"number": "01"}, {"number": "02"}],
"corr": True,
"no_join": False,
},
deps=["tpl_source.tex"],
output="02_source.tex",
@ -309,7 +291,7 @@ def test_tasks_builder_generate_compile_corr_joined():
def test_only_corr_tasks_builder():
tasks = only_corr_tasks_builder(
tasks = accj_task_builder(
options={
"sources": ["01_source.tex", "02_source.tex"],
}