From 34fbec9a726113381a27c30d2363aae676b9086a Mon Sep 17 00:00:00 2001 From: lisongmin Date: Tue, 23 Feb 2021 14:34:36 +0800 Subject: add default parameter to groupby --- tests/test_filters.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tests') diff --git a/tests/test_filters.py b/tests/test_filters.py index 2c119c3..0843246 100644 --- a/tests/test_filters.py +++ b/tests/test_filters.py @@ -593,6 +593,21 @@ class TestFilter: "", ] + def test_groupby_default(self, env): + tmpl = env.from_string( + "{% for city, items in users|groupby('city', default='NY') %}" + "{{ city }}: {{ items|map(attribute='name')|join(', ') }}\n" + "{% endfor %}" + ) + out = tmpl.render( + users=[ + {"name": "emma", "city": "NY"}, + {"name": "smith", "city": "WA"}, + {"name": "john"}, + ] + ) + assert out == "NY: emma, john\nWA: smith\n" + def test_filtertag(self, env): tmpl = env.from_string( "{% filter upper|replace('FOO', 'foo') %}foobar{% endfilter %}" -- cgit v1.2.1