Skip to content

Commit e7ff9c1

Browse files
committed
Test regroup and spaceless
1 parent b7500c8 commit e7ff9c1

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

tests/test_flow.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Tests of control-flow structures for django_coverage_plugin."""
22

3+
import textwrap
4+
35
from .plugin_test import DjangoPluginTestCase, squashed
46

57

@@ -98,6 +100,40 @@ def test_loop_with_empty_clause(self):
98100
self.assertEqual(text, "Before\n\nNONE\n\nAfter\n")
99101
self.assert_analysis([1, 2, 3, 5, 7], [3])
100102

103+
def test_regroup(self):
104+
self.make_template("""\
105+
{% spaceless %}
106+
{% regroup cities by country as country_list %}
107+
<ul>
108+
{% for country in country_list %}
109+
<li>{{ country.grouper }}
110+
<ul>
111+
{% for item in country.list %}
112+
<li>{{ item.name }}: {{ item.population }}</li>
113+
{% endfor %}
114+
</ul>
115+
</li>
116+
{% endfor %}
117+
</ul>
118+
{% endspaceless %}
119+
""")
120+
text = self.run_django_coverage(context={
121+
'cities': [
122+
{'name': 'Mumbai', 'population': '19', 'country': 'India'},
123+
{'name': 'Calcutta', 'population': '15', 'country': 'India'},
124+
{'name': 'New York', 'population': '20', 'country': 'USA'},
125+
{'name': 'Chicago', 'population': '7', 'country': 'USA'},
126+
{'name': 'Tokyo', 'population': '33', 'country': 'Japan'},
127+
],
128+
})
129+
self.assertEqual(text, textwrap.dedent("""\
130+
<ul><li>India
131+
<ul><li>Mumbai: 19</li><li>Calcutta: 15</li></ul></li><li>USA
132+
<ul><li>New York: 20</li><li>Chicago: 7</li></ul></li><li>Japan
133+
<ul><li>Tokyo: 33</li></ul></li></ul>
134+
"""))
135+
self.assert_analysis([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13])
136+
101137

102138
class IfChangedTest(DjangoPluginTestCase):
103139

0 commit comments

Comments
 (0)