conftest.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. from pathlib import Path
  2. import pytest
  3. from jinja2 import loaders
  4. from jinja2.environment import Environment
  5. @pytest.fixture
  6. def env():
  7. """returns a new environment."""
  8. return Environment()
  9. @pytest.fixture
  10. def dict_loader():
  11. """returns DictLoader"""
  12. return loaders.DictLoader({"justdict.html": "FOO"})
  13. @pytest.fixture
  14. def package_loader():
  15. """returns PackageLoader initialized from templates"""
  16. return loaders.PackageLoader("res", "templates")
  17. @pytest.fixture
  18. def filesystem_loader():
  19. """returns FileSystemLoader initialized to res/templates directory"""
  20. import yatest.common
  21. here = Path(yatest.common.test_source_path())
  22. return loaders.FileSystemLoader(here / "res" / "templates")
  23. @pytest.fixture
  24. def function_loader():
  25. """returns a FunctionLoader"""
  26. return loaders.FunctionLoader({"justfunction.html": "FOO"}.get)
  27. @pytest.fixture
  28. def choice_loader(dict_loader, package_loader):
  29. """returns a ChoiceLoader"""
  30. return loaders.ChoiceLoader([dict_loader, package_loader])
  31. @pytest.fixture
  32. def prefix_loader(filesystem_loader, dict_loader):
  33. """returns a PrefixLoader"""
  34. return loaders.PrefixLoader({"a": filesystem_loader, "b": dict_loader})