import os import pytest from bopytex.planner import fake_planner from bopytex.service import get_config, orcherstrator from bopytex.tasks import Task from bopytex.worker import Dispatcher from .fakes.workers import fake_worker 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}"] 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", "latexmk", "clean", "j2", "dispatcher", "pdfjam", "jinja2", "texenv", "from_option", } assert list(config["jinja2"].keys()) == ["environment"]