option.dict => value.dict

This commit is contained in:
Emmanuel Garette 2018-09-09 12:21:47 +02:00
parent 7bfa6679e3
commit 6110a37cc7
11 changed files with 180 additions and 171 deletions

View file

@ -759,13 +759,13 @@ def autocheck_display(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwa
return return
make_dict = kwargs['make_dict'] make_dict = kwargs['make_dict']
make_dict_value = kwargs['make_dict_value'] make_dict_value = kwargs['make_dict_value']
assert cfg.config(confread).config.dict() == make_dict assert cfg.config(confread).value.dict() == make_dict
if confread != confwrite: if confread != confwrite:
assert(cfg.config(confwrite).config.dict()) == make_dict assert(cfg.config(confwrite).value.dict()) == make_dict
_set_value(cfg, pathwrite, confwrite, **kwargs) _set_value(cfg, pathwrite, confwrite, **kwargs)
assert cfg.config(confread).config.dict() == make_dict_value assert cfg.config(confread).value.dict() == make_dict_value
if confread != confwrite: if confread != confwrite:
assert(cfg.config(confwrite).config.dict()) == make_dict_value assert(cfg.config(confwrite).value.dict()) == make_dict_value
@autocheck @autocheck

View file

@ -64,11 +64,11 @@ def test_cache_importation():
cfg = Config(od1) cfg = Config(od1)
cfg.option('u2').value.set(1) cfg.option('u2').value.set(1)
export = cfg.value.exportation() export = cfg.value.exportation()
assert cfg.config.dict() == {'u1': [], 'u2': 1, 'u3': []} assert cfg.value.dict() == {'u1': [], 'u2': 1, 'u3': []}
cfg.option('u2').value.set(2) cfg.option('u2').value.set(2)
assert cfg.config.dict() == {'u1': [], 'u2': 2, 'u3': []} assert cfg.value.dict() == {'u1': [], 'u2': 2, 'u3': []}
cfg.value.importation(export) cfg.value.importation(export)
assert cfg.config.dict() == {'u1': [], 'u2': 1, 'u3': []} assert cfg.value.dict() == {'u1': [], 'u2': 1, 'u3': []}
def test_cache_importation_property(): def test_cache_importation_property():
@ -328,7 +328,7 @@ def test_cache_callback():
cfg.property.read_write() cfg.property.read_write()
if TIRAMISU_VERSION == 2: if TIRAMISU_VERSION == 2:
cfg.property.pop('expire') cfg.property.pop('expire')
cfg.config.dict() cfg.value.dict()
#assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, #assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
# 'val1': {None: (set([]), None)}} # 'val1': {None: (set([]), None)}}
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('val', None)}, compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('val', None)},
@ -341,7 +341,7 @@ def test_cache_callback():
# 'val1': {None: (set([]), None)}} # 'val1': {None: (set([]), None)}}
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val3': {None: ('yes', None)}, compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val3': {None: ('yes', None)},
'val5': {None: (['yes'], None)}}) 'val5': {None: (['yes'], None)}})
cfg.config.dict() cfg.value.dict()
#assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, #assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
# 'val1': {None: (set([]), None)}} # 'val1': {None: (set([]), None)}}
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)}, compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)},
@ -357,7 +357,7 @@ def test_cache_callback():
'val2': {None: ('new', None)}, 'val2': {None: ('new', None)},
'val4': {None: ('new', None)}, 'val4': {None: ('new', None)},
'val5': {None: (['yes'], None)}}) 'val5': {None: (['yes'], None)}})
cfg.config.dict() cfg.value.dict()
#assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, #assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
# 'val1': {None: (set([]), None)}, # 'val1': {None: (set([]), None)},
# 'val3': {None: (set([]), None)}} # 'val3': {None: (set([]), None)}}
@ -375,7 +375,7 @@ def test_cache_callback():
'val2': {None: ('new', None)}, 'val2': {None: ('new', None)},
'val3': {None: ('new2', None)}, 'val3': {None: ('new2', None)},
'val5': {None: (['yes'], None)}}) 'val5': {None: (['yes'], None)}})
cfg.config.dict() cfg.value.dict()
#assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, #assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
# 'val1': {None: (set([]), None)}, # 'val1': {None: (set([]), None)},
# 'val3': {None: (set([]), None)}, # 'val3': {None: (set([]), None)},
@ -395,7 +395,7 @@ def test_cache_callback():
'val2': {None: ('new', None)}, 'val2': {None: ('new', None)},
'val3': {None: ('new2', None)}, 'val3': {None: ('new2', None)},
'val4': {None: ('new3', None)}}) 'val4': {None: ('new3', None)}})
cfg.config.dict() cfg.value.dict()
#assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, #assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
# 'val1': {None: (set([]), None)}, # 'val1': {None: (set([]), None)},
# 'val3': {None: (set([]), None)}, # 'val3': {None: (set([]), None)},
@ -416,7 +416,7 @@ def test_cache_master_and_slaves_master():
maconfig = OptionDescription('rootconfig', '', [interface1]) maconfig = OptionDescription('rootconfig', '', [interface1])
cfg = Config(maconfig) cfg = Config(maconfig)
cfg.property.read_write() cfg.property.read_write()
cfg.config.dict() cfg.value.dict()
global_props = ['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings'] global_props = ['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']
val1_props = [] val1_props = []
val1_val1_props = ['empty'] val1_val1_props = ['empty']
@ -448,7 +448,7 @@ def test_cache_master_and_slaves_master():
cfg.option('val1.val1').value.set([undefined]) cfg.option('val1.val1').value.set([undefined])
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}}) compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}})
assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {} assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {}
cfg.config.dict() cfg.value.dict()
if TIRAMISU_VERSION == 2: if TIRAMISU_VERSION == 2:
val_val2 = [None] val_val2 = [None]
val_val2_props = {None: (set(), None), 0: (set(), None)} val_val2_props = {None: (set(), None), 0: (set(), None)}
@ -464,7 +464,7 @@ def test_cache_master_and_slaves_master():
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1.val1': {None: ([None], None)}, compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1.val1': {None: ([None], None)},
'val1.val2': {idx_val2: (val_val2, None)}}) 'val1.val2': {idx_val2: (val_val2, None)}})
cfg.option('val1.val1').value.set([undefined, undefined]) cfg.option('val1.val1').value.set([undefined, undefined])
cfg.config.dict() cfg.value.dict()
cfg.option('val1.val2', 1).value.set('oui') cfg.option('val1.val2', 1).value.set('oui')
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}}) compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}})
assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {} assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {}
@ -492,7 +492,7 @@ def test_cache_master_callback():
maconfig = OptionDescription('rootconfig', '', [interface1]) maconfig = OptionDescription('rootconfig', '', [interface1])
cfg = Config(maconfig) cfg = Config(maconfig)
cfg.property.read_write() cfg.property.read_write()
cfg.config.dict() cfg.value.dict()
global_props = ['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings'] global_props = ['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']
val1_props = [] val1_props = []
val1_val1_props = ['empty'] val1_val1_props = ['empty']
@ -521,7 +521,7 @@ def test_cache_master_callback():
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}}) compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}})
assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {} assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {}
cfg.config.dict() cfg.value.dict()
#FIXMEassert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, #FIXMEassert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
# 'val1': {None: (set([]), None)}} # 'val1': {None: (set([]), None)}}
#FIXMEassert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([None], None)}, #FIXMEassert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([None], None)},
@ -549,7 +549,7 @@ def test_cache_requires():
else: else:
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'ip_address_service': {None: (None, None)}, compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'ip_address_service': {None: (None, None)},
'activate_service': {None: (True, None)}}) 'activate_service': {None: (True, None)}})
cfg.config.dict() cfg.value.dict()
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
'activate_service': {None: (set([]), None)}, 'activate_service': {None: (set([]), None)},
'ip_address_service': {None: (set([]), None)}}) 'ip_address_service': {None: (set([]), None)}})
@ -561,7 +561,7 @@ def test_cache_requires():
'activate_service': {None: (set([]), None)}}) 'activate_service': {None: (set([]), None)}})
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'activate_service': {None: (True, None)}}) compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'activate_service': {None: (True, None)}})
cfg.config.dict() cfg.value.dict()
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
'activate_service': {None: (set([]), None)}, 'activate_service': {None: (set([]), None)},
'ip_address_service': {None: (set([]), None)}}) 'ip_address_service': {None: (set([]), None)}})
@ -572,7 +572,7 @@ def test_cache_requires():
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}}) compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}})
assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {} assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {}
cfg.config.dict() cfg.value.dict()
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
'activate_service': {None: (set([]), None)}, 'activate_service': {None: (set([]), None)},
'ip_address_service': {None: (set(['disabled']), None)}}) 'ip_address_service': {None: (set(['disabled']), None)}})

