From 6110a37cc7bb2da47a063125020d5986a54dc035 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Sun, 9 Sep 2018 12:21:47 +0200 Subject: [PATCH] option.dict => value.dict --- test/auto/test_auto.py | 8 +-- test/test_cache.py | 32 ++++----- test/test_config_api.py | 32 ++++----- test/test_dyn_optiondescription.py | 48 ++++++------- test/test_masterslaves.py | 16 ++--- test/test_metaconfig.py | 78 ++++++++++----------- test/test_option_consistency.py | 4 +- test/test_option_setting.py | 2 +- test/test_requires.py | 12 ++-- test/test_symlink.py | 14 ++-- tiramisu/api.py | 105 ++++++++++++++++------------- 11 files changed, 180 insertions(+), 171 deletions(-) diff --git a/test/auto/test_auto.py b/test/auto/test_auto.py index 04cffb7..860ab53 100644 --- a/test/auto/test_auto.py +++ b/test/auto/test_auto.py @@ -759,13 +759,13 @@ def autocheck_display(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwa return make_dict = kwargs['make_dict'] 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: - assert(cfg.config(confwrite).config.dict()) == make_dict + assert(cfg.config(confwrite).value.dict()) == make_dict _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: - assert(cfg.config(confwrite).config.dict()) == make_dict_value + assert(cfg.config(confwrite).value.dict()) == make_dict_value @autocheck diff --git a/test/test_cache.py b/test/test_cache.py index 9725a2c..0507e07 100644 --- a/test/test_cache.py +++ b/test/test_cache.py @@ -64,11 +64,11 @@ def test_cache_importation(): cfg = Config(od1) cfg.option('u2').value.set(1) 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) - assert cfg.config.dict() == {'u1': [], 'u2': 2, 'u3': []} + assert cfg.value.dict() == {'u1': [], 'u2': 2, 'u3': []} 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(): @@ -328,7 +328,7 @@ def test_cache_callback(): cfg.property.read_write() if TIRAMISU_VERSION == 2: 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)}, # 'val1': {None: (set([]), 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)}} compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val3': {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)}, # 'val1': {None: (set([]), 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)}, 'val4': {None: ('new', 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)}, # 'val1': {None: (set([]), None)}, # 'val3': {None: (set([]), None)}} @@ -375,7 +375,7 @@ def test_cache_callback(): 'val2': {None: ('new', None)}, 'val3': {None: ('new2', 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)}, # 'val1': {None: (set([]), None)}, # 'val3': {None: (set([]), None)}, @@ -395,7 +395,7 @@ def test_cache_callback(): 'val2': {None: ('new', None)}, 'val3': {None: ('new2', 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)}, # 'val1': {None: (set([]), None)}, # 'val3': {None: (set([]), None)}, @@ -416,7 +416,7 @@ def test_cache_master_and_slaves_master(): maconfig = OptionDescription('rootconfig', '', [interface1]) cfg = Config(maconfig) cfg.property.read_write() - cfg.config.dict() + cfg.value.dict() global_props = ['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings'] val1_props = [] val1_val1_props = ['empty'] @@ -448,7 +448,7 @@ def test_cache_master_and_slaves_master(): 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)}}) assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {} - cfg.config.dict() + cfg.value.dict() if TIRAMISU_VERSION == 2: val_val2 = [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)}, 'val1.val2': {idx_val2: (val_val2, None)}}) cfg.option('val1.val1').value.set([undefined, undefined]) - cfg.config.dict() + cfg.value.dict() 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)}}) assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {} @@ -492,7 +492,7 @@ def test_cache_master_callback(): maconfig = OptionDescription('rootconfig', '', [interface1]) cfg = Config(maconfig) cfg.property.read_write() - cfg.config.dict() + cfg.value.dict() global_props = ['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings'] val1_props = [] 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)}}) 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)}, # 'val1': {None: (set([]), 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: compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'ip_address_service': {None: (None, 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)}, 'activate_service': {None: (set([]), None)}, 'ip_address_service': {None: (set([]), None)}}) @@ -561,7 +561,7 @@ def test_cache_requires(): 'activate_service': {None: (set([]), 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)}, 'activate_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)}}) 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)}, 'activate_service': {None: (set([]), None)}, 'ip_address_service': {None: (set(['disabled']), None)}}) diff --git a/test/test_config_api.py b/test/test_config_api.py index f41831a..d92d628 100644 --- a/test/test_config_api.py +++ b/test/test_config_api.py @@ -64,16 +64,16 @@ def test_make_dict(): config = Config(descr) config.property.read_write() config.permissive.set(frozenset(['hidden'])) - d = config.config.dict() + d = config.value.dict() assert d == {"s1.a": False, "int": 42} config.option('int').value.set(43) config.option('s1.a').value.set(True) - d = config.config.dict() + d = config.value.dict() 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} - raises(ValueError, 'd2 = config.config.dict(withvalue="3")') - d = config.forcepermissive.config.dict() + raises(ValueError, 'd2 = config.value.dict(withvalue="3")') + d = config.forcepermissive.value.dict() assert d == {"s1.a": True, "s1.b": False, "int": 43} @@ -88,9 +88,9 @@ def test_make_dict_with_disabled(): IntOption("int", "", default=42)]) config = Config(descr) config.property.read_only() - assert config.config.dict() == {"s1.a": False, "int": 42} - assert config.forcepermissive.config.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.value.dict() == {"s1.a": False, "int": 42} + assert config.forcepermissive.value.dict() == {"s1.a": False, "int": 42} + 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(): @@ -104,9 +104,9 @@ def test_make_dict_with_disabled_withoption(): IntOption("int", "", default=42)]) config = Config(descr) config.property.read_only() - assert config.config.dict(withoption="a") == {"s1.a": False} - assert config.forcepermissive.config.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.value.dict(withoption="a") == {"s1.a": False} + assert config.forcepermissive.value.dict(withoption="a") == {"s1.a": 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(): @@ -120,7 +120,7 @@ def test_make_dict_with_disabled_in_callback(): IntOption("int", "", default=42)]) config = Config(descr) config.property.read_only() - d = config.config.dict() + d = config.value.dict() assert d == {"s1.a": False, "int": 42} @@ -137,10 +137,10 @@ def test_make_dict_fullpath(): IntOption("introot", "", default=42)]) config = Config(descr) config.property.read_only() - assert config.config.dict() == {"opt.s1.a": False, "opt.int": 42, "introot": 42} - assert config.option('opt').dict() == {"s1.a": False, "int": 42} - assert config.config.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.value.dict() == {"opt.s1.a": False, "opt.int": 42, "introot": 42} + assert config.option('opt').value.dict() == {"s1.a": False, "int": 42} + assert config.value.dict(fullpath=True) == {"opt.s1.a": False, "opt.int": 42, "introot": 42} + assert config.option('opt').value.dict(fullpath=True) == {"opt.s1.a": False, "opt.int": 42} def test_find_in_config(): diff --git a/test/test_dyn_optiondescription.py b/test/test_dyn_optiondescription.py index eff3476..42dcfcb 100644 --- a/test/test_dyn_optiondescription.py +++ b/test/test_dyn_optiondescription.py @@ -57,7 +57,7 @@ def test_build_dyndescription(): dod = DynOptionDescription('dod', '', [st1], callback=return_list) od1 = OptionDescription('od', '', [dod]) 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(): @@ -65,7 +65,7 @@ def test_build_dyndescription_raise(): dod = DynOptionDescription('dod', '', [st1], callback=return_raise) od1 = OptionDescription('od', '', [dod]) cfg = Config(od1) - raises(ConfigError, "cfg.config.dict()") + raises(ConfigError, "cfg.value.dict()") def test_build_dyndescription_not_list(): @@ -73,7 +73,7 @@ def test_build_dyndescription_not_list(): dod = DynOptionDescription('dod', '', [st1], callback=return_str) od1 = OptionDescription('od', '', [dod]) cfg = Config(od1) - raises(ValueError, "cfg.config.dict()") + raises(ValueError, "cfg.value.dict()") def test_subpath_dyndescription(): @@ -82,7 +82,7 @@ def test_subpath_dyndescription(): od1 = OptionDescription('od', '', [dod]) od2 = OptionDescription('od', '', [od1]) 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(): @@ -290,7 +290,7 @@ def test_build_dyndescription_context(): dod = DynOptionDescription('dod', '', [st1], callback=return_list, callback_params=Params(ParamOption(val1))) od1 = OptionDescription('od', '', [dod, val1]) 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(): @@ -300,7 +300,7 @@ def test_subpath_dyndescription_context(): od1 = OptionDescription('od', '', [dod, val1]) od2 = OptionDescription('od', '', [od1]) 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(): @@ -637,11 +637,11 @@ def test_makedict_dyndescription_context(): od2 = OptionDescription('od', '', [od]) api = Config(od2) 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.config.dict(flatten=True) == {'val1': ['val1', 'val2'], 'stval1': 'yes', 'stval2': None} - assert api.config.dict(withoption='stval1') == {'od.dodval1.stval1': 'yes'} - assert api.option('od').dict(withoption='stval1') == {'dodval1.stval1': 'yes'} - assert api.option('od.dodval1').dict(withoption='stval1') == {'stval1': 'yes'} + assert api.value.dict() == {'od.val1': ['val1', 'val2'], 'od.dodval1.stval1': 'yes', 'od.dodval2.stval2': None} + assert api.value.dict(flatten=True) == {'val1': ['val1', 'val2'], 'stval1': 'yes', 'stval2': None} + assert api.value.dict(withoption='stval1') == {'od.dodval1.stval1': 'yes'} + assert api.option('od').value.dict(withoption='stval1') == {'dodval1.stval1': 'yes'} + assert api.option('od.dodval1').value.dict(withoption='stval1') == {'stval1': 'yes'} def test_find_dyndescription_context(): @@ -901,14 +901,14 @@ def test_masterslaves_dyndescription(): api = Config(od2) 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.stval2.st1val2.st1val2').value.get() == [] assert api.option('od.stval1.st1val1.st1val1').owner.isdefault() assert api.option('od.stval2.st1val2.st1val2').owner.isdefault() # 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.st2val1', 0).value.get() == None assert api.option('od.stval2.st1val2.st1val2').value.get() == [] @@ -983,14 +983,14 @@ def test_masterslaves_dyndescription_param(): od2 = OptionDescription('od', '', [od]) cfg = Config(od2) 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.stval2.st1val2.st1val2').value.get() == [] assert cfg.option('od.stval1.st1val1.st1val1').owner.get() == owners.default assert cfg.option('od.stval2.st1val2.st1val2').owner.get() == owners.default # 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.st2val1', 0).value.get() == None 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.val2', 0).value.set('val1') 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.stval2.st1val2.st1val2').value.get() == [] assert cfg.option('od.stval1.st1val1.st1val1').owner.get() == owners.default assert cfg.option('od.stval2.st1val2.st1val2').owner.get() == owners.default # 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.st2val1', 0).value.get() == None assert cfg.option('od.stval2.st1val2.st1val2').value.get() == [] @@ -1270,14 +1270,14 @@ def test_masterslaves_callback_dyndescription(): od2 = OptionDescription('od', '', [od1]) api = Config(od2) 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.stval2.st1val2.st1val2').value.get() == [] assert api.option('od.stval1.st1val1.st1val1').owner.isdefault() assert api.option('od.stval2.st1val2.st1val2').owner.isdefault() # 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.st2val1', 0).value.get() == 'yes' assert api.option('od.stval2.st1val2.st1val2').value.get() == [] @@ -1362,7 +1362,7 @@ def test_masterslaves_callback_samegroup_dyndescription(): od2 = OptionDescription('od', '', [od1]) api = Config(od2) 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.st3val1': [], 'od.stval2.st1val2.st1val2': [], @@ -1374,7 +1374,7 @@ def test_masterslaves_callback_samegroup_dyndescription(): assert api.option('od.stval2.st1val2.st1val2').owner.isdefault() # 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.st3val1': [None], 'od.stval2.st1val2.st1val2': [], @@ -1386,7 +1386,7 @@ def test_masterslaves_callback_samegroup_dyndescription(): assert api.option('od.stval2.st1val2.st1val2').owner.isdefault() # 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.st3val1': ['yes'], 'od.stval2.st1val2.st1val2': [], @@ -1439,7 +1439,7 @@ def test_invalid_samevalue_dyndescription(): dod = DynOptionDescription('dod', '', [st1], callback=return_same_list) od1 = OptionDescription('od', '', [dod]) cfg = Config(od1) - raises(ValueError, "cfg.config.dict()") + raises(ValueError, "cfg.value.dict()") def test_invalid_name_dyndescription(): @@ -1447,4 +1447,4 @@ def test_invalid_name_dyndescription(): dod = DynOptionDescription('dod', '', [st1], callback=return_wrong_list) od1 = OptionDescription('od', '', [dod]) cfg = Config(od1) - raises(ValueError, "cfg.config.dict()") + raises(ValueError, "cfg.value.dict()") diff --git a/test/test_masterslaves.py b/test/test_masterslaves.py index 292a81c..d5516d4 100644 --- a/test/test_masterslaves.py +++ b/test/test_masterslaves.py @@ -70,12 +70,12 @@ def test_base_config(): 'general.mode_conteneur_actif': False, 'general.time_zone': 'Paris', 'interface1.ip_admin_eth0.netmask_admin_eth0': None, 'general.nom_machine': '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, 'ip_admin_eth0': None, 'time_zone': 'Paris', 'numero_etab': None, 'netmask_admin_eth0': None, 'nom_machine': 'eoleng', 'activer_proxy_client': 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(): @@ -89,10 +89,10 @@ def test_make_dict_filter(): result = {} for key, value in subresult.items(): result['general.' + key] = value - assert api.option('creole').dict(withoption='numero_etab') == result - raises(AttributeError, "api.option('creole').dict(withoption='numero_etab', withvalue='toto')") - assert api.option('creole').dict(withoption='numero_etab', withvalue=None) == result - assert api.option('creole.general').dict(withoption='numero_etab') == subresult + assert api.option('creole').value.dict(withoption='numero_etab') == result + raises(AttributeError, "api.option('creole').value.dict(withoption='numero_etab', withvalue='toto')") + assert api.option('creole').value.dict(withoption='numero_etab', withvalue=None) == result + assert api.option('creole.general').value.dict(withoption='numero_etab') == subresult 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]) od = OptionDescription('root', '', [interface1]) 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']) - 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(): diff --git a/test/test_metaconfig.py b/test/test_metaconfig.py index 9565fb2..f73bc48 100644 --- a/test/test_metaconfig.py +++ b/test/test_metaconfig.py @@ -133,7 +133,7 @@ def test_find(): assert len(ret) == 1 assert 1 == ret[0].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]} @@ -581,7 +581,7 @@ def test_meta_properties_meta(): conf2.property.read_write() meta = MetaConfig([conf1, conf2]) meta.property.read_write() - assert meta.config('conf1').config.dict() == {} + assert meta.config('conf1').value.dict() == {} def test_meta_exception_meta(): @@ -607,17 +607,17 @@ def test_meta_callback(): cfg = Config(maconfig, session_id='cfg') meta = MetaConfig([cfg]) 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') - #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.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') - #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.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() @@ -632,36 +632,36 @@ def test_meta_callback_slave(): cfg = Config(maconfig, session_id='cfg1') meta = MetaConfig([cfg]) 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') - 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.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.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() - 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') - 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') - 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.config('cfg1').option('val1.val3', 0).value.reset() 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() - 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']) - 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') - 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']) - 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.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(): @@ -707,17 +707,17 @@ def test_meta_properties_meta_copy(): meta2 = conf3.config.meta() assert meta != meta2 - assert meta.config('conf1').config.dict() == {'ip_admin_eth0': ['192.168.1.1']} - assert meta.config('conf2').config.dict() == {'ip_admin_eth0': ['192.168.1.1']} - assert meta.config('conf3').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').value.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']) - assert meta.config('conf1').config.dict() == {'ip_admin_eth0': ['192.168.1.2']} - assert meta.config('conf2').config.dict() == {'ip_admin_eth0': ['192.168.1.2']} - assert meta.config('conf3').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').value.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) - assert meta.config('conf1').config.dict() == {'ip_admin_eth0': ['192.168.1.3']} - assert meta.config('conf2').config.dict() == {'ip_admin_eth0': ['192.168.1.3']} - assert meta.config('conf3').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').value.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(): @@ -737,17 +737,17 @@ def test_meta_properties_meta_deepcopy(): assert meta != meta2 assert meta.permissive.get() == meta2.permissive.get() - assert meta.config('conf1').config.dict() == {'ip_admin_eth0': ['192.168.1.1']} - assert meta.config('conf2').config.dict() == {'ip_admin_eth0': ['192.168.1.1']} - assert meta2.config('conf3').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').value.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']) - assert meta.config('conf1').config.dict() == {'ip_admin_eth0': ['192.168.1.2']} - assert meta.config('conf2').config.dict() == {'ip_admin_eth0': ['192.168.1.2']} - assert meta2.config('conf3').config.dict() == {'ip_admin_eth0': ['192.168.1.1']} + assert meta.config('conf1').value.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').value.dict() == {'ip_admin_eth0': ['192.168.1.1']} 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('conf2').config.dict() == {'ip_admin_eth0': ['192.168.1.3']} - assert meta2.config('conf3').config.dict() == {'ip_admin_eth0': ['192.168.1.1']} + assert meta.config('conf1').value.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').value.dict() == {'ip_admin_eth0': ['192.168.1.1']} def test_meta_properties_meta_set_value(): @@ -760,7 +760,7 @@ def test_meta_properties_meta_set_value(): conf2.property.read_write() meta = MetaConfig([conf1, conf2]) 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) assert len(ret) == 2 assert isinstance(ret[0], PropertiesOptionError) diff --git a/test/test_option_consistency.py b/test/test_option_consistency.py index 6f991a1..a37977b 100644 --- a/test/test_option_consistency.py +++ b/test/test_option_consistency.py @@ -260,7 +260,7 @@ def test_consistency_not_equal_masterslave(): api.option('a.b', 0).value.set(2) api.option('a.a').value.reset() api.option('a.a').value.set([1]) - api.config.dict() + api.value.dict() def test_consistency_not_equal_masterslave_error_multi1(): @@ -891,7 +891,7 @@ def test_consistency_network_netmask_mandatory(): api = Config(od2) api.property.read_only() api.property.pop('mandatory') - api.config.dict() + api.value.dict() def test_consistency_has_dependency(): diff --git a/test/test_option_setting.py b/test/test_option_setting.py index 2d041e5..10a884f 100644 --- a/test/test_option_setting.py +++ b/test/test_option_setting.py @@ -99,7 +99,7 @@ def test_default_with_multi(): def test_idontexist(): descr = make_description() api = Config(descr) - api.config.dict() + api.value.dict() raises(AttributeError, "api.option('idontexist').value.get()") diff --git a/test/test_requires.py b/test/test_requires.py index cca6174..f892d4a 100644 --- a/test/test_requires.py +++ b/test/test_requires.py @@ -948,13 +948,13 @@ def test_master_slave_requires(): 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') 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']} # 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 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 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 @@ -962,7 +962,7 @@ def test_master_slave_requires(): 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') - 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 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 @@ -995,7 +995,7 @@ def test_master_slave_requires_master(): 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.netmask_admin_eth0', 0).value.get()") - assert api.config.dict() == {'activate': False} + assert api.value.dict() == {'activate': False} def test_master_slave_requires_masterslaves(): @@ -1023,7 +1023,7 @@ def test_master_slave_requires_masterslaves(): 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.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(): @@ -1053,4 +1053,4 @@ def test_master_slave_requires_no_master(): 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', 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} diff --git a/test/test_symlink.py b/test/test_symlink.py index e990408..ab08b05 100644 --- a/test/test_symlink.py +++ b/test/test_symlink.py @@ -207,9 +207,9 @@ def test_symlink_with_master(): master = SymLinkOption('master', ip_admin_eth0) od = OptionDescription('root', '', [interface1, master]) 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']) - 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(): @@ -219,9 +219,9 @@ def test_symlink_with_slave(): slave = SymLinkOption('slave', netmask_admin_eth0) od = OptionDescription('root', '', [interface1, slave]) 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']) - 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', 1).value.get() == None @@ -229,7 +229,7 @@ def test_symlink_with_slave(): assert api.option('slave', 1).value.get() == None # 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', 1).value.get() == 'val3' @@ -255,6 +255,6 @@ def test_symlink_makedict(): descr = OptionDescription("opt", "", [linkopt, OptionDescription("s1", "", [boolopt])]) 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) - assert api.config.dict() == {'c': True, 's1.b': True} + assert api.value.dict() == {'c': True, 's1.b': True} diff --git a/tiramisu/api.py b/tiramisu/api.py index 5d35588..6d2ab2e 100644 --- a/tiramisu/api.py +++ b/tiramisu/api.py @@ -403,16 +403,17 @@ class TiramisuOptionInformation(CommonTiramisuOption): class TiramisuOptionValue(CommonTiramisuOption): """manager option's value""" + allow_optiondescription = True slave_need_index = False - def get(self): + def _o_get(self): """get option's value""" option = self.option_bag.option self._test_slave_index() return self.subconfig.getattr(self._name, self.option_bag) - def set(self, value): + def _o_set(self, value): """set a value for a specified option""" option = self.option_bag.option self._test_slave_index() @@ -432,7 +433,7 @@ class TiramisuOptionValue(CommonTiramisuOption): self.subconfig.setattr(value, self.option_bag) - def _pop(self, index): + def _m_pop(self, index): """pop value for a master option (only for master option)""" if self.option_bag.option.impl_is_symlinkoption(): raise TypeError(_("can't delete a SymLinkOption")) @@ -440,12 +441,12 @@ class TiramisuOptionValue(CommonTiramisuOption): self.option_bag, self.subconfig) - def reset(self): + def _o_reset(self): """reset value for a value""" self._test_slave_index() self.subconfig.delattr(self.option_bag) - def _len_master(self): + def _m_len_master(self): """length of master option (only for slave option)""" option = self.option_bag.option # for example if index is None @@ -453,7 +454,7 @@ class TiramisuOptionValue(CommonTiramisuOption): self._length = self.subconfig.cfgimpl_get_length() return self._length - def _len_slave(self): + def _s_len_slave(self): """length of slave option (only for slave option)""" option = self.option_bag.option # for example if index is None @@ -463,22 +464,49 @@ class TiramisuOptionValue(CommonTiramisuOption): def __getattr__(self, name: str) -> Callable: option = self.option_bag.option - if name == 'list' and isinstance(option, ChoiceOption): - return self._list + if name.startswith('_'): + # 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'): - return self._pop + return self._m_pop elif name == 'len': if option.impl_is_master_slaves('slave'): - return self._len_slave + return self._s_len_slave 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)) - def _list(self): + def _c_list(self): """all values available for an option (only for choiceoption)""" option = self.option_bag.option 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: for module_name in globals().keys(): @@ -521,25 +549,6 @@ class TiramisuOption(CommonTiramisu): return getattr(self, '_' + 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, name: str, value=undefined, @@ -714,6 +723,23 @@ class TiramisuContextValue(TiramisuContext): self.config_bag.context.reset(path, 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): """export all values""" 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)) - 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: pass