diff --git a/tests/conftest.py b/tests/conftest.py index e225ab907..2fda63a82 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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.""" diff --git a/tests/test_async.py b/tests/test_async.py index 4edced9dd..9bd9fda17 100644 --- a/tests/test_async.py +++ b/tests/test_async.py @@ -1,7 +1,4 @@ -import asyncio - import pytest -import trio from jinja2 import ChainableUndefined from jinja2 import DictLoader @@ -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 diff --git a/tests/test_async_filters.py b/tests/test_async_filters.py index e8cc350d5..88ae5f41e 100644 --- a/tests/test_async_filters.py +++ b/tests/test_async_filters.py @@ -1,9 +1,7 @@ -import asyncio import contextlib from collections import namedtuple import pytest -import trio from markupsafe import Markup from jinja2 import Environment @@ -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: diff --git a/tests/test_nativetypes.py b/tests/test_nativetypes.py index 8c8525251..355799cc7 100644 --- a/tests/test_nativetypes.py +++ b/tests/test_nativetypes.py @@ -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() @@ -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")