Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional test coverage for async rendering of native type templates #1807

Merged
merged 18 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
84c1836
Revert "support native types in macros"
jayaddison Feb 18, 2023
bdcaad6
Test coverage: add asynchronous native-environment string concatenati…
jayaddison Feb 18, 2023
78549cb
Revert "Revert "support native types in macros""
jayaddison Feb 18, 2023
26f3ace
Fixup: linting
jayaddison Feb 19, 2023
8b52122
Add CHANGES.rst entry
jayaddison Feb 19, 2023
e918fcc
Merge branch 'main' into issue-1806/pr-1511-additional-test-coverage
jayaddison Apr 16, 2023
e489935
Merge branch 'main' into issue-1806/pr-1511-additional-test-coverage
jayaddison Jun 4, 2023
1ef3021
Merge branch 'main' into issue-1806/pr-1511-additional-test-coverage
jayaddison Aug 21, 2023
fe2a0d5
Merge branch 'main' into issue-1806/pr-1511-additional-test-coverage
jayaddison Nov 28, 2023
743e813
Merge branch 'main' into issue-1806/pr-1511-additional-test-coverage
jayaddison Feb 22, 2024
84c5e4b
Merge branch 'main' into issue-1806/pr-1511-additional-test-coverage
jayaddison May 3, 2024
c9853e4
Merge branch 'main' into issue-1806/pr-1511-additional-test-coverage
jayaddison May 9, 2024
6802e4f
Merge branch 'main' into issue-1806/pr-1511-additional-test-coverage
jayaddison Jun 18, 2024
67962f1
[tests] Promote run_async_fn fixture to pytest conftest.py in prepara…
jayaddison Jun 18, 2024
4e1cd31
[tests] Refactor: re-use run_async_fn fixture for async native string…
jayaddison Jun 18, 2024
9506181
[tests] Cleanup: remove duplicate definition of run_async_fn fixture.
jayaddison Jun 18, 2024
5f0f2e9
Merge branch 'main' into issue-1806/pr-1511-additional-test-coverage
jayaddison Jul 8, 2024
1659885
Revert "Add CHANGES.rst entry"
jayaddison Jul 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Unreleased
- Use modern packaging metadata with ``pyproject.toml`` instead of ``setup.cfg``.
:pr:`1793`
- Use ``flit_core`` instead of ``setuptools`` as build backend.
- Additional test coverage for async rendering of native type templates
jayaddison marked this conversation as resolved.
Show resolved Hide resolved
:issue:`1806`


Version 3.1.5
Expand Down
11 changes: 11 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
import asyncio
from pathlib import Path

import pytest
import trio

from jinja2 import loaders
from jinja2.environment import Environment


def _asyncio_run(async_fn, *args):
return asyncio.run(async_fn(*args))


@pytest.fixture(params=[_asyncio_run, trio.run], ids=["asyncio", "trio"])
def run_async_fn(request):
return request.param


@pytest.fixture
def env():
"""returns a new environment."""
Expand Down
12 changes: 0 additions & 12 deletions tests/test_async.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import asyncio

import pytest
import trio

from jinja2 import ChainableUndefined
from jinja2 import DictLoader
Expand All @@ -14,15 +11,6 @@
from jinja2.nativetypes import NativeEnvironment


def _asyncio_run(async_fn, *args):
return asyncio.run(async_fn(*args))


@pytest.fixture(params=[_asyncio_run, trio.run], ids=["asyncio", "trio"])
def run_async_fn(request):
return request.param


def test_basic_async(run_async_fn):
t = Template(
"{% for item in [1, 2, 3] %}[{{ item }}]{% endfor %}", enable_async=True
Expand Down
11 changes: 0 additions & 11 deletions tests/test_async_filters.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import asyncio
import contextlib
from collections import namedtuple

import pytest
import trio
from markupsafe import Markup

from jinja2 import Environment
Expand All @@ -29,15 +27,6 @@ def env_async():
return Environment(enable_async=True)


def _asyncio_run(async_fn, *args):
return asyncio.run(async_fn(*args))


@pytest.fixture(params=[_asyncio_run, trio.run], ids=["asyncio", "trio"])
def run_async_fn(request):
return request.param


@contextlib.asynccontextmanager
async def closing_factory():
async with contextlib.AsyncExitStack() as stack:
Expand Down
17 changes: 17 additions & 0 deletions tests/test_nativetypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ def env():
return NativeEnvironment()


@pytest.fixture
def async_native_env():
return NativeEnvironment(enable_async=True)


def test_is_defined_native_return(env):
t = env.from_string("{{ missing is defined }}")
assert not t.render()
Expand Down Expand Up @@ -122,6 +127,18 @@ def test_string_top_level(env):
assert result == "Jinja"


def test_string_concatenation(async_native_env, run_async_fn):
async def async_render():
t = async_native_env.from_string(
"{%- macro x(y) -%}{{ y }}{%- endmacro -%}{{- x('not') }} {{ x('bad') -}}"
)
result = await t.render_async()
assert isinstance(result, str)
assert result == "not bad"

run_async_fn(async_render)


def test_tuple_of_variable_strings(env):
t = env.from_string("'{{ a }}', 'data', '{{ b }}', b'{{ c }}'")
result = t.render(a=1, b=2, c="bytes")
Expand Down