Skip to content

Commit

Permalink
!squash helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
tony committed Oct 29, 2023
1 parent 5553ea3 commit b8fc497
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/helpers.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b8fc497

Please sign in to comment.