conftest.py
This file
Path
tests/conftest.py
60 lines · 1.4 KiB · Python
Last changed by
Additional test coverage for async rendering of native type templates (#1807)James Addisonbefore adoptionf8323cf
History of this fileTake it
1import asyncio2from pathlib import Path34import pytest5import trio67from jinja2 import loaders8from jinja2.environment import Environment91011def _asyncio_run(async_fn, *args):12 return asyncio.run(async_fn(*args))131415@pytest.fixture(params=[_asyncio_run, trio.run], ids=["asyncio", "trio"])16def run_async_fn(request):17 return request.param181920@pytest.fixture21def env():22 """returns a new environment."""23 return Environment()242526@pytest.fixture27def dict_loader():28 """returns DictLoader"""29 return loaders.DictLoader({"justdict.html": "FOO"})303132@pytest.fixture33def package_loader():34 """returns PackageLoader initialized from templates"""35 return loaders.PackageLoader("res", "templates")363738@pytest.fixture39def filesystem_loader():40 """returns FileSystemLoader initialized to res/templates directory"""41 here = Path(__file__).parent.resolve()42 return loaders.FileSystemLoader(here / "res" / "templates")434445@pytest.fixture46def function_loader():47 """returns a FunctionLoader"""48 return loaders.FunctionLoader({"justfunction.html": "FOO"}.get)495051@pytest.fixture52def choice_loader(dict_loader, package_loader):53 """returns a ChoiceLoader"""54 return loaders.ChoiceLoader([dict_loader, package_loader])555657@pytest.fixture58def prefix_loader(filesystem_loader, dict_loader):59 """returns a PrefixLoader"""60 return loaders.PrefixLoader({"a": filesystem_loader, "b": dict_loader})