diff options
author | David Lord <davidism@gmail.com> | 2017-07-06 08:37:17 -0700 |
---|---|---|
committer | David Lord <davidism@gmail.com> | 2017-07-06 08:37:17 -0700 |
commit | 52dcb4753ac0f33ca9cd1027fb8831fe86af8fc4 (patch) | |
tree | d149582bf074adfa5385adeb6c2a6221e9089c94 /tests | |
parent | 5435d35f97d1e74eba2854651b8ef7258f31292b (diff) | |
download | jinja2-52dcb4753ac0f33ca9cd1027fb8831fe86af8fc4.tar.gz |
parametrize tests
argument order consistent with existing filters
add changelog
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_filters.py | 44 |
1 files changed, 20 insertions, 24 deletions
diff --git a/tests/test_filters.py b/tests/test_filters.py index 9c4504a..84e77d9 100644 --- a/tests/test_filters.py +++ b/tests/test_filters.py @@ -391,30 +391,6 @@ class TestFilter(object): tmpl = env.from_string('''{{ items|sort(attribute='value')|join }}''') assert tmpl.render(items=map(Magic, [3, 2, 4, 1])) == '1234' - def test_min1(self, env): - tmpl = env.from_string('{{ ["a", "B"]|min }}') - assert tmpl.render() == 'a' - - def test_min2(self, env): - tmpl = env.from_string('{{ []|min }}') - assert tmpl.render() == '' - - def test_min3(self, env): - tmpl = env.from_string('{{ items|min("value") }}') - assert tmpl.render(items=map(Magic, [5, 1, 9])) == '1' - - def test_max1(self, env): - tmpl = env.from_string('{{ ["a", "B"]|max }}') - assert tmpl.render() == 'B' - - def test_max2(self, env): - tmpl = env.from_string('{{ []|max }}') - assert tmpl.render() == '' - - def test_max3(self, env): - tmpl = env.from_string('{{ items|max("value") }}') - assert tmpl.render(items=map(Magic, [5, 9, 1])) == '9' - def test_unique(self, env): t = env.from_string('{{ "".join(["b", "A", "a", "b"]|unique) }}') assert t.render() == "bA" @@ -427,6 +403,26 @@ class TestFilter(object): t = env.from_string("{{ items|unique(attribute='value')|join }}") assert t.render(items=map(Magic, [3, 2, 4, 1, 2])) == '3241' + @pytest.mark.parametrize('source,expect', ( + ('{{ ["a", "B"]|min }}', 'a'), + ('{{ ["a", "B"]|min(case_sensitive=true) }}', 'B'), + ('{{ []|min }}', ''), + ('{{ ["a", "B"]|max }}', 'B'), + ('{{ ["a", "B"]|max(case_sensitive=true) }}', 'a'), + ('{{ []|max }}', ''), + )) + def test_min_max(self, env, source, expect): + t = env.from_string(source) + assert t.render() == expect + + @pytest.mark.parametrize('name,expect', ( + ('min', '1'), + ('max', '9'), + )) + def test_min_max_attribute(self, env, name, expect): + t = env.from_string('{{ items|' + name + '(attribute="value") }}') + assert t.render(items=map(Magic, [5, 1, 9])) == expect + def test_groupby(self, env): tmpl = env.from_string(''' {%- for grouper, list in [{'foo': 1, 'bar': 2}, |