2 from py.test import raises
4 from tiramisu.setting import groups
5 from tiramisu.config import Config
6 from tiramisu.option import ChoiceOption, BoolOption, IntOption, FloatOption, \
7 StrOption, OptionDescription, SymLinkOption
8 from tiramisu.error import PropertiesOptionError, ConflictError, SlaveError, ConfigError
15 def return_concat(*args):
16 return '.'.join(list(args))
19 def return_list(value=None):
23 def return_list2(*args):
26 if isinstance(arg, list):
33 def return_value(value=None):
37 def return_value2(*args, **kwargs):
39 value.extend(kwargs.values())
43 def return_calc(i, j, k):
47 def make_description():
48 gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
49 gcdummy = BoolOption('dummy', 'dummy', default=False)
50 objspaceoption = ChoiceOption('objspace', 'Object space',
51 ('std', 'thunk'), 'std')
52 booloption = BoolOption('bool', 'Test boolean option', default=True)
53 intoption = IntOption('int', 'Test int option', default=0)
54 intoption2 = IntOption('int', 'Test int option', default=0)
55 floatoption = FloatOption('float', 'Test float option', default=2.3)
56 stroption = StrOption('str', 'Test string option', default="abc")
57 boolop = BoolOption('boolop', 'Test boolean option op', default=True)
58 wantref_option = BoolOption('wantref', 'Test requires', default=False,
59 requires=({'option': boolop, 'expected': True, 'action': 'hidden'},))
60 wantframework_option = BoolOption('wantframework', 'Test requires',
62 requires=({'option': boolop, 'expected': True, 'action': 'hidden'},))
63 gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption, intoption2])
64 descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
65 wantref_option, stroption,
71 def make_description_duplicates():
72 gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
74 gcdummy = BoolOption('dummy', 'dummy', default=False)
75 objspaceoption = ChoiceOption('objspace', 'Object space',
76 ('std', 'thunk'), 'std')
77 booloption = BoolOption('bool', 'Test boolean option', default=True)
78 intoption = IntOption('int', 'Test int option', default=0)
79 floatoption = FloatOption('float', 'Test float option', default=2.3)
80 stroption = StrOption('str', 'Test string option', default="abc")
81 boolop = BoolOption('boolop', 'Test boolean option op', default=True)
82 wantref_option = BoolOption('wantref', 'Test requires', default=False,
83 requires=({'option': boolop, 'expected': True, 'action': 'hidden'},))
84 wantframework_option = BoolOption('wantframework', 'Test requires',
86 requires=({'option': boolop, 'expected': True, 'action': 'hidden'},))
88 gcdummy2 = BoolOption('dummy', 'dummy2', default=True)
90 gcdummy3 = BoolOption('dummy', 'dummy2', default=True)
91 gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, gcdummy2, floatoption])
92 descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
93 wantref_option, stroption,
95 intoption, boolop, gcdummy3])
99 def test_identical_paths():
100 """If in the schema (the option description) there is something that
101 have the same name, an exection is raised
103 raises(ConflictError, "make_description_duplicates()")
106 def make_description_requires():
107 gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
108 gcdummy = BoolOption('dummy', 'dummy', default=False)
110 floatoption = FloatOption('float', 'Test float option', default=2.3)
112 objspaceoption = ChoiceOption('objspace', 'Object space',
113 ('std', 'thunk'), 'std')
114 booloption = BoolOption('bool', 'Test boolean option', default=True)
115 intoption = IntOption('int', 'Test int option', default=0)
116 stroption = StrOption('str', 'Test string option', default="abc",
117 requires=({'option': intoption, 'expected': 1, 'action': 'hidden'},))
119 gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
120 descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
121 stroption, intoption])
125 def test_hidden_if_in():
126 descr = make_description_requires()
128 setting = cfg.cfgimpl_get_settings()
130 stroption = cfg.unwrap_from_path('str')
131 assert not 'hidden' in setting[stroption]
133 raises(PropertiesOptionError, "cfg.str")
134 raises(PropertiesOptionError, 'cfg.str="uvw"')
135 assert 'hidden' in setting[stroption]
138 def test_hidden_if_in_with_group():
139 gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
140 gcdummy = BoolOption('dummy', 'dummy', default=False)
142 floatoption = FloatOption('float', 'Test float option', default=2.3)
144 objspaceoption = ChoiceOption('objspace', 'Object space',
145 ('std', 'thunk'), 'std')
146 booloption = BoolOption('bool', 'Test boolean option', default=True)
147 intoption = IntOption('int', 'Test int option', default=0)
148 stroption = StrOption('str', 'Test string option', default="abc")
149 gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption],
150 requires=({'option': intoption, 'expected': 1, 'action': 'hidden'},))
151 descr = OptionDescription('constraints', '', [gcgroup, booloption,
152 objspaceoption, stroption, intoption])
154 setting = cfg.cfgimpl_get_settings()
156 assert not 'hidden' in setting[stroption]
158 raises(PropertiesOptionError, "cfg.gc.name")
161 def test_disabled_with_group():
162 gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
163 gcdummy = BoolOption('dummy', 'dummy', default=False)
165 floatoption = FloatOption('float', 'Test float option', default=2.3)
167 objspaceoption = ChoiceOption('objspace', 'Object space',
168 ('std', 'thunk'), 'std')
169 booloption = BoolOption('bool', 'Test boolean option', default=True)
170 intoption = IntOption('int', 'Test int option', default=0)
171 stroption = StrOption('str', 'Test string option', default="abc")
172 gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption],
173 requires=({'option': intoption, 'expected': 1, 'action': 'disabled'},))
174 descr = OptionDescription('constraints', '', [gcgroup, booloption,
175 objspaceoption, stroption, intoption])
180 raises(PropertiesOptionError, "cfg.gc.name")
181 #____________________________________________________________
184 def make_description_callback():
185 gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
186 gcdummy = BoolOption('dummy', 'dummy')
187 objspaceoption = ChoiceOption('objspace', 'Object space',
188 ('std', 'thunk'), 'std')
189 booloption = BoolOption('bool', 'Test boolean option', default=True)
190 intoption = IntOption('int', 'Test int option', default=0)
191 floatoption = FloatOption('float', 'Test float option', default=2.3)
192 stroption = StrOption('str', 'Test string option', default="abc")
193 boolop = BoolOption('boolop', 'Test boolean option op', default=True)
194 wantref_option = BoolOption('wantref', 'Test requires', default=False,
195 requires=({'option': boolop, 'expected': True, 'action': 'hidden'},))
196 wantframework_option = BoolOption('wantframework', 'Test requires',
198 requires=({'option': boolop, 'expected': True, 'action': 'hidden'},))
199 gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
200 descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
201 wantref_option, stroption,
202 wantframework_option,
207 def test_has_callback():
208 descr = make_description_callback()
209 # here the owner is 'default'
210 config = Config(descr)
211 setting = config.cfgimpl_get_settings()
214 # because dummy has a callback
215 dummy = config.unwrap_from_path('gc.dummy')
216 setting.append('freeze')
217 setting[dummy].append('frozen')
218 raises(PropertiesOptionError, "config.gc.dummy = True")
221 def test_freeze_and_has_callback():
222 descr = make_description_callback()
223 config = Config(descr)
224 setting = config.cfgimpl_get_settings()
227 setting = config.cfgimpl_get_settings()
228 setting.append('freeze')
229 dummy = config.unwrap_from_path('gc.dummy')
230 setting[dummy].append('frozen')
231 raises(PropertiesOptionError, "config.gc.dummy = True")
235 val1 = StrOption('val1', "", callback=return_val)
236 maconfig = OptionDescription('rootconfig', '', [val1])
237 cfg = Config(maconfig)
239 assert cfg.val1 == 'val'
241 assert cfg.val1 == 'new-val'
243 assert cfg.val1 == 'val'
246 def test_callback_params_without_callback():
247 raises(ValueError, "StrOption('val2', '', callback_params={'': ('yes',)})")
250 def test_callback_invalid():
251 raises(ValueError, 'val1 = StrOption("val1", "", callback="string")')
252 raises(ValueError, 'val1 = StrOption("val1", "", callback=return_val, callback_params="string")')
253 val1 = StrOption('val1', "", 'val')
254 raises(ValueError, "StrOption('val2', '', callback=return_value, callback_params={'': 'string'})")
255 raises(ValueError, "StrOption('val4', '', callback=return_value, callback_params={'value': (('string', False),)})")
256 raises(ValueError, "StrOption('val4', '', callback=return_value, callback_params={'value': ((val1, 'string'),)})")
259 def test_callback_value():
260 val1 = StrOption('val1', "", 'val')
261 val2 = StrOption('val2', "", callback=return_value, callback_params={'': ((val1, False),)})
262 val3 = StrOption('val3', "", callback=return_value, callback_params={'': ('yes',)})
263 val4 = StrOption('val4', "", callback=return_value, callback_params={'value': ((val1, False),)})
264 val5 = StrOption('val5', "", callback=return_value, callback_params={'value': ('yes',)})
265 maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4, val5])
266 cfg = Config(maconfig)
268 assert cfg.val1 == 'val'
269 assert cfg.val2 == 'val'
270 assert cfg.val4 == 'val'
272 assert cfg.val1 == 'new-val'
273 assert cfg.val2 == 'new-val'
274 assert cfg.val4 == 'new-val'
276 assert cfg.val1 == 'val'
277 assert cfg.val2 == 'val'
278 assert cfg.val3 == 'yes'
279 assert cfg.val4 == 'val'
280 assert cfg.val5 == 'yes'
283 def test_callback_value_tuple():
284 val1 = StrOption('val1', "", 'val1')
285 val2 = StrOption('val2', "", 'val2')
286 val3 = StrOption('val3', "", callback=return_concat, callback_params={'': ((val1, False), (val2, False))})
287 val4 = StrOption('val4', "", callback=return_concat, callback_params={'': ('yes', 'no')})
288 raises(ValueError, "StrOption('val4', '', callback=return_concat, callback_params={'value': ('yes', 'no')})")
289 maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4])
290 cfg = Config(maconfig)
292 assert cfg.val1 == 'val1'
293 assert cfg.val2 == 'val2'
294 assert cfg.val3 == 'val1.val2'
295 assert cfg.val4 == 'yes.no'
297 assert cfg.val3 == 'new-val.val2'
299 assert cfg.val3 == 'val1.val2'
302 def test_callback_value_force_permissive():
303 val1 = StrOption('val1', "", 'val', properties=('disabled',))
304 val2 = StrOption('val2', "", callback=return_value, callback_params={'': ((val1, False),)})
305 val3 = StrOption('val3', "", callback=return_value, callback_params={'': ((val1, True),)})
306 maconfig = OptionDescription('rootconfig', '', [val1, val2, val3])
307 cfg = Config(maconfig)
309 raises(ConfigError, "cfg.val2")
310 assert cfg.val3 is None
313 def test_callback_symlink():
314 val1 = StrOption('val1', "", 'val')
315 val2 = SymLinkOption('val2', val1)
316 val3 = StrOption('val3', "", callback=return_value, callback_params={'': ((val2, False),)})
317 maconfig = OptionDescription('rootconfig', '', [val1, val2, val3])
318 cfg = Config(maconfig)
320 assert cfg.val1 == 'val'
321 assert cfg.val2 == 'val'
322 assert cfg.val3 == 'val'
324 assert cfg.val1 == 'new-val'
325 assert cfg.val3 == 'new-val'
327 assert cfg.val1 == 'val'
328 assert cfg.val3 == 'val'
331 def test_callback_list():
332 val1 = StrOption('val1', "", callback=return_list)
333 maconfig = OptionDescription('rootconfig', '', [val1])
334 cfg = Config(maconfig)
336 raises(ValueError, "cfg.val1")
339 def test_callback_multi():
340 val1 = StrOption('val1', "", callback=return_val, multi=True)
341 maconfig = OptionDescription('rootconfig', '', [val1])
342 cfg = Config(maconfig)
344 assert cfg.val1 == ['val']
345 cfg.val1 = ['new-val']
346 assert cfg.val1 == ['new-val']
347 cfg.val1.append('new-val2')
348 assert cfg.val1 == ['new-val', 'new-val2']
350 assert cfg.val1 == ['val']
353 def test_callback_multi_value():
354 val1 = StrOption('val1', "", ['val'], multi=True)
355 val2 = StrOption('val2', "", multi=True, callback=return_value, callback_params={'': ((val1, False),)})
356 val3 = StrOption('val3', "", multi=True, callback=return_value, callback_params={'': ('yes',)})
357 val4 = StrOption('val4', "", multi=True, callback=return_list2, callback_params={'': ((val1, False), 'yes')})
358 maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4])
359 cfg = Config(maconfig)
361 assert cfg.val1 == ['val']
362 assert cfg.val2 == ['val']
363 assert cfg.val4 == ['val', 'yes']
364 cfg.val1 = ['new-val']
365 assert cfg.val1 == ['new-val']
366 assert cfg.val2 == ['new-val']
367 assert cfg.val4 == ['new-val', 'yes']
368 cfg.val1.append('new-val2')
369 assert cfg.val1 == ['new-val', 'new-val2']
370 assert cfg.val2 == ['new-val', 'new-val2']
371 assert cfg.val4 == ['new-val', 'new-val2', 'yes']
373 assert cfg.val1 == ['val']
374 assert cfg.val2 == ['val']
375 assert cfg.val3 == ['yes']
376 assert cfg.val4 == ['val', 'yes']
379 def test_callback_multi_list():
380 val1 = StrOption('val1', "", callback=return_list, multi=True)
381 maconfig = OptionDescription('rootconfig', '', [val1])
382 cfg = Config(maconfig)
384 assert cfg.val1 == ['val', 'val']
385 cfg.val1 = ['new-val']
386 assert cfg.val1 == ['new-val']
387 cfg.val1.append('new-val2')
388 assert cfg.val1 == ['new-val', 'new-val2']
390 assert cfg.val1 == ['val', 'val']
393 def test_callback_multi_list_extend():
394 val1 = StrOption('val1', "", callback=return_list2, callback_params={'': (['1', '2', '3'], ['4', '5'])}, multi=True)
395 maconfig = OptionDescription('rootconfig', '', [val1])
396 cfg = Config(maconfig)
398 assert cfg.val1 == ['1', '2', '3', '4', '5']
401 def test_callback_master_and_slaves_master():
402 val1 = StrOption('val1', "", multi=True, callback=return_val)
403 val2 = StrOption('val2', "", multi=True)
404 interface1 = OptionDescription('val1', '', [val1, val2])
405 interface1.impl_set_group_type(groups.master)
406 maconfig = OptionDescription('rootconfig', '', [interface1])
407 cfg = Config(maconfig)
409 assert cfg.val1.val1 == ['val']
410 cfg.val1.val1.append()
411 assert cfg.val1.val1 == ['val', 'val']
412 assert cfg.val1.val2 == [None, None]
415 def test_callback_master_and_slaves_master_list():
416 val1 = StrOption('val1', "", multi=True, callback=return_list)
417 val2 = StrOption('val2', "", multi=True)
418 interface1 = OptionDescription('val1', '', [val1, val2])
419 interface1.impl_set_group_type(groups.master)
420 maconfig = OptionDescription('rootconfig', '', [interface1])
421 cfg = Config(maconfig)
423 assert cfg.val1.val1 == ['val', 'val']
424 assert cfg.val1.val2 == [None, None]
425 cfg.val1.val1.append()
426 assert cfg.val1.val1 == ['val', 'val', None]
427 assert cfg.val1.val2 == [None, None, None]
429 assert cfg.val1.val1 == ['val', 'val']
430 assert cfg.val1.val2 == [None, None]
431 assert cfg.val1.val1.pop(1)
432 assert cfg.val1.val1 == ['val']
433 assert cfg.val1.val2 == [None]
436 def test_callback_master_and_slaves_slave():
437 val1 = StrOption('val1', "", multi=True)
438 val2 = StrOption('val2', "", multi=True, callback=return_val)
439 interface1 = OptionDescription('val1', '', [val1, val2])
440 interface1.impl_set_group_type(groups.master)
441 maconfig = OptionDescription('rootconfig', '', [interface1])
442 cfg = Config(maconfig)
444 assert cfg.val1.val1 == []
445 assert cfg.val1.val2 == []
447 cfg.val1.val1 = ['val1']
448 assert cfg.val1.val1 == ['val1']
449 assert cfg.val1.val2 == ['val']
451 cfg.val1.val1.append('val2')
452 assert cfg.val1.val1 == ['val1', 'val2']
453 assert cfg.val1.val2 == ['val', 'val']
455 cfg.val1.val1 = ['val1', 'val2', 'val3']
456 assert cfg.val1.val1 == ['val1', 'val2', 'val3']
457 assert cfg.val1.val2 == ['val', 'val', 'val']
460 assert cfg.val1.val1 == ['val1', 'val2']
461 assert cfg.val1.val2 == ['val', 'val']
463 cfg.val1.val2 = ['val2', 'val2']
464 assert cfg.val1.val2 == ['val2', 'val2']
466 cfg.val1.val1.append('val3')
467 assert cfg.val1.val2 == ['val2', 'val2', 'val']
470 def test_callback_master_and_slaves_slave_list():
471 val1 = StrOption('val1', "", multi=True)
472 val2 = StrOption('val2', "", multi=True, callback=return_list)
473 interface1 = OptionDescription('val1', '', [val1, val2])
474 interface1.impl_set_group_type(groups.master)
475 maconfig = OptionDescription('rootconfig', '', [interface1])
476 cfg = Config(maconfig)
478 assert cfg.val1.val2 == []
479 cfg.val1.val1 = ['val1', 'val2']
480 assert cfg.val1.val1 == ['val1', 'val2']
481 assert cfg.val1.val2 == ['val', 'val']
482 cfg.val1.val1 = ['val1']
485 raises(SlaveError, 'cfg.val1.val2')
488 def test_callback_master_and_slaves_value():
489 val1 = StrOption('val1', "", multi=True)
490 val2 = StrOption('val2', "", multi=True, callback=return_value, callback_params={'': ((val1, False),)})
491 val3 = StrOption('val3', "", multi=True, callback=return_value, callback_params={'': ('yes',)})
492 val4 = StrOption('val4', '', multi=True, default=['val10', 'val11'])
493 val5 = StrOption('val5', "", multi=True, callback=return_value, callback_params={'': ((val4, False),)})
494 val6 = StrOption('val6', "", multi=True, callback=return_value, callback_params={'': ((val5, False),)})
495 interface1 = OptionDescription('val1', '', [val1, val2, val3, val5, val6])
496 interface1.impl_set_group_type(groups.master)
497 maconfig = OptionDescription('rootconfig', '', [interface1, val4])
498 cfg = Config(maconfig)
500 assert cfg.val1.val1 == []
501 assert cfg.val1.val2 == []
502 assert cfg.val1.val3 == []
503 assert cfg.val1.val5 == []
504 assert cfg.val1.val6 == []
506 cfg.val1.val1 = ['val1']
507 assert cfg.val1.val1 == ['val1']
508 assert cfg.val1.val2 == ['val1']
509 assert cfg.val1.val3 == ['yes']
510 assert cfg.val1.val5 == ['val10']
511 assert cfg.val1.val6 == ['val10']
513 cfg.val1.val1.append('val2')
514 assert cfg.val1.val1 == ['val1', 'val2']
515 assert cfg.val1.val2 == ['val1', 'val2']
516 assert cfg.val1.val3 == ['yes', 'yes']
517 assert cfg.val1.val5 == ['val10', 'val11']
518 assert cfg.val1.val6 == ['val10', 'val11']
520 cfg.val1.val1 = ['val1', 'val2', 'val3']
521 assert cfg.val1.val1 == ['val1', 'val2', 'val3']
522 assert cfg.val1.val2 == ['val1', 'val2', 'val3']
523 assert cfg.val1.val3 == ['yes', 'yes', 'yes']
524 assert cfg.val1.val5 == ['val10', 'val11', None]
525 assert cfg.val1.val6 == ['val10', 'val11', None]
528 assert cfg.val1.val1 == ['val1', 'val2']
529 assert cfg.val1.val2 == ['val1', 'val2']
530 assert cfg.val1.val3 == ['yes', 'yes']
531 assert cfg.val1.val5 == ['val10', 'val11']
532 assert cfg.val1.val6 == ['val10', 'val11']
534 cfg.val1.val2 = ['val2', 'val2']
535 cfg.val1.val3 = ['val2', 'val2']
536 cfg.val1.val5 = ['val2', 'val2']
537 assert cfg.val1.val2 == ['val2', 'val2']
538 assert cfg.val1.val3 == ['val2', 'val2']
539 assert cfg.val1.val5 == ['val2', 'val2']
540 assert cfg.val1.val6 == ['val2', 'val2']
542 cfg.val1.val1.append('val3')
543 assert cfg.val1.val2 == ['val2', 'val2', 'val3']
544 assert cfg.val1.val3 == ['val2', 'val2', 'yes']
545 assert cfg.val1.val5 == ['val2', 'val2', None]
546 assert cfg.val1.val6 == ['val2', 'val2', None]
547 cfg.cfgimpl_get_settings().remove('cache')
548 cfg.val4 = ['val10', 'val11', 'val12']
549 #if value is already set, not updated !
551 cfg.val1.val1.append('val3')
552 cfg.val1.val1 = ['val1', 'val2', 'val3']
553 assert cfg.val1.val5 == ['val2', 'val2', 'val12']
554 assert cfg.val1.val6 == ['val2', 'val2', 'val12']
557 def test_callback_master():
558 val2 = StrOption('val2', "", multi=True, callback=return_value)
559 val1 = StrOption('val1', "", multi=True, callback=return_value, callback_params={'': ((val2, False),)})
560 interface1 = OptionDescription('val1', '', [val1, val2])
561 raises(ValueError, "interface1.impl_set_group_type(groups.master)")
564 def test_callback_master_and_other_master_slave():
565 val1 = StrOption('val1', "", multi=True)
566 val2 = StrOption('val2', "", multi=True)
567 val3 = StrOption('val3', "", multi=True)
568 val4 = StrOption('val4', '', multi=True, default=['val10', 'val11'])
569 val5 = StrOption('val5', "", multi=True, callback=return_value, callback_params={'': ((val1, False),)})
570 val6 = StrOption('val6', "", multi=True, callback=return_value, callback_params={'': ((val2, False),)})
571 interface1 = OptionDescription('val1', '', [val1, val2, val3])
572 interface1.impl_set_group_type(groups.master)
573 interface2 = OptionDescription('val4', '', [val4, val5, val6])
574 interface2.impl_set_group_type(groups.master)
575 maconfig = OptionDescription('rootconfig', '', [interface1, interface2])
576 cfg = Config(maconfig)
578 assert cfg.val4.val4 == ['val10', 'val11']
579 assert cfg.val4.val5 == [None, None]
580 assert cfg.val4.val6 == [None, None]
581 cfg.val1.val1 = ['yes']
582 assert cfg.val4.val4 == ['val10', 'val11']
583 assert cfg.val4.val5 == ['yes', None]
584 assert cfg.val4.val6 == [None, None]
585 cfg.val1.val2 = ['no']
586 assert cfg.val4.val4 == ['val10', 'val11']
587 assert cfg.val4.val5 == ['yes', None]
588 assert cfg.val4.val6 == ['no', None]
589 cfg.val1.val1 = ['yes', 'yes', 'yes']
590 cfg.val1.val2 = ['no', 'no', 'no']
591 assert cfg.val4.val4 == ['val10', 'val11']
592 assert cfg.val4.val5 == ['yes', 'yes']
593 assert cfg.val4.val6 == ['no', 'no']
596 def test_callback_different_type():
597 val = IntOption('val', "", default=2)
598 val_ = IntOption('val_', "", default=3)
599 val1 = IntOption('val1', "", multi=True)
600 val2 = IntOption('val2', "", multi=True, callback=return_calc, callback_params={'': ((val, False), (val1, False)), 'k': ((val_, False),)})
601 interface1 = OptionDescription('val1', '', [val1, val2])
602 interface1.impl_set_group_type(groups.master)
603 maconfig = OptionDescription('rootconfig', '', [interface1, val, val_])
604 cfg = Config(maconfig)
606 assert cfg.val1.val1 == []
607 assert cfg.val1.val2 == []
609 assert cfg.val1.val1 == [1]
610 assert cfg.val1.val2 == [6]
611 cfg.val1.val1 = [1, 3]
612 assert cfg.val1.val1 == [1, 3]
613 assert cfg.val1.val2 == [6, 8]
614 cfg.val1.val1 = [1, 3, 5]
615 assert cfg.val1.val1 == [1, 3, 5]
616 assert cfg.val1.val2 == [6, 8, 10]
619 def test_callback_hidden():
620 opt1 = BoolOption('opt1', '')
621 opt2 = BoolOption('opt2', '', callback=return_value, callback_params={'': ((opt1, False),)})
622 od1 = OptionDescription('od1', '', [opt1], properties=('hidden',))
623 od2 = OptionDescription('od2', '', [opt2])
624 maconfig = OptionDescription('rootconfig', '', [od1, od2])
625 cfg = Config(maconfig)
626 cfg.cfgimpl_get_settings().setpermissive(('hidden',))
628 raises(PropertiesOptionError, 'cfg.od1.opt1')
632 def test_callback_two_disabled():
633 opt1 = BoolOption('opt1', '', properties=('disabled',))
634 opt2 = BoolOption('opt2', '', callback=return_value, callback_params={'': ((opt1, False),)}, properties=('disabled',))
635 od1 = OptionDescription('od1', '', [opt1])
636 od2 = OptionDescription('od2', '', [opt2])
637 maconfig = OptionDescription('rootconfig', '', [od1, od2])
638 cfg = Config(maconfig)
640 raises(PropertiesOptionError, 'cfg.od2.opt2')
643 def test_callback_calculating_disabled():
644 opt1 = BoolOption('opt1', '', properties=('disabled',))
645 opt2 = BoolOption('opt2', '', callback=return_value, callback_params={'': ((opt1, False),)})
646 od1 = OptionDescription('od1', '', [opt1])
647 od2 = OptionDescription('od2', '', [opt2])
648 maconfig = OptionDescription('rootconfig', '', [od1, od2])
649 cfg = Config(maconfig)
651 raises(ConfigError, 'cfg.od2.opt2')
654 def test_callback_calculating_mandatory():
655 opt1 = BoolOption('opt1', '', properties=('disabled',))
656 opt2 = BoolOption('opt2', '', callback=return_value, callback_params={'': ((opt1, False),)}, properties=('mandatory',))
657 od1 = OptionDescription('od1', '', [opt1])
658 od2 = OptionDescription('od2', '', [opt2])
659 maconfig = OptionDescription('rootconfig', '', [od1, od2])
660 cfg = Config(maconfig)
662 raises(ConfigError, 'cfg.od2.opt2')
665 def test_callback_two_disabled_multi():
666 opt1 = BoolOption('opt1', '', properties=('disabled',))
667 opt2 = BoolOption('opt2', '', callback=return_value, callback_params={'': ((opt1, False),)}, properties=('disabled',), multi=True)
668 od1 = OptionDescription('od1', '', [opt1])
669 od2 = OptionDescription('od2', '', [opt2])
670 maconfig = OptionDescription('rootconfig', '', [od1, od2])
671 cfg = Config(maconfig)
673 raises(PropertiesOptionError, 'cfg.od2.opt2')
676 def test_callback_multi_list_params():
677 val1 = StrOption('val1', "", multi=True, default=['val1', 'val2'])
678 val2 = StrOption('val2', "", multi=True, callback=return_list, callback_params={'': ((val1, False),)})
679 oval2 = OptionDescription('val2', '', [val2])
680 maconfig = OptionDescription('rootconfig', '', [val1, oval2])
681 cfg = Config(maconfig)
683 assert cfg.val2.val2 == ['val', 'val']
686 def test_callback_multi_list_params_key():
687 val1 = StrOption('val1', "", multi=True, default=['val1', 'val2'])
688 val2 = StrOption('val2', "", multi=True, callback=return_list, callback_params={'value': ((val1, False),)})
689 oval2 = OptionDescription('val2', '', [val2])
690 maconfig = OptionDescription('rootconfig', '', [val1, oval2])
691 cfg = Config(maconfig)
693 assert cfg.val2.val2 == ['val', 'val']