-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathstop_test.py
More file actions
107 lines (89 loc) · 2.04 KB
/
stop_test.py
File metadata and controls
107 lines (89 loc) · 2.04 KB
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
from template import Template, TemplateException
from template.test import TestCase, main
def halt(*args):
raise TemplateException("stop", "big error")
class StopTest(TestCase):
def testStop(self):
ttblocks = {"header": lambda *_: "This is the header\n",
"footer": lambda *_: "This is the footer\n",
"halt1": halt}
ttvars = {"halt": halt}
ttbare = Template({"BLOCKS": ttblocks})
ttwrap = Template({"PRE_PROCESS": "header",
"POST_PROCESS": "footer",
"BLOCKS": ttblocks})
self.Expect(DATA, (("bare", ttbare), ("wrapped", ttwrap)), ttvars)
DATA = r"""
-- test --
This is some text
[% STOP %]
More text
-- expect --
This is some text
-- test --
This is some text
[% halt %]
More text
-- expect --
This is some text
-- test --
This is some text
[% INCLUDE halt1 %]
More text
-- expect --
This is some text
-- test --
This is some text
[% INCLUDE myblock1 %]
More text
[% BLOCK myblock1 -%]
This is myblock1
[% STOP %]
more of myblock1
[% END %]
-- expect --
This is some text
This is myblock1
-- test --
This is some text
[% INCLUDE myblock2 %]
More text
[% BLOCK myblock2 -%]
This is myblock2
[% halt %]
more of myblock2
[% END %]
-- expect --
This is some text
This is myblock2
#------------------------------------------------------------------------
# ensure 'stop' exceptions get ignored by TRY...END blocks
#------------------------------------------------------------------------
-- test --
before
[% TRY -%]
trying
[% STOP -%]
tried
[% CATCH -%]
caught [[% error.type %]] - [% error.info %]
[% END %]
after
-- expect --
before
trying
#------------------------------------------------------------------------
# ensure PRE_PROCESS and POST_PROCESS templates get added with STOP
#------------------------------------------------------------------------
-- test --
-- use wrapped --
This is some text
[% STOP %]
More text
-- expect --
This is the header
This is some text
This is the footer
"""
if __name__ == '__main__':
main()