-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is a preparation for async rendering. The fixture can then be parametrized and invoked from both the sync and async implementation.
- Loading branch information
Showing
8 changed files
with
256 additions
and
202 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from __future__ import annotations | ||
|
||
import typing as t | ||
|
||
import pytest | ||
|
||
from htpy import Node, iter_node | ||
|
||
if t.TYPE_CHECKING: | ||
from collections.abc import Generator | ||
|
||
|
||
RenderFixture: t.TypeAlias = t.Callable[[Node], list[str]] | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def django_env() -> None: | ||
import django | ||
from django.conf import settings | ||
|
||
settings.configure( | ||
TEMPLATES=[ | ||
{"BACKEND": "django.template.backends.django.DjangoTemplates"}, | ||
{"BACKEND": "htpy.django.HtpyTemplateBackend", "NAME": "htpy"}, | ||
] | ||
) | ||
django.setup() | ||
|
||
|
||
@pytest.fixture | ||
def render() -> Generator[RenderFixture, None, None]: | ||
called = False | ||
|
||
def func(node: Node) -> list[str]: | ||
nonlocal called | ||
called = True | ||
return list(iter_node(node)) | ||
|
||
yield func | ||
|
||
if not called: | ||
raise AssertionError("render() was not called") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.