Bopytex/test/test_service.py

63 lines
1.5 KiB
Python
Raw Normal View History

2022-05-05 12:35:01 +00:00
import os
2022-07-28 07:39:51 +00:00
2022-05-05 12:35:01 +00:00
import pytest
2022-04-10 04:45:10 +00:00
from bopytex.planner import fake_planner
2022-07-19 13:15:06 +00:00
from bopytex.service import build_config, orcherstrator
2022-04-10 04:45:10 +00:00
from bopytex.tasks import Task
from bopytex.worker import Dispatcher
2022-07-28 07:39:51 +00:00
from .fakes.workers import fake_worker
2022-04-09 05:30:13 +00:00
2022-04-10 04:45:10 +00:00
def test_service():
options = {"quantity": 3, "template": "tpl_src.tex"}
dispatcher = Dispatcher(actions={"DO": fake_worker})
service = orcherstrator(options, fake_planner.simple, dispatcher)
for i, message in enumerate(service):
assert message.status == 0
assert message.out == [f"FAKE - {{'number': {i}}} - [] - {i}"]
2022-05-05 12:35:01 +00:00
def test_get_config_no_configfile():
pass
@pytest.fixture
def config_file(tmp_path):
config_file = tmp_path / "bopytex_config.py"
with open(config_file, "w") as f:
f.write(
"""
from bopytex.jinja2_env.texenv import texenv
jinja2 = {
"environment": texenv,
}
"""
)
return config_file
def test_get_config_with_configfile(config_file, tmp_path):
os.chdir(tmp_path)
2022-07-19 13:15:06 +00:00
config = build_config({"from_option": "config", "configfile": str(config_file)})
2022-05-05 12:35:01 +00:00
assert type(config) == dict
assert set(config.keys()) == {
"generate",
"configfile",
"Dispatcher",
"planner",
2022-05-07 14:55:33 +00:00
"pdflatex",
2022-05-05 12:35:01 +00:00
"clean",
"latex",
"activate_corr",
2022-05-05 12:35:01 +00:00
"dispatcher",
"pdfjam",
"jinja2",
"texenv",
"from_option",
}
assert list(config["jinja2"].keys()) == ["environment"]