View file

@ -64,16 +64,16 @@ def test_make_dict():
config = Config(descr) config = Config(descr)
config.property.read_write() config.property.read_write()
config.permissive.set(frozenset(['hidden'])) config.permissive.set(frozenset(['hidden']))
d = config.config.dict() d = config.value.dict()
assert d == {"s1.a": False, "int": 42} assert d == {"s1.a": False, "int": 42}
config.option('int').value.set(43) config.option('int').value.set(43)
config.option('s1.a').value.set(True) config.option('s1.a').value.set(True)
d = config.config.dict() d = config.value.dict()
assert d == {"s1.a": True, "int": 43} assert d == {"s1.a": True, "int": 43}
d2 = config.config.dict(flatten=True) d2 = config.value.dict(flatten=True)
assert d2 == {'a': True, 'int': 43} assert d2 == {'a': True, 'int': 43}
raises(ValueError, 'd2 = config.config.dict(withvalue="3")') raises(ValueError, 'd2 = config.value.dict(withvalue="3")')
d = config.forcepermissive.config.dict() d = config.forcepermissive.value.dict()
assert d == {"s1.a": True, "s1.b": False, "int": 43} assert d == {"s1.a": True, "s1.b": False, "int": 43}
@ -88,9 +88,9 @@ def test_make_dict_with_disabled():
IntOption("int", "", default=42)]) IntOption("int", "", default=42)])
config = Config(descr) config = Config(descr)
config.property.read_only() config.property.read_only()
assert config.config.dict() == {"s1.a": False, "int": 42} assert config.value.dict() == {"s1.a": False, "int": 42}
assert config.forcepermissive.config.dict() == {"s1.a": False, "int": 42} assert config.forcepermissive.value.dict() == {"s1.a": False, "int": 42}
assert config.unrestraint.config.dict() == {"int": 42, "s1.a": False, "s1.b": False, "s2.a": False, "s2.b": False} assert config.unrestraint.value.dict() == {"int": 42, "s1.a": False, "s1.b": False, "s2.a": False, "s2.b": False}
def test_make_dict_with_disabled_withoption(): def test_make_dict_with_disabled_withoption():
@ -104,9 +104,9 @@ def test_make_dict_with_disabled_withoption():
IntOption("int", "", default=42)]) IntOption("int", "", default=42)])
config = Config(descr) config = Config(descr)
config.property.read_only() config.property.read_only()
assert config.config.dict(withoption="a") == {"s1.a": False} assert config.value.dict(withoption="a") == {"s1.a": False}
assert config.forcepermissive.config.dict(withoption="a") == {"s1.a": False} assert config.forcepermissive.value.dict(withoption="a") == {"s1.a": False}
assert config.unrestraint.config.dict(withoption="a") == {"s1.a": False, "s1.b": False, "s2.a": False, "s2.b": False} assert config.unrestraint.value.dict(withoption="a") == {"s1.a": False, "s1.b": False, "s2.a": False, "s2.b": False}
def test_make_dict_with_disabled_in_callback(): def test_make_dict_with_disabled_in_callback():
@ -120,7 +120,7 @@ def test_make_dict_with_disabled_in_callback():
IntOption("int", "", default=42)]) IntOption("int", "", default=42)])
config = Config(descr) config = Config(descr)
config.property.read_only() config.property.read_only()
d = config.config.dict() d = config.value.dict()
assert d == {"s1.a": False, "int": 42} assert d == {"s1.a": False, "int": 42}
@ -137,10 +137,10 @@ def test_make_dict_fullpath():
IntOption("introot", "", default=42)]) IntOption("introot", "", default=42)])
config = Config(descr) config = Config(descr)
config.property.read_only() config.property.read_only()
assert config.config.dict() == {"opt.s1.a": False, "opt.int": 42, "introot": 42} assert config.value.dict() == {"opt.s1.a": False, "opt.int": 42, "introot": 42}
assert config.option('opt').dict() == {"s1.a": False, "int": 42} assert config.option('opt').value.dict() == {"s1.a": False, "int": 42}
assert config.config.dict(fullpath=True) == {"opt.s1.a": False, "opt.int": 42, "introot": 42} assert config.value.dict(fullpath=True) == {"opt.s1.a": False, "opt.int": 42, "introot": 42}
assert config.option('opt').dict(fullpath=True) == {"opt.s1.a": False, "opt.int": 42} assert config.option('opt').value.dict(fullpath=True) == {"opt.s1.a": False, "opt.int": 42}
def test_find_in_config(): def test_find_in_config():

View file

