|
1 | 1 | """Tests of control-flow structures for django_coverage_plugin."""
|
2 | 2 |
|
| 3 | +import textwrap |
| 4 | + |
3 | 5 | from .plugin_test import DjangoPluginTestCase, squashed
|
4 | 6 |
|
5 | 7 |
|
@@ -98,6 +100,40 @@ def test_loop_with_empty_clause(self):
|
98 | 100 | self.assertEqual(text, "Before\n\nNONE\n\nAfter\n")
|
99 | 101 | self.assert_analysis([1, 2, 3, 5, 7], [3])
|
100 | 102 |
|
| 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 | + |
101 | 137 |
|
102 | 138 | class IfChangedTest(DjangoPluginTestCase):
|
103 | 139 |
|
|
0 commit comments