4 #from py.test import raises
5 from tiramisu.config import Config
6 from tiramisu.option import StrOption, UnicodeOption, OptionDescription
7 from tiramisu.error import PropertiesOptionError
10 def make_description():
11 stroption = StrOption('str', 'Test string option', default="abc",
12 properties=('mandatory', ))
13 stroption1 = StrOption('str1', 'Test string option',
14 properties=('mandatory', ))
15 stroption2 = UnicodeOption('unicode2', 'Test string option',
16 properties=('mandatory', ))
17 stroption3 = StrOption('str3', 'Test string option', multi=True,
18 properties=('mandatory', ))
19 descr = OptionDescription('tiram', '', [stroption, stroption1, stroption2, stroption3])
23 def test_mandatory_ro():
24 descr = make_description()
25 config = Config(descr)
30 except PropertiesOptionError as err:
32 assert 'mandatory' in prop
36 assert config.str1 == 'yes'
39 def test_mandatory_rw():
40 descr = make_description()
41 config = Config(descr)
46 assert config.str1 == 'yes'
49 def test_mandatory_default():
50 descr = make_description()
51 config = Config(descr)
65 except PropertiesOptionError as err:
67 assert 'mandatory' in prop
70 #valeur vide : None, '', u'', ...
71 def test_mandatory_none():
72 descr = make_description()
73 config = Config(descr)
75 assert config.getowner(config.unwrap_from_path('str1')) == 'user'
80 except PropertiesOptionError as err:
82 assert 'mandatory' in prop
85 def test_mandatory_empty():
86 descr = make_description()
87 config = Config(descr)
89 assert config.getowner(config.unwrap_from_path('str1')) == 'user'
94 except PropertiesOptionError as err:
96 assert 'mandatory' in prop
99 def test_mandatory_multi_none():
100 descr = make_description()
101 config = Config(descr)
103 assert config.getowner(config.unwrap_from_path('str3')) == 'user'
108 except PropertiesOptionError as err:
110 assert 'mandatory' in prop
112 config.str3 = ['yes', None]
113 assert config.getowner(config.unwrap_from_path('str3')) == 'user'
118 except PropertiesOptionError as err:
120 assert 'mandatory' in prop
123 def test_mandatory_multi_empty():
124 descr = make_description()
125 config = Config(descr)
127 assert config.getowner(config.unwrap_from_path('str3')) == 'user'
132 except PropertiesOptionError as err:
134 assert 'mandatory' in prop
136 config.str3 = ['yes', '']
137 assert config.getowner(config.unwrap_from_path('str3')) == 'user'
142 except PropertiesOptionError as err:
144 assert 'mandatory' in prop
147 def test_mandatory_multi_append():
148 descr = make_description()
149 config = Config(descr)
150 config.str3 = ['yes']
152 config.str3.append(None)
155 def test_mandatory_disabled():
156 descr = make_description()
157 config = Config(descr)
158 setting = config.cfgimpl_get_settings()
164 except PropertiesOptionError as err:
166 assert prop == ['mandatory']
167 setting[descr.str1].append('disabled')
171 except PropertiesOptionError as err:
173 assert set(prop) == set(['disabled', 'mandatory'])
176 def test_mandatory_unicode():
177 descr = make_description()
178 config = Config(descr)
184 except PropertiesOptionError as err:
186 assert prop == ['mandatory']
188 config.unicode2 = u''
193 except PropertiesOptionError as err:
195 assert prop == ['mandatory']
198 def test_mandatory_warnings_ro():
199 descr = make_description()
200 config = Config(descr)
206 except PropertiesOptionError as err:
208 assert proc == ['mandatory']
209 assert config.cfgimpl_get_values().mandatory_warnings() == ['str', 'str1', 'unicode2', 'str3']
213 assert config.cfgimpl_get_values().mandatory_warnings() == ['str1', 'unicode2', 'str3']
217 def test_mandatory_warnings_rw():
218 descr = make_description()
219 config = Config(descr)
223 assert config.cfgimpl_get_values().mandatory_warnings() == ['str', 'str1', 'unicode2', 'str3']
225 assert config.cfgimpl_get_values().mandatory_warnings() == ['str1', 'unicode2', 'str3']
229 def test_mandatory_warnings_disabled():
230 descr = make_description()
231 config = Config(descr)
233 setting = config.cfgimpl_get_settings()
236 assert config.cfgimpl_get_values().mandatory_warnings() == ['str', 'str1', 'unicode2', 'str3']
237 setting[descr.str].append('disabled')
238 assert config.cfgimpl_get_values().mandatory_warnings() == ['str1', 'unicode2', 'str3']
242 def test_mandatory_warnings_frozen():
243 descr = make_description()
244 config = Config(descr)
246 setting = config.cfgimpl_get_settings()
249 assert config.cfgimpl_get_values().mandatory_warnings() == ['str', 'str1', 'unicode2', 'str3']
250 setting[descr.str].append('frozen')
252 assert config.cfgimpl_get_values().mandatory_warnings() == ['str', 'str1', 'unicode2', 'str3']