File: test_resetcycle.py

package info (click to toggle)
python-django 3%3A5.2.5-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 61,236 kB
  • sloc: python: 361,585; javascript: 19,250; xml: 211; makefile: 182; sh: 28
file content (134 lines) | stat: -rw-r--r-- 4,329 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
from django.template import TemplateSyntaxError
from django.test import SimpleTestCase

from ..utils import setup


class ResetCycleTagTests(SimpleTestCase):
    @setup({"resetcycle01": "{% resetcycle %}"})
    def test_resetcycle01(self):
        with self.assertRaisesMessage(TemplateSyntaxError, "No cycles in template."):
            self.engine.get_template("resetcycle01")

    @setup({"resetcycle02": "{% resetcycle undefinedcycle %}"})
    def test_resetcycle02(self):
        with self.assertRaisesMessage(
            TemplateSyntaxError, "Named cycle 'undefinedcycle' does not exist."
        ):
            self.engine.get_template("resetcycle02")

    @setup({"resetcycle03": "{% cycle 'a' 'b' %}{% resetcycle undefinedcycle %}"})
    def test_resetcycle03(self):
        with self.assertRaisesMessage(
            TemplateSyntaxError, "Named cycle 'undefinedcycle' does not exist."
        ):
            self.engine.get_template("resetcycle03")

    @setup({"resetcycle04": "{% cycle 'a' 'b' as ab %}{% resetcycle undefinedcycle %}"})
    def test_resetcycle04(self):
        with self.assertRaisesMessage(
            TemplateSyntaxError, "Named cycle 'undefinedcycle' does not exist."
        ):
            self.engine.get_template("resetcycle04")

    @setup(
        {
            "resetcycle05": (
                "{% for i in test %}{% cycle 'a' 'b' %}{% resetcycle %}{% endfor %}"
            )
        }
    )
    def test_resetcycle05(self):
        output = self.engine.render_to_string("resetcycle05", {"test": list(range(5))})
        self.assertEqual(output, "aaaaa")

    @setup(
        {
            "resetcycle06": "{% cycle 'a' 'b' 'c' as abc %}"
            "{% for i in test %}"
            "{% cycle abc %}"
            "{% cycle '-' '+' %}"
            "{% resetcycle %}"
            "{% endfor %}"
        }
    )
    def test_resetcycle06(self):
        output = self.engine.render_to_string("resetcycle06", {"test": list(range(5))})
        self.assertEqual(output, "ab-c-a-b-c-")

    @setup(
        {
            "resetcycle07": "{% cycle 'a' 'b' 'c' as abc %}"
            "{% for i in test %}"
            "{% resetcycle abc %}"
            "{% cycle abc %}"
            "{% cycle '-' '+' %}"
            "{% endfor %}"
        }
    )
    def test_resetcycle07(self):
        output = self.engine.render_to_string("resetcycle07", {"test": list(range(5))})
        self.assertEqual(output, "aa-a+a-a+a-")

    @setup(
        {
            "resetcycle08": "{% for i in outer %}"
            "{% for j in inner %}"
            "{% cycle 'a' 'b' %}"
            "{% endfor %}"
            "{% resetcycle %}"
            "{% endfor %}"
        }
    )
    def test_resetcycle08(self):
        output = self.engine.render_to_string(
            "resetcycle08", {"outer": list(range(2)), "inner": list(range(3))}
        )
        self.assertEqual(output, "abaaba")

    @setup(
        {
            "resetcycle09": "{% for i in outer %}"
            "{% cycle 'a' 'b' %}"
            "{% for j in inner %}"
            "{% cycle 'X' 'Y' %}"
            "{% endfor %}"
            "{% resetcycle %}"
            "{% endfor %}"
        }
    )
    def test_resetcycle09(self):
        output = self.engine.render_to_string(
            "resetcycle09", {"outer": list(range(2)), "inner": list(range(3))}
        )
        self.assertEqual(output, "aXYXbXYX")

    @setup(
        {
            "resetcycle10": "{% for i in test %}"
            "{% cycle 'X' 'Y' 'Z' as XYZ %}"
            "{% cycle 'a' 'b' 'c' as abc %}"
            "{% if i == 1 %}"
            "{% resetcycle abc %}"
            "{% endif %}"
            "{% endfor %}"
        }
    )
    def test_resetcycle10(self):
        output = self.engine.render_to_string("resetcycle10", {"test": list(range(5))})
        self.assertEqual(output, "XaYbZaXbYc")

    @setup(
        {
            "resetcycle11": "{% for i in test %}"
            "{% cycle 'X' 'Y' 'Z' as XYZ %}"
            "{% cycle 'a' 'b' 'c' as abc %}"
            "{% if i == 1 %}"
            "{% resetcycle XYZ %}"
            "{% endif %}"
            "{% endfor %}"
        }
    )
    def test_resetcycle11(self):
        output = self.engine.render_to_string("resetcycle11", {"test": list(range(5))})
        self.assertEqual(output, "XaYbXcYaZb")