key is now always path and change opt by path dictionary storage
[tiramisu.git] / test / test_permissive.py
1 # coding: utf-8
2 import autopath
3 from tiramisu.option import IntOption, OptionDescription
4 from tiramisu.config import Config
5 from tiramisu.error import PropertiesOptionError
6
7
8 def make_description():
9     u1 = IntOption('u1', '', properties=('frozen', 'mandatory', 'disabled', ))
10     return OptionDescription('od1', '', [u1])
11
12
13 def test_permissive():
14     descr = make_description()
15     config = Config(descr)
16     setting = config.cfgimpl_get_settings()
17     config.read_write()
18     props = []
19     try:
20         config.u1
21     except PropertiesOptionError, err:
22         props = err.proptype
23     assert props == ['disabled']
24     setting.setpermissive(('disabled',))
25     props = []
26     try:
27         config.u1
28     except PropertiesOptionError, err:
29         props = err.proptype
30     assert props == ['disabled']
31     setting.append('permissive')
32     config.u1
33     setting.remove('permissive')
34     props = []
35     try:
36         config.u1
37     except PropertiesOptionError, err:
38         props = err.proptype
39     assert props == ['disabled']
40
41
42 def test_permissive_mandatory():
43     descr = make_description()
44     config = Config(descr)
45     setting = config.cfgimpl_get_settings()
46     config.read_only()
47     props = []
48     try:
49         config.u1
50     except PropertiesOptionError, err:
51         props = err.proptype
52     assert props == ['disabled', 'mandatory']
53     setting.setpermissive(('mandatory', 'disabled',))
54     setting.append('permissive')
55     config.u1
56     setting.remove('permissive')
57     try:
58         config.u1
59     except PropertiesOptionError, err:
60         props = err.proptype
61     assert props == ['disabled', 'mandatory']
62
63
64 def test_permissive_frozen():
65     descr = make_description()
66     config = Config(descr)
67     setting = config.cfgimpl_get_settings()
68     config.read_write()
69     setting.setpermissive(('frozen', 'disabled',))
70     try:
71         config.u1 = 1
72     except PropertiesOptionError, err:
73         props = err.proptype
74     assert props == ['frozen', 'disabled']
75     setting.append('permissive')
76     config.u1 = 1
77     assert config.u1 == 1
78     setting.remove('permissive')
79     try:
80         config.u1 = 1
81     except PropertiesOptionError, err:
82         props = err.proptype
83     assert props == ['frozen', 'disabled']