1import os 2 3import pytest 4 5from jinja2 import Environment 6from jinja2 import loaders 7from jinja2.utils import have_async_gen 8 9 10def pytest_ignore_collect(path): 11 if "async" in path.basename and not have_async_gen: 12 return True 13 return False 14 15 16@pytest.fixture 17def env(): 18 """returns a new environment.""" 19 return Environment() 20 21 22@pytest.fixture 23def dict_loader(): 24 """returns DictLoader""" 25 return loaders.DictLoader({"justdict.html": "FOO"}) 26 27 28@pytest.fixture 29def package_loader(): 30 """returns PackageLoader initialized from templates""" 31 return loaders.PackageLoader("res", "templates") 32 33 34@pytest.fixture 35def filesystem_loader(): 36 """returns FileSystemLoader initialized to res/templates directory""" 37 here = os.path.dirname(os.path.abspath(__file__)) 38 return loaders.FileSystemLoader(here + "/res/templates") 39 40 41@pytest.fixture 42def function_loader(): 43 """returns a FunctionLoader""" 44 return loaders.FunctionLoader({"justfunction.html": "FOO"}.get) 45 46 47@pytest.fixture 48def choice_loader(dict_loader, package_loader): 49 """returns a ChoiceLoader""" 50 return loaders.ChoiceLoader([dict_loader, package_loader]) 51 52 53@pytest.fixture 54def prefix_loader(filesystem_loader, dict_loader): 55 """returns a PrefixLoader""" 56 return loaders.PrefixLoader({"a": filesystem_loader, "b": dict_loader}) 57