Bopytex/test/test_planner.py

264 lines
6.5 KiB
Python

from bopytex.planner import only_corr_planner, planner
from bopytex.tasks import Task
def test_planner_generate():
tasks = planner(
template="tpl_source.tex",
subjects=[{"number": "01"}, {"number": "02"}],
no_pdf=1,
)
assert tasks == [
Task(
action="GENERATE",
args={"number": "01"},
deps=["tpl_source.tex"],
output="01_source.tex",
),
Task(
action="GENERATE",
args={"number": "02"},
deps=["tpl_source.tex"],
output="02_source.tex",
),
]
def test_planner_generate_compile():
tasks = planner(
template="tpl_source.tex",
subjects=[{"number": "01"}, {"number": "02"}],
no_join=1,
)
assert tasks == [
Task(
action="GENERATE",
args={"number": "01"},
deps=["tpl_source.tex"],
output="01_source.tex",
),
Task(
action="COMPILE",
args={},
deps=["01_source.tex"],
output="01_source.pdf",
),
Task(
action="GENERATE",
args={"number": "02"},
deps=["tpl_source.tex"],
output="02_source.tex",
),
Task(
action="COMPILE",
args={},
deps=["02_source.tex"],
output="02_source.pdf",
),
]
def test_planner_generate_compile_join():
tasks = planner(
template="tpl_source.tex",
subjects=[{"number": "01"}, {"number": "02"}],
)
assert tasks == [
Task(
action="GENERATE",
args={"number": "01"},
deps=["tpl_source.tex"],
output="01_source.tex",
),
Task(
action="COMPILE",
args={},
deps=["01_source.tex"],
output="01_source.pdf",
),
Task(
action="GENERATE",
args={"number": "02"},
deps=["tpl_source.tex"],
output="02_source.tex",
),
Task(
action="COMPILE",
args={},
deps=["02_source.tex"],
output="02_source.pdf",
),
Task(
action="JOIN",
args={},
deps=["01_source.pdf", "02_source.pdf"],
output="joined_source.pdf",
),
]
def test_planner_generate_compile_corr():
tasks = planner(
template="tpl_source.tex",
subjects=[{"number": "01"}, {"number": "02"}],
corr=1,
no_join=1,
)
assert tasks == [
Task(
action="GENERATE",
args={"number": "01"},
deps=["tpl_source.tex"],
output="01_source.tex",
),
Task(
action="COMPILE",
args={},
deps=["01_source.tex"],
output="01_source.pdf",
),
Task(
action="ACTIVATE_CORR",
args={},
deps=["01_source.tex"],
output="corr_01_source.tex",
),
Task(
action="COMPILE",
args={},
deps=["corr_01_source.tex"],
output="corr_01_source.pdf",
),
Task(
action="GENERATE",
args={"number": "02"},
deps=["tpl_source.tex"],
output="02_source.tex",
),
Task(
action="COMPILE",
args={},
deps=["02_source.tex"],
output="02_source.pdf",
),
Task(
action="ACTIVATE_CORR",
args={},
deps=["02_source.tex"],
output="corr_02_source.tex",
),
Task(
action="COMPILE",
args={},
deps=["corr_02_source.tex"],
output="corr_02_source.pdf",
),
]
def test_planner_generate_compile_corr_joined():
tasks = planner(
template="tpl_source.tex",
subjects=[{"number": "01"}, {"number": "02"}],
corr=1,
)
assert tasks == [
Task(
action="GENERATE",
args={"number": "01"},
deps=["tpl_source.tex"],
output="01_source.tex",
),
Task(
action="COMPILE",
args={},
deps=["01_source.tex"],
output="01_source.pdf",
),
Task(
action="ACTIVATE_CORR",
args={},
deps=["01_source.tex"],
output="corr_01_source.tex",
),
Task(
action="COMPILE",
args={},
deps=["corr_01_source.tex"],
output="corr_01_source.pdf",
),
Task(
action="GENERATE",
args={"number": "02"},
deps=["tpl_source.tex"],
output="02_source.tex",
),
Task(
action="COMPILE",
args={},
deps=["02_source.tex"],
output="02_source.pdf",
),
Task(
action="ACTIVATE_CORR",
args={},
deps=["02_source.tex"],
output="corr_02_source.tex",
),
Task(
action="COMPILE",
args={},
deps=["corr_02_source.tex"],
output="corr_02_source.pdf",
),
Task(
action="JOIN",
args={},
deps=["01_source.pdf", "02_source.pdf"],
output="joined_source.pdf",
),
Task(
action="JOIN",
args={},
deps=["corr_01_source.pdf", "corr_02_source.pdf"],
output="corr_joined_source.pdf",
),
]
def test_only_corr_planner():
tasks = only_corr_planner(
sources = ["01_source.tex", "02_source.tex"],
)
assert tasks == [
Task(
action="ACTIVATE_CORR",
args={},
deps=["01_source.tex"],
output="corr_01_source.tex",
),
Task(
action="COMPILE",
args={},
deps=["corr_01_source.tex"],
output="corr_01_source.pdf",
),
Task(
action="ACTIVATE_CORR",
args={},
deps=["02_source.tex"],
output="corr_02_source.tex",
),
Task(
action="COMPILE",
args={},
deps=["corr_02_source.tex"],
output="corr_02_source.pdf",
),
Task(
action="JOIN",
args={},
deps=["corr_01_source.pdf", "corr_02_source.pdf"],
output="corr_joined.pdf",
),
]