Skip to content
Myr

Restructured tests for async filters

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent 7c62100 · Browse files · 1 file+24 added−17 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+24 added−17 removed

  • tests:+24 added−17 removed

1 file+24 added−17 removed

modified:tests/test_asyncfilters.py+24 added-17 removed
5 unmodified lines
6 for item in iter:7 yield item8910def mark_dualiter(parameter, factory):11 def decorator(f):12 return pytest.mark.parametrize(parameter, [13 lambda: factory(),14 lambda: make_aiter(factory()),15 ])(f)16 return decorator171819@pytest.fixture20def env_async():21 return Environment(enable_async=True)222315@pytest.mark.parametrize('foo', [16 lambda: range(10),17 lambda: make_aiter(range(10)),18])24@mark_dualiter('foo', lambda: range(10))25def test_first(env_async, foo):26 tmpl = env_async.from_string('{{ foo()|first }}')27 out = tmpl.render(foo=foo)28 assert out == '0'293031@mark_dualiter('items', lambda: [32 {'foo': 1, 'bar': 2},33 {'foo': 2, 'bar': 3},34 {'foo': 1, 'bar': 1},35 {'foo': 3, 'bar': 4}36])25def test_groupby(env_async):37def test_groupby(env_async, items):38 tmpl = env_async.from_string('''27 {%- for grouper, list in [{'foo': 1, 'bar': 2},28 {'foo': 2, 'bar': 3},29 {'foo': 1, 'bar': 1},30 {'foo': 3, 'bar': 4}]|groupby('foo') -%}39 {%- for grouper, list in items()|groupby('foo') -%}40 {{ grouper }}{% for x in list %}: {{ x.foo }}, {{ x.bar }}{% endfor %}|41 {%- endfor %}''')33 assert tmpl.render().split('|') == [42 assert tmpl.render(items=items).split('|') == [43 "1: 1, 2: 1, 1",44 "2: 2, 3",45 "3: 3, 4",46 ""47 ]484950@mark_dualiter('items', lambda: [('a', 1), ('a', 2), ('b', 1)])41def test_groupby_tuple_index(env_async):51def test_groupby_tuple_index(env_async, items):52 tmpl = env_async.from_string('''43 {%- for grouper, list in [('a', 1), ('a', 2), ('b', 1)]|groupby(0) -%}53 {%- for grouper, list in items()|groupby(0) -%}54 {{ grouper }}{% for x in list %}:{{ x.1 }}{% endfor %}|55 {%- endfor %}''')46 assert tmpl.render() == 'a:1:2|b:1|'56 assert tmpl.render(items=items) == 'a:1:2|b:1|'575859def make_articles():60 class Date(object):
14 unmodified lines
75 Article('totally not', 1, 1, 1971)76 ]777869@pytest.mark.parametrize('articles', [70 make_articles,71 lambda: make_aiter(make_articles()),72])79@mark_dualiter('articles', make_articles)80def test_groupby_multidot(env_async, articles):81 tmpl = env_async.from_string('''82 {%- for year, list in articles()|groupby('date.year') -%}83 {{ year }}{% for x in list %}[{{ x.title }}]{% endfor %}|
6 unmodified lines