@ -57,7 +57,7 @@ def test_build_dyndescription():
dod = DynOptionDescription('dod', '', [st1], callback=return_list) dod = DynOptionDescription('dod', '', [st1], callback=return_list)
od1 = OptionDescription('od', '', [dod]) od1 = OptionDescription('od', '', [dod])
cfg = Config(od1) cfg = Config(od1)
assert cfg.config.dict() == {'dodval1.stval1': None, 'dodval2.stval2': None} assert cfg.value.dict() == {'dodval1.stval1': None, 'dodval2.stval2': None}
def test_build_dyndescription_raise(): def test_build_dyndescription_raise():
@ -65,7 +65,7 @@ def test_build_dyndescription_raise():
dod = DynOptionDescription('dod', '', [st1], callback=return_raise) dod = DynOptionDescription('dod', '', [st1], callback=return_raise)
od1 = OptionDescription('od', '', [dod]) od1 = OptionDescription('od', '', [dod])
cfg = Config(od1) cfg = Config(od1)
raises(ConfigError, "cfg.config.dict()") raises(ConfigError, "cfg.value.dict()")
def test_build_dyndescription_not_list(): def test_build_dyndescription_not_list():
@ -73,7 +73,7 @@ def test_build_dyndescription_not_list():
dod = DynOptionDescription('dod', '', [st1], callback=return_str) dod = DynOptionDescription('dod', '', [st1], callback=return_str)
od1 = OptionDescription('od', '', [dod]) od1 = OptionDescription('od', '', [dod])
cfg = Config(od1) cfg = Config(od1)
raises(ValueError, "cfg.config.dict()") raises(ValueError, "cfg.value.dict()")
def test_subpath_dyndescription(): def test_subpath_dyndescription():
@ -82,7 +82,7 @@ def test_subpath_dyndescription():
od1 = OptionDescription('od', '', [dod]) od1 = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od1]) od2 = OptionDescription('od', '', [od1])
api = Config(od2) api = Config(od2)
assert api.config.dict() == {'od.dodval1.stval1': None, 'od.dodval2.stval2': None} assert api.value.dict() == {'od.dodval1.stval1': None, 'od.dodval2.stval2': None}
def test_list_dyndescription(): def test_list_dyndescription():
@ -290,7 +290,7 @@ def test_build_dyndescription_context():
dod = DynOptionDescription('dod', '', [st1], callback=return_list, callback_params=Params(ParamOption(val1))) dod = DynOptionDescription('dod', '', [st1], callback=return_list, callback_params=Params(ParamOption(val1)))
od1 = OptionDescription('od', '', [dod, val1]) od1 = OptionDescription('od', '', [dod, val1])
cfg = Config(od1) cfg = Config(od1)
assert cfg.config.dict() == {'dodval1.stval1': None, 'dodval2.stval2': None, 'val1': ['val1', 'val2']} assert cfg.value.dict() == {'dodval1.stval1': None, 'dodval2.stval2': None, 'val1': ['val1', 'val2']}
def test_subpath_dyndescription_context(): def test_subpath_dyndescription_context():
@ -300,7 +300,7 @@ def test_subpath_dyndescription_context():
od1 = OptionDescription('od', '', [dod, val1]) od1 = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od1]) od2 = OptionDescription('od', '', [od1])
api = Config(od2) api = Config(od2)
assert api.config.dict() == {'od.dodval1.stval1': None, 'od.dodval2.stval2': None, 'od.val1': ['val1', 'val2']} assert api.value.dict() == {'od.dodval1.stval1': None, 'od.dodval2.stval2': None, 'od.val1': ['val1', 'val2']}
def test_list_dyndescription_context(): def test_list_dyndescription_context():
@ -637,11 +637,11 @@ def test_makedict_dyndescription_context():
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
api = Config(od2) api = Config(od2)
api.option('od.dodval1.stval1').value.set('yes') api.option('od.dodval1.stval1').value.set('yes')
assert api.config.dict() == {'od.val1': ['val1', 'val2'], 'od.dodval1.stval1': 'yes', 'od.dodval2.stval2': None} assert api.value.dict() == {'od.val1': ['val1', 'val2'], 'od.dodval1.stval1': 'yes', 'od.dodval2.stval2': None}
assert api.config.dict(flatten=True) == {'val1': ['val1', 'val2'], 'stval1': 'yes', 'stval2': None} assert api.value.dict(flatten=True) == {'val1': ['val1', 'val2'], 'stval1': 'yes', 'stval2': None}
assert api.config.dict(withoption='stval1') == {'od.dodval1.stval1': 'yes'} assert api.value.dict(withoption='stval1') == {'od.dodval1.stval1': 'yes'}
assert api.option('od').dict(withoption='stval1') == {'dodval1.stval1': 'yes'} assert api.option('od').value.dict(withoption='stval1') == {'dodval1.stval1': 'yes'}
assert api.option('od.dodval1').dict(withoption='stval1') == {'stval1': 'yes'} assert api.option('od.dodval1').value.dict(withoption='stval1') == {'stval1': 'yes'}
def test_find_dyndescription_context(): def test_find_dyndescription_context():
@ -901,14 +901,14 @@ def test_masterslaves_dyndescription():
api = Config(od2) api = Config(od2)
owner = api.owner.get() owner = api.owner.get()
# #
assert api.config.dict() == {'od.stval1.st1val1.st2val1': [], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': []} assert api.value.dict() == {'od.stval1.st1val1.st2val1': [], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': []}
assert api.option('od.stval1.st1val1.st1val1').value.get() == [] assert api.option('od.stval1.st1val1.st1val1').value.get() == []
assert api.option('od.stval2.st1val2.st1val2').value.get() == [] assert api.option('od.stval2.st1val2.st1val2').value.get() == []
assert api.option('od.stval1.st1val1.st1val1').owner.isdefault() assert api.option('od.stval1.st1val1.st1val1').owner.isdefault()
assert api.option('od.stval2.st1val2.st1val2').owner.isdefault() assert api.option('od.stval2.st1val2.st1val2').owner.isdefault()
# #
api.option('od.stval1.st1val1.st1val1').value.set(['yes']) api.option('od.stval1.st1val1.st1val1').value.set(['yes'])
assert api.config.dict() == {'od.stval1.st1val1.st2val1': [None], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': ['yes']} assert api.value.dict() == {'od.stval1.st1val1.st2val1': [None], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': ['yes']}
assert api.option('od.stval1.st1val1.st1val1').value.get() == ['yes'] assert api.option('od.stval1.st1val1.st1val1').value.get() == ['yes']
assert api.option('od.stval1.st1val1.st2val1', 0).value.get() == None assert api.option('od.stval1.st1val1.st2val1', 0).value.get() == None
assert api.option('od.stval2.st1val2.st1val2').value.get() == [] assert api.option('od.stval2.st1val2.st1val2').value.get() == []
@ -983,14 +983,14 @@ def test_masterslaves_dyndescription_param():
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
cfg = Config(od2) cfg = Config(od2)
owner = cfg.owner.get() owner = cfg.owner.get()
assert cfg.config.dict() == {'od.stval1.st1val1.st2val1': [], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': [], 'od.odval1.val1': ['val1', 'val2']} assert cfg.value.dict() == {'od.stval1.st1val1.st2val1': [], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': [], 'od.odval1.val1': ['val1', 'val2']}
assert cfg.option('od.stval1.st1val1.st1val1').value.get() == [] assert cfg.option('od.stval1.st1val1.st1val1').value.get() == []
assert cfg.option('od.stval2.st1val2.st1val2').value.get() == [] assert cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert cfg.option('od.stval1.st1val1.st1val1').owner.get() == owners.default assert cfg.option('od.stval1.st1val1.st1val1').owner.get() == owners.default
assert cfg.option('od.stval2.st1val2.st1val2').owner.get() == owners.default assert cfg.option('od.stval2.st1val2.st1val2').owner.get() == owners.default
# #
cfg.option('od.stval1.st1val1.st1val1').value.set(['yes']) cfg.option('od.stval1.st1val1.st1val1').value.set(['yes'])
assert cfg.config.dict() == {'od.stval1.st1val1.st2val1': [None], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': ['yes'], 'od.odval1.val1': ['val1', 'val2']} assert cfg.value.dict() == {'od.stval1.st1val1.st2val1': [None], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': ['yes'], 'od.odval1.val1': ['val1', 'val2']}
assert cfg.option('od.stval1.st1val1.st1val1').value.get() == ['yes'] assert cfg.option('od.stval1.st1val1.st1val1').value.get() == ['yes']
assert cfg.option('od.stval1.st1val1.st2val1', 0).value.get() == None assert cfg.option('od.stval1.st1val1.st2val1', 0).value.get() == None
assert cfg.option('od.stval2.st1val2.st1val2').value.get() == [] assert cfg.option('od.stval2.st1val2.st1val2').value.get() == []
@ -1061,14 +1061,14 @@ def _test_masterslaves(cfg):
cfg.option('od.val1.val1').value.set(['val1', 'val2']) cfg.option('od.val1.val1').value.set(['val1', 'val2'])
cfg.option('od.val1.val2', 0).value.set('val1') cfg.option('od.val1.val2', 0).value.set('val1')
cfg.option('od.val1.val2', 1).value.set('val2') cfg.option('od.val1.val2', 1).value.set('val2')
assert cfg.config.dict() == {'od.stval1.st1val1.st2val1': [], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': [], 'od.val1.val1': ['val1', 'val2'], 'od.val1.val2': ['val1', 'val2']} assert cfg.value.dict() == {'od.stval1.st1val1.st2val1': [], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': [], 'od.val1.val1': ['val1', 'val2'], 'od.val1.val2': ['val1', 'val2']}
assert cfg.option('od.stval1.st1val1.st1val1').value.get() == [] assert cfg.option('od.stval1.st1val1.st1val1').value.get() == []
assert cfg.option('od.stval2.st1val2.st1val2').value.get() == [] assert cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert cfg.option('od.stval1.st1val1.st1val1').owner.get() == owners.default assert cfg.option('od.stval1.st1val1.st1val1').owner.get() == owners.default
assert cfg.option('od.stval2.st1val2.st1val2').owner.get() == owners.default assert cfg.option('od.stval2.st1val2.st1val2').owner.get() == owners.default
# #
cfg.option('od.stval1.st1val1.st1val1').value.set(['yes']) cfg.option('od.stval1.st1val1.st1val1').value.set(['yes'])
assert cfg.config.dict() == {'od.stval1.st1val1.st2val1': [None], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': ['yes'], 'od.val1.val1': ['val1', 'val2'], 'od.val1.val2': ['val1', 'val2']} assert cfg.value.dict() == {'od.stval1.st1val1.st2val1': [None], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': ['yes'], 'od.val1.val1': ['val1', 'val2'], 'od.val1.val2': ['val1', 'val2']}
assert cfg.option('od.stval1.st1val1.st1val1').value.get() == ['yes'] assert cfg.option('od.stval1.st1val1.st1val1').value.get() == ['yes']
assert cfg.option('od.stval1.st1val1.st2val1', 0).value.get() == None assert cfg.option('od.stval1.st1val1.st2val1', 0).value.get() == None
assert cfg.option('od.stval2.st1val2.st1val2').value.get() == [] assert cfg.option('od.stval2.st1val2.st1val2').value.get() == []
@ -1270,14 +1270,14 @@ def test_masterslaves_callback_dyndescription():
od2 = OptionDescription('od', '', [od1]) od2 = OptionDescription('od', '', [od1])
api = Config(od2) api = Config(od2)
owner = api.owner.get() owner = api.owner.get()
assert api.config.dict() == {'od.stval1.st1val1.st2val1': [], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': []} assert api.value.dict() == {'od.stval1.st1val1.st2val1': [], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': []}
assert api.option('od.stval1.st1val1.st1val1').value.get() ==[] assert api.option('od.stval1.st1val1.st1val1').value.get() ==[]
assert api.option('od.stval2.st1val2.st1val2').value.get() == [] assert api.option('od.stval2.st1val2.st1val2').value.get() == []
assert api.option('od.stval1.st1val1.st1val1').owner.isdefault() assert api.option('od.stval1.st1val1.st1val1').owner.isdefault()
assert api.option('od.stval2.st1val2.st1val2').owner.isdefault() assert api.option('od.stval2.st1val2.st1val2').owner.isdefault()
# #
api.option('od.stval1.st1val1.st1val1').value.set(['yes']) api.option('od.stval1.st1val1.st1val1').value.set(['yes'])
assert api.config.dict() == {'od.stval1.st1val1.st2val1': ['yes'], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': ['yes']} assert api.value.dict() == {'od.stval1.st1val1.st2val1': ['yes'], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': ['yes']}
assert api.option('od.stval1.st1val1.st1val1').value.get() == ['yes'] assert api.option('od.stval1.st1val1.st1val1').value.get() == ['yes']
assert api.option('od.stval1.st1val1.st2val1', 0).value.get() == 'yes' assert api.option('od.stval1.st1val1.st2val1', 0).value.get() == 'yes'
assert api.option('od.stval2.st1val2.st1val2').value.get() == [] assert api.option('od.stval2.st1val2.st1val2').value.get() == []
@ -1362,7 +1362,7 @@ def test_masterslaves_callback_samegroup_dyndescription():
od2 = OptionDescription('od', '', [od1]) od2 = OptionDescription('od', '', [od1])
api = Config(od2) api = Config(od2)
owner = api.owner.get() owner = api.owner.get()
assert api.config.dict() == {'od.stval1.st1val1.st1val1': [], assert api.value.dict() == {'od.stval1.st1val1.st1val1': [],
'od.stval1.st1val1.st2val1': [], 'od.stval1.st1val1.st2val1': [],
'od.stval1.st1val1.st3val1': [], 'od.stval1.st1val1.st3val1': [],
'od.stval2.st1val2.st1val2': [], 'od.stval2.st1val2.st1val2': [],
@ -1374,7 +1374,7 @@ def test_masterslaves_callback_samegroup_dyndescription():
assert api.option('od.stval2.st1val2.st1val2').owner.isdefault() assert api.option('od.stval2.st1val2.st1val2').owner.isdefault()
# #
api.option('od.stval1.st1val1.st1val1').value.set(['yes']) api.option('od.stval1.st1val1.st1val1').value.set(['yes'])
assert api.config.dict() == {'od.stval1.st1val1.st1val1': ['yes'], assert api.value.dict() == {'od.stval1.st1val1.st1val1': ['yes'],
'od.stval1.st1val1.st2val1': [None], 'od.stval1.st1val1.st2val1': [None],
'od.stval1.st1val1.st3val1': [None], 'od.stval1.st1val1.st3val1': [None],
'od.stval2.st1val2.st1val2': [], 'od.stval2.st1val2.st1val2': [],
@ -1386,7 +1386,7 @@ def test_masterslaves_callback_samegroup_dyndescription():
assert api.option('od.stval2.st1val2.st1val2').owner.isdefault() assert api.option('od.stval2.st1val2.st1val2').owner.isdefault()
# #
api.option('od.stval1.st1val1.st2val1', 0).value.set('yes') api.option('od.stval1.st1val1.st2val1', 0).value.set('yes')
assert api.config.dict() == {'od.stval1.st1val1.st1val1': ['yes'], assert api.value.dict() == {'od.stval1.st1val1.st1val1': ['yes'],
'od.stval1.st1val1.st2val1': ['yes'], 'od.stval1.st1val1.st2val1': ['yes'],
'od.stval1.st1val1.st3val1': ['yes'], 'od.stval1.st1val1.st3val1': ['yes'],
'od.stval2.st1val2.st1val2': [], 'od.stval2.st1val2.st1val2': [],
@ -1439,7 +1439,7 @@ def test_invalid_samevalue_dyndescription():
dod = DynOptionDescription('dod', '', [st1], callback=return_same_list) dod = DynOptionDescription('dod', '', [st1], callback=return_same_list)
od1 = OptionDescription('od', '', [dod]) od1 = OptionDescription('od', '', [dod])
cfg = Config(od1) cfg = Config(od1)
raises(ValueError, "cfg.config.dict()") raises(ValueError, "cfg.value.dict()")
def test_invalid_name_dyndescription(): def test_invalid_name_dyndescription():
@ -1447,4 +1447,4 @@ def test_invalid_name_dyndescription():
dod = DynOptionDescription('dod', '', [st1], callback=return_wrong_list) dod = DynOptionDescription('dod', '', [st1], callback=return_wrong_list)
od1 = OptionDescription('od', '', [dod]) od1 = OptionDescription('od', '', [dod])
cfg = Config(od1) cfg = Config(od1)
raises(ValueError, "cfg.config.dict()") raises(ValueError, "cfg.value.dict()")

View file

@ -70,12 +70,12 @@ def test_base_config():
'general.mode_conteneur_actif': False, 'general.time_zone': 'Paris', 'general.mode_conteneur_actif': False, 'general.time_zone': 'Paris',
'interface1.ip_admin_eth0.netmask_admin_eth0': None, 'general.nom_machine': 'interface1.ip_admin_eth0.netmask_admin_eth0': None, 'general.nom_machine':
'eoleng', 'general.activer_proxy_client': False} 'eoleng', 'general.activer_proxy_client': False}
assert api.option('creole').dict() == result assert api.option('creole').value.dict() == result
result = {'serveur_ntp': [], 'mode_conteneur_actif': False, result = {'serveur_ntp': [], 'mode_conteneur_actif': False,
'ip_admin_eth0': None, 'time_zone': 'Paris', 'numero_etab': None, 'ip_admin_eth0': None, 'time_zone': 'Paris', 'numero_etab': None,
'netmask_admin_eth0': None, 'nom_machine': 'eoleng', 'activer_proxy_client': 'netmask_admin_eth0': None, 'nom_machine': 'eoleng', 'activer_proxy_client':
False, 'nombre_interfaces': 1} False, 'nombre_interfaces': 1}
assert api.option('creole').dict(flatten=True) == result assert api.option('creole').value.dict(flatten=True) == result
def test_make_dict_filter(): def test_make_dict_filter():
@ -89,10 +89,10 @@ def test_make_dict_filter():
result = {} result = {}
for key, value in subresult.items(): for key, value in subresult.items():
result['general.' + key] = value result['general.' + key] = value
assert api.option('creole').dict(withoption='numero_etab') == result assert api.option('creole').value.dict(withoption='numero_etab') == result
raises(AttributeError, "api.option('creole').dict(withoption='numero_etab', withvalue='toto')") raises(AttributeError, "api.option('creole').value.dict(withoption='numero_etab', withvalue='toto')")
assert api.option('creole').dict(withoption='numero_etab', withvalue=None) == result assert api.option('creole').value.dict(withoption='numero_etab', withvalue=None) == result
assert api.option('creole.general').dict(withoption='numero_etab') == subresult assert api.option('creole.general').value.dict(withoption='numero_etab') == subresult
def test_get_group_type(): def test_get_group_type():
@ -220,9 +220,9 @@ def test_groups_with_master_make_dict():
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1]) od = OptionDescription('root', '', [interface1])
api = Config(od) api = Config(od)
assert api.config.dict() == {'ip_admin_eth0.ip_admin_eth0': [], 'ip_admin_eth0.netmask_admin_eth0': []} assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [], 'ip_admin_eth0.netmask_admin_eth0': []}
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip1', 'ip2']) api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip1', 'ip2'])
assert api.config.dict() == {'ip_admin_eth0.ip_admin_eth0': ['ip1', 'ip2'], 'ip_admin_eth0.netmask_admin_eth0': [None, None]} assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['ip1', 'ip2'], 'ip_admin_eth0.netmask_admin_eth0': [None, None]}
def test_groups_with_master_hidden_in_config(): def test_groups_with_master_hidden_in_config():

