summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorlisongmin <lisongmin@protonmail.com>2021-02-23 14:34:36 +0800
committerDavid Lord <davidism@gmail.com>2021-04-05 14:42:34 -0700
commit34fbec9a726113381a27c30d2363aae676b9086a (patch)
tree0c6bb6b23598c54f1332d58c2feae705a20d5f03 /tests
parent4a941cab0ddff1ce58f4c6634e22a7659fd0648b (diff)
downloadjinja2-34fbec9a726113381a27c30d2363aae676b9086a.tar.gz
add default parameter to groupby
Diffstat (limited to 'tests')
-rw-r--r--tests/test_filters.py15
1 files changed, 15 insertions, 0 deletions
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 %}"