-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathblock_test.py
More file actions
109 lines (91 loc) · 2.07 KB
/
block_test.py
File metadata and controls
109 lines (91 loc) · 2.07 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
108
109
from template.test import TestCase, main
class BlockTest(TestCase):
def testBlock(self):
ttcfg = {
'INCLUDE_PATH': ['test/lib'],
'POST_CHOMP': 1,
'BLOCKS': {
'header': '<html><head><title>[% title %]</title></head><body>',
'footer': '</body></html>',
'block_a': lambda *_: 'this is block a',
'block_b': lambda *_: 'this is block b',
}
}
self.Expect(DATA, ttcfg, self._callsign())
DATA = r"""[% BLOCK block1 %]
This is the original block1
[% END %]
[% INCLUDE block1 %]
[% INCLUDE blockdef %]
[% INCLUDE block1 %]
-- expect --
This is the original block1
start of blockdef
end of blockdef
This is the original block1
-- test --
[% BLOCK block1 %]
This is the original block1
[% END %]
[% INCLUDE block1 %]
[% PROCESS blockdef %]
[% INCLUDE block1 %]
-- expect --
This is the original block1
start of blockdef
end of blockdef
This is block 1, defined in blockdef, a is alpha
-- test --
[% INCLUDE block_a +%]
[% INCLUDE block_b %]
-- expect --
this is block a
this is block b
-- test --
[% INCLUDE header
title = 'A New Beginning'
+%]
A long time ago in a galaxy far, far away...
[% PROCESS footer %]
-- expect --
<html><head><title>A New Beginning</title></head><body>
A long time ago in a galaxy far, far away...
</body></html>
-- test --
[% BLOCK foo:bar %]
blah
[% END %]
[% PROCESS foo:bar %]
-- expect --
blah
-- test --
[% BLOCK 'hello html' -%]
Hello World!
[% END -%]
[% PROCESS 'hello html' %]
-- expect --
Hello World!
-- test --
<[% INCLUDE foo %]>
[% BLOCK foo %][% END %]
-- expect --
<>
-- stop --
# these test the experimental BLOCK args feature which will hopefully allow
# parser/eval options to be set for different blocks
-- test --
[% BLOCK foo eval_python=0 tags="star" -%]
This is the foo block
[% END -%]
foo: [% INCLUDE foo %]
-- expect --
foo: This is the foo block
-- test --
[% BLOCK eval_python=0 tags="star" -%]
This is an anonymous block
[% END -%]
-- expect --
This is an anonymous block
"""
if __name__ == '__main__':
main()