View file

@ -133,7 +133,7 @@ def test_find():
assert len(ret) == 1 assert len(ret) == 1
assert 1 == ret[0].value.get() assert 1 == ret[0].value.get()
assert 1 == meta.option.find('i2', first=True).value.get() assert 1 == meta.option.find('i2', first=True).value.get()
assert meta.config.dict() == {'od1.i4': 2, 'od1.i1': None, 'od1.i3': None, assert meta.value.dict() == {'od1.i4': 2, 'od1.i1': None, 'od1.i3': None,
'od1.i2': 1, 'od1.i5': [2]} 'od1.i2': 1, 'od1.i5': [2]}
@ -581,7 +581,7 @@ def test_meta_properties_meta():
conf2.property.read_write() conf2.property.read_write()
meta = MetaConfig([conf1, conf2]) meta = MetaConfig([conf1, conf2])
meta.property.read_write() meta.property.read_write()
assert meta.config('conf1').config.dict() == {} assert meta.config('conf1').value.dict() == {}
def test_meta_exception_meta(): def test_meta_exception_meta():
@ -607,17 +607,17 @@ def test_meta_callback():
cfg = Config(maconfig, session_id='cfg') cfg = Config(maconfig, session_id='cfg')
meta = MetaConfig([cfg]) meta = MetaConfig([cfg])
meta.property.read_write() meta.property.read_write()
assert meta.config('cfg').config.dict() == {'val3': 'yes', 'val2': 'val', 'val1': 'val', 'val5': 'yes', 'val4': 'val'} assert meta.config('cfg').value.dict() == {'val3': 'yes', 'val2': 'val', 'val1': 'val', 'val5': 'yes', 'val4': 'val'}
meta.config('cfg').option('val1').value.set('new') meta.config('cfg').option('val1').value.set('new')
#assert meta.config('cfg').config.dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new'} #assert meta.config('cfg').value.dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new'}
#meta.config('cfg').option('val1').value.reset() #meta.config('cfg').option('val1').value.reset()
#meta.option('val1').value.set('new') #meta.option('val1').value.set('new')
#assert meta.config('cfg').config.dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new'} #assert meta.config('cfg').value.dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new'}
#meta.config('cfg').option('val4').value.set('new1') #meta.config('cfg').option('val4').value.set('new1')
#assert meta.config('cfg').config.dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new1'} #assert meta.config('cfg').value.dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new1'}
#meta.config('cfg').option('val4').value.reset() #meta.config('cfg').option('val4').value.reset()
#meta.option('val4').value.set('new1') #meta.option('val4').value.set('new1')
#assert meta.config('cfg').config.dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new1'} #assert meta.config('cfg').value.dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new1'}
#meta.option('val4').value.reset() #meta.option('val4').value.reset()
@ -632,36 +632,36 @@ def test_meta_callback_slave():
cfg = Config(maconfig, session_id='cfg1') cfg = Config(maconfig, session_id='cfg1')
meta = MetaConfig([cfg]) meta = MetaConfig([cfg])
meta.property.read_write() meta.property.read_write()
assert meta.config('cfg1').config.dict() == {'val1.val2': ['val'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'} assert meta.config('cfg1').value.dict() == {'val1.val2': ['val'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
meta.config('cfg1').option('val').value.set('val1') meta.config('cfg1').option('val').value.set('val1')
assert meta.config('cfg1').config.dict() == {'val1.val2': ['val1'], 'val1.val1': ['val1'], 'val1.val3': ['val1'], 'val': 'val1'} assert meta.config('cfg1').value.dict() == {'val1.val2': ['val1'], 'val1.val1': ['val1'], 'val1.val3': ['val1'], 'val': 'val1'}
meta.config('cfg1').option('val').value.reset() meta.config('cfg1').option('val').value.reset()
meta.option('val').value.set('val1') meta.option('val').value.set('val1')
assert meta.config('cfg1').config.dict() == {'val1.val2': ['val1'], 'val1.val1': ['val1'], 'val1.val3': ['val1'], 'val': 'val1'} assert meta.config('cfg1').value.dict() == {'val1.val2': ['val1'], 'val1.val1': ['val1'], 'val1.val3': ['val1'], 'val': 'val1'}
meta.option('val').value.reset() meta.option('val').value.reset()
meta.config('cfg1').option('val1.val2', 0).value.set('val2') meta.config('cfg1').option('val1.val2', 0).value.set('val2')
assert meta.config('cfg1').config.dict() == {'val1.val2': ['val2'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'} assert meta.config('cfg1').value.dict() == {'val1.val2': ['val2'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
meta.config('cfg1').option('val1.val2', 0).value.reset() meta.config('cfg1').option('val1.val2', 0).value.reset()
assert meta.config('cfg1').config.dict() == {'val1.val2': ['val'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'} assert meta.config('cfg1').value.dict() == {'val1.val2': ['val'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
meta.option('val1.val2', 0).value.set('val2') meta.option('val1.val2', 0).value.set('val2')
assert meta.config('cfg1').config.dict() == {'val1.val2': ['val2'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'} assert meta.config('cfg1').value.dict() == {'val1.val2': ['val2'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
meta.config('cfg1').option('val1.val3', 0).value.set('val6') meta.config('cfg1').option('val1.val3', 0).value.set('val6')
assert meta.config('cfg1').config.dict() == {'val1.val2': ['val2'], 'val1.val1': ['val'], 'val1.val3': ['val6'], 'val': 'val'} assert meta.config('cfg1').value.dict() == {'val1.val2': ['val2'], 'val1.val1': ['val'], 'val1.val3': ['val6'], 'val': 'val'}
meta.option('val1.val2', 0).value.reset() meta.option('val1.val2', 0).value.reset()
meta.config('cfg1').option('val1.val3', 0).value.reset() meta.config('cfg1').option('val1.val3', 0).value.reset()
meta.config('cfg1').option('val1.val1').value.set(['val3']) meta.config('cfg1').option('val1.val1').value.set(['val3'])
assert meta.config('cfg1').config.dict() == {'val1.val2': ['val3'], 'val1.val1': ['val3'], 'val1.val3': ['val3'], 'val': 'val'} assert meta.config('cfg1').value.dict() == {'val1.val2': ['val3'], 'val1.val1': ['val3'], 'val1.val3': ['val3'], 'val': 'val'}
meta.config('cfg1').option('val1.val1').value.reset() meta.config('cfg1').option('val1.val1').value.reset()
assert meta.config('cfg1').config.dict() == {'val1.val2': ['val'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'} assert meta.config('cfg1').value.dict() == {'val1.val2': ['val'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
meta.option('val1.val1').value.set(['val3']) meta.option('val1.val1').value.set(['val3'])
assert meta.config('cfg1').config.dict() == {'val1.val2': ['val3'], 'val1.val1': ['val3'], 'val1.val3': ['val3'], 'val': 'val'} assert meta.config('cfg1').value.dict() == {'val1.val2': ['val3'], 'val1.val1': ['val3'], 'val1.val3': ['val3'], 'val': 'val'}
meta.config('cfg1').option('val1.val2', 0).value.set('val2') meta.config('cfg1').option('val1.val2', 0).value.set('val2')
assert meta.config('cfg1').config.dict() == {'val1.val2': ['val2'], 'val1.val1': ['val3'], 'val1.val3': ['val3'], 'val': 'val'} assert meta.config('cfg1').value.dict() == {'val1.val2': ['val2'], 'val1.val1': ['val3'], 'val1.val3': ['val3'], 'val': 'val'}
meta.option('val1.val1').value.set(['val3', 'rah']) meta.option('val1.val1').value.set(['val3', 'rah'])
assert meta.config('cfg1').config.dict() == {'val1.val2': ['val2', 'rah'], 'val1.val1': ['val3', 'rah'], 'val1.val3': ['val3', 'rah'], 'val': 'val'} assert meta.config('cfg1').value.dict() == {'val1.val2': ['val2', 'rah'], 'val1.val1': ['val3', 'rah'], 'val1.val3': ['val3', 'rah'], 'val': 'val'}
meta.option('val1.val1').value.pop(1) meta.option('val1.val1').value.pop(1)
meta.option('val1.val1').value.set(['val4']) meta.option('val1.val1').value.set(['val4'])
assert meta.config('cfg1').config.dict() == {'val1.val2': ['val2'], 'val1.val1': ['val4'], 'val1.val3': ['val4'], 'val': 'val'} assert meta.config('cfg1').value.dict() == {'val1.val2': ['val2'], 'val1.val1': ['val4'], 'val1.val3': ['val4'], 'val': 'val'}
def test_meta_reset(): def test_meta_reset():
@ -707,17 +707,17 @@ def test_meta_properties_meta_copy():
meta2 = conf3.config.meta() meta2 = conf3.config.meta()
assert meta != meta2 assert meta != meta2
assert meta.config('conf1').config.dict() == {'ip_admin_eth0': ['192.168.1.1']} assert meta.config('conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
assert meta.config('conf2').config.dict() == {'ip_admin_eth0': ['192.168.1.1']} assert meta.config('conf2').value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
assert meta.config('conf3').config.dict() == {'ip_admin_eth0': ['192.168.1.1']} assert meta.config('conf3').value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
meta.option('ip_admin_eth0').value.set(['192.168.1.2']) meta.option('ip_admin_eth0').value.set(['192.168.1.2'])
assert meta.config('conf1').config.dict() == {'ip_admin_eth0': ['192.168.1.2']} assert meta.config('conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.2']}
assert meta.config('conf2').config.dict() == {'ip_admin_eth0': ['192.168.1.2']} assert meta.config('conf2').value.dict() == {'ip_admin_eth0': ['192.168.1.2']}
assert meta.config('conf3').config.dict() == {'ip_admin_eth0': ['192.168.1.2']} assert meta.config('conf3').value.dict() == {'ip_admin_eth0': ['192.168.1.2']}
ret = meta.value.set('ip_admin_eth0', ['192.168.1.3'], force_default_if_same=True) ret = meta.value.set('ip_admin_eth0', ['192.168.1.3'], force_default_if_same=True)
assert meta.config('conf1').config.dict() == {'ip_admin_eth0': ['192.168.1.3']} assert meta.config('conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.3']}
assert meta.config('conf2').config.dict() == {'ip_admin_eth0': ['192.168.1.3']} assert meta.config('conf2').value.dict() == {'ip_admin_eth0': ['192.168.1.3']}
assert meta.config('conf3').config.dict() == {'ip_admin_eth0': ['192.168.1.3']} assert meta.config('conf3').value.dict() == {'ip_admin_eth0': ['192.168.1.3']}
def test_meta_properties_meta_deepcopy(): def test_meta_properties_meta_deepcopy():
@ -737,17 +737,17 @@ def test_meta_properties_meta_deepcopy():
assert meta != meta2 assert meta != meta2
assert meta.permissive.get() == meta2.permissive.get() assert meta.permissive.get() == meta2.permissive.get()
assert meta.config('conf1').config.dict() == {'ip_admin_eth0': ['192.168.1.1']} assert meta.config('conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
assert meta.config('conf2').config.dict() == {'ip_admin_eth0': ['192.168.1.1']} assert meta.config('conf2').value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
assert meta2.config('conf3').config.dict() == {'ip_admin_eth0': ['192.168.1.1']} assert meta2.config('conf3').value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
meta.option('ip_admin_eth0').value.set(['192.168.1.2']) meta.option('ip_admin_eth0').value.set(['192.168.1.2'])
assert meta.config('conf1').config.dict() == {'ip_admin_eth0': ['192.168.1.2']} assert meta.config('conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.2']}
assert meta.config('conf2').config.dict() == {'ip_admin_eth0': ['192.168.1.2']} assert meta.config('conf2').value.dict() == {'ip_admin_eth0': ['192.168.1.2']}
assert meta2.config('conf3').config.dict() == {'ip_admin_eth0': ['192.168.1.1']} assert meta2.config('conf3').value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
meta.value.set('ip_admin_eth0', ['192.168.1.3'], force_default_if_same=True) meta.value.set('ip_admin_eth0', ['192.168.1.3'], force_default_if_same=True)
assert meta.config('conf1').config.dict() == {'ip_admin_eth0': ['192.168.1.3']} assert meta.config('conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.3']}
assert meta.config('conf2').config.dict() == {'ip_admin_eth0': ['192.168.1.3']} assert meta.config('conf2').value.dict() == {'ip_admin_eth0': ['192.168.1.3']}
assert meta2.config('conf3').config.dict() == {'ip_admin_eth0': ['192.168.1.1']} assert meta2.config('conf3').value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
def test_meta_properties_meta_set_value(): def test_meta_properties_meta_set_value():
@ -760,7 +760,7 @@ def test_meta_properties_meta_set_value():
conf2.property.read_write() conf2.property.read_write()
meta = MetaConfig([conf1, conf2]) meta = MetaConfig([conf1, conf2])
meta.property.read_write() meta.property.read_write()
assert meta.config('conf1').config.dict() == {'ip_admin_eth0': ['192.168.1.1']} assert meta.config('conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
ret = meta.value.set('netmask_admin_eth0', ['255.255.255.255'], only_config=True) ret = meta.value.set('netmask_admin_eth0', ['255.255.255.255'], only_config=True)
assert len(ret) == 2 assert len(ret) == 2
assert isinstance(ret[0], PropertiesOptionError) assert isinstance(ret[0], PropertiesOptionError)

View file

@ -260,7 +260,7 @@ def test_consistency_not_equal_masterslave():
api.option('a.b', 0).value.set(2) api.option('a.b', 0).value.set(2)
api.option('a.a').value.reset() api.option('a.a').value.reset()
api.option('a.a').value.set([1]) api.option('a.a').value.set([1])
api.config.dict() api.value.dict()
def test_consistency_not_equal_masterslave_error_multi1(): def test_consistency_not_equal_masterslave_error_multi1():
@ -891,7 +891,7 @@ def test_consistency_network_netmask_mandatory():
api = Config(od2) api = Config(od2)
api.property.read_only() api.property.read_only()
api.property.pop('mandatory') api.property.pop('mandatory')
api.config.dict() api.value.dict()
def test_consistency_has_dependency(): def test_consistency_has_dependency():

View file

@ -99,7 +99,7 @@ def test_default_with_multi():
def test_idontexist(): def test_idontexist():
descr = make_description() descr = make_description()
api = Config(descr) api = Config(descr)
api.config.dict() api.value.dict()
raises(AttributeError, "api.option('idontexist').value.get()") raises(AttributeError, "api.option('idontexist').value.get()")

View file

@ -948,13 +948,13 @@ def test_master_slave_requires():
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() is None assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() is None
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.255') api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.255')
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.255' assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.255'
assert api.config.dict() == {'ip_admin_eth0.ip_admin_eth0': ['192.168.1.2', '192.168.1.2'], assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['192.168.1.2', '192.168.1.2'],
'ip_admin_eth0.netmask_admin_eth0': [None, '255.255.255.255']} 'ip_admin_eth0.netmask_admin_eth0': [None, '255.255.255.255']}
# #
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1']) api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1'])
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()") raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()")
ret = api.config.dict() ret = api.value.dict()
assert set(ret.keys()) == set(['ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0']) assert set(ret.keys()) == set(['ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
assert ret['ip_admin_eth0.ip_admin_eth0'] == ['192.168.1.2', '192.168.1.1'] assert ret['ip_admin_eth0.ip_admin_eth0'] == ['192.168.1.2', '192.168.1.1']
assert len(ret['ip_admin_eth0.netmask_admin_eth0']) == 2 assert len(ret['ip_admin_eth0.netmask_admin_eth0']) == 2
@ -962,7 +962,7 @@ def test_master_slave_requires():
assert isinstance(ret['ip_admin_eth0.netmask_admin_eth0'][1], PropertiesOptionError) assert isinstance(ret['ip_admin_eth0.netmask_admin_eth0'][1], PropertiesOptionError)
# #
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.255') api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.255')
ret = api.config.dict() ret = api.value.dict()
assert set(ret.keys()) == set(['ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0']) assert set(ret.keys()) == set(['ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
assert ret['ip_admin_eth0.ip_admin_eth0'] == ['192.168.1.2', '192.168.1.1'] assert ret['ip_admin_eth0.ip_admin_eth0'] == ['192.168.1.2', '192.168.1.1']
assert len(ret['ip_admin_eth0.netmask_admin_eth0']) == 2 assert len(ret['ip_admin_eth0.netmask_admin_eth0']) == 2
@ -995,7 +995,7 @@ def test_master_slave_requires_master():
api.option('activate').value.set(False) api.option('activate').value.set(False)
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()") raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()")
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()") raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
assert api.config.dict() == {'activate': False} assert api.value.dict() == {'activate': False}
def test_master_slave_requires_masterslaves(): def test_master_slave_requires_masterslaves():
@ -1023,7 +1023,7 @@ def test_master_slave_requires_masterslaves():
api.option('activate').value.set(False) api.option('activate').value.set(False)
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()") raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()")
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()") raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
assert api.config.dict() == {'activate': False} assert api.value.dict() == {'activate': False}
def test_master_slave_requires_no_master(): def test_master_slave_requires_no_master():
@ -1053,4 +1053,4 @@ def test_master_slave_requires_no_master():
api.option('activate').value.set(False) api.option('activate').value.set(False)
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()") raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()") raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()")
assert api.config.dict() == {'ip_admin_eth0.ip_admin_eth0': ['192.168.1.2', '192.168.1.1'], 'activate': False} assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['192.168.1.2', '192.168.1.1'], 'activate': False}

View file

@ -207,9 +207,9 @@ def test_symlink_with_master():
master = SymLinkOption('master', ip_admin_eth0) master = SymLinkOption('master', ip_admin_eth0)
od = OptionDescription('root', '', [interface1, master]) od = OptionDescription('root', '', [interface1, master])
api = Config(od) api = Config(od)
assert api.config.dict() == {'ip_admin_eth0.ip_admin_eth0': [], 'ip_admin_eth0.netmask_admin_eth0': [], 'master': []} assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [], 'ip_admin_eth0.netmask_admin_eth0': [], 'master': []}
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val2']) api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val2'])
assert api.config.dict() == {'ip_admin_eth0.ip_admin_eth0': ['val1', 'val2'], 'ip_admin_eth0.netmask_admin_eth0': [None, None], 'master': ['val1', 'val2']} assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['val1', 'val2'], 'ip_admin_eth0.netmask_admin_eth0': [None, None], 'master': ['val1', 'val2']}
def test_symlink_with_slave(): def test_symlink_with_slave():
@ -219,9 +219,9 @@ def test_symlink_with_slave():
slave = SymLinkOption('slave', netmask_admin_eth0) slave = SymLinkOption('slave', netmask_admin_eth0)
od = OptionDescription('root', '', [interface1, slave]) od = OptionDescription('root', '', [interface1, slave])
api = Config(od) api = Config(od)
assert api.config.dict() == {'ip_admin_eth0.ip_admin_eth0': [], 'ip_admin_eth0.netmask_admin_eth0': [], 'slave': []} assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [], 'ip_admin_eth0.netmask_admin_eth0': [], 'slave': []}
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val2']) api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val2'])
assert api.config.dict() == {'ip_admin_eth0.ip_admin_eth0': ['val1', 'val2'], 'ip_admin_eth0.netmask_admin_eth0': [None, None], 'slave': [None, None]} assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['val1', 'val2'], 'ip_admin_eth0.netmask_admin_eth0': [None, None], 'slave': [None, None]}
# #
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == None assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == None
@ -229,7 +229,7 @@ def test_symlink_with_slave():
assert api.option('slave', 1).value.get() == None assert api.option('slave', 1).value.get() == None
# #
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val3') api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val3')
assert api.config.dict() == {'ip_admin_eth0.ip_admin_eth0': ['val1', 'val2'], 'ip_admin_eth0.netmask_admin_eth0': [None, 'val3'], 'slave': [None, 'val3']} assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['val1', 'val2'], 'ip_admin_eth0.netmask_admin_eth0': [None, 'val3'], 'slave': [None, 'val3']}
# #
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == 'val3' assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == 'val3'
@ -255,6 +255,6 @@ def test_symlink_makedict():
descr = OptionDescription("opt", "", descr = OptionDescription("opt", "",
[linkopt, OptionDescription("s1", "", [boolopt])]) [linkopt, OptionDescription("s1", "", [boolopt])])
api = Config(descr) api = Config(descr)
assert api.config.dict() == {'c': False, 's1.b': False} assert api.value.dict() == {'c': False, 's1.b': False}
api.option('s1.b').value.set(True) api.option('s1.b').value.set(True)
assert api.config.dict() == {'c': True, 's1.b': True} assert api.value.dict() == {'c': True, 's1.b': True}

