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
Provenance
- Commit
7641542- Tree
b9cf898- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
7c62100
1 file changed+24 added−17 removed
modified:tests/test_asyncfilters.py+24 added-17 removed
5 unmodified lines6 for item in iter:7 yield item8 9 10+def 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 decorator17+18+19 @pytest.fixture20 def env_async():21 return Environment(enable_async=True)22 23 15-@pytest.mark.parametrize('foo', [16- lambda: range(10),17- lambda: make_aiter(range(10)),18-])24+@mark_dualiter('foo', lambda: range(10))25 def test_first(env_async, foo):26 tmpl = env_async.from_string('{{ foo()|first }}')27 out = tmpl.render(foo=foo)28 assert out == '0'29 30 31+@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+])25-def test_groupby(env_async):37+def 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 ]48 49 50+@mark_dualiter('items', lambda: [('a', 1), ('a', 2), ('b', 1)])41-def test_groupby_tuple_index(env_async):51+def 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|'57 58 59 def make_articles():60 class Date(object):14 unmodified lines75 Article('totally not', 1, 1, 1971)76 ]77 78 69-@pytest.mark.parametrize('articles', [70- make_articles,71- lambda: make_aiter(make_articles()),72-])79+@mark_dualiter('articles', make_articles)80 def 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