diff --git a/tests/helpers.py b/tests/helpers.py new file mode 100644 index 00000000..adb4d582 --- /dev/null +++ b/tests/helpers.py @@ -0,0 +1,28 @@ +"""Tests for DocutilsView template view.""" +import typing as t + +from django.template.engine import Engine + +if t.TYPE_CHECKING: + import sys + import types + + from typing_extensions import TypeAlias + + # https://github.com/python/typeshed/blob/f7aa7b7/stdlib/builtins.pyi#L1461 + if sys.version_info >= (3, 10): + _ClassInfo: TypeAlias = type | types.UnionType | tuple["_ClassInfo", ...] + else: + _ClassInfo: TypeAlias = type | tuple[_ClassInfo, ...] + + +def get_template_engine( + using: "_ClassInfo", +) -> None | Engine: + """Return Template Engine (e.g. DocutilsTemplates), for augmenting dirs in tests.""" + from django.template import engines + + for engine in engines.all(): + if isinstance(engine, using): + return t.cast(Engine, engine.engine) # type:ignore + return None