]> mj.ucw.cz Git - moe.git/blob - t/moe/conf.test.py
New module for config evaluation. Basic testing.
[moe.git] / t / moe / conf.test.py
1 import conf
2 import logging as log
3 log.getLogger().setLevel(log.DEBUG)
4
5 vcnt = 3
6
7 def cs(s):
8   return conf.ConfigExpression([s], s)
9
10 root = conf.ConfigTree(None, None)
11 t_a = conf.ConfigTree('a', root)
12 t_a_b = conf.ConfigTree('b', t_a)
13 t_c = conf.ConfigTree('c', root)
14
15 v_r = conf.ConfigVar('r', root)
16 v_r.add_operation('SET', [], cs('ROOTVAR'))
17
18 v_a = []
19 v_b = []
20 for i in range(vcnt):
21   v_a.append(conf.ConfigVar('va%d'%i, t_a))
22   v_a[i].add_operation('SET', [], cs('VALUE-A%d'%i))
23
24   v_b.append(conf.ConfigVar('vb%d'%i, t_a_b))
25   v_b[i].add_operation('APPEND', [], cs(' FOO'))
26   v_b[i].add_operation('SET', [], conf.ConfigExpression([v_a[i]], '{va%d}'%i))
27   v_b[i].add_operation('APPEND', [], cs(' BAR'))
28   if i>0: 
29     v_b[i].add_operation('APPEND', [], conf.ConfigExpression([' ', v_b[i-1]], ' {vb%d}'%(i-1)))
30 print '\n'.join(root.pprint())
31
32 v_b[0].remove_operation(1)
33 v_b[0].add_operation('SET', [], cs('NEW-VALUE'))
34 v_b[1].add_operation('APPEND', [], cs(' NEW-ADDED'))
35 v_a[1].add_operation('APPEND', [], cs(' NEW-ADDED-A'))
36 print '\n'.join(root.pprint())
37
38 v_a[0].add_operation('SET', [], cs('NEW-VALUE-A0'))
39 print '\n'.join(root.pprint())