Bopytex/test/test_service.py

60 lines
1.4 KiB
Python
Raw Normal View History

2022-05-05 12:35:01 +00:00
import os
import pytest
2022-04-10 04:45:10 +00:00
from bopytex.planner import fake_planner
2022-05-05 12:35:01 +00:00
from bopytex.service import get_config, orcherstrator
2022-04-10 04:45:10 +00:00
from bopytex.tasks import Task
from bopytex.worker import Dispatcher
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)
config = get_config({"from_option": "config", "configfile": str(config_file)})
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",
"j2",
"dispatcher",
"pdfjam",
"jinja2",
"texenv",
"from_option",
}
assert list(config["jinja2"].keys()) == ["environment"]