View file

@ -403,16 +403,17 @@ class TiramisuOptionInformation(CommonTiramisuOption):
class TiramisuOptionValue(CommonTiramisuOption): class TiramisuOptionValue(CommonTiramisuOption):
"""manager option's value""" """manager option's value"""
allow_optiondescription = True
slave_need_index = False slave_need_index = False
def get(self): def _o_get(self):
"""get option's value""" """get option's value"""
option = self.option_bag.option option = self.option_bag.option
self._test_slave_index() self._test_slave_index()
return self.subconfig.getattr(self._name, return self.subconfig.getattr(self._name,
self.option_bag) self.option_bag)
def set(self, value): def _o_set(self, value):
"""set a value for a specified option""" """set a value for a specified option"""
option = self.option_bag.option option = self.option_bag.option
self._test_slave_index() self._test_slave_index()
@ -432,7 +433,7 @@ class TiramisuOptionValue(CommonTiramisuOption):
self.subconfig.setattr(value, self.subconfig.setattr(value,
self.option_bag) self.option_bag)
def _pop(self, index): def _m_pop(self, index):
"""pop value for a master option (only for master option)""" """pop value for a master option (only for master option)"""
if self.option_bag.option.impl_is_symlinkoption(): if self.option_bag.option.impl_is_symlinkoption():
raise TypeError(_("can't delete a SymLinkOption")) raise TypeError(_("can't delete a SymLinkOption"))
@ -440,12 +441,12 @@ class TiramisuOptionValue(CommonTiramisuOption):
self.option_bag, self.option_bag,
self.subconfig) self.subconfig)
def reset(self): def _o_reset(self):
"""reset value for a value""" """reset value for a value"""
self._test_slave_index() self._test_slave_index()
self.subconfig.delattr(self.option_bag) self.subconfig.delattr(self.option_bag)
def _len_master(self): def _m_len_master(self):
"""length of master option (only for slave option)""" """length of master option (only for slave option)"""
option = self.option_bag.option option = self.option_bag.option
# for example if index is None # for example if index is None
@ -453,7 +454,7 @@ class TiramisuOptionValue(CommonTiramisuOption):
self._length = self.subconfig.cfgimpl_get_length() self._length = self.subconfig.cfgimpl_get_length()
return self._length return self._length
def _len_slave(self): def _s_len_slave(self):
"""length of slave option (only for slave option)""" """length of slave option (only for slave option)"""
option = self.option_bag.option option = self.option_bag.option
# for example if index is None # for example if index is None
@ -463,22 +464,49 @@ class TiramisuOptionValue(CommonTiramisuOption):
def __getattr__(self, name: str) -> Callable: def __getattr__(self, name: str) -> Callable:
option = self.option_bag.option option = self.option_bag.option
if name == 'list' and isinstance(option, ChoiceOption): if name.startswith('_'):
return self._list # not a valid function
pass
elif name == 'list' and isinstance(option, ChoiceOption):
return self._c_list
elif name == 'pop' and option.impl_is_master_slaves('master'): elif name == 'pop' and option.impl_is_master_slaves('master'):
return self._pop return self._m_pop
elif name == 'len': elif name == 'len':
if option.impl_is_master_slaves('slave'): if option.impl_is_master_slaves('slave'):
return self._len_slave return self._s_len_slave
if option.impl_is_master_slaves('master'): if option.impl_is_master_slaves('master'):
return self._len_master return self._m_len_master
elif name == 'dict' and option.impl_is_optiondescription():
return self._od_dict
elif not option.impl_is_optiondescription():
return getattr(self, '_o_' + name)
raise APIError(_('{} is unknown').format(name)) raise APIError(_('{} is unknown').format(name))
def _list(self): def _c_list(self):
"""all values available for an option (only for choiceoption)""" """all values available for an option (only for choiceoption)"""
option = self.option_bag.option option = self.option_bag.option
return option.impl_get_values(self.option_bag) return option.impl_get_values(self.option_bag)
def _od_dict(self,
flatten=False,
withvalue=undefined,
withoption=None,
fullpath=False):
"""return dict with path as key and value (only for optiondescription)"""
self._get_option()
name = self.option_bag.option.impl_getname()
subconfig = self.subconfig.get_subconfig(name,
self.option_bag)
config_bag = self.option_bag.config_bag
if config_bag.properties and 'warnings' in config_bag.properties:
config_bag = config_bag.copy()
config_bag.properties = config_bag.properties - {'warnings'}
return subconfig.make_dict(config_bag=config_bag,
flatten=flatten,
fullpath=fullpath,
withoption=withoption,
withvalue=withvalue)
def registers(registers: Dict[str, type], prefix: str) -> None: def registers(registers: Dict[str, type], prefix: str) -> None:
for module_name in globals().keys(): for module_name in globals().keys():
@ -521,25 +549,6 @@ class TiramisuOption(CommonTiramisu):
return getattr(self, '_' + subfunc) return getattr(self, '_' + subfunc)
raise APIError(_('please specify a valid sub function ({})').format(subfunc)) raise APIError(_('please specify a valid sub function ({})').format(subfunc))
def dict(self,
flatten=False,
withvalue=undefined,
withoption=None,
fullpath=False):
"""return dict with path as key and value (only for optiondescription)"""
self._get_option()
if not self.config_bag.properties:
config_bag = self.config_bag
else:
config_bag = self.config_bag.copy()
config_bag.properties = self.config_bag.properties - {'warnings'}
return config_bag.context.get_subconfig(self._path,
self.option_bag).make_dict(config_bag=config_bag,
flatten=flatten,
fullpath=fullpath,
withoption=withoption,
withvalue=withvalue)
def _find(self, def _find(self,
name: str, name: str,
value=undefined, value=undefined,
@ -714,6 +723,23 @@ class TiramisuContextValue(TiramisuContext):
self.config_bag.context.reset(path, self.config_bag.context.reset(path,
self.config_bag) self.config_bag)
def dict(self,
flatten=False,
withvalue=undefined,
withoption=None,
fullpath=False):
"""return dict with path as key and value"""
if not self.config_bag.properties:
config_bag = self.config_bag
else:
config_bag = self.config_bag.copy()
config_bag.properties = self.config_bag.properties - {'warnings'}
return config_bag.context.make_dict(config_bag,
flatten=flatten,
fullpath=fullpath,
withoption=withoption,
withvalue=withvalue)
def exportation(self): def exportation(self):
"""export all values""" """export all values"""
return self.config_bag.context.cfgimpl_get_values()._p_.exportation() return self.config_bag.context.cfgimpl_get_values()._p_.exportation()
@ -974,23 +1000,6 @@ class TiramisuContextConfig(TiramisuContext):
raise APIError(_('{} is unknown').format(name)) raise APIError(_('{} is unknown').format(name))
raise APIError(_('{} is unknown').format(name)) raise APIError(_('{} is unknown').format(name))
def dict(self,
flatten=False,
withvalue=undefined,
withoption=None,
fullpath=False):
"""return dict with path as key and value"""
if not self.config_bag.properties:
config_bag = self.config_bag
else:
config_bag = self.config_bag.copy()
config_bag.properties = self.config_bag.properties - {'warnings'}
return config_bag.context.make_dict(config_bag,
flatten=flatten,
fullpath=fullpath,
withoption=withoption,
withvalue=withvalue)
class TiramisuDispatcher: class TiramisuDispatcher:
pass pass