-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathfactory_test.py
More file actions
36 lines (27 loc) · 811 Bytes
/
factory_test.py
File metadata and controls
36 lines (27 loc) · 811 Bytes
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
from template.directive import Directive
from template.test import TestCase, main
class MyDirective(Directive):
constants = {'pi': 3.14, 'e': 2.718}
def ident(self, ident):
if isinstance(ident, (tuple, list)) and ident[0] == "'constant'":
key = ident[2].replace("'", "")
return self.constants.get(key, "")
return Directive.ident(self, ident)
class FactoryTest(TestCase):
def testFactory(self):
cfg = {'FACTORY': MyDirective}
vars = {'foo': {'bar': 'Place to purchase drinks',
'baz': 'Short form of "Basil"'}}
self.Expect(DATA, cfg, vars)
DATA = r"""
-- test --
[% foo.bar %]
-- expect --
Place to purchase drinks
-- test --
[% constant.pi %]
-- expect --
3.14
"""
if __name__ == '__main__':
main()