diff --git a/tests/config.py b/tests/config.py index e21b12e..721adf8 100644 --- a/tests/config.py +++ b/tests/config.py @@ -42,3 +42,24 @@ def global_owner(config, config_type): @pytest.fixture(params=PARAMS) def config_type(request): return request.param + + +def parse_od_get(dico): + ret = {} + for k, v in dico.items(): + if k.isoptiondescription(): + if k.isleadership(): + leader_path = k.leader().path() + ret_leadership = [] + for variable, value in v.items(): + if variable.path() == leader_path: + for val in value: + ret_leadership.append({leader_path: val}) + else: + ret_leadership[variable.index()][variable.path()] = value + ret[leader_path] = ret_leadership + else: + ret.update(parse_od_get(v)) + else: + ret[k.path()] = v + return ret diff --git a/tests/test_cache.py b/tests/test_cache.py index f46b877..eb1038d 100644 --- a/tests/test_cache.py +++ b/tests/test_cache.py @@ -54,12 +54,13 @@ def test_cache_importation(): od1 = make_description() cfg = Config(od1) cfg.option('u2').value.set(1) + values = cfg._config_bag.context._impl_values_cache export = cfg.value.exportation() - assert cfg.value.dict() == {'u1': [], 'u2': 1, 'u3': []} + compare(values.get_cached(), {'u2': {None: (1, None)}}) cfg.option('u2').value.set(2) - assert cfg.value.dict() == {'u1': [], 'u2': 2, 'u3': []} + compare(values.get_cached(), {'u2': {None: (2, None)}}) cfg.value.importation(export) - assert cfg.value.dict() == {'u1': [], 'u2': 1, 'u3': []} + compare(values.get_cached(), {}) # assert not list_sessions() @@ -309,19 +310,19 @@ def test_cache_callback(): od1 = OptionDescription('rootconfig', '', [val1, val2, val3, val4, val5]) cfg = Config(od1) cfg.property.read_write() - cfg.value.dict() + cfg.value.get() values = cfg._config_bag.context._impl_values_cache settings = cfg._config_bag.context.properties_cache compare(values.get_cached(), {'val1': {None: ('val', None)}, - 'val2': {None: ('val', None)}, - 'val3': {None: ('yes', None)}, - 'val4': {None: ('val', None)}, - 'val5': {None: (['yes'], None)}}) + 'val2': {None: ('val', None)}, + 'val3': {None: ('yes', None)}, + 'val4': {None: ('val', None)}, + 'val5': {None: (['yes'], None)}}) cfg.option('val1').value.set('new') compare(values.get_cached(), {'val3': {None: ('yes', None)}, 'val1': {None: ('new', None)}, 'val5': {None: (['yes'], None)}}) - cfg.value.dict() + cfg.value.get() compare(values.get_cached(), {'val1': {None: ('new', None)}, 'val2': {None: ('new', None)}, 'val3': {None: ('yes', None)}, @@ -334,7 +335,7 @@ def test_cache_callback(): 'val1': {None: ('new', None)}, 'val3': {None: ('new2', None, True)}, 'val5': {None: (['yes'], None)}}) - cfg.value.dict() + cfg.value.get() compare(values.get_cached(), {'val1': {None: ('new', None)}, 'val2': {None: ('new', None)}, 'val3': {None: ('new2', None)}, @@ -346,7 +347,7 @@ def test_cache_callback(): 'val3': {None: ('new2', None)}, 'val4': {None: ('new3', None, True)}, 'val5': {None: (['yes'], None)}}) - cfg.value.dict() + cfg.value.get() compare(values.get_cached(), {'val1': {None: ('new', None)}, 'val2': {None: ('new', None)}, 'val3': {None: ('new2', None)}, @@ -362,7 +363,7 @@ def test_cache_leader_and_followers(): od1 = OptionDescription('rootconfig', '', [interface1]) cfg = Config(od1) cfg.property.read_write() - cfg.value.dict() + cfg.value.get() global_props = ['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value'] val1_props = [] val1_val1_props = ['empty', 'unique'] @@ -385,10 +386,10 @@ def test_cache_leader_and_followers(): cfg.option('val1.val1').value.set([None]) val_val2_props = {idx_val2: (val1_val2_props, None), None: (set(), None)} compare(settings.get_cached(), {None: {None: (set(global_props), None)}, - 'val1.val1': {None: (val1_val1_props, None)}, +# 'val1.val1': {None: (val1_val1_props, None)}, }) compare(values.get_cached(), {'val1.val1': {None: ([None], None, True)}}) - cfg.value.dict() + cfg.value.get() #has value idx_val2 = 0 val_val2 = None @@ -401,7 +402,7 @@ def test_cache_leader_and_followers(): 'val1.val2': {idx_val2: (val_val2, None)}, }) cfg.option('val1.val1').value.set([None, None]) - cfg.value.dict() + cfg.value.get() cfg.option('val1.val2', 1).value.set('oui') compare(settings.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)}}) compare(values.get_cached(), {'val1.val2': {1: ('oui', None, True)}}) @@ -416,7 +417,7 @@ def test_cache_leader_callback(): od1 = OptionDescription('rootconfig', '', [interface1]) cfg = Config(od1) cfg.property.read_write() - cfg.value.dict() + cfg.value.get() global_props = ['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value'] val1_props = [] val1_val1_props = ['empty', 'unique'] @@ -434,11 +435,11 @@ def test_cache_leader_callback(): compare(values.get_cached(), {'val1.val1': {None: ([], None)}}) cfg.option('val1.val1').value.set([None]) compare(settings.get_cached(), {None: {None: (set(global_props), None)}, - 'val1.val1': {None: (val1_val1_props, None)}, +# 'val1.val1': {None: (val1_val1_props, None)}, }) compare(values.get_cached(), {'val1.val1': {None: ([None], None, True)}}) - cfg.value.dict() + cfg.value.get() # assert not list_sessions() @@ -463,7 +464,7 @@ def test_cache_requires(): compare(values.get_cached(), {'ip_address_service': {None: (None, None)}, 'activate_service': {None: (True, None)}}) - cfg.value.dict() + cfg.value.get() compare(settings.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)}, 'activate_service': {None: (set([]), None)}, 'ip_address_service': {None: (set([]), None)}}) @@ -475,7 +476,7 @@ def test_cache_requires(): 'activate_service': {None: (set([]), None)}}) compare(values.get_cached(), {'activate_service': {None: (True, None)}, 'ip_address_service': {None: ('1.1.1.1', None, True)}}) - cfg.value.dict() + cfg.value.get() compare(settings.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)}, 'activate_service': {None: (set([]), None)}, 'ip_address_service': {None: (set([]), None)}}) @@ -486,7 +487,7 @@ def test_cache_requires(): compare(settings.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)}}) compare(values.get_cached(), {'activate_service': {None: (False, None)}}) - cfg.value.dict() + cfg.value.get() compare(settings.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)}, 'activate_service': {None: (set([]), None)}, 'ip_address_service': {None: (set(['disabled']), None)}}) diff --git a/tests/test_config_api.py b/tests/test_config_api.py index 79727c2..577ff04 100644 --- a/tests/test_config_api.py +++ b/tests/test_config_api.py @@ -3,7 +3,7 @@ from pytest import raises from .autopath import do_autopath do_autopath() -from .config import config_type, get_config, value_list, global_owner +from .config import config_type, get_config, value_list, global_owner, parse_od_get from tiramisu import Config, IntOption, FloatOption, StrOption, ChoiceOption, \ BoolOption, FilenameOption, SymLinkOption, IPOption, \ @@ -76,14 +76,12 @@ def test_make_dict(config_type): cfg.property.read_write() cfg.permissive.add('hidden') cfg = get_config(cfg, config_type) - d = cfg.value.dict() - assert d == {"s1.a": False, "int": 42} + assert parse_od_get(cfg.value.get()) == {"s1.a": False, "int": 42} cfg.option('int').value.set(43) cfg.option('s1.a').value.set(True) - d = cfg.value.dict() - assert d == {"s1.a": True, "int": 43} + assert parse_od_get(cfg.value.get()) == {"s1.a": True, "int": 43} if config_type == 'tiramisu': - assert cfg.forcepermissive.value.dict() == {"s1.a": True, "s1.b": False, "int": 43} + assert parse_od_get(cfg.forcepermissive.value.get()) == {"s1.a": True, "s1.b": False, "int": 43} # assert not list_sessions() @@ -98,22 +96,7 @@ def test_make_dict_sub(config_type): cfg.property.read_write() cfg.permissive.add('hidden') cfg = get_config(cfg, config_type) - assert cfg.option('s1').value.dict() == {'s1.a': False} - - -def test_make_dict_not_value(config_type): - "serialization part of config to a dict" - od1 = OptionDescription("opt", "", [ - OptionDescription("s1", "", [ - BoolOption("a", "", default=False), - BoolOption("b", "", default=False, properties=('hidden',))]), - IntOption("int", "", default=42)]) - cfg = Config(od1) - cfg.property.read_write() - cfg.permissive.add('hidden') - cfg = get_config(cfg, config_type) - with raises(ConfigError): - cfg.option('s1.a').value.dict() + assert parse_od_get(cfg.option('s1').value.get()) == {'s1.a': False} def test_make_dict_with_disabled(config_type): @@ -128,10 +111,10 @@ def test_make_dict_with_disabled(config_type): cfg = Config(od1) cfg.property.read_only() cfg = get_config(cfg, config_type) - assert cfg.value.dict() == {"s1.a": False, "int": 42} + assert parse_od_get(cfg.value.get()) == {"s1.a": False, "int": 42} if config_type == 'tiramisu': - assert cfg.forcepermissive.value.dict() == {"s1.a": False, "int": 42} - assert cfg.unrestraint.value.dict() == {"int": 42, "s1.a": False, "s1.b": False, "s2.a": False, "s2.b": False} + assert parse_od_get(cfg.forcepermissive.value.get()) == {"s1.a": False, "int": 42} + assert parse_od_get(cfg.unrestraint.value.get()) == {"int": 42, "s1.a": False, "s1.b": False, "s2.a": False, "s2.b": False} # assert not list_sessions() @@ -147,8 +130,7 @@ def test_make_dict_with_disabled_in_callback(config_type): cfg = Config(od1) cfg.property.read_only() cfg = get_config(cfg, config_type) - d = cfg.value.dict() - assert d == {"s1.a": False, "int": 42} + assert parse_od_get(cfg.value.get()) == {"s1.a": False, "int": 42} # assert not list_sessions() @@ -166,150 +148,150 @@ def test_make_dict_fullpath(config_type): cfg = Config(od1) cfg.property.read_only() cfg = get_config(cfg, config_type) - assert cfg.value.dict() == {"opt.s1.a": False, "opt.int": 42, "introot": 42} - assert cfg.option('opt').value.dict() == {"opt.s1.a": False, "opt.int": 42} + assert parse_od_get(cfg.value.get()) == {"opt.s1.a": False, "opt.int": 42, "introot": 42} + assert parse_od_get(cfg.option('opt').value.get()) == {"opt.s1.a": False, "opt.int": 42} # assert not list_sessions() -def test_find_in_config(): - "finds option in config" - od1 = make_description() - cfg = Config(od1) - cfg.property.read_only() - cfg.permissive.add('hidden') - ret = list(cfg.option.find('dummy')) - assert len(ret) == 1 - _is_same_opt(ret[0].get(), cfg.option('gc.dummy').get()) - # - ret_find = cfg.option.find('dummy', first=True) - ret = ret_find.get() - _is_same_opt(ret, cfg.option('gc.dummy').get()) - # - ret = list(cfg.option.find('float')) - assert len(ret) == 2 - _is_same_opt(ret[0].get(), cfg.option('gc.float').get()) - _is_same_opt(ret[1].get(), cfg.option('float').get()) - # - ret = cfg.option.find('bool', first=True) - _is_same_opt(ret.get(), cfg.option('gc.gc2.bool').get()) - ret = cfg.option.find('bool', value=True, first=True) - _is_same_opt(ret.get(), cfg.option('bool').get()) - ret = cfg.option.find('dummy', first=True) - _is_same_opt(ret.get(), cfg.option('gc.dummy').get()) - ret = cfg.option.find('float', first=True) - _is_same_opt(ret.get(), cfg.option('gc.float').get()) - ret = list(cfg.option.find('prop')) - assert len(ret) == 1 - _is_same_opt(ret[0].get(), cfg.option('gc.prop').get()) - # - ret = list(cfg.option.find('prop', value=None)) - assert len(ret) == 1 - ret = list(cfg.option.find('prop')) - assert len(ret) == 1 - _is_same_opt(ret[0].get(), cfg.option('gc.prop').get()) - # - cfg.property.read_write() - with raises(AttributeError): - ret = cfg.option.find('prop') - assert ret.get() - ret = list(cfg.unrestraint.option.find(name='prop')) - assert len(ret) == 2 - _is_same_opt(ret[0].get(), cfg.unrestraint.option('gc.gc2.prop').get()) - _is_same_opt(ret[1].get(), cfg.forcepermissive.option('gc.prop').get()) - # - ret = list(cfg.forcepermissive.option.find('prop')) - assert len(ret) == 1 - _is_same_opt(ret[0].get(), cfg.forcepermissive.option('gc.prop').get()) - # - ret = cfg.forcepermissive.option.find('prop', first=True) - _is_same_opt(ret.get(), cfg.forcepermissive.option('gc.prop').get()) - # combinaison of filters - ret = list(cfg.unrestraint.option.find('prop', type=BoolOption)) - assert len(ret) == 1 - _is_same_opt(ret[0].get(), cfg.unrestraint.option('gc.gc2.prop').get()) - ret = cfg.unrestraint.option.find('prop', type=BoolOption, first=True) - _is_same_opt(ret.get(), cfg.unrestraint.option('gc.gc2.prop').get()) - # - ret = list(cfg.option.find('dummy', value=False)) - assert len(ret) == 1 - _is_same_opt(ret[0].get(), cfg.option('gc.dummy').get()) - # - ret = cfg.option.find('dummy', value=False, first=True) - _is_same_opt(ret.get(), cfg.option('gc.dummy').get()) - #subcfgig - ret = list(cfg.option('gc').find('dummy')) - assert len(ret) == 1 - _is_same_opt(ret[0].get(), cfg.option('gc.dummy').get()) - # - ret = list(cfg.option('gc').find('float')) - assert len(ret) == 1 - _is_same_opt(ret[0].get(), cfg.option('gc.float').get()) - # - ret = list(cfg.option('gc.gc2').find('bool')) - assert len(ret) == 1 - _is_same_opt(ret[0].get(), cfg.option('gc.gc2.bool').get()) - ret = cfg.option('gc').find('bool', value=False, first=True) - _is_same_opt(ret.get(), cfg.option('gc.gc2.bool').get()) - # - with raises(AttributeError): - ret = cfg.option('gc').find('bool', value=True, first=True) - assert ret.get() - # - with raises(AttributeError): - ret = cfg.option('gc').find('wantref') - ret.get() - # - ret = list(cfg.unrestraint.option('gc').find('prop')) - assert len(ret) == 2 - _is_same_opt(ret[0].get(), cfg.unrestraint.option('gc.gc2.prop').get()) - _is_same_opt(ret[1].get(), cfg.forcepermissive.option('gc.prop').get()) - # - cfg.property.read_only() - ret = list(cfg.option('gc').find('prop')) - assert len(ret) == 1 - _is_same_opt(ret[0].get(), cfg.option('gc.prop').get()) - # not OptionDescription - with raises(AttributeError): - cfg.option.find('gc', first=True) - with raises(AttributeError): - cfg.option.find('gc2', first=True) -# assert not list_sessions() - - -def test_find_multi(): - b = BoolOption('bool', '', multi=True, properties=('notunique',)) - od1 = OptionDescription('od', '', [b]) - cfg = Config(od1) - # - with raises(AttributeError): - list(cfg.option.find('bool', value=True)) - with raises(AttributeError): - list(cfg.option.find('bool', value=True, first=True)) - cfg.option('bool').value.set([False]) - with raises(AttributeError): - list(cfg.option.find('bool', value=True)) - with raises(AttributeError): - list(cfg.option.find('bool', value=True, first=True)) - cfg.option('bool').value.set([False, False]) - with raises(AttributeError): - list(cfg.option.find('bool', value=True)) - with raises(AttributeError): - list(cfg.option.find('bool', value=True, first=True)) - cfg.option('bool').value.set([False, False, True]) - ret = list(cfg.option.find('bool', value=True)) - assert len(ret) == 1 - _is_same_opt(ret[0].get(), b) - ret = cfg.option.find('bool', value=True, first=True) - _is_same_opt(ret.get(), b) -# assert not list_sessions() - - -def test_does_not_find_in_config(): - od1 = make_description() - cfg = Config(od1) - with raises(AttributeError): - list(cfg.option.find('IDontExist')) -# assert not list_sessions() +#def test_find_in_config(): +# "finds option in config" +# od1 = make_description() +# cfg = Config(od1) +# cfg.property.read_only() +# cfg.permissive.add('hidden') +# ret = list(cfg.option.find('dummy')) +# assert len(ret) == 1 +# _is_same_opt(ret[0].get(), cfg.option('gc.dummy').get()) +# # +# ret_find = cfg.option.find('dummy', first=True) +# ret = ret_find.get() +# _is_same_opt(ret, cfg.option('gc.dummy').get()) +# # +# ret = list(cfg.option.find('float')) +# assert len(ret) == 2 +# _is_same_opt(ret[0].get(), cfg.option('gc.float').get()) +# _is_same_opt(ret[1].get(), cfg.option('float').get()) +# # +# ret = cfg.option.find('bool', first=True) +# _is_same_opt(ret.get(), cfg.option('gc.gc2.bool').get()) +# ret = cfg.option.find('bool', value=True, first=True) +# _is_same_opt(ret.get(), cfg.option('bool').get()) +# ret = cfg.option.find('dummy', first=True) +# _is_same_opt(ret.get(), cfg.option('gc.dummy').get()) +# ret = cfg.option.find('float', first=True) +# _is_same_opt(ret.get(), cfg.option('gc.float').get()) +# ret = list(cfg.option.find('prop')) +# assert len(ret) == 1 +# _is_same_opt(ret[0].get(), cfg.option('gc.prop').get()) +# # +# ret = list(cfg.option.find('prop', value=None)) +# assert len(ret) == 1 +# ret = list(cfg.option.find('prop')) +# assert len(ret) == 1 +# _is_same_opt(ret[0].get(), cfg.option('gc.prop').get()) +# # +# cfg.property.read_write() +# with raises(AttributeError): +# ret = cfg.option.find('prop') +# assert ret.get() +# ret = list(cfg.unrestraint.option.find(name='prop')) +# assert len(ret) == 2 +# _is_same_opt(ret[0].get(), cfg.unrestraint.option('gc.gc2.prop').get()) +# _is_same_opt(ret[1].get(), cfg.forcepermissive.option('gc.prop').get()) +# # +# ret = list(cfg.forcepermissive.option.find('prop')) +# assert len(ret) == 1 +# _is_same_opt(ret[0].get(), cfg.forcepermissive.option('gc.prop').get()) +# # +# ret = cfg.forcepermissive.option.find('prop', first=True) +# _is_same_opt(ret.get(), cfg.forcepermissive.option('gc.prop').get()) +# # combinaison of filters +# ret = list(cfg.unrestraint.option.find('prop', type=BoolOption)) +# assert len(ret) == 1 +# _is_same_opt(ret[0].get(), cfg.unrestraint.option('gc.gc2.prop').get()) +# ret = cfg.unrestraint.option.find('prop', type=BoolOption, first=True) +# _is_same_opt(ret.get(), cfg.unrestraint.option('gc.gc2.prop').get()) +# # +# ret = list(cfg.option.find('dummy', value=False)) +# assert len(ret) == 1 +# _is_same_opt(ret[0].get(), cfg.option('gc.dummy').get()) +# # +# ret = cfg.option.find('dummy', value=False, first=True) +# _is_same_opt(ret.get(), cfg.option('gc.dummy').get()) +# #subcfgig +# ret = list(cfg.option('gc').find('dummy')) +# assert len(ret) == 1 +# _is_same_opt(ret[0].get(), cfg.option('gc.dummy').get()) +# # +# ret = list(cfg.option('gc').find('float')) +# assert len(ret) == 1 +# _is_same_opt(ret[0].get(), cfg.option('gc.float').get()) +# # +# ret = list(cfg.option('gc.gc2').find('bool')) +# assert len(ret) == 1 +# _is_same_opt(ret[0].get(), cfg.option('gc.gc2.bool').get()) +# ret = cfg.option('gc').find('bool', value=False, first=True) +# _is_same_opt(ret.get(), cfg.option('gc.gc2.bool').get()) +# # +# with raises(AttributeError): +# ret = cfg.option('gc').find('bool', value=True, first=True) +# assert ret.get() +# # +# with raises(AttributeError): +# ret = cfg.option('gc').find('wantref') +# ret.get() +# # +# ret = list(cfg.unrestraint.option('gc').find('prop')) +# assert len(ret) == 2 +# _is_same_opt(ret[0].get(), cfg.unrestraint.option('gc.gc2.prop').get()) +# _is_same_opt(ret[1].get(), cfg.forcepermissive.option('gc.prop').get()) +# # +# cfg.property.read_only() +# ret = list(cfg.option('gc').find('prop')) +# assert len(ret) == 1 +# _is_same_opt(ret[0].get(), cfg.option('gc.prop').get()) +# # not OptionDescription +# with raises(AttributeError): +# cfg.option.find('gc', first=True) +# with raises(AttributeError): +# cfg.option.find('gc2', first=True) +## assert not list_sessions() +# +# +#def test_find_multi(): +# b = BoolOption('bool', '', multi=True, properties=('notunique',)) +# od1 = OptionDescription('od', '', [b]) +# cfg = Config(od1) +# # +# with raises(AttributeError): +# list(cfg.option.find('bool', value=True)) +# with raises(AttributeError): +# list(cfg.option.find('bool', value=True, first=True)) +# cfg.option('bool').value.set([False]) +# with raises(AttributeError): +# list(cfg.option.find('bool', value=True)) +# with raises(AttributeError): +# list(cfg.option.find('bool', value=True, first=True)) +# cfg.option('bool').value.set([False, False]) +# with raises(AttributeError): +# list(cfg.option.find('bool', value=True)) +# with raises(AttributeError): +# list(cfg.option.find('bool', value=True, first=True)) +# cfg.option('bool').value.set([False, False, True]) +# ret = list(cfg.option.find('bool', value=True)) +# assert len(ret) == 1 +# _is_same_opt(ret[0].get(), b) +# ret = cfg.option.find('bool', value=True, first=True) +# _is_same_opt(ret.get(), b) +## assert not list_sessions() +# +# +#def test_does_not_find_in_config(): +# od1 = make_description() +# cfg = Config(od1) +# with raises(AttributeError): +# list(cfg.option.find('IDontExist')) +## assert not list_sessions() def test_filename(config_type): diff --git a/tests/test_duplicate_config.py b/tests/test_duplicate_config.py index c6124f3..f4eca78 100644 --- a/tests/test_duplicate_config.py +++ b/tests/test_duplicate_config.py @@ -59,36 +59,36 @@ def test_copy_information(): ncfg = cfg.config.copy() assert ncfg.information.get('key') == 'value' # assert not list_sessions() - - -def test_copy_force_store_value(): - od1 = make_description() - conf = Config(od1) - conf2 = Config(od1) - assert conf.value.exportation() == {} - assert conf2.value.exportation() == {} - # - conf.property.read_write() - assert conf.value.exportation() == {'creole.general.wantref': {None: [False, 'forced']}} - assert conf2.value.exportation() == {} - # - conf2.property.read_only() - assert conf.value.exportation() == {'creole.general.wantref': {None: [False, 'forced']}} - assert conf2.value.exportation() == {'creole.general.wantref': {None: [False, 'forced']}} - # - conf.option('creole.general.wantref').value.set(True) - assert conf.value.exportation() == {'creole.general.wantref': {None: [True, 'user']}} - assert conf2.value.exportation() == {'creole.general.wantref': {None: [False, 'forced']}} -# assert not list_sessions() - - -def test_copy_force_store_value_metaconfig(): - od1 = make_description() - meta = MetaConfig([], optiondescription=od1) - conf = meta.config.new() - assert meta.property.get() == conf.property.get() - assert meta.permissive.get() == conf.permissive.get() - conf.property.read_write() - assert conf.value.exportation() == {'creole.general.wantref': {None: [False, 'forced']}} - assert meta.value.exportation() == {} -# assert not list_sessions() +# +# +#def test_copy_force_store_value(): +# od1 = make_description() +# conf = Config(od1) +# conf2 = Config(od1) +# assert conf.value.exportation() == {} +# assert conf2.value.exportation() == {} +# # +# conf.property.read_write() +# assert conf.value.exportation() == {'creole.general.wantref': {None: [False, 'forced']}} +# assert conf2.value.exportation() == {} +# # +# conf2.property.read_only() +# assert conf.value.exportation() == {'creole.general.wantref': {None: [False, 'forced']}} +# assert conf2.value.exportation() == {'creole.general.wantref': {None: [False, 'forced']}} +# # +# conf.option('creole.general.wantref').value.set(True) +# assert conf.value.exportation() == {'creole.general.wantref': {None: [True, 'user']}} +# assert conf2.value.exportation() == {'creole.general.wantref': {None: [False, 'forced']}} +## assert not list_sessions() +# +# +#def test_copy_force_store_value_metaconfig(): +# od1 = make_description() +# meta = MetaConfig([], optiondescription=od1) +# conf = meta.config.new() +# assert meta.property.get() == conf.property.get() +# assert meta.permissive.get() == conf.permissive.get() +# conf.property.read_write() +# assert conf.value.exportation() == {'creole.general.wantref': {None: [False, 'forced']}} +# assert meta.value.exportation() == {} +## assert not list_sessions() diff --git a/tests/test_dyn_optiondescription.py b/tests/test_dyn_optiondescription.py index 1d987a3..7d0bad5 100644 --- a/tests/test_dyn_optiondescription.py +++ b/tests/test_dyn_optiondescription.py @@ -1,6 +1,7 @@ # coding: utf-8 from .autopath import do_autopath do_autopath() +from .config import parse_od_get import pytest from tiramisu.setting import groups, owners @@ -8,13 +9,21 @@ from tiramisu import BoolOption, StrOption, ChoiceOption, IPOption, \ NetworkOption, NetmaskOption, IntOption, FloatOption, \ StrOption, PortOption, BroadcastOption, DomainnameOption, \ EmailOption, URLOption, UsernameOption, FilenameOption, SymLinkOption, \ - OptionDescription, DynOptionDescription, SynDynOption, submulti, Leadership, \ + OptionDescription, DynOptionDescription, submulti, Leadership, \ Config, \ Params, ParamOption, ParamValue, ParamSuffix, ParamSelfOption, ParamDynOption, ParamIndex, \ Calculation, calc_value +from tiramisu.option.syndynoption import SynDynOption from tiramisu.error import PropertiesOptionError, ConfigError, ConflictError, ValueOptionError +def display_name(kls) -> str: + """Replace the Tiramisu display_name function to display path + description""" + doc = kls.impl_get_information("doc", None) + comment = f" ({doc})" if doc and doc != kls.impl_getname() else "" + return f"{kls.impl_getpath()}{comment}" + + class ConvertDynOptionDescription(DynOptionDescription): def convert_suffix_to_path(self, suffix): # remove dot with is illegal @@ -66,7 +75,7 @@ def test_build_dyndescription(): dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(return_list)) od1 = OptionDescription('od', '', [dod]) cfg = Config(od1) - assert cfg.value.get() == {'dodval1.st': None, 'dodval2.st': None} + assert parse_od_get(cfg.value.get()) == {'dodval1.st': None, 'dodval2.st': None} assert cfg.option('dodval1').isdynamic() assert cfg.option('dodval1.st').isdynamic() # assert not list_sessions() @@ -77,7 +86,7 @@ def test_build_dyndescription_with_int(): dod = DynOptionDescription('dod', '', [int1], suffixes=Calculation(return_list, Params(ParamValue([1, 2])))) od1 = OptionDescription('od', '', [dod]) cfg = Config(od1) - assert cfg.value.get() == {'dod1.int': 1, 'dod2.int': 2} + assert parse_od_get(cfg.value.get()) == {'dod1.int': 1, 'dod2.int': 2} # assert not list_sessions() @@ -86,7 +95,7 @@ def test_build_dyndescription_with_dot(): dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(return_list_dot)) od1 = OptionDescription('od', '', [dod]) cfg = Config(od1) - assert cfg.value.get() == {'dodval_1.st': 'val.1', 'dodval_2.st': 'val.2'} + assert parse_od_get(cfg.value.get()) == {'dodval_1.st': 'val.1', 'dodval_2.st': 'val.2'} # assert not list_sessions() @@ -116,7 +125,7 @@ def test_subpath_dyndescription(): od1 = OptionDescription('od', '', [dod]) od2 = OptionDescription('od', '', [od1]) cfg = Config(od2) - assert cfg.value.get() == {'od.dodval1.st': None, 'od.dodval2.st': None} + assert parse_od_get(cfg.value.get()) == {'od.dodval1.st': None, 'od.dodval2.st': None} # assert not list_sessions() @@ -259,36 +268,36 @@ def test_prop_dyndescription(): assert set(cfg.option('od.dodval1').property.get()) == set([]) assert set(cfg.option('od.dodval2').property.get()) == set([]) # assert not list_sessions() - - -def test_prop_dyndescription_force_store_value(): - st = StrOption('st', '', properties=('force_store_value',)) - dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) - od = OptionDescription('od', '', [dod]) - od2 = OptionDescription('od', '', [od]) - cfg = Config(od2) - cfg.property.read_write() - assert cfg.value.get() == {'od.dodval1.st': None, 'od.dodval2.st': None} -# assert not list_sessions() - - -def test_prop_dyndescription_force_store_value_calculation_prefix(): - lst = StrOption('lst', '', ['val1', 'val2'], multi=True) - st = StrOption('st', '', Calculation(return_list, Params(ParamSuffix())) , properties=('force_store_value',)) - dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(lst)))) - od = OptionDescription('od', '', [dod, lst]) - od2 = OptionDescription('od', '', [od]) - cfg = Config(od2) - cfg.property.read_write() - assert cfg.option('od.dodval1.st').owner.isdefault() == False - assert cfg.option('od.dodval2.st').owner.isdefault() == False - assert cfg.value.get() == {'od.lst': ['val1', 'val2'], 'od.dodval1.st': 'val1', 'od.dodval2.st': 'val2'} - # - cfg.option('od.lst').value.set(['val1', 'val2', 'val3']) - assert cfg.option('od.dodval3.st').owner.isdefault() == False - assert cfg.option('od.dodval1.st').owner.isdefault() == False - assert cfg.option('od.dodval2.st').owner.isdefault() == False - assert cfg.value.get() == {'od.lst': ['val1', 'val2', 'val3'], 'od.dodval1.st': 'val1', 'od.dodval2.st': 'val2', 'od.dodval3.st': 'val3'} +# +# +#def test_prop_dyndescription_force_store_value(): +# st = StrOption('st', '', properties=('force_store_value',)) +# dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) +# od = OptionDescription('od', '', [dod]) +# od2 = OptionDescription('od', '', [od]) +# cfg = Config(od2) +# cfg.property.read_write() +# assert cfg.value.get() == {'od.dodval1.st': None, 'od.dodval2.st': None} +## assert not list_sessions() +# +# +#def test_prop_dyndescription_force_store_value_calculation_prefix(): +# lst = StrOption('lst', '', ['val1', 'val2'], multi=True) +# st = StrOption('st', '', Calculation(return_list, Params(ParamSuffix())) , properties=('force_store_value',)) +# dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(lst)))) +# od = OptionDescription('od', '', [dod, lst]) +# od2 = OptionDescription('od', '', [od]) +# cfg = Config(od2) +# cfg.property.read_write() +# assert cfg.option('od.dodval1.st').owner.isdefault() == False +# assert cfg.option('od.dodval2.st').owner.isdefault() == False +# assert cfg.value.get() == {'od.lst': ['val1', 'val2'], 'od.dodval1.st': 'val1', 'od.dodval2.st': 'val2'} +# # +# cfg.option('od.lst').value.set(['val1', 'val2', 'val3']) +# assert cfg.option('od.dodval3.st').owner.isdefault() == False +# assert cfg.option('od.dodval1.st').owner.isdefault() == False +# assert cfg.option('od.dodval2.st').owner.isdefault() == False +# assert cfg.value.get() == {'od.lst': ['val1', 'val2', 'val3'], 'od.dodval1.st': 'val1', 'od.dodval2.st': 'val2', 'od.dodval3.st': 'val3'} # assert not list_sessions() @@ -315,38 +324,38 @@ def test_callback_dyndescription(): assert cfg.option('od.dodval1.st').owner.isdefault() assert cfg.option('od.dodval2.st').owner.isdefault() # assert not list_sessions() - - -def test_callback_dyndescription_outside_wrong_param(): - lst = StrOption('lst', '', ['val1', 'val2'], multi=True) - st = StrOption('st', '', Calculation(return_dynval)) - dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(lst)))) - out = StrOption('out', '', Calculation(return_dynval, Params(ParamOption(st)))) - od = OptionDescription('od', '', [dod, out]) - od2 = OptionDescription('od', '', [od, lst]) - cfg = Config(od2) - with pytest.raises(ValueOptionError): - cfg.value.get() -# assert not list_sessions() +# +# +#def test_callback_dyndescription_outside_wrong_param(): +# lst = StrOption('lst', '', ['val1', 'val2'], multi=True) +# st = StrOption('st', '', Calculation(return_dynval)) +# dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(lst)))) +# out = StrOption('out', '', Calculation(return_dynval, Params(ParamOption(st)))) +# od = OptionDescription('od', '', [dod, out]) +# od2 = OptionDescription('od', '', [od, lst]) +# cfg = Config(od2) +# with pytest.raises(ValueOptionError): +# cfg.value.get() +## assert not list_sessions() def test_callback_dyndescription_outside1(): lst = StrOption('lst', '', ['val1', 'val2'], multi=True) st = StrOption('st', '', Calculation(return_dynval)) dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(lst)))) - out = StrOption('out', '', Calculation(return_dynval, Params(ParamDynOption(st, 'dodval1.st', dod)))) + out = StrOption('out', '', Calculation(return_dynval, Params(ParamDynOption(st, ['val1'], dod)))) od = OptionDescription('od', '', [dod, out]) od2 = OptionDescription('od', '', [od, lst]) cfg = Config(od2) - assert cfg.value.get() == {'od.dodval1.st': 'val', 'od.dodval2.st': 'val', 'od.out': 'val', 'lst': ['val1', 'val2']} + assert parse_od_get(cfg.value.get()) == {'od.dodval1.st': 'val', 'od.dodval2.st': 'val', 'od.out': 'val', 'lst': ['val1', 'val2']} cfg.option('od.dodval1.st').value.set('val1') cfg.option('od.dodval2.st').value.set('val2') - assert cfg.value.get() == {'od.dodval1.st': 'val1', 'od.dodval2.st': 'val2', 'od.out': 'val1', 'lst': ['val1', 'val2']} + assert parse_od_get(cfg.value.get()) == {'od.dodval1.st': 'val1', 'od.dodval2.st': 'val2', 'od.out': 'val1', 'lst': ['val1', 'val2']} cfg.option('lst').value.set(['val2']) with pytest.raises(ConfigError): cfg.value.get() cfg.option('lst').value.set(['val1']) - assert cfg.value.get() == {'od.dodval1.st': 'val1', 'od.out': 'val1', 'lst': ['val1']} + assert parse_od_get(cfg.value.get()) == {'od.dodval1.st': 'val1', 'od.out': 'val1', 'lst': ['val1']} # assert not list_sessions() @@ -358,9 +367,9 @@ def test_callback_dyndescription_outside2(): od = OptionDescription('od', '', [dod, out]) od2 = OptionDescription('od', '', [od, lst]) cfg = Config(od2) - assert cfg.value.get() == {'od.dodval1.st': None, 'od.dodval2.st': None, 'od.out': None, 'lst': ['val1', 'val2']} + assert parse_od_get(cfg.value.get()) == {'od.dodval1.st': None, 'od.dodval2.st': None, 'od.out': None, 'lst': ['val1', 'val2']} cfg.option('od.out').value.set('val1') - assert cfg.value.get() == {'od.dodval1.st': 'val1', 'od.dodval2.st': 'val1', 'od.out': 'val1', 'lst': ['val1', 'val2']} + assert parse_od_get(cfg.value.get()) == {'od.dodval1.st': 'val1', 'od.dodval2.st': 'val1', 'od.out': 'val1', 'lst': ['val1', 'val2']} # assert not list_sessions() @@ -414,7 +423,7 @@ def test_build_dyndescription_context(): dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(return_list, Params(ParamOption(val1)))) od1 = OptionDescription('od', '', [dod, val1]) cfg = Config(od1) - assert cfg.value.get() == {'dodval1.st': None, 'dodval2.st': None, 'val1': ['val1', 'val2']} + assert parse_od_get(cfg.value.get()) == {'dodval1.st': None, 'dodval2.st': None, 'val1': ['val1', 'val2']} # assert not list_sessions() @@ -425,7 +434,7 @@ def test_subpath_dyndescription_context(): od1 = OptionDescription('od', '', [dod, val1]) od2 = OptionDescription('od', '', [od1]) cfg = Config(od2) - assert cfg.value.get() == {'od.dodval1.st': None, 'od.dodval2.st': None, 'od.val1': ['val1', 'val2']} + assert parse_od_get(cfg.value.get()) == {'od.dodval1.st': None, 'od.dodval2.st': None, 'od.val1': ['val1', 'val2']} # assert not list_sessions() @@ -661,10 +670,10 @@ def test_dyndescription_disable_suffix_root(): od1 = OptionDescription('root', 'root', [boolean, val, dod]) cfg = Config(od1) cfg.property.read_write() - assert cfg.value.get() == {'boolean': True, 'val': ['ext1', 'ext2'], 'dodext1.st': None, 'dodext2.st': None} + assert parse_od_get(cfg.value.get()) == {'boolean': True, 'val': ['ext1', 'ext2'], 'dodext1.st': None, 'dodext2.st': None} # cfg.option('boolean').value.set(False) - assert cfg.value.get() == {'boolean': False} + assert parse_od_get(cfg.value.get()) == {'boolean': False} # assert not list_sessions() @@ -681,10 +690,10 @@ def test_dyndescription_disable_suffix_root_2(): od1 = OptionDescription('root', 'root', [boolean, val, dod]) cfg = Config(od1) cfg.property.read_write() - assert cfg.value.get() == {'boolean': False} + assert parse_od_get(cfg.value.get()) == {'boolean': False} # cfg.option('boolean').value.set(True) - assert cfg.value.get() == {'boolean': True, 'val': ['ext1', 'ext2'], 'dodext1.st': None, 'dodext2.st': None} + assert parse_od_get(cfg.value.get()) == {'boolean': True, 'val': ['ext1', 'ext2'], 'dodext1.st': None, 'dodext2.st': None} # assert not list_sessions() @@ -702,10 +711,10 @@ def test_dyndescription_disable_suffix(): od1 = OptionDescription('root', 'root', [od]) cfg = Config(od1) cfg.property.read_write() - assert cfg.value.get() == {'root.boolean': True, 'root.val': ['ext1', 'ext2'], 'root.dodext1.st': None, 'root.dodext2.st': None} + assert parse_od_get(cfg.value.get()) == {'root.boolean': True, 'root.val': ['ext1', 'ext2'], 'root.dodext1.st': None, 'root.dodext2.st': None} # cfg.option('root.boolean').value.set(False) - assert cfg.value.get() == {'root.boolean': False} + assert parse_od_get(cfg.value.get()) == {'root.boolean': False} # assert not list_sessions() @@ -778,23 +787,23 @@ def test_requires_dyndescription_boolean(): od2 = OptionDescription('od', '', [od, boolean1, boolean]) cfg = Config(od2) cfg.property.read_write() - assert cfg.value.get() == {'boolean1': True, - 'boolean': True, - 'od.dodval1.st': None, - 'od.dodval2.st': None} + assert parse_od_get(cfg.value.get()) == {'boolean1': True, + 'boolean': True, + 'od.dodval1.st': None, + 'od.dodval2.st': None} # cfg.option('boolean').value.set(False) - assert cfg.value.get() == {'boolean1': True, - 'boolean': False} + assert parse_od_get(cfg.value.get()) == {'boolean1': True, + 'boolean': False} # cfg.option('boolean').value.set(True) - assert cfg.value.get() == {'boolean1': True, - 'boolean': True, - 'od.dodval1.st': None, - 'od.dodval2.st': None} + assert parse_od_get(cfg.value.get()) == {'boolean1': True, + 'boolean': True, + 'od.dodval1.st': None, + 'od.dodval2.st': None} # cfg.option('boolean1').value.set(False) - assert cfg.value.get() == {'boolean1': False} + assert parse_od_get(cfg.value.get()) == {'boolean1': False} # assert not list_sessions() @@ -840,42 +849,42 @@ def calc_value_not_same(param, condition, expected, default, suffix): return calc_value(param, condition=condition[index], expected=expected, default=default) -def test_requires_dyndescription_in_dyn_not_same(): - boolean = BoolOption('boolean', '', True) - disabled_property = Calculation(calc_value_not_same, - Params(ParamValue('disabled'), - kwargs={'condition': ParamOption(boolean, raisepropertyerror=True), - 'expected': ParamValue(False), - 'default': ParamValue(None), - 'suffix': ParamSuffix()})) - st = StrOption('st', '', properties=(disabled_property,)) - dod1 = DynOptionDescription('dod1', '', [boolean], suffixes=Calculation(return_list)) - dod2 = DynOptionDescription('dod2', '', [st], suffixes=Calculation(return_list)) - od = OptionDescription('od', '', [dod1, dod2]) - od2 = OptionDescription('od', '', [od]) - cfg = Config(od2) - cfg.property.read_write() - - assert cfg.option('od.dod2val1.st').value.get() is None - assert cfg.option('od.dod2val2.st').value.get() is None - # - cfg.option('od.dod1val1.boolean').value.set(False) - - props = [] - try: - cfg.option('od.dod2val1.st').value.get() - except PropertiesOptionError as err: - props = err.proptype - assert props == frozenset(['disabled']) - props = [] - cfg.option('od.dod2val2.st').value.get() - # - cfg.option('od.dod1val1.boolean').value.set(True) - assert cfg.option('od.dod2val1.st').value.get() is None - assert cfg.option('od.dod2val2.st').value.get() is None -# assert not list_sessions() - - +#def test_requires_dyndescription_in_dyn_not_same(): +# boolean = BoolOption('boolean', '', True) +# disabled_property = Calculation(calc_value_not_same, +# Params(ParamValue('disabled'), +# kwargs={'condition': ParamOption(boolean, raisepropertyerror=True), +# 'expected': ParamValue(False), +# 'default': ParamValue(None), +# 'suffix': ParamSuffix()})) +# st = StrOption('st', '', properties=(disabled_property,)) +# dod1 = DynOptionDescription('dod1', '', [boolean], suffixes=Calculation(return_list)) +# dod2 = DynOptionDescription('dod2', '', [st], suffixes=Calculation(return_list)) +# od = OptionDescription('od', '', [dod1, dod2]) +# od2 = OptionDescription('od', '', [od]) +# cfg = Config(od2) +# cfg.property.read_write() +# +# assert cfg.option('od.dod2val1.st').value.get() is None +# assert cfg.option('od.dod2val2.st').value.get() is None +# # +# cfg.option('od.dod1val1.boolean').value.set(False) +# +# props = [] +# try: +# cfg.option('od.dod2val1.st').value.get() +# except PropertiesOptionError as err: +# props = err.proptype +# assert props == frozenset(['disabled']) +# props = [] +# cfg.option('od.dod2val2.st').value.get() +# # +# cfg.option('od.dod1val1.boolean').value.set(True) +# assert cfg.option('od.dod2val1.st').value.get() is None +# assert cfg.option('od.dod2val2.st').value.get() is None +## assert not list_sessions() +# +# def test_requires_dyndescription2(): boolean = BoolOption('boolean', '', True) st1 = StrOption('st', '') @@ -948,32 +957,32 @@ def test_makedict_dyndescription_context(): od2 = OptionDescription('od', '', [od]) cfg = Config(od2) cfg.option('od.dodval1.st').value.set('yes') - assert cfg.value.get() == {'od.val1': ['val1', 'val2'], 'od.dodval1.st': 'yes', 'od.dodval2.st': None} -# assert not list_sessions() - - -def test_find_dyndescription_context(): - val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) - st = StrOption('st', '') - dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) - od = OptionDescription('od', '', [dod, val1]) - od2 = OptionDescription('od', '', [od]) - cfg = Config(od2) - cfg.option('od.dodval1.st').value.set('yes') - ret = cfg.option.find('st', first=True) - assert ret.value.get() == "yes" - ret = cfg.option.find('st', first=True) - assert isinstance(ret.get(), SynDynOption) - #assert cfg.option.find(bytype=StrOption, type='path') == ['od.dodval1.st', 'od.dodval2.st', 'od.val1'] - #opts = cfg.option.find(byvalue='yes') - #assert len(opts) == 1 - #assert isinstance(opts[0], SynDynOption) - #assert opts[0].impl_getname() == 'st' - with pytest.raises(AttributeError): - list(cfg.option.find('strnotexists')) + assert parse_od_get(cfg.value.get()) == {'od.val1': ['val1', 'val2'], 'od.dodval1.st': 'yes', 'od.dodval2.st': None} # assert not list_sessions() +#def test_find_dyndescription_context(): +# val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) +# st = StrOption('st', '') +# dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) +# od = OptionDescription('od', '', [dod, val1]) +# od2 = OptionDescription('od', '', [od]) +# cfg = Config(od2) +# cfg.option('od.dodval1.st').value.set('yes') +# ret = cfg.option.find('st', first=True) +# assert ret.value.get() == "yes" +# ret = cfg.option.find('st', first=True) +# assert isinstance(ret.get(), SynDynOption) +# #assert cfg.option.find(bytype=StrOption, type='path') == ['od.dodval1.st', 'od.dodval2.st', 'od.val1'] +# #opts = cfg.option.find(byvalue='yes') +# #assert len(opts) == 1 +# #assert isinstance(opts[0], SynDynOption) +# #assert opts[0].impl_getname() == 'st' +# with pytest.raises(AttributeError): +# list(cfg.option.find('strnotexists')) +## assert not list_sessions() +# +# def test_information_dyndescription_context(): val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) st = StrOption('st', '') @@ -1088,535 +1097,535 @@ def test_all_dyndescription(): # assert not list_sessions() -def test_leadership_dyndescription(): - st1 = StrOption('st1', "", multi=True) - st2 = StrOption('st2', "", multi=True) - stm = Leadership('st1', '', [st1, st2]) - st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) - od = OptionDescription('od', '', [st]) - od1 = OptionDescription('od', '', [od]) - cfg = Config(od1) - owner = cfg.owner.get() - # - assert cfg.value.get() == {'od.stval2.st1.st1': [], 'od.stval1.st1.st1': []} - assert cfg.option('od.stval1.st1.st1').value.get() == [] - assert cfg.option('od.stval2.st1.st1').value.get() == [] - assert cfg.option('od.stval1.st1.st1').owner.isdefault() - assert cfg.option('od.stval2.st1.st1').owner.isdefault() - # - cfg.option('od.stval1.st1.st1').value.set(['yes']) - assert cfg.value.get() == {'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'yes', 'od.stval1.st1.st2': None}], 'od.stval2.st1.st1': []} - assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] - assert cfg.option('od.stval1.st1.st2', 0).value.get() == None - assert cfg.option('od.stval2.st1.st1').value.get() == [] - assert cfg.option('od.stval1.st1.st1').owner.get() == owner - assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() - assert cfg.option('od.stval2.st1.st1').owner.isdefault() - # - cfg.option('od.stval1.st1.st2', 0).value.set('no') - assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] - assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'no' - assert cfg.option('od.stval2.st1.st1').value.get() == [] - assert cfg.option('od.stval1.st1.st1').owner.get() == owner - assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner - assert cfg.option('od.stval2.st1.st1').owner.isdefault() - # - cfg.option('od.stval1.st1.st1').value.pop(0) - assert cfg.option('od.stval1.st1.st1').value.get() == [] - assert cfg.option('od.stval2.st1.st1').value.get() == [] - assert cfg.option('od.stval1.st1.st1').owner.get() == owner - assert cfg.option('od.stval2.st1.st1').owner.isdefault() - # - cfg.option('od.stval1.st1.st1').value.set(['yes']) - cfg.option('od.stval1.st1.st2', 0).value.set('yes') - assert cfg.option('od.stval1.st1.st1').owner.get() == owner - assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner - assert cfg.option('od.stval2.st1.st1').owner.isdefault() - assert cfg.option('od.stval1.st1.st1').owner.get() == owner - cfg.option('od.stval1.st1.st2', 0).value.reset() - assert cfg.option('od.stval1.st1.st1').owner.get() == owner - assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() - # - cfg.option('od.stval1.st1.st1').value.set(['yes']) - cfg.option('od.stval1.st1.st2', 0).value.set('yes') - cfg.option('od.stval1.st1.st1').value.reset() - assert cfg.option('od.stval1.st1.st1').value.get() == [] - assert cfg.option('od.stval2.st1.st1').value.get() == [] - assert cfg.option('od.stval1.st1.st1').owner.isdefault() - assert cfg.option('od.stval2.st1.st1').owner.isdefault() -# assert not list_sessions() - - -def test_leadership_dyndescription_force_store_value_leader(): - st1 = StrOption('st1', "", multi=True, default=Calculation(return_list), properties=('force_store_value',)) - st2 = StrOption('st2', "", multi=True, default=Calculation(return_list, Params(ParamOption(st1)))) - stm = Leadership('st1', '', [st1, st2]) - val1 = StrOption('val1', '', multi=True, default=['val1', 'val2']) - st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list, Params(ParamOption(val1)))) - od = OptionDescription('od', '', [val1, st]) - od1 = OptionDescription('od', '', [od]) - cfg = Config(od1) - cfg.property.read_write() - assert cfg.option('od.stval1.st1.st1').owner.isdefault() == False - assert cfg.option('od.stval2.st1.st1').owner.isdefault() == False - assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() == True - assert cfg.option('od.stval1.st1.st2', 1).owner.isdefault() == True - assert cfg.option('od.stval2.st1.st2', 0).owner.isdefault() == True - assert cfg.option('od.stval2.st1.st2', 1).owner.isdefault() == True - assert cfg.value.get() == {'od.val1': ['val1', 'val2'], 'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'val1', 'od.stval1.st1.st2': 'val1'}, {'od.stval1.st1.st1': 'val2', 'od.stval1.st1.st2': 'val2'}], 'od.stval2.st1.st1': [{'od.stval2.st1.st1': 'val1', 'od.stval2.st1.st2': 'val1'}, {'od.stval2.st1.st1': 'val2', 'od.stval2.st1.st2': 'val2'}]} - # - cfg.option('od.val1').value.set(['val1', 'val2', 'val3']) - assert cfg.option('od.stval3.st1.st1').owner.isdefault() == False - assert cfg.option('od.stval3.st1.st2', 0).owner.isdefault() == True - assert cfg.option('od.stval3.st1.st2', 1).owner.isdefault() == True - assert cfg.value.get() == {'od.val1': ['val1', 'val2', 'val3'], 'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'val1', 'od.stval1.st1.st2': 'val1'}, {'od.stval1.st1.st1': 'val2', 'od.stval1.st1.st2': 'val2'}], 'od.stval2.st1.st1': [{'od.stval2.st1.st1': 'val1', 'od.stval2.st1.st2': 'val1'}, {'od.stval2.st1.st1': 'val2', 'od.stval2.st1.st2': 'val2'}], 'od.stval3.st1.st1': [{'od.stval3.st1.st1': 'val1', 'od.stval3.st1.st2': 'val1'}, {'od.stval3.st1.st1': 'val2', 'od.stval3.st1.st2': 'val2'}]} - # - cfg.option('od.stval3.st1.st1').value.set(['val1', 'val2', 'val3']) - assert cfg.option('od.stval3.st1.st1').owner.isdefault() == False - assert cfg.option('od.stval3.st1.st2', 0).owner.isdefault() == True - assert cfg.option('od.stval3.st1.st2', 1).owner.isdefault() == True - assert cfg.option('od.stval3.st1.st2', 2).owner.isdefault() == True - assert cfg.value.get() == {'od.val1': ['val1', 'val2', 'val3'], 'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'val1', 'od.stval1.st1.st2': 'val1'}, {'od.stval1.st1.st1': 'val2', 'od.stval1.st1.st2': 'val2'}], 'od.stval2.st1.st1': [{'od.stval2.st1.st1': 'val1', 'od.stval2.st1.st2': 'val1'}, {'od.stval2.st1.st1': 'val2', 'od.stval2.st1.st2': 'val2'}], 'od.stval3.st1.st1': [{'od.stval3.st1.st1': 'val1', 'od.stval3.st1.st2': 'val1'}, {'od.stval3.st1.st1': 'val2', 'od.stval3.st1.st2': 'val2'}, {'od.stval3.st1.st1': 'val3', 'od.stval3.st1.st2': 'val3'}]} -# assert not list_sessions() - - -def test_leadership_dyndescription_force_store_value(): - st1 = StrOption('st1', "", multi=True, default=Calculation(return_list)) - st2 = StrOption('st2', "", multi=True, properties=('force_store_value',), default=Calculation(return_list, Params(ParamOption(st1)))) - stm = Leadership('st1', '', [st1, st2]) - val1 = StrOption('val1', '', multi=True, default=['val1', 'val2']) - st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list, Params(ParamOption(val1)))) - od = OptionDescription('od', '', [val1, st]) - od1 = OptionDescription('od', '', [od]) - cfg = Config(od1) - cfg.property.read_write() - assert cfg.option('od.stval1.st1.st1').owner.isdefault() == True - assert cfg.option('od.stval2.st1.st1').owner.isdefault() == True - assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() == False - assert cfg.option('od.stval1.st1.st2', 1).owner.isdefault() == False - assert cfg.option('od.stval2.st1.st2', 0).owner.isdefault() == False - assert cfg.option('od.stval2.st1.st2', 1).owner.isdefault() == False - assert cfg.value.get() == {'od.val1': ['val1', 'val2'], 'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'val1', 'od.stval1.st1.st2': 'val1'}, {'od.stval1.st1.st1': 'val2', 'od.stval1.st1.st2': 'val2'}], 'od.stval2.st1.st1': [{'od.stval2.st1.st1': 'val1', 'od.stval2.st1.st2': 'val1'}, {'od.stval2.st1.st1': 'val2', 'od.stval2.st1.st2': 'val2'}]} - # - cfg.option('od.val1').value.set(['val1', 'val2', 'val3']) - assert cfg.option('od.stval3.st1.st1').owner.isdefault() == True - assert cfg.option('od.stval3.st1.st2', 0).owner.isdefault() == False - assert cfg.option('od.stval3.st1.st2', 1).owner.isdefault() == False - assert cfg.value.get() == {'od.val1': ['val1', 'val2', 'val3'], 'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'val1', 'od.stval1.st1.st2': 'val1'}, {'od.stval1.st1.st1': 'val2', 'od.stval1.st1.st2': 'val2'}], 'od.stval2.st1.st1': [{'od.stval2.st1.st1': 'val1', 'od.stval2.st1.st2': 'val1'}, {'od.stval2.st1.st1': 'val2', 'od.stval2.st1.st2': 'val2'}], 'od.stval3.st1.st1': [{'od.stval3.st1.st1': 'val1', 'od.stval3.st1.st2': 'val1'}, {'od.stval3.st1.st1': 'val2', 'od.stval3.st1.st2': 'val2'}]} - # - cfg.option('od.stval3.st1.st1').value.set(['val1', 'val2', 'val3']) - assert cfg.option('od.stval3.st1.st1').owner.isdefault() == False - assert cfg.option('od.stval3.st1.st2', 0).owner.isdefault() == False - assert cfg.option('od.stval3.st1.st2', 1).owner.isdefault() == False - assert cfg.option('od.stval3.st1.st2', 2).owner.isdefault() == False - assert cfg.value.get() == {'od.val1': ['val1', 'val2', 'val3'], 'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'val1', 'od.stval1.st1.st2': 'val1'}, {'od.stval1.st1.st1': 'val2', 'od.stval1.st1.st2': 'val2'}], 'od.stval2.st1.st1': [{'od.stval2.st1.st1': 'val1', 'od.stval2.st1.st2': 'val1'}, {'od.stval2.st1.st1': 'val2', 'od.stval2.st1.st2': 'val2'}], 'od.stval3.st1.st1': [{'od.stval3.st1.st1': 'val1', 'od.stval3.st1.st2': 'val1'}, {'od.stval3.st1.st1': 'val2', 'od.stval3.st1.st2': 'val2'}, {'od.stval3.st1.st1': 'val3', 'od.stval3.st1.st2': 'val3'}]} -# assert not list_sessions() - - -def test_leadership_default_multi_dyndescription(): - st1 = StrOption('st1', "", multi=True) - st2 = StrOption('st2', "", multi=True, default_multi='no') - stm = Leadership('st1', '', [st1, st2]) - st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) - od = OptionDescription('od', '', [st]) - od1 = OptionDescription('od', '', [od]) - cfg = Config(od1) - owner = cfg.owner.get() - # - assert cfg.option('od.stval1.st1.st1').value.get() == [] - assert cfg.option('od.stval2.st1.st1').value.get() == [] - assert cfg.option('od.stval1.st1.st1').owner.isdefault() - assert cfg.option('od.stval2.st1.st1').owner.isdefault() - # - cfg.option('od.stval1.st1.st1').value.set(['yes']) - assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] - assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'no' - assert cfg.option('od.stval2.st1.st1').value.get() == [] - assert cfg.option('od.stval1.st1.st1').owner.get() == owner - assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() - assert cfg.option('od.stval2.st1.st1').owner.isdefault() -# assert not list_sessions() - - -def test_leadership_dyndescription_param(): - val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) - odval = OptionDescription('odval1', '', [val1]) - st1 = StrOption('st1', "", multi=True) - st2 = StrOption('st2', "", multi=True) - stm = Leadership('st1', '', [st1, st2]) - st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list, Params(ParamOption(val1)))) - od = OptionDescription('od', '', [st, odval]) - od1 = OptionDescription('od', '', [od]) - cfg = Config(od1) - owner = cfg.owner.get() - assert cfg.value.get() == {'od.stval1.st1.st1': [], 'od.stval2.st1.st1': [], 'od.odval1.val1': ['val1', 'val2']} - assert cfg.option('od.stval1.st1.st1').value.get() == [] - assert cfg.option('od.stval2.st1.st1').value.get() == [] - assert cfg.option('od.stval1.st1.st1').owner.get() == owners.default - assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default - # - cfg.option('od.stval1.st1.st1').value.set(['yes']) - assert cfg.value.get() == {'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'yes', 'od.stval1.st1.st2': None}], 'od.stval2.st1.st1': [], 'od.odval1.val1': ['val1', 'val2']} - assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] - assert cfg.option('od.stval1.st1.st2', 0).value.get() == None - assert cfg.option('od.stval2.st1.st1').value.get() == [] - assert cfg.option('od.stval1.st1.st1').owner.get() == owner - assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owners.default - assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default - # - cfg.option('od.stval1.st1.st2', 0).value.set('no') - assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] - assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'no' - assert cfg.option('od.stval2.st1.st1').value.get() == [] - assert cfg.option('od.stval1.st1.st1').owner.get() == owner - assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner - assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default - # - cfg.option('od.stval1.st1.st1').value.pop(0) - assert cfg.option('od.stval1.st1.st1').value.get() == [] - assert cfg.option('od.stval2.st1.st1').value.get() == [] - assert cfg.option('od.stval1.st1.st1').owner.get() == owner - assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default - # - cfg.option('od.stval1.st1.st1').value.set(['yes']) - cfg.option('od.stval1.st1.st2', 0).value.set('yes') - assert cfg.option('od.stval1.st1.st1').owner.get() == owner - assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner - assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default - # - cfg.option('od.stval1.st1.st2', 0).value.reset() - assert cfg.option('od.stval1.st1.st1').owner.get() == owner - assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owners.default - assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default - # - cfg.option('od.stval1.st1.st1').value.set(['yes']) - cfg.option('od.stval1.st1.st2', 0).value.set('yes') - cfg.option('od.stval1.st1.st1').value.reset() - assert cfg.option('od.stval1.st1.st1').value.get() == [] - assert cfg.option('od.stval2.st1.st1').value.get() == [] - assert cfg.option('od.stval1.st1.st1').owner.get() == owners.default - assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default -# assert not list_sessions() - - -def test_leadership_default_multi_dyndescription(): - st1 = StrOption('st1', "", multi=True) - st2 = StrOption('st2', "", multi=True, default_multi='no') - stm = Leadership('st1', '', [st1, st2]) - st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) - od = OptionDescription('od', '', [st]) - od1 = OptionDescription('od', '', [od]) - cfg = Config(od1) - owner = cfg.owner.get() - # - assert cfg.option('od.stval1.st1.st1').value.get() == [] - assert cfg.option('od.stval2.st1.st1').value.get() == [] - assert cfg.option('od.stval1.st1.st1').owner.isdefault() - assert cfg.option('od.stval2.st1.st1').owner.isdefault() - # - cfg.option('od.stval1.st1.st1').value.set(['yes']) - assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] - assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'no' - assert cfg.option('od.stval2.st1.st1').value.get() == [] - assert cfg.option('od.stval1.st1.st1').owner.get() == owner - assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() - assert cfg.option('od.stval2.st1.st1').owner.isdefault() -# assert not list_sessions() - - -def _test_leadership(cfg): - owner = cfg.owner.get() - 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.value.get() == {'od.stval1.st1.st1': [], 'od.stval2.st1.st1': [], 'od.val1.val1': [{'od.val1.val1': 'val1', 'od.val1.val2': 'val1'}, {'od.val1.val1': 'val2', 'od.val1.val2': 'val2'}]} - assert cfg.option('od.stval1.st1.st1').value.get() == [] - assert cfg.option('od.stval2.st1.st1').value.get() == [] - assert cfg.option('od.stval1.st1.st1').owner.get() == owners.default - assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default - # - cfg.option('od.stval1.st1.st1').value.set(['yes']) - assert cfg.value.get() == {'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'yes', 'od.stval1.st1.st2': None}], 'od.stval2.st1.st1': [], 'od.val1.val1': [{'od.val1.val1': 'val1', 'od.val1.val2': 'val1'}, {'od.val1.val1': 'val2', 'od.val1.val2': 'val2'}]} - assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] - assert cfg.option('od.stval1.st1.st2', 0).value.get() == None - assert cfg.option('od.stval2.st1.st1').value.get() == [] - assert cfg.option('od.stval1.st1.st1').owner.get() == owner - assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owners.default - assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default - # - cfg.option('od.stval1.st1.st2', 0).value.set('no') - assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] - assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'no' - assert cfg.option('od.stval2.st1.st1').value.get() == [] - assert cfg.option('od.stval1.st1.st1').owner.get() == owner - assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner - assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default - # - cfg.option('od.stval1.st1.st1').value.pop(0) - assert cfg.option('od.stval1.st1.st1').value.get() == [] - assert cfg.option('od.stval2.st1.st1').value.get() == [] - assert cfg.option('od.stval1.st1.st1').owner.get() == owner - assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default - # - cfg.option('od.stval1.st1.st1').value.set(['yes']) - cfg.option('od.stval1.st1.st2', 0).value.set('yes') - assert cfg.option('od.stval1.st1.st1').owner.get() == owner - assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner - assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default - # - cfg.option('od.stval1.st1.st2', 0).value.reset() - assert cfg.option('od.stval1.st1.st1').owner.get() == owner - assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owners.default - assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default - # - cfg.option('od.stval1.st1.st1').value.set(['yes']) - cfg.option('od.stval1.st1.st2', 0).value.set('yes') - cfg.option('od.stval1.st1.st1').value.reset() - assert cfg.option('od.stval1.st1.st1').value.get() == [] - assert cfg.option('od.stval2.st1.st1').value.get() == [] - assert cfg.option('od.stval1.st1.st1').owner.get() == owners.default - assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default - - -def test_leadership_dyndescription_param_leader(): - val1 = StrOption('val1', "", multi=True) - val2 = StrOption('val2', "", multi=True) - odval = Leadership('val1', '', [val1, val2]) - st1 = StrOption('st1', "", multi=True) - st2 = StrOption('st2', "", multi=True) - stm = Leadership('st1', '', [st1, st2]) - st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list, Params(ParamOption(val1)))) - od = OptionDescription('od', '', [st, odval]) - od1 = OptionDescription('od', '', [od]) - cfg = Config(od1) - _test_leadership(cfg) -# assert not list_sessions() - - -def test_leadership_default_multi_dyndescription(): - st1 = StrOption('st1', "", multi=True) - st2 = StrOption('st2', "", multi=True, default_multi='no') - stm = Leadership('st1', '', [st1, st2]) - st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) - od = OptionDescription('od', '', [st]) - od2 = OptionDescription('od', '', [od]) - with Config(od2) as cfg: - owner = cfg.owner.get() - # - assert cfg.option('od.stval1.st1.st1').value.get() == [] - assert cfg.option('od.stval2.st1.st1').value.get() == [] - assert cfg.option('od.stval1.st1.st1').owner.isdefault() - assert cfg.option('od.stval2.st1.st1').owner.isdefault() - # - cfg.option('od.stval1.st1.st1').value.set(['yes']) - assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] - assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'no' - assert cfg.option('od.stval2.st1.st1').value.get() == [] - assert cfg.option('od.stval1.st1.st1').owner.get() == owner - assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() - assert cfg.option('od.stval2.st1.st1').owner.isdefault() -# assert not list_sessions() - - -def test_leadership_dyndescription_param_follower(): - val1 = StrOption('val1', "", multi=True) - val2 = StrOption('val2', "", multi=True) - odval = Leadership('val1', '', [val1, val2]) - st1 = StrOption('st1', "", multi=True) - st2 = StrOption('st2', "", multi=True) - stm = Leadership('st1', '', [st1, st2]) - st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list, Params(ParamOption(val2)))) - od = OptionDescription('od', '', [st, odval]) - od1 = OptionDescription('od', '', [od]) - cfg = Config(od1) - _test_leadership(cfg) -# assert not list_sessions() - - -def test_leadership_default_multi_dyndescription_sub(): - st1 = StrOption('st1', "", multi=True) - st2 = StrOption('st2', "", multi=True, default_multi='no') - stm = Leadership('st1', '', [st1, st2]) - st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) - od = OptionDescription('od', '', [st]) - od1 = OptionDescription('od', '', [od]) - cfg = Config(od1) - owner = cfg.owner.get() - # - assert cfg.option('od.stval1.st1.st1').value.get() == [] - assert cfg.option('od.stval2.st1.st1').value.get() == [] - assert cfg.option('od.stval1.st1.st1').owner.isdefault() - assert cfg.option('od.stval2.st1.st1').owner.isdefault() - # - cfg.option('od.stval1.st1.st1').value.set(['yes']) - assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] - assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'no' - assert cfg.option('od.stval2.st1.st1').value.get() == [] - assert cfg.option('od.stval1.st1.st1').owner.get() == owner - assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() - assert cfg.option('od.stval2.st1.st1').owner.isdefault() -# assert not list_sessions() - - -def test_leadership_submulti_dyndescription(): - st1 = StrOption('st1', "", multi=True) - st2 = StrOption('st2', "", multi=submulti) - stm = Leadership('st1', '', [st1, st2]) - std = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) - od1 = OptionDescription('od', '', [std]) - od2 = OptionDescription('od', '', [od1]) - cfg = Config(od2) - owner = cfg.owner.get() - # - assert cfg.option('od.stval1.st1.st1').value.get() == [] - assert cfg.option('od.stval2.st1.st1').value.get() == [] - assert cfg.option('od.stval1.st1.st1').owner.isdefault() - assert cfg.option('od.stval2.st1.st1').owner.isdefault() - # - cfg.option('od.stval1.st1.st1').value.set(['yes']) - assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] - assert cfg.option('od.stval1.st1.st2', 0).value.get() == [] - assert cfg.option('od.stval2.st1.st1').value.get() == [] - assert cfg.option('od.stval1.st1.st1').owner.get() == owner - assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() - assert cfg.option('od.stval2.st1.st1').owner.isdefault() - # - cfg.option('od.stval1.st1.st2', 0).value.set(['no']) - assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] - assert cfg.option('od.stval1.st1.st2', 0).value.get() == ['no'] - assert cfg.option('od.stval2.st1.st1').value.get() == [] - assert cfg.option('od.stval1.st1.st1').owner.get() == owner - assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner - assert cfg.option('od.stval2.st1.st1').owner.isdefault() -# assert not list_sessions() - - -def test_leadership_callback_dyndescription(): - st1 = StrOption('st1', "", multi=True) - st2 = StrOption('st2', "", Calculation(return_dynval, Params(kwargs={'value': ParamOption(st1)})), multi=True) - stm = Leadership('st1', '', [st1, st2]) - st1 = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) - od1 = OptionDescription('od', '', [st1]) - od2 = OptionDescription('od', '', [od1]) - cfg = Config(od2) - owner = cfg.owner.get() - assert cfg.value.get() == {'od.stval1.st1.st1': [], 'od.stval2.st1.st1': []} - assert cfg.option('od.stval1.st1.st1').value.get() ==[] - assert cfg.option('od.stval2.st1.st1').value.get() == [] - assert cfg.option('od.stval1.st1.st1').owner.isdefault() - assert cfg.option('od.stval2.st1.st1').owner.isdefault() - # - cfg.option('od.stval1.st1.st1').value.set(['yes']) - assert cfg.value.get() == {'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'yes', 'od.stval1.st1.st2': 'yes'}], 'od.stval2.st1.st1': []} - assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] - assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'yes' - assert cfg.option('od.stval2.st1.st1').value.get() == [] - assert cfg.option('od.stval1.st1.st1').owner.get() == owner - assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() - assert cfg.option('od.stval2.st1.st1').owner.isdefault() - # - cfg.option('od.stval1.st1.st2', 0).value.set('no') - assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] - assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'no' - assert cfg.option('od.stval2.st1.st1').value.get() == [] - assert cfg.option('od.stval1.st1.st1').owner.get() == owner - assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner - assert cfg.option('od.stval2.st1.st1').owner.isdefault() - # - cfg.option('od.stval1.st1.st1').value.pop(0) - assert cfg.option('od.stval1.st1.st1').value.get() == [] - assert cfg.option('od.stval2.st1.st1').value.get() == [] - assert cfg.option('od.stval1.st1.st1').owner.get() == owner - assert cfg.option('od.stval2.st1.st1').owner.isdefault() - # - cfg.option('od.stval1.st1.st1').value.set(['yes']) - cfg.option('od.stval1.st1.st2', 0).value.set('yes') - assert cfg.option('od.stval1.st1.st1').owner.get() == owner - assert cfg.option('od.stval1.st1.st1').owner.get() == owner - assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner - assert cfg.option('od.stval2.st1.st1').owner.isdefault() - cfg.option('od.stval1.st1.st2', 0).value.reset() - assert cfg.option('od.stval1.st1.st1').owner.get() == owner - assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() - assert cfg.option('od.stval2.st1.st1').owner.isdefault() - # - cfg.option('od.stval1.st1.st1').value.set(['yes']) - cfg.option('od.stval1.st1.st2', 0).value.set('yes') - cfg.option('od.stval1.st1.st1').value.reset() - assert cfg.option('od.stval1.st1.st1').value.get() == [] - assert cfg.option('od.stval2.st1.st1').value.get() == [] - assert cfg.option('od.stval1.st1.st1').owner.isdefault() - assert cfg.option('od.stval2.st1.st1').owner.isdefault() - # - cfg.option('od.stval1.st1.st1').value.set(['yes']) - assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'yes' -# assert not list_sessions() - - -def test_leadership_callback_value_dyndescription(): - st1 = StrOption('st1', "", multi=True) - st2 = StrOption('st2', "", Calculation(return_dynval, Params(kwargs={'value': ParamValue('val')})), multi=True) - stm = Leadership('st1', '', [st1, st2]) - st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) - od = OptionDescription('od', '', [st]) - od1 = OptionDescription('od', '', [od]) - cfg = Config(od1) - assert cfg.option('od.stval1.st1.st1').value.get() == [] - cfg.option('od.stval1.st1.st1').value.set(['yes']) - assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] - cfg.option('od.stval1.st1.st2', 0).value.set('val') - assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'val' -# assert not list_sessions() - - -def test_leadership_callback_nomulti_dyndescription(): - v11 = StrOption('v1', '', "val") - st1 = StrOption('st1', "", multi=True) - st2 = StrOption('st2', "", Calculation(return_dynval, Params(ParamOption(v11))), multi=True) - stm = Leadership('st1', '', [st1, st2]) - stt = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) - od1 = OptionDescription('od', '', [stt]) - od2 = OptionDescription('od', '', [od1, v11]) - cfg = Config(od2) - assert cfg.option('od.stval1.st1.st1').value.get() == [] - cfg.option('od.stval1.st1.st1').value.set(['yes']) - assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] - assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'val' -# assert not list_sessions() - - -def test_leadership_callback_samegroup_dyndescription(): - st1 = StrOption('st1', "", multi=True) - st2 = StrOption('st2', "", multi=True) - st3 = StrOption('st3', "", Calculation(return_dynval, Params(ParamOption(st2))), multi=True) - stm = Leadership('st1', '', [st1, st2, st3]) - stt = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) - od1 = OptionDescription('od', '', [stt]) - od2 = OptionDescription('od', '', [od1]) - cfg = Config(od2) - owner = cfg.owner.get() - assert cfg.value.get() == {'od.stval1.st1.st1': [], 'od.stval2.st1.st1': []} - assert cfg.option('od.stval1.st1.st1').value.get() == [] - assert cfg.option('od.stval2.st1.st1').value.get() == [] - assert cfg.option('od.stval1.st1.st1').owner.isdefault() - assert cfg.option('od.stval2.st1.st1').owner.isdefault() - # - cfg.option('od.stval1.st1.st1').value.set(['yes']) - assert cfg.value.get() == {'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'yes', 'od.stval1.st1.st2': None, 'od.stval1.st1.st3': None}], 'od.stval2.st1.st1': []} - assert cfg.option('od.stval1.st1.st1').owner.get() == owner - assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() - assert cfg.option('od.stval1.st1.st3', 0).owner.isdefault() - assert cfg.option('od.stval2.st1.st1').owner.isdefault() - # - cfg.option('od.stval1.st1.st2', 0).value.set('yes') - assert cfg.value.get() == {'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'yes', 'od.stval1.st1.st2': 'yes', 'od.stval1.st1.st3': 'yes'}], 'od.stval2.st1.st1': []} - assert cfg.option('od.stval1.st1.st1').owner.get() == owner - assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner - assert cfg.option('od.stval1.st1.st3', 0).owner.isdefault() - assert cfg.option('od.stval2.st1.st1').owner.isdefault() -# assert not list_sessions() - - +#def test_leadership_dyndescription(): +# st1 = StrOption('st1', "", multi=True) +# st2 = StrOption('st2', "", multi=True) +# stm = Leadership('st1', '', [st1, st2]) +# st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) +# od = OptionDescription('od', '', [st]) +# od1 = OptionDescription('od', '', [od]) +# cfg = Config(od1) +# owner = cfg.owner.get() +# # +# assert cfg.value.get() == {'od.stval2.st1.st1': [], 'od.stval1.st1.st1': []} +# assert cfg.option('od.stval1.st1.st1').value.get() == [] +# assert cfg.option('od.stval2.st1.st1').value.get() == [] +# assert cfg.option('od.stval1.st1.st1').owner.isdefault() +# assert cfg.option('od.stval2.st1.st1').owner.isdefault() +# # +# cfg.option('od.stval1.st1.st1').value.set(['yes']) +# assert cfg.value.get() == {'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'yes', 'od.stval1.st1.st2': None}], 'od.stval2.st1.st1': []} +# assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] +# assert cfg.option('od.stval1.st1.st2', 0).value.get() == None +# assert cfg.option('od.stval2.st1.st1').value.get() == [] +# assert cfg.option('od.stval1.st1.st1').owner.get() == owner +# assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() +# assert cfg.option('od.stval2.st1.st1').owner.isdefault() +# # +# cfg.option('od.stval1.st1.st2', 0).value.set('no') +# assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] +# assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'no' +# assert cfg.option('od.stval2.st1.st1').value.get() == [] +# assert cfg.option('od.stval1.st1.st1').owner.get() == owner +# assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner +# assert cfg.option('od.stval2.st1.st1').owner.isdefault() +# # +# cfg.option('od.stval1.st1.st1').value.pop(0) +# assert cfg.option('od.stval1.st1.st1').value.get() == [] +# assert cfg.option('od.stval2.st1.st1').value.get() == [] +# assert cfg.option('od.stval1.st1.st1').owner.get() == owner +# assert cfg.option('od.stval2.st1.st1').owner.isdefault() +# # +# cfg.option('od.stval1.st1.st1').value.set(['yes']) +# cfg.option('od.stval1.st1.st2', 0).value.set('yes') +# assert cfg.option('od.stval1.st1.st1').owner.get() == owner +# assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner +# assert cfg.option('od.stval2.st1.st1').owner.isdefault() +# assert cfg.option('od.stval1.st1.st1').owner.get() == owner +# cfg.option('od.stval1.st1.st2', 0).value.reset() +# assert cfg.option('od.stval1.st1.st1').owner.get() == owner +# assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() +# # +# cfg.option('od.stval1.st1.st1').value.set(['yes']) +# cfg.option('od.stval1.st1.st2', 0).value.set('yes') +# cfg.option('od.stval1.st1.st1').value.reset() +# assert cfg.option('od.stval1.st1.st1').value.get() == [] +# assert cfg.option('od.stval2.st1.st1').value.get() == [] +# assert cfg.option('od.stval1.st1.st1').owner.isdefault() +# assert cfg.option('od.stval2.st1.st1').owner.isdefault() +## assert not list_sessions() +# +# +#def test_leadership_dyndescription_force_store_value_leader(): +# st1 = StrOption('st1', "", multi=True, default=Calculation(return_list), properties=('force_store_value',)) +# st2 = StrOption('st2', "", multi=True, default=Calculation(return_list, Params(ParamOption(st1)))) +# stm = Leadership('st1', '', [st1, st2]) +# val1 = StrOption('val1', '', multi=True, default=['val1', 'val2']) +# st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list, Params(ParamOption(val1)))) +# od = OptionDescription('od', '', [val1, st]) +# od1 = OptionDescription('od', '', [od]) +# cfg = Config(od1) +# cfg.property.read_write() +# assert cfg.option('od.stval1.st1.st1').owner.isdefault() == False +# assert cfg.option('od.stval2.st1.st1').owner.isdefault() == False +# assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() == True +# assert cfg.option('od.stval1.st1.st2', 1).owner.isdefault() == True +# assert cfg.option('od.stval2.st1.st2', 0).owner.isdefault() == True +# assert cfg.option('od.stval2.st1.st2', 1).owner.isdefault() == True +# assert cfg.value.get() == {'od.val1': ['val1', 'val2'], 'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'val1', 'od.stval1.st1.st2': 'val1'}, {'od.stval1.st1.st1': 'val2', 'od.stval1.st1.st2': 'val2'}], 'od.stval2.st1.st1': [{'od.stval2.st1.st1': 'val1', 'od.stval2.st1.st2': 'val1'}, {'od.stval2.st1.st1': 'val2', 'od.stval2.st1.st2': 'val2'}]} +# # +# cfg.option('od.val1').value.set(['val1', 'val2', 'val3']) +# assert cfg.option('od.stval3.st1.st1').owner.isdefault() == False +# assert cfg.option('od.stval3.st1.st2', 0).owner.isdefault() == True +# assert cfg.option('od.stval3.st1.st2', 1).owner.isdefault() == True +# assert cfg.value.get() == {'od.val1': ['val1', 'val2', 'val3'], 'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'val1', 'od.stval1.st1.st2': 'val1'}, {'od.stval1.st1.st1': 'val2', 'od.stval1.st1.st2': 'val2'}], 'od.stval2.st1.st1': [{'od.stval2.st1.st1': 'val1', 'od.stval2.st1.st2': 'val1'}, {'od.stval2.st1.st1': 'val2', 'od.stval2.st1.st2': 'val2'}], 'od.stval3.st1.st1': [{'od.stval3.st1.st1': 'val1', 'od.stval3.st1.st2': 'val1'}, {'od.stval3.st1.st1': 'val2', 'od.stval3.st1.st2': 'val2'}]} +# # +# cfg.option('od.stval3.st1.st1').value.set(['val1', 'val2', 'val3']) +# assert cfg.option('od.stval3.st1.st1').owner.isdefault() == False +# assert cfg.option('od.stval3.st1.st2', 0).owner.isdefault() == True +# assert cfg.option('od.stval3.st1.st2', 1).owner.isdefault() == True +# assert cfg.option('od.stval3.st1.st2', 2).owner.isdefault() == True +# assert cfg.value.get() == {'od.val1': ['val1', 'val2', 'val3'], 'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'val1', 'od.stval1.st1.st2': 'val1'}, {'od.stval1.st1.st1': 'val2', 'od.stval1.st1.st2': 'val2'}], 'od.stval2.st1.st1': [{'od.stval2.st1.st1': 'val1', 'od.stval2.st1.st2': 'val1'}, {'od.stval2.st1.st1': 'val2', 'od.stval2.st1.st2': 'val2'}], 'od.stval3.st1.st1': [{'od.stval3.st1.st1': 'val1', 'od.stval3.st1.st2': 'val1'}, {'od.stval3.st1.st1': 'val2', 'od.stval3.st1.st2': 'val2'}, {'od.stval3.st1.st1': 'val3', 'od.stval3.st1.st2': 'val3'}]} +## assert not list_sessions() +# +# +#def test_leadership_dyndescription_force_store_value(): +# st1 = StrOption('st1', "", multi=True, default=Calculation(return_list)) +# st2 = StrOption('st2', "", multi=True, properties=('force_store_value',), default=Calculation(return_list, Params(ParamOption(st1)))) +# stm = Leadership('st1', '', [st1, st2]) +# val1 = StrOption('val1', '', multi=True, default=['val1', 'val2']) +# st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list, Params(ParamOption(val1)))) +# od = OptionDescription('od', '', [val1, st]) +# od1 = OptionDescription('od', '', [od]) +# cfg = Config(od1) +# cfg.property.read_write() +# assert cfg.option('od.stval1.st1.st1').owner.isdefault() == True +# assert cfg.option('od.stval2.st1.st1').owner.isdefault() == True +# assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() == False +# assert cfg.option('od.stval1.st1.st2', 1).owner.isdefault() == False +# assert cfg.option('od.stval2.st1.st2', 0).owner.isdefault() == False +# assert cfg.option('od.stval2.st1.st2', 1).owner.isdefault() == False +# assert cfg.value.get() == {'od.val1': ['val1', 'val2'], 'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'val1', 'od.stval1.st1.st2': 'val1'}, {'od.stval1.st1.st1': 'val2', 'od.stval1.st1.st2': 'val2'}], 'od.stval2.st1.st1': [{'od.stval2.st1.st1': 'val1', 'od.stval2.st1.st2': 'val1'}, {'od.stval2.st1.st1': 'val2', 'od.stval2.st1.st2': 'val2'}]} +# # +# cfg.option('od.val1').value.set(['val1', 'val2', 'val3']) +# assert cfg.option('od.stval3.st1.st1').owner.isdefault() == True +# assert cfg.option('od.stval3.st1.st2', 0).owner.isdefault() == False +# assert cfg.option('od.stval3.st1.st2', 1).owner.isdefault() == False +# assert cfg.value.get() == {'od.val1': ['val1', 'val2', 'val3'], 'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'val1', 'od.stval1.st1.st2': 'val1'}, {'od.stval1.st1.st1': 'val2', 'od.stval1.st1.st2': 'val2'}], 'od.stval2.st1.st1': [{'od.stval2.st1.st1': 'val1', 'od.stval2.st1.st2': 'val1'}, {'od.stval2.st1.st1': 'val2', 'od.stval2.st1.st2': 'val2'}], 'od.stval3.st1.st1': [{'od.stval3.st1.st1': 'val1', 'od.stval3.st1.st2': 'val1'}, {'od.stval3.st1.st1': 'val2', 'od.stval3.st1.st2': 'val2'}]} +# # +# cfg.option('od.stval3.st1.st1').value.set(['val1', 'val2', 'val3']) +# assert cfg.option('od.stval3.st1.st1').owner.isdefault() == False +# assert cfg.option('od.stval3.st1.st2', 0).owner.isdefault() == False +# assert cfg.option('od.stval3.st1.st2', 1).owner.isdefault() == False +# assert cfg.option('od.stval3.st1.st2', 2).owner.isdefault() == False +# assert cfg.value.get() == {'od.val1': ['val1', 'val2', 'val3'], 'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'val1', 'od.stval1.st1.st2': 'val1'}, {'od.stval1.st1.st1': 'val2', 'od.stval1.st1.st2': 'val2'}], 'od.stval2.st1.st1': [{'od.stval2.st1.st1': 'val1', 'od.stval2.st1.st2': 'val1'}, {'od.stval2.st1.st1': 'val2', 'od.stval2.st1.st2': 'val2'}], 'od.stval3.st1.st1': [{'od.stval3.st1.st1': 'val1', 'od.stval3.st1.st2': 'val1'}, {'od.stval3.st1.st1': 'val2', 'od.stval3.st1.st2': 'val2'}, {'od.stval3.st1.st1': 'val3', 'od.stval3.st1.st2': 'val3'}]} +## assert not list_sessions() +# +# +#def test_leadership_default_multi_dyndescription1(): +# st1 = StrOption('st1', "", multi=True) +# st2 = StrOption('st2', "", multi=True, default_multi='no') +# stm = Leadership('st1', '', [st1, st2]) +# st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) +# od = OptionDescription('od', '', [st]) +# od1 = OptionDescription('od', '', [od]) +# cfg = Config(od1) +# owner = cfg.owner.get() +# # +# assert cfg.option('od.stval1.st1.st1').value.get() == [] +# assert cfg.option('od.stval2.st1.st1').value.get() == [] +# assert cfg.option('od.stval1.st1.st1').owner.isdefault() +# assert cfg.option('od.stval2.st1.st1').owner.isdefault() +# # +# cfg.option('od.stval1.st1.st1').value.set(['yes']) +# assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] +# assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'no' +# assert cfg.option('od.stval2.st1.st1').value.get() == [] +# assert cfg.option('od.stval1.st1.st1').owner.get() == owner +# assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() +# assert cfg.option('od.stval2.st1.st1').owner.isdefault() +## assert not list_sessions() +# +# +#def test_leadership_dyndescription_param(): +# val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) +# odval = OptionDescription('odval1', '', [val1]) +# st1 = StrOption('st1', "", multi=True) +# st2 = StrOption('st2', "", multi=True) +# stm = Leadership('st1', '', [st1, st2]) +# st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list, Params(ParamOption(val1)))) +# od = OptionDescription('od', '', [st, odval]) +# od1 = OptionDescription('od', '', [od]) +# cfg = Config(od1) +# owner = cfg.owner.get() +# assert cfg.value.get() == {'od.stval1.st1.st1': [], 'od.stval2.st1.st1': [], 'od.odval1.val1': ['val1', 'val2']} +# assert cfg.option('od.stval1.st1.st1').value.get() == [] +# assert cfg.option('od.stval2.st1.st1').value.get() == [] +# assert cfg.option('od.stval1.st1.st1').owner.get() == owners.default +# assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default +# # +# cfg.option('od.stval1.st1.st1').value.set(['yes']) +# assert cfg.value.get() == {'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'yes', 'od.stval1.st1.st2': None}], 'od.stval2.st1.st1': [], 'od.odval1.val1': ['val1', 'val2']} +# assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] +# assert cfg.option('od.stval1.st1.st2', 0).value.get() == None +# assert cfg.option('od.stval2.st1.st1').value.get() == [] +# assert cfg.option('od.stval1.st1.st1').owner.get() == owner +# assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owners.default +# assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default +# # +# cfg.option('od.stval1.st1.st2', 0).value.set('no') +# assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] +# assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'no' +# assert cfg.option('od.stval2.st1.st1').value.get() == [] +# assert cfg.option('od.stval1.st1.st1').owner.get() == owner +# assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner +# assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default +# # +# cfg.option('od.stval1.st1.st1').value.pop(0) +# assert cfg.option('od.stval1.st1.st1').value.get() == [] +# assert cfg.option('od.stval2.st1.st1').value.get() == [] +# assert cfg.option('od.stval1.st1.st1').owner.get() == owner +# assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default +# # +# cfg.option('od.stval1.st1.st1').value.set(['yes']) +# cfg.option('od.stval1.st1.st2', 0).value.set('yes') +# assert cfg.option('od.stval1.st1.st1').owner.get() == owner +# assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner +# assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default +# # +# cfg.option('od.stval1.st1.st2', 0).value.reset() +# assert cfg.option('od.stval1.st1.st1').owner.get() == owner +# assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owners.default +# assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default +# # +# cfg.option('od.stval1.st1.st1').value.set(['yes']) +# cfg.option('od.stval1.st1.st2', 0).value.set('yes') +# cfg.option('od.stval1.st1.st1').value.reset() +# assert cfg.option('od.stval1.st1.st1').value.get() == [] +# assert cfg.option('od.stval2.st1.st1').value.get() == [] +# assert cfg.option('od.stval1.st1.st1').owner.get() == owners.default +# assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default +## assert not list_sessions() +# +# +#def test_leadership_default_multi_dyndescription2(): +# st1 = StrOption('st1', "", multi=True) +# st2 = StrOption('st2', "", multi=True, default_multi='no') +# stm = Leadership('st1', '', [st1, st2]) +# st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) +# od = OptionDescription('od', '', [st]) +# od1 = OptionDescription('od', '', [od]) +# cfg = Config(od1) +# owner = cfg.owner.get() +# # +# assert cfg.option('od.stval1.st1.st1').value.get() == [] +# assert cfg.option('od.stval2.st1.st1').value.get() == [] +# assert cfg.option('od.stval1.st1.st1').owner.isdefault() +# assert cfg.option('od.stval2.st1.st1').owner.isdefault() +# # +# cfg.option('od.stval1.st1.st1').value.set(['yes']) +# assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] +# assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'no' +# assert cfg.option('od.stval2.st1.st1').value.get() == [] +# assert cfg.option('od.stval1.st1.st1').owner.get() == owner +# assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() +# assert cfg.option('od.stval2.st1.st1').owner.isdefault() +## assert not list_sessions() +# +# +#def _test_leadership(cfg): +# owner = cfg.owner.get() +# 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.value.get() == {'od.stval1.st1.st1': [], 'od.stval2.st1.st1': [], 'od.val1.val1': [{'od.val1.val1': 'val1', 'od.val1.val2': 'val1'}, {'od.val1.val1': 'val2', 'od.val1.val2': 'val2'}]} +# assert cfg.option('od.stval1.st1.st1').value.get() == [] +# assert cfg.option('od.stval2.st1.st1').value.get() == [] +# assert cfg.option('od.stval1.st1.st1').owner.get() == owners.default +# assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default +# # +# cfg.option('od.stval1.st1.st1').value.set(['yes']) +# assert cfg.value.get() == {'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'yes', 'od.stval1.st1.st2': None}], 'od.stval2.st1.st1': [], 'od.val1.val1': [{'od.val1.val1': 'val1', 'od.val1.val2': 'val1'}, {'od.val1.val1': 'val2', 'od.val1.val2': 'val2'}]} +# assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] +# assert cfg.option('od.stval1.st1.st2', 0).value.get() == None +# assert cfg.option('od.stval2.st1.st1').value.get() == [] +# assert cfg.option('od.stval1.st1.st1').owner.get() == owner +# assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owners.default +# assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default +# # +# cfg.option('od.stval1.st1.st2', 0).value.set('no') +# assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] +# assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'no' +# assert cfg.option('od.stval2.st1.st1').value.get() == [] +# assert cfg.option('od.stval1.st1.st1').owner.get() == owner +# assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner +# assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default +# # +# cfg.option('od.stval1.st1.st1').value.pop(0) +# assert cfg.option('od.stval1.st1.st1').value.get() == [] +# assert cfg.option('od.stval2.st1.st1').value.get() == [] +# assert cfg.option('od.stval1.st1.st1').owner.get() == owner +# assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default +# # +# cfg.option('od.stval1.st1.st1').value.set(['yes']) +# cfg.option('od.stval1.st1.st2', 0).value.set('yes') +# assert cfg.option('od.stval1.st1.st1').owner.get() == owner +# assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner +# assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default +# # +# cfg.option('od.stval1.st1.st2', 0).value.reset() +# assert cfg.option('od.stval1.st1.st1').owner.get() == owner +# assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owners.default +# assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default +# # +# cfg.option('od.stval1.st1.st1').value.set(['yes']) +# cfg.option('od.stval1.st1.st2', 0).value.set('yes') +# cfg.option('od.stval1.st1.st1').value.reset() +# assert cfg.option('od.stval1.st1.st1').value.get() == [] +# assert cfg.option('od.stval2.st1.st1').value.get() == [] +# assert cfg.option('od.stval1.st1.st1').owner.get() == owners.default +# assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default +# +# +#def test_leadership_dyndescription_param_leader(): +# val1 = StrOption('val1', "", multi=True) +# val2 = StrOption('val2', "", multi=True) +# odval = Leadership('val1', '', [val1, val2]) +# st1 = StrOption('st1', "", multi=True) +# st2 = StrOption('st2', "", multi=True) +# stm = Leadership('st1', '', [st1, st2]) +# st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list, Params(ParamOption(val1)))) +# od = OptionDescription('od', '', [st, odval]) +# od1 = OptionDescription('od', '', [od]) +# cfg = Config(od1) +# _test_leadership(cfg) +## assert not list_sessions() +# +# +#def test_leadership_default_multi_dyndescription3(): +# st1 = StrOption('st1', "", multi=True) +# st2 = StrOption('st2', "", multi=True, default_multi='no') +# stm = Leadership('st1', '', [st1, st2]) +# st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) +# od = OptionDescription('od', '', [st]) +# od2 = OptionDescription('od', '', [od]) +# with Config(od2) as cfg: +# owner = cfg.owner.get() +# # +# assert cfg.option('od.stval1.st1.st1').value.get() == [] +# assert cfg.option('od.stval2.st1.st1').value.get() == [] +# assert cfg.option('od.stval1.st1.st1').owner.isdefault() +# assert cfg.option('od.stval2.st1.st1').owner.isdefault() +# # +# cfg.option('od.stval1.st1.st1').value.set(['yes']) +# assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] +# assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'no' +# assert cfg.option('od.stval2.st1.st1').value.get() == [] +# assert cfg.option('od.stval1.st1.st1').owner.get() == owner +# assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() +# assert cfg.option('od.stval2.st1.st1').owner.isdefault() +## assert not list_sessions() +# +# +#def test_leadership_dyndescription_param_follower(): +# val1 = StrOption('val1', "", multi=True) +# val2 = StrOption('val2', "", multi=True) +# odval = Leadership('val1', '', [val1, val2]) +# st1 = StrOption('st1', "", multi=True) +# st2 = StrOption('st2', "", multi=True) +# stm = Leadership('st1', '', [st1, st2]) +# st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list, Params(ParamOption(val2)))) +# od = OptionDescription('od', '', [st, odval]) +# od1 = OptionDescription('od', '', [od]) +# cfg = Config(od1) +# _test_leadership(cfg) +## assert not list_sessions() +# +# +#def test_leadership_default_multi_dyndescription_sub(): +# st1 = StrOption('st1', "", multi=True) +# st2 = StrOption('st2', "", multi=True, default_multi='no') +# stm = Leadership('st1', '', [st1, st2]) +# st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) +# od = OptionDescription('od', '', [st]) +# od1 = OptionDescription('od', '', [od]) +# cfg = Config(od1) +# owner = cfg.owner.get() +# # +# assert cfg.option('od.stval1.st1.st1').value.get() == [] +# assert cfg.option('od.stval2.st1.st1').value.get() == [] +# assert cfg.option('od.stval1.st1.st1').owner.isdefault() +# assert cfg.option('od.stval2.st1.st1').owner.isdefault() +# # +# cfg.option('od.stval1.st1.st1').value.set(['yes']) +# assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] +# assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'no' +# assert cfg.option('od.stval2.st1.st1').value.get() == [] +# assert cfg.option('od.stval1.st1.st1').owner.get() == owner +# assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() +# assert cfg.option('od.stval2.st1.st1').owner.isdefault() +## assert not list_sessions() +# +# +#def test_leadership_submulti_dyndescription(): +# st1 = StrOption('st1', "", multi=True) +# st2 = StrOption('st2', "", multi=submulti) +# stm = Leadership('st1', '', [st1, st2]) +# std = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) +# od1 = OptionDescription('od', '', [std]) +# od2 = OptionDescription('od', '', [od1]) +# cfg = Config(od2) +# owner = cfg.owner.get() +# # +# assert cfg.option('od.stval1.st1.st1').value.get() == [] +# assert cfg.option('od.stval2.st1.st1').value.get() == [] +# assert cfg.option('od.stval1.st1.st1').owner.isdefault() +# assert cfg.option('od.stval2.st1.st1').owner.isdefault() +# # +# cfg.option('od.stval1.st1.st1').value.set(['yes']) +# assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] +# assert cfg.option('od.stval1.st1.st2', 0).value.get() == [] +# assert cfg.option('od.stval2.st1.st1').value.get() == [] +# assert cfg.option('od.stval1.st1.st1').owner.get() == owner +# assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() +# assert cfg.option('od.stval2.st1.st1').owner.isdefault() +# # +# cfg.option('od.stval1.st1.st2', 0).value.set(['no']) +# assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] +# assert cfg.option('od.stval1.st1.st2', 0).value.get() == ['no'] +# assert cfg.option('od.stval2.st1.st1').value.get() == [] +# assert cfg.option('od.stval1.st1.st1').owner.get() == owner +# assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner +# assert cfg.option('od.stval2.st1.st1').owner.isdefault() +## assert not list_sessions() +# +# +#def test_leadership_callback_dyndescription(): +# st1 = StrOption('st1', "", multi=True) +# st2 = StrOption('st2', "", Calculation(return_dynval, Params(kwargs={'value': ParamOption(st1)})), multi=True) +# stm = Leadership('st1', '', [st1, st2]) +# st1 = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) +# od1 = OptionDescription('od', '', [st1]) +# od2 = OptionDescription('od', '', [od1]) +# cfg = Config(od2) +# owner = cfg.owner.get() +# assert cfg.value.get() == {'od.stval1.st1.st1': [], 'od.stval2.st1.st1': []} +# assert cfg.option('od.stval1.st1.st1').value.get() ==[] +# assert cfg.option('od.stval2.st1.st1').value.get() == [] +# assert cfg.option('od.stval1.st1.st1').owner.isdefault() +# assert cfg.option('od.stval2.st1.st1').owner.isdefault() +# # +# cfg.option('od.stval1.st1.st1').value.set(['yes']) +# assert cfg.value.get() == {'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'yes', 'od.stval1.st1.st2': 'yes'}], 'od.stval2.st1.st1': []} +# assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] +# assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'yes' +# assert cfg.option('od.stval2.st1.st1').value.get() == [] +# assert cfg.option('od.stval1.st1.st1').owner.get() == owner +# assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() +# assert cfg.option('od.stval2.st1.st1').owner.isdefault() +# # +# cfg.option('od.stval1.st1.st2', 0).value.set('no') +# assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] +# assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'no' +# assert cfg.option('od.stval2.st1.st1').value.get() == [] +# assert cfg.option('od.stval1.st1.st1').owner.get() == owner +# assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner +# assert cfg.option('od.stval2.st1.st1').owner.isdefault() +# # +# cfg.option('od.stval1.st1.st1').value.pop(0) +# assert cfg.option('od.stval1.st1.st1').value.get() == [] +# assert cfg.option('od.stval2.st1.st1').value.get() == [] +# assert cfg.option('od.stval1.st1.st1').owner.get() == owner +# assert cfg.option('od.stval2.st1.st1').owner.isdefault() +# # +# cfg.option('od.stval1.st1.st1').value.set(['yes']) +# cfg.option('od.stval1.st1.st2', 0).value.set('yes') +# assert cfg.option('od.stval1.st1.st1').owner.get() == owner +# assert cfg.option('od.stval1.st1.st1').owner.get() == owner +# assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner +# assert cfg.option('od.stval2.st1.st1').owner.isdefault() +# cfg.option('od.stval1.st1.st2', 0).value.reset() +# assert cfg.option('od.stval1.st1.st1').owner.get() == owner +# assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() +# assert cfg.option('od.stval2.st1.st1').owner.isdefault() +# # +# cfg.option('od.stval1.st1.st1').value.set(['yes']) +# cfg.option('od.stval1.st1.st2', 0).value.set('yes') +# cfg.option('od.stval1.st1.st1').value.reset() +# assert cfg.option('od.stval1.st1.st1').value.get() == [] +# assert cfg.option('od.stval2.st1.st1').value.get() == [] +# assert cfg.option('od.stval1.st1.st1').owner.isdefault() +# assert cfg.option('od.stval2.st1.st1').owner.isdefault() +# # +# cfg.option('od.stval1.st1.st1').value.set(['yes']) +# assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'yes' +## assert not list_sessions() +# +# +#def test_leadership_callback_value_dyndescription(): +# st1 = StrOption('st1', "", multi=True) +# st2 = StrOption('st2', "", Calculation(return_dynval, Params(kwargs={'value': ParamValue('val')})), multi=True) +# stm = Leadership('st1', '', [st1, st2]) +# st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) +# od = OptionDescription('od', '', [st]) +# od1 = OptionDescription('od', '', [od]) +# cfg = Config(od1) +# assert cfg.option('od.stval1.st1.st1').value.get() == [] +# cfg.option('od.stval1.st1.st1').value.set(['yes']) +# assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] +# cfg.option('od.stval1.st1.st2', 0).value.set('val') +# assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'val' +## assert not list_sessions() +# +# +#def test_leadership_callback_nomulti_dyndescription(): +# v11 = StrOption('v1', '', "val") +# st1 = StrOption('st1', "", multi=True) +# st2 = StrOption('st2', "", Calculation(return_dynval, Params(ParamOption(v11))), multi=True) +# stm = Leadership('st1', '', [st1, st2]) +# stt = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) +# od1 = OptionDescription('od', '', [stt]) +# od2 = OptionDescription('od', '', [od1, v11]) +# cfg = Config(od2) +# assert cfg.option('od.stval1.st1.st1').value.get() == [] +# cfg.option('od.stval1.st1.st1').value.set(['yes']) +# assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] +# assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'val' +## assert not list_sessions() +# +# +#def test_leadership_callback_samegroup_dyndescription(): +# st1 = StrOption('st1', "", multi=True) +# st2 = StrOption('st2', "", multi=True) +# st3 = StrOption('st3', "", Calculation(return_dynval, Params(ParamOption(st2))), multi=True) +# stm = Leadership('st1', '', [st1, st2, st3]) +# stt = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) +# od1 = OptionDescription('od', '', [stt]) +# od2 = OptionDescription('od', '', [od1]) +# cfg = Config(od2) +# owner = cfg.owner.get() +# assert cfg.value.get() == {'od.stval1.st1.st1': [], 'od.stval2.st1.st1': []} +# assert cfg.option('od.stval1.st1.st1').value.get() == [] +# assert cfg.option('od.stval2.st1.st1').value.get() == [] +# assert cfg.option('od.stval1.st1.st1').owner.isdefault() +# assert cfg.option('od.stval2.st1.st1').owner.isdefault() +# # +# cfg.option('od.stval1.st1.st1').value.set(['yes']) +# assert cfg.value.get() == {'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'yes', 'od.stval1.st1.st2': None, 'od.stval1.st1.st3': None}], 'od.stval2.st1.st1': []} +# assert cfg.option('od.stval1.st1.st1').owner.get() == owner +# assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() +# assert cfg.option('od.stval1.st1.st3', 0).owner.isdefault() +# assert cfg.option('od.stval2.st1.st1').owner.isdefault() +# # +# cfg.option('od.stval1.st1.st2', 0).value.set('yes') +# assert cfg.value.get() == {'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'yes', 'od.stval1.st1.st2': 'yes', 'od.stval1.st1.st3': 'yes'}], 'od.stval2.st1.st1': []} +# assert cfg.option('od.stval1.st1.st1').owner.get() == owner +# assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner +# assert cfg.option('od.stval1.st1.st3', 0).owner.isdefault() +# assert cfg.option('od.stval2.st1.st1').owner.isdefault() +## assert not list_sessions() +# +# def test_invalid_conflict_dyndescription(): st = StrOption('st', '') dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) @@ -1627,7 +1636,7 @@ def test_invalid_conflict_dyndescription(): # assert not list_sessions() -def test_leadership_default_multi_dyndescription(): +def test_leadership_default_multi_dyndescription4(): st1 = StrOption('st1', "", multi=True) st2 = StrOption('st2', "", multi=True, default_multi='no') stm = Leadership('st1', '', [st1, st2]) @@ -1638,9 +1647,9 @@ def test_leadership_default_multi_dyndescription(): cfg = Config(od1) owner = cfg.owner.get() # - assert cfg.value.get() == {'od.stval1.od1.st1.st1': [], - 'od.stval2.od1.st1.st1': [], - } + assert parse_od_get(cfg.value.get()) == {'od.stval1.od1.st1.st1': [], + 'od.stval2.od1.st1.st1': [], + } assert cfg.option('od.stval1.od1.st1.st1').value.get() == [] assert cfg.option('od.stval2.od1.st1.st1').value.get() == [] assert cfg.option('od.stval1.od1.st1.st1').owner.isdefault() @@ -1653,10 +1662,9 @@ def test_leadership_default_multi_dyndescription(): assert cfg.option('od.stval1.od1.st1.st1').owner.get() == owner assert cfg.option('od.stval1.od1.st1.st2', 0).owner.isdefault() assert cfg.option('od.stval2.od1.st1.st1').owner.isdefault() - assert cfg.value.get() == {'od.stval1.od1.st1.st1': [], - 'od.stval1.od1.st1.st1': [{'od.stval1.od1.st1.st1': 'yes', - 'od.stval1.od1.st1.st2': 'no'}], - 'od.stval2.od1.st1.st1': [], + assert parse_od_get(cfg.value.get()) == {'od.stval1.od1.st1.st1': [{'od.stval1.od1.st1.st1': 'yes', + 'od.stval1.od1.st1.st2': 'no'}], + 'od.stval2.od1.st1.st1': [], } # assert not list_sessions() @@ -1665,16 +1673,16 @@ def test_subdynod_dyndescription_root(): st2 = StrOption('st2', '') dod1 = DynOptionDescription('dod1', '', [st2], suffixes=Calculation(return_list, Params(ParamValue(['a', 'b'])))) dod = DynOptionDescription('dod', '', [dod1], suffixes=Calculation(return_list)) - st3 = StrOption('st3', '', Calculation(return_dynval, Params(ParamDynOption(st2, 'dodval1.dod1a.st2', dod)))) + st3 = StrOption('st3', '', Calculation(return_dynval, Params(ParamDynOption(st2, ['val1', 'a'], dod)))) # FIXME st4 = StrOption('st4', '', Calculation(return_dynval, Params(ParamOption(st2))), multi=True) od1 = OptionDescription('od', '', [dod, st3]) #, st4]) cfg = Config(od1) - assert cfg.value.get() == {'dodval1.dod1a.st2': None, - 'dodval1.dod1b.st2': None, - 'dodval2.dod1a.st2': None, - 'dodval2.dod1b.st2': None, - 'st3': None, - } + assert parse_od_get(cfg.value.get()) == {'dodval1.dod1a.st2': None, + 'dodval1.dod1b.st2': None, + 'dodval2.dod1a.st2': None, + 'dodval2.dod1b.st2': None, + 'st3': None, + } assert cfg.option('dodval1.dod1a.st2').owner.isdefault() assert cfg.option('dodval1.dod1a.st2').value.get() is None assert cfg.option('dodval1.dod1b.st2').value.get() is None @@ -1684,12 +1692,12 @@ def test_subdynod_dyndescription_root(): assert cfg.option('st3').value.get() is None # cfg.option('dodval1.dod1a.st2').value.set('val') - assert cfg.value.get() == {'dodval1.dod1a.st2': 'val', - 'dodval1.dod1b.st2': None, - 'dodval2.dod1a.st2': None, - 'dodval2.dod1b.st2': None, - 'st3': 'val', - } + assert parse_od_get(cfg.value.get()) == {'dodval1.dod1a.st2': 'val', + 'dodval1.dod1b.st2': None, + 'dodval2.dod1a.st2': None, + 'dodval2.dod1b.st2': None, + 'st3': 'val', + } assert not cfg.option('dodval1.dod1a.st2').owner.isdefault() assert cfg.option('dodval1.dod1a.st2').value.get() == 'val' assert cfg.option('dodval1.dod1b.st2').value.get() is None @@ -1698,12 +1706,12 @@ def test_subdynod_dyndescription_root(): assert cfg.option('st3').value.get() == 'val' # cfg.option('dodval2.dod1a.st2').value.reset() - assert cfg.value.get() == {'dodval1.dod1a.st2': 'val', - 'dodval1.dod1b.st2': None, - 'dodval2.dod1a.st2': None, - 'dodval2.dod1b.st2': None, - 'st3': 'val', - } + assert parse_od_get(cfg.value.get()) == {'dodval1.dod1a.st2': 'val', + 'dodval1.dod1b.st2': None, + 'dodval2.dod1a.st2': None, + 'dodval2.dod1b.st2': None, + 'st3': 'val', + } assert not cfg.option('dodval1.dod1a.st2').owner.isdefault() assert cfg.option('dodval1.dod1a.st2').value.get() == 'val' assert cfg.option('dodval1.dod1b.st2').value.get() is None @@ -1712,12 +1720,12 @@ def test_subdynod_dyndescription_root(): assert cfg.option('st3').value.get() == 'val' # cfg.option('dodval1.dod1a.st2').value.reset() - assert cfg.value.get() == {'dodval1.dod1a.st2': None, - 'dodval1.dod1b.st2': None, - 'dodval2.dod1a.st2': None, - 'dodval2.dod1b.st2': None, - 'st3': None, - } + assert parse_od_get(cfg.value.get()) == {'dodval1.dod1a.st2': None, + 'dodval1.dod1b.st2': None, + 'dodval2.dod1a.st2': None, + 'dodval2.dod1b.st2': None, + 'st3': None, + } assert cfg.option('dodval1.dod1a.st2').owner.isdefault() assert cfg.option('dodval1.dod1a.st2').value.get() is None assert cfg.option('dodval1.dod1b.st2').value.get() is None @@ -1732,15 +1740,15 @@ def test_subdynod_dyndescription(): dod1 = DynOptionDescription('dod1', '', [st2], suffixes=Calculation(return_list, Params(ParamValue(['a', 'b'])))) dod = DynOptionDescription('dod', '', [dod1], suffixes=Calculation(return_list)) od1 = OptionDescription('od', '', [dod]) - st3 = StrOption('st3', '', Calculation(return_dynval, Params(ParamDynOption(st2, 'dodval1.dod1a.st2', dod)))) + st3 = StrOption('st3', '', Calculation(return_dynval, Params(ParamDynOption(st2, ['val1', 'a'], dod)))) od = OptionDescription('od', '', [od1, st3]) #, st4]) cfg = Config(od) - assert cfg.value.get() == {'od.dodval1.dod1a.st2': None, - 'od.dodval1.dod1b.st2': None, - 'od.dodval2.dod1a.st2': None, - 'od.dodval2.dod1b.st2': None, - 'st3': None, - } + assert parse_od_get(cfg.value.get()) == {'od.dodval1.dod1a.st2': None, + 'od.dodval1.dod1b.st2': None, + 'od.dodval2.dod1a.st2': None, + 'od.dodval2.dod1b.st2': None, + 'st3': None, + } assert cfg.option('od.dodval1.dod1a.st2').owner.isdefault() assert cfg.option('od.dodval1.dod1a.st2').value.get() is None assert cfg.option('od.dodval1.dod1b.st2').value.get() is None @@ -1750,12 +1758,12 @@ def test_subdynod_dyndescription(): assert cfg.option('st3').value.get() is None # cfg.option('od.dodval1.dod1a.st2').value.set('val') - assert cfg.value.get() == {'od.dodval1.dod1a.st2': 'val', - 'od.dodval1.dod1b.st2': None, - 'od.dodval2.dod1a.st2': None, - 'od.dodval2.dod1b.st2': None, - 'st3': 'val', - } + assert parse_od_get(cfg.value.get()) == {'od.dodval1.dod1a.st2': 'val', + 'od.dodval1.dod1b.st2': None, + 'od.dodval2.dod1a.st2': None, + 'od.dodval2.dod1b.st2': None, + 'st3': 'val', + } assert not cfg.option('od.dodval1.dod1a.st2').owner.isdefault() assert cfg.option('od.dodval1.dod1a.st2').value.get() == 'val' assert cfg.option('od.dodval1.dod1b.st2').value.get() is None @@ -1764,12 +1772,12 @@ def test_subdynod_dyndescription(): assert cfg.option('st3').value.get() == 'val' # cfg.option('od.dodval2.dod1a.st2').value.reset() - assert cfg.value.get() == {'od.dodval1.dod1a.st2': 'val', - 'od.dodval1.dod1b.st2': None, - 'od.dodval2.dod1a.st2': None, - 'od.dodval2.dod1b.st2': None, - 'st3': 'val', - } + assert parse_od_get(cfg.value.get()) == {'od.dodval1.dod1a.st2': 'val', + 'od.dodval1.dod1b.st2': None, + 'od.dodval2.dod1a.st2': None, + 'od.dodval2.dod1b.st2': None, + 'st3': 'val', + } assert not cfg.option('od.dodval1.dod1a.st2').owner.isdefault() assert cfg.option('od.dodval1.dod1a.st2').value.get() == 'val' assert cfg.option('od.dodval1.dod1b.st2').value.get() is None @@ -1778,12 +1786,12 @@ def test_subdynod_dyndescription(): assert cfg.option('st3').value.get() == 'val' # cfg.option('od.dodval1.dod1a.st2').value.reset() - assert cfg.value.get() == {'od.dodval1.dod1a.st2': None, - 'od.dodval1.dod1b.st2': None, - 'od.dodval2.dod1a.st2': None, - 'od.dodval2.dod1b.st2': None, - 'st3': None, - } + assert parse_od_get(cfg.value.get()) == {'od.dodval1.dod1a.st2': None, + 'od.dodval1.dod1b.st2': None, + 'od.dodval2.dod1a.st2': None, + 'od.dodval2.dod1b.st2': None, + 'st3': None, + } assert cfg.option('od.dodval1.dod1a.st2').owner.isdefault() assert cfg.option('od.dodval1.dod1a.st2').value.get() is None assert cfg.option('od.dodval1.dod1b.st2').value.get() is None @@ -1792,91 +1800,91 @@ def test_subdynod_dyndescription(): assert cfg.option('st3').value.get() is None # assert not list_sessions() -def test_subdynod_dyndescription_2(): - st2 = StrOption('st2', '') - st1 = StrOption('st1', '', default=['a', 'b'], multi=True) - dod1 = DynOptionDescription('dod1', '', [st2], suffixes=Calculation(return_list, Params(ParamOption(st1)))) - dod = DynOptionDescription('dod', '', [dod1, st1], suffixes=Calculation(return_list)) - od1 = OptionDescription('od', '', [dod]) - st3 = StrOption('st3', '', Calculation(return_dynval, Params(ParamDynOption(st2, 'dodval1.dod1a.st2', dod)))) - od = OptionDescription('od', '', [od1, st3]) #, st4]) - cfg = Config(od) - assert cfg.value.get() == {'od.dodval1.dod1a.st2': None, - 'od.dodval1.dod1b.st2': None, - 'od.dodval1.st1': ['a', 'b'], - 'od.dodval2.dod1a.st2': None, - 'od.dodval2.dod1b.st2': None, - 'od.dodval2.st1': ['a', 'b'], - 'st3': None, - } - cfg.cache.reset() - assert cfg.option('od.dodval1.dod1a.st2').value.get() is None - assert cfg.option('od.dodval1.dod1b.st2').value.get() is None - assert cfg.option('od.dodval1.st1').value.get() == ['a', 'b'] - assert cfg.option('od.dodval2.dod1a.st2').value.get() is None - assert cfg.option('od.dodval2.dod1b.st2').value.get() is None - assert cfg.option('od.dodval2.st1').value.get() == ['a', 'b'] - assert cfg.option('st3').value.get() is None - # - cfg.option('od.dodval1.st1').value.set(['a']) - cfg.option('od.dodval2.st1').value.set(['b', 'c']) - assert cfg.value.get() == {'od.dodval1.st1': ['a'], - 'od.dodval1.dod1a.st2': None, - 'od.dodval2.st1': ['b', 'c'], - 'od.dodval2.dod1b.st2': None, - 'od.dodval2.dod1c.st2': None, - 'st3': None, - } - - -def test_subdynod_dyndescription_leadership(): - st1 = StrOption('st1', '', multi=True) - st2 = StrOption('st2', '', multi=True) - stm = Leadership('stm', '', [st1, st2]) - dod1 = DynOptionDescription('dod1', '', [stm], suffixes=Calculation(return_list, Params(ParamValue(['a', 'b'])))) - dod = DynOptionDescription('dod', '', [dod1], suffixes=Calculation(return_list)) - od1 = OptionDescription('od', '', [dod]) - st3 = StrOption('st3', '', Calculation(return_dynval, Params(ParamDynOption(st1, 'dodval1.dod1a.stm.st1', dod))), multi=True) - # FIXME st4 = StrOption('st4', '', Calculation(return_dynval, Params(ParamOption(st2))), multi=True) - st5 = StrOption('st5', '', Calculation(return_dynval, Params(ParamDynOption(st2, 'dodval1.dod1a.stm.st2', dod))), multi=True) - #cfg = Config(od1) - #FIXME - od = OptionDescription('od', '', [od1, st3 , st5]) #, st4]) - cfg = Config(od) - assert cfg.value.get() == {'od.dodval1.dod1a.stm.st1': [], - 'od.dodval1.dod1b.stm.st1': [], - 'od.dodval2.dod1a.stm.st1': [], - 'od.dodval2.dod1b.stm.st1': [], - 'st3': [], - 'st5': [], - } - assert cfg.option('od.dodval1.dod1a.stm.st1').owner.isdefault() - assert cfg.option('od.dodval1.dod1a.stm.st1').value.get() == [] - assert cfg.option('od.dodval1.dod1b.stm.st1').value.get() == [] - assert cfg.option('od.dodval2.dod1a.stm.st1').value.get() == [] - assert cfg.option('od.dodval2.dod1b.stm.st1').value.get() == [] - assert cfg.option('od.dodval2.dod1b.stm.st1').value.get() == [] - assert cfg.option('st3').value.get() == [] - assert cfg.option('st5').value.get() == [] - # - cfg.option('od.dodval1.dod1a.stm.st1').value.set(['val']) - assert cfg.option('st3').value.get() == ['val'] - assert cfg.value.get() == {'od.dodval1.dod1a.stm.st1': [{'od.dodval1.dod1a.stm.st1': 'val', - 'od.dodval1.dod1a.stm.st2': None}], - 'od.dodval1.dod1b.stm.st1': [], - 'od.dodval2.dod1a.stm.st1': [], - 'od.dodval2.dod1b.stm.st1': [], - 'st3': ['val'], - 'st5': [], - } - assert not cfg.option('od.dodval1.dod1a.stm.st1').owner.isdefault() - assert cfg.option('od.dodval1.dod1a.stm.st1').value.get() == ['val'] - assert cfg.option('od.dodval1.dod1b.stm.st1').value.get() == [] - assert cfg.option('od.dodval2.dod1a.stm.st1').value.get() == [] - assert cfg.option('od.dodval2.dod1b.stm.st1').value.get() == [] - # - - +#def test_subdynod_dyndescription_2(): +# st2 = StrOption('st2', '') +# st1 = StrOption('st1', '', default=['a', 'b'], multi=True) +# dod1 = DynOptionDescription('dod1', '', [st2], suffixes=Calculation(return_list, Params(ParamOption(st1)))) +# dod = DynOptionDescription('dod', '', [dod1, st1], suffixes=Calculation(return_list)) +# od1 = OptionDescription('od', '', [dod]) +# st3 = StrOption('st3', '', Calculation(return_dynval, Params(ParamDynOption(st2, ['val1', 'a'], dod)))) +# od = OptionDescription('od', '', [od1, st3]) #, st4]) +# cfg = Config(od) +# assert cfg.value.get() == {'od.dodval1.dod1a.st2': None, +# 'od.dodval1.dod1b.st2': None, +# 'od.dodval1.st1': ['a', 'b'], +# 'od.dodval2.dod1a.st2': None, +# 'od.dodval2.dod1b.st2': None, +# 'od.dodval2.st1': ['a', 'b'], +# 'st3': None, +# } +# cfg.cache.reset() +# assert cfg.option('od.dodval1.dod1a.st2').value.get() is None +# assert cfg.option('od.dodval1.dod1b.st2').value.get() is None +# assert cfg.option('od.dodval1.st1').value.get() == ['a', 'b'] +# assert cfg.option('od.dodval2.dod1a.st2').value.get() is None +# assert cfg.option('od.dodval2.dod1b.st2').value.get() is None +# assert cfg.option('od.dodval2.st1').value.get() == ['a', 'b'] +# assert cfg.option('st3').value.get() is None +# # +# cfg.option('od.dodval1.st1').value.set(['a']) +# cfg.option('od.dodval2.st1').value.set(['b', 'c']) +# assert cfg.value.get() == {'od.dodval1.st1': ['a'], +# 'od.dodval1.dod1a.st2': None, +# 'od.dodval2.st1': ['b', 'c'], +# 'od.dodval2.dod1b.st2': None, +# 'od.dodval2.dod1c.st2': None, +# 'st3': None, +# } +# +# +#def test_subdynod_dyndescription_leadership(): +# st1 = StrOption('st1', '', multi=True) +# st2 = StrOption('st2', '', multi=True) +# stm = Leadership('stm', '', [st1, st2]) +# dod1 = DynOptionDescription('dod1', '', [stm], suffixes=Calculation(return_list, Params(ParamValue(['a', 'b'])))) +# dod = DynOptionDescription('dod', '', [dod1], suffixes=Calculation(return_list)) +# od1 = OptionDescription('od', '', [dod]) +# st3 = StrOption('st3', '', Calculation(return_dynval, Params(ParamDynOption(st1, ['val1', 'a'], dod))), multi=True) +# # FIXME st4 = StrOption('st4', '', Calculation(return_dynval, Params(ParamOption(st2))), multi=True) +# st5 = StrOption('st5', '', Calculation(return_dynval, Params(ParamDynOption(st2, ['val1', 'a'], dod))), multi=True) +# #cfg = Config(od1) +# #FIXME +# od = OptionDescription('od', '', [od1, st3 , st5]) #, st4]) +# cfg = Config(od) +# assert cfg.value.get() == {'od.dodval1.dod1a.stm.st1': [], +# 'od.dodval1.dod1b.stm.st1': [], +# 'od.dodval2.dod1a.stm.st1': [], +# 'od.dodval2.dod1b.stm.st1': [], +# 'st3': [], +# 'st5': [], +# } +# assert cfg.option('od.dodval1.dod1a.stm.st1').owner.isdefault() +# assert cfg.option('od.dodval1.dod1a.stm.st1').value.get() == [] +# assert cfg.option('od.dodval1.dod1b.stm.st1').value.get() == [] +# assert cfg.option('od.dodval2.dod1a.stm.st1').value.get() == [] +# assert cfg.option('od.dodval2.dod1b.stm.st1').value.get() == [] +# assert cfg.option('od.dodval2.dod1b.stm.st1').value.get() == [] +# assert cfg.option('st3').value.get() == [] +# assert cfg.option('st5').value.get() == [] +# # +# cfg.option('od.dodval1.dod1a.stm.st1').value.set(['val']) +# assert cfg.option('st3').value.get() == ['val'] +# assert cfg.value.get() == {'od.dodval1.dod1a.stm.st1': [{'od.dodval1.dod1a.stm.st1': 'val', +# 'od.dodval1.dod1a.stm.st2': None}], +# 'od.dodval1.dod1b.stm.st1': [], +# 'od.dodval2.dod1a.stm.st1': [], +# 'od.dodval2.dod1b.stm.st1': [], +# 'st3': ['val'], +# 'st5': [], +# } +# assert not cfg.option('od.dodval1.dod1a.stm.st1').owner.isdefault() +# assert cfg.option('od.dodval1.dod1a.stm.st1').value.get() == ['val'] +# assert cfg.option('od.dodval1.dod1b.stm.st1').value.get() == [] +# assert cfg.option('od.dodval2.dod1a.stm.st1').value.get() == [] +# assert cfg.option('od.dodval2.dod1b.stm.st1').value.get() == [] +# # +# +# def test_invalid_symlink_dyndescription(): st = StrOption('st', '') st2 = SymLinkOption('st2', st) @@ -1913,737 +1921,751 @@ def test_invalid_name_dyndescription(): # assert not list_sessions() -def test_leadership_dyndescription_convert(): - st1 = StrOption('st1', "", multi=True) - st2 = StrOption('st2', "", multi=True) - stm = Leadership('st1', '', [st1, st2]) - st = ConvertDynOptionDescription('st', '', [stm], suffixes=Calculation(return_list_dot)) - od = OptionDescription('od', '', [st]) - od1 = OptionDescription('od', '', [od]) - cfg = Config(od1) - owner = cfg.owner.get() - # - assert cfg.value.get() == {'od.stval1.st1.st1': [], 'od.stval2.st1.st1': []} - assert cfg.option('od.stval1.st1.st1').value.get() == [] - assert cfg.option('od.stval2.st1.st1').value.get() == [] - assert cfg.option('od.stval1.st1.st1').owner.isdefault() - assert cfg.option('od.stval2.st1.st1').owner.isdefault() - # - cfg.option('od.stval1.st1.st1').value.set(['yes']) - assert cfg.value.get() == {'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'yes', 'od.stval1.st1.st2': None}], 'od.stval2.st1.st1': []} - assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] - assert cfg.option('od.stval1.st1.st2', 0).value.get() == None - assert cfg.option('od.stval2.st1.st1').value.get() == [] - assert cfg.option('od.stval1.st1.st1').owner.get() == owner - assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() - assert cfg.option('od.stval2.st1.st1').owner.isdefault() - # - cfg.option('od.stval1.st1.st2', 0).value.set('no') - assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] - assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'no' - assert cfg.option('od.stval2.st1.st1').value.get() == [] - assert cfg.option('od.stval1.st1.st1').owner.get() == owner - assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner - assert cfg.option('od.stval2.st1.st1').owner.isdefault() - # - cfg.option('od.stval1.st1.st1').value.pop(0) - assert cfg.option('od.stval1.st1.st1').value.get() == [] - assert cfg.option('od.stval2.st1.st1').value.get() == [] - assert cfg.option('od.stval1.st1.st1').owner.get() == owner - assert cfg.option('od.stval2.st1.st1').owner.isdefault() - # - cfg.option('od.stval1.st1.st1').value.set(['yes']) - cfg.option('od.stval1.st1.st2', 0).value.set('yes') - assert cfg.option('od.stval1.st1.st1').owner.get() == owner - assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner - assert cfg.option('od.stval2.st1.st1').owner.isdefault() - assert cfg.option('od.stval1.st1.st1').owner.get() == owner - cfg.option('od.stval1.st1.st2', 0).value.reset() - assert cfg.option('od.stval1.st1.st1').owner.get() == owner - assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() - # - cfg.option('od.stval1.st1.st1').value.set(['yes']) - cfg.option('od.stval1.st1.st2', 0).value.set('yes') - cfg.option('od.stval1.st1.st1').value.reset() - assert cfg.option('od.stval1.st1.st1').value.get() == [] - assert cfg.option('od.stval2.st1.st1').value.get() == [] - assert cfg.option('od.stval1.st1.st1').owner.isdefault() - assert cfg.option('od.stval2.st1.st1').owner.isdefault() -# assert not list_sessions() - - -def test_leadership_callback_samegroup_dyndescription_convert(): - st1 = StrOption('st1', "", multi=True) - st2 = StrOption('st2', "", multi=True) - st3 = StrOption('st3', "", Calculation(return_dynval, Params(ParamOption(st2))), multi=True) - stm = Leadership('st1', '', [st1, st2, st3]) - stt = ConvertDynOptionDescription('st', '', [stm], suffixes=Calculation(return_list_dot)) - od1 = OptionDescription('od', '', [stt]) - od2 = OptionDescription('od', '', [od1]) - cfg = Config(od2) - owner = cfg.owner.get() - assert cfg.value.get() == {'od.stval1.st1.st1': [], 'od.stval2.st1.st1': []} - assert cfg.option('od.stval1.st1.st1').value.get() == [] - assert cfg.option('od.stval2.st1.st1').value.get() == [] - assert cfg.option('od.stval1.st1.st1').owner.isdefault() - assert cfg.option('od.stval2.st1.st1').owner.isdefault() - # - cfg.option('od.stval1.st1.st1').value.set(['yes']) - assert cfg.value.get() == {'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'yes', 'od.stval1.st1.st2': None, 'od.stval1.st1.st3': None}], 'od.stval2.st1.st1': []} - assert cfg.option('od.stval1.st1.st1').owner.get() == owner - assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() - assert cfg.option('od.stval1.st1.st3', 0).owner.isdefault() - assert cfg.option('od.stval2.st1.st1').owner.isdefault() - # - cfg.option('od.stval1.st1.st2', 0).value.set('yes') - assert cfg.value.get() == {'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'yes', 'od.stval1.st1.st2': 'yes', 'od.stval1.st1.st3': 'yes'}], 'od.stval2.st1.st1': []} - assert cfg.option('od.stval1.st1.st1').owner.get() == owner - assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner - assert cfg.option('od.stval1.st1.st3', 0).owner.isdefault() - assert cfg.option('od.stval2.st1.st1').owner.isdefault() -# assert not list_sessions() - - -def test_dyn_with_leader_hidden_in_config(): - ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) - netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, properties=('hidden',)) - interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0], properties=('hidden',)) - dyn = DynOptionDescription('leader', '', [interface1], suffixes=Calculation(return_list)) - od1 = OptionDescription('root', '', [dyn]) - cfg = Config(od1) - cfg.property.read_write() - cfg.permissive.add('hidden') - assert cfg.forcepermissive.option('leaderval1.ip_admin_eth0.ip_admin_eth0').value.get() == [] - cfg.forcepermissive.option('leaderval1.ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) - assert cfg.forcepermissive.option('leaderval1.ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None - with pytest.raises(PropertiesOptionError): - cfg.option('leaderval1.ip_admin_eth0.ip_admin_eth0').value.get() - with pytest.raises(PropertiesOptionError): - cfg.option('leaderval1.ip_admin_eth0.netmask_admin_eth0', 0).value.get() - cfg.value.get() == {'leaderval1.ip_admin_eth0.ip_admin_eth0': [{'leaderval1.ip_admin_eth0.ip_admin_eth0': '192.168.1.1'}], - 'leaderval2.ip_admin_eth0.ip_admin_eth0': [{'leaderval2.ip_admin_eth0.ip_admin_eth0': '192.168.1.1'}]} -# assert not list_sessions() - - -def test_dyn_leadership_requires(): - ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True, properties=('notunique',)) - disabled_property = Calculation(calc_value, - Params(ParamValue('disabled'), - kwargs={'condition': ParamOption(ip_admin_eth0, notraisepropertyerror=True), - 'expected': ParamValue('192.168.1.1'), - 'no_condition_is_invalid': ParamValue(True), - 'index': ParamIndex()})) - netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, properties=(disabled_property,)) - interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) - dyn = DynOptionDescription('leader', '', [interface1], suffixes=Calculation(return_list)) - od1 = OptionDescription('toto', '', [dyn]) - cfg = Config(od1) - cfg.property.read_write() - assert cfg.option('leaderval1.ip_admin_eth0.ip_admin_eth0').value.get() == [] - cfg.option('leaderval1.ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2']) - assert cfg.option('leaderval1.ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None - assert cfg.option('leaderval1.ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2'] - # - cfg.option('leaderval1.ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1']) - assert cfg.option('leaderval1.ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None - with pytest.raises(PropertiesOptionError): - cfg.option('leaderval1.ip_admin_eth0.netmask_admin_eth0', 1).value.get() - # - cfg.option('leaderval1.ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.2']) - assert cfg.option('leaderval1.ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None - assert cfg.option('leaderval1.ip_admin_eth0.netmask_admin_eth0', 1).value.get() is None - cfg.option('leaderval1.ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.255') - assert cfg.option('leaderval1.ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.255' - ret = cfg.value.get() - assert ret == {'leaderval1.ip_admin_eth0.ip_admin_eth0': [{'leaderval1.ip_admin_eth0.ip_admin_eth0': '192.168.1.2', 'leaderval1.ip_admin_eth0.netmask_admin_eth0': None}, - {'leaderval1.ip_admin_eth0.ip_admin_eth0': '192.168.1.2', 'leaderval1.ip_admin_eth0.netmask_admin_eth0': '255.255.255.255'}], - 'leaderval2.ip_admin_eth0.ip_admin_eth0': []} - - # - cfg.option('leaderval1.ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1']) - assert cfg.option('leaderval1.ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None - with pytest.raises(PropertiesOptionError): - cfg.option('leaderval1.ip_admin_eth0.netmask_admin_eth0', 1).value.get() - assert cfg.value.get() == {'leaderval1.ip_admin_eth0.ip_admin_eth0': [{'leaderval1.ip_admin_eth0.ip_admin_eth0': '192.168.1.2', 'leaderval1.ip_admin_eth0.netmask_admin_eth0': None}, {'leaderval1.ip_admin_eth0.ip_admin_eth0': '192.168.1.1'}], 'leaderval2.ip_admin_eth0.ip_admin_eth0': []} - # -# assert not list_sessions() - - -def test_dyn_leadership_mandatory(): - nsd_zones_all = StrOption(name="nsd_zones_all", doc="nsd_zones_all", multi=True, default=['val1', 'val2']) - is_auto = BoolOption(name="is_auto_", doc="is auto") - hostname = DomainnameOption(name="hostname_", doc="hostname_", multi=True, type='hostname') - choice = ChoiceOption(name="type_", doc="type_", values=('A', 'CNAME'), multi=True, default_multi="A") - leadership = Leadership(name="hostname_", doc="hostname_", children=[hostname, choice], properties=frozenset({Calculation(calc_value, Params(ParamValue('hidden'), kwargs={'condition': ParamOption(is_auto, notraisepropertyerror=True), 'expected': ParamValue(True)}))})) - dyn = DynOptionDescription(name="nsd_zone_", doc="Zone ", suffixes=Calculation(calc_value, Params((ParamOption(nsd_zones_all, notraisepropertyerror=True)))), children=[is_auto, leadership], properties=frozenset({"normal"})) - od1 = OptionDescription(name="nsd", doc="nsd", children=[nsd_zones_all, dyn]) - cfg = Config(od1) - assert cfg.value.mandatory() == [] -# assert not list_sessions() - - -def test_dyn_symlink(): - remotes = StrOption("remotes", "Remotes", ['a', 'b', 'c'], multi=True) - remote_ip = StrOption("remote_ip_", "Remote IP", Calculation(calc_value, Params(ParamSuffix()))) - dyn_remote = DynOptionDescription("remote_", "Account for ", suffixes=Calculation(calc_value, Params((ParamOption(remotes)))), children=[remote_ip]) - name = SymLinkOption("name", opt=remote_ip) - od1 = OptionDescription(name="accounts", doc="accounts.remote_.remote_ip_", children=[remotes, dyn_remote, name]) - cfg = Config(od1) - assert cfg.option('name').value.get() == ['a', 'b', 'c'] - assert cfg.option('name').ismulti() == True - assert cfg.option('name').issubmulti() == False - assert cfg.value.get() == {'remotes': ['a', 'b', 'c'], 'remote_a.remote_ip_': 'a', 'remote_b.remote_ip_': 'b', 'remote_c.remote_ip_': 'c', 'name': ['a', 'b', 'c']} -# assert not list_sessions() - - -def test_dyn_callback_with_not_dyn(): - remotes = StrOption("remotes", "Remotes", ['a', 'b', 'c'], multi=True) - remote_ip = StrOption("remote_ip_", "Remote IP", Calculation(calc_value, Params(ParamSuffix()))) - dyn_remote = DynOptionDescription("remote_", "Account for ", suffixes=Calculation(calc_value, Params((ParamOption(remotes)))), children=[remote_ip]) - names = StrOption('names', '', Calculation(calc_value, Params(ParamOption(remote_ip))), multi=True) - od1 = OptionDescription(name="accounts", doc="accounts.remote_.remote_ip_", children=[remotes, dyn_remote, names]) - cfg = Config(od1) - assert cfg.option('names').value.get() == ['a', 'b', 'c'] - assert cfg.option('names').ismulti() == True - assert cfg.option('names').issubmulti() == False - assert cfg.value.get() == {'remotes': ['a', 'b', 'c'], 'remote_a.remote_ip_': 'a', 'remote_b.remote_ip_': 'b', 'remote_c.remote_ip_': 'c', 'names': ['a', 'b', 'c']} -# assert not list_sessions() - - -def test_dyn_link_subdyn(): - database_names = StrOption(name="database_names", doc="database_names", multi=True, default=["srep", "snom", "srem"]) - password = StrOption(name="password", doc="password", properties=('mandatory',)) - name = StrOption(name="name", doc="name", properties=('mandatory',)) - password2 = StrOption(name="password", doc="password", default=Calculation(calc_value, Params((ParamOption(password)))), properties=('mandatory',)) - user = OptionDescription(name="user", doc="user", children=[name, password2]) - sub = OptionDescription(name="sub", doc="sub", children=[user]) - user_database = DynOptionDescription(name="user_database_", doc="user database", suffixes=Calculation(calc_value, Params((ParamOption(database_names, notraisepropertyerror=True)))), children=[password, sub]) - socle = OptionDescription(name="socle", doc="socle", children=[user_database, database_names]) - root = OptionDescription(name="baseoption", doc="baseoption", children=[socle]) - cfg = Config(root) - assert cfg.option('socle.database_names').value.get() == ["srep", "snom", "srem"] - assert cfg.option('socle.user_database_srep.password').value.get() is None - assert cfg.option('socle.user_database_srep.sub.user.name').value.get() is None - assert cfg.option('socle.user_database_srep.sub.user.password').value.get() is None - assert [opt.path() for opt in cfg.value.mandatory()] == ['socle.user_database_srep.password', - 'socle.user_database_srep.sub.user.name', - 'socle.user_database_srep.sub.user.password', - 'socle.user_database_snom.password', - 'socle.user_database_snom.sub.user.name', - 'socle.user_database_snom.sub.user.password', - 'socle.user_database_srem.password', - 'socle.user_database_srem.sub.user.name', - 'socle.user_database_srem.sub.user.password', - ] - # - cfg.option('socle.user_database_srep.password').value.set('pass') - cfg.option('socle.user_database_snom.sub.user.password').value.set('pass') - assert cfg.option('socle.user_database_srep.password').value.get() is 'pass' - assert cfg.option('socle.user_database_srep.sub.user.name').value.get() is None - assert cfg.option('socle.user_database_srep.sub.user.password').value.get() is 'pass' - assert [opt.path() for opt in cfg.value.mandatory()] == ['socle.user_database_srep.sub.user.name', - 'socle.user_database_snom.password', - 'socle.user_database_snom.sub.user.name', - 'socle.user_database_srem.password', - 'socle.user_database_srem.sub.user.name', - 'socle.user_database_srem.sub.user.password', - ] - # - cfg.option('socle.user_database_snom.password').value.set('pass2') - cfg.option('socle.user_database_srem.password').value.set('pass3') - cfg.option('socle.user_database_srep.sub.user.name').value.set('name1') - cfg.option('socle.user_database_snom.sub.user.name').value.set('name2') - cfg.option('socle.user_database_srem.sub.user.name').value.set('name3') - assert [opt.path() for opt in cfg.value.mandatory()] == [] - assert cfg.value.get() == {'socle.database_names': ['srep', - 'snom', - 'srem'], - 'socle.user_database_snom.password': 'pass2', - 'socle.user_database_snom.sub.user.name': 'name2', - 'socle.user_database_snom.sub.user.password': 'pass', - 'socle.user_database_srem.password': 'pass3', - 'socle.user_database_srem.sub.user.name': 'name3', - 'socle.user_database_srem.sub.user.password': 'pass3', - 'socle.user_database_srep.password': 'pass', - 'socle.user_database_srep.sub.user.name': 'name1', - 'socle.user_database_srep.sub.user.password': 'pass', - } - # - assert [opt.path() for opt in cfg.value.mandatory()] == [] - - -def test_dyn_link_subdyn_2(): - database_names = StrOption(name="database_names", doc="database_names", multi=True, default=["srep", "snom", "srem"]) - password2 = StrOption(name="password", doc="password", properties=('mandatory',)) - password = StrOption(name="password", doc="password", default=Calculation(calc_value, Params((ParamOption(password2)))), properties=('mandatory',)) - name = StrOption(name="name", doc="name", properties=('mandatory',)) - user = OptionDescription(name="user", doc="user", children=[name, password2]) - sub = OptionDescription(name="sub", doc="sub", children=[user]) - user_database = DynOptionDescription(name="user_database_", doc="user database", suffixes=Calculation(calc_value, Params((ParamOption(database_names, notraisepropertyerror=True)))), children=[password, sub]) - socle = OptionDescription(name="socle", doc="socle", children=[user_database, database_names]) - root = OptionDescription(name="baseoption", doc="baseoption", children=[socle]) - cfg = Config(root) - assert cfg.option('socle.database_names').value.get() == ["srep", "snom", "srem"] - assert cfg.option('socle.user_database_srep.password').value.get() is None - assert cfg.option('socle.user_database_srep.sub.user.name').value.get() is None - assert cfg.option('socle.user_database_srep.sub.user.password').value.get() is None - assert [opt.path() for opt in cfg.value.mandatory()] == ['socle.user_database_srep.password', - 'socle.user_database_srep.sub.user.name', - 'socle.user_database_srep.sub.user.password', - 'socle.user_database_snom.password', - 'socle.user_database_snom.sub.user.name', - 'socle.user_database_snom.sub.user.password', - 'socle.user_database_srem.password', - 'socle.user_database_srem.sub.user.name', - 'socle.user_database_srem.sub.user.password', - ] - # - cfg.option('socle.user_database_srep.password').value.set('pass') - cfg.option('socle.user_database_snom.sub.user.password').value.set('pass') - assert cfg.option('socle.user_database_srep.password').value.get() is 'pass' - assert cfg.option('socle.user_database_srep.sub.user.name').value.get() is None - assert cfg.option('socle.user_database_srep.sub.user.password').value.get() is None - assert [opt.path() for opt in cfg.value.mandatory()] == ['socle.user_database_srep.sub.user.name', - 'socle.user_database_srep.sub.user.password', - 'socle.user_database_snom.sub.user.name', - 'socle.user_database_srem.password', - 'socle.user_database_srem.sub.user.name', - 'socle.user_database_srem.sub.user.password', - ] - # - cfg.option('socle.user_database_srep.sub.user.password').value.set('pass2') - cfg.option('socle.user_database_srem.sub.user.password').value.set('pass3') - cfg.option('socle.user_database_srep.sub.user.name').value.set('name1') - cfg.option('socle.user_database_snom.sub.user.name').value.set('name2') - cfg.option('socle.user_database_srem.sub.user.name').value.set('name3') - assert [opt.path() for opt in cfg.value.mandatory()] == [] - assert cfg.value.get() == {'socle.database_names': ['srep', - 'snom', - 'srem'], - 'socle.user_database_snom.password': 'pass', - 'socle.user_database_snom.sub.user.name': 'name2', - 'socle.user_database_snom.sub.user.password': 'pass', - 'socle.user_database_srem.password': 'pass3', - 'socle.user_database_srem.sub.user.name': 'name3', - 'socle.user_database_srem.sub.user.password': 'pass3', - 'socle.user_database_srep.password': 'pass', - 'socle.user_database_srep.sub.user.name': 'name1', - 'socle.user_database_srep.sub.user.password': 'pass2', - } - # - assert [opt.path() for opt in cfg.value.mandatory()] == [] - - -def test_dyn_link_subdyn_twice(): - password = StrOption(name="password", doc="password", properties=('mandatory',)) - name = StrOption(name="name", doc="name", properties=('mandatory',)) - login = StrOption(name="login", doc="login", default=Calculation(calc_value, Params((ParamOption(name)))), properties=('mandatory',)) - password2 = StrOption(name="password2", doc="password2", default=Calculation(calc_value, Params((ParamOption(password)))), properties=('mandatory',)) - database_names = StrOption(name="database_names", doc="database_names", multi=True, default=["srep", "snom", "srem"]) - user_database = DynOptionDescription(name="user_database_", doc="user database", suffixes=Calculation(calc_value, Params((ParamOption(database_names, notraisepropertyerror=True)))), children=[name, login, password2]) - databases = OptionDescription(name="databases", doc="database", children=[password, user_database]) - schema_names = StrOption(name="database_schemas", doc="database_schemas", multi=True, default=["schema1", "schema2", "schema3"]) - schema = DynOptionDescription(name="schema_", doc="schema_", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[database_names, databases]) - socle = OptionDescription(name="socle", doc="socle", children=[schema, schema_names]) - root = OptionDescription(name="baseoption", doc="baseoption", children=[socle]) - cfg = Config(root) - assert cfg.value.get() == {'socle.database_schemas': ['schema1', - 'schema2', - 'schema3'], - 'socle.schema_schema1.database_names': ['srep', - 'snom', - 'srem'], - 'socle.schema_schema1.databases.password': None, - 'socle.schema_schema1.databases.user_database_snom.name': None, - 'socle.schema_schema1.databases.user_database_snom.login': None, - 'socle.schema_schema1.databases.user_database_snom.password2': None, - 'socle.schema_schema1.databases.user_database_srem.name': None, - 'socle.schema_schema1.databases.user_database_srem.login': None, - 'socle.schema_schema1.databases.user_database_srem.password2': None, - 'socle.schema_schema1.databases.user_database_srep.name': None, - 'socle.schema_schema1.databases.user_database_srep.login': None, - 'socle.schema_schema1.databases.user_database_srep.password2': None, - 'socle.schema_schema2.database_names': ['srep', - 'snom', - 'srem'], - 'socle.schema_schema2.databases.password': None, - 'socle.schema_schema2.databases.user_database_snom.name': None, - 'socle.schema_schema2.databases.user_database_snom.login': None, - 'socle.schema_schema2.databases.user_database_snom.password2': None, - 'socle.schema_schema2.databases.user_database_srem.name': None, - 'socle.schema_schema2.databases.user_database_srem.login': None, - 'socle.schema_schema2.databases.user_database_srem.password2': None, - 'socle.schema_schema2.databases.user_database_srep.name': None, - 'socle.schema_schema2.databases.user_database_srep.login': None, - 'socle.schema_schema2.databases.user_database_srep.password2': None, - 'socle.schema_schema3.database_names': ['srep', - 'snom', - 'srem'], - 'socle.schema_schema3.databases.password': None, - 'socle.schema_schema3.databases.user_database_snom.name': None, - 'socle.schema_schema3.databases.user_database_snom.login': None, - 'socle.schema_schema3.databases.user_database_snom.password2': None, - 'socle.schema_schema3.databases.user_database_srem.name': None, - 'socle.schema_schema3.databases.user_database_srem.login': None, - 'socle.schema_schema3.databases.user_database_srem.password2': None, - 'socle.schema_schema3.databases.user_database_srep.name': None, - 'socle.schema_schema3.databases.user_database_srep.login': None, - 'socle.schema_schema3.databases.user_database_srep.password2': None, - } - # - assert [opt.path() for opt in cfg.value.mandatory()] == ['socle.schema_schema1.databases.password', - 'socle.schema_schema1.databases.user_database_srep.name', - 'socle.schema_schema1.databases.user_database_srep.login', - 'socle.schema_schema1.databases.user_database_srep.password2', - 'socle.schema_schema1.databases.user_database_snom.name', - 'socle.schema_schema1.databases.user_database_snom.login', - 'socle.schema_schema1.databases.user_database_snom.password2', - 'socle.schema_schema1.databases.user_database_srem.name', - 'socle.schema_schema1.databases.user_database_srem.login', - 'socle.schema_schema1.databases.user_database_srem.password2', - 'socle.schema_schema2.databases.password', - 'socle.schema_schema2.databases.user_database_srep.name', - 'socle.schema_schema2.databases.user_database_srep.login', - 'socle.schema_schema2.databases.user_database_srep.password2', - 'socle.schema_schema2.databases.user_database_snom.name', - 'socle.schema_schema2.databases.user_database_snom.login', - 'socle.schema_schema2.databases.user_database_snom.password2', - 'socle.schema_schema2.databases.user_database_srem.name', - 'socle.schema_schema2.databases.user_database_srem.login', - 'socle.schema_schema2.databases.user_database_srem.password2', - 'socle.schema_schema3.databases.password', - 'socle.schema_schema3.databases.user_database_srep.name', - 'socle.schema_schema3.databases.user_database_srep.login', - 'socle.schema_schema3.databases.user_database_srep.password2', - 'socle.schema_schema3.databases.user_database_snom.name', - 'socle.schema_schema3.databases.user_database_snom.login', - 'socle.schema_schema3.databases.user_database_snom.password2', - 'socle.schema_schema3.databases.user_database_srem.name', - 'socle.schema_schema3.databases.user_database_srem.login', - 'socle.schema_schema3.databases.user_database_srem.password2', - ] - # - cfg.option('socle.schema_schema2.database_names').value.set(['another']) - assert cfg.value.get() == {'socle.database_schemas': ['schema1', - 'schema2', - 'schema3'], - 'socle.schema_schema1.database_names': ['srep', - 'snom', - 'srem'], - 'socle.schema_schema1.databases.password': None, - 'socle.schema_schema1.databases.user_database_snom.name': None, - 'socle.schema_schema1.databases.user_database_snom.login': None, - 'socle.schema_schema1.databases.user_database_snom.password2': None, - 'socle.schema_schema1.databases.user_database_srem.name': None, - 'socle.schema_schema1.databases.user_database_srem.login': None, - 'socle.schema_schema1.databases.user_database_srem.password2': None, - 'socle.schema_schema1.databases.user_database_srep.name': None, - 'socle.schema_schema1.databases.user_database_srep.login': None, - 'socle.schema_schema1.databases.user_database_srep.password2': None, - 'socle.schema_schema2.database_names': ['another'], - 'socle.schema_schema2.databases.password': None, - 'socle.schema_schema2.databases.user_database_another.name': None, - 'socle.schema_schema2.databases.user_database_another.login': None, - 'socle.schema_schema2.databases.user_database_another.password2': None, - 'socle.schema_schema3.database_names': ['srep', - 'snom', - 'srem'], - 'socle.schema_schema3.databases.password': None, - 'socle.schema_schema3.databases.user_database_snom.name': None, - 'socle.schema_schema3.databases.user_database_snom.login': None, - 'socle.schema_schema3.databases.user_database_snom.password2': None, - 'socle.schema_schema3.databases.user_database_srem.name': None, - 'socle.schema_schema3.databases.user_database_srem.login': None, - 'socle.schema_schema3.databases.user_database_srem.password2': None, - 'socle.schema_schema3.databases.user_database_srep.name': None, - 'socle.schema_schema3.databases.user_database_srep.login': None, - 'socle.schema_schema3.databases.user_database_srep.password2': None, - } - # - cfg.option('socle.database_schemas').value.set(['schema1']) - assert cfg.value.get() == {'socle.database_schemas': ['schema1'], - 'socle.schema_schema1.database_names': ['srep', - 'snom', - 'srem'], - 'socle.schema_schema1.databases.password': None, - 'socle.schema_schema1.databases.user_database_snom.name': None, - 'socle.schema_schema1.databases.user_database_snom.login': None, - 'socle.schema_schema1.databases.user_database_snom.password2': None, - 'socle.schema_schema1.databases.user_database_srem.name': None, - 'socle.schema_schema1.databases.user_database_srem.login': None, - 'socle.schema_schema1.databases.user_database_srem.password2': None, - 'socle.schema_schema1.databases.user_database_srep.name': None, - 'socle.schema_schema1.databases.user_database_srep.login': None, - 'socle.schema_schema1.databases.user_database_srep.password2': None, - } - # - cfg.option('socle.schema_schema1.databases.password').value.set('password') - cfg.option('socle.schema_schema1.databases.user_database_snom.name').value.set('name1') - cfg.option('socle.schema_schema1.databases.user_database_srem.name').value.set('name2') - cfg.option('socle.schema_schema1.databases.user_database_srep.name').value.set('name3') - assert cfg.value.get() == {'socle.database_schemas': ['schema1'], - 'socle.schema_schema1.database_names': ['srep', - 'snom', - 'srem'], - 'socle.schema_schema1.databases.password': 'password', - 'socle.schema_schema1.databases.user_database_snom.login': 'name1', - 'socle.schema_schema1.databases.user_database_snom.name': 'name1', - 'socle.schema_schema1.databases.user_database_snom.password2': 'password', - 'socle.schema_schema1.databases.user_database_srem.login': 'name2', - 'socle.schema_schema1.databases.user_database_srem.name': 'name2', - 'socle.schema_schema1.databases.user_database_srem.password2': 'password', - 'socle.schema_schema1.databases.user_database_srep.login': 'name3', - 'socle.schema_schema1.databases.user_database_srep.name': 'name3', - 'socle.schema_schema1.databases.user_database_srep.password2': 'password', - } - assert [opt.path() for opt in cfg.value.mandatory()] == [] - # - cfg.option('socle.schema_schema1.database_names').value.set(['snom']) - assert cfg.value.get() == {'socle.database_schemas': ['schema1'], - 'socle.schema_schema1.database_names': ['snom'], - 'socle.schema_schema1.databases.password': 'password', - 'socle.schema_schema1.databases.user_database_snom.login': 'name1', - 'socle.schema_schema1.databases.user_database_snom.name': 'name1', - 'socle.schema_schema1.databases.user_database_snom.password2': 'password', - } - assert [opt.path() for opt in cfg.value.mandatory()] == [] - - -def test_dyn_link_subdyn_tree(): - password = StrOption(name="password", doc="password", properties=('mandatory',)) - name = StrOption(name="name", doc="name", properties=('mandatory',)) - login = StrOption(name="login", doc="login", default=Calculation(calc_value, Params((ParamOption(name)))), properties=('mandatory',)) - password2 = StrOption(name="password2", doc="password2", default=Calculation(calc_value, Params((ParamOption(password)))), properties=('mandatory',)) - user_names = StrOption(name="users", doc="users", multi=True, default=["user1"]) - user_database = DynOptionDescription(name="user_database_", doc="user database", suffixes=Calculation(calc_value, Params((ParamOption(user_names, notraisepropertyerror=True)))), children=[name, login, password2]) - database_names = StrOption(name="database_names", doc="database_names", multi=True, default=["srep"]) - databases = DynOptionDescription(name="db_", doc="database", suffixes=Calculation(calc_value, Params((ParamOption(database_names, notraisepropertyerror=True)))), children=[user_names, password, user_database]) - schema_names = StrOption(name="database_schemas", doc="database_schemas", multi=True, default=["schema1"]) - schema = DynOptionDescription(name="schema_", doc="schema_", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[database_names, databases]) - socle = OptionDescription(name="socle", doc="socle", children=[schema, schema_names]) - root = OptionDescription(name="baseoption", doc="baseoption", children=[socle]) - cfg = Config(root) - assert [opt.path() for opt in cfg.value.mandatory()] == ['socle.schema_schema1.db_srep.password', - 'socle.schema_schema1.db_srep.user_database_user1.name', - 'socle.schema_schema1.db_srep.user_database_user1.login', - 'socle.schema_schema1.db_srep.user_database_user1.password2', - ] - # - cfg.option('socle.schema_schema1.db_srep.user_database_user1.name').value.set('name') - assert [opt.path() for opt in cfg.value.mandatory()] == ['socle.schema_schema1.db_srep.password', - 'socle.schema_schema1.db_srep.user_database_user1.password2', - ] - # - cfg.option('socle.schema_schema1.db_srep.password').value.set('password') - assert [opt.path() for opt in cfg.value.mandatory()] == [] - assert cfg.value.get() == {'socle.database_schemas': ['schema1'], - 'socle.schema_schema1.database_names': ['srep'], - 'socle.schema_schema1.db_srep.password': 'password', - 'socle.schema_schema1.db_srep.user_database_user1.login': 'name', - 'socle.schema_schema1.db_srep.user_database_user1.name': 'name', - 'socle.schema_schema1.db_srep.user_database_user1.password2': 'password', - 'socle.schema_schema1.db_srep.users': ['user1'], - } - # - cfg.option('socle.schema_schema1.db_srep.users').value.set(['user1', 'user2']) - assert cfg.value.get() == {'socle.database_schemas': ['schema1'], - 'socle.schema_schema1.database_names': ['srep'], - 'socle.schema_schema1.db_srep.password': 'password', - 'socle.schema_schema1.db_srep.user_database_user1.login': 'name', - 'socle.schema_schema1.db_srep.user_database_user1.name': 'name', - 'socle.schema_schema1.db_srep.user_database_user1.password2': 'password', - 'socle.schema_schema1.db_srep.user_database_user2.login': None, - 'socle.schema_schema1.db_srep.user_database_user2.name': None, - 'socle.schema_schema1.db_srep.user_database_user2.password2': 'password', - 'socle.schema_schema1.db_srep.users': ['user1', 'user2'], - } - # - cfg.option('socle.schema_schema1.db_srep.users').value.set([]) - assert cfg.value.get() == {'socle.database_schemas': ['schema1'], - 'socle.schema_schema1.database_names': ['srep'], - 'socle.schema_schema1.db_srep.password': 'password', - 'socle.schema_schema1.db_srep.users': [], - } - # - cfg.option('socle.schema_schema1.database_names').value.set([]) - assert cfg.value.get() == {'socle.database_schemas': ['schema1'], - 'socle.schema_schema1.database_names': [], - } - # - cfg.option('socle.database_schemas').value.set([]) - assert cfg.value.get() == {'socle.database_schemas': [], - } - # - cfg.option('socle.database_schemas').value.reset() - cfg.option('socle.schema_schema1.database_names').value.reset() - cfg.option('socle.schema_schema1.db_srep.users').value.reset() - assert cfg.value.get() == {'socle.database_schemas': ['schema1'], - 'socle.schema_schema1.database_names': ['srep'], - 'socle.schema_schema1.db_srep.password': 'password', - 'socle.schema_schema1.db_srep.user_database_user1.login': 'name', - 'socle.schema_schema1.db_srep.user_database_user1.name': 'name', - 'socle.schema_schema1.db_srep.user_database_user1.password2': 'password', - 'socle.schema_schema1.db_srep.users': ['user1'], - } - - -def test_dyn_link_subdyn_same_variable(): - password = StrOption(name="password", doc="password", properties=('mandatory',)) - name = StrOption(name="name", doc="name", properties=('mandatory',)) - login = StrOption(name="login", doc="login", default=Calculation(calc_value, Params((ParamOption(name)))), properties=('mandatory',)) - password2 = StrOption(name="password2", doc="password2", default=Calculation(calc_value, Params((ParamOption(password)))), properties=('mandatory',)) - schema_names = StrOption(name="database_schemas", doc="database_schemas", multi=True, default=["schema1"]) - user_database = DynOptionDescription(name="user_database_", doc="user database", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[name, login, password2]) - databases = DynOptionDescription(name="db_", doc="database", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[password, user_database]) - schema = DynOptionDescription(name="schema_", doc="schema_", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[databases]) - socle = OptionDescription(name="socle", doc="socle", children=[schema, schema_names]) - root = OptionDescription(name="baseoption", doc="baseoption", children=[socle]) - cfg = Config(root) - assert [opt.path() for opt in cfg.value.mandatory()] == ['socle.schema_schema1.db_schema1.password', - 'socle.schema_schema1.db_schema1.user_database_schema1.name', - 'socle.schema_schema1.db_schema1.user_database_schema1.login', - 'socle.schema_schema1.db_schema1.user_database_schema1.password2', - ] - # - cfg.option('socle.schema_schema1.db_schema1.user_database_schema1.name').value.set('name') - assert [opt.path() for opt in cfg.value.mandatory()] == ['socle.schema_schema1.db_schema1.password', - 'socle.schema_schema1.db_schema1.user_database_schema1.password2', - ] - # - cfg.option('socle.schema_schema1.db_schema1.password').value.set('password') - cfg.option('socle.schema_schema1.db_schema1.user_database_schema1.name').value.set('name') - assert [opt.path() for opt in cfg.value.mandatory()] == [] - assert cfg.value.get() == {'socle.database_schemas': ['schema1'], - 'socle.schema_schema1.db_schema1.password': 'password', - 'socle.schema_schema1.db_schema1.user_database_schema1.login': 'name', - 'socle.schema_schema1.db_schema1.user_database_schema1.name': 'name', - 'socle.schema_schema1.db_schema1.user_database_schema1.password2': 'password', - } - # - cfg.option('socle.database_schemas').value.set(['schema1', 'schema2']) - assert [opt.path() for opt in cfg.value.mandatory()] == ['socle.schema_schema1.db_schema1.user_database_schema2.name', - 'socle.schema_schema1.db_schema1.user_database_schema2.login', - 'socle.schema_schema1.db_schema2.password', - 'socle.schema_schema1.db_schema2.user_database_schema1.name', - 'socle.schema_schema1.db_schema2.user_database_schema1.login', - 'socle.schema_schema1.db_schema2.user_database_schema1.password2', - 'socle.schema_schema1.db_schema2.user_database_schema2.name', - 'socle.schema_schema1.db_schema2.user_database_schema2.login', - 'socle.schema_schema1.db_schema2.user_database_schema2.password2', - 'socle.schema_schema2.db_schema1.password', - 'socle.schema_schema2.db_schema1.user_database_schema1.name', - 'socle.schema_schema2.db_schema1.user_database_schema1.login', - 'socle.schema_schema2.db_schema1.user_database_schema1.password2', - 'socle.schema_schema2.db_schema1.user_database_schema2.name', - 'socle.schema_schema2.db_schema1.user_database_schema2.login', - 'socle.schema_schema2.db_schema1.user_database_schema2.password2', - 'socle.schema_schema2.db_schema2.password', - 'socle.schema_schema2.db_schema2.user_database_schema1.name', - 'socle.schema_schema2.db_schema2.user_database_schema1.login', - 'socle.schema_schema2.db_schema2.user_database_schema1.password2', - - 'socle.schema_schema2.db_schema2.user_database_schema2.name', - 'socle.schema_schema2.db_schema2.user_database_schema2.login', - 'socle.schema_schema2.db_schema2.user_database_schema2.password2', - ] - assert cfg.value.get() == {'socle.database_schemas': ['schema1', 'schema2'], - 'socle.schema_schema1.db_schema1.password': 'password', - 'socle.schema_schema1.db_schema1.user_database_schema1.login': 'name', - 'socle.schema_schema1.db_schema1.user_database_schema1.name': 'name', - 'socle.schema_schema1.db_schema1.user_database_schema1.password2': 'password', - 'socle.schema_schema1.db_schema1.user_database_schema2.login': None, - 'socle.schema_schema1.db_schema1.user_database_schema2.name': None, - 'socle.schema_schema1.db_schema1.user_database_schema2.password2': 'password', - 'socle.schema_schema1.db_schema2.password': None, - 'socle.schema_schema1.db_schema2.user_database_schema1.login': None, - 'socle.schema_schema1.db_schema2.user_database_schema1.name': None, - 'socle.schema_schema1.db_schema2.user_database_schema1.password2': None, - 'socle.schema_schema1.db_schema2.user_database_schema2.login': None, - 'socle.schema_schema1.db_schema2.user_database_schema2.name': None, - 'socle.schema_schema1.db_schema2.user_database_schema2.password2': None, - 'socle.schema_schema2.db_schema1.password': None, - 'socle.schema_schema2.db_schema1.user_database_schema1.login': None, - 'socle.schema_schema2.db_schema1.user_database_schema1.name': None, - 'socle.schema_schema2.db_schema1.user_database_schema1.password2': None, - 'socle.schema_schema2.db_schema1.user_database_schema2.login': None, - 'socle.schema_schema2.db_schema1.user_database_schema2.name': None, - 'socle.schema_schema2.db_schema1.user_database_schema2.password2': None, - 'socle.schema_schema2.db_schema2.password': None, - 'socle.schema_schema2.db_schema2.user_database_schema1.login': None, - 'socle.schema_schema2.db_schema2.user_database_schema1.name': None, - 'socle.schema_schema2.db_schema2.user_database_schema1.password2': None, - 'socle.schema_schema2.db_schema2.user_database_schema2.login': None, - 'socle.schema_schema2.db_schema2.user_database_schema2.name': None, - 'socle.schema_schema2.db_schema2.user_database_schema2.password2': None, - } - assert cfg.option('socle.schema_schema1.db_schema1.user_database_schema1').value.get() == { - 'socle.schema_schema1.db_schema1.user_database_schema1.login': 'name', - 'socle.schema_schema1.db_schema1.user_database_schema1.name': 'name', - 'socle.schema_schema1.db_schema1.user_database_schema1.password2': 'password', - } - - -def test_dyn_link_subdyn_disabled(): - password = StrOption(name="password", doc="password") - name = StrOption(name="name", doc="name") - login = StrOption(name="login", doc="login", default=Calculation(calc_value, Params((ParamOption(name))))) - disabled_property = Calculation(calc_value, - Params(ParamValue('disabled'), - kwargs={'condition': ParamOption(login), - 'expected': ParamValue('name'), - 'default': ParamValue(None)})) - password2 = StrOption(name="password2", doc="password2", default=Calculation(calc_value, Params((ParamOption(password)))), properties=(disabled_property,)) - schema_names = StrOption(name="database_schemas", doc="database_schemas", multi=True, default=["schema1"]) - user_database = DynOptionDescription(name="user_database_", doc="user database", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[name, login, password2]) - databases = DynOptionDescription(name="db_", doc="database", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[password, user_database]) - schema = DynOptionDescription(name="schema_", doc="schema_", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[databases]) - socle = OptionDescription(name="socle", doc="socle", children=[schema, schema_names]) - root = OptionDescription(name="baseoption", doc="baseoption", children=[socle]) - cfg = Config(root) - cfg.property.read_write() - assert [opt.path() for opt in cfg.value.mandatory()] == [] - assert cfg.value.get() == {'socle.database_schemas': ['schema1'], - 'socle.schema_schema1.db_schema1.password': None, - 'socle.schema_schema1.db_schema1.user_database_schema1.login': None, - 'socle.schema_schema1.db_schema1.user_database_schema1.name': None, - 'socle.schema_schema1.db_schema1.user_database_schema1.password2': None, - } - # - cfg.option('socle.schema_schema1.db_schema1.user_database_schema1.name').value.set('name') - assert cfg.value.get() == {'socle.database_schemas': ['schema1'], - 'socle.schema_schema1.db_schema1.password': None, - 'socle.schema_schema1.db_schema1.user_database_schema1.login': 'name', - 'socle.schema_schema1.db_schema1.user_database_schema1.name': 'name', - } - # - cfg.option('socle.database_schemas').value.set(['schema1', 'schema2']) - cfg.option('socle.schema_schema2.db_schema2.user_database_schema2.name').value.set('name2') - assert cfg.value.get() == {'socle.database_schemas': ['schema1', 'schema2'], - 'socle.schema_schema1.db_schema1.password': None, - 'socle.schema_schema1.db_schema1.user_database_schema1.login': 'name', - 'socle.schema_schema1.db_schema1.user_database_schema1.name': 'name', - 'socle.schema_schema1.db_schema1.user_database_schema2.login': None, - 'socle.schema_schema1.db_schema1.user_database_schema2.name': None, - 'socle.schema_schema1.db_schema1.user_database_schema2.password2': None, - 'socle.schema_schema1.db_schema2.password': None, - 'socle.schema_schema1.db_schema2.user_database_schema1.login': None, - 'socle.schema_schema1.db_schema2.user_database_schema1.name': None, - 'socle.schema_schema1.db_schema2.user_database_schema1.password2': None, - 'socle.schema_schema1.db_schema2.user_database_schema2.login': None, - 'socle.schema_schema1.db_schema2.user_database_schema2.name': None, - 'socle.schema_schema1.db_schema2.user_database_schema2.password2': None, - 'socle.schema_schema2.db_schema1.password': None, - 'socle.schema_schema2.db_schema1.user_database_schema1.login': None, - 'socle.schema_schema2.db_schema1.user_database_schema1.name': None, - 'socle.schema_schema2.db_schema1.user_database_schema1.password2': None, - 'socle.schema_schema2.db_schema1.user_database_schema2.login': None, - 'socle.schema_schema2.db_schema1.user_database_schema2.name': None, - 'socle.schema_schema2.db_schema1.user_database_schema2.password2': None, - 'socle.schema_schema2.db_schema2.password': None, - 'socle.schema_schema2.db_schema2.user_database_schema1.login': None, - 'socle.schema_schema2.db_schema2.user_database_schema1.name': None, - 'socle.schema_schema2.db_schema2.user_database_schema1.password2': None, - 'socle.schema_schema2.db_schema2.user_database_schema2.login': 'name2', - 'socle.schema_schema2.db_schema2.user_database_schema2.name': 'name2', - 'socle.schema_schema2.db_schema2.user_database_schema2.password2': None, - } +#def test_leadership_dyndescription_convert(): +# st1 = StrOption('st1', "", multi=True) +# st2 = StrOption('st2', "", multi=True) +# stm = Leadership('st1', '', [st1, st2]) +# st = ConvertDynOptionDescription('st', '', [stm], suffixes=Calculation(return_list_dot)) +# od = OptionDescription('od', '', [st]) +# od1 = OptionDescription('od', '', [od]) +# cfg = Config(od1) +# owner = cfg.owner.get() +# # +# assert cfg.value.get() == {'od.stval1.st1.st1': [], 'od.stval2.st1.st1': []} +# assert cfg.option('od.stval1.st1.st1').value.get() == [] +# assert cfg.option('od.stval2.st1.st1').value.get() == [] +# assert cfg.option('od.stval1.st1.st1').owner.isdefault() +# assert cfg.option('od.stval2.st1.st1').owner.isdefault() +# # +# cfg.option('od.stval1.st1.st1').value.set(['yes']) +# assert cfg.value.get() == {'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'yes', 'od.stval1.st1.st2': None}], 'od.stval2.st1.st1': []} +# assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] +# assert cfg.option('od.stval1.st1.st2', 0).value.get() == None +# assert cfg.option('od.stval2.st1.st1').value.get() == [] +# assert cfg.option('od.stval1.st1.st1').owner.get() == owner +# assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() +# assert cfg.option('od.stval2.st1.st1').owner.isdefault() +# # +# cfg.option('od.stval1.st1.st2', 0).value.set('no') +# assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] +# assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'no' +# assert cfg.option('od.stval2.st1.st1').value.get() == [] +# assert cfg.option('od.stval1.st1.st1').owner.get() == owner +# assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner +# assert cfg.option('od.stval2.st1.st1').owner.isdefault() +# # +# cfg.option('od.stval1.st1.st1').value.pop(0) +# assert cfg.option('od.stval1.st1.st1').value.get() == [] +# assert cfg.option('od.stval2.st1.st1').value.get() == [] +# assert cfg.option('od.stval1.st1.st1').owner.get() == owner +# assert cfg.option('od.stval2.st1.st1').owner.isdefault() +# # +# cfg.option('od.stval1.st1.st1').value.set(['yes']) +# cfg.option('od.stval1.st1.st2', 0).value.set('yes') +# assert cfg.option('od.stval1.st1.st1').owner.get() == owner +# assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner +# assert cfg.option('od.stval2.st1.st1').owner.isdefault() +# assert cfg.option('od.stval1.st1.st1').owner.get() == owner +# cfg.option('od.stval1.st1.st2', 0).value.reset() +# assert cfg.option('od.stval1.st1.st1').owner.get() == owner +# assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() +# # +# cfg.option('od.stval1.st1.st1').value.set(['yes']) +# cfg.option('od.stval1.st1.st2', 0).value.set('yes') +# cfg.option('od.stval1.st1.st1').value.reset() +# assert cfg.option('od.stval1.st1.st1').value.get() == [] +# assert cfg.option('od.stval2.st1.st1').value.get() == [] +# assert cfg.option('od.stval1.st1.st1').owner.isdefault() +# assert cfg.option('od.stval2.st1.st1').owner.isdefault() +## assert not list_sessions() +# +# +#def test_leadership_callback_samegroup_dyndescription_convert(): +# st1 = StrOption('st1', "", multi=True) +# st2 = StrOption('st2', "", multi=True) +# st3 = StrOption('st3', "", Calculation(return_dynval, Params(ParamOption(st2))), multi=True) +# stm = Leadership('st1', '', [st1, st2, st3]) +# stt = ConvertDynOptionDescription('st', '', [stm], suffixes=Calculation(return_list_dot)) +# od1 = OptionDescription('od', '', [stt]) +# od2 = OptionDescription('od', '', [od1]) +# cfg = Config(od2) +# owner = cfg.owner.get() +# assert cfg.value.get() == {'od.stval1.st1.st1': [], 'od.stval2.st1.st1': []} +# assert cfg.option('od.stval1.st1.st1').value.get() == [] +# assert cfg.option('od.stval2.st1.st1').value.get() == [] +# assert cfg.option('od.stval1.st1.st1').owner.isdefault() +# assert cfg.option('od.stval2.st1.st1').owner.isdefault() +# # +# cfg.option('od.stval1.st1.st1').value.set(['yes']) +# assert cfg.value.get() == {'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'yes', 'od.stval1.st1.st2': None, 'od.stval1.st1.st3': None}], 'od.stval2.st1.st1': []} +# assert cfg.option('od.stval1.st1.st1').owner.get() == owner +# assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() +# assert cfg.option('od.stval1.st1.st3', 0).owner.isdefault() +# assert cfg.option('od.stval2.st1.st1').owner.isdefault() +# # +# cfg.option('od.stval1.st1.st2', 0).value.set('yes') +# assert cfg.value.get() == {'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'yes', 'od.stval1.st1.st2': 'yes', 'od.stval1.st1.st3': 'yes'}], 'od.stval2.st1.st1': []} +# assert cfg.option('od.stval1.st1.st1').owner.get() == owner +# assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner +# assert cfg.option('od.stval1.st1.st3', 0).owner.isdefault() +# assert cfg.option('od.stval2.st1.st1').owner.isdefault() +## assert not list_sessions() +# +# +#def test_dyn_with_leader_hidden_in_config(): +# ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) +# netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, properties=('hidden',)) +# interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0], properties=('hidden',)) +# dyn = DynOptionDescription('leader', '', [interface1], suffixes=Calculation(return_list)) +# od1 = OptionDescription('root', '', [dyn]) +# cfg = Config(od1) +# cfg.property.read_write() +# cfg.permissive.add('hidden') +# assert cfg.forcepermissive.option('leaderval1.ip_admin_eth0.ip_admin_eth0').value.get() == [] +# cfg.forcepermissive.option('leaderval1.ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) +# assert cfg.forcepermissive.option('leaderval1.ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None +# with pytest.raises(PropertiesOptionError): +# cfg.option('leaderval1.ip_admin_eth0.ip_admin_eth0').value.get() +# with pytest.raises(PropertiesOptionError): +# cfg.option('leaderval1.ip_admin_eth0.netmask_admin_eth0', 0).value.get() +# cfg.value.get() == {'leaderval1.ip_admin_eth0.ip_admin_eth0': [{'leaderval1.ip_admin_eth0.ip_admin_eth0': '192.168.1.1'}], +# 'leaderval2.ip_admin_eth0.ip_admin_eth0': [{'leaderval2.ip_admin_eth0.ip_admin_eth0': '192.168.1.1'}]} +## assert not list_sessions() +# +# +#def test_dyn_leadership_requires(): +# ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True, properties=('notunique',)) +# disabled_property = Calculation(calc_value, +# Params(ParamValue('disabled'), +# kwargs={'condition': ParamOption(ip_admin_eth0, notraisepropertyerror=True), +# 'expected': ParamValue('192.168.1.1'), +# 'no_condition_is_invalid': ParamValue(True), +# 'index': ParamIndex()})) +# netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, properties=(disabled_property,)) +# interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) +# dyn = DynOptionDescription('leader', '', [interface1], suffixes=Calculation(return_list)) +# od1 = OptionDescription('toto', '', [dyn]) +# cfg = Config(od1) +# cfg.property.read_write() +# assert cfg.option('leaderval1.ip_admin_eth0.ip_admin_eth0').value.get() == [] +# cfg.option('leaderval1.ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2']) +# assert cfg.option('leaderval1.ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None +# assert cfg.option('leaderval1.ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2'] +# # +# cfg.option('leaderval1.ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1']) +# assert cfg.option('leaderval1.ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None +# with pytest.raises(PropertiesOptionError): +# cfg.option('leaderval1.ip_admin_eth0.netmask_admin_eth0', 1).value.get() +# # +# cfg.option('leaderval1.ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.2']) +# assert cfg.option('leaderval1.ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None +# assert cfg.option('leaderval1.ip_admin_eth0.netmask_admin_eth0', 1).value.get() is None +# cfg.option('leaderval1.ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.255') +# assert cfg.option('leaderval1.ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.255' +# ret = cfg.value.get() +# assert ret == {'leaderval1.ip_admin_eth0.ip_admin_eth0': [{'leaderval1.ip_admin_eth0.ip_admin_eth0': '192.168.1.2', 'leaderval1.ip_admin_eth0.netmask_admin_eth0': None}, +# {'leaderval1.ip_admin_eth0.ip_admin_eth0': '192.168.1.2', 'leaderval1.ip_admin_eth0.netmask_admin_eth0': '255.255.255.255'}], +# 'leaderval2.ip_admin_eth0.ip_admin_eth0': []} +# +# # +# cfg.option('leaderval1.ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1']) +# assert cfg.option('leaderval1.ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None +# with pytest.raises(PropertiesOptionError): +# cfg.option('leaderval1.ip_admin_eth0.netmask_admin_eth0', 1).value.get() +# assert cfg.value.get() == {'leaderval1.ip_admin_eth0.ip_admin_eth0': [{'leaderval1.ip_admin_eth0.ip_admin_eth0': '192.168.1.2', 'leaderval1.ip_admin_eth0.netmask_admin_eth0': None}, {'leaderval1.ip_admin_eth0.ip_admin_eth0': '192.168.1.1'}], 'leaderval2.ip_admin_eth0.ip_admin_eth0': []} +# # +## assert not list_sessions() +# +# +#def test_dyn_leadership_mandatory(): +# nsd_zones_all = StrOption(name="nsd_zones_all", doc="nsd_zones_all", multi=True, default=['val1', 'val2']) +# is_auto = BoolOption(name="is_auto_", doc="is auto") +# hostname = DomainnameOption(name="hostname_", doc="hostname_", multi=True, type='hostname') +# choice = ChoiceOption(name="type_", doc="type_", values=('A', 'CNAME'), multi=True, default_multi="A") +# leadership = Leadership(name="hostname_", doc="hostname_", children=[hostname, choice], properties=frozenset({Calculation(calc_value, Params(ParamValue('hidden'), kwargs={'condition': ParamOption(is_auto, notraisepropertyerror=True), 'expected': ParamValue(True)}))})) +# dyn = DynOptionDescription(name="nsd_zone_", doc="Zone ", suffixes=Calculation(calc_value, Params((ParamOption(nsd_zones_all, notraisepropertyerror=True)))), children=[is_auto, leadership], properties=frozenset({"normal"})) +# od1 = OptionDescription(name="nsd", doc="nsd", children=[nsd_zones_all, dyn]) +# cfg = Config(od1) +# assert cfg.value.mandatory() == [] +## assert not list_sessions() +# +# +#def test_dyn_symlink(): +# remotes = StrOption("remotes", "Remotes", ['a', 'b', 'c'], multi=True) +# remote_ip = StrOption("remote_ip_", "Remote IP", Calculation(calc_value, Params(ParamSuffix()))) +# dyn_remote = DynOptionDescription("remote_", "Account for ", suffixes=Calculation(calc_value, Params((ParamOption(remotes)))), children=[remote_ip]) +# name = SymLinkOption("name", opt=remote_ip) +# od1 = OptionDescription(name="accounts", doc="accounts.remote_.remote_ip_", children=[remotes, dyn_remote, name]) +# cfg = Config(od1) +# assert cfg.option('name').value.get() == ['a', 'b', 'c'] +# assert cfg.option('name').ismulti() == True +# assert cfg.option('name').issubmulti() == False +# assert cfg.value.get() == {'remotes': ['a', 'b', 'c'], 'remote_a.remote_ip_': 'a', 'remote_b.remote_ip_': 'b', 'remote_c.remote_ip_': 'c', 'name': ['a', 'b', 'c']} +## assert not list_sessions() +# +# +#def test_dyn_callback_with_not_dyn(): +# remotes = StrOption("remotes", "Remotes", ['a', 'b', 'c'], multi=True) +# remote_ip = StrOption("remote_ip_", "Remote IP", Calculation(calc_value, Params(ParamSuffix()))) +# dyn_remote = DynOptionDescription("remote_", "Account for ", suffixes=Calculation(calc_value, Params((ParamOption(remotes)))), children=[remote_ip]) +# names = StrOption('names', '', Calculation(calc_value, Params(ParamOption(remote_ip))), multi=True) +# od1 = OptionDescription(name="accounts", doc="accounts.remote_.remote_ip_", children=[remotes, dyn_remote, names]) +# cfg = Config(od1) +# assert cfg.option('names').value.get() == ['a', 'b', 'c'] +# assert cfg.option('names').ismulti() == True +# assert cfg.option('names').issubmulti() == False +# assert cfg.value.get() == {'remotes': ['a', 'b', 'c'], 'remote_a.remote_ip_': 'a', 'remote_b.remote_ip_': 'b', 'remote_c.remote_ip_': 'c', 'names': ['a', 'b', 'c']} +## assert not list_sessions() +# +# +#def test_dyn_link_subdyn(): +# database_names = StrOption(name="database_names", doc="database_names", multi=True, default=["srep", "snom", "srem"]) +# password = StrOption(name="password", doc="password", properties=('mandatory',)) +# name = StrOption(name="name", doc="name", properties=('mandatory',)) +# password2 = StrOption(name="password", doc="password", default=Calculation(calc_value, Params((ParamOption(password)))), properties=('mandatory',)) +# user = OptionDescription(name="user", doc="user", children=[name, password2]) +# sub = OptionDescription(name="sub", doc="sub", children=[user]) +# user_database = DynOptionDescription(name="user_database_", doc="user database", suffixes=Calculation(calc_value, Params((ParamOption(database_names, notraisepropertyerror=True)))), children=[password, sub]) +# socle = OptionDescription(name="socle", doc="socle", children=[user_database, database_names]) +# root = OptionDescription(name="baseoption", doc="baseoption", children=[socle]) +# cfg = Config(root) +# assert cfg.option('socle.database_names').value.get() == ["srep", "snom", "srem"] +# assert cfg.option('socle.user_database_srep.password').value.get() is None +# assert cfg.option('socle.user_database_srep.sub.user.name').value.get() is None +# assert cfg.option('socle.user_database_srep.sub.user.password').value.get() is None +# assert [opt.path() for opt in cfg.value.mandatory()] == ['socle.user_database_srep.password', +# 'socle.user_database_srep.sub.user.name', +# 'socle.user_database_srep.sub.user.password', +# 'socle.user_database_snom.password', +# 'socle.user_database_snom.sub.user.name', +# 'socle.user_database_snom.sub.user.password', +# 'socle.user_database_srem.password', +# 'socle.user_database_srem.sub.user.name', +# 'socle.user_database_srem.sub.user.password', +# ] +# # +# cfg.option('socle.user_database_srep.password').value.set('pass') +# cfg.option('socle.user_database_snom.sub.user.password').value.set('pass') +# assert cfg.option('socle.user_database_srep.password').value.get() is 'pass' +# assert cfg.option('socle.user_database_srep.sub.user.name').value.get() is None +# assert cfg.option('socle.user_database_srep.sub.user.password').value.get() is 'pass' +# assert [opt.path() for opt in cfg.value.mandatory()] == ['socle.user_database_srep.sub.user.name', +# 'socle.user_database_snom.password', +# 'socle.user_database_snom.sub.user.name', +# 'socle.user_database_srem.password', +# 'socle.user_database_srem.sub.user.name', +# 'socle.user_database_srem.sub.user.password', +# ] +# # +# cfg.option('socle.user_database_snom.password').value.set('pass2') +# cfg.option('socle.user_database_srem.password').value.set('pass3') +# cfg.option('socle.user_database_srep.sub.user.name').value.set('name1') +# cfg.option('socle.user_database_snom.sub.user.name').value.set('name2') +# cfg.option('socle.user_database_srem.sub.user.name').value.set('name3') +# assert [opt.path() for opt in cfg.value.mandatory()] == [] +# assert cfg.value.get() == {'socle.database_names': ['srep', +# 'snom', +# 'srem'], +# 'socle.user_database_snom.password': 'pass2', +# 'socle.user_database_snom.sub.user.name': 'name2', +# 'socle.user_database_snom.sub.user.password': 'pass', +# 'socle.user_database_srem.password': 'pass3', +# 'socle.user_database_srem.sub.user.name': 'name3', +# 'socle.user_database_srem.sub.user.password': 'pass3', +# 'socle.user_database_srep.password': 'pass', +# 'socle.user_database_srep.sub.user.name': 'name1', +# 'socle.user_database_srep.sub.user.password': 'pass', +# } +# # +# assert [opt.path() for opt in cfg.value.mandatory()] == [] +# +# +#def test_dyn_link_subdyn_2(): +# database_names = StrOption(name="database_names", doc="database_names", multi=True, default=["srep", "snom", "srem"]) +# password2 = StrOption(name="password", doc="password", properties=('mandatory',)) +# password = StrOption(name="password", doc="password", default=Calculation(calc_value, Params((ParamOption(password2)))), properties=('mandatory',)) +# name = StrOption(name="name", doc="name", properties=('mandatory',)) +# user = OptionDescription(name="user", doc="user", children=[name, password2]) +# sub = OptionDescription(name="sub", doc="sub", children=[user]) +# user_database = DynOptionDescription(name="user_database_", doc="user database", suffixes=Calculation(calc_value, Params((ParamOption(database_names, notraisepropertyerror=True)))), children=[password, sub]) +# socle = OptionDescription(name="socle", doc="socle", children=[user_database, database_names]) +# root = OptionDescription(name="baseoption", doc="baseoption", children=[socle]) +# cfg = Config(root) +# assert cfg.option('socle.database_names').value.get() == ["srep", "snom", "srem"] +# assert cfg.option('socle.user_database_srep.password').value.get() is None +# assert cfg.option('socle.user_database_srep.sub.user.name').value.get() is None +# assert cfg.option('socle.user_database_srep.sub.user.password').value.get() is None +# assert [opt.path() for opt in cfg.value.mandatory()] == ['socle.user_database_srep.password', +# 'socle.user_database_srep.sub.user.name', +# 'socle.user_database_srep.sub.user.password', +# 'socle.user_database_snom.password', +# 'socle.user_database_snom.sub.user.name', +# 'socle.user_database_snom.sub.user.password', +# 'socle.user_database_srem.password', +# 'socle.user_database_srem.sub.user.name', +# 'socle.user_database_srem.sub.user.password', +# ] +# # +# cfg.option('socle.user_database_srep.password').value.set('pass') +# cfg.option('socle.user_database_snom.sub.user.password').value.set('pass') +# assert cfg.option('socle.user_database_srep.password').value.get() is 'pass' +# assert cfg.option('socle.user_database_srep.sub.user.name').value.get() is None +# assert cfg.option('socle.user_database_srep.sub.user.password').value.get() is None +# assert [opt.path() for opt in cfg.value.mandatory()] == ['socle.user_database_srep.sub.user.name', +# 'socle.user_database_srep.sub.user.password', +# 'socle.user_database_snom.sub.user.name', +# 'socle.user_database_srem.password', +# 'socle.user_database_srem.sub.user.name', +# 'socle.user_database_srem.sub.user.password', +# ] +# # +# cfg.option('socle.user_database_srep.sub.user.password').value.set('pass2') +# cfg.option('socle.user_database_srem.sub.user.password').value.set('pass3') +# cfg.option('socle.user_database_srep.sub.user.name').value.set('name1') +# cfg.option('socle.user_database_snom.sub.user.name').value.set('name2') +# cfg.option('socle.user_database_srem.sub.user.name').value.set('name3') +# assert [opt.path() for opt in cfg.value.mandatory()] == [] +# assert cfg.value.get() == {'socle.database_names': ['srep', +# 'snom', +# 'srem'], +# 'socle.user_database_snom.password': 'pass', +# 'socle.user_database_snom.sub.user.name': 'name2', +# 'socle.user_database_snom.sub.user.password': 'pass', +# 'socle.user_database_srem.password': 'pass3', +# 'socle.user_database_srem.sub.user.name': 'name3', +# 'socle.user_database_srem.sub.user.password': 'pass3', +# 'socle.user_database_srep.password': 'pass', +# 'socle.user_database_srep.sub.user.name': 'name1', +# 'socle.user_database_srep.sub.user.password': 'pass2', +# } +# # +# assert [opt.path() for opt in cfg.value.mandatory()] == [] +# +# +#def test_dyn_link_subdyn_twice(): +# password = StrOption(name="password", doc="password", properties=('mandatory',)) +# name = StrOption(name="name", doc="name", properties=('mandatory',)) +# login = StrOption(name="login", doc="login", default=Calculation(calc_value, Params((ParamOption(name)))), properties=('mandatory',)) +# password2 = StrOption(name="password2", doc="password2", default=Calculation(calc_value, Params((ParamOption(password)))), properties=('mandatory',)) +# database_names = StrOption(name="database_names", doc="database_names", multi=True, default=["srep", "snom", "srem"]) +# user_database = DynOptionDescription(name="user_database_", doc="user database", suffixes=Calculation(calc_value, Params((ParamOption(database_names, notraisepropertyerror=True)))), children=[name, login, password2]) +# databases = OptionDescription(name="databases", doc="database", children=[password, user_database]) +# schema_names = StrOption(name="database_schemas", doc="database_schemas", multi=True, default=["schema1", "schema2", "schema3"]) +# schema = DynOptionDescription(name="schema_", doc="schema_", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[database_names, databases]) +# socle = OptionDescription(name="socle", doc="socle", children=[schema, schema_names]) +# root = OptionDescription(name="baseoption", doc="baseoption", children=[socle]) +# cfg = Config(root) +# assert cfg.value.get() == {'socle.database_schemas': ['schema1', +# 'schema2', +# 'schema3'], +# 'socle.schema_schema1.database_names': ['srep', +# 'snom', +# 'srem'], +# 'socle.schema_schema1.databases.password': None, +# 'socle.schema_schema1.databases.user_database_snom.name': None, +# 'socle.schema_schema1.databases.user_database_snom.login': None, +# 'socle.schema_schema1.databases.user_database_snom.password2': None, +# 'socle.schema_schema1.databases.user_database_srem.name': None, +# 'socle.schema_schema1.databases.user_database_srem.login': None, +# 'socle.schema_schema1.databases.user_database_srem.password2': None, +# 'socle.schema_schema1.databases.user_database_srep.name': None, +# 'socle.schema_schema1.databases.user_database_srep.login': None, +# 'socle.schema_schema1.databases.user_database_srep.password2': None, +# 'socle.schema_schema2.database_names': ['srep', +# 'snom', +# 'srem'], +# 'socle.schema_schema2.databases.password': None, +# 'socle.schema_schema2.databases.user_database_snom.name': None, +# 'socle.schema_schema2.databases.user_database_snom.login': None, +# 'socle.schema_schema2.databases.user_database_snom.password2': None, +# 'socle.schema_schema2.databases.user_database_srem.name': None, +# 'socle.schema_schema2.databases.user_database_srem.login': None, +# 'socle.schema_schema2.databases.user_database_srem.password2': None, +# 'socle.schema_schema2.databases.user_database_srep.name': None, +# 'socle.schema_schema2.databases.user_database_srep.login': None, +# 'socle.schema_schema2.databases.user_database_srep.password2': None, +# 'socle.schema_schema3.database_names': ['srep', +# 'snom', +# 'srem'], +# 'socle.schema_schema3.databases.password': None, +# 'socle.schema_schema3.databases.user_database_snom.name': None, +# 'socle.schema_schema3.databases.user_database_snom.login': None, +# 'socle.schema_schema3.databases.user_database_snom.password2': None, +# 'socle.schema_schema3.databases.user_database_srem.name': None, +# 'socle.schema_schema3.databases.user_database_srem.login': None, +# 'socle.schema_schema3.databases.user_database_srem.password2': None, +# 'socle.schema_schema3.databases.user_database_srep.name': None, +# 'socle.schema_schema3.databases.user_database_srep.login': None, +# 'socle.schema_schema3.databases.user_database_srep.password2': None, +# } +# # +# assert [opt.path() for opt in cfg.value.mandatory()] == ['socle.schema_schema1.databases.password', +# 'socle.schema_schema1.databases.user_database_srep.name', +# 'socle.schema_schema1.databases.user_database_srep.login', +# 'socle.schema_schema1.databases.user_database_srep.password2', +# 'socle.schema_schema1.databases.user_database_snom.name', +# 'socle.schema_schema1.databases.user_database_snom.login', +# 'socle.schema_schema1.databases.user_database_snom.password2', +# 'socle.schema_schema1.databases.user_database_srem.name', +# 'socle.schema_schema1.databases.user_database_srem.login', +# 'socle.schema_schema1.databases.user_database_srem.password2', +# 'socle.schema_schema2.databases.password', +# 'socle.schema_schema2.databases.user_database_srep.name', +# 'socle.schema_schema2.databases.user_database_srep.login', +# 'socle.schema_schema2.databases.user_database_srep.password2', +# 'socle.schema_schema2.databases.user_database_snom.name', +# 'socle.schema_schema2.databases.user_database_snom.login', +# 'socle.schema_schema2.databases.user_database_snom.password2', +# 'socle.schema_schema2.databases.user_database_srem.name', +# 'socle.schema_schema2.databases.user_database_srem.login', +# 'socle.schema_schema2.databases.user_database_srem.password2', +# 'socle.schema_schema3.databases.password', +# 'socle.schema_schema3.databases.user_database_srep.name', +# 'socle.schema_schema3.databases.user_database_srep.login', +# 'socle.schema_schema3.databases.user_database_srep.password2', +# 'socle.schema_schema3.databases.user_database_snom.name', +# 'socle.schema_schema3.databases.user_database_snom.login', +# 'socle.schema_schema3.databases.user_database_snom.password2', +# 'socle.schema_schema3.databases.user_database_srem.name', +# 'socle.schema_schema3.databases.user_database_srem.login', +# 'socle.schema_schema3.databases.user_database_srem.password2', +# ] +# # +# cfg.option('socle.schema_schema2.database_names').value.set(['another']) +# assert cfg.value.get() == {'socle.database_schemas': ['schema1', +# 'schema2', +# 'schema3'], +# 'socle.schema_schema1.database_names': ['srep', +# 'snom', +# 'srem'], +# 'socle.schema_schema1.databases.password': None, +# 'socle.schema_schema1.databases.user_database_snom.name': None, +# 'socle.schema_schema1.databases.user_database_snom.login': None, +# 'socle.schema_schema1.databases.user_database_snom.password2': None, +# 'socle.schema_schema1.databases.user_database_srem.name': None, +# 'socle.schema_schema1.databases.user_database_srem.login': None, +# 'socle.schema_schema1.databases.user_database_srem.password2': None, +# 'socle.schema_schema1.databases.user_database_srep.name': None, +# 'socle.schema_schema1.databases.user_database_srep.login': None, +# 'socle.schema_schema1.databases.user_database_srep.password2': None, +# 'socle.schema_schema2.database_names': ['another'], +# 'socle.schema_schema2.databases.password': None, +# 'socle.schema_schema2.databases.user_database_another.name': None, +# 'socle.schema_schema2.databases.user_database_another.login': None, +# 'socle.schema_schema2.databases.user_database_another.password2': None, +# 'socle.schema_schema3.database_names': ['srep', +# 'snom', +# 'srem'], +# 'socle.schema_schema3.databases.password': None, +# 'socle.schema_schema3.databases.user_database_snom.name': None, +# 'socle.schema_schema3.databases.user_database_snom.login': None, +# 'socle.schema_schema3.databases.user_database_snom.password2': None, +# 'socle.schema_schema3.databases.user_database_srem.name': None, +# 'socle.schema_schema3.databases.user_database_srem.login': None, +# 'socle.schema_schema3.databases.user_database_srem.password2': None, +# 'socle.schema_schema3.databases.user_database_srep.name': None, +# 'socle.schema_schema3.databases.user_database_srep.login': None, +# 'socle.schema_schema3.databases.user_database_srep.password2': None, +# } +# # +# cfg.option('socle.database_schemas').value.set(['schema1']) +# assert cfg.value.get() == {'socle.database_schemas': ['schema1'], +# 'socle.schema_schema1.database_names': ['srep', +# 'snom', +# 'srem'], +# 'socle.schema_schema1.databases.password': None, +# 'socle.schema_schema1.databases.user_database_snom.name': None, +# 'socle.schema_schema1.databases.user_database_snom.login': None, +# 'socle.schema_schema1.databases.user_database_snom.password2': None, +# 'socle.schema_schema1.databases.user_database_srem.name': None, +# 'socle.schema_schema1.databases.user_database_srem.login': None, +# 'socle.schema_schema1.databases.user_database_srem.password2': None, +# 'socle.schema_schema1.databases.user_database_srep.name': None, +# 'socle.schema_schema1.databases.user_database_srep.login': None, +# 'socle.schema_schema1.databases.user_database_srep.password2': None, +# } +# # +# cfg.option('socle.schema_schema1.databases.password').value.set('password') +# cfg.option('socle.schema_schema1.databases.user_database_snom.name').value.set('name1') +# cfg.option('socle.schema_schema1.databases.user_database_srem.name').value.set('name2') +# cfg.option('socle.schema_schema1.databases.user_database_srep.name').value.set('name3') +# assert cfg.value.get() == {'socle.database_schemas': ['schema1'], +# 'socle.schema_schema1.database_names': ['srep', +# 'snom', +# 'srem'], +# 'socle.schema_schema1.databases.password': 'password', +# 'socle.schema_schema1.databases.user_database_snom.login': 'name1', +# 'socle.schema_schema1.databases.user_database_snom.name': 'name1', +# 'socle.schema_schema1.databases.user_database_snom.password2': 'password', +# 'socle.schema_schema1.databases.user_database_srem.login': 'name2', +# 'socle.schema_schema1.databases.user_database_srem.name': 'name2', +# 'socle.schema_schema1.databases.user_database_srem.password2': 'password', +# 'socle.schema_schema1.databases.user_database_srep.login': 'name3', +# 'socle.schema_schema1.databases.user_database_srep.name': 'name3', +# 'socle.schema_schema1.databases.user_database_srep.password2': 'password', +# } +# assert [opt.path() for opt in cfg.value.mandatory()] == [] +# # +# cfg.option('socle.schema_schema1.database_names').value.set(['snom']) +# assert cfg.value.get() == {'socle.database_schemas': ['schema1'], +# 'socle.schema_schema1.database_names': ['snom'], +# 'socle.schema_schema1.databases.password': 'password', +# 'socle.schema_schema1.databases.user_database_snom.login': 'name1', +# 'socle.schema_schema1.databases.user_database_snom.name': 'name1', +# 'socle.schema_schema1.databases.user_database_snom.password2': 'password', +# } +# assert [opt.path() for opt in cfg.value.mandatory()] == [] +# +# +#def test_dyn_link_subdyn_tree(): +# password = StrOption(name="password", doc="password", properties=('mandatory',)) +# name = StrOption(name="name", doc="name", properties=('mandatory',)) +# login = StrOption(name="login", doc="login", default=Calculation(calc_value, Params((ParamOption(name)))), properties=('mandatory',)) +# password2 = StrOption(name="password2", doc="password2", default=Calculation(calc_value, Params((ParamOption(password)))), properties=('mandatory',)) +# user_names = StrOption(name="users", doc="users", multi=True, default=["user1"]) +# user_database = DynOptionDescription(name="user_database_", doc="user database", suffixes=Calculation(calc_value, Params((ParamOption(user_names, notraisepropertyerror=True)))), children=[name, login, password2]) +# database_names = StrOption(name="database_names", doc="database_names", multi=True, default=["srep"]) +# databases = DynOptionDescription(name="db_", doc="database", suffixes=Calculation(calc_value, Params((ParamOption(database_names, notraisepropertyerror=True)))), children=[user_names, password, user_database]) +# schema_names = StrOption(name="database_schemas", doc="database_schemas", multi=True, default=["schema1"]) +# schema = DynOptionDescription(name="schema_", doc="schema_", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[database_names, databases]) +# socle = OptionDescription(name="socle", doc="socle", children=[schema, schema_names]) +# root = OptionDescription(name="baseoption", doc="baseoption", children=[socle]) +# cfg = Config(root) +# assert [opt.path() for opt in cfg.value.mandatory()] == ['socle.schema_schema1.db_srep.password', +# 'socle.schema_schema1.db_srep.user_database_user1.name', +# 'socle.schema_schema1.db_srep.user_database_user1.login', +# 'socle.schema_schema1.db_srep.user_database_user1.password2', +# ] +# # +# cfg.option('socle.schema_schema1.db_srep.user_database_user1.name').value.set('name') +# assert [opt.path() for opt in cfg.value.mandatory()] == ['socle.schema_schema1.db_srep.password', +# 'socle.schema_schema1.db_srep.user_database_user1.password2', +# ] +# # +# cfg.option('socle.schema_schema1.db_srep.password').value.set('password') +# assert [opt.path() for opt in cfg.value.mandatory()] == [] +# assert cfg.value.get() == {'socle.database_schemas': ['schema1'], +# 'socle.schema_schema1.database_names': ['srep'], +# 'socle.schema_schema1.db_srep.password': 'password', +# 'socle.schema_schema1.db_srep.user_database_user1.login': 'name', +# 'socle.schema_schema1.db_srep.user_database_user1.name': 'name', +# 'socle.schema_schema1.db_srep.user_database_user1.password2': 'password', +# 'socle.schema_schema1.db_srep.users': ['user1'], +# } +# # +# cfg.option('socle.schema_schema1.db_srep.users').value.set(['user1', 'user2']) +# assert cfg.value.get() == {'socle.database_schemas': ['schema1'], +# 'socle.schema_schema1.database_names': ['srep'], +# 'socle.schema_schema1.db_srep.password': 'password', +# 'socle.schema_schema1.db_srep.user_database_user1.login': 'name', +# 'socle.schema_schema1.db_srep.user_database_user1.name': 'name', +# 'socle.schema_schema1.db_srep.user_database_user1.password2': 'password', +# 'socle.schema_schema1.db_srep.user_database_user2.login': None, +# 'socle.schema_schema1.db_srep.user_database_user2.name': None, +# 'socle.schema_schema1.db_srep.user_database_user2.password2': 'password', +# 'socle.schema_schema1.db_srep.users': ['user1', 'user2'], +# } +# # +# cfg.option('socle.schema_schema1.db_srep.users').value.set([]) +# assert cfg.value.get() == {'socle.database_schemas': ['schema1'], +# 'socle.schema_schema1.database_names': ['srep'], +# 'socle.schema_schema1.db_srep.password': 'password', +# 'socle.schema_schema1.db_srep.users': [], +# } +# # +# cfg.option('socle.schema_schema1.database_names').value.set([]) +# assert cfg.value.get() == {'socle.database_schemas': ['schema1'], +# 'socle.schema_schema1.database_names': [], +# } +# # +# cfg.option('socle.database_schemas').value.set([]) +# assert cfg.value.get() == {'socle.database_schemas': [], +# } +# # +# cfg.option('socle.database_schemas').value.reset() +# cfg.option('socle.schema_schema1.database_names').value.reset() +# cfg.option('socle.schema_schema1.db_srep.users').value.reset() +# assert cfg.value.get() == {'socle.database_schemas': ['schema1'], +# 'socle.schema_schema1.database_names': ['srep'], +# 'socle.schema_schema1.db_srep.password': 'password', +# 'socle.schema_schema1.db_srep.user_database_user1.login': 'name', +# 'socle.schema_schema1.db_srep.user_database_user1.name': 'name', +# 'socle.schema_schema1.db_srep.user_database_user1.password2': 'password', +# 'socle.schema_schema1.db_srep.users': ['user1'], +# } +# +# +#def test_dyn_link_subdyn_same_variable(): +# password = StrOption(name="password", doc="password", properties=('mandatory',)) +# name = StrOption(name="name", doc="name", properties=('mandatory',)) +# login = StrOption(name="login", doc="login", default=Calculation(calc_value, Params((ParamOption(name)))), properties=('mandatory',)) +# password2 = StrOption(name="password2", doc="password2", default=Calculation(calc_value, Params((ParamOption(password)))), properties=('mandatory',)) +# schema_names = StrOption(name="database_schemas", doc="database_schemas", multi=True, default=["schema1"]) +# user_database = DynOptionDescription(name="user_database_", doc="user database", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[name, login, password2]) +# databases = DynOptionDescription(name="db_", doc="database", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[password, user_database]) +# schema = DynOptionDescription(name="schema_", doc="schema_", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[databases]) +# socle = OptionDescription(name="socle", doc="socle", children=[schema, schema_names]) +# root = OptionDescription(name="baseoption", doc="baseoption", children=[socle]) +# cfg = Config(root) +# assert [opt.path() for opt in cfg.value.mandatory()] == ['socle.schema_schema1.db_schema1.password', +# 'socle.schema_schema1.db_schema1.user_database_schema1.name', +# 'socle.schema_schema1.db_schema1.user_database_schema1.login', +# 'socle.schema_schema1.db_schema1.user_database_schema1.password2', +# ] +# # +# cfg.option('socle.schema_schema1.db_schema1.user_database_schema1.name').value.set('name') +# assert [opt.path() for opt in cfg.value.mandatory()] == ['socle.schema_schema1.db_schema1.password', +# 'socle.schema_schema1.db_schema1.user_database_schema1.password2', +# ] +# # +# cfg.option('socle.schema_schema1.db_schema1.password').value.set('password') +# cfg.option('socle.schema_schema1.db_schema1.user_database_schema1.name').value.set('name') +# assert [opt.path() for opt in cfg.value.mandatory()] == [] +# assert cfg.value.get() == {'socle.database_schemas': ['schema1'], +# 'socle.schema_schema1.db_schema1.password': 'password', +# 'socle.schema_schema1.db_schema1.user_database_schema1.login': 'name', +# 'socle.schema_schema1.db_schema1.user_database_schema1.name': 'name', +# 'socle.schema_schema1.db_schema1.user_database_schema1.password2': 'password', +# } +# # +# cfg.option('socle.database_schemas').value.set(['schema1', 'schema2']) +# assert [opt.path() for opt in cfg.value.mandatory()] == ['socle.schema_schema1.db_schema1.user_database_schema2.name', +# 'socle.schema_schema1.db_schema1.user_database_schema2.login', +# 'socle.schema_schema1.db_schema2.password', +# 'socle.schema_schema1.db_schema2.user_database_schema1.name', +# 'socle.schema_schema1.db_schema2.user_database_schema1.login', +# 'socle.schema_schema1.db_schema2.user_database_schema1.password2', +# 'socle.schema_schema1.db_schema2.user_database_schema2.name', +# 'socle.schema_schema1.db_schema2.user_database_schema2.login', +# 'socle.schema_schema1.db_schema2.user_database_schema2.password2', +# 'socle.schema_schema2.db_schema1.password', +# 'socle.schema_schema2.db_schema1.user_database_schema1.name', +# 'socle.schema_schema2.db_schema1.user_database_schema1.login', +# 'socle.schema_schema2.db_schema1.user_database_schema1.password2', +# 'socle.schema_schema2.db_schema1.user_database_schema2.name', +# 'socle.schema_schema2.db_schema1.user_database_schema2.login', +# 'socle.schema_schema2.db_schema1.user_database_schema2.password2', +# 'socle.schema_schema2.db_schema2.password', +# 'socle.schema_schema2.db_schema2.user_database_schema1.name', +# 'socle.schema_schema2.db_schema2.user_database_schema1.login', +# 'socle.schema_schema2.db_schema2.user_database_schema1.password2', +# +# 'socle.schema_schema2.db_schema2.user_database_schema2.name', +# 'socle.schema_schema2.db_schema2.user_database_schema2.login', +# 'socle.schema_schema2.db_schema2.user_database_schema2.password2', +# ] +# assert cfg.value.get() == {'socle.database_schemas': ['schema1', 'schema2'], +# 'socle.schema_schema1.db_schema1.password': 'password', +# 'socle.schema_schema1.db_schema1.user_database_schema1.login': 'name', +# 'socle.schema_schema1.db_schema1.user_database_schema1.name': 'name', +# 'socle.schema_schema1.db_schema1.user_database_schema1.password2': 'password', +# 'socle.schema_schema1.db_schema1.user_database_schema2.login': None, +# 'socle.schema_schema1.db_schema1.user_database_schema2.name': None, +# 'socle.schema_schema1.db_schema1.user_database_schema2.password2': 'password', +# 'socle.schema_schema1.db_schema2.password': None, +# 'socle.schema_schema1.db_schema2.user_database_schema1.login': None, +# 'socle.schema_schema1.db_schema2.user_database_schema1.name': None, +# 'socle.schema_schema1.db_schema2.user_database_schema1.password2': None, +# 'socle.schema_schema1.db_schema2.user_database_schema2.login': None, +# 'socle.schema_schema1.db_schema2.user_database_schema2.name': None, +# 'socle.schema_schema1.db_schema2.user_database_schema2.password2': None, +# 'socle.schema_schema2.db_schema1.password': None, +# 'socle.schema_schema2.db_schema1.user_database_schema1.login': None, +# 'socle.schema_schema2.db_schema1.user_database_schema1.name': None, +# 'socle.schema_schema2.db_schema1.user_database_schema1.password2': None, +# 'socle.schema_schema2.db_schema1.user_database_schema2.login': None, +# 'socle.schema_schema2.db_schema1.user_database_schema2.name': None, +# 'socle.schema_schema2.db_schema1.user_database_schema2.password2': None, +# 'socle.schema_schema2.db_schema2.password': None, +# 'socle.schema_schema2.db_schema2.user_database_schema1.login': None, +# 'socle.schema_schema2.db_schema2.user_database_schema1.name': None, +# 'socle.schema_schema2.db_schema2.user_database_schema1.password2': None, +# 'socle.schema_schema2.db_schema2.user_database_schema2.login': None, +# 'socle.schema_schema2.db_schema2.user_database_schema2.name': None, +# 'socle.schema_schema2.db_schema2.user_database_schema2.password2': None, +# } +# assert cfg.option('socle.schema_schema1.db_schema1.user_database_schema1').value.get() == { +# 'socle.schema_schema1.db_schema1.user_database_schema1.login': 'name', +# 'socle.schema_schema1.db_schema1.user_database_schema1.name': 'name', +# 'socle.schema_schema1.db_schema1.user_database_schema1.password2': 'password', +# } +# +# +#def test_dyn_link_subdyn_disabled(): +# password = StrOption(name="password", doc="password") +# name = StrOption(name="name", doc="name") +# login = StrOption(name="login", doc="login", default=Calculation(calc_value, Params((ParamOption(name))))) +# disabled_property = Calculation(calc_value, +# Params(ParamValue('disabled'), +# kwargs={'condition': ParamOption(login), +# 'expected': ParamValue('name'), +# 'default': ParamValue(None)})) +# password2 = StrOption(name="password2", doc="password2", default=Calculation(calc_value, Params((ParamOption(password)))), properties=(disabled_property,)) +# schema_names = StrOption(name="database_schemas", doc="database_schemas", multi=True, default=["schema1"]) +# user_database = DynOptionDescription(name="user_database_", doc="user database", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[name, login, password2]) +# databases = DynOptionDescription(name="db_", doc="database", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[password, user_database]) +# schema = DynOptionDescription(name="schema_", doc="schema_", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[databases]) +# socle = OptionDescription(name="socle", doc="socle", children=[schema, schema_names]) +# root = OptionDescription(name="baseoption", doc="baseoption", children=[socle]) +# cfg = Config(root) +# cfg.property.read_write() +# assert [opt.path() for opt in cfg.value.mandatory()] == [] +# assert cfg.value.get() == {'socle.database_schemas': ['schema1'], +# 'socle.schema_schema1.db_schema1.password': None, +# 'socle.schema_schema1.db_schema1.user_database_schema1.login': None, +# 'socle.schema_schema1.db_schema1.user_database_schema1.name': None, +# 'socle.schema_schema1.db_schema1.user_database_schema1.password2': None, +# } +# # +# cfg.option('socle.schema_schema1.db_schema1.user_database_schema1.name').value.set('name') +# assert cfg.value.get() == {'socle.database_schemas': ['schema1'], +# 'socle.schema_schema1.db_schema1.password': None, +# 'socle.schema_schema1.db_schema1.user_database_schema1.login': 'name', +# 'socle.schema_schema1.db_schema1.user_database_schema1.name': 'name', +# } +# # +# cfg.option('socle.database_schemas').value.set(['schema1', 'schema2']) +# cfg.option('socle.schema_schema2.db_schema2.user_database_schema2.name').value.set('name2') +# assert cfg.value.get() == {'socle.database_schemas': ['schema1', 'schema2'], +# 'socle.schema_schema1.db_schema1.password': None, +# 'socle.schema_schema1.db_schema1.user_database_schema1.login': 'name', +# 'socle.schema_schema1.db_schema1.user_database_schema1.name': 'name', +# 'socle.schema_schema1.db_schema1.user_database_schema2.login': None, +# 'socle.schema_schema1.db_schema1.user_database_schema2.name': None, +# 'socle.schema_schema1.db_schema1.user_database_schema2.password2': None, +# 'socle.schema_schema1.db_schema2.password': None, +# 'socle.schema_schema1.db_schema2.user_database_schema1.login': None, +# 'socle.schema_schema1.db_schema2.user_database_schema1.name': None, +# 'socle.schema_schema1.db_schema2.user_database_schema1.password2': None, +# 'socle.schema_schema1.db_schema2.user_database_schema2.login': None, +# 'socle.schema_schema1.db_schema2.user_database_schema2.name': None, +# 'socle.schema_schema1.db_schema2.user_database_schema2.password2': None, +# 'socle.schema_schema2.db_schema1.password': None, +# 'socle.schema_schema2.db_schema1.user_database_schema1.login': None, +# 'socle.schema_schema2.db_schema1.user_database_schema1.name': None, +# 'socle.schema_schema2.db_schema1.user_database_schema1.password2': None, +# 'socle.schema_schema2.db_schema1.user_database_schema2.login': None, +# 'socle.schema_schema2.db_schema1.user_database_schema2.name': None, +# 'socle.schema_schema2.db_schema1.user_database_schema2.password2': None, +# 'socle.schema_schema2.db_schema2.password': None, +# 'socle.schema_schema2.db_schema2.user_database_schema1.login': None, +# 'socle.schema_schema2.db_schema2.user_database_schema1.name': None, +# 'socle.schema_schema2.db_schema2.user_database_schema1.password2': None, +# 'socle.schema_schema2.db_schema2.user_database_schema2.login': 'name2', +# 'socle.schema_schema2.db_schema2.user_database_schema2.name': 'name2', +# 'socle.schema_schema2.db_schema2.user_database_schema2.password2': None, +# } +# assert cfg.option('socle.schema_schema1.db_schema1.user_database_schema1.name').owner.get() == owners.user +# assert cfg.option('socle.schema_schema1.db_schema1.user_database_schema1.name').information.get('doc') == 'name' +# +# +#def test_option_dynoption_display_name(): +# password = StrOption(name="password", doc="password") +# schema_names = StrOption(name="database_schemas", doc="database_schemas", multi=True, default=["schema1"]) +# user_database = OptionDescription(name="user_database", doc="user database", children=[password]) +# databases = DynOptionDescription(name="db_", doc="database", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[user_database]) +# schema = DynOptionDescription(name="schema_", doc="schema_", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[databases]) +# socle = OptionDescription(name="socle", doc="socle", children=[schema, schema_names]) +# root = OptionDescription(name="baseoption", doc="baseoption", children=[socle]) +# cfg = Config(root, display_name=display_name) +# assert cfg.option('socle.schema_schema1.db_schema1.user_database').doc() == 'socle.schema_schema1.db_schema1.user_database (user database)' diff --git a/tests/test_freeze.py b/tests/test_freeze.py index fd92262..105bd18 100644 --- a/tests/test_freeze.py +++ b/tests/test_freeze.py @@ -1,4 +1,4 @@ -# coding: utf-8 +#test_force_store_value coding: utf-8 "frozen and hidden values" from .autopath import do_autopath do_autopath() @@ -160,57 +160,57 @@ def test_freeze_multi(): # assert not list_sessions() -def test_force_store_value(): - od1 = make_description_freeze() - cfg = Config(od1) - compare(cfg.value.exportation(), {}) - cfg.property.read_write() - compare(cfg.value.exportation(), {'wantref': {None: [False, 'forced']}, 'wantref2': {None: [False, 'forced']}, 'wantref3': {None: [[False], 'forced']}}) - cfg.option('bool').value.set(False) - cfg.option('wantref').value.set(True) - cfg.option('bool').value.reset() - compare(cfg.value.exportation(), {'wantref': {None: [True, 'user']}, 'wantref2': {None: [False, 'forced']}, 'wantref3': {None: [[False], 'forced']}}) - cfg.option('bool').value.set(False) - cfg.option('wantref').value.reset() - cfg.option('bool').value.reset() - compare(cfg.value.exportation(), {'wantref': {None: [False, 'forced']}, 'wantref2': {None: [False, 'forced']}, 'wantref3': {None: [[False], 'forced']}}) -# assert not list_sessions() - - -def test_force_store_value_leadership_sub(): - b = IntOption('int', 'Test int option', multi=True, properties=('force_store_value',)) - c = StrOption('str', 'Test string option', multi=True) - descr = Leadership("int", "", [b, c]) - od1 = OptionDescription('odr', '', [descr]) - cfg = Config(od1) - cfg.property.read_only() - compare(cfg.value.exportation(), {'int.int': {None: [[], 'forced']}}) -# assert not list_sessions() - - -def test_force_store_value_callback(): - b = IntOption('int', 'Test int option', Calculation(return_val), properties=('force_store_value',)) - od1 = OptionDescription("int", "", [b]) - cfg = Config(od1) - cfg.property.read_only() - compare(cfg.value.exportation(), {'int': {None: [1, 'forced']}}) -# assert not list_sessions() - - -def test_force_store_value_callback_params(): - b = IntOption('int', 'Test int option', Calculation(return_val2, Params(kwargs={'value': ParamValue(2)})), properties=('force_store_value',)) - od1 = OptionDescription("int", "", [b]) - cfg = Config(od1) - cfg.property.read_only() - compare(cfg.value.exportation(), {'int': {None: [2, 'forced']}}) -# assert not list_sessions() - - -def test_force_store_value_callback_params_with_opt(): - a = IntOption('val1', "", 2) - b = IntOption('int', 'Test int option', Calculation(return_val2, Params(kwargs={'value': ParamOption(a)})), properties=('force_store_value',)) - od1 = OptionDescription("int", "", [a, b]) - cfg = Config(od1) - cfg.property.read_only() - compare(cfg.value.exportation(), {'int': {None: [2, 'forced']}}) -# assert not list_sessions() +#def test_force_store_value(): +# od1 = make_description_freeze() +# cfg = Config(od1) +# compare(cfg.value.exportation(), {}) +# cfg.property.read_write() +# compare(cfg.value.exportation(), {'wantref': {None: [False, 'forced']}, 'wantref2': {None: [False, 'forced']}, 'wantref3': {None: [[False], 'forced']}}) +# cfg.option('bool').value.set(False) +# cfg.option('wantref').value.set(True) +# cfg.option('bool').value.reset() +# compare(cfg.value.exportation(), {'wantref': {None: [True, 'user']}, 'wantref2': {None: [False, 'forced']}, 'wantref3': {None: [[False], 'forced']}}) +# cfg.option('bool').value.set(False) +# cfg.option('wantref').value.reset() +# cfg.option('bool').value.reset() +# compare(cfg.value.exportation(), {'wantref': {None: [False, 'forced']}, 'wantref2': {None: [False, 'forced']}, 'wantref3': {None: [[False], 'forced']}}) +## assert not list_sessions() +# +# +#def test_force_store_value_leadership_sub(): +# b = IntOption('int', 'Test int option', multi=True, properties=('force_store_value',)) +# c = StrOption('str', 'Test string option', multi=True) +# descr = Leadership("int", "", [b, c]) +# od1 = OptionDescription('odr', '', [descr]) +# cfg = Config(od1) +# cfg.property.read_only() +# compare(cfg.value.exportation(), {'int.int': {None: [[], 'forced']}}) +## assert not list_sessions() +# +# +#def test_force_store_value_callback(): +# b = IntOption('int', 'Test int option', Calculation(return_val), properties=('force_store_value',)) +# od1 = OptionDescription("int", "", [b]) +# cfg = Config(od1) +# cfg.property.read_only() +# compare(cfg.value.exportation(), {'int': {None: [1, 'forced']}}) +## assert not list_sessions() +# +# +#def test_force_store_value_callback_params(): +# b = IntOption('int', 'Test int option', Calculation(return_val2, Params(kwargs={'value': ParamValue(2)})), properties=('force_store_value',)) +# od1 = OptionDescription("int", "", [b]) +# cfg = Config(od1) +# cfg.property.read_only() +# compare(cfg.value.exportation(), {'int': {None: [2, 'forced']}}) +## assert not list_sessions() +# +# +#def test_force_store_value_callback_params_with_opt(): +# a = IntOption('val1', "", 2) +# b = IntOption('int', 'Test int option', Calculation(return_val2, Params(kwargs={'value': ParamOption(a)})), properties=('force_store_value',)) +# od1 = OptionDescription("int", "", [a, b]) +# cfg = Config(od1) +# cfg.property.read_only() +# compare(cfg.value.exportation(), {'int': {None: [2, 'forced']}}) +## assert not list_sessions() diff --git a/tests/test_leadership.py b/tests/test_leadership.py index b80bc4c..d71b901 100644 --- a/tests/test_leadership.py +++ b/tests/test_leadership.py @@ -1,7 +1,7 @@ # coding: utf-8 from .autopath import do_autopath do_autopath() -from .config import config_type, get_config, value_list, global_owner +from .config import config_type, get_config, value_list, global_owner, parse_od_get import pytest from tiramisu.setting import groups, owners @@ -59,10 +59,10 @@ def test_base_config(config_type): cfg = get_config(cfg, config_type) assert cfg.option('creole.general.activer_proxy_client').value.get() is False assert cfg.option('creole.general.nom_machine').value.get() == "eoleng" - if config_type != 'tiramisu-api': - ret = cfg.option.find('nom_machine', first=True) - assert ret.value.get() == "eoleng" - assert cfg.option('creole').value.dict() == {'creole.general.numero_etab': None, 'creole.general.nom_machine': 'eoleng', 'creole.general.nombre_interfaces': 1, 'creole.general.activer_proxy_client': False, 'creole.general.mode_conteneur_actif': False, 'creole.general.serveur_ntp': [], 'creole.general.time_zone': 'Paris', 'creole.interface1.ip_admin_eth0.ip_admin_eth0': None, 'creole.interface1.ip_admin_eth0.netmask_admin_eth0': None} +# if config_type != 'tiramisu-api': +# ret = cfg.option.find('nom_machine', first=True) +# assert ret.value.get() == "eoleng" + assert parse_od_get(cfg.option('creole').value.get()) == {'creole.general.numero_etab': None, 'creole.general.nom_machine': 'eoleng', 'creole.general.nombre_interfaces': 1, 'creole.general.activer_proxy_client': False, 'creole.general.mode_conteneur_actif': False, 'creole.general.serveur_ntp': [], 'creole.general.time_zone': 'Paris', 'creole.interface1.ip_admin_eth0.ip_admin_eth0': None, 'creole.interface1.ip_admin_eth0.netmask_admin_eth0': None} if config_type == 'tiramisu-api': cfg.send() # assert not list_sessions() @@ -77,49 +77,40 @@ def test_get_group_type(): assert grp.group_type() == 'family' assert isinstance(grp.group_type(), groups.GroupType) # assert not list_sessions() - - -def test_iter_on_groups(): - od1 = make_description() - cfg = Config(od1) - cfg.property.read_write() - result = cfg.option('creole').list('optiondescription', - group_type=groups.family, - ) - group_names = [res.name() for res in result] - assert group_names == ['general', 'interface1'] - for i in cfg.option('creole').list('optiondescription', - group_type=groups.family, - ): - #test StopIteration - break - result = cfg.option('creole').list('option', - group_type=groups.family, - ) - assert list(result) == [] - result = cfg.option('creole.general').list('optiondescription', - group_type=groups.family, - ) - assert list(result) == [] -# assert not list_sessions() +# +# +#def test_iter_on_groups(): +# od1 = make_description() +# cfg = Config(od1) +# cfg.property.read_write() +# result = cfg.option('creole').list('optiondescription', +# group_type=groups.family, +# ) +# group_names = [res.name() for res in result] +# assert group_names == ['general', 'interface1'] +# for i in cfg.option('creole').list('optiondescription', +# group_type=groups.family, +# ): +# #test StopIteration +# break +# result = cfg.option('creole').list('option', +# group_type=groups.family, +# ) +# assert list(result) == [] +# result = cfg.option('creole.general').list('optiondescription', +# group_type=groups.family, +# ) +# assert list(result) == [] +## assert not list_sessions() def test_list_recursive(): od1 = make_description() cfg = Config(od1) cfg.property.read_write() - result = cfg.option('creole').list('all') + result = cfg.option('creole').list() group_names = [res.name() for res in result] assert group_names == ['general', 'interface1'] # - result = cfg.option.list(recursive=True) - group_names = [res.name() for res in result] - assert group_names == ['numero_etab', 'nom_machine', 'nombre_interfaces', - 'activer_proxy_client', 'mode_conteneur_actif', - 'serveur_ntp', 'time_zone', 'ip_admin_eth0', - 'netmask_admin_eth0'] - result = list(cfg.option.list(recursive=True, type='optiondescription')) - group_names = [res.name() for res in result] - assert group_names == ['creole', 'general', 'interface1', 'ip_admin_eth0'] # assert not list_sessions() @@ -147,8 +138,7 @@ def test_iter_group_on_groups_force_permissive(): cfg = Config(od1) cfg.property.read_write() cfg.permissive.add('hidden') - result = cfg.forcepermissive.option('creole').list(type='optiondescription', - group_type=groups.family) + result = cfg.forcepermissive.option('creole').list() group_names = [res.name() for res in result] assert group_names == ['general', 'interface1', 'new'] # assert not list_sessions() @@ -159,8 +149,7 @@ def test_iter_on_groups_props(): cfg = Config(od1) cfg.property.read_write() cfg.option('creole.interface1').property.add('disabled') - result = cfg.option('creole').list(type='optiondescription', - group_type=groups.family) + result = cfg.option('creole').list() group_names = [res.name() for res in result] assert group_names == ['general'] # assert not list_sessions() @@ -170,20 +159,11 @@ def test_iter_on_empty_group(): od1 = OptionDescription("name", "descr", []) cfg = Config(od1) cfg.property.read_write() - result = list(cfg.option.list(type='optiondescription')) + result = list(cfg.option.list()) assert result == [] # assert not list_sessions() -def test_iter_not_group(): - od1 = OptionDescription("name", "descr", []) - cfg = Config(od1) - cfg.property.read_write() - with pytest.raises(AssertionError): - print(list(cfg.option.list(type='optiondescription', group_type='family'))) -# assert not list_sessions() - - def test_groups_with_leader(): ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) @@ -221,25 +201,26 @@ def test_groups_is_leader(config_type): def test_leader_list(config_type): - ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) + ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", ['val1'], multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, default_multi='value') interface1 = Leadership('leadership', '', [ip_admin_eth0, netmask_admin_eth0]) od1 = OptionDescription('od', '', [interface1]) cfg = Config(od1) cfg = get_config(cfg, config_type) - ret = cfg.option.list('all') + ret = cfg.option.list() assert len(ret) == 1 assert ret[0].name() == 'leadership' # - ret = cfg.option('leadership').list('all') + ret = cfg.option('leadership').list() assert len(ret) == 2 assert ret[0].name() == 'ip_admin_eth0' assert ret[1].name() == 'netmask_admin_eth0' + assert ret[1].index() == 0 # cfg.option('leadership.ip_admin_eth0').value.set(['a', 'b']) cfg.option('leadership.netmask_admin_eth0', 0).value.set('c') cfg.option('leadership.netmask_admin_eth0', 1).value.set('d') - ret = cfg.option('leadership').list('all') + ret = cfg.option('leadership').list() assert ret[0].name() == 'ip_admin_eth0' assert ret[1].name() == 'netmask_admin_eth0' # assert ret[1].option.index() == 0 @@ -303,7 +284,7 @@ def test_groups_with_leader_make_dict(config_type): od1 = OptionDescription('root', '', [interface1]) cfg = Config(od1) cfg = get_config(cfg, config_type) - assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': []} + assert parse_od_get(cfg.value.get()) == {'ip_admin_eth0.ip_admin_eth0': []} if config_type != 'tiramisu-api': # FIXME useful? already in leadership assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.len() == 0 @@ -313,7 +294,7 @@ def test_groups_with_leader_make_dict(config_type): # FIXME assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.len() == 2 assert cfg.option('ip_admin_eth0.netmask_admin_eth0').value.len() == 2 - assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [{'ip_admin_eth0.ip_admin_eth0': 'ip1', 'ip_admin_eth0.netmask_admin_eth0': None}, {'ip_admin_eth0.ip_admin_eth0': 'ip2', 'ip_admin_eth0.netmask_admin_eth0': None}]} + assert parse_od_get(cfg.value.get()) == {'ip_admin_eth0.ip_admin_eth0': [{'ip_admin_eth0.ip_admin_eth0': 'ip1', 'ip_admin_eth0.netmask_admin_eth0': None}, {'ip_admin_eth0.ip_admin_eth0': 'ip2', 'ip_admin_eth0.netmask_admin_eth0': None}]} if config_type == 'tiramisu-api': cfg.send() # assert not list_sessions() @@ -336,7 +317,7 @@ def test_groups_with_leader_make_dict2(config_type): od1 = OptionDescription('root', '', [interface1]) cfg = Config(od1) cfg = get_config(cfg, config_type) - assert cfg.value.dict() == {'other.ip_admin_eth0': []} + assert parse_od_get(cfg.value.get()) == {'other.ip_admin_eth0': []} if config_type != 'tiramisu-api': # FIXME useful? already in leadership assert cfg.option('other.ip_admin_eth0').value.len() == 0 @@ -346,7 +327,7 @@ def test_groups_with_leader_make_dict2(config_type): # FIXME assert cfg.option('other.ip_admin_eth0').value.len() == 2 assert cfg.option('other.netmask_admin_eth0').value.len() == 2 - assert cfg.value.dict() == {'other.ip_admin_eth0': [{'other.ip_admin_eth0': 'ip1', 'other.netmask_admin_eth0': None}, {'other.ip_admin_eth0': 'ip2', 'other.netmask_admin_eth0': None}]} + assert parse_od_get(cfg.value.get()) == {'other.ip_admin_eth0': [{'other.ip_admin_eth0': 'ip1', 'other.netmask_admin_eth0': None}, {'other.ip_admin_eth0': 'ip2', 'other.netmask_admin_eth0': None}]} if config_type == 'tiramisu-api': cfg.send() # assert not list_sessions() @@ -411,7 +392,7 @@ def test_groups_with_leader_hidden_in_config(): cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() with pytest.raises(PropertiesOptionError): cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() - assert cfg.value.dict() == {} + assert parse_od_get(cfg.value.get()) == {} # assert not list_sessions() @@ -426,16 +407,13 @@ def test_groups_with_leader_hidden_in_config2(): assert cfg.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] cfg.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) assert cfg.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None - with pytest.raises(PropertiesOptionError): - cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() + assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] with pytest.raises(PropertiesOptionError): cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() - assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['192.168.1.1']} - assert cfg.value.dict(leader_to_list=True) == {'ip_admin_eth0.ip_admin_eth0': [{'ip_admin_eth0.ip_admin_eth0': '192.168.1.1'}]} # assert not list_sessions() -def test_groups_with_leader_hidden_in_config2(): +def test_groups_with_leader_hidden_in_config3(): ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, properties=('hidden',)) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) @@ -1005,66 +983,66 @@ def test_follower_not_multi(): # assert not list_sessions() -def test_follower_force_store_value_none(): - ip_admin_eth0 = IPOption('ip_admin_eth0', "ip réseau autorisé", multi=True, default=['1.1.1.1']) - netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, properties=('force_store_value',)) - interface0 = Leadership('interface0', '', [ip_admin_eth0, netmask_admin_eth0]) - od1 = OptionDescription('od', '', [interface0]) - od2 = OptionDescription('toto', '', [od1]) - cfg = Config(od2) - cfg.property.read_write() - assert cfg.option('od.interface0.netmask_admin_eth0', 0).owner.isdefault() -# assert not list_sessions() - - -def test_follower_force_store_value(): - ip_admin_eth0 = IPOption('ip_admin_eth0', "ip réseau autorisé", multi=True, default=['1.1.1.1']) - netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "masque du sous-réseau", default_multi='255.255.255.0', multi=True, properties=('force_store_value',)) - interface0 = Leadership('interface0', '', [ip_admin_eth0, netmask_admin_eth0]) - od1 = OptionDescription('od', '', [interface0]) - od2 = OptionDescription('toto', '', [od1]) - cfg = Config(od2) - cfg.property.read_write() - assert not cfg.option('od.interface0.netmask_admin_eth0', 0).owner.isdefault() -# assert not list_sessions() - - -def test_follower_force_store_value_read_only(): - ip_admin_eth0 = IPOption('ip_admin_eth0', "ip réseau autorisé", multi=True, default=['1.1.1.1']) - netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "masque du sous-réseau", default_multi='255.255.255.0', multi=True, properties=('force_store_value',)) - interface0 = Leadership('interface0', '', [ip_admin_eth0, netmask_admin_eth0]) - od1 = OptionDescription('od', '', [interface0]) - od2 = OptionDescription('toto', '', [od1]) - cfg = Config(od2) - cfg.property.read_only() - assert not cfg.option('od.interface0.netmask_admin_eth0', 0).owner.isdefault() -# assert not list_sessions() - - -def test_follower_force_store_value_reset(): - ip_admin_eth0 = IPOption('ip_admin_eth0', "ip réseau autorisé", multi=True, default=['1.1.1.1']) - netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "masque du sous-réseau", default_multi='255.255.255.0', multi=True, properties=('force_store_value',)) - interface0 = Leadership('interface0', '', [ip_admin_eth0, netmask_admin_eth0]) - od1 = OptionDescription('od', '', [interface0]) - od2 = OptionDescription('toto', '', [od1]) - cfg = Config(od2) - cfg.property.read_write() - cfg.option('od.interface0.ip_admin_eth0').value.set(['1.1.1.1', '192.168.0.0']) - assert not cfg.option('od.interface0.netmask_admin_eth0', 0).owner.isdefault() - assert not cfg.option('od.interface0.netmask_admin_eth0', 1).owner.isdefault() - # - cfg.option('od.interface0.netmask_admin_eth0', 1).value.reset() - assert not cfg.option('od.interface0.netmask_admin_eth0', 1).owner.isdefault() - # - cfg.option('od.interface0.ip_admin_eth0').value.pop(0) - cfg.option('od.interface0.ip_admin_eth0').value.pop(0) - assert cfg.option('od.interface0.ip_admin_eth0').value.get() == [] - cfg.option('od.interface0.ip_admin_eth0').value.reset() - assert not cfg.option('od.interface0.netmask_admin_eth0', 0).owner.isdefault() -# assert not list_sessions() - - -def test_follower_properties(): +#def test_follower_force_store_value_none(): +# ip_admin_eth0 = IPOption('ip_admin_eth0', "ip réseau autorisé", multi=True, default=['1.1.1.1']) +# netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, properties=('force_store_value',)) +# interface0 = Leadership('interface0', '', [ip_admin_eth0, netmask_admin_eth0]) +# od1 = OptionDescription('od', '', [interface0]) +# od2 = OptionDescription('toto', '', [od1]) +# cfg = Config(od2) +# cfg.property.read_write() +# assert cfg.option('od.interface0.netmask_admin_eth0', 0).owner.isdefault() +## assert not list_sessions() +# +# +#def test_follower_force_store_value(): +# ip_admin_eth0 = IPOption('ip_admin_eth0', "ip réseau autorisé", multi=True, default=['1.1.1.1']) +# netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "masque du sous-réseau", default_multi='255.255.255.0', multi=True, properties=('force_store_value',)) +# interface0 = Leadership('interface0', '', [ip_admin_eth0, netmask_admin_eth0]) +# od1 = OptionDescription('od', '', [interface0]) +# od2 = OptionDescription('toto', '', [od1]) +# cfg = Config(od2) +# cfg.property.read_write() +# assert not cfg.option('od.interface0.netmask_admin_eth0', 0).owner.isdefault() +## assert not list_sessions() +# +# +#def test_follower_force_store_value_read_only(): +# ip_admin_eth0 = IPOption('ip_admin_eth0', "ip réseau autorisé", multi=True, default=['1.1.1.1']) +# netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "masque du sous-réseau", default_multi='255.255.255.0', multi=True, properties=('force_store_value',)) +# interface0 = Leadership('interface0', '', [ip_admin_eth0, netmask_admin_eth0]) +# od1 = OptionDescription('od', '', [interface0]) +# od2 = OptionDescription('toto', '', [od1]) +# cfg = Config(od2) +# cfg.property.read_only() +# assert not cfg.option('od.interface0.netmask_admin_eth0', 0).owner.isdefault() +## assert not list_sessions() +# +# +#def test_follower_force_store_value_reset(): +# ip_admin_eth0 = IPOption('ip_admin_eth0', "ip réseau autorisé", multi=True, default=['1.1.1.1']) +# netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "masque du sous-réseau", default_multi='255.255.255.0', multi=True, properties=('force_store_value',)) +# interface0 = Leadership('interface0', '', [ip_admin_eth0, netmask_admin_eth0]) +# od1 = OptionDescription('od', '', [interface0]) +# od2 = OptionDescription('toto', '', [od1]) +# cfg = Config(od2) +# cfg.property.read_write() +# cfg.option('od.interface0.ip_admin_eth0').value.set(['1.1.1.1', '192.168.0.0']) +# assert not cfg.option('od.interface0.netmask_admin_eth0', 0).owner.isdefault() +# assert not cfg.option('od.interface0.netmask_admin_eth0', 1).owner.isdefault() +# # +# cfg.option('od.interface0.netmask_admin_eth0', 1).value.reset() +# assert not cfg.option('od.interface0.netmask_admin_eth0', 1).owner.isdefault() +# # +# cfg.option('od.interface0.ip_admin_eth0').value.pop(0) +# cfg.option('od.interface0.ip_admin_eth0').value.pop(0) +# assert cfg.option('od.interface0.ip_admin_eth0').value.get() == [] +# cfg.option('od.interface0.ip_admin_eth0').value.reset() +# assert not cfg.option('od.interface0.netmask_admin_eth0', 0).owner.isdefault() +## assert not list_sessions() +# +# +#def test_follower_properties(): ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, properties=('aproperty',)) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) diff --git a/tests/test_mandatory.py b/tests/test_mandatory.py index f568434..d993206 100644 --- a/tests/test_mandatory.py +++ b/tests/test_mandatory.py @@ -1,6 +1,7 @@ # coding: utf-8 from .autopath import do_autopath do_autopath() +from .config import parse_od_get # FIXME from .config import config_type, get_config import pytest @@ -50,18 +51,6 @@ def make_description2(): return descr -def make_description_sym(): - stroption = StrOption('str', 'Test string option', default="abc", - properties=('mandatory', )) - stroption1 = StrOption('str1', 'Test string option', - properties=('mandatory', )) - stroption2 = SymLinkOption('unicode2', stroption1) - stroption3 = StrOption('str3', 'Test string option', multi=True, - properties=('mandatory', )) - descr = OptionDescription('tiram', '', [stroption, stroption1, stroption2, stroption3]) - return descr - - def make_description3(): stroption = StrOption('str', 'Test string option', default="abc", properties=('mandatory', )) @@ -99,7 +88,7 @@ def test_mandatory_ro_dict(): cfg.property.read_only() prop = [] try: - cfg.value.dict() + cfg.value.get() except PropertiesOptionError as err: prop = err.proptype assert 'mandatory' in prop @@ -108,14 +97,14 @@ def test_mandatory_ro_dict(): cfg.option('unicode2').value.set('yes') cfg.property.read_only() try: - cfg.value.dict() + cfg.value.get() except PropertiesOptionError as err: prop = err.proptype assert 'mandatory' in prop cfg.property.read_write() cfg.option('str3').value.set(['yes']) cfg.property.read_only() - assert cfg.value.dict() == {'str': 'abc', 'str1': 'yes', 'str3': ['yes'], 'unicode2': 'yes'} + assert parse_od_get(cfg.value.get()) == {'str': 'abc', 'str1': 'yes', 'str3': ['yes'], 'unicode2': 'yes'} # assert not list_sessions() @@ -414,7 +403,7 @@ def test_mandatory_leader(): with pytest.raises(PropertiesOptionError): cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() with pytest.raises(PropertiesOptionError): - cfg.value.dict() + cfg.value.get() # assert not list_sessions() @@ -431,7 +420,7 @@ def test_mandatory_leader_sub(): with pytest.raises(PropertiesOptionError): cfg.option('o.ip_admin_eth0.ip_admin_eth0').value.get() with pytest.raises(PropertiesOptionError): - cfg.value.dict() + cfg.value.get() # assert not list_sessions() @@ -529,7 +518,7 @@ def test_mandatory_follower(): cfg = Config(od1) cfg.property.read_only() assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': []} + assert parse_od_get(cfg.value.get()) == {'ip_admin_eth0.ip_admin_eth0': []} # cfg.property.read_write() cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip']) @@ -550,7 +539,7 @@ def test_mandatory_follower(): cfg.property.read_only() assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip'] assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == 'ip' - assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [{'ip_admin_eth0.ip_admin_eth0': 'ip', 'ip_admin_eth0.netmask_admin_eth0': 'ip'}]} + assert parse_od_get(cfg.value.get()) == {'ip_admin_eth0.ip_admin_eth0': [{'ip_admin_eth0.ip_admin_eth0': 'ip', 'ip_admin_eth0.netmask_admin_eth0': 'ip'}]} # assert not list_sessions() @@ -572,7 +561,14 @@ def test_mandatory_warnings_follower(): def test_mandatory_warnings_symlink(): - od1 = make_description_sym() + stroption = StrOption('str', 'Test string option', default="abc", + properties=('mandatory', )) + stroption1 = StrOption('str1', 'Test string option', + properties=('mandatory', )) + stroption2 = SymLinkOption('unicode2', stroption1) + stroption3 = StrOption('str3', 'Test string option', multi=True, + properties=('mandatory', )) + od1 = OptionDescription('tiram', '', [stroption, stroption1, stroption2, stroption3]) cfg = Config(od1) cfg.option('str').value.set('') cfg.property.read_write() @@ -692,25 +688,25 @@ def return_list(val=None, suffix=None): return ['val1', 'val2'] -def test_mandatory_dyndescription(): - st = StrOption('st', '', properties=('mandatory',)) - dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) - od = OptionDescription('od', '', [dod]) - od2 = OptionDescription('od', '', [od]) - cfg = Config(od2) - cfg.property.read_only() - compare(cfg.value.mandatory(), ['od.dodval1.st', 'od.dodval2.st']) - - -def test_mandatory_dyndescription_context(): - val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) - st = StrOption('st', '', properties=('mandatory',)) - dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(val1)))) - od = OptionDescription('od', '', [dod, val1]) - od2 = OptionDescription('od', '', [od]) - cfg = Config(od2) - cfg.property.read_only() - compare(cfg.value.mandatory(), ['od.dodval1.st', 'od.dodval2.st']) +#def test_mandatory_dyndescription(): +# st = StrOption('st', '', properties=('mandatory',)) +# dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) +# od = OptionDescription('od', '', [dod]) +# od2 = OptionDescription('od', '', [od]) +# cfg = Config(od2) +# cfg.property.read_only() +# compare(cfg.value.mandatory(), ['od.dodval1.st', 'od.dodval2.st']) +# +# +#def test_mandatory_dyndescription_context(): +# val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) +# st = StrOption('st', '', properties=('mandatory',)) +# dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(val1)))) +# od = OptionDescription('od', '', [dod, val1]) +# od2 = OptionDescription('od', '', [od]) +# cfg = Config(od2) +# cfg.property.read_only() +# compare(cfg.value.mandatory(), ['od.dodval1.st', 'od.dodval2.st']) def test_mandatory_callback_leader_and_followers_leader(): @@ -733,4 +729,4 @@ def test_mandatory_and_disabled(): od1 = OptionDescription('rootconfig', '', [username, password]) cfg = Config(od1) cfg.property.read_write() - cfg.value.dict() + cfg.value.get() diff --git a/tests/test_metaconfig.py b/tests/test_metaconfig.py index fb6e053..582aa3a 100644 --- a/tests/test_metaconfig.py +++ b/tests/test_metaconfig.py @@ -59,1289 +59,1289 @@ def make_metaconfig(double=False): return meta -def test_unknown_config(): - meta = make_metaconfig() - with pytest.raises(ConfigError): - meta.config('unknown') - - -def test_error_metaconfig(): - od2 = make_description() - conf1 = Config(od2, name='conf1') - with pytest.raises(TypeError): - MetaConfig([GroupConfig([conf1])], name='meta') - - -def test_path(): - meta = make_metaconfig() - assert meta.config.path() == 'meta' - ret = meta.config('conf1') - assert ret.config.path() == 'meta.conf1' - ret = meta.config('conf2') - assert ret.config.path() == 'meta.conf2' - - -def test_none(): - meta = make_metaconfig() - conf1 = meta.config('conf1') - conf2 = meta.config('conf2') - assert meta.option('od1.i3').value.get() is conf1.option('od1.i3').value.get() is conf2.option('od1.i3').value.get() is None - assert meta.option('od1.i3').owner.get() is conf1.option('od1.i3').owner.get() is conf2.option('od1.i3').owner.get() is owners.default - # - assert meta.option('od1.i3').value.set(3) == [] - assert meta.option('od1.i3').value.get() == conf1.option('od1.i3').value.get() == conf2.option('od1.i3').value.get() == 3 - assert meta.option('od1.i3').owner.get() is conf1.option('od1.i3').owner.get() is conf2.option('od1.i3').owner.get() is owners.meta1 - # - conf1.option('od1.i3').value.set(2) - assert meta.option('od1.i3').value.get() == conf2.option('od1.i3').value.get() == 3 - assert conf1.option('od1.i3').value.get() == 2 - assert meta.option('od1.i3').owner.get() is conf2.option('od1.i3').owner.get() is owners.meta1 - assert conf1.option('od1.i3').owner.get() is owners.user - # - meta.option('od1.i3').value.set(4) - assert meta.option('od1.i3').value.get() == conf2.option('od1.i3').value.get() == 4 - assert conf1.option('od1.i3').value.get() == 2 - assert meta.option('od1.i3').owner.get() is conf2.option('od1.i3').owner.get() is owners.meta1 - assert conf1.option('od1.i3').owner.get() is owners.user - # - meta.option('od1.i3').value.reset() - assert meta.option('od1.i3').value.get() is conf2.option('od1.i3').value.get() is None - assert conf1.option('od1.i3').value.get() == 2 - assert meta.option('od1.i3').owner.get() is conf2.option('od1.i3').owner.get() is owners.default - assert conf1.option('od1.i3').owner.get() is owners.user - # - conf1.option('od1.i3').value.reset() - assert meta.option('od1.i3').value.get() is conf1.option('od1.i3').value.get() is conf2.option('od1.i3').value.get() is None - assert meta.option('od1.i3').owner.get() is conf1.option('od1.i3').owner.get() is conf2.option('od1.i3').owner.get() is owners.default - - -def test_metaconfig_reset(config_type): - meta = make_metaconfig() - meta_api = get_config(meta, config_type) - assert meta_api.option('od1.i2').value.get() == 1 - meta_api.option('od1.i2').value.set(2) - if config_type == 'tiramisu-api': - meta_api.send() - conf1 = meta.config('conf1') - conf2 = meta.config('conf2') - conf1.option('od1.i2').value.set(3) - assert meta.option('od1.i2').value.get() == 2 - assert conf1.option('od1.i2').value.get() == 3 - assert conf2.option('od1.i2').value.get() == 2 - meta.config.reset() - assert meta.option('od1.i2').value.get() == 1 - assert conf1.option('od1.i2').value.get() == 3 - assert conf2.option('od1.i2').value.get() == 1 - - -def test_default(): - meta = make_metaconfig() - conf1 = meta.config('conf1') - conf2 = meta.config('conf2') - assert meta.option('od1.i2').value.get() == conf1.option('od1.i2').value.get() == conf2.option('od1.i2').value.get() == 1 - assert meta.option('od1.i2').owner.get() is conf1.option('od1.i2').owner.get() is conf2.option('od1.i2').owner.get() is owners.default - # - meta.option('od1.i2').value.set(3) - assert meta.option('od1.i2').value.get() == conf1.option('od1.i2').value.get() == conf2.option('od1.i2').value.get() == 3 - assert meta.option('od1.i2').owner.get() is conf1.option('od1.i2').owner.get() is conf2.option('od1.i2').owner.get() is owners.meta1 - # - conf1.option('od1.i2').value.set(2) - assert meta.option('od1.i2').value.get() == conf2.option('od1.i2').value.get() == 3 - assert conf1.option('od1.i2').value.get() == 2 - assert meta.option('od1.i2').owner.get() is conf2.option('od1.i2').owner.get() is owners.meta1 - assert conf1.option('od1.i2').owner.get() is owners.user - # - meta.option('od1.i2').value.set(4) - assert meta.option('od1.i2').value.get() == conf2.option('od1.i2').value.get() == 4 - assert conf1.option('od1.i2').value.get() == 2 - assert meta.option('od1.i2').owner.get() is conf2.option('od1.i2').owner.get() is owners.meta1 - assert conf1.option('od1.i2').owner.get() is owners.user - # - meta.option('od1.i2').value.reset() - assert meta.option('od1.i2').value.get() == conf2.option('od1.i2').value.get() == 1 - assert conf1.option('od1.i2').value.get() == 2 - assert meta.option('od1.i2').owner.get() is conf2.option('od1.i2').owner.get() is owners.default - assert conf1.option('od1.i2').owner.get() is owners.user - # - conf1.option('od1.i2').value.reset() - assert meta.option('od1.i2').value.get() == conf1.option('od1.i2').value.get() == conf2.option('od1.i2').value.get() == 1 - assert meta.option('od1.i2').owner.get() is conf1.option('od1.i2').owner.get() is conf2.option('od1.i2').owner.get() is owners.default - - -def test_contexts(): - meta = make_metaconfig() - errors = meta.value.set('od1.i2', 6, only_config=True) - assert len(errors) == 0 - conf1 = meta.config('conf1') - assert meta.option('od1.i2').value.get() == 1 - assert meta.option('od1.i2').owner.get() == owners.default - assert conf1.option('od1.i2').value.get() == conf1.option('od1.i2').value.get() == 6 - assert conf1.option('od1.i2').owner.get() == conf1.option('od1.i2').owner.get() is owners.user - - -def test_find(): - meta = make_metaconfig() - ret = list(meta.option.find('i2')) - assert len(ret) == 1 - assert 1 == ret[0].value.get() - ret = meta.option.find('i2', first=True) - assert 1 == ret.value.get() - assert meta.value.dict() == {'od1.i4': 2, 'od1.i1': None, 'od1.i3': None, - 'od1.i2': 1, 'od1.i5': [2]} - - -def test_meta_meta(): - meta = make_metaconfig(double=True) - meta1 = meta.config('meta') - conf1 = meta.config('meta.conf1') - conf2 = meta.config('meta.conf2') - assert meta.option('od1.i2').value.get() == meta1.option('od1.i2').value.get() == conf1.option('od1.i2').value.get() == conf2.option('od1.i2').value.get() == 1 - assert meta.option('od1.i2').owner.get() is meta1.option('od1.i2').owner.get() is conf1.option('od1.i2').owner.get() is conf2.option('od1.i2').owner.get() is owners.default - # - meta.option('od1.i2').value.set(3) - assert meta.option('od1.i2').value.get() == meta1.option('od1.i2').value.get() == conf1.option('od1.i2').value.get() == conf2.option('od1.i2').value.get() == 3 - assert meta.option('od1.i2').owner.get() is meta1.option('od1.i2').owner.get() is conf1.option('od1.i2').owner.get() is conf2.option('od1.i2').owner.get() is owners.meta1 - # - conf1.option('od1.i2').value.set(2) - assert meta.option('od1.i2').value.get() == meta1.option('od1.i2').value.get() == conf2.option('od1.i2').value.get() == 3 - assert conf1.option('od1.i2').value.get() == 2 - assert meta.option('od1.i2').owner.get() is meta1.option('od1.i2').owner.get() is conf2.option('od1.i2').owner.get() is owners.meta1 - assert conf1.option('od1.i2').owner.get() is owners.user - # - meta1.option('od1.i2').value.set(4) - assert meta.option('od1.i2').value.get() == 3 - assert meta1.option('od1.i2').value.get() == conf2.option('od1.i2').value.get() == 4 - assert conf1.option('od1.i2').value.get() == 2 - assert meta.option('od1.i2').owner.get() is owners.meta1 - assert meta1.option('od1.i2').owner.get() is conf2.option('od1.i2').owner.get() is owners.meta2 - assert conf1.option('od1.i2').owner.get() is owners.user - # - meta1.option('od1.i2').value.reset() - assert meta.option('od1.i2').value.get() == meta1.option('od1.i2').value.get() == conf2.option('od1.i2').value.get() == 3 - assert conf1.option('od1.i2').value.get() == 2 - assert meta.option('od1.i2').owner.get() is meta1.option('od1.i2').owner.get() is conf2.option('od1.i2').owner.get() is owners.meta1 - assert conf1.option('od1.i2').owner.get() is owners.user - # - meta.option('od1.i2').value.reset() - assert meta.option('od1.i2').value.get() == meta1.option('od1.i2').value.get() == conf2.option('od1.i2').value.get() == 1 - assert conf1.option('od1.i2').value.get() == 2 - assert meta.option('od1.i2').owner.get() is meta1.option('od1.i2').owner.get() is conf2.option('od1.i2').owner.get() is owners.default - assert conf1.option('od1.i2').owner.get() is owners.user - # - conf1.option('od1.i2').value.reset() - assert meta.option('od1.i2').value.get() == meta1.option('od1.i2').value.get() == conf1.option('od1.i2').value.get() == conf2.option('od1.i2').value.get() == 1 - assert meta.option('od1.i2').owner.get() is meta1.option('od1.i2').owner.get() is conf1.option('od1.i2').owner.get() is conf2.option('od1.i2').owner.get() is owners.default - - -def test_meta_new_config(): - od = make_description() - meta = MetaConfig(['name1', 'name2'], optiondescription=od) - assert len(list(meta.config.list())) == 2 - meta.config.new('newconf1') - assert len(list(meta.config.list())) == 3 - - -def test_meta_new_config_owner(): - od = make_description() - meta = MetaConfig(['name1', 'name2'], optiondescription=od) - meta.owner.set('meta') - meta.config.new('newconf1') - assert meta.owner.get() == 'meta' - - -def test_meta_new_metaconfig(): - od = make_description() - meta = MetaConfig(['name1', 'name2'], optiondescription=od) - meta.config.new('newconf1', type='metaconfig') - newconf1 = meta.config('newconf1') - newconf1.config.new('newconf2', type='metaconfig') - newconf2 = newconf1.config('newconf2') - newconf2.config.new('newconf3') - newconf3 = newconf2.config('newconf3') - assert newconf3.config.name() == 'newconf3' - - -def test_meta_pop_config(): - od = make_description() - meta = MetaConfig(['name1', 'name2'], optiondescription=od) - meta.option('od1.i1').value.set(2) - # - assert len(list(meta.config.list())) == 2 - meta.config.new('newconf1') - newconf1 = meta.config('newconf1') - assert newconf1.value.dict() == {'od1.i1': 2, 'od1.i2': 1, 'od1.i3': None, 'od1.i4': 2, 'od1.i5': [2], 'od1.i6': None} - # - assert len(list(meta.config.list())) == 3 - newconf1 = meta.config.remove('newconf1') - try: - meta.config('newconf1') - except ConfigError: - pass - else: - raise Exception('must raise') - assert newconf1.value.dict() == {'od1.i1': None, 'od1.i2': 1, 'od1.i3': None, 'od1.i4': 2, 'od1.i5': [2], 'od1.i6': None} - # - assert len(list(meta.config.list())) == 2 - with pytest.raises(ConfigError): - meta.config.remove('newconf1') - - -def test_meta_add_config(): - od = make_description() - od2 = make_description() - meta = MetaConfig(['name1', 'name2'], optiondescription=od) - meta.option('od1.i1').value.set(2) - # - assert len(list(meta.config.list())) == 2 - config = Config(od, name='new') - assert config.value.dict() == {'od1.i1': None, 'od1.i2': 1, 'od1.i3': None, 'od1.i4': 2, 'od1.i5': [2], 'od1.i6': None} - meta.config.add(config) - # - assert len(list(meta.config.list())) == 3 - assert config.value.dict() == {'od1.i1': 2, 'od1.i2': 1, 'od1.i3': None, 'od1.i4': 2, 'od1.i5': [2], 'od1.i6': None} - # - with pytest.raises(ConflictError): - meta.config.add(config) - newconfig = Config(od2) - with pytest.raises(ValueError): - meta.config.add(newconfig) - - -def test_meta_add_config_not_name(): - od = make_description() - od2 = make_description() - meta = MetaConfig(['name1', 'name2'], optiondescription=od) - meta.option('od1.i1').value.set(2) - # - assert len(list(meta.config.list())) == 2 - config = Config(od) - with pytest.raises(ConfigError): - meta.config.add(config) - - -def test_meta_add_config_readd(): - od = make_description() - meta = MetaConfig([], optiondescription=od) - meta2 = MetaConfig([], optiondescription=od) - config = Config(od, name='new') - # - meta.config.add(config) - meta2.config.add(config) - assert len(list(config.config.parents())) == 2 - - -def test_meta_new_config_wrong_name(): - od = make_description() - meta = MetaConfig(['name1', 'name2'], optiondescription=od) - assert len(list(meta.config.list())) == 2 - with pytest.raises(ConflictError): - meta.config.new('name1') - assert len(list(meta.config.list())) == 2 - - -def test_meta_load_config(): - od = make_description() - meta = MetaConfig(['name1', 'name2'], optiondescription=od) - assert len(list(meta.config.list())) == 2 - meta.config('name1') - - -def test_meta_load_config_wrong_name(): - od = make_description() - meta = MetaConfig(['name1', 'name2'], optiondescription=od) - assert len(list(meta.config.list())) == 2 - with pytest.raises(ConfigError): - meta.config('name3') - - -def test_meta_meta_set(): - meta = make_metaconfig(double=True) - errors1 = meta.value.set('od1.i1', 7, only_config=True) - errors2 = meta.value.set('od1.i6', 7, only_config=True) - assert len(errors1) == 0 - assert len(errors2) == 2 - conf1 = meta.config('meta.conf1') - conf2 = meta.config('meta.conf2') - assert conf1.option('od1.i1').value.get() == conf2.option('od1.i1').value.get() == 7 - # - dconfigs = [] - ret = meta.config.find('i1', value=7) - for conf in ret.config.list(): - dconfigs.append(conf._config_bag.context) - assert [conf1._config_bag.context, conf2._config_bag.context] == dconfigs - conf1.option('od1.i1').value.set(8) - # - dconfigs = [] - ret = meta.config.find('i1') - for conf in ret.config.list(): - dconfigs.append(conf._config_bag.context) - assert [conf1._config_bag.context, conf2._config_bag.context] == dconfigs - ret = meta.config.find('i1', value=7) - assert len(ret.config.list()) == 1 - assert conf2._config_bag.context == list(ret.config.list())[0]._config_bag.context - - ret = meta.config.find('i1', value=8) - assert len(ret.config.list()) == 1 - assert conf1._config_bag.context == list(ret.config.list())[0]._config_bag.context - # - dconfigs = [] - ret = meta.config.find('i5', value=2) - for conf in ret.config.list(): - dconfigs.append(conf._config_bag.context) - assert [conf1._config_bag.context, conf2._config_bag.context] == dconfigs - # - with pytest.raises(AttributeError): - meta.config.find('i1', value=10) - with pytest.raises(AttributeError): - meta.config.find('not', value=10) - with pytest.raises(AttributeError): - meta.config.find('i6') - with pytest.raises(ValueError): - meta.value.set('od1.i6', 7, only_config=True, force_default=True) - with pytest.raises(ValueError): - meta.value.set('od1.i6', 7, only_config=True, force_default_if_same=True) - with pytest.raises(ValueError): - meta.value.set('od1.i6', 7, only_config=True, force_dont_change_value=True) - - -def test_not_meta(): - i1 = IntOption('i1', '') - od1 = OptionDescription('od1', '', [i1]) - od2 = OptionDescription('od2', '', [od1]) - conf1 = Config(od2, name='conf1') - conf2 = Config(od2, name='conf2') - conf3 = Config(od2) - conf4 = Config(od2, name='conf4') - with pytest.raises(TypeError): - GroupConfig(conf1) - with pytest.raises(ConflictError): - GroupConfig([conf2, conf2], name='conf8') - grp = GroupConfig([conf1, conf2]) - assert grp.config.type() == 'groupconfig' - with pytest.raises(ConfigError): - grp.option('od1.i1').value.get() - conf1, conf2 = grp.config.list() - errors = grp.value.set('od1.i1', 7) - assert len(errors) == 0 - conf1 = grp.config('conf1') - conf2 = grp.config('conf2') - assert conf1.option('od1.i1').value.get() == conf2.option('od1.i1').value.get() == 7 - assert conf1.option('od1.i1').owner.get() is conf2.option('od1.i1').owner.get() is owners.user - grp.option('od1.i1').value.reset() - assert conf1.option('od1.i1').owner.get() is conf2.option('od1.i1').owner.get() is owners.default - - -def test_group_find_firsts(): - i1 = IntOption('i1', '') - od1 = OptionDescription('od1', '', [i1]) - od2 = OptionDescription('od2', '', [od1]) - conf1 = Config(od2, name='conf1') - conf2 = Config(od2, name='conf2') - grp = GroupConfig([conf1, conf2]) - ret = grp.config.find('i1') - newconf1, newconf2 = grp.config.list() - conf1._config_bag.context == newconf1._config_bag.context - conf2._config_bag.context == newconf2._config_bag.context - - -def test_group_group(): - i1 = IntOption('i1', '') - od1 = OptionDescription('od1', '', [i1]) - od2 = OptionDescription('od2', '', [od1]) - conf1 = Config(od2, name='conf9') - conf2 = Config(od2, name='conf10') - grp = GroupConfig([conf1, conf2], 'grp') - grp2 = GroupConfig([grp]) - errors = grp2.value.set('od1.i1', 2) - assert len(errors) == 0 - conf9 = grp2.config('grp.conf9') - assert conf9.option('od1.i1').value.get() == 2 - assert conf9.option('od1.i1').owner.get() is owners.user - - -def test_group_group_path(): - i1 = IntOption('i1', '') - od1 = OptionDescription('od1', '', [i1]) - od2 = OptionDescription('od2', '', [od1]) - conf1 = Config(od2, name='conf9') - conf2 = Config(od2, name='conf10') - grp = GroupConfig([conf1, conf2], 'grp') - grp2 = GroupConfig([grp], 'grp2') - assert grp2.config.path() == 'grp2' - newgrp = grp2.config('grp') - assert newgrp.config.path() == 'grp' - newgrp = grp2.config('grp.conf9') - assert newgrp.config.path() == 'conf9' - newgrp = grp2.config('grp.conf10') - assert newgrp.config.path() == 'conf10' - - -def test_meta_unconsistent(): - i1 = IntOption('i1', '') - i2 = IntOption('i2', '', default=1) - i3 = IntOption('i3', '') - i4 = IntOption('i4', '', default=2) - od1 = OptionDescription('od1', '', [i1, i2, i3, i4]) - od2 = OptionDescription('od2', '', [od1]) - i5 = IntOption('i5', '') - od3 = OptionDescription('od3', '', [i5]) - conf1 = Config(od2, name='conf1') - conf2 = Config(od2, name='conf2') - conf3 = Config(od2, name='conf3') - conf4 = Config(od3, name='conf4') - meta = MetaConfig([conf1, conf2]) - meta.owner.set(owners.meta1) - with pytest.raises(TypeError): - MetaConfig("string") - #same descr but conf1 already in meta - assert len(list(conf1.config.parents())) == 1 - assert len(list(conf3.config.parents())) == 0 - new_meta = MetaConfig([conf1, conf3]) - assert len(list(conf1.config.parents())) == 2 - assert len(list(conf3.config.parents())) == 1 - #not same descr - with pytest.raises(ValueError): - MetaConfig([conf3, conf4]) - - -def test_meta_leadership(): - ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) - netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) - interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) - od = OptionDescription('root', '', [interface1]) - conf1 = Config(od, name='conf1') - conf2 = Config(od, name='conf2') - meta = MetaConfig([conf1, conf2]) - meta.property.read_only() - ret = meta.config.find('ip_admin_eth0') - configs = ret.config.list() - assert len(configs) == 2 - assert conf1._config_bag.context == configs[0]._config_bag.context - assert conf2._config_bag.context == configs[1]._config_bag.context - ret = meta.config.find('netmask_admin_eth0') - configs = ret.config.list() - assert len(configs) == 2 - assert conf1._config_bag.context == configs[0]._config_bag.context - assert conf2._config_bag.context == configs[1]._config_bag.context - meta.property.read_write() - with pytest.raises(AttributeError): - meta.config.find('netmask_admin_eth0') - ret = meta.unrestraint.config.find('netmask_admin_eth0') - configs = ret.config.list() - assert conf1._config_bag.context == configs[0]._config_bag.context - assert conf2._config_bag.context == configs[1]._config_bag.context - meta.property.read_only() - ret = meta.config.find('netmask_admin_eth0') - configs = ret.config.list() - assert conf1._config_bag.context == configs[0]._config_bag.context - assert conf2._config_bag.context == configs[1]._config_bag.context - - -def test_meta_leadership_value(): - ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) - netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) - interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) - od = OptionDescription('root', '', [interface1]) - conf1 = Config(od, name='conf1') - conf2 = Config(od, name='conf2') - meta = MetaConfig([conf1, conf2], name="meta") - conf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.8']) - assert conf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None - with pytest.raises(ConfigError): - conf1.option('ip_admin_eth0.ip_admin_eth0', 0).value.get() - # - conf1.option('ip_admin_eth0.ip_admin_eth0').value.reset() - # - meta.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) - assert conf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None - meta.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0') - assert conf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0' - meta.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.0.0') - assert conf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0' - # - conf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) - assert conf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0' - # - meta.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.2.1', '192.168.3.1']) - meta.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.0') - # - assert conf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] - assert conf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0' - - -def test_meta_leadership_value_default(): - ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) - netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True) - interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) - od = OptionDescription('root', '', [interface1]) - conf1 = Config(od, name='conf1') - conf2 = Config(od, name='conf2') - meta = MetaConfig([conf1, conf2]) - newconf1 = meta.config('conf1') - assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None - # - meta.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) - assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None - # - meta.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0') - assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0' - # - meta.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.0.0') - assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0' - # - newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) - assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0' - - -def test_meta_leadership_owners(): - ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) - netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) - interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) - od = OptionDescription('root', '', [interface1]) - conf1 = Config(od, name='conf1') - conf2 = Config(od, name='conf2') - meta = MetaConfig([conf1, conf2]) - meta.owner.set(owners.meta1) - newconf1 = meta.config('conf1') - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault() - with pytest.raises(LeadershipError): - newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault() - # - newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.user - assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault() - # - newconf1.option('ip_admin_eth0.ip_admin_eth0').value.reset() - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault() - # - meta.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.meta1 - assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault() - # - meta.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0') - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.meta1 - assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.meta1 - # - meta.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.0.0') - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.meta1 - assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.meta1 - # - newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.user - assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.meta1 - - -def test_meta_force_default(): - ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) - netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) - interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) - od = OptionDescription('root', '', [interface1]) - conf1 = Config(od, name='conf1') - conf2 = Config(od, name='conf2') - meta = MetaConfig([conf1, conf2]) - meta.property.read_write() - meta.owner.set('meta1') - newconf1 = meta.config('conf1') - newconf2 = meta.config('conf2') - assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - # - errors = meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.1']) - assert len(errors) == 0 - assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] - # - newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2']) - assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2'] - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] - # - errors = meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.3']) - assert len(errors) == 0 - assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3'] - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2'] - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3'] - # - errors = meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_default=True) - assert len(errors) == 0 - assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] - - -def test_meta_force_dont_change_value(): - ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) - netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) - interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) - od = OptionDescription('root', '', [interface1]) - conf1 = Config(od, name='conf1') - conf2 = Config(od, name='conf2') - meta = MetaConfig([conf1, conf2]) - meta.property.read_write() - meta.owner.set('meta1') - assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - newconf1 = meta.config('conf1') - newconf2 = meta.config('conf2') - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.4']) - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault() - errors = meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_dont_change_value=True) - assert len(errors) == 0 - assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user - - -def test_meta_force_default_if_same(): - ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) - netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) - interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) - od = OptionDescription('root', '', [interface1]) - conf1 = Config(od, name='conf1') - conf2 = Config(od, name='conf2') - meta = MetaConfig([conf1, conf2]) - meta.property.read_write() - meta.owner.set('meta1') - # - newconf1 = meta.config('conf1') - newconf2 = meta.config('conf2') - assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - # - newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.4']) - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault() - errors = meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_default_if_same=True) - assert len(errors) == 0 - assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.meta1 - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.meta1 - # - newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.3']) - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3'] - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.meta1 - errors = meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.5'], force_default_if_same=True) - assert len(errors) == 0 - assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.5'] - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3'] - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.5'] - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.meta1 - - -def test_meta_force_default_if_same_and_dont_change(): - ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) - netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) - interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) - od = OptionDescription('root', '', [interface1]) - conf1 = Config(od, name='conf1') - conf2 = Config(od, name='conf2') - meta = MetaConfig([conf1, conf2]) - meta.property.read_write() - meta.owner.set('meta1') - # - newconf1 = meta.config('conf1') - newconf2 = meta.config('conf2') - assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - # - newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.4']) - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault() - errors = meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_default_if_same=True, force_dont_change_value=True) - assert len(errors) == 0 - assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.meta1 - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user - # - newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.3']) - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3'] - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user - errors = meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.5'], force_default_if_same=True, force_dont_change_value=True) - assert len(errors) == 0 - assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.5'] - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3'] - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user - - -def test_meta_force_default_and_dont_change(): - ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) - netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) - interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) - od = OptionDescription('root', '', [interface1]) - conf1 = Config(od, name='rconf1') - conf2 = Config(od, name='rconf2') - meta = MetaConfig([conf1, conf2]) - meta.property.read_write() - meta.owner.set('meta1') - with pytest.raises(ValueError): - meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_default=True, force_dont_change_value=True) - - -def test_meta_properties_meta(): - ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) - netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, validators=[Calculation(valid_network_netmask, Params((ParamOption(ip_admin_eth0), ParamSelfOption())))]) - interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0], properties=('disabled',)) - od = OptionDescription('root', '', [interface1]) - conf1 = Config(od, name='conf1') - conf2 = Config(od, name='conf2') - conf1.property.read_write() - conf2.property.read_write() - meta = MetaConfig([conf1, conf2]) - meta.property.read_write() - ret = meta.config('conf1') - assert ret.value.dict() == {} - - -def test_meta_exception_meta(): - ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) - netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", Calculation(raise_exception), multi=True, validators=[Calculation(valid_network_netmask, Params((ParamOption(ip_admin_eth0), ParamSelfOption())))]) - interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) - od = OptionDescription('root', '', [interface1]) - conf1 = Config(od, name='conf1') - conf2 = Config(od, name='conf2') - meta = MetaConfig([conf1, conf2]) - meta.property.read_write() - with pytest.raises(Exception): - conf1.make_dict() - - -def test_meta_properties_requires1(): - opt1 = BoolOption('opt1', 'opt1', False) - opt2 = BoolOption('opt2', "") - disabled_property = Calculation(calc_value, - Params(ParamValue('disabled'), - kwargs={'condition': ParamOption(opt1), - 'expected': ParamValue(False)})) - od2 = OptionDescription('od2', "", [opt2], properties=(disabled_property,)) - opt3 = BoolOption('opt3', '', validators=[Calculation(valid_not_equal, Params((ParamSelfOption(), ParamOption(opt2))))]) - od = OptionDescription('root', '', [opt1, od2, opt3]) - conf1 = Config(od, name='conf1') - conf1.property.read_write() - meta = MetaConfig([conf1], 'meta') - meta.property.read_write() - meta.option('opt1').value.set(True) - # - conf1.option('od2.opt2').value.set(False) - - -def test_meta_properties_requires_mandatory(): - probes = BoolOption('probes', 'probes available', False) - eth0_method = ChoiceOption('eth0_method', '', ('static', 'dhcp'), 'static') - ip_address = IPOption('ip_address', '') - mandatory_property = Calculation(calc_value, - Params(ParamValue('mandatory'), - kwargs={'condition': ParamOption(probes), - 'expected': ParamValue('yes'), - 'default': ParamValue(None)})) - ip_eth0 = IPOption('ip_eth0', "ip", Calculation(return_condition, Params(kwargs={'val': ParamOption(ip_address), 'condition': ParamOption(eth0_method), 'expected': ParamValue('dhcp')})), properties=(mandatory_property,)) - ip_gw = IPOption('ip_gw', 'gw', validators=[Calculation(valid_not_equal, Params((ParamSelfOption(), ParamOption(ip_eth0))))]) - od = OptionDescription('root', '', [ip_gw, probes, eth0_method, ip_address, ip_eth0]) - conf1 = Config(od, name='conf1') - conf1.property.read_write() - meta = MetaConfig([conf1], 'meta') - # - meta.option('probes').value.set(True) - meta.option('ip_address').value.set('1.1.1.1') - meta.option('ip_gw').value.set('1.1.1.2') - conf1.option('eth0_method').value.set('dhcp') - conf1.property.read_only() - assert conf1.value.dict() == {'ip_gw': '1.1.1.2', 'probes': True, 'eth0_method': 'dhcp', 'ip_address': '1.1.1.1', 'ip_eth0': '1.1.1.1'} - - -def test_meta_callback(): - val1 = StrOption('val1', "", 'val') - val2 = StrOption('val2', "", Calculation(return_value, Params(ParamOption(val1)))) - val3 = StrOption('val3', "", Calculation(return_value, Params(ParamValue('yes')))) - val4 = StrOption('val4', "", Calculation(return_value, Params(kwargs={'value': ParamOption(val1)}))) - val5 = StrOption('val5', "", Calculation(return_value, Params(kwargs={'value': ParamValue('yes')}))) - maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4, val5]) - cfg = Config(maconfig, name='cfg') - meta = MetaConfig([cfg]) - meta.property.read_write() - newcfg = meta.config('cfg') - assert newcfg.value.dict() == {'val3': 'yes', 'val2': 'val', 'val1': 'val', 'val5': 'yes', 'val4': 'val'} - newcfg.option('val1').value.set('new') - assert newcfg.value.dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new'} - newcfg.option('val1').value.reset() - meta.option('val1').value.set('new') - assert newcfg.value.dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new'} - newcfg.option('val4').value.set('new1') - assert newcfg.value.dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new1'} - newcfg.option('val4').value.reset() - meta.option('val4').value.set('new1') - assert newcfg.value.dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new1'} - meta.option('val4').value.reset() - - -def test_meta_callback_follower(): - val = StrOption('val', "", default='val') - val1 = StrOption('val1', "", [Calculation(return_value, Params(ParamOption(val)))], multi=True) - val3 = StrOption('val2', "", Calculation(return_value, Params(ParamOption(val1))), multi=True) - val4 = StrOption('val3', "", Calculation(return_value, Params(ParamOption(val1))), multi=True) - interface1 = Leadership('val1', '', [val1, val3, val4]) - od = OptionDescription('root', '', [interface1]) - maconfig = OptionDescription('rootconfig', '', [val, interface1]) - conf1 = Config(maconfig, name='conf1') - meta = MetaConfig([conf1]) - meta.property.read_write() - assert conf1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val', 'val1.val2': 'val', 'val1.val3': 'val'}]} - # - conf1.option('val').value.set('val1') - assert conf1.value.dict() == {'val': 'val1', 'val1.val1': [{'val1.val1': 'val1', 'val1.val2': 'val1', 'val1.val3': 'val1'}]} - # - conf1.option('val').value.reset() - meta.option('val').value.set('val1') - assert conf1.value.dict() == {'val': 'val1', 'val1.val1': [{'val1.val1': 'val1', 'val1.val2': 'val1', 'val1.val3': 'val1'}]} - # - meta.option('val').value.reset() - conf1.option('val1.val2', 0).value.set('val2') - assert conf1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val', 'val1.val2': 'val2', 'val1.val3': 'val'}]} - # - conf1.option('val1.val2', 0).value.reset() - assert conf1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val', 'val1.val2': 'val', 'val1.val3': 'val'}]} - # - meta.option('val1.val2', 0).value.set('val2') - assert conf1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val', 'val1.val2': 'val2', 'val1.val3': 'val'}]} - # - meta.option('val1.val1').value.set(['val']) - assert conf1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val', 'val1.val2': 'val2', 'val1.val3': 'val'}]} - # - conf1.option('val1.val3', 0).value.set('val6') - assert conf1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val', 'val1.val2': 'val2', 'val1.val3': 'val6'}]} - # - meta.option('val1.val2', 0).value.reset() - conf1.option('val1.val3', 0).value.reset() - conf1.option('val1.val1').value.set(['val3']) - assert conf1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val3', 'val1.val2': 'val3', 'val1.val3': 'val3'}]} - # - conf1.option('val1.val1').value.reset() - assert conf1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val', 'val1.val2': 'val', 'val1.val3': 'val'}]} - # - meta.option('val1.val1').value.set(['val3']) - assert conf1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val3', 'val1.val2': 'val3', 'val1.val3': 'val3'}]} - # - conf1.option('val1.val2', 0).value.set('val2') - assert conf1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val3', 'val1.val2': 'val2', 'val1.val3': 'val3'}]} - # - meta.option('val1.val1').value.set(['val3', 'rah']) - assert conf1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val3', 'val1.val2': 'val2', 'val1.val3': 'val3'}, {'val1.val1': 'rah', 'val1.val2': 'rah', 'val1.val3': 'rah'}]} - # - meta.option('val1.val1').value.pop(1) - meta.option('val1.val1').value.set(['val4']) - assert conf1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val4', 'val1.val2': 'val2', 'val1.val3': 'val4'}]} - - -def test_meta_reset(): - ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) - netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) - interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) - od = OptionDescription('root', '', [interface1]) - conf1 = Config(od, name='conf1') - conf2 = Config(od, name='conf2') - meta = MetaConfig([conf1, conf2]) - meta.property.read_write() - meta.owner.set('meta1') - newconf1 = meta.config('conf1') - newconf2 = meta.config('conf2') - assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - errors = meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.1']) - assert len(errors) == 0 - assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] - newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2']) - assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2'] - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] - meta.value.reset('ip_admin_eth0.ip_admin_eth0') - assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - - -def test_meta_properties_meta_copy(): - ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) - netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, properties=('disabled',)) - interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) - conf1 = Config(interface1, name='conf1') - conf2 = Config(interface1, name='conf2') - conf1.property.read_write() - conf2.property.read_write() - meta = MetaConfig([conf1, conf2], name='meta1') - meta.property.read_write() - - newconf1 = meta.config('conf1') - newconf2 = meta.config('conf2') - conf3 = newconf1.config.copy(name='conf3') - meta2 = list(conf3.config.parents()) - assert len(meta2) == 1 - assert meta.config.name() == meta2[0].config.name() - - assert newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.1']} - assert newconf2.value.dict() == {'ip_admin_eth0': ['192.168.1.1']} - newconf3 = meta.config('conf3') - assert newconf3.value.dict() == {'ip_admin_eth0': ['192.168.1.1']} - meta.option('ip_admin_eth0').value.set(['192.168.1.2']) - assert newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.2']} - assert newconf2.value.dict() == {'ip_admin_eth0': ['192.168.1.2']} - assert newconf3.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 newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.3']} - assert newconf2.value.dict() == {'ip_admin_eth0': ['192.168.1.3']} - assert newconf3.value.dict() == {'ip_admin_eth0': ['192.168.1.3']} - - -def test_meta_properties_meta_deepcopy(): - ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) - netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, - properties=('disabled',)) - interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) - conf1 = Config(interface1, name='conf1') - conf2 = Config(interface1, name='conf2') - conf1.property.read_write() - conf2.property.read_write() - meta = MetaConfig([conf1, conf2]) - meta.permissive.add('hidden') - meta.property.read_write() - - newconf1 = meta.config('conf1') - newconf2 = meta.config('conf2') - meta2 = newconf1.config.deepcopy(name='conf3') - newconf3 = meta2.config('conf3') - assert meta != meta2 - assert meta.permissive.get() == meta2.permissive.get() - - assert newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.1']} - assert newconf2.value.dict() == {'ip_admin_eth0': ['192.168.1.1']} - assert newconf3.value.dict() == {'ip_admin_eth0': ['192.168.1.1']} - meta.option('ip_admin_eth0').value.set(['192.168.1.2']) - assert newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.2']} - assert newconf2.value.dict() == {'ip_admin_eth0': ['192.168.1.2']} - assert newconf3.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 newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.3']} - assert newconf2.value.dict() == {'ip_admin_eth0': ['192.168.1.3']} - assert newconf3.value.dict() == {'ip_admin_eth0': ['192.168.1.1']} - - -def test_meta_properties_meta_deepcopy_multi_parent(): - ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip") - netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask") - interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) - conf1 = Config(interface1, name='conf1') - conf2 = Config(interface1, name='conf2') - conf1.property.read_write() - conf2.property.read_write() - meta1 = MetaConfig([conf1, conf2], name='meta1') - meta1.permissive.add('hidden') - meta1.property.read_write() - - meta2 = MetaConfig(['name1', 'name2'], optiondescription=interface1, name='meta2') - meta2.config.add(conf1) - - meta1.option('ip_admin_eth0').value.set('192.168.1.1') - meta2.option('netmask_admin_eth0').value.set('255.255.255.0') - - assert meta1.value.dict() == {'ip_admin_eth0': '192.168.1.1', 'netmask_admin_eth0': None} - assert meta2.value.dict() == {'ip_admin_eth0': None, 'netmask_admin_eth0': '255.255.255.0'} - assert conf1.value.dict() == {'ip_admin_eth0': '192.168.1.1', 'netmask_admin_eth0': '255.255.255.0'} - assert conf2.value.dict() == {'ip_admin_eth0': '192.168.1.1', 'netmask_admin_eth0': None} - - copy_meta2 = conf1.config.deepcopy(name='copy_conf1', metaconfig_prefix='copy_') - assert copy_meta2.config.path() == 'copy_meta2' - copy_meta1 = copy_meta2.config('copy_meta1') - copy_conf1 = copy_meta1.config('copy_conf1') - assert copy_meta2.value.dict() == {'ip_admin_eth0': None, 'netmask_admin_eth0': '255.255.255.0'} - assert copy_conf1.value.dict() == {'ip_admin_eth0': '192.168.1.1', 'netmask_admin_eth0': '255.255.255.0'} - - -def test_meta_properties_submeta_deepcopy(): - ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) - netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, - properties=('disabled',)) - interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) - conf1 = Config(interface1, name='conf1') - conf1.property.read_write() - meta1 = MetaConfig([conf1], name='meta1') - meta2 = MetaConfig([meta1], name='meta2') - meta_copy = conf1.config.deepcopy(name='conf2', - metaconfig_prefix='copy_') - assert meta_copy.config.name() == 'copy_meta2' - newcopy = meta_copy.config('copy_meta1') - assert newcopy.config.name() == 'copy_meta1' - newcopy = newcopy.config('conf2') - assert newcopy.config.name() == 'conf2' - - -def test_meta_properties_copy_meta(): - ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) - netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, - properties=('disabled',)) - interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) - conf1 = Config(interface1, name='conf1') - conf1.property.read_write() - meta1 = MetaConfig([conf1], name='meta1') - meta2 = MetaConfig([meta1], name='meta2') - meta_copy = meta1.config.copy(name='meta3') - assert meta_copy.config.name() == 'meta3' - assert list(meta_copy.config.list()) == [] - - -def test_meta_properties_deepcopy_meta(): - ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) - netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, - properties=('disabled',)) - interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) - conf1 = Config(interface1, name='conf1') - conf1.property.read_write() - meta1 = MetaConfig([conf1], name='meta1') - meta2 = MetaConfig([meta1], name='meta2') - meta_copy = meta1.config.deepcopy(name='meta3', - metaconfig_prefix='copy_') - assert meta_copy.config.name() == 'copy_meta2' - newcopy = meta_copy.config('meta3') - assert newcopy.config.name() == 'meta3' - assert list(newcopy.config.list()) == [] - - -def test_meta_properties_submeta_deepcopy_owner(): - ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip") - netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask") - interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) - conf1 = Config(interface1, name='conf1') - conf1.owner.set('conf1_user') - conf1.property.read_write() - meta1 = MetaConfig([conf1], name='meta1') - meta1.owner.set('meta1_user') - meta2 = MetaConfig([meta1], name='meta2') - meta2.owner.set('meta2_user') - # - conf1.option('ip_admin_eth0').value.set('192.168.0.1') - assert conf1.option('ip_admin_eth0').owner.get() == 'conf1_user' - meta1.option('ip_admin_eth0').value.set('192.168.0.2') - assert meta1.option('ip_admin_eth0').owner.get() == 'meta1_user' - meta2.option('ip_admin_eth0').value.set('192.168.0.3') - assert meta2.option('ip_admin_eth0').owner.get() == 'meta2_user' - # - meta2_copy = conf1.config.deepcopy(name='conf2', - metaconfig_prefix='copy_') - meta2_copy.option('netmask_admin_eth0').value.set('255.255.255.255') - assert meta2_copy.option('ip_admin_eth0').value.get() == '192.168.0.3' - assert meta2_copy.option('ip_admin_eth0').owner.get() == 'meta2_user' - assert meta2_copy.option('netmask_admin_eth0').owner.get() == 'meta2_user' - # - meta1_copy = meta2_copy.config('copy_meta1') - meta1_copy.option('netmask_admin_eth0').value.set('255.255.255.255') - assert meta1_copy.option('ip_admin_eth0').value.get() == '192.168.0.2' - assert meta1_copy.option('ip_admin_eth0').owner.get() == 'meta1_user' - assert meta1_copy.option('netmask_admin_eth0').owner.get() == 'meta1_user' - # - conf2 = meta1_copy.config('conf2') - conf2.owner.set('conf2_user') - conf2.option('netmask_admin_eth0').value.set('255.255.255.255') - assert conf2.option('netmask_admin_eth0').owner.get() == 'conf2_user' - assert conf2.option('ip_admin_eth0').value.get() == '192.168.0.1' - assert conf2.option('ip_admin_eth0').owner.get() == 'conf1_user' - - -def test_meta_properties_meta_set_value(): - ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) - netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, properties=('disabled',)) - interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) - conf1 = Config(interface1, name='conf1') - conf2 = Config(interface1, name='conf2') - conf1.property.read_write() - conf2.property.read_write() - meta = MetaConfig([conf1, conf2]) - meta.property.read_write() - ret = meta.config('conf1') - assert ret.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) - assert isinstance(ret[1], PropertiesOptionError) - del ret[1] - del ret[0] - del ret - ret = meta.value.set('netmask_admin_eth0', ['255.255.255.255'], force_default=True) - assert len(ret) == 1 - assert isinstance(ret[0], PropertiesOptionError) - del ret[0] - del ret - ret = meta.value.set('netmask_admin_eth0', ['255.255.255.255'], force_dont_change_value=True) - assert len(ret) == 3 - assert isinstance(ret[0], PropertiesOptionError) - assert isinstance(ret[1], PropertiesOptionError) - assert isinstance(ret[2], PropertiesOptionError) - del ret[2] - del ret[1] - del ret[0] - del ret - ret = meta.value.set('netmask_admin_eth0', ['255.255.255.255'], force_default_if_same=True) - assert len(ret) == 1 - assert isinstance(ret[0], PropertiesOptionError) - del ret[0] - del ret - ret = meta.value.set('ip_admin_eth0', '255.255.255.255', only_config=True) - assert len(ret) == 2 - assert isinstance(ret[0], ValueError) - assert isinstance(ret[1], ValueError) - del ret[1] - del ret[0] - del ret - ret = meta.value.set('ip_admin_eth0', '255.255.255.255', force_default=True) - assert len(ret) == 1 - assert isinstance(ret[0], ValueError) - del ret[0] - del ret - ret = meta.value.set('ip_admin_eth0', '255.255.255.255', force_dont_change_value=True) - assert len(ret) == 1 - assert isinstance(ret[0], ValueError) - del ret[0] - del ret - ret = meta.value.set('ip_admin_eth0', '255.255.255.255', force_default_if_same=True) - assert len(ret) == 1 - assert isinstance(ret[0], ValueError) - del ret[0] - del ret - - -def test_metaconfig_force_metaconfig_on_freeze(): - dummy1 = StrOption('dummy1', 'doc dummy', default='default', properties=('force_metaconfig_on_freeze',)) - group = OptionDescription('group', '', [dummy1]) - cfg = Config(group, name='cfg') - cfg.owner.set(owners.config) - meta1 = MetaConfig([cfg], name='meta1') - meta1.owner.set(owners.meta1) - meta2 = MetaConfig([meta1], name='meta2') - meta2.owner.set(owners.meta2) - cfg.property.read_write() - - cfg.option('dummy1').property.add('frozen') - # - assert cfg.option('dummy1').value.get() == 'default' - assert cfg.option('dummy1').owner.get() == 'default' - # - meta2.option('dummy1').value.set('meta2') - # - assert cfg.option('dummy1').value.get() == 'meta2' - assert cfg.option('dummy1').owner.get() == 'meta2' - # - cfg.option('dummy1').property.remove('frozen') - cfg.option('dummy1').value.set('cfg') - cfg.option('dummy1').property.add('frozen') - # - assert cfg.option('dummy1').value.get() == 'meta2' - assert cfg.option('dummy1').owner.get() == 'meta2' - # - meta1.option('dummy1').value.set('meta1') - # - assert cfg.option('dummy1').value.get() == 'meta1' - assert cfg.option('dummy1').owner.get() == 'meta1' - # - cfg.option('dummy1').property.remove('frozen') - assert cfg.option('dummy1').value.get() == 'cfg' - assert cfg.option('dummy1').owner.get() == 'config' - - -def test_metaconfig_force_metaconfig_on_freeze_option(): - dummy1 = StrOption('dummy1', 'doc dummy', default='default') - dummy2 = StrOption('dummy2', 'doc dummy', default='default', properties=('force_default_on_freeze',)) - group = OptionDescription('group', '', [dummy1, dummy2]) - cfg = Config(group, name='cfg') - cfg.owner.set(owners.config) - meta1 = MetaConfig([cfg], name='meta1') - meta1.owner.set(owners.meta1) - meta2 = MetaConfig([meta1], name='meta2') - meta2.owner.set(owners.meta2) - cfg.property.read_write() - - cfg.option('dummy1').property.add('frozen') - cfg.option('dummy1').property.add('force_metaconfig_on_freeze') - cfg.option('dummy2').property.add('frozen') - # - assert cfg.option('dummy1').value.get() == 'default' - assert cfg.option('dummy1').owner.get() == 'default' - assert cfg.option('dummy2').value.get() == 'default' - assert cfg.option('dummy2').owner.get() == 'default' - # - meta2.option('dummy1').value.set('meta2') - meta2.option('dummy2').value.set('meta2') - # - assert cfg.option('dummy1').value.get() == 'meta2' - assert cfg.option('dummy1').owner.get() == 'meta2' - assert cfg.option('dummy2').value.get() == 'default' - assert cfg.option('dummy2').owner.get() == 'default' - # - cfg.option('dummy1').property.remove('frozen') - cfg.option('dummy2').property.remove('frozen') - cfg.option('dummy1').value.set('cfg') - cfg.option('dummy2').value.set('cfg') - cfg.option('dummy1').property.add('frozen') - cfg.option('dummy2').property.add('frozen') - # - assert cfg.option('dummy1').value.get() == 'meta2' - assert cfg.option('dummy1').owner.get() == 'meta2' - assert cfg.option('dummy2').value.get() == 'default' - assert cfg.option('dummy2').owner.get() == 'default' - # - meta1.option('dummy1').value.set('meta1') - meta1.option('dummy2').value.set('meta1') - # - assert cfg.option('dummy1').value.get() == 'meta1' - assert cfg.option('dummy1').owner.get() == 'meta1' - assert cfg.option('dummy2').value.get() == 'default' - assert cfg.option('dummy2').owner.get() == 'default' - # - meta1.option('dummy1').property.add('force_metaconfig_on_freeze') - assert cfg.option('dummy1').value.get() == 'meta2' - assert cfg.option('dummy1').owner.get() == 'meta2' - # - meta2.option('dummy1').property.add('force_metaconfig_on_freeze') - assert cfg.option('dummy1').value.get() == 'default' - assert cfg.option('dummy1').owner.get() == 'default' - # - meta1.option('dummy1').property.remove('force_metaconfig_on_freeze') - assert cfg.option('dummy1').value.get() == 'meta1' - assert cfg.option('dummy1').owner.get() == 'meta1' - # - cfg.option('dummy1').property.remove('frozen') - assert cfg.option('dummy1').value.get() == 'cfg' - assert cfg.option('dummy1').owner.get() == 'config' - - -def test_meta_get_config(): - od = make_description() - meta = MetaConfig(['name1', 'name2'], optiondescription=od) - meta.config.new('meta1', type='metaconfig') - assert isinstance(meta.config('meta1'), MetaConfig) - assert isinstance(meta.config('name1'), Config) - with pytest.raises(ConfigError): - meta.config('unknown') +#def test_unknown_config(): +# meta = make_metaconfig() +# with pytest.raises(ConfigError): +# meta.config('unknown') +# +# +#def test_error_metaconfig(): +# od2 = make_description() +# conf1 = Config(od2, name='conf1') +# with pytest.raises(TypeError): +# MetaConfig([GroupConfig([conf1])], name='meta') +# +# +#def test_path(): +# meta = make_metaconfig() +# assert meta.config.path() == 'meta' +# ret = meta.config('conf1') +# assert ret.config.path() == 'meta.conf1' +# ret = meta.config('conf2') +# assert ret.config.path() == 'meta.conf2' +# +# +#def test_none(): +# meta = make_metaconfig() +# conf1 = meta.config('conf1') +# conf2 = meta.config('conf2') +# assert meta.option('od1.i3').value.get() is conf1.option('od1.i3').value.get() is conf2.option('od1.i3').value.get() is None +# assert meta.option('od1.i3').owner.get() is conf1.option('od1.i3').owner.get() is conf2.option('od1.i3').owner.get() is owners.default +# # +# assert meta.option('od1.i3').value.set(3) == [] +# assert meta.option('od1.i3').value.get() == conf1.option('od1.i3').value.get() == conf2.option('od1.i3').value.get() == 3 +# assert meta.option('od1.i3').owner.get() is conf1.option('od1.i3').owner.get() is conf2.option('od1.i3').owner.get() is owners.meta1 +# # +# conf1.option('od1.i3').value.set(2) +# assert meta.option('od1.i3').value.get() == conf2.option('od1.i3').value.get() == 3 +# assert conf1.option('od1.i3').value.get() == 2 +# assert meta.option('od1.i3').owner.get() is conf2.option('od1.i3').owner.get() is owners.meta1 +# assert conf1.option('od1.i3').owner.get() is owners.user +# # +# meta.option('od1.i3').value.set(4) +# assert meta.option('od1.i3').value.get() == conf2.option('od1.i3').value.get() == 4 +# assert conf1.option('od1.i3').value.get() == 2 +# assert meta.option('od1.i3').owner.get() is conf2.option('od1.i3').owner.get() is owners.meta1 +# assert conf1.option('od1.i3').owner.get() is owners.user +# # +# meta.option('od1.i3').value.reset() +# assert meta.option('od1.i3').value.get() is conf2.option('od1.i3').value.get() is None +# assert conf1.option('od1.i3').value.get() == 2 +# assert meta.option('od1.i3').owner.get() is conf2.option('od1.i3').owner.get() is owners.default +# assert conf1.option('od1.i3').owner.get() is owners.user +# # +# conf1.option('od1.i3').value.reset() +# assert meta.option('od1.i3').value.get() is conf1.option('od1.i3').value.get() is conf2.option('od1.i3').value.get() is None +# assert meta.option('od1.i3').owner.get() is conf1.option('od1.i3').owner.get() is conf2.option('od1.i3').owner.get() is owners.default +# +# +#def test_metaconfig_reset(config_type): +# meta = make_metaconfig() +# meta_api = get_config(meta, config_type) +# assert meta_api.option('od1.i2').value.get() == 1 +# meta_api.option('od1.i2').value.set(2) +# if config_type == 'tiramisu-api': +# meta_api.send() +# conf1 = meta.config('conf1') +# conf2 = meta.config('conf2') +# conf1.option('od1.i2').value.set(3) +# assert meta.option('od1.i2').value.get() == 2 +# assert conf1.option('od1.i2').value.get() == 3 +# assert conf2.option('od1.i2').value.get() == 2 +# meta.config.reset() +# assert meta.option('od1.i2').value.get() == 1 +# assert conf1.option('od1.i2').value.get() == 3 +# assert conf2.option('od1.i2').value.get() == 1 +# +# +#def test_default(): +# meta = make_metaconfig() +# conf1 = meta.config('conf1') +# conf2 = meta.config('conf2') +# assert meta.option('od1.i2').value.get() == conf1.option('od1.i2').value.get() == conf2.option('od1.i2').value.get() == 1 +# assert meta.option('od1.i2').owner.get() is conf1.option('od1.i2').owner.get() is conf2.option('od1.i2').owner.get() is owners.default +# # +# meta.option('od1.i2').value.set(3) +# assert meta.option('od1.i2').value.get() == conf1.option('od1.i2').value.get() == conf2.option('od1.i2').value.get() == 3 +# assert meta.option('od1.i2').owner.get() is conf1.option('od1.i2').owner.get() is conf2.option('od1.i2').owner.get() is owners.meta1 +# # +# conf1.option('od1.i2').value.set(2) +# assert meta.option('od1.i2').value.get() == conf2.option('od1.i2').value.get() == 3 +# assert conf1.option('od1.i2').value.get() == 2 +# assert meta.option('od1.i2').owner.get() is conf2.option('od1.i2').owner.get() is owners.meta1 +# assert conf1.option('od1.i2').owner.get() is owners.user +# # +# meta.option('od1.i2').value.set(4) +# assert meta.option('od1.i2').value.get() == conf2.option('od1.i2').value.get() == 4 +# assert conf1.option('od1.i2').value.get() == 2 +# assert meta.option('od1.i2').owner.get() is conf2.option('od1.i2').owner.get() is owners.meta1 +# assert conf1.option('od1.i2').owner.get() is owners.user +# # +# meta.option('od1.i2').value.reset() +# assert meta.option('od1.i2').value.get() == conf2.option('od1.i2').value.get() == 1 +# assert conf1.option('od1.i2').value.get() == 2 +# assert meta.option('od1.i2').owner.get() is conf2.option('od1.i2').owner.get() is owners.default +# assert conf1.option('od1.i2').owner.get() is owners.user +# # +# conf1.option('od1.i2').value.reset() +# assert meta.option('od1.i2').value.get() == conf1.option('od1.i2').value.get() == conf2.option('od1.i2').value.get() == 1 +# assert meta.option('od1.i2').owner.get() is conf1.option('od1.i2').owner.get() is conf2.option('od1.i2').owner.get() is owners.default +# +# +#def test_contexts(): +# meta = make_metaconfig() +# errors = meta.value.set('od1.i2', 6, only_config=True) +# assert len(errors) == 0 +# conf1 = meta.config('conf1') +# assert meta.option('od1.i2').value.get() == 1 +# assert meta.option('od1.i2').owner.get() == owners.default +# assert conf1.option('od1.i2').value.get() == conf1.option('od1.i2').value.get() == 6 +# assert conf1.option('od1.i2').owner.get() == conf1.option('od1.i2').owner.get() is owners.user +# +# +#def test_find(): +# meta = make_metaconfig() +# ret = list(meta.option.find('i2')) +# assert len(ret) == 1 +# assert 1 == ret[0].value.get() +# ret = meta.option.find('i2', first=True) +# assert 1 == ret.value.get() +# assert meta.value.dict() == {'od1.i4': 2, 'od1.i1': None, 'od1.i3': None, +# 'od1.i2': 1, 'od1.i5': [2]} +# +# +#def test_meta_meta(): +# meta = make_metaconfig(double=True) +# meta1 = meta.config('meta') +# conf1 = meta.config('meta.conf1') +# conf2 = meta.config('meta.conf2') +# assert meta.option('od1.i2').value.get() == meta1.option('od1.i2').value.get() == conf1.option('od1.i2').value.get() == conf2.option('od1.i2').value.get() == 1 +# assert meta.option('od1.i2').owner.get() is meta1.option('od1.i2').owner.get() is conf1.option('od1.i2').owner.get() is conf2.option('od1.i2').owner.get() is owners.default +# # +# meta.option('od1.i2').value.set(3) +# assert meta.option('od1.i2').value.get() == meta1.option('od1.i2').value.get() == conf1.option('od1.i2').value.get() == conf2.option('od1.i2').value.get() == 3 +# assert meta.option('od1.i2').owner.get() is meta1.option('od1.i2').owner.get() is conf1.option('od1.i2').owner.get() is conf2.option('od1.i2').owner.get() is owners.meta1 +# # +# conf1.option('od1.i2').value.set(2) +# assert meta.option('od1.i2').value.get() == meta1.option('od1.i2').value.get() == conf2.option('od1.i2').value.get() == 3 +# assert conf1.option('od1.i2').value.get() == 2 +# assert meta.option('od1.i2').owner.get() is meta1.option('od1.i2').owner.get() is conf2.option('od1.i2').owner.get() is owners.meta1 +# assert conf1.option('od1.i2').owner.get() is owners.user +# # +# meta1.option('od1.i2').value.set(4) +# assert meta.option('od1.i2').value.get() == 3 +# assert meta1.option('od1.i2').value.get() == conf2.option('od1.i2').value.get() == 4 +# assert conf1.option('od1.i2').value.get() == 2 +# assert meta.option('od1.i2').owner.get() is owners.meta1 +# assert meta1.option('od1.i2').owner.get() is conf2.option('od1.i2').owner.get() is owners.meta2 +# assert conf1.option('od1.i2').owner.get() is owners.user +# # +# meta1.option('od1.i2').value.reset() +# assert meta.option('od1.i2').value.get() == meta1.option('od1.i2').value.get() == conf2.option('od1.i2').value.get() == 3 +# assert conf1.option('od1.i2').value.get() == 2 +# assert meta.option('od1.i2').owner.get() is meta1.option('od1.i2').owner.get() is conf2.option('od1.i2').owner.get() is owners.meta1 +# assert conf1.option('od1.i2').owner.get() is owners.user +# # +# meta.option('od1.i2').value.reset() +# assert meta.option('od1.i2').value.get() == meta1.option('od1.i2').value.get() == conf2.option('od1.i2').value.get() == 1 +# assert conf1.option('od1.i2').value.get() == 2 +# assert meta.option('od1.i2').owner.get() is meta1.option('od1.i2').owner.get() is conf2.option('od1.i2').owner.get() is owners.default +# assert conf1.option('od1.i2').owner.get() is owners.user +# # +# conf1.option('od1.i2').value.reset() +# assert meta.option('od1.i2').value.get() == meta1.option('od1.i2').value.get() == conf1.option('od1.i2').value.get() == conf2.option('od1.i2').value.get() == 1 +# assert meta.option('od1.i2').owner.get() is meta1.option('od1.i2').owner.get() is conf1.option('od1.i2').owner.get() is conf2.option('od1.i2').owner.get() is owners.default +# +# +#def test_meta_new_config(): +# od = make_description() +# meta = MetaConfig(['name1', 'name2'], optiondescription=od) +# assert len(list(meta.config.list())) == 2 +# meta.config.new('newconf1') +# assert len(list(meta.config.list())) == 3 +# +# +#def test_meta_new_config_owner(): +# od = make_description() +# meta = MetaConfig(['name1', 'name2'], optiondescription=od) +# meta.owner.set('meta') +# meta.config.new('newconf1') +# assert meta.owner.get() == 'meta' +# +# +#def test_meta_new_metaconfig(): +# od = make_description() +# meta = MetaConfig(['name1', 'name2'], optiondescription=od) +# meta.config.new('newconf1', type='metaconfig') +# newconf1 = meta.config('newconf1') +# newconf1.config.new('newconf2', type='metaconfig') +# newconf2 = newconf1.config('newconf2') +# newconf2.config.new('newconf3') +# newconf3 = newconf2.config('newconf3') +# assert newconf3.config.name() == 'newconf3' +# +# +#def test_meta_pop_config(): +# od = make_description() +# meta = MetaConfig(['name1', 'name2'], optiondescription=od) +# meta.option('od1.i1').value.set(2) +# # +# assert len(list(meta.config.list())) == 2 +# meta.config.new('newconf1') +# newconf1 = meta.config('newconf1') +# assert newconf1.value.dict() == {'od1.i1': 2, 'od1.i2': 1, 'od1.i3': None, 'od1.i4': 2, 'od1.i5': [2], 'od1.i6': None} +# # +# assert len(list(meta.config.list())) == 3 +# newconf1 = meta.config.remove('newconf1') +# try: +# meta.config('newconf1') +# except ConfigError: +# pass +# else: +# raise Exception('must raise') +# assert newconf1.value.dict() == {'od1.i1': None, 'od1.i2': 1, 'od1.i3': None, 'od1.i4': 2, 'od1.i5': [2], 'od1.i6': None} +# # +# assert len(list(meta.config.list())) == 2 +# with pytest.raises(ConfigError): +# meta.config.remove('newconf1') +# +# +#def test_meta_add_config(): +# od = make_description() +# od2 = make_description() +# meta = MetaConfig(['name1', 'name2'], optiondescription=od) +# meta.option('od1.i1').value.set(2) +# # +# assert len(list(meta.config.list())) == 2 +# config = Config(od, name='new') +# assert config.value.dict() == {'od1.i1': None, 'od1.i2': 1, 'od1.i3': None, 'od1.i4': 2, 'od1.i5': [2], 'od1.i6': None} +# meta.config.add(config) +# # +# assert len(list(meta.config.list())) == 3 +# assert config.value.dict() == {'od1.i1': 2, 'od1.i2': 1, 'od1.i3': None, 'od1.i4': 2, 'od1.i5': [2], 'od1.i6': None} +# # +# with pytest.raises(ConflictError): +# meta.config.add(config) +# newconfig = Config(od2) +# with pytest.raises(ValueError): +# meta.config.add(newconfig) +# +# +#def test_meta_add_config_not_name(): +# od = make_description() +# od2 = make_description() +# meta = MetaConfig(['name1', 'name2'], optiondescription=od) +# meta.option('od1.i1').value.set(2) +# # +# assert len(list(meta.config.list())) == 2 +# config = Config(od) +# with pytest.raises(ConfigError): +# meta.config.add(config) +# +# +#def test_meta_add_config_readd(): +# od = make_description() +# meta = MetaConfig([], optiondescription=od) +# meta2 = MetaConfig([], optiondescription=od) +# config = Config(od, name='new') +# # +# meta.config.add(config) +# meta2.config.add(config) +# assert len(list(config.config.parents())) == 2 +# +# +#def test_meta_new_config_wrong_name(): +# od = make_description() +# meta = MetaConfig(['name1', 'name2'], optiondescription=od) +# assert len(list(meta.config.list())) == 2 +# with pytest.raises(ConflictError): +# meta.config.new('name1') +# assert len(list(meta.config.list())) == 2 +# +# +#def test_meta_load_config(): +# od = make_description() +# meta = MetaConfig(['name1', 'name2'], optiondescription=od) +# assert len(list(meta.config.list())) == 2 +# meta.config('name1') +# +# +#def test_meta_load_config_wrong_name(): +# od = make_description() +# meta = MetaConfig(['name1', 'name2'], optiondescription=od) +# assert len(list(meta.config.list())) == 2 +# with pytest.raises(ConfigError): +# meta.config('name3') +# +# +#def test_meta_meta_set(): +# meta = make_metaconfig(double=True) +# errors1 = meta.value.set('od1.i1', 7, only_config=True) +# errors2 = meta.value.set('od1.i6', 7, only_config=True) +# assert len(errors1) == 0 +# assert len(errors2) == 2 +# conf1 = meta.config('meta.conf1') +# conf2 = meta.config('meta.conf2') +# assert conf1.option('od1.i1').value.get() == conf2.option('od1.i1').value.get() == 7 +# # +# dconfigs = [] +# ret = meta.config.find('i1', value=7) +# for conf in ret.config.list(): +# dconfigs.append(conf._config_bag.context) +# assert [conf1._config_bag.context, conf2._config_bag.context] == dconfigs +# conf1.option('od1.i1').value.set(8) +# # +# dconfigs = [] +# ret = meta.config.find('i1') +# for conf in ret.config.list(): +# dconfigs.append(conf._config_bag.context) +# assert [conf1._config_bag.context, conf2._config_bag.context] == dconfigs +# ret = meta.config.find('i1', value=7) +# assert len(ret.config.list()) == 1 +# assert conf2._config_bag.context == list(ret.config.list())[0]._config_bag.context +# +# ret = meta.config.find('i1', value=8) +# assert len(ret.config.list()) == 1 +# assert conf1._config_bag.context == list(ret.config.list())[0]._config_bag.context +# # +# dconfigs = [] +# ret = meta.config.find('i5', value=2) +# for conf in ret.config.list(): +# dconfigs.append(conf._config_bag.context) +# assert [conf1._config_bag.context, conf2._config_bag.context] == dconfigs +# # +# with pytest.raises(AttributeError): +# meta.config.find('i1', value=10) +# with pytest.raises(AttributeError): +# meta.config.find('not', value=10) +# with pytest.raises(AttributeError): +# meta.config.find('i6') +# with pytest.raises(ValueError): +# meta.value.set('od1.i6', 7, only_config=True, force_default=True) +# with pytest.raises(ValueError): +# meta.value.set('od1.i6', 7, only_config=True, force_default_if_same=True) +# with pytest.raises(ValueError): +# meta.value.set('od1.i6', 7, only_config=True, force_dont_change_value=True) +# +# +#def test_not_meta(): +# i1 = IntOption('i1', '') +# od1 = OptionDescription('od1', '', [i1]) +# od2 = OptionDescription('od2', '', [od1]) +# conf1 = Config(od2, name='conf1') +# conf2 = Config(od2, name='conf2') +# conf3 = Config(od2) +# conf4 = Config(od2, name='conf4') +# with pytest.raises(TypeError): +# GroupConfig(conf1) +# with pytest.raises(ConflictError): +# GroupConfig([conf2, conf2], name='conf8') +# grp = GroupConfig([conf1, conf2]) +# assert grp.config.type() == 'groupconfig' +# with pytest.raises(ConfigError): +# grp.option('od1.i1').value.get() +# conf1, conf2 = grp.config.list() +# errors = grp.value.set('od1.i1', 7) +# assert len(errors) == 0 +# conf1 = grp.config('conf1') +# conf2 = grp.config('conf2') +# assert conf1.option('od1.i1').value.get() == conf2.option('od1.i1').value.get() == 7 +# assert conf1.option('od1.i1').owner.get() is conf2.option('od1.i1').owner.get() is owners.user +# grp.option('od1.i1').value.reset() +# assert conf1.option('od1.i1').owner.get() is conf2.option('od1.i1').owner.get() is owners.default +# +# +#def test_group_find_firsts(): +# i1 = IntOption('i1', '') +# od1 = OptionDescription('od1', '', [i1]) +# od2 = OptionDescription('od2', '', [od1]) +# conf1 = Config(od2, name='conf1') +# conf2 = Config(od2, name='conf2') +# grp = GroupConfig([conf1, conf2]) +# ret = grp.config.find('i1') +# newconf1, newconf2 = grp.config.list() +# conf1._config_bag.context == newconf1._config_bag.context +# conf2._config_bag.context == newconf2._config_bag.context +# +# +#def test_group_group(): +# i1 = IntOption('i1', '') +# od1 = OptionDescription('od1', '', [i1]) +# od2 = OptionDescription('od2', '', [od1]) +# conf1 = Config(od2, name='conf9') +# conf2 = Config(od2, name='conf10') +# grp = GroupConfig([conf1, conf2], 'grp') +# grp2 = GroupConfig([grp]) +# errors = grp2.value.set('od1.i1', 2) +# assert len(errors) == 0 +# conf9 = grp2.config('grp.conf9') +# assert conf9.option('od1.i1').value.get() == 2 +# assert conf9.option('od1.i1').owner.get() is owners.user +# +# +#def test_group_group_path(): +# i1 = IntOption('i1', '') +# od1 = OptionDescription('od1', '', [i1]) +# od2 = OptionDescription('od2', '', [od1]) +# conf1 = Config(od2, name='conf9') +# conf2 = Config(od2, name='conf10') +# grp = GroupConfig([conf1, conf2], 'grp') +# grp2 = GroupConfig([grp], 'grp2') +# assert grp2.config.path() == 'grp2' +# newgrp = grp2.config('grp') +# assert newgrp.config.path() == 'grp' +# newgrp = grp2.config('grp.conf9') +# assert newgrp.config.path() == 'conf9' +# newgrp = grp2.config('grp.conf10') +# assert newgrp.config.path() == 'conf10' +# +# +#def test_meta_unconsistent(): +# i1 = IntOption('i1', '') +# i2 = IntOption('i2', '', default=1) +# i3 = IntOption('i3', '') +# i4 = IntOption('i4', '', default=2) +# od1 = OptionDescription('od1', '', [i1, i2, i3, i4]) +# od2 = OptionDescription('od2', '', [od1]) +# i5 = IntOption('i5', '') +# od3 = OptionDescription('od3', '', [i5]) +# conf1 = Config(od2, name='conf1') +# conf2 = Config(od2, name='conf2') +# conf3 = Config(od2, name='conf3') +# conf4 = Config(od3, name='conf4') +# meta = MetaConfig([conf1, conf2]) +# meta.owner.set(owners.meta1) +# with pytest.raises(TypeError): +# MetaConfig("string") +# #same descr but conf1 already in meta +# assert len(list(conf1.config.parents())) == 1 +# assert len(list(conf3.config.parents())) == 0 +# new_meta = MetaConfig([conf1, conf3]) +# assert len(list(conf1.config.parents())) == 2 +# assert len(list(conf3.config.parents())) == 1 +# #not same descr +# with pytest.raises(ValueError): +# MetaConfig([conf3, conf4]) +# +# +#def test_meta_leadership(): +# ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) +# netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) +# interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) +# od = OptionDescription('root', '', [interface1]) +# conf1 = Config(od, name='conf1') +# conf2 = Config(od, name='conf2') +# meta = MetaConfig([conf1, conf2]) +# meta.property.read_only() +# ret = meta.config.find('ip_admin_eth0') +# configs = ret.config.list() +# assert len(configs) == 2 +# assert conf1._config_bag.context == configs[0]._config_bag.context +# assert conf2._config_bag.context == configs[1]._config_bag.context +# ret = meta.config.find('netmask_admin_eth0') +# configs = ret.config.list() +# assert len(configs) == 2 +# assert conf1._config_bag.context == configs[0]._config_bag.context +# assert conf2._config_bag.context == configs[1]._config_bag.context +# meta.property.read_write() +# with pytest.raises(AttributeError): +# meta.config.find('netmask_admin_eth0') +# ret = meta.unrestraint.config.find('netmask_admin_eth0') +# configs = ret.config.list() +# assert conf1._config_bag.context == configs[0]._config_bag.context +# assert conf2._config_bag.context == configs[1]._config_bag.context +# meta.property.read_only() +# ret = meta.config.find('netmask_admin_eth0') +# configs = ret.config.list() +# assert conf1._config_bag.context == configs[0]._config_bag.context +# assert conf2._config_bag.context == configs[1]._config_bag.context +# +# +#def test_meta_leadership_value(): +# ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) +# netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) +# interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) +# od = OptionDescription('root', '', [interface1]) +# conf1 = Config(od, name='conf1') +# conf2 = Config(od, name='conf2') +# meta = MetaConfig([conf1, conf2], name="meta") +# conf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.8']) +# assert conf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None +# with pytest.raises(ConfigError): +# conf1.option('ip_admin_eth0.ip_admin_eth0', 0).value.get() +# # +# conf1.option('ip_admin_eth0.ip_admin_eth0').value.reset() +# # +# meta.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) +# assert conf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None +# meta.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0') +# assert conf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0' +# meta.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.0.0') +# assert conf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0' +# # +# conf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) +# assert conf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0' +# # +# meta.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.2.1', '192.168.3.1']) +# meta.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.0') +# # +# assert conf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] +# assert conf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0' +# +# +#def test_meta_leadership_value_default(): +# ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) +# netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True) +# interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) +# od = OptionDescription('root', '', [interface1]) +# conf1 = Config(od, name='conf1') +# conf2 = Config(od, name='conf2') +# meta = MetaConfig([conf1, conf2]) +# newconf1 = meta.config('conf1') +# assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None +# # +# meta.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) +# assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None +# # +# meta.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0') +# assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0' +# # +# meta.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.0.0') +# assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0' +# # +# newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) +# assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0' +# +# +#def test_meta_leadership_owners(): +# ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) +# netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) +# interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) +# od = OptionDescription('root', '', [interface1]) +# conf1 = Config(od, name='conf1') +# conf2 = Config(od, name='conf2') +# meta = MetaConfig([conf1, conf2]) +# meta.owner.set(owners.meta1) +# newconf1 = meta.config('conf1') +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault() +# with pytest.raises(LeadershipError): +# newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault() +# # +# newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.user +# assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault() +# # +# newconf1.option('ip_admin_eth0.ip_admin_eth0').value.reset() +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault() +# # +# meta.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.meta1 +# assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault() +# # +# meta.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0') +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.meta1 +# assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.meta1 +# # +# meta.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.0.0') +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.meta1 +# assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.meta1 +# # +# newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.user +# assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.meta1 +# +# +#def test_meta_force_default(): +# ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) +# netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) +# interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) +# od = OptionDescription('root', '', [interface1]) +# conf1 = Config(od, name='conf1') +# conf2 = Config(od, name='conf2') +# meta = MetaConfig([conf1, conf2]) +# meta.property.read_write() +# meta.owner.set('meta1') +# newconf1 = meta.config('conf1') +# newconf2 = meta.config('conf2') +# assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# # +# errors = meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.1']) +# assert len(errors) == 0 +# assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] +# # +# newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2']) +# assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2'] +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] +# # +# errors = meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.3']) +# assert len(errors) == 0 +# assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3'] +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2'] +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3'] +# # +# errors = meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_default=True) +# assert len(errors) == 0 +# assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] +# +# +#def test_meta_force_dont_change_value(): +# ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) +# netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) +# interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) +# od = OptionDescription('root', '', [interface1]) +# conf1 = Config(od, name='conf1') +# conf2 = Config(od, name='conf2') +# meta = MetaConfig([conf1, conf2]) +# meta.property.read_write() +# meta.owner.set('meta1') +# assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# newconf1 = meta.config('conf1') +# newconf2 = meta.config('conf2') +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.4']) +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault() +# errors = meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_dont_change_value=True) +# assert len(errors) == 0 +# assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user +# +# +#def test_meta_force_default_if_same(): +# ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) +# netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) +# interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) +# od = OptionDescription('root', '', [interface1]) +# conf1 = Config(od, name='conf1') +# conf2 = Config(od, name='conf2') +# meta = MetaConfig([conf1, conf2]) +# meta.property.read_write() +# meta.owner.set('meta1') +# # +# newconf1 = meta.config('conf1') +# newconf2 = meta.config('conf2') +# assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# # +# newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.4']) +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault() +# errors = meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_default_if_same=True) +# assert len(errors) == 0 +# assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.meta1 +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.meta1 +# # +# newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.3']) +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3'] +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.meta1 +# errors = meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.5'], force_default_if_same=True) +# assert len(errors) == 0 +# assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.5'] +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3'] +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.5'] +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.meta1 +# +# +#def test_meta_force_default_if_same_and_dont_change(): +# ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) +# netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) +# interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) +# od = OptionDescription('root', '', [interface1]) +# conf1 = Config(od, name='conf1') +# conf2 = Config(od, name='conf2') +# meta = MetaConfig([conf1, conf2]) +# meta.property.read_write() +# meta.owner.set('meta1') +# # +# newconf1 = meta.config('conf1') +# newconf2 = meta.config('conf2') +# assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# # +# newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.4']) +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault() +# errors = meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_default_if_same=True, force_dont_change_value=True) +# assert len(errors) == 0 +# assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.meta1 +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user +# # +# newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.3']) +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3'] +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user +# errors = meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.5'], force_default_if_same=True, force_dont_change_value=True) +# assert len(errors) == 0 +# assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.5'] +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3'] +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user +# +# +#def test_meta_force_default_and_dont_change(): +# ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) +# netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) +# interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) +# od = OptionDescription('root', '', [interface1]) +# conf1 = Config(od, name='rconf1') +# conf2 = Config(od, name='rconf2') +# meta = MetaConfig([conf1, conf2]) +# meta.property.read_write() +# meta.owner.set('meta1') +# with pytest.raises(ValueError): +# meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_default=True, force_dont_change_value=True) +# +# +#def test_meta_properties_meta(): +# ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) +# netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, validators=[Calculation(valid_network_netmask, Params((ParamOption(ip_admin_eth0), ParamSelfOption())))]) +# interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0], properties=('disabled',)) +# od = OptionDescription('root', '', [interface1]) +# conf1 = Config(od, name='conf1') +# conf2 = Config(od, name='conf2') +# conf1.property.read_write() +# conf2.property.read_write() +# meta = MetaConfig([conf1, conf2]) +# meta.property.read_write() +# ret = meta.config('conf1') +# assert ret.value.dict() == {} +# +# +#def test_meta_exception_meta(): +# ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) +# netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", Calculation(raise_exception), multi=True, validators=[Calculation(valid_network_netmask, Params((ParamOption(ip_admin_eth0), ParamSelfOption())))]) +# interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) +# od = OptionDescription('root', '', [interface1]) +# conf1 = Config(od, name='conf1') +# conf2 = Config(od, name='conf2') +# meta = MetaConfig([conf1, conf2]) +# meta.property.read_write() +# with pytest.raises(Exception): +# conf1.make_dict() +# +# +#def test_meta_properties_requires1(): +# opt1 = BoolOption('opt1', 'opt1', False) +# opt2 = BoolOption('opt2', "") +# disabled_property = Calculation(calc_value, +# Params(ParamValue('disabled'), +# kwargs={'condition': ParamOption(opt1), +# 'expected': ParamValue(False)})) +# od2 = OptionDescription('od2', "", [opt2], properties=(disabled_property,)) +# opt3 = BoolOption('opt3', '', validators=[Calculation(valid_not_equal, Params((ParamSelfOption(), ParamOption(opt2))))]) +# od = OptionDescription('root', '', [opt1, od2, opt3]) +# conf1 = Config(od, name='conf1') +# conf1.property.read_write() +# meta = MetaConfig([conf1], 'meta') +# meta.property.read_write() +# meta.option('opt1').value.set(True) +# # +# conf1.option('od2.opt2').value.set(False) +# +# +#def test_meta_properties_requires_mandatory(): +# probes = BoolOption('probes', 'probes available', False) +# eth0_method = ChoiceOption('eth0_method', '', ('static', 'dhcp'), 'static') +# ip_address = IPOption('ip_address', '') +# mandatory_property = Calculation(calc_value, +# Params(ParamValue('mandatory'), +# kwargs={'condition': ParamOption(probes), +# 'expected': ParamValue('yes'), +# 'default': ParamValue(None)})) +# ip_eth0 = IPOption('ip_eth0', "ip", Calculation(return_condition, Params(kwargs={'val': ParamOption(ip_address), 'condition': ParamOption(eth0_method), 'expected': ParamValue('dhcp')})), properties=(mandatory_property,)) +# ip_gw = IPOption('ip_gw', 'gw', validators=[Calculation(valid_not_equal, Params((ParamSelfOption(), ParamOption(ip_eth0))))]) +# od = OptionDescription('root', '', [ip_gw, probes, eth0_method, ip_address, ip_eth0]) +# conf1 = Config(od, name='conf1') +# conf1.property.read_write() +# meta = MetaConfig([conf1], 'meta') +# # +# meta.option('probes').value.set(True) +# meta.option('ip_address').value.set('1.1.1.1') +# meta.option('ip_gw').value.set('1.1.1.2') +# conf1.option('eth0_method').value.set('dhcp') +# conf1.property.read_only() +# assert conf1.value.dict() == {'ip_gw': '1.1.1.2', 'probes': True, 'eth0_method': 'dhcp', 'ip_address': '1.1.1.1', 'ip_eth0': '1.1.1.1'} +# +# +#def test_meta_callback(): +# val1 = StrOption('val1', "", 'val') +# val2 = StrOption('val2', "", Calculation(return_value, Params(ParamOption(val1)))) +# val3 = StrOption('val3', "", Calculation(return_value, Params(ParamValue('yes')))) +# val4 = StrOption('val4', "", Calculation(return_value, Params(kwargs={'value': ParamOption(val1)}))) +# val5 = StrOption('val5', "", Calculation(return_value, Params(kwargs={'value': ParamValue('yes')}))) +# maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4, val5]) +# cfg = Config(maconfig, name='cfg') +# meta = MetaConfig([cfg]) +# meta.property.read_write() +# newcfg = meta.config('cfg') +# assert newcfg.value.dict() == {'val3': 'yes', 'val2': 'val', 'val1': 'val', 'val5': 'yes', 'val4': 'val'} +# newcfg.option('val1').value.set('new') +# assert newcfg.value.dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new'} +# newcfg.option('val1').value.reset() +# meta.option('val1').value.set('new') +# assert newcfg.value.dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new'} +# newcfg.option('val4').value.set('new1') +# assert newcfg.value.dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new1'} +# newcfg.option('val4').value.reset() +# meta.option('val4').value.set('new1') +# assert newcfg.value.dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new1'} +# meta.option('val4').value.reset() +# +# +#def test_meta_callback_follower(): +# val = StrOption('val', "", default='val') +# val1 = StrOption('val1', "", [Calculation(return_value, Params(ParamOption(val)))], multi=True) +# val3 = StrOption('val2', "", Calculation(return_value, Params(ParamOption(val1))), multi=True) +# val4 = StrOption('val3', "", Calculation(return_value, Params(ParamOption(val1))), multi=True) +# interface1 = Leadership('val1', '', [val1, val3, val4]) +# od = OptionDescription('root', '', [interface1]) +# maconfig = OptionDescription('rootconfig', '', [val, interface1]) +# conf1 = Config(maconfig, name='conf1') +# meta = MetaConfig([conf1]) +# meta.property.read_write() +# assert conf1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val', 'val1.val2': 'val', 'val1.val3': 'val'}]} +# # +# conf1.option('val').value.set('val1') +# assert conf1.value.dict() == {'val': 'val1', 'val1.val1': [{'val1.val1': 'val1', 'val1.val2': 'val1', 'val1.val3': 'val1'}]} +# # +# conf1.option('val').value.reset() +# meta.option('val').value.set('val1') +# assert conf1.value.dict() == {'val': 'val1', 'val1.val1': [{'val1.val1': 'val1', 'val1.val2': 'val1', 'val1.val3': 'val1'}]} +# # +# meta.option('val').value.reset() +# conf1.option('val1.val2', 0).value.set('val2') +# assert conf1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val', 'val1.val2': 'val2', 'val1.val3': 'val'}]} +# # +# conf1.option('val1.val2', 0).value.reset() +# assert conf1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val', 'val1.val2': 'val', 'val1.val3': 'val'}]} +# # +# meta.option('val1.val2', 0).value.set('val2') +# assert conf1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val', 'val1.val2': 'val2', 'val1.val3': 'val'}]} +# # +# meta.option('val1.val1').value.set(['val']) +# assert conf1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val', 'val1.val2': 'val2', 'val1.val3': 'val'}]} +# # +# conf1.option('val1.val3', 0).value.set('val6') +# assert conf1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val', 'val1.val2': 'val2', 'val1.val3': 'val6'}]} +# # +# meta.option('val1.val2', 0).value.reset() +# conf1.option('val1.val3', 0).value.reset() +# conf1.option('val1.val1').value.set(['val3']) +# assert conf1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val3', 'val1.val2': 'val3', 'val1.val3': 'val3'}]} +# # +# conf1.option('val1.val1').value.reset() +# assert conf1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val', 'val1.val2': 'val', 'val1.val3': 'val'}]} +# # +# meta.option('val1.val1').value.set(['val3']) +# assert conf1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val3', 'val1.val2': 'val3', 'val1.val3': 'val3'}]} +# # +# conf1.option('val1.val2', 0).value.set('val2') +# assert conf1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val3', 'val1.val2': 'val2', 'val1.val3': 'val3'}]} +# # +# meta.option('val1.val1').value.set(['val3', 'rah']) +# assert conf1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val3', 'val1.val2': 'val2', 'val1.val3': 'val3'}, {'val1.val1': 'rah', 'val1.val2': 'rah', 'val1.val3': 'rah'}]} +# # +# meta.option('val1.val1').value.pop(1) +# meta.option('val1.val1').value.set(['val4']) +# assert conf1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val4', 'val1.val2': 'val2', 'val1.val3': 'val4'}]} +# +# +#def test_meta_reset(): +# ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) +# netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) +# interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) +# od = OptionDescription('root', '', [interface1]) +# conf1 = Config(od, name='conf1') +# conf2 = Config(od, name='conf2') +# meta = MetaConfig([conf1, conf2]) +# meta.property.read_write() +# meta.owner.set('meta1') +# newconf1 = meta.config('conf1') +# newconf2 = meta.config('conf2') +# assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# errors = meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.1']) +# assert len(errors) == 0 +# assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] +# newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2']) +# assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2'] +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] +# meta.value.reset('ip_admin_eth0.ip_admin_eth0') +# assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# +# +#def test_meta_properties_meta_copy(): +# ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) +# netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, properties=('disabled',)) +# interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) +# conf1 = Config(interface1, name='conf1') +# conf2 = Config(interface1, name='conf2') +# conf1.property.read_write() +# conf2.property.read_write() +# meta = MetaConfig([conf1, conf2], name='meta1') +# meta.property.read_write() +# +# newconf1 = meta.config('conf1') +# newconf2 = meta.config('conf2') +# conf3 = newconf1.config.copy(name='conf3') +# meta2 = list(conf3.config.parents()) +# assert len(meta2) == 1 +# assert meta.config.name() == meta2[0].config.name() +# +# assert newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.1']} +# assert newconf2.value.dict() == {'ip_admin_eth0': ['192.168.1.1']} +# newconf3 = meta.config('conf3') +# assert newconf3.value.dict() == {'ip_admin_eth0': ['192.168.1.1']} +# meta.option('ip_admin_eth0').value.set(['192.168.1.2']) +# assert newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.2']} +# assert newconf2.value.dict() == {'ip_admin_eth0': ['192.168.1.2']} +# assert newconf3.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 newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.3']} +# assert newconf2.value.dict() == {'ip_admin_eth0': ['192.168.1.3']} +# assert newconf3.value.dict() == {'ip_admin_eth0': ['192.168.1.3']} +# +# +#def test_meta_properties_meta_deepcopy(): +# ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) +# netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, +# properties=('disabled',)) +# interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) +# conf1 = Config(interface1, name='conf1') +# conf2 = Config(interface1, name='conf2') +# conf1.property.read_write() +# conf2.property.read_write() +# meta = MetaConfig([conf1, conf2]) +# meta.permissive.add('hidden') +# meta.property.read_write() +# +# newconf1 = meta.config('conf1') +# newconf2 = meta.config('conf2') +# meta2 = newconf1.config.deepcopy(name='conf3') +# newconf3 = meta2.config('conf3') +# assert meta != meta2 +# assert meta.permissive.get() == meta2.permissive.get() +# +# assert newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.1']} +# assert newconf2.value.dict() == {'ip_admin_eth0': ['192.168.1.1']} +# assert newconf3.value.dict() == {'ip_admin_eth0': ['192.168.1.1']} +# meta.option('ip_admin_eth0').value.set(['192.168.1.2']) +# assert newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.2']} +# assert newconf2.value.dict() == {'ip_admin_eth0': ['192.168.1.2']} +# assert newconf3.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 newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.3']} +# assert newconf2.value.dict() == {'ip_admin_eth0': ['192.168.1.3']} +# assert newconf3.value.dict() == {'ip_admin_eth0': ['192.168.1.1']} +# +# +#def test_meta_properties_meta_deepcopy_multi_parent(): +# ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip") +# netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask") +# interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) +# conf1 = Config(interface1, name='conf1') +# conf2 = Config(interface1, name='conf2') +# conf1.property.read_write() +# conf2.property.read_write() +# meta1 = MetaConfig([conf1, conf2], name='meta1') +# meta1.permissive.add('hidden') +# meta1.property.read_write() +# +# meta2 = MetaConfig(['name1', 'name2'], optiondescription=interface1, name='meta2') +# meta2.config.add(conf1) +# +# meta1.option('ip_admin_eth0').value.set('192.168.1.1') +# meta2.option('netmask_admin_eth0').value.set('255.255.255.0') +# +# assert meta1.value.dict() == {'ip_admin_eth0': '192.168.1.1', 'netmask_admin_eth0': None} +# assert meta2.value.dict() == {'ip_admin_eth0': None, 'netmask_admin_eth0': '255.255.255.0'} +# assert conf1.value.dict() == {'ip_admin_eth0': '192.168.1.1', 'netmask_admin_eth0': '255.255.255.0'} +# assert conf2.value.dict() == {'ip_admin_eth0': '192.168.1.1', 'netmask_admin_eth0': None} +# +# copy_meta2 = conf1.config.deepcopy(name='copy_conf1', metaconfig_prefix='copy_') +# assert copy_meta2.config.path() == 'copy_meta2' +# copy_meta1 = copy_meta2.config('copy_meta1') +# copy_conf1 = copy_meta1.config('copy_conf1') +# assert copy_meta2.value.dict() == {'ip_admin_eth0': None, 'netmask_admin_eth0': '255.255.255.0'} +# assert copy_conf1.value.dict() == {'ip_admin_eth0': '192.168.1.1', 'netmask_admin_eth0': '255.255.255.0'} +# +# +#def test_meta_properties_submeta_deepcopy(): +# ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) +# netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, +# properties=('disabled',)) +# interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) +# conf1 = Config(interface1, name='conf1') +# conf1.property.read_write() +# meta1 = MetaConfig([conf1], name='meta1') +# meta2 = MetaConfig([meta1], name='meta2') +# meta_copy = conf1.config.deepcopy(name='conf2', +# metaconfig_prefix='copy_') +# assert meta_copy.config.name() == 'copy_meta2' +# newcopy = meta_copy.config('copy_meta1') +# assert newcopy.config.name() == 'copy_meta1' +# newcopy = newcopy.config('conf2') +# assert newcopy.config.name() == 'conf2' +# +# +#def test_meta_properties_copy_meta(): +# ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) +# netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, +# properties=('disabled',)) +# interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) +# conf1 = Config(interface1, name='conf1') +# conf1.property.read_write() +# meta1 = MetaConfig([conf1], name='meta1') +# meta2 = MetaConfig([meta1], name='meta2') +# meta_copy = meta1.config.copy(name='meta3') +# assert meta_copy.config.name() == 'meta3' +# assert list(meta_copy.config.list()) == [] +# +# +#def test_meta_properties_deepcopy_meta(): +# ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) +# netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, +# properties=('disabled',)) +# interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) +# conf1 = Config(interface1, name='conf1') +# conf1.property.read_write() +# meta1 = MetaConfig([conf1], name='meta1') +# meta2 = MetaConfig([meta1], name='meta2') +# meta_copy = meta1.config.deepcopy(name='meta3', +# metaconfig_prefix='copy_') +# assert meta_copy.config.name() == 'copy_meta2' +# newcopy = meta_copy.config('meta3') +# assert newcopy.config.name() == 'meta3' +# assert list(newcopy.config.list()) == [] +# +# +#def test_meta_properties_submeta_deepcopy_owner(): +# ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip") +# netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask") +# interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) +# conf1 = Config(interface1, name='conf1') +# conf1.owner.set('conf1_user') +# conf1.property.read_write() +# meta1 = MetaConfig([conf1], name='meta1') +# meta1.owner.set('meta1_user') +# meta2 = MetaConfig([meta1], name='meta2') +# meta2.owner.set('meta2_user') +# # +# conf1.option('ip_admin_eth0').value.set('192.168.0.1') +# assert conf1.option('ip_admin_eth0').owner.get() == 'conf1_user' +# meta1.option('ip_admin_eth0').value.set('192.168.0.2') +# assert meta1.option('ip_admin_eth0').owner.get() == 'meta1_user' +# meta2.option('ip_admin_eth0').value.set('192.168.0.3') +# assert meta2.option('ip_admin_eth0').owner.get() == 'meta2_user' +# # +# meta2_copy = conf1.config.deepcopy(name='conf2', +# metaconfig_prefix='copy_') +# meta2_copy.option('netmask_admin_eth0').value.set('255.255.255.255') +# assert meta2_copy.option('ip_admin_eth0').value.get() == '192.168.0.3' +# assert meta2_copy.option('ip_admin_eth0').owner.get() == 'meta2_user' +# assert meta2_copy.option('netmask_admin_eth0').owner.get() == 'meta2_user' +# # +# meta1_copy = meta2_copy.config('copy_meta1') +# meta1_copy.option('netmask_admin_eth0').value.set('255.255.255.255') +# assert meta1_copy.option('ip_admin_eth0').value.get() == '192.168.0.2' +# assert meta1_copy.option('ip_admin_eth0').owner.get() == 'meta1_user' +# assert meta1_copy.option('netmask_admin_eth0').owner.get() == 'meta1_user' +# # +# conf2 = meta1_copy.config('conf2') +# conf2.owner.set('conf2_user') +# conf2.option('netmask_admin_eth0').value.set('255.255.255.255') +# assert conf2.option('netmask_admin_eth0').owner.get() == 'conf2_user' +# assert conf2.option('ip_admin_eth0').value.get() == '192.168.0.1' +# assert conf2.option('ip_admin_eth0').owner.get() == 'conf1_user' +# +# +#def test_meta_properties_meta_set_value(): +# ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) +# netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, properties=('disabled',)) +# interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) +# conf1 = Config(interface1, name='conf1') +# conf2 = Config(interface1, name='conf2') +# conf1.property.read_write() +# conf2.property.read_write() +# meta = MetaConfig([conf1, conf2]) +# meta.property.read_write() +# ret = meta.config('conf1') +# assert ret.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) +# assert isinstance(ret[1], PropertiesOptionError) +# del ret[1] +# del ret[0] +# del ret +# ret = meta.value.set('netmask_admin_eth0', ['255.255.255.255'], force_default=True) +# assert len(ret) == 1 +# assert isinstance(ret[0], PropertiesOptionError) +# del ret[0] +# del ret +# ret = meta.value.set('netmask_admin_eth0', ['255.255.255.255'], force_dont_change_value=True) +# assert len(ret) == 3 +# assert isinstance(ret[0], PropertiesOptionError) +# assert isinstance(ret[1], PropertiesOptionError) +# assert isinstance(ret[2], PropertiesOptionError) +# del ret[2] +# del ret[1] +# del ret[0] +# del ret +# ret = meta.value.set('netmask_admin_eth0', ['255.255.255.255'], force_default_if_same=True) +# assert len(ret) == 1 +# assert isinstance(ret[0], PropertiesOptionError) +# del ret[0] +# del ret +# ret = meta.value.set('ip_admin_eth0', '255.255.255.255', only_config=True) +# assert len(ret) == 2 +# assert isinstance(ret[0], ValueError) +# assert isinstance(ret[1], ValueError) +# del ret[1] +# del ret[0] +# del ret +# ret = meta.value.set('ip_admin_eth0', '255.255.255.255', force_default=True) +# assert len(ret) == 1 +# assert isinstance(ret[0], ValueError) +# del ret[0] +# del ret +# ret = meta.value.set('ip_admin_eth0', '255.255.255.255', force_dont_change_value=True) +# assert len(ret) == 1 +# assert isinstance(ret[0], ValueError) +# del ret[0] +# del ret +# ret = meta.value.set('ip_admin_eth0', '255.255.255.255', force_default_if_same=True) +# assert len(ret) == 1 +# assert isinstance(ret[0], ValueError) +# del ret[0] +# del ret +# +# +#def test_metaconfig_force_metaconfig_on_freeze(): +# dummy1 = StrOption('dummy1', 'doc dummy', default='default', properties=('force_metaconfig_on_freeze',)) +# group = OptionDescription('group', '', [dummy1]) +# cfg = Config(group, name='cfg') +# cfg.owner.set(owners.config) +# meta1 = MetaConfig([cfg], name='meta1') +# meta1.owner.set(owners.meta1) +# meta2 = MetaConfig([meta1], name='meta2') +# meta2.owner.set(owners.meta2) +# cfg.property.read_write() +# +# cfg.option('dummy1').property.add('frozen') +# # +# assert cfg.option('dummy1').value.get() == 'default' +# assert cfg.option('dummy1').owner.get() == 'default' +# # +# meta2.option('dummy1').value.set('meta2') +# # +# assert cfg.option('dummy1').value.get() == 'meta2' +# assert cfg.option('dummy1').owner.get() == 'meta2' +# # +# cfg.option('dummy1').property.remove('frozen') +# cfg.option('dummy1').value.set('cfg') +# cfg.option('dummy1').property.add('frozen') +# # +# assert cfg.option('dummy1').value.get() == 'meta2' +# assert cfg.option('dummy1').owner.get() == 'meta2' +# # +# meta1.option('dummy1').value.set('meta1') +# # +# assert cfg.option('dummy1').value.get() == 'meta1' +# assert cfg.option('dummy1').owner.get() == 'meta1' +# # +# cfg.option('dummy1').property.remove('frozen') +# assert cfg.option('dummy1').value.get() == 'cfg' +# assert cfg.option('dummy1').owner.get() == 'config' +# +# +#def test_metaconfig_force_metaconfig_on_freeze_option(): +# dummy1 = StrOption('dummy1', 'doc dummy', default='default') +# dummy2 = StrOption('dummy2', 'doc dummy', default='default', properties=('force_default_on_freeze',)) +# group = OptionDescription('group', '', [dummy1, dummy2]) +# cfg = Config(group, name='cfg') +# cfg.owner.set(owners.config) +# meta1 = MetaConfig([cfg], name='meta1') +# meta1.owner.set(owners.meta1) +# meta2 = MetaConfig([meta1], name='meta2') +# meta2.owner.set(owners.meta2) +# cfg.property.read_write() +# +# cfg.option('dummy1').property.add('frozen') +# cfg.option('dummy1').property.add('force_metaconfig_on_freeze') +# cfg.option('dummy2').property.add('frozen') +# # +# assert cfg.option('dummy1').value.get() == 'default' +# assert cfg.option('dummy1').owner.get() == 'default' +# assert cfg.option('dummy2').value.get() == 'default' +# assert cfg.option('dummy2').owner.get() == 'default' +# # +# meta2.option('dummy1').value.set('meta2') +# meta2.option('dummy2').value.set('meta2') +# # +# assert cfg.option('dummy1').value.get() == 'meta2' +# assert cfg.option('dummy1').owner.get() == 'meta2' +# assert cfg.option('dummy2').value.get() == 'default' +# assert cfg.option('dummy2').owner.get() == 'default' +# # +# cfg.option('dummy1').property.remove('frozen') +# cfg.option('dummy2').property.remove('frozen') +# cfg.option('dummy1').value.set('cfg') +# cfg.option('dummy2').value.set('cfg') +# cfg.option('dummy1').property.add('frozen') +# cfg.option('dummy2').property.add('frozen') +# # +# assert cfg.option('dummy1').value.get() == 'meta2' +# assert cfg.option('dummy1').owner.get() == 'meta2' +# assert cfg.option('dummy2').value.get() == 'default' +# assert cfg.option('dummy2').owner.get() == 'default' +# # +# meta1.option('dummy1').value.set('meta1') +# meta1.option('dummy2').value.set('meta1') +# # +# assert cfg.option('dummy1').value.get() == 'meta1' +# assert cfg.option('dummy1').owner.get() == 'meta1' +# assert cfg.option('dummy2').value.get() == 'default' +# assert cfg.option('dummy2').owner.get() == 'default' +# # +# meta1.option('dummy1').property.add('force_metaconfig_on_freeze') +# assert cfg.option('dummy1').value.get() == 'meta2' +# assert cfg.option('dummy1').owner.get() == 'meta2' +# # +# meta2.option('dummy1').property.add('force_metaconfig_on_freeze') +# assert cfg.option('dummy1').value.get() == 'default' +# assert cfg.option('dummy1').owner.get() == 'default' +# # +# meta1.option('dummy1').property.remove('force_metaconfig_on_freeze') +# assert cfg.option('dummy1').value.get() == 'meta1' +# assert cfg.option('dummy1').owner.get() == 'meta1' +# # +# cfg.option('dummy1').property.remove('frozen') +# assert cfg.option('dummy1').value.get() == 'cfg' +# assert cfg.option('dummy1').owner.get() == 'config' +# +# +#def test_meta_get_config(): +# od = make_description() +# meta = MetaConfig(['name1', 'name2'], optiondescription=od) +# meta.config.new('meta1', type='metaconfig') +# assert isinstance(meta.config('meta1'), MetaConfig) +# assert isinstance(meta.config('name1'), Config) +# with pytest.raises(ConfigError): +# meta.config('unknown') diff --git a/tests/test_mixconfig.py b/tests/test_mixconfig.py index 3c8a46b..e44f6f7 100644 --- a/tests/test_mixconfig.py +++ b/tests/test_mixconfig.py @@ -89,1168 +89,1168 @@ def make_mixconfig(double=False): return mix -def test_mix_name(): - mix = make_mixconfig(True) - assert mix.config.path() == 'doublemix' - ret = mix.config('mix') - assert ret.config.path() == 'doublemix.mix' - ret = mix.config('mix.conf1') - assert ret.config.path() == 'doublemix.mix.conf1' - ret = mix.config('mix.conf2') - assert ret.config.path() == 'doublemix.mix.conf2' - - -def test_mix_not_group(): - i1 = IntOption('i1', '') - od1 = OptionDescription('od1', '', [i1]) - od2 = OptionDescription('od2', '', [od1]) - cfg = Config(od2, name='conf1') - grp = GroupConfig([cfg]) - with pytest.raises(TypeError): - MixConfig(od2, [grp], name='error') -# assert not list_sessions() - - -def test_unknown_config(): - mix = make_mixconfig() - with pytest.raises(ConfigError): - mix.config('unknown') - - -def test_none(): - mix = make_mixconfig() - newconf1 = mix.config('conf1') - newconf2 = mix.config('conf2') - assert mix.option('od1.i3').value.get() is newconf1.option('od1.i3').value.get() is newconf2.option('od1.i3').value.get() is None - assert mix.option('od1.i3').owner.get() is newconf1.option('od1.i3').owner.get() is newconf2.option('od1.i3').owner.get() is owners.default - # - mix.option('od1.i3').value.set(3) - assert mix.option('od1.i3').value.get() == newconf1.option('od1.i3').value.get() == newconf2.option('od1.i3').value.get() == 3 - assert mix.option('od1.i3').owner.get() is newconf1.option('od1.i3').owner.get() is newconf2.option('od1.i3').owner.get() is owners.mix1 - # - newconf1.option('od1.i3').value.set(2) - assert mix.option('od1.i3').value.get() == newconf2.option('od1.i3').value.get() == 3 - assert newconf1.option('od1.i3').value.get() == 2 - assert mix.option('od1.i3').owner.get() is newconf2.option('od1.i3').owner.get() is owners.mix1 - assert newconf1.option('od1.i3').owner.get() is owners.user - # - mix.option('od1.i3').value.set(4) - assert mix.option('od1.i3').value.get() == newconf2.option('od1.i3').value.get() == 4 - assert newconf1.option('od1.i3').value.get() == 2 - assert mix.option('od1.i3').owner.get() is newconf2.option('od1.i3').owner.get() is owners.mix1 - assert newconf1.option('od1.i3').owner.get() is owners.user - # - mix.option('od1.i3').value.reset() - assert mix.option('od1.i3').value.get() is newconf2.option('od1.i3').value.get() is None - assert newconf1.option('od1.i3').value.get() == 2 - assert mix.option('od1.i3').owner.get() is newconf2.option('od1.i3').owner.get() is owners.default - assert newconf1.option('od1.i3').owner.get() is owners.user - # - newconf1.option('od1.i3').value.reset() - assert mix.option('od1.i3').value.get() is newconf1.option('od1.i3').value.get() is newconf2.option('od1.i3').value.get() is None - assert mix.option('od1.i3').owner.get() is newconf1.option('od1.i3').owner.get() is newconf2.option('od1.i3').owner.get() is owners.default - # - assert mix.config.name() == mix.config.name() - - -def test_reset(): - mix = make_mixconfig() - assert mix.option('od1.i2').value.get() == 1 - mix.option('od1.i2').value.set(2) - newconf1 = mix.config('conf1') - newconf2 = mix.config('conf2') - newconf1.option('od1.i2').value.set(3) - assert mix.option('od1.i2').value.get() == 2 - assert newconf1.option('od1.i2').value.get() == 3 - assert newconf2.option('od1.i2').value.get() == 2 - mix.config.reset() - assert mix.option('od1.i2').value.get() == 1 - assert newconf1.option('od1.i2').value.get() == 3 - assert newconf2.option('od1.i2').value.get() == 1 - - -def test_default(): - mix = make_mixconfig() - newconf1 = mix.config('conf1') - newconf2 = mix.config('conf2') - assert mix.option('od1.i2').value.get() == newconf1.option('od1.i2').value.get() == newconf2.option('od1.i2').value.get() == 1 - assert mix.option('od1.i2').owner.get() is newconf1.option('od1.i2').owner.get() is newconf2.option('od1.i2').owner.get() is owners.default - # - mix.option('od1.i2').value.set(3) - assert mix.option('od1.i2').value.get() == newconf1.option('od1.i2').value.get() == newconf2.option('od1.i2').value.get() == 3 - assert mix.option('od1.i2').owner.get() is newconf1.option('od1.i2').owner.get() is newconf2.option('od1.i2').owner.get() is owners.mix1 - # - newconf1.option('od1.i2').value.set(2) - assert mix.option('od1.i2').value.get() == newconf2.option('od1.i2').value.get() == 3 - assert newconf1.option('od1.i2').value.get() == 2 - assert mix.option('od1.i2').owner.get() is newconf2.option('od1.i2').owner.get() is owners.mix1 - assert newconf1.option('od1.i2').owner.get() is owners.user - # - mix.option('od1.i2').value.set(4) - assert mix.option('od1.i2').value.get() == newconf2.option('od1.i2').value.get() == 4 - assert newconf1.option('od1.i2').value.get() == 2 - assert mix.option('od1.i2').owner.get() is newconf2.option('od1.i2').owner.get() is owners.mix1 - assert newconf1.option('od1.i2').owner.get() is owners.user - # - mix.option('od1.i2').value.reset() - assert mix.option('od1.i2').value.get() == newconf2.option('od1.i2').value.get() == 1 - assert newconf1.option('od1.i2').value.get() == 2 - assert mix.option('od1.i2').owner.get() is newconf2.option('od1.i2').owner.get() is owners.default - assert newconf1.option('od1.i2').owner.get() is owners.user - # - newconf1.option('od1.i2').value.reset() - assert mix.option('od1.i2').value.get() == newconf1.option('od1.i2').value.get() == newconf2.option('od1.i2').value.get() == 1 - assert mix.option('od1.i2').owner.get() is newconf1.option('od1.i2').owner.get() is newconf2.option('od1.i2').owner.get() is owners.default - - -def test_contexts(): - mix = make_mixconfig() - errors = mix.value.set('od1.i2', 6, only_config=True) - newconf1 = mix.config('conf1') - assert mix.option('od1.i2').value.get() == 1 - assert mix.option('od1.i2').owner.get() == owners.default - assert newconf1.option('od1.i2').value.get() == newconf1.option('od1.i2').value.get() == 6 - assert newconf1.option('od1.i2').owner.get() == newconf1.option('od1.i2').owner.get() is owners.user - assert len(errors) == 0 - - - -def test_find(): - mix = make_mixconfig() - ret = list(mix.option.find('i2')) - assert len(ret) == 1 - assert 1 == ret[0].value.get() - ret = mix.option.find('i2', first=True) - assert 1 == ret.value.get() - assert mix.value.dict() == {'od1.i4': 2, 'od1.i1': None, 'od1.i3': None, - 'od1.i2': 1, 'od1.i5': [2]} - - -def test_mix_mix(): - mix = make_mixconfig(double=True) - newmix = mix.config('mix') - newconf1 = mix.config('mix.conf1') - newconf2 = mix.config('mix.conf2') - assert mix.option('od1.i2').value.get() == newmix.option('od1.i2').value.get() == newconf1.option('od1.i2').value.get() == newconf2.option('od1.i2').value.get() == 1 - assert mix.option('od1.i2').owner.get() is newmix.option('od1.i2').owner.get() is newconf1.option('od1.i2').owner.get() is newconf2.option('od1.i2').owner.get() is owners.default - # - mix.option('od1.i2').value.set(3) - assert mix.option('od1.i2').value.get() == newmix.option('od1.i2').value.get() == newconf1.option('od1.i2').value.get() == newconf2.option('od1.i2').value.get() == 3 - assert mix.option('od1.i2').owner.get() is newmix.option('od1.i2').owner.get() is newconf1.option('od1.i2').owner.get() is newconf2.option('od1.i2').owner.get() is owners.mix1 - # - newconf1.option('od1.i2').value.set(2) - assert mix.option('od1.i2').value.get() == newmix.option('od1.i2').value.get() == newconf2.option('od1.i2').value.get() == 3 - assert newconf1.option('od1.i2').value.get() == 2 - assert mix.option('od1.i2').owner.get() is newmix.option('od1.i2').owner.get() is newconf2.option('od1.i2').owner.get() is owners.mix1 - assert newconf1.option('od1.i2').owner.get() is owners.user - # - newmix.option('od1.i2').value.set(4) - assert mix.option('od1.i2').value.get() == 3 - assert newmix.option('od1.i2').value.get() == newconf2.option('od1.i2').value.get() == 4 - assert newconf1.option('od1.i2').value.get() == 2 - assert mix.option('od1.i2').owner.get() is owners.mix1 - assert newmix.option('od1.i2').owner.get() is newconf2.option('od1.i2').owner.get() is owners.mix2 - assert newconf1.option('od1.i2').owner.get() is owners.user - # - newmix.option('od1.i2').value.reset() - assert mix.option('od1.i2').value.get() == newmix.option('od1.i2').value.get() == newconf2.option('od1.i2').value.get() == 3 - assert newconf1.option('od1.i2').value.get() == 2 - assert mix.option('od1.i2').owner.get() is newmix.option('od1.i2').owner.get() is newconf2.option('od1.i2').owner.get() is owners.mix1 - assert newconf1.option('od1.i2').owner.get() is owners.user - # - mix.option('od1.i2').value.reset() - assert mix.option('od1.i2').value.get() == newmix.option('od1.i2').value.get() == newconf2.option('od1.i2').value.get() == 1 - assert newconf1.option('od1.i2').value.get() == 2 - assert mix.option('od1.i2').owner.get() is newmix.option('od1.i2').owner.get() is newconf2.option('od1.i2').owner.get() is owners.default - assert newconf1.option('od1.i2').owner.get() is owners.user - # - newconf1.option('od1.i2').value.reset() - assert mix.option('od1.i2').value.get() == newmix.option('od1.i2').value.get() == newconf1.option('od1.i2').value.get() == newconf2.option('od1.i2').value.get() == 1 - assert mix.option('od1.i2').owner.get() is newmix.option('od1.i2').owner.get() is newconf1.option('od1.i2').owner.get() is newconf2.option('od1.i2').owner.get() is owners.default - - -def test_mix_mix_set(): - mix = make_mixconfig(double=True) - errors1 = mix.value.set('od1.i1', 7, only_config=True) - errors2 = mix.value.set('od1.i6', 7, only_config=True) - assert len(errors1) == 0 - assert len(errors2) == 2 - ret = mix.config('mix.conf1') - conf1 = ret._config_bag.context - ret = mix.config('mix.conf2') - conf2 = ret._config_bag.context - newconf1 = mix.config('mix.conf1') - newconf2 = mix.config('mix.conf2') - assert newconf1.option('od1.i1').value.get() == newconf2.option('od1.i1').value.get() == 7 - # - dconfigs = [] - ret = mix.config.find('i1', value=7) - for conf in ret.config.list(): - dconfigs.append(conf._config_bag.context) - assert [conf1, conf2] == dconfigs - newconf1.option('od1.i1').value.set(8) - # - dconfigs = [] - ret = mix.config.find('i1') - for conf in ret.config.list(): - dconfigs.append(conf._config_bag.context) - assert [conf1, conf2] == dconfigs - ret = mix.config.find('i1', value=7) - assert conf2 == list(ret.config.list())[0]._config_bag.context - ret = mix.config.find('i1', value=8) - assert conf1 == list(ret.config.list())[0]._config_bag.context - # - dconfigs = [] - ret = mix.config.find('i5', value=2) - for conf in ret.config.list(): - dconfigs.append(conf._config_bag.context) - assert [conf1, conf2] == dconfigs - # - with pytest.raises(AttributeError): - mix.config.find('i1', value=10) - with pytest.raises(AttributeError): - mix.config.find('not', value=10) - with pytest.raises(AttributeError): - mix.config.find('i6') - with pytest.raises(ValueError): - mix.value.set('od1.i6', 7, only_config=True, force_default=True) - with pytest.raises(ValueError): - mix.value.set('od1.i6', 7, only_config=True, force_default_if_same=True) - with pytest.raises(ValueError): - mix.value.set('od1.i6', 7, only_config=True, force_dont_change_value=True) - - -def test_mix_unconsistent(): - i1 = IntOption('i1', '') - i2 = IntOption('i2', '', default=1) - i3 = IntOption('i3', '') - i4 = IntOption('i4', '', default=2) - od1 = OptionDescription('od1', '', [i1, i2, i3, i4]) - od2 = OptionDescription('od2', '', [od1]) - od3 = OptionDescription('od3', '', [od1]) - conf1 = Config(od2, name='conf1') - conf2 = Config(od2, name='conf2') - conf3 = Config(od2, name='conf3') - i5 = IntOption('i5', '') - od4 = OptionDescription('od4', '', [i5]) - conf4 = Config(od4, name='conf4') - mix = MixConfig(od2, [conf1, conf2]) - mix.owner.set(owners.mix1) - with pytest.raises(TypeError): - MixConfig(od2, "string", name='error') - # same descr but conf1 already in mix - assert len(list(conf1.config.parents())) == 1 - assert len(list(conf3.config.parents())) == 0 - new_mix = MixConfig(od2, [conf1, conf3]) - assert len(list(conf1.config.parents())) == 2 - assert len(list(conf3.config.parents())) == 1 - # not same descr - tmix = MixConfig(od2, [conf3, conf4]) - - -def test_mix_leadership(): - ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) - netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) - interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) - od = OptionDescription('root', '', [interface1]) - conf1 = Config(od, name='conf1') - conf2 = Config(od, name='conf2') - mix = MixConfig(od, [conf1, conf2]) - mix.property.read_only() - ret = mix.config.find('ip_admin_eth0') - configs = ret.config.list() - assert len(configs) == 2 - assert conf1._config_bag.context == configs[0]._config_bag.context - assert conf2._config_bag.context == configs[1]._config_bag.context - ret = mix.config.find('netmask_admin_eth0') - configs = ret.config.list() - assert len(configs) == 2 - assert conf1._config_bag.context == configs[0]._config_bag.context - assert conf2._config_bag.context == configs[1]._config_bag.context - mix.property.read_write() - with pytest.raises(AttributeError): - mix.config.find('netmask_admin_eth0') - ret = mix.unrestraint.config.find('netmask_admin_eth0') - configs = ret.config.list() - assert len(configs) == 2 - assert conf1._config_bag.context == configs[0]._config_bag.context - assert conf2._config_bag.context == configs[1]._config_bag.context - mix.property.read_only() - ret = mix.config.find('netmask_admin_eth0') - configs = ret.config.list() - assert len(configs) == 2 - assert conf1._config_bag.context == configs[0]._config_bag.context - assert conf2._config_bag.context == configs[1]._config_bag.context - - -def test_mix_leadership_value2(): - ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) - netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) - interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) - od = OptionDescription('root', '', [interface1]) - conf1 = Config(od, name='conf1') - conf2 = Config(od, name='conf2') - mix = MixConfig(od, [conf1, conf2], name="mix") - newconf1 = mix.config('conf1') - newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.8']) - assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None - #FIXME devrait raise ! assert newconf1.option('ip_admin_eth0.ip_admin_eth0', 0).value.get() == None - # - newconf1.option('ip_admin_eth0.ip_admin_eth0').value.reset() - # - mix.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) - assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None - mix.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0') - assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0' - mix.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.0.0') - assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0' - # - newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) - assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0' - - -def test_mix_leadership_value_default(): - ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) - netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True) - interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) - od = OptionDescription('root', '', [interface1]) - conf1 = Config(od, name='conf1') - conf2 = Config(od, name='conf2') - mix = MixConfig(od, [conf1, conf2]) - newconf1 = mix.config('conf1') - assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None - # - mix.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) - assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None - # - mix.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0') - assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0' - # - mix.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.0.0') - assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0' - # - newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) - assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0' - - -def test_mix_leadership_owners(): - ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) - netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) - interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) - od = OptionDescription('root', '', [interface1]) - conf1 = Config(od, name='conf1') - conf2 = Config(od, name='conf2') - mix = MixConfig(od, [conf1, conf2]) - mix.owner.set(owners.mix1) - newconf1 = mix.config('conf1') - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault() - with pytest.raises(LeadershipError): - newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault() - # - newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.user - assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault() - # - newconf1.option('ip_admin_eth0.ip_admin_eth0').value.reset() - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault() - # - mix.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.mix1 - assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault() - # - mix.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0') - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.mix1 - assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.mix1 - # - mix.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.0.0') - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.mix1 - assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.mix1 - # - newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.user - assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.mix1 - - -def test_mix_force_default(): - ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) - netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) - interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) - od = OptionDescription('root', '', [interface1]) - conf1 = Config(od, name='conf1') - conf2 = Config(od, name='conf2') - mix = MixConfig(od, [conf1, conf2]) - mix.property.read_write() - mix.owner.set('mix1') - assert mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - newconf1 = mix.config('conf1') - newconf2 = mix.config('conf2') - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - # - errors = mix.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.1']) - assert len(errors) == 0 - assert mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] - # - newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2']) - assert mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2'] - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] - # - errors = mix.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.3']) - assert len(errors) == 0 - assert mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3'] - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2'] - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3'] - # - errors = mix.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_default=True) - assert len(errors) == 0 - assert mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] - - -def test_mix_force_dont_change_value(): - ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) - netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) - interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) - od = OptionDescription('root', '', [interface1]) - conf1 = Config(od, name='conf1') - conf2 = Config(od, name='conf2') - mix = MixConfig(od, [conf1, conf2]) - mix.property.read_write() - mix.owner.set('mix1') - assert mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - newconf1 = mix.config('conf1') - newconf2 = mix.config('conf2') - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.4']) - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault() - errors = mix.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_dont_change_value=True) - assert len(errors) == 0 - assert mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user - - -def test_mix_force_default_if_same(): - ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) - netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) - interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) - od = OptionDescription('root', '', [interface1]) - conf1 = Config(od, name='conf1') - conf2 = Config(od, name='conf2') - mix = MixConfig(od, [conf1, conf2]) - mix.property.read_write() - mix.owner.set('mix1') - # - assert mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - newconf1 = mix.config('conf1') - newconf2 = mix.config('conf2') - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - # - newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.4']) - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault() - errors = mix.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_default_if_same=True) - assert len(errors) == 0 - assert mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.mix1 - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.mix1 - # - newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.3']) - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3'] - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.mix1 - errors = mix.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.5'], force_default_if_same=True) - assert len(errors) == 0 - assert mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.5'] - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3'] - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.5'] - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.mix1 - - -def test_mix_force_default_if_same_and_dont_change(): - ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) - netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) - interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) - od = OptionDescription('root', '', [interface1]) - conf1 = Config(od, name='conf1') - conf2 = Config(od, name='conf2') - mix = MixConfig(od, [conf1, conf2]) - mix.property.read_write() - mix.owner.set('mix1') - # - assert mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - newconf1 = mix.config('conf1') - newconf2 = mix.config('conf2') - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - # - newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.4']) - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault() - errors = mix.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_default_if_same=True, force_dont_change_value=True) - assert len(errors) == 0 - assert mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.mix1 - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user - # - newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.3']) - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3'] - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user - errors = mix.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.5'], force_default_if_same=True, force_dont_change_value=True) - assert len(errors) == 0 - assert mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.5'] - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3'] - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user - - - -def test_mix_force_default_and_dont_change(): - ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) - netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) - interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) - od = OptionDescription('root', '', [interface1]) - conf1 = Config(od, name='rconf1') - conf2 = Config(od, name='rconf2') - mix = MixConfig(od, [conf1, conf2]) - mix.property.read_write() - mix.owner.set('mix1') - with pytest.raises(ValueError): - mix.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_default=True, force_dont_change_value=True) - - -def test_mix_properties_mix(): - ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) - netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, validators=[Calculation(valid_network_netmask, Params((ParamOption(ip_admin_eth0), ParamSelfOption())))]) - interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0], properties=('disabled',)) - od = OptionDescription('root', '', [interface1]) - conf1 = Config(od, name='conf1') - conf2 = Config(od, name='conf2') - conf1.property.read_write() - conf2.property.read_write() - mix = MixConfig(od, [conf1, conf2]) - mix.property.read_write() - newconf1 = mix.config('conf1') - assert newconf1.value.dict() == {} - - -def test_mix_exception_mix(): - ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) - netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", Calculation(raise_exception), multi=True, validators=[Calculation(valid_network_netmask, Params((ParamOption(ip_admin_eth0), ParamSelfOption())))]) - interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) - od = OptionDescription('root', '', [interface1]) - conf1 = Config(od, name='conf1') - conf2 = Config(od, name='conf2') - mix = MixConfig(od, [conf1, conf2]) - mix.property.read_write() - with pytest.raises(ConfigError): - conf1.value.dict() - - - -def test_mix_callback(): - val1 = StrOption('val1', "", 'val') - val2 = StrOption('val2', "", Calculation(return_value, Params(ParamOption(val1)))) - val3 = StrOption('val3', "", Calculation(return_value, Params(ParamValue('yes')))) - val4 = StrOption('val4', "", Calculation(return_value, Params(kwargs={'value': ParamOption(val1)}))) - val5 = StrOption('val5', "", Calculation(return_value, Params(kwargs={'value': ParamValue('yes')}))) - maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4, val5]) - cfg = Config(maconfig, name='cfg') - mix = MixConfig(maconfig, [cfg]) - mix.property.read_write() - newcfg = mix.config('cfg') - assert newcfg.value.dict() == {'val3': 'yes', 'val2': 'val', 'val1': 'val', 'val5': 'yes', 'val4': 'val'} - newcfg.option('val1').value.set('new') - assert newcfg.value.dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new'} - newcfg.option('val1').value.reset() - mix.option('val1').value.set('new') - assert newcfg.value.dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new'} - newcfg.option('val4').value.set('new1') - assert newcfg.value.dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new1'} - newcfg.option('val4').value.reset() - mix.option('val4').value.set('new1') - assert newcfg.value.dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new1'} - mix.option('val4').value.reset() - - -def test_mix_callback_follower(): - val = StrOption('val', "", default='val') - val1 = StrOption('val1', "", [Calculation(return_value, Params(ParamOption(val)))], multi=True) - val3 = StrOption('val2', "", Calculation(return_value, Params(ParamOption(val1))), multi=True) - val4 = StrOption('val3', "", Calculation(return_value, Params(ParamOption(val1))), multi=True) - interface1 = Leadership('val1', '', [val1, val3, val4]) - od = OptionDescription('root', '', [interface1]) - maconfig = OptionDescription('rootconfig', '', [val, interface1]) - cfg = Config(maconfig, name='cfg1') - mix = MixConfig(maconfig, [cfg]) - mix.property.read_write() - newcfg1 = mix.config('cfg1') - assert newcfg1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val', 'val1.val2': 'val', 'val1.val3': 'val'}]} - # - newcfg1.option('val').value.set('val1') - assert newcfg1.value.dict() == {'val': 'val1', 'val1.val1': [{'val1.val1': 'val1', 'val1.val2': 'val1', 'val1.val3': 'val1'}]} - # - newcfg1.option('val').value.reset() - mix.option('val').value.set('val1') - assert newcfg1.value.dict() == {'val': 'val1', 'val1.val1': [{'val1.val1': 'val1', 'val1.val2': 'val1', 'val1.val3': 'val1'}]} - # - mix.option('val').value.reset() - newcfg1.option('val1.val2', 0).value.set('val2') - assert newcfg1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val', 'val1.val2': 'val2', 'val1.val3': 'val'}]} - # - newcfg1.option('val1.val2', 0).value.reset() - assert newcfg1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val', 'val1.val2': 'val', 'val1.val3': 'val'}]} - # - mix.option('val1.val2', 0).value.set('val2') - assert newcfg1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val', 'val1.val2': 'val2', 'val1.val3': 'val'}]} - # - mix.option('val1.val1').value.set(['val']) - assert newcfg1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val', 'val1.val2': 'val2', 'val1.val3': 'val'}]} - # - newcfg1.option('val1.val3', 0).value.set('val6') - assert newcfg1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val', 'val1.val2': 'val2', 'val1.val3': 'val6'}]} - # - mix.option('val1.val2', 0).value.reset() - newcfg1.option('val1.val3', 0).value.reset() - newcfg1.option('val1.val1').value.set(['val3']) - assert newcfg1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val3', 'val1.val2': 'val3', 'val1.val3': 'val3'}]} - # - newcfg1.option('val1.val1').value.reset() - assert newcfg1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val', 'val1.val2': 'val', 'val1.val3': 'val'}]} - # - mix.option('val1.val1').value.set(['val3']) - assert newcfg1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val3', 'val1.val2': 'val3', 'val1.val3': 'val3'}]} - # - newcfg1.option('val1.val2', 0).value.set('val2') - assert newcfg1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val3', 'val1.val2': 'val2', 'val1.val3': 'val3'}]} - # - mix.option('val1.val1').value.set(['val3', 'rah']) - assert newcfg1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val3', 'val1.val2': 'val2', 'val1.val3': 'val3'}, {'val1.val1': 'rah', 'val1.val2': 'rah', 'val1.val3': 'rah'}]} - # - mix.option('val1.val1').value.pop(1) - mix.option('val1.val1').value.set(['val4']) - assert newcfg1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val4', 'val1.val2': 'val2', 'val1.val3': 'val4'}]} - - -def test_meta_reset(): - ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) - netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) - interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) - od0 = OptionDescription('root', '', [interface1]) - ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) - netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) - interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) - od1 = OptionDescription('root', '', [interface1]) - ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) - netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) - interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) - od2 = OptionDescription('root', '', [interface1]) - conf1 = Config(od0, name='conf1') - conf2 = Config(od1, name='conf2') - mix = MixConfig(od2, [conf1, conf2]) - mix.property.read_write() - mix.owner.set('mix1') - assert mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - newconf1 = mix.config('conf1') - newconf2 = mix.config('conf2') - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - errors = mix.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.1']) - assert len(errors) == 0 - assert mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] - newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2']) - assert mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2'] - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] - mix.value.reset('ip_admin_eth0.ip_admin_eth0') - assert mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] - - -def test_mix_properties_mix_copy(): - ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) - netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, properties=('disabled',)) - interface0 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) - ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) - netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, properties=('disabled',)) - interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) - ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) - netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, properties=('disabled',)) - interface2 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) - conf1 = Config(interface0, name='conf1') - conf2 = Config(interface1, name='conf2') - conf1.property.read_write() - conf2.property.read_write() - mix = MixConfig(interface2, [conf1, conf2], name='mix1') - mix.property.read_write() - - newconf1 = mix.config('conf1') - conf3 = newconf1.config.copy(name='conf3') - newconf3 = mix.config('conf3') - mix2 = list(conf3.config.parents()) - assert len(mix2) == 1 - assert mix.config.name() == mix2[0].config.name() - - newconf2 = mix.config('conf2') - assert newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.1']} - assert conf2.value.dict() == {'ip_admin_eth0': ['192.168.1.1']} - assert newconf3.value.dict() == {'ip_admin_eth0': ['192.168.1.1']} - mix.option('ip_admin_eth0').value.set(['192.168.1.2']) - assert newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.2']} - assert conf2.value.dict() == {'ip_admin_eth0': ['192.168.1.2']} - assert newconf3.value.dict() == {'ip_admin_eth0': ['192.168.1.2']} - ret = mix.value.set('ip_admin_eth0', ['192.168.1.3'], force_default_if_same=True) - assert newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.3']} - assert conf2.value.dict() == {'ip_admin_eth0': ['192.168.1.3']} - assert newconf3.value.dict() == {'ip_admin_eth0': ['192.168.1.3']} - - -def test_mix_properties_mix_deepcopy(): - ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) - netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, - properties=('disabled',)) - interface0 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) - ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) - netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, - properties=('disabled',)) - interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) - ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) - netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, - properties=('disabled',)) - interface2 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) - conf1 = Config(interface0, name='conf1') - conf2 = Config(interface1, name='conf2') - conf1.property.read_write() - conf2.property.read_write() - mix = MixConfig(interface2, [conf1, conf2]) - mix.permissive.add('hidden') - mix.property.read_write() - - newconf1 = mix.config('conf1') - newconf2 = mix.config('conf2') - mix2 = newconf1.config.deepcopy(name='conf3') - newconf3 = mix2.config('conf3') - assert mix != mix2 - assert mix.permissive.get() == mix2.permissive.get() - - assert newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.1']} - assert newconf2.value.dict() == {'ip_admin_eth0': ['192.168.1.1']} - assert newconf3.value.dict() == {'ip_admin_eth0': ['192.168.1.1']} - mix.option('ip_admin_eth0').value.set(['192.168.1.2']) - assert newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.2']} - assert newconf2.value.dict() == {'ip_admin_eth0': ['192.168.1.2']} - assert newconf3.value.dict() == {'ip_admin_eth0': ['192.168.1.1']} - mix.value.set('ip_admin_eth0', ['192.168.1.3'], force_default_if_same=True) - assert newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.3']} - assert newconf2.value.dict() == {'ip_admin_eth0': ['192.168.1.3']} - assert newconf3.value.dict() == {'ip_admin_eth0': ['192.168.1.1']} - - -def test_mix_properties_submix_deepcopy(): - ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) - netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, - properties=('disabled',)) - interface0 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) - ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) - netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, - properties=('disabled',)) - interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) - ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) - netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, - properties=('disabled',)) - interface2 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) - conf1 = Config(interface0, name='conf1') - conf1.property.read_write() - mix1 = MixConfig(interface1, [conf1], name='mix1') - mix2 = MixConfig(interface2, [mix1], name='mix2') - mix_copy = conf1.config.deepcopy(name='conf2', - metaconfig_prefix='copy_') - assert mix_copy.config.name() == 'copy_mix2' - ret1 = mix_copy.config('copy_mix1') - assert ret1.config.name() == 'copy_mix1' - ret2 = mix_copy.config('copy_mix1.conf2') - assert ret2.config.name() == 'conf2' - - -def test_mix_properties_submix_deepcopy_owner(): - ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip") - netmask_admin_eth0 = NetmaskOption('netmask_admin_eth1', "mask") - interface0 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) - ip_admin_eth0 = NetworkOption('ip_admin_eth1', "ip") - netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask") - interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) - ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip") - netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask") - interface2 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) - conf1 = Config(interface0, name='conf1') - conf1.owner.set('conf1_user') - conf1.property.read_write() - mix1 = MixConfig(interface1, [conf1], name='mix1') - mix1.owner.set('mix1_user') - mix2 = MixConfig(interface2, [mix1], name='mix2') - mix2.owner.set('mix2_user') - # - conf1.option('ip_admin_eth0').value.set('192.168.0.1') - assert conf1.option('ip_admin_eth0').owner.get() == 'conf1_user' - mix2.option('ip_admin_eth0').value.set('192.168.0.3') - assert mix2.option('ip_admin_eth0').owner.get() == 'mix2_user' - # - mix2_copy = conf1.config.deepcopy(name='conf2', - metaconfig_prefix='copy_') - mix2_copy.option('netmask_admin_eth0').value.set('255.255.255.255') - assert mix2_copy.option('ip_admin_eth0').value.get() == '192.168.0.3' - assert mix2_copy.option('ip_admin_eth0').owner.get() == 'mix2_user' - assert mix2_copy.option('netmask_admin_eth0').owner.get() == 'mix2_user' - # - mix1_copy = mix2_copy.config('copy_mix1') - mix1_copy.option('netmask_admin_eth0').value.set('255.255.255.255') - # - conf2 = mix1_copy.config('conf2') - conf2.owner.set('conf2_user') - conf2.option('netmask_admin_eth1').value.set('255.255.255.255') - assert conf2.option('netmask_admin_eth1').owner.get() == 'conf2_user' - assert conf2.option('ip_admin_eth0').value.get() == '192.168.0.1' - assert conf2.option('ip_admin_eth0').owner.get() == 'conf1_user' - - -def test_mix_properties_mix_set_value(): - ip_admin_eth0 = NetworkOption('ip_admin_eth1', "ip", multi=True, default=['192.168.1.1']) - netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, properties=('disabled',)) - interface0 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) - ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) - netmask_admin_eth0 = NetmaskOption('netmask_admin_eth1', "mask", multi=True, properties=('disabled',)) - interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) - ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) - netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, properties=('disabled',)) - interface2 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) - conf1 = Config(interface0, name='conf1') - conf2 = Config(interface1, name='conf2') - conf1.property.read_write() - conf2.property.read_write() - mix = MixConfig(interface2, [conf1, conf2]) - mix.property.read_write() - newconf2 = mix.config('conf2') - assert newconf2.value.dict() == {'ip_admin_eth0': ['192.168.1.1']} - ret = mix.value.set('netmask_admin_eth0', ['255.255.255.255'], only_config=True) - assert len(ret) == 2 - assert isinstance(ret[0], PropertiesOptionError) - assert isinstance(ret[1], AttributeError) - del ret[1] - del ret[0] - del ret - ret = mix.value.set('netmask_admin_eth0', ['255.255.255.255'], force_default=True) - assert len(ret) == 2 - assert isinstance(ret[0], AttributeError) - assert isinstance(ret[1], PropertiesOptionError) - del ret[1] - del ret[0] - del ret - ret = mix.value.set('netmask_admin_eth0', ['255.255.255.255'], force_dont_change_value=True) - assert len(ret) == 3 - assert isinstance(ret[0], PropertiesOptionError) - assert isinstance(ret[1], AttributeError) - assert isinstance(ret[2], PropertiesOptionError) - del ret[2] - del ret[1] - del ret[0] - del ret - ret = mix.value.set('netmask_admin_eth0', ['255.255.255.255'], force_default_if_same=True) - assert len(ret) == 2 - assert isinstance(ret[0], AttributeError) - assert isinstance(ret[1], PropertiesOptionError) - del ret[1] - del ret[0] - del ret - ret = mix.value.set('ip_admin_eth0', '255.255.255.255', only_config=True) - assert len(ret) == 2 - assert isinstance(ret[0], AttributeError) - assert isinstance(ret[1], ValueError) - del ret[1] - del ret[0] - del ret - ret = mix.value.set('ip_admin_eth0', '255.255.255.255', force_default=True) - assert len(ret) == 2 - assert isinstance(ret[0], AttributeError) - assert isinstance(ret[1], ValueError) - del ret[1] - del ret[0] - del ret - ret = mix.value.set('ip_admin_eth0', '255.255.255.255', force_dont_change_value=True) - assert len(ret) == 2 - assert isinstance(ret[0], AttributeError) - assert isinstance(ret[1], ValueError) - del ret[1] - del ret[0] - del ret - ret = mix.value.set('ip_admin_eth0', '255.255.255.255', force_default_if_same=True) - assert len(ret) == 2 - assert isinstance(ret[0], AttributeError) - assert isinstance(ret[1], ValueError) - del ret[1] - del ret[0] - del ret - - -def test_mix_different_default(): - ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) - interface0 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0]) - ip_admin_eth0 = NetworkOption('ip_admin_eth1', "ip", multi=True, default=['192.168.1.2']) - interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0]) - ip_admin_eth0 = NetworkOption('ip_admin_eth1', "ip", multi=True, default=['192.168.1.3']) - interface2 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0]) - ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.4']) - ip_admin_eth1 = NetworkOption('ip_admin_eth1', "ip", multi=True, default=['192.168.1.5']) - interface3 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, ip_admin_eth1]) - ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.6']) - interface4 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0]) - conf1 = Config(interface0, name='conf1') - conf1.property.read_write() - conf2 = Config(interface1, name='conf2') - conf2.property.read_write() - mix = MixConfig(interface2, [conf1, conf2], name='submix1') - mix = MixConfig(interface3, [mix], name='submix2') - mix = MixConfig(interface4, [mix]) - mix.property.read_write() - # - assert mix.value.dict() == {'ip_admin_eth0': ['192.168.1.6']} - newsubmix2 = mix.config('submix2') - newsubmix1 = mix.config('submix2.submix1') - newconf1 = mix.config('submix2.submix1.conf1') - newconf2 = mix.config('submix2.submix1.conf2') - assert newsubmix2.value.dict() == {'ip_admin_eth0': ['192.168.1.4'], 'ip_admin_eth1': ['192.168.1.5']} - assert newsubmix1.value.dict() == {'ip_admin_eth1': ['192.168.1.3']} - assert newconf2.value.dict() == {'ip_admin_eth1': ['192.168.1.2']} - assert newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.1']} - # - mix.option('ip_admin_eth0').value.set(['192.168.1.7']) - assert mix.value.dict() == {'ip_admin_eth0': ['192.168.1.7']} - assert newsubmix2.value.dict() == {'ip_admin_eth0': ['192.168.1.7'], 'ip_admin_eth1': ['192.168.1.5']} - assert newsubmix1.value.dict() == {'ip_admin_eth1': ['192.168.1.3']} - assert newconf2.value.dict() == {'ip_admin_eth1': ['192.168.1.2']} - assert newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.7']} - # - newsubmix2.option('ip_admin_eth0').value.set(['192.168.1.8']) - assert mix.value.dict() == {'ip_admin_eth0': ['192.168.1.7']} - assert newsubmix2.value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.5']} - assert newsubmix1.value.dict() == {'ip_admin_eth1': ['192.168.1.3']} - assert newconf2.value.dict() == {'ip_admin_eth1': ['192.168.1.2']} - assert newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.8']} - # - with pytest.raises(AttributeError): - newsubmix1.option('ip_admin_eth0').value.set(['192.168.1.9']) - assert mix.value.dict() == {'ip_admin_eth0': ['192.168.1.7']} - assert newsubmix2.value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.5']} - assert newsubmix1.value.dict() == {'ip_admin_eth1': ['192.168.1.3']} - assert newconf2.value.dict() == {'ip_admin_eth1': ['192.168.1.2']} - assert newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.8']} - # - with pytest.raises(AttributeError): - newconf2.option('ip_admin_eth0').value.set(['192.168.1.9']) - assert mix.value.dict() == {'ip_admin_eth0': ['192.168.1.7']} - assert newsubmix2.value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.5']} - assert newsubmix1.value.dict() == {'ip_admin_eth1': ['192.168.1.3']} - assert newconf2.value.dict() == {'ip_admin_eth1': ['192.168.1.2']} - assert newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.8']} - # - newconf1.option('ip_admin_eth0').value.set(['192.168.1.9']) - assert mix.value.dict() == {'ip_admin_eth0': ['192.168.1.7']} - assert newsubmix2.value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.5']} - assert newsubmix1.value.dict() == {'ip_admin_eth1': ['192.168.1.3']} - assert newconf2.value.dict() == {'ip_admin_eth1': ['192.168.1.2']} - assert newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.9']} - # - with pytest.raises(AttributeError): - mix.option('ip_admin_eth1').value.set(['192.168.1.10']) - assert mix.value.dict() == {'ip_admin_eth0': ['192.168.1.7']} - assert newsubmix2.value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.5']} - assert newsubmix1.value.dict() == {'ip_admin_eth1': ['192.168.1.3']} - assert newconf2.value.dict() == {'ip_admin_eth1': ['192.168.1.2']} - assert newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.9']} - # - newsubmix2.option('ip_admin_eth1').value.set(['192.168.1.10']) - assert mix.value.dict() == {'ip_admin_eth0': ['192.168.1.7']} - assert newsubmix2.value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.10']} - assert newsubmix1.value.dict() == {'ip_admin_eth1': ['192.168.1.10']} - assert newconf2.value.dict() == {'ip_admin_eth1': ['192.168.1.10']} - assert newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.9']} - # - newsubmix1.option('ip_admin_eth1').value.set(['192.168.1.11']) - assert mix.value.dict() == {'ip_admin_eth0': ['192.168.1.7']} - assert newsubmix2.value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.10']} - assert newsubmix1.value.dict() == {'ip_admin_eth1': ['192.168.1.11']} - assert newconf2.value.dict() == {'ip_admin_eth1': ['192.168.1.11']} - assert newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.9']} - # - newconf2.option('ip_admin_eth1').value.set(['192.168.1.12']) - assert mix.value.dict() == {'ip_admin_eth0': ['192.168.1.7']} - assert newsubmix2.value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.10']} - assert newsubmix1.value.dict() == {'ip_admin_eth1': ['192.168.1.11']} - assert newconf2.value.dict() == {'ip_admin_eth1': ['192.168.1.12']} - assert newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.9']} - # - with pytest.raises(AttributeError): - newconf1.option('ip_admin_eth1').value.set(['192.168.1.13']) - assert mix.value.dict() == {'ip_admin_eth0': ['192.168.1.7']} - assert newsubmix2.value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.10']} - assert newsubmix1.value.dict() == {'ip_admin_eth1': ['192.168.1.11']} - assert newconf2.value.dict() == {'ip_admin_eth1': ['192.168.1.12']} - assert newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.9']} - - -def test_mix_different_default_reset(): - ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) - interface0 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0]) - ip_admin_eth0 = NetworkOption('ip_admin_eth1', "ip", multi=True, default=['192.168.1.2']) - interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0]) - ip_admin_eth0 = NetworkOption('ip_admin_eth1', "ip", multi=True, default=['192.168.1.3']) - interface2 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0]) - ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.4']) - ip_admin_eth1 = NetworkOption('ip_admin_eth1', "ip", multi=True, default=['192.168.1.5']) - interface3 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, ip_admin_eth1]) - ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.6']) - interface4 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0]) - conf1 = Config(interface0, name='conf1') - conf1.property.read_write() - conf2 = Config(interface1, name='conf2') - conf2.property.read_write() - mix = MixConfig(interface2, [conf1, conf2], name='submix1') - mix = MixConfig(interface3, [mix], name='submix2') - mix = MixConfig(interface4, [mix]) - mix.property.read_write() - # - mix.option('ip_admin_eth0').value.set(['192.168.1.7']) - submix2 = mix.config('submix2') - submix1 = mix.config('submix2.submix1') - conf1 = mix.config('submix2.submix1.conf1') - conf2 = mix.config('submix2.submix1.conf2') - submix2.option('ip_admin_eth0').value.set(['192.168.1.8']) - submix2.option('ip_admin_eth1').value.set(['192.168.1.10']) - submix1.option('ip_admin_eth1').value.set(['192.168.1.11']) - conf2.option('ip_admin_eth1').value.set(['192.168.1.12']) - conf1.option('ip_admin_eth0').value.set(['192.168.1.9']) - assert mix.value.dict() == {'ip_admin_eth0': ['192.168.1.7']} - assert submix2.value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.10']} - assert submix1.value.dict() == {'ip_admin_eth1': ['192.168.1.11']} - assert conf2.value.dict() == {'ip_admin_eth1': ['192.168.1.12']} - assert conf1.value.dict() == {'ip_admin_eth0': ['192.168.1.9']} - # - mix.value.reset('ip_admin_eth0') - assert mix.value.dict() == {'ip_admin_eth0': ['192.168.1.6']} - assert submix2.value.dict() == {'ip_admin_eth0': ['192.168.1.4'], 'ip_admin_eth1': ['192.168.1.10']} - assert submix1.value.dict() == {'ip_admin_eth1': ['192.168.1.11']} - assert conf2.value.dict() == {'ip_admin_eth1': ['192.168.1.12']} - assert conf1.value.dict() == {'ip_admin_eth0': ['192.168.1.1']} - # - mix.value.reset('ip_admin_eth1') - assert mix.value.dict() == {'ip_admin_eth0': ['192.168.1.6']} - assert submix2.value.dict() == {'ip_admin_eth0': ['192.168.1.4'], 'ip_admin_eth1': ['192.168.1.5']} - assert submix1.value.dict() == {'ip_admin_eth1': ['192.168.1.3']} - assert conf2.value.dict() == {'ip_admin_eth1': ['192.168.1.2']} - assert conf1.value.dict() == {'ip_admin_eth0': ['192.168.1.1']} - - -def test_mix_pop_config(): - od = make_description() - config1 = Config(od, name='config1') - config2 = Config(od, name='config2') - mix = MixConfig(od, [config1, config2]) - mix.option('od1.i1').value.set(2) - # - assert len(list(mix.config.list())) == 2 - newconfig1 = mix.config('config1') - assert newconfig1.value.dict() == {'od1.i1': 2, 'od1.i2': 1, 'od1.i3': None, 'od1.i4': 2, 'od1.i5': [2], 'od1.i6': None} - newconf1 = mix.config.remove('config1') - try: - mix.config('config1') - except ConfigError: - pass - else: - raise Exception('must raise') - assert newconf1.value.dict() == {'od1.i1': None, 'od1.i2': 1, 'od1.i3': None, 'od1.i4': 2, 'od1.i5': [2], 'od1.i6': None} - # - assert len(list(mix.config.list())) == 1 - with pytest.raises(ConfigError): - mix.config.remove('newconf1') - - -def test_mix_add_config(): - od = make_description() - config1 = Config(od, name='config1') - config2 = Config(od, name='config2') - mix = MixConfig(od, [config1, config2]) - mix.option('od1.i1').value.set(2) - # - assert len(list(mix.config.list())) == 2 - config = Config(od, name='new') - assert config.value.dict() == {'od1.i1': None, 'od1.i2': 1, 'od1.i3': None, 'od1.i4': 2, 'od1.i5': [2], 'od1.i6': None} - mix.config.add(config) - # - assert len(list(mix.config.list())) == 3 - assert config.value.dict() == {'od1.i1': 2, 'od1.i2': 1, 'od1.i3': None, 'od1.i4': 2, 'od1.i5': [2], 'od1.i6': None} - # - with pytest.raises(ConflictError): - mix.config.add(config) - - -def test_mix_add_config_readd(): - od = make_description() - mix = MixConfig(od, []) - mix2 = MixConfig(od, []) - # - config = Config(od, name='new') - mix.config.add(config) - mix2.config.add(config) - assert len(list(config.config.parents())) == 2 - - -def test_mix_new_config_readd(): - od = make_description() - mix = MixConfig(od, []) - assert len(list(mix.config.list())) == 0 - mix2 = mix.config.new('mix2') - assert len(list(mix.config.list())) == 1 - - -def test_meta_new_mixconfig(): - od = make_description() - cfg = Config(od, name='cfg1') - meta = MetaConfig([cfg]) - mix = meta.config.new('mixconfig', type="mixconfig") - assert isinstance(mix, MixConfig) - - -def test_meta_mixconfig_parents(): - od = make_description() - cfg = Config(od, name='cfg1') - meta = MetaConfig([cfg]) - mix = meta.config.new('mixconfig', type="mixconfig") - parents = mix.config.parents() - assert len(parents) == 1 -# assert parents[0].config.get() == meta +#def test_mix_name(): +# mix = make_mixconfig(True) +# assert mix.config.path() == 'doublemix' +# ret = mix.config('mix') +# assert ret.config.path() == 'doublemix.mix' +# ret = mix.config('mix.conf1') +# assert ret.config.path() == 'doublemix.mix.conf1' +# ret = mix.config('mix.conf2') +# assert ret.config.path() == 'doublemix.mix.conf2' +# +# +#def test_mix_not_group(): +# i1 = IntOption('i1', '') +# od1 = OptionDescription('od1', '', [i1]) +# od2 = OptionDescription('od2', '', [od1]) +# cfg = Config(od2, name='conf1') +# grp = GroupConfig([cfg]) +# with pytest.raises(TypeError): +# MixConfig(od2, [grp], name='error') +## assert not list_sessions() +# +# +#def test_unknown_config(): +# mix = make_mixconfig() +# with pytest.raises(ConfigError): +# mix.config('unknown') +# +# +#def test_none(): +# mix = make_mixconfig() +# newconf1 = mix.config('conf1') +# newconf2 = mix.config('conf2') +# assert mix.option('od1.i3').value.get() is newconf1.option('od1.i3').value.get() is newconf2.option('od1.i3').value.get() is None +# assert mix.option('od1.i3').owner.get() is newconf1.option('od1.i3').owner.get() is newconf2.option('od1.i3').owner.get() is owners.default +# # +# mix.option('od1.i3').value.set(3) +# assert mix.option('od1.i3').value.get() == newconf1.option('od1.i3').value.get() == newconf2.option('od1.i3').value.get() == 3 +# assert mix.option('od1.i3').owner.get() is newconf1.option('od1.i3').owner.get() is newconf2.option('od1.i3').owner.get() is owners.mix1 +# # +# newconf1.option('od1.i3').value.set(2) +# assert mix.option('od1.i3').value.get() == newconf2.option('od1.i3').value.get() == 3 +# assert newconf1.option('od1.i3').value.get() == 2 +# assert mix.option('od1.i3').owner.get() is newconf2.option('od1.i3').owner.get() is owners.mix1 +# assert newconf1.option('od1.i3').owner.get() is owners.user +# # +# mix.option('od1.i3').value.set(4) +# assert mix.option('od1.i3').value.get() == newconf2.option('od1.i3').value.get() == 4 +# assert newconf1.option('od1.i3').value.get() == 2 +# assert mix.option('od1.i3').owner.get() is newconf2.option('od1.i3').owner.get() is owners.mix1 +# assert newconf1.option('od1.i3').owner.get() is owners.user +# # +# mix.option('od1.i3').value.reset() +# assert mix.option('od1.i3').value.get() is newconf2.option('od1.i3').value.get() is None +# assert newconf1.option('od1.i3').value.get() == 2 +# assert mix.option('od1.i3').owner.get() is newconf2.option('od1.i3').owner.get() is owners.default +# assert newconf1.option('od1.i3').owner.get() is owners.user +# # +# newconf1.option('od1.i3').value.reset() +# assert mix.option('od1.i3').value.get() is newconf1.option('od1.i3').value.get() is newconf2.option('od1.i3').value.get() is None +# assert mix.option('od1.i3').owner.get() is newconf1.option('od1.i3').owner.get() is newconf2.option('od1.i3').owner.get() is owners.default +# # +# assert mix.config.name() == mix.config.name() +# +# +#def test_reset(): +# mix = make_mixconfig() +# assert mix.option('od1.i2').value.get() == 1 +# mix.option('od1.i2').value.set(2) +# newconf1 = mix.config('conf1') +# newconf2 = mix.config('conf2') +# newconf1.option('od1.i2').value.set(3) +# assert mix.option('od1.i2').value.get() == 2 +# assert newconf1.option('od1.i2').value.get() == 3 +# assert newconf2.option('od1.i2').value.get() == 2 +# mix.config.reset() +# assert mix.option('od1.i2').value.get() == 1 +# assert newconf1.option('od1.i2').value.get() == 3 +# assert newconf2.option('od1.i2').value.get() == 1 +# +# +#def test_default(): +# mix = make_mixconfig() +# newconf1 = mix.config('conf1') +# newconf2 = mix.config('conf2') +# assert mix.option('od1.i2').value.get() == newconf1.option('od1.i2').value.get() == newconf2.option('od1.i2').value.get() == 1 +# assert mix.option('od1.i2').owner.get() is newconf1.option('od1.i2').owner.get() is newconf2.option('od1.i2').owner.get() is owners.default +# # +# mix.option('od1.i2').value.set(3) +# assert mix.option('od1.i2').value.get() == newconf1.option('od1.i2').value.get() == newconf2.option('od1.i2').value.get() == 3 +# assert mix.option('od1.i2').owner.get() is newconf1.option('od1.i2').owner.get() is newconf2.option('od1.i2').owner.get() is owners.mix1 +# # +# newconf1.option('od1.i2').value.set(2) +# assert mix.option('od1.i2').value.get() == newconf2.option('od1.i2').value.get() == 3 +# assert newconf1.option('od1.i2').value.get() == 2 +# assert mix.option('od1.i2').owner.get() is newconf2.option('od1.i2').owner.get() is owners.mix1 +# assert newconf1.option('od1.i2').owner.get() is owners.user +# # +# mix.option('od1.i2').value.set(4) +# assert mix.option('od1.i2').value.get() == newconf2.option('od1.i2').value.get() == 4 +# assert newconf1.option('od1.i2').value.get() == 2 +# assert mix.option('od1.i2').owner.get() is newconf2.option('od1.i2').owner.get() is owners.mix1 +# assert newconf1.option('od1.i2').owner.get() is owners.user +# # +# mix.option('od1.i2').value.reset() +# assert mix.option('od1.i2').value.get() == newconf2.option('od1.i2').value.get() == 1 +# assert newconf1.option('od1.i2').value.get() == 2 +# assert mix.option('od1.i2').owner.get() is newconf2.option('od1.i2').owner.get() is owners.default +# assert newconf1.option('od1.i2').owner.get() is owners.user +# # +# newconf1.option('od1.i2').value.reset() +# assert mix.option('od1.i2').value.get() == newconf1.option('od1.i2').value.get() == newconf2.option('od1.i2').value.get() == 1 +# assert mix.option('od1.i2').owner.get() is newconf1.option('od1.i2').owner.get() is newconf2.option('od1.i2').owner.get() is owners.default +# +# +#def test_contexts(): +# mix = make_mixconfig() +# errors = mix.value.set('od1.i2', 6, only_config=True) +# newconf1 = mix.config('conf1') +# assert mix.option('od1.i2').value.get() == 1 +# assert mix.option('od1.i2').owner.get() == owners.default +# assert newconf1.option('od1.i2').value.get() == newconf1.option('od1.i2').value.get() == 6 +# assert newconf1.option('od1.i2').owner.get() == newconf1.option('od1.i2').owner.get() is owners.user +# assert len(errors) == 0 +# +# +# +#def test_find(): +# mix = make_mixconfig() +# ret = list(mix.option.find('i2')) +# assert len(ret) == 1 +# assert 1 == ret[0].value.get() +# ret = mix.option.find('i2', first=True) +# assert 1 == ret.value.get() +# assert mix.value.dict() == {'od1.i4': 2, 'od1.i1': None, 'od1.i3': None, +# 'od1.i2': 1, 'od1.i5': [2]} +# +# +#def test_mix_mix(): +# mix = make_mixconfig(double=True) +# newmix = mix.config('mix') +# newconf1 = mix.config('mix.conf1') +# newconf2 = mix.config('mix.conf2') +# assert mix.option('od1.i2').value.get() == newmix.option('od1.i2').value.get() == newconf1.option('od1.i2').value.get() == newconf2.option('od1.i2').value.get() == 1 +# assert mix.option('od1.i2').owner.get() is newmix.option('od1.i2').owner.get() is newconf1.option('od1.i2').owner.get() is newconf2.option('od1.i2').owner.get() is owners.default +# # +# mix.option('od1.i2').value.set(3) +# assert mix.option('od1.i2').value.get() == newmix.option('od1.i2').value.get() == newconf1.option('od1.i2').value.get() == newconf2.option('od1.i2').value.get() == 3 +# assert mix.option('od1.i2').owner.get() is newmix.option('od1.i2').owner.get() is newconf1.option('od1.i2').owner.get() is newconf2.option('od1.i2').owner.get() is owners.mix1 +# # +# newconf1.option('od1.i2').value.set(2) +# assert mix.option('od1.i2').value.get() == newmix.option('od1.i2').value.get() == newconf2.option('od1.i2').value.get() == 3 +# assert newconf1.option('od1.i2').value.get() == 2 +# assert mix.option('od1.i2').owner.get() is newmix.option('od1.i2').owner.get() is newconf2.option('od1.i2').owner.get() is owners.mix1 +# assert newconf1.option('od1.i2').owner.get() is owners.user +# # +# newmix.option('od1.i2').value.set(4) +# assert mix.option('od1.i2').value.get() == 3 +# assert newmix.option('od1.i2').value.get() == newconf2.option('od1.i2').value.get() == 4 +# assert newconf1.option('od1.i2').value.get() == 2 +# assert mix.option('od1.i2').owner.get() is owners.mix1 +# assert newmix.option('od1.i2').owner.get() is newconf2.option('od1.i2').owner.get() is owners.mix2 +# assert newconf1.option('od1.i2').owner.get() is owners.user +# # +# newmix.option('od1.i2').value.reset() +# assert mix.option('od1.i2').value.get() == newmix.option('od1.i2').value.get() == newconf2.option('od1.i2').value.get() == 3 +# assert newconf1.option('od1.i2').value.get() == 2 +# assert mix.option('od1.i2').owner.get() is newmix.option('od1.i2').owner.get() is newconf2.option('od1.i2').owner.get() is owners.mix1 +# assert newconf1.option('od1.i2').owner.get() is owners.user +# # +# mix.option('od1.i2').value.reset() +# assert mix.option('od1.i2').value.get() == newmix.option('od1.i2').value.get() == newconf2.option('od1.i2').value.get() == 1 +# assert newconf1.option('od1.i2').value.get() == 2 +# assert mix.option('od1.i2').owner.get() is newmix.option('od1.i2').owner.get() is newconf2.option('od1.i2').owner.get() is owners.default +# assert newconf1.option('od1.i2').owner.get() is owners.user +# # +# newconf1.option('od1.i2').value.reset() +# assert mix.option('od1.i2').value.get() == newmix.option('od1.i2').value.get() == newconf1.option('od1.i2').value.get() == newconf2.option('od1.i2').value.get() == 1 +# assert mix.option('od1.i2').owner.get() is newmix.option('od1.i2').owner.get() is newconf1.option('od1.i2').owner.get() is newconf2.option('od1.i2').owner.get() is owners.default +# +# +#def test_mix_mix_set(): +# mix = make_mixconfig(double=True) +# errors1 = mix.value.set('od1.i1', 7, only_config=True) +# errors2 = mix.value.set('od1.i6', 7, only_config=True) +# assert len(errors1) == 0 +# assert len(errors2) == 2 +# ret = mix.config('mix.conf1') +# conf1 = ret._config_bag.context +# ret = mix.config('mix.conf2') +# conf2 = ret._config_bag.context +# newconf1 = mix.config('mix.conf1') +# newconf2 = mix.config('mix.conf2') +# assert newconf1.option('od1.i1').value.get() == newconf2.option('od1.i1').value.get() == 7 +# # +# dconfigs = [] +# ret = mix.config.find('i1', value=7) +# for conf in ret.config.list(): +# dconfigs.append(conf._config_bag.context) +# assert [conf1, conf2] == dconfigs +# newconf1.option('od1.i1').value.set(8) +# # +# dconfigs = [] +# ret = mix.config.find('i1') +# for conf in ret.config.list(): +# dconfigs.append(conf._config_bag.context) +# assert [conf1, conf2] == dconfigs +# ret = mix.config.find('i1', value=7) +# assert conf2 == list(ret.config.list())[0]._config_bag.context +# ret = mix.config.find('i1', value=8) +# assert conf1 == list(ret.config.list())[0]._config_bag.context +# # +# dconfigs = [] +# ret = mix.config.find('i5', value=2) +# for conf in ret.config.list(): +# dconfigs.append(conf._config_bag.context) +# assert [conf1, conf2] == dconfigs +# # +# with pytest.raises(AttributeError): +# mix.config.find('i1', value=10) +# with pytest.raises(AttributeError): +# mix.config.find('not', value=10) +# with pytest.raises(AttributeError): +# mix.config.find('i6') +# with pytest.raises(ValueError): +# mix.value.set('od1.i6', 7, only_config=True, force_default=True) +# with pytest.raises(ValueError): +# mix.value.set('od1.i6', 7, only_config=True, force_default_if_same=True) +# with pytest.raises(ValueError): +# mix.value.set('od1.i6', 7, only_config=True, force_dont_change_value=True) +# +# +#def test_mix_unconsistent(): +# i1 = IntOption('i1', '') +# i2 = IntOption('i2', '', default=1) +# i3 = IntOption('i3', '') +# i4 = IntOption('i4', '', default=2) +# od1 = OptionDescription('od1', '', [i1, i2, i3, i4]) +# od2 = OptionDescription('od2', '', [od1]) +# od3 = OptionDescription('od3', '', [od1]) +# conf1 = Config(od2, name='conf1') +# conf2 = Config(od2, name='conf2') +# conf3 = Config(od2, name='conf3') +# i5 = IntOption('i5', '') +# od4 = OptionDescription('od4', '', [i5]) +# conf4 = Config(od4, name='conf4') +# mix = MixConfig(od2, [conf1, conf2]) +# mix.owner.set(owners.mix1) +# with pytest.raises(TypeError): +# MixConfig(od2, "string", name='error') +# # same descr but conf1 already in mix +# assert len(list(conf1.config.parents())) == 1 +# assert len(list(conf3.config.parents())) == 0 +# new_mix = MixConfig(od2, [conf1, conf3]) +# assert len(list(conf1.config.parents())) == 2 +# assert len(list(conf3.config.parents())) == 1 +# # not same descr +# tmix = MixConfig(od2, [conf3, conf4]) +# +# +#def test_mix_leadership(): +# ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) +# netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) +# interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) +# od = OptionDescription('root', '', [interface1]) +# conf1 = Config(od, name='conf1') +# conf2 = Config(od, name='conf2') +# mix = MixConfig(od, [conf1, conf2]) +# mix.property.read_only() +# ret = mix.config.find('ip_admin_eth0') +# configs = ret.config.list() +# assert len(configs) == 2 +# assert conf1._config_bag.context == configs[0]._config_bag.context +# assert conf2._config_bag.context == configs[1]._config_bag.context +# ret = mix.config.find('netmask_admin_eth0') +# configs = ret.config.list() +# assert len(configs) == 2 +# assert conf1._config_bag.context == configs[0]._config_bag.context +# assert conf2._config_bag.context == configs[1]._config_bag.context +# mix.property.read_write() +# with pytest.raises(AttributeError): +# mix.config.find('netmask_admin_eth0') +# ret = mix.unrestraint.config.find('netmask_admin_eth0') +# configs = ret.config.list() +# assert len(configs) == 2 +# assert conf1._config_bag.context == configs[0]._config_bag.context +# assert conf2._config_bag.context == configs[1]._config_bag.context +# mix.property.read_only() +# ret = mix.config.find('netmask_admin_eth0') +# configs = ret.config.list() +# assert len(configs) == 2 +# assert conf1._config_bag.context == configs[0]._config_bag.context +# assert conf2._config_bag.context == configs[1]._config_bag.context +# +# +#def test_mix_leadership_value2(): +# ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) +# netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) +# interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) +# od = OptionDescription('root', '', [interface1]) +# conf1 = Config(od, name='conf1') +# conf2 = Config(od, name='conf2') +# mix = MixConfig(od, [conf1, conf2], name="mix") +# newconf1 = mix.config('conf1') +# newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.8']) +# assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None +# #FIXME devrait raise ! assert newconf1.option('ip_admin_eth0.ip_admin_eth0', 0).value.get() == None +# # +# newconf1.option('ip_admin_eth0.ip_admin_eth0').value.reset() +# # +# mix.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) +# assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None +# mix.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0') +# assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0' +# mix.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.0.0') +# assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0' +# # +# newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) +# assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0' +# +# +#def test_mix_leadership_value_default(): +# ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) +# netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True) +# interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) +# od = OptionDescription('root', '', [interface1]) +# conf1 = Config(od, name='conf1') +# conf2 = Config(od, name='conf2') +# mix = MixConfig(od, [conf1, conf2]) +# newconf1 = mix.config('conf1') +# assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None +# # +# mix.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) +# assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None +# # +# mix.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0') +# assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0' +# # +# mix.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.0.0') +# assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0' +# # +# newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) +# assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0' +# +# +#def test_mix_leadership_owners(): +# ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) +# netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) +# interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) +# od = OptionDescription('root', '', [interface1]) +# conf1 = Config(od, name='conf1') +# conf2 = Config(od, name='conf2') +# mix = MixConfig(od, [conf1, conf2]) +# mix.owner.set(owners.mix1) +# newconf1 = mix.config('conf1') +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault() +# with pytest.raises(LeadershipError): +# newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault() +# # +# newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.user +# assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault() +# # +# newconf1.option('ip_admin_eth0.ip_admin_eth0').value.reset() +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault() +# # +# mix.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.mix1 +# assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault() +# # +# mix.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0') +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.mix1 +# assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.mix1 +# # +# mix.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.0.0') +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.mix1 +# assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.mix1 +# # +# newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.user +# assert newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.mix1 +# +# +#def test_mix_force_default(): +# ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) +# netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) +# interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) +# od = OptionDescription('root', '', [interface1]) +# conf1 = Config(od, name='conf1') +# conf2 = Config(od, name='conf2') +# mix = MixConfig(od, [conf1, conf2]) +# mix.property.read_write() +# mix.owner.set('mix1') +# assert mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# newconf1 = mix.config('conf1') +# newconf2 = mix.config('conf2') +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# # +# errors = mix.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.1']) +# assert len(errors) == 0 +# assert mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] +# # +# newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2']) +# assert mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2'] +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] +# # +# errors = mix.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.3']) +# assert len(errors) == 0 +# assert mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3'] +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2'] +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3'] +# # +# errors = mix.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_default=True) +# assert len(errors) == 0 +# assert mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] +# +# +#def test_mix_force_dont_change_value(): +# ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) +# netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) +# interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) +# od = OptionDescription('root', '', [interface1]) +# conf1 = Config(od, name='conf1') +# conf2 = Config(od, name='conf2') +# mix = MixConfig(od, [conf1, conf2]) +# mix.property.read_write() +# mix.owner.set('mix1') +# assert mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# newconf1 = mix.config('conf1') +# newconf2 = mix.config('conf2') +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.4']) +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault() +# errors = mix.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_dont_change_value=True) +# assert len(errors) == 0 +# assert mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user +# +# +#def test_mix_force_default_if_same(): +# ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) +# netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) +# interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) +# od = OptionDescription('root', '', [interface1]) +# conf1 = Config(od, name='conf1') +# conf2 = Config(od, name='conf2') +# mix = MixConfig(od, [conf1, conf2]) +# mix.property.read_write() +# mix.owner.set('mix1') +# # +# assert mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# newconf1 = mix.config('conf1') +# newconf2 = mix.config('conf2') +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# # +# newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.4']) +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault() +# errors = mix.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_default_if_same=True) +# assert len(errors) == 0 +# assert mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.mix1 +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.mix1 +# # +# newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.3']) +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3'] +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.mix1 +# errors = mix.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.5'], force_default_if_same=True) +# assert len(errors) == 0 +# assert mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.5'] +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3'] +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.5'] +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.mix1 +# +# +#def test_mix_force_default_if_same_and_dont_change(): +# ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) +# netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) +# interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) +# od = OptionDescription('root', '', [interface1]) +# conf1 = Config(od, name='conf1') +# conf2 = Config(od, name='conf2') +# mix = MixConfig(od, [conf1, conf2]) +# mix.property.read_write() +# mix.owner.set('mix1') +# # +# assert mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# newconf1 = mix.config('conf1') +# newconf2 = mix.config('conf2') +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# # +# newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.4']) +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault() +# errors = mix.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_default_if_same=True, force_dont_change_value=True) +# assert len(errors) == 0 +# assert mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.mix1 +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user +# # +# newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.3']) +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3'] +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user +# errors = mix.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.5'], force_default_if_same=True, force_dont_change_value=True) +# assert len(errors) == 0 +# assert mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.5'] +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3'] +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user +# +# +# +#def test_mix_force_default_and_dont_change(): +# ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) +# netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) +# interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) +# od = OptionDescription('root', '', [interface1]) +# conf1 = Config(od, name='rconf1') +# conf2 = Config(od, name='rconf2') +# mix = MixConfig(od, [conf1, conf2]) +# mix.property.read_write() +# mix.owner.set('mix1') +# with pytest.raises(ValueError): +# mix.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_default=True, force_dont_change_value=True) +# +# +#def test_mix_properties_mix(): +# ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) +# netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, validators=[Calculation(valid_network_netmask, Params((ParamOption(ip_admin_eth0), ParamSelfOption())))]) +# interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0], properties=('disabled',)) +# od = OptionDescription('root', '', [interface1]) +# conf1 = Config(od, name='conf1') +# conf2 = Config(od, name='conf2') +# conf1.property.read_write() +# conf2.property.read_write() +# mix = MixConfig(od, [conf1, conf2]) +# mix.property.read_write() +# newconf1 = mix.config('conf1') +# assert newconf1.value.dict() == {} +# +# +#def test_mix_exception_mix(): +# ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) +# netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", Calculation(raise_exception), multi=True, validators=[Calculation(valid_network_netmask, Params((ParamOption(ip_admin_eth0), ParamSelfOption())))]) +# interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) +# od = OptionDescription('root', '', [interface1]) +# conf1 = Config(od, name='conf1') +# conf2 = Config(od, name='conf2') +# mix = MixConfig(od, [conf1, conf2]) +# mix.property.read_write() +# with pytest.raises(ConfigError): +# conf1.value.dict() +# +# +# +#def test_mix_callback(): +# val1 = StrOption('val1', "", 'val') +# val2 = StrOption('val2', "", Calculation(return_value, Params(ParamOption(val1)))) +# val3 = StrOption('val3', "", Calculation(return_value, Params(ParamValue('yes')))) +# val4 = StrOption('val4', "", Calculation(return_value, Params(kwargs={'value': ParamOption(val1)}))) +# val5 = StrOption('val5', "", Calculation(return_value, Params(kwargs={'value': ParamValue('yes')}))) +# maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4, val5]) +# cfg = Config(maconfig, name='cfg') +# mix = MixConfig(maconfig, [cfg]) +# mix.property.read_write() +# newcfg = mix.config('cfg') +# assert newcfg.value.dict() == {'val3': 'yes', 'val2': 'val', 'val1': 'val', 'val5': 'yes', 'val4': 'val'} +# newcfg.option('val1').value.set('new') +# assert newcfg.value.dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new'} +# newcfg.option('val1').value.reset() +# mix.option('val1').value.set('new') +# assert newcfg.value.dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new'} +# newcfg.option('val4').value.set('new1') +# assert newcfg.value.dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new1'} +# newcfg.option('val4').value.reset() +# mix.option('val4').value.set('new1') +# assert newcfg.value.dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new1'} +# mix.option('val4').value.reset() +# +# +#def test_mix_callback_follower(): +# val = StrOption('val', "", default='val') +# val1 = StrOption('val1', "", [Calculation(return_value, Params(ParamOption(val)))], multi=True) +# val3 = StrOption('val2', "", Calculation(return_value, Params(ParamOption(val1))), multi=True) +# val4 = StrOption('val3', "", Calculation(return_value, Params(ParamOption(val1))), multi=True) +# interface1 = Leadership('val1', '', [val1, val3, val4]) +# od = OptionDescription('root', '', [interface1]) +# maconfig = OptionDescription('rootconfig', '', [val, interface1]) +# cfg = Config(maconfig, name='cfg1') +# mix = MixConfig(maconfig, [cfg]) +# mix.property.read_write() +# newcfg1 = mix.config('cfg1') +# assert newcfg1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val', 'val1.val2': 'val', 'val1.val3': 'val'}]} +# # +# newcfg1.option('val').value.set('val1') +# assert newcfg1.value.dict() == {'val': 'val1', 'val1.val1': [{'val1.val1': 'val1', 'val1.val2': 'val1', 'val1.val3': 'val1'}]} +# # +# newcfg1.option('val').value.reset() +# mix.option('val').value.set('val1') +# assert newcfg1.value.dict() == {'val': 'val1', 'val1.val1': [{'val1.val1': 'val1', 'val1.val2': 'val1', 'val1.val3': 'val1'}]} +# # +# mix.option('val').value.reset() +# newcfg1.option('val1.val2', 0).value.set('val2') +# assert newcfg1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val', 'val1.val2': 'val2', 'val1.val3': 'val'}]} +# # +# newcfg1.option('val1.val2', 0).value.reset() +# assert newcfg1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val', 'val1.val2': 'val', 'val1.val3': 'val'}]} +# # +# mix.option('val1.val2', 0).value.set('val2') +# assert newcfg1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val', 'val1.val2': 'val2', 'val1.val3': 'val'}]} +# # +# mix.option('val1.val1').value.set(['val']) +# assert newcfg1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val', 'val1.val2': 'val2', 'val1.val3': 'val'}]} +# # +# newcfg1.option('val1.val3', 0).value.set('val6') +# assert newcfg1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val', 'val1.val2': 'val2', 'val1.val3': 'val6'}]} +# # +# mix.option('val1.val2', 0).value.reset() +# newcfg1.option('val1.val3', 0).value.reset() +# newcfg1.option('val1.val1').value.set(['val3']) +# assert newcfg1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val3', 'val1.val2': 'val3', 'val1.val3': 'val3'}]} +# # +# newcfg1.option('val1.val1').value.reset() +# assert newcfg1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val', 'val1.val2': 'val', 'val1.val3': 'val'}]} +# # +# mix.option('val1.val1').value.set(['val3']) +# assert newcfg1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val3', 'val1.val2': 'val3', 'val1.val3': 'val3'}]} +# # +# newcfg1.option('val1.val2', 0).value.set('val2') +# assert newcfg1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val3', 'val1.val2': 'val2', 'val1.val3': 'val3'}]} +# # +# mix.option('val1.val1').value.set(['val3', 'rah']) +# assert newcfg1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val3', 'val1.val2': 'val2', 'val1.val3': 'val3'}, {'val1.val1': 'rah', 'val1.val2': 'rah', 'val1.val3': 'rah'}]} +# # +# mix.option('val1.val1').value.pop(1) +# mix.option('val1.val1').value.set(['val4']) +# assert newcfg1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val4', 'val1.val2': 'val2', 'val1.val3': 'val4'}]} +# +# +#def test_meta_reset(): +# ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) +# netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) +# interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) +# od0 = OptionDescription('root', '', [interface1]) +# ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) +# netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) +# interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) +# od1 = OptionDescription('root', '', [interface1]) +# ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True) +# netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',)) +# interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) +# od2 = OptionDescription('root', '', [interface1]) +# conf1 = Config(od0, name='conf1') +# conf2 = Config(od1, name='conf2') +# mix = MixConfig(od2, [conf1, conf2]) +# mix.property.read_write() +# mix.owner.set('mix1') +# assert mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# newconf1 = mix.config('conf1') +# newconf2 = mix.config('conf2') +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# errors = mix.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.1']) +# assert len(errors) == 0 +# assert mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] +# newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2']) +# assert mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2'] +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] +# mix.value.reset('ip_admin_eth0.ip_admin_eth0') +# assert mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# assert newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# assert newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] +# +# +#def test_mix_properties_mix_copy(): +# ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) +# netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, properties=('disabled',)) +# interface0 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) +# ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) +# netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, properties=('disabled',)) +# interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) +# ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) +# netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, properties=('disabled',)) +# interface2 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) +# conf1 = Config(interface0, name='conf1') +# conf2 = Config(interface1, name='conf2') +# conf1.property.read_write() +# conf2.property.read_write() +# mix = MixConfig(interface2, [conf1, conf2], name='mix1') +# mix.property.read_write() +# +# newconf1 = mix.config('conf1') +# conf3 = newconf1.config.copy(name='conf3') +# newconf3 = mix.config('conf3') +# mix2 = list(conf3.config.parents()) +# assert len(mix2) == 1 +# assert mix.config.name() == mix2[0].config.name() +# +# newconf2 = mix.config('conf2') +# assert newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.1']} +# assert conf2.value.dict() == {'ip_admin_eth0': ['192.168.1.1']} +# assert newconf3.value.dict() == {'ip_admin_eth0': ['192.168.1.1']} +# mix.option('ip_admin_eth0').value.set(['192.168.1.2']) +# assert newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.2']} +# assert conf2.value.dict() == {'ip_admin_eth0': ['192.168.1.2']} +# assert newconf3.value.dict() == {'ip_admin_eth0': ['192.168.1.2']} +# ret = mix.value.set('ip_admin_eth0', ['192.168.1.3'], force_default_if_same=True) +# assert newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.3']} +# assert conf2.value.dict() == {'ip_admin_eth0': ['192.168.1.3']} +# assert newconf3.value.dict() == {'ip_admin_eth0': ['192.168.1.3']} +# +# +#def test_mix_properties_mix_deepcopy(): +# ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) +# netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, +# properties=('disabled',)) +# interface0 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) +# ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) +# netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, +# properties=('disabled',)) +# interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) +# ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) +# netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, +# properties=('disabled',)) +# interface2 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) +# conf1 = Config(interface0, name='conf1') +# conf2 = Config(interface1, name='conf2') +# conf1.property.read_write() +# conf2.property.read_write() +# mix = MixConfig(interface2, [conf1, conf2]) +# mix.permissive.add('hidden') +# mix.property.read_write() +# +# newconf1 = mix.config('conf1') +# newconf2 = mix.config('conf2') +# mix2 = newconf1.config.deepcopy(name='conf3') +# newconf3 = mix2.config('conf3') +# assert mix != mix2 +# assert mix.permissive.get() == mix2.permissive.get() +# +# assert newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.1']} +# assert newconf2.value.dict() == {'ip_admin_eth0': ['192.168.1.1']} +# assert newconf3.value.dict() == {'ip_admin_eth0': ['192.168.1.1']} +# mix.option('ip_admin_eth0').value.set(['192.168.1.2']) +# assert newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.2']} +# assert newconf2.value.dict() == {'ip_admin_eth0': ['192.168.1.2']} +# assert newconf3.value.dict() == {'ip_admin_eth0': ['192.168.1.1']} +# mix.value.set('ip_admin_eth0', ['192.168.1.3'], force_default_if_same=True) +# assert newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.3']} +# assert newconf2.value.dict() == {'ip_admin_eth0': ['192.168.1.3']} +# assert newconf3.value.dict() == {'ip_admin_eth0': ['192.168.1.1']} +# +# +#def test_mix_properties_submix_deepcopy(): +# ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) +# netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, +# properties=('disabled',)) +# interface0 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) +# ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) +# netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, +# properties=('disabled',)) +# interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) +# ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) +# netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, +# properties=('disabled',)) +# interface2 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) +# conf1 = Config(interface0, name='conf1') +# conf1.property.read_write() +# mix1 = MixConfig(interface1, [conf1], name='mix1') +# mix2 = MixConfig(interface2, [mix1], name='mix2') +# mix_copy = conf1.config.deepcopy(name='conf2', +# metaconfig_prefix='copy_') +# assert mix_copy.config.name() == 'copy_mix2' +# ret1 = mix_copy.config('copy_mix1') +# assert ret1.config.name() == 'copy_mix1' +# ret2 = mix_copy.config('copy_mix1.conf2') +# assert ret2.config.name() == 'conf2' +# +# +#def test_mix_properties_submix_deepcopy_owner(): +# ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip") +# netmask_admin_eth0 = NetmaskOption('netmask_admin_eth1', "mask") +# interface0 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) +# ip_admin_eth0 = NetworkOption('ip_admin_eth1', "ip") +# netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask") +# interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) +# ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip") +# netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask") +# interface2 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) +# conf1 = Config(interface0, name='conf1') +# conf1.owner.set('conf1_user') +# conf1.property.read_write() +# mix1 = MixConfig(interface1, [conf1], name='mix1') +# mix1.owner.set('mix1_user') +# mix2 = MixConfig(interface2, [mix1], name='mix2') +# mix2.owner.set('mix2_user') +# # +# conf1.option('ip_admin_eth0').value.set('192.168.0.1') +# assert conf1.option('ip_admin_eth0').owner.get() == 'conf1_user' +# mix2.option('ip_admin_eth0').value.set('192.168.0.3') +# assert mix2.option('ip_admin_eth0').owner.get() == 'mix2_user' +# # +# mix2_copy = conf1.config.deepcopy(name='conf2', +# metaconfig_prefix='copy_') +# mix2_copy.option('netmask_admin_eth0').value.set('255.255.255.255') +# assert mix2_copy.option('ip_admin_eth0').value.get() == '192.168.0.3' +# assert mix2_copy.option('ip_admin_eth0').owner.get() == 'mix2_user' +# assert mix2_copy.option('netmask_admin_eth0').owner.get() == 'mix2_user' +# # +# mix1_copy = mix2_copy.config('copy_mix1') +# mix1_copy.option('netmask_admin_eth0').value.set('255.255.255.255') +# # +# conf2 = mix1_copy.config('conf2') +# conf2.owner.set('conf2_user') +# conf2.option('netmask_admin_eth1').value.set('255.255.255.255') +# assert conf2.option('netmask_admin_eth1').owner.get() == 'conf2_user' +# assert conf2.option('ip_admin_eth0').value.get() == '192.168.0.1' +# assert conf2.option('ip_admin_eth0').owner.get() == 'conf1_user' +# +# +#def test_mix_properties_mix_set_value(): +# ip_admin_eth0 = NetworkOption('ip_admin_eth1', "ip", multi=True, default=['192.168.1.1']) +# netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, properties=('disabled',)) +# interface0 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) +# ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) +# netmask_admin_eth0 = NetmaskOption('netmask_admin_eth1', "mask", multi=True, properties=('disabled',)) +# interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) +# ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) +# netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, properties=('disabled',)) +# interface2 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) +# conf1 = Config(interface0, name='conf1') +# conf2 = Config(interface1, name='conf2') +# conf1.property.read_write() +# conf2.property.read_write() +# mix = MixConfig(interface2, [conf1, conf2]) +# mix.property.read_write() +# newconf2 = mix.config('conf2') +# assert newconf2.value.dict() == {'ip_admin_eth0': ['192.168.1.1']} +# ret = mix.value.set('netmask_admin_eth0', ['255.255.255.255'], only_config=True) +# assert len(ret) == 2 +# assert isinstance(ret[0], PropertiesOptionError) +# assert isinstance(ret[1], AttributeError) +# del ret[1] +# del ret[0] +# del ret +# ret = mix.value.set('netmask_admin_eth0', ['255.255.255.255'], force_default=True) +# assert len(ret) == 2 +# assert isinstance(ret[0], AttributeError) +# assert isinstance(ret[1], PropertiesOptionError) +# del ret[1] +# del ret[0] +# del ret +# ret = mix.value.set('netmask_admin_eth0', ['255.255.255.255'], force_dont_change_value=True) +# assert len(ret) == 3 +# assert isinstance(ret[0], PropertiesOptionError) +# assert isinstance(ret[1], AttributeError) +# assert isinstance(ret[2], PropertiesOptionError) +# del ret[2] +# del ret[1] +# del ret[0] +# del ret +# ret = mix.value.set('netmask_admin_eth0', ['255.255.255.255'], force_default_if_same=True) +# assert len(ret) == 2 +# assert isinstance(ret[0], AttributeError) +# assert isinstance(ret[1], PropertiesOptionError) +# del ret[1] +# del ret[0] +# del ret +# ret = mix.value.set('ip_admin_eth0', '255.255.255.255', only_config=True) +# assert len(ret) == 2 +# assert isinstance(ret[0], AttributeError) +# assert isinstance(ret[1], ValueError) +# del ret[1] +# del ret[0] +# del ret +# ret = mix.value.set('ip_admin_eth0', '255.255.255.255', force_default=True) +# assert len(ret) == 2 +# assert isinstance(ret[0], AttributeError) +# assert isinstance(ret[1], ValueError) +# del ret[1] +# del ret[0] +# del ret +# ret = mix.value.set('ip_admin_eth0', '255.255.255.255', force_dont_change_value=True) +# assert len(ret) == 2 +# assert isinstance(ret[0], AttributeError) +# assert isinstance(ret[1], ValueError) +# del ret[1] +# del ret[0] +# del ret +# ret = mix.value.set('ip_admin_eth0', '255.255.255.255', force_default_if_same=True) +# assert len(ret) == 2 +# assert isinstance(ret[0], AttributeError) +# assert isinstance(ret[1], ValueError) +# del ret[1] +# del ret[0] +# del ret +# +# +#def test_mix_different_default(): +# ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) +# interface0 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0]) +# ip_admin_eth0 = NetworkOption('ip_admin_eth1', "ip", multi=True, default=['192.168.1.2']) +# interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0]) +# ip_admin_eth0 = NetworkOption('ip_admin_eth1', "ip", multi=True, default=['192.168.1.3']) +# interface2 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0]) +# ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.4']) +# ip_admin_eth1 = NetworkOption('ip_admin_eth1', "ip", multi=True, default=['192.168.1.5']) +# interface3 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, ip_admin_eth1]) +# ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.6']) +# interface4 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0]) +# conf1 = Config(interface0, name='conf1') +# conf1.property.read_write() +# conf2 = Config(interface1, name='conf2') +# conf2.property.read_write() +# mix = MixConfig(interface2, [conf1, conf2], name='submix1') +# mix = MixConfig(interface3, [mix], name='submix2') +# mix = MixConfig(interface4, [mix]) +# mix.property.read_write() +# # +# assert mix.value.dict() == {'ip_admin_eth0': ['192.168.1.6']} +# newsubmix2 = mix.config('submix2') +# newsubmix1 = mix.config('submix2.submix1') +# newconf1 = mix.config('submix2.submix1.conf1') +# newconf2 = mix.config('submix2.submix1.conf2') +# assert newsubmix2.value.dict() == {'ip_admin_eth0': ['192.168.1.4'], 'ip_admin_eth1': ['192.168.1.5']} +# assert newsubmix1.value.dict() == {'ip_admin_eth1': ['192.168.1.3']} +# assert newconf2.value.dict() == {'ip_admin_eth1': ['192.168.1.2']} +# assert newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.1']} +# # +# mix.option('ip_admin_eth0').value.set(['192.168.1.7']) +# assert mix.value.dict() == {'ip_admin_eth0': ['192.168.1.7']} +# assert newsubmix2.value.dict() == {'ip_admin_eth0': ['192.168.1.7'], 'ip_admin_eth1': ['192.168.1.5']} +# assert newsubmix1.value.dict() == {'ip_admin_eth1': ['192.168.1.3']} +# assert newconf2.value.dict() == {'ip_admin_eth1': ['192.168.1.2']} +# assert newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.7']} +# # +# newsubmix2.option('ip_admin_eth0').value.set(['192.168.1.8']) +# assert mix.value.dict() == {'ip_admin_eth0': ['192.168.1.7']} +# assert newsubmix2.value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.5']} +# assert newsubmix1.value.dict() == {'ip_admin_eth1': ['192.168.1.3']} +# assert newconf2.value.dict() == {'ip_admin_eth1': ['192.168.1.2']} +# assert newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.8']} +# # +# with pytest.raises(AttributeError): +# newsubmix1.option('ip_admin_eth0').value.set(['192.168.1.9']) +# assert mix.value.dict() == {'ip_admin_eth0': ['192.168.1.7']} +# assert newsubmix2.value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.5']} +# assert newsubmix1.value.dict() == {'ip_admin_eth1': ['192.168.1.3']} +# assert newconf2.value.dict() == {'ip_admin_eth1': ['192.168.1.2']} +# assert newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.8']} +# # +# with pytest.raises(AttributeError): +# newconf2.option('ip_admin_eth0').value.set(['192.168.1.9']) +# assert mix.value.dict() == {'ip_admin_eth0': ['192.168.1.7']} +# assert newsubmix2.value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.5']} +# assert newsubmix1.value.dict() == {'ip_admin_eth1': ['192.168.1.3']} +# assert newconf2.value.dict() == {'ip_admin_eth1': ['192.168.1.2']} +# assert newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.8']} +# # +# newconf1.option('ip_admin_eth0').value.set(['192.168.1.9']) +# assert mix.value.dict() == {'ip_admin_eth0': ['192.168.1.7']} +# assert newsubmix2.value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.5']} +# assert newsubmix1.value.dict() == {'ip_admin_eth1': ['192.168.1.3']} +# assert newconf2.value.dict() == {'ip_admin_eth1': ['192.168.1.2']} +# assert newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.9']} +# # +# with pytest.raises(AttributeError): +# mix.option('ip_admin_eth1').value.set(['192.168.1.10']) +# assert mix.value.dict() == {'ip_admin_eth0': ['192.168.1.7']} +# assert newsubmix2.value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.5']} +# assert newsubmix1.value.dict() == {'ip_admin_eth1': ['192.168.1.3']} +# assert newconf2.value.dict() == {'ip_admin_eth1': ['192.168.1.2']} +# assert newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.9']} +# # +# newsubmix2.option('ip_admin_eth1').value.set(['192.168.1.10']) +# assert mix.value.dict() == {'ip_admin_eth0': ['192.168.1.7']} +# assert newsubmix2.value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.10']} +# assert newsubmix1.value.dict() == {'ip_admin_eth1': ['192.168.1.10']} +# assert newconf2.value.dict() == {'ip_admin_eth1': ['192.168.1.10']} +# assert newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.9']} +# # +# newsubmix1.option('ip_admin_eth1').value.set(['192.168.1.11']) +# assert mix.value.dict() == {'ip_admin_eth0': ['192.168.1.7']} +# assert newsubmix2.value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.10']} +# assert newsubmix1.value.dict() == {'ip_admin_eth1': ['192.168.1.11']} +# assert newconf2.value.dict() == {'ip_admin_eth1': ['192.168.1.11']} +# assert newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.9']} +# # +# newconf2.option('ip_admin_eth1').value.set(['192.168.1.12']) +# assert mix.value.dict() == {'ip_admin_eth0': ['192.168.1.7']} +# assert newsubmix2.value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.10']} +# assert newsubmix1.value.dict() == {'ip_admin_eth1': ['192.168.1.11']} +# assert newconf2.value.dict() == {'ip_admin_eth1': ['192.168.1.12']} +# assert newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.9']} +# # +# with pytest.raises(AttributeError): +# newconf1.option('ip_admin_eth1').value.set(['192.168.1.13']) +# assert mix.value.dict() == {'ip_admin_eth0': ['192.168.1.7']} +# assert newsubmix2.value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.10']} +# assert newsubmix1.value.dict() == {'ip_admin_eth1': ['192.168.1.11']} +# assert newconf2.value.dict() == {'ip_admin_eth1': ['192.168.1.12']} +# assert newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.9']} +# +# +#def test_mix_different_default_reset(): +# ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) +# interface0 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0]) +# ip_admin_eth0 = NetworkOption('ip_admin_eth1', "ip", multi=True, default=['192.168.1.2']) +# interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0]) +# ip_admin_eth0 = NetworkOption('ip_admin_eth1', "ip", multi=True, default=['192.168.1.3']) +# interface2 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0]) +# ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.4']) +# ip_admin_eth1 = NetworkOption('ip_admin_eth1', "ip", multi=True, default=['192.168.1.5']) +# interface3 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, ip_admin_eth1]) +# ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.6']) +# interface4 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0]) +# conf1 = Config(interface0, name='conf1') +# conf1.property.read_write() +# conf2 = Config(interface1, name='conf2') +# conf2.property.read_write() +# mix = MixConfig(interface2, [conf1, conf2], name='submix1') +# mix = MixConfig(interface3, [mix], name='submix2') +# mix = MixConfig(interface4, [mix]) +# mix.property.read_write() +# # +# mix.option('ip_admin_eth0').value.set(['192.168.1.7']) +# submix2 = mix.config('submix2') +# submix1 = mix.config('submix2.submix1') +# conf1 = mix.config('submix2.submix1.conf1') +# conf2 = mix.config('submix2.submix1.conf2') +# submix2.option('ip_admin_eth0').value.set(['192.168.1.8']) +# submix2.option('ip_admin_eth1').value.set(['192.168.1.10']) +# submix1.option('ip_admin_eth1').value.set(['192.168.1.11']) +# conf2.option('ip_admin_eth1').value.set(['192.168.1.12']) +# conf1.option('ip_admin_eth0').value.set(['192.168.1.9']) +# assert mix.value.dict() == {'ip_admin_eth0': ['192.168.1.7']} +# assert submix2.value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.10']} +# assert submix1.value.dict() == {'ip_admin_eth1': ['192.168.1.11']} +# assert conf2.value.dict() == {'ip_admin_eth1': ['192.168.1.12']} +# assert conf1.value.dict() == {'ip_admin_eth0': ['192.168.1.9']} +# # +# mix.value.reset('ip_admin_eth0') +# assert mix.value.dict() == {'ip_admin_eth0': ['192.168.1.6']} +# assert submix2.value.dict() == {'ip_admin_eth0': ['192.168.1.4'], 'ip_admin_eth1': ['192.168.1.10']} +# assert submix1.value.dict() == {'ip_admin_eth1': ['192.168.1.11']} +# assert conf2.value.dict() == {'ip_admin_eth1': ['192.168.1.12']} +# assert conf1.value.dict() == {'ip_admin_eth0': ['192.168.1.1']} +# # +# mix.value.reset('ip_admin_eth1') +# assert mix.value.dict() == {'ip_admin_eth0': ['192.168.1.6']} +# assert submix2.value.dict() == {'ip_admin_eth0': ['192.168.1.4'], 'ip_admin_eth1': ['192.168.1.5']} +# assert submix1.value.dict() == {'ip_admin_eth1': ['192.168.1.3']} +# assert conf2.value.dict() == {'ip_admin_eth1': ['192.168.1.2']} +# assert conf1.value.dict() == {'ip_admin_eth0': ['192.168.1.1']} +# +# +#def test_mix_pop_config(): +# od = make_description() +# config1 = Config(od, name='config1') +# config2 = Config(od, name='config2') +# mix = MixConfig(od, [config1, config2]) +# mix.option('od1.i1').value.set(2) +# # +# assert len(list(mix.config.list())) == 2 +# newconfig1 = mix.config('config1') +# assert newconfig1.value.dict() == {'od1.i1': 2, 'od1.i2': 1, 'od1.i3': None, 'od1.i4': 2, 'od1.i5': [2], 'od1.i6': None} +# newconf1 = mix.config.remove('config1') +# try: +# mix.config('config1') +# except ConfigError: +# pass +# else: +# raise Exception('must raise') +# assert newconf1.value.dict() == {'od1.i1': None, 'od1.i2': 1, 'od1.i3': None, 'od1.i4': 2, 'od1.i5': [2], 'od1.i6': None} +# # +# assert len(list(mix.config.list())) == 1 +# with pytest.raises(ConfigError): +# mix.config.remove('newconf1') +# +# +#def test_mix_add_config(): +# od = make_description() +# config1 = Config(od, name='config1') +# config2 = Config(od, name='config2') +# mix = MixConfig(od, [config1, config2]) +# mix.option('od1.i1').value.set(2) +# # +# assert len(list(mix.config.list())) == 2 +# config = Config(od, name='new') +# assert config.value.dict() == {'od1.i1': None, 'od1.i2': 1, 'od1.i3': None, 'od1.i4': 2, 'od1.i5': [2], 'od1.i6': None} +# mix.config.add(config) +# # +# assert len(list(mix.config.list())) == 3 +# assert config.value.dict() == {'od1.i1': 2, 'od1.i2': 1, 'od1.i3': None, 'od1.i4': 2, 'od1.i5': [2], 'od1.i6': None} +# # +# with pytest.raises(ConflictError): +# mix.config.add(config) +# +# +#def test_mix_add_config_readd(): +# od = make_description() +# mix = MixConfig(od, []) +# mix2 = MixConfig(od, []) +# # +# config = Config(od, name='new') +# mix.config.add(config) +# mix2.config.add(config) +# assert len(list(config.config.parents())) == 2 +# +# +#def test_mix_new_config_readd(): +# od = make_description() +# mix = MixConfig(od, []) +# assert len(list(mix.config.list())) == 0 +# mix2 = mix.config.new('mix2') +# assert len(list(mix.config.list())) == 1 +# +# +#def test_meta_new_mixconfig(): +# od = make_description() +# cfg = Config(od, name='cfg1') +# meta = MetaConfig([cfg]) +# mix = meta.config.new('mixconfig', type="mixconfig") +# assert isinstance(mix, MixConfig) +# +# +#def test_meta_mixconfig_parents(): +# od = make_description() +# cfg = Config(od, name='cfg1') +# meta = MetaConfig([cfg]) +# mix = meta.config.new('mixconfig', type="mixconfig") +# parents = mix.config.parents() +# assert len(parents) == 1 +## assert parents[0].config.get() == meta diff --git a/tests/test_multi_parents.py b/tests/test_multi_parents.py index 8107577..ad0ac26 100644 --- a/tests/test_multi_parents.py +++ b/tests/test_multi_parents.py @@ -15,76 +15,76 @@ def make_metaconfig(): return MetaConfig([], optiondescription=od2, name='metacfg1') -def test_multi_parents_path(): - """ - metacfg1 (1) --- - | -- cfg1 - metacfg2 (2) --- - """ - metacfg1 = make_metaconfig() - cfg1 = metacfg1.config.new(type='config', name="cfg1") - metacfg2 = MetaConfig([cfg1], name='metacfg2') - # - assert metacfg1.config.path() == 'metacfg1' - assert metacfg2.config.path() == 'metacfg2' - assert cfg1.config.path() == 'metacfg2.metacfg1.cfg1' - - -def test_multi_parents_path_same(): - """ - --- metacfg2 (1) --- - metacfg1 --| | -- cfg1 - --- metacfg3 (2) --- - """ - metacfg1 = make_metaconfig() - metacfg2 = metacfg1.config.new(type='metaconfig', name="metacfg2") - metacfg3 = metacfg1.config.new(type='metaconfig', name="metacfg3") - cfg1 = metacfg2.config.new(type='config', name="cfg1") - metacfg3.config.add(cfg1) - # - assert metacfg2.config.path() == 'metacfg1.metacfg2' - assert metacfg3.config.path() == 'metacfg1.metacfg3' - assert cfg1.config.path() == 'metacfg1.metacfg3.metacfg1.metacfg2.cfg1' - metacfg1.option('od1.i1').value.set(1) - metacfg3.option('od1.i1').value.set(2) - assert cfg1.option('od1.i1').value.get() == 1 - orideep = cfg1.config.deepcopy(metaconfig_prefix="test_", name='test_cfg1') - deep = orideep - while True: - try: - children = list(deep.config.list()) - except: - break - assert len(children) < 2 - deep = children[0] - assert deep.config.path() == 'test_metacfg3.test_metacfg1.test_metacfg2.test_cfg1' - assert cfg1.option('od1.i1').value.get() == 1 - - - -def test_multi_parents_value(): - metacfg1 = make_metaconfig() - cfg1 = metacfg1.config.new(type='config', name="cfg1") - metacfg2 = MetaConfig([cfg1], name='metacfg2') - # - assert cfg1.option('od1.i1').value.get() == None - assert cfg1.option('od1.i2').value.get() == 1 - assert cfg1.option('od1.i3').value.get() == None - # - assert metacfg1.option('od1.i1').value.get() == None - assert metacfg1.option('od1.i2').value.get() == 1 - assert metacfg1.option('od1.i3').value.get() == None - # - assert metacfg2.option('od1.i1').value.get() == None - assert metacfg2.option('od1.i2').value.get() == 1 - assert metacfg2.option('od1.i3').value.get() == None - # - metacfg1.option('od1.i3').value.set(3) - assert metacfg1.option('od1.i3').value.get() == 3 - assert cfg1.option('od1.i3').value.get() == 3 - assert metacfg2.option('od1.i2').value.get() == 1 - # - metacfg2.option('od1.i2').value.set(4) - assert metacfg2.option('od1.i2').value.get() == 4 - assert metacfg1.option('od1.i2').value.get() == 1 - assert cfg1.option('od1.i2').value.get() == 4 +#def test_multi_parents_path(): +# """ +# metacfg1 (1) --- +# | -- cfg1 +# metacfg2 (2) --- +# """ +# metacfg1 = make_metaconfig() +# cfg1 = metacfg1.config.new(type='config', name="cfg1") +# metacfg2 = MetaConfig([cfg1], name='metacfg2') +# # +# assert metacfg1.config.path() == 'metacfg1' +# assert metacfg2.config.path() == 'metacfg2' +# assert cfg1.config.path() == 'metacfg2.metacfg1.cfg1' +# +# +#def test_multi_parents_path_same(): +# """ +# --- metacfg2 (1) --- +# metacfg1 --| | -- cfg1 +# --- metacfg3 (2) --- +# """ +# metacfg1 = make_metaconfig() +# metacfg2 = metacfg1.config.new(type='metaconfig', name="metacfg2") +# metacfg3 = metacfg1.config.new(type='metaconfig', name="metacfg3") +# cfg1 = metacfg2.config.new(type='config', name="cfg1") +# metacfg3.config.add(cfg1) +# # +# assert metacfg2.config.path() == 'metacfg1.metacfg2' +# assert metacfg3.config.path() == 'metacfg1.metacfg3' +# assert cfg1.config.path() == 'metacfg1.metacfg3.metacfg1.metacfg2.cfg1' +# metacfg1.option('od1.i1').value.set(1) +# metacfg3.option('od1.i1').value.set(2) +# assert cfg1.option('od1.i1').value.get() == 1 +# orideep = cfg1.config.deepcopy(metaconfig_prefix="test_", name='test_cfg1') +# deep = orideep +# while True: +# try: +# children = list(deep.config.list()) +# except: +# break +# assert len(children) < 2 +# deep = children[0] +# assert deep.config.path() == 'test_metacfg3.test_metacfg1.test_metacfg2.test_cfg1' +# assert cfg1.option('od1.i1').value.get() == 1 +# +# +# +#def test_multi_parents_value(): +# metacfg1 = make_metaconfig() +# cfg1 = metacfg1.config.new(type='config', name="cfg1") +# metacfg2 = MetaConfig([cfg1], name='metacfg2') +# # +# assert cfg1.option('od1.i1').value.get() == None +# assert cfg1.option('od1.i2').value.get() == 1 +# assert cfg1.option('od1.i3').value.get() == None +# # +# assert metacfg1.option('od1.i1').value.get() == None +# assert metacfg1.option('od1.i2').value.get() == 1 +# assert metacfg1.option('od1.i3').value.get() == None +# # +# assert metacfg2.option('od1.i1').value.get() == None +# assert metacfg2.option('od1.i2').value.get() == 1 +# assert metacfg2.option('od1.i3').value.get() == None +# # +# metacfg1.option('od1.i3').value.set(3) +# assert metacfg1.option('od1.i3').value.get() == 3 +# assert cfg1.option('od1.i3').value.get() == 3 +# assert metacfg2.option('od1.i2').value.get() == 1 +# # +# metacfg2.option('od1.i2').value.set(4) +# assert metacfg2.option('od1.i2').value.get() == 4 +# assert metacfg1.option('od1.i2').value.get() == 1 +# assert cfg1.option('od1.i2').value.get() == 4 diff --git a/tests/test_option.py b/tests/test_option.py index 6734152..4542db7 100644 --- a/tests/test_option.py +++ b/tests/test_option.py @@ -202,24 +202,9 @@ def test_optiondescription_list(): od2 = OptionDescription('od', '', [od1, od3]) od4 = OptionDescription('od', '', [od2]) cfg = Config(od4) - assert len(list(cfg.option('od').list('option'))) == 0 - assert len(list(cfg.option('od').list('optiondescription'))) == 2 - assert len(list(cfg.option('od').list('optiondescription', group_type=groups.family))) == 1 - assert len(list(cfg.option('od').list('optiondescription', group_type=groups.notfamily1))) == 1 - assert len(list(cfg.option('od.od').list('option'))) == 1 - assert len(list(cfg.option('od.od2').list('option'))) == 1 - try: - list(cfg.option('od').list('unknown')) - except AssertionError: - pass - else: - raise Exception('must raise') - try: - list(cfg.option('od').list('option', group_type='toto')) - except AssertionError: - pass - else: - raise Exception('must raise') + assert len(list(cfg.option('od').list())) == 2 + assert len(list(cfg.option('od.od').list())) == 1 + assert len(list(cfg.option('od.od2').list())) == 1 # assert not list_sessions() @@ -233,22 +218,7 @@ def test_optiondescription_group(): od3.impl_set_group_type(groups.notfamily) od2 = OptionDescription('od', '', [od1, od3]) cfg = Config(od2) - assert len(list(cfg.option.list('option'))) == 0 - assert len(list(cfg.option.list('optiondescription'))) == 2 - assert len(list(cfg.option.list('optiondescription', group_type=groups.family))) == 1 - assert len(list(cfg.option.list('optiondescription', group_type=groups.notfamily))) == 1 - try: - list(cfg.option.list('unknown')) - except AssertionError: - pass - else: - raise Exception('must raise') - try: - list(cfg.option.list('option', group_type='toto')) - except AssertionError: - pass - else: - raise Exception('must raise') + assert len(list(cfg.option.list())) == 2 # assert not list_sessions() diff --git a/tests/test_option_callback.py b/tests/test_option_callback.py index 620814f..1550cdd 100644 --- a/tests/test_option_callback.py +++ b/tests/test_option_callback.py @@ -13,7 +13,7 @@ from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \ valid_ip_netmask, ParamSelfOption, ParamInformation, ParamSelfInformation from tiramisu.error import PropertiesOptionError, ConflictError, LeadershipError, ConfigError from tiramisu.i18n import _ -from .config import config_type, get_config +from .config import config_type, get_config, parse_od_get def return_val(): @@ -1528,7 +1528,7 @@ def test_calc_value_simple(config_type): od1 = OptionDescription('root', '', [val1, val2]) cfg = Config(od1) cfg = get_config(cfg, config_type) - assert cfg.value.dict() == {'val1': 'val1', 'val2': 'val1'} + assert parse_od_get(cfg.value.get()) == {'val1': 'val1', 'val2': 'val1'} # assert not list_sessions() @@ -1539,7 +1539,7 @@ def test_calc_value_multi(config_type): od1 = OptionDescription('root', '', [val1, val2, val3]) cfg = Config(od1) cfg = get_config(cfg, config_type) - assert cfg.value.dict() == {'val1': 'val1', 'val2': 'val2', 'val3': ['val1', 'val2']} + assert parse_od_get(cfg.value.get()) == {'val1': 'val1', 'val2': 'val2', 'val3': ['val1', 'val2']} # assert not list_sessions() @@ -1549,9 +1549,9 @@ def test_calc_value_disabled(): od1 = OptionDescription('root', '', [val1, val2]) cfg = Config(od1) cfg.property.read_write() - assert cfg.value.dict() == {'val1': 'val1', 'val2': 'val1'} + assert parse_od_get(cfg.value.get()) == {'val1': 'val1', 'val2': 'val1'} cfg.option('val1').property.add('disabled') - assert cfg.value.dict() == {'val2': 'default_value'} + assert parse_od_get(cfg.value.get()) == {'val2': 'default_value'} # assert not list_sessions() @@ -1566,9 +1566,9 @@ def test_calc_value_condition(config_type): cfg = Config(od1) cfg.property.read_write() cfg = get_config(cfg, config_type) - assert cfg.value.dict() == {'boolean': True, 'val1': 'val1', 'val2': 'val1'} + assert parse_od_get(cfg.value.get()) == {'boolean': True, 'val1': 'val1', 'val2': 'val1'} cfg.option('boolean').value.set(False) - assert cfg.value.dict() == {'boolean': False, 'val1': 'val1', 'val2': 'default_value'} + assert parse_od_get(cfg.value.get()) == {'boolean': False, 'val1': 'val1', 'val2': 'default_value'} # assert not list_sessions() @@ -1579,7 +1579,7 @@ def test_calc_value_allow_none(config_type): od1 = OptionDescription('root', '', [val1, val2, val3]) cfg = Config(od1) cfg = get_config(cfg, config_type) - assert cfg.value.dict() == {'val1': 'val1', 'val2': None, 'val3': ['val1', None]} + assert parse_od_get(cfg.value.get()) == {'val1': 'val1', 'val2': None, 'val3': ['val1', None]} # assert not list_sessions() @@ -1590,7 +1590,7 @@ def test_calc_value_remove_duplicate(config_type): od1 = OptionDescription('root', '', [val1, val2, val3]) cfg = Config(od1) cfg = get_config(cfg, config_type) - assert cfg.value.dict() == {'val1': 'val1', 'val2': 'val1', 'val3': ['val1']} + assert parse_od_get(cfg.value.get()) == {'val1': 'val1', 'val2': 'val1', 'val3': ['val1']} # assert not list_sessions() @@ -1601,7 +1601,7 @@ def test_calc_value_remove_duplicate2(config_type): od1 = OptionDescription('root', '', [val1, val2, val3]) cfg = Config(od1) cfg = get_config(cfg, config_type) - assert cfg.value.dict() == {'val1': ['val1', 'val1'], 'val2': ['val1', 'val1'], 'val3': ['val1-val1']} + assert parse_od_get(cfg.value.get()) == {'val1': ['val1', 'val1'], 'val2': ['val1', 'val1'], 'val3': ['val1-val1']} # assert not list_sessions() @@ -1613,9 +1613,9 @@ def test_calc_value_join(config_type): od1 = OptionDescription('root', '', [val1, val2, val3, val4]) cfg = Config(od1) cfg = get_config(cfg, config_type) - assert cfg.value.dict() == {'val1': 'val1', 'val2': 'val2', 'val3': None, 'val4': None} + assert parse_od_get(cfg.value.get()) == {'val1': 'val1', 'val2': 'val2', 'val3': None, 'val4': None} cfg.option('val3').value.set('val3') - assert cfg.value.dict() == {'val1': 'val1', 'val2': 'val2', 'val3': 'val3', 'val4': 'val1.val2.val3'} + assert parse_od_get(cfg.value.get()) == {'val1': 'val1', 'val2': 'val2', 'val3': 'val3', 'val4': 'val1.val2.val3'} # assert not list_sessions() @@ -1625,9 +1625,9 @@ def test_calc_value_join_multi(config_type): od1 = OptionDescription('root', '', [val1, val4]) cfg = Config(od1) cfg = get_config(cfg, config_type) - assert cfg.value.dict() == {'val1': [], 'val4': []} + assert parse_od_get(cfg.value.get()) == {'val1': [], 'val4': []} cfg.option('val1').value.set(['val1']) - assert cfg.value.dict() == {'val1': ['val1'], 'val4': ['val1']} + assert parse_od_get(cfg.value.get()) == {'val1': ['val1'], 'val4': ['val1']} # assert not list_sessions() @@ -1639,9 +1639,9 @@ def test_calc_value_join_multi_value(config_type): od1 = OptionDescription('root', '', [val1, val2, val3, val4]) cfg = Config(od1) cfg = get_config(cfg, config_type) - assert cfg.value.dict() == {'val1': ['val1'], 'val2': ['val2'], 'val3': [None], 'val4': []} + assert parse_od_get(cfg.value.get()) == {'val1': ['val1'], 'val2': ['val2'], 'val3': [None], 'val4': []} cfg.option('val3').value.set(['val3']) - assert cfg.value.dict() == {'val1': ['val1'], 'val2': ['val2'], 'val3': ['val3'], 'val4': ['val1.val2.val3']} + assert parse_od_get(cfg.value.get()) == {'val1': ['val1'], 'val2': ['val2'], 'val3': ['val3'], 'val4': ['val1.val2.val3']} # assert not list_sessions() @@ -1653,9 +1653,9 @@ def test_calc_value_min(): od1 = OptionDescription('root', '', [val1, val2, val3, val4]) cfg = Config(od1) cfg.property.read_write() - assert cfg.value.dict() == {'val1': 'val1', 'val2': 'val2', 'val3': 'val3', 'val4': 'val1.val2.val3'} + assert parse_od_get(cfg.value.get()) == {'val1': 'val1', 'val2': 'val2', 'val3': 'val3', 'val4': 'val1.val2.val3'} cfg.option('val3').property.add('disabled') - assert cfg.value.dict() == {'val1': 'val1', 'val2': 'val2', 'val4': ''} + assert parse_od_get(cfg.value.get()) == {'val1': 'val1', 'val2': 'val2', 'val4': ''} # assert not list_sessions() @@ -1666,7 +1666,7 @@ def test_calc_value_add(config_type): od1 = OptionDescription('root', '', [val1, val2, val3]) cfg = Config(od1) cfg = get_config(cfg, config_type) - assert cfg.value.dict() == {'val1': 1, 'val2': 2, 'val3': 3} + assert parse_od_get(cfg.value.get()) == {'val1': 1, 'val2': 2, 'val3': 3} # assert not list_sessions() diff --git a/tests/test_option_setting.py b/tests/test_option_setting.py index 85aca5d..54027fe 100644 --- a/tests/test_option_setting.py +++ b/tests/test_option_setting.py @@ -14,7 +14,7 @@ from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \ calc_value, calc_value_property_help, ParamInformation from tiramisu.error import PropertiesOptionError import warnings -from .config import config_type, get_config +from .config import config_type, get_config, parse_od_get def make_description(): @@ -228,7 +228,7 @@ def test_default_with_multi(): def test_idontexist(): od1 = make_description() cfg = Config(od1) - cfg.value.dict() + cfg.value.get() with pytest.raises(AttributeError): cfg.option('idontexist').value.get() # assert not list_sessions() @@ -535,12 +535,8 @@ def test_allow_multiple_changes_from_config(): def test_access_by_get(): od1 = make_description() cfg = Config(od1) - with pytest.raises(AttributeError): - list(cfg.option.find('idontexist')) - ret = cfg.option.find('wantref', first=True) - assert ret.value.get() is False - ret = cfg.option.find('dummy', first=True) - assert ret.value.get() is False + assert cfg.option('wantref').value.get() is False + assert cfg.option('gc.dummy').value.get() is False # assert not list_sessions() @@ -555,8 +551,7 @@ def test_access_by_get_whith_hide(): cfg = Config(od1) cfg.property.read_write() with pytest.raises(AttributeError): - ret = cfg.option.find('b1') - ret.value.get() + cfg.option('b1').value.get() # assert not list_sessions() @@ -645,27 +640,27 @@ def test_reset_properties_force_store_value(): # assert not list_sessions() -def test_importation_force_store_value(): - gcdummy = BoolOption('dummy', 'dummy', default=False, - properties=('force_store_value',)) - gcgroup = OptionDescription('gc', '', [gcdummy]) - od1 = OptionDescription('tiramisu', '', [gcgroup]) - config1 = Config(od1) - assert config1.value.exportation() == {} - config1.property.add('frozen') - assert config1.value.exportation() == {} - config1.property.add('force_store_value') - assert config1.value.exportation() == {'gc.dummy': {None: [False, 'forced']}} - exportation = config1.property.exportation() - config2 = Config(od1) - assert config2.value.exportation() == {} - config2.property.importation(exportation) - assert config2.value.exportation() == {'gc.dummy': {None: [False, 'forced']}} - config2.property.importation(exportation) - assert config2.value.exportation() == {'gc.dummy': {None: [False, 'forced']}} -# assert not list_sessions() - - +#def test_importation_force_store_value(): +# gcdummy = BoolOption('dummy', 'dummy', default=False, +# properties=('force_store_value',)) +# gcgroup = OptionDescription('gc', '', [gcdummy]) +# od1 = OptionDescription('tiramisu', '', [gcgroup]) +# config1 = Config(od1) +# assert config1.value.exportation() == {} +# config1.property.add('frozen') +# assert config1.value.exportation() == {} +# config1.property.add('force_store_value') +# assert config1.value.exportation() == {'gc.dummy': {None: [False, 'forced']}} +# exportation = config1.property.exportation() +# config2 = Config(od1) +# assert config2.value.exportation() == {} +# config2.property.importation(exportation) +# assert config2.value.exportation() == {'gc.dummy': {None: [False, 'forced']}} +# config2.property.importation(exportation) +# assert config2.value.exportation() == {'gc.dummy': {None: [False, 'forced']}} +## assert not list_sessions() +# +# def test_set_modified_value(): gcdummy = BoolOption('dummy', 'dummy', default=False, properties=('force_store_value',)) gcgroup = OptionDescription('gc', '', [gcdummy]) @@ -678,18 +673,18 @@ def test_set_modified_value(): # assert not list_sessions() -def test_none_is_not_modified(): - gcdummy = StrOption('dummy', 'dummy', properties=('force_store_value',)) - gcdummy1 = StrOption('dummy1', 'dummy1', default="str", properties=('force_store_value',)) - gcgroup = OptionDescription('gc', '', [gcdummy, gcdummy1]) - od1 = OptionDescription('tiramisu', '', [gcgroup]) - cfg = Config(od1) - assert cfg.value.exportation() == {} - cfg.property.read_write() - assert cfg.value.exportation() == {'gc.dummy1': {None: ['str', 'forced']}} -# assert not list_sessions() - - +#def test_none_is_not_modified(): +# gcdummy = StrOption('dummy', 'dummy', properties=('force_store_value',)) +# gcdummy1 = StrOption('dummy1', 'dummy1', default="str", properties=('force_store_value',)) +# gcgroup = OptionDescription('gc', '', [gcdummy, gcdummy1]) +# od1 = OptionDescription('tiramisu', '', [gcgroup]) +# cfg = Config(od1) +# assert cfg.value.exportation() == {} +# cfg.property.read_write() +# assert cfg.value.exportation() == {'gc.dummy1': {None: ['str', 'forced']}} +## assert not list_sessions() +# +# def test_pprint(): msg_error = _("cannot access to {0} \"{1}\" because has {2} {3}") msg_is_not = _('the value of "{0}" is not {1}') @@ -893,7 +888,9 @@ def test_settings_list_with_follower(): descr = Leadership("root", "", [leader, option, ip]) cfg = Config(OptionDescription('root', 'root', [descr])) cfg.property.read_write() - assert len(cfg.option('root').list('all')) == 2 + assert parse_od_get(cfg.option('root').value.get()) == {'root.leader': ['leader']} + assert len(cfg.option('root').list()) == 1 + assert len(cfg.option('root').list(validate_properties=False)) == 3 def return_none(*args): @@ -908,4 +905,4 @@ def test_settings_disable_set_information(config_type): cfg = Config(od1) cfg.property.read_only() cfg.information.set('key', 'val') - assert cfg.value.dict() == {'leadership.opt1': [{'leadership.opt1': 'val', 'leadership.opt2': 'test'}]} + assert parse_od_get(cfg.value.get()) == {'leadership.opt1': [{'leadership.opt1': 'val', 'leadership.opt2': 'test'}]} diff --git a/tests/test_option_validator.py b/tests/test_option_validator.py index 40c26ba..f904cae 100644 --- a/tests/test_option_validator.py +++ b/tests/test_option_validator.py @@ -441,7 +441,7 @@ def test_validator_warning_leadership(config_type): with warnings.catch_warnings(record=True) as w: cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val']) if config_type != 'tiramisu-api': - assert w[0].message.opt() == ip_admin_eth0 + assert w and w[0].message.opt() == ip_admin_eth0 assert str(w[0].message) == msg_err.format('val', ip_admin_eth0.get_type(), display_name_ip) + ', test error return_false' else: assert len(w) == 2 @@ -965,7 +965,7 @@ def test_validator_broadcast_default_1(): od1 = OptionDescription('a', '', [a, b, c]) cfg = Config(od1) with pytest.raises(ValueError): - cfg.value.dict() + cfg.value.get() # assert not list_sessions() @@ -975,7 +975,7 @@ def test_validator_broadcast_default_2(): d = BroadcastOption('d', '', '192.168.1.127', validators=[Calculation(valid_broadcast, Params((ParamOption(a), ParamOption(b), ParamSelfOption())))]) od1 = OptionDescription('a', '', [a, b, d]) cfg = Config(od1) - assert cfg.value.dict() + assert cfg.value.get() # assert not list_sessions() @@ -1001,7 +1001,7 @@ def test_validator_network_netmask_mandatory(config_type): cfg = Config(od1) cfg.property.read_only() cfg = get_config(cfg, config_type) - cfg.value.dict() + cfg.value.get() # assert not list_sessions() @@ -1109,7 +1109,7 @@ def test_validator_not_equal_leadership(config_type): cfg.option('a.b', 0).value.set(2) cfg.option('a.a').value.reset() cfg.option('a.a').value.set([1]) - cfg.value.dict() + cfg.value.get() # assert not list_sessions() diff --git a/tests/test_requires.py b/tests/test_requires.py index c323570..68a7f2e 100644 --- a/tests/test_requires.py +++ b/tests/test_requires.py @@ -13,7 +13,7 @@ from tiramisu import IPOption, OptionDescription, BoolOption, IntOption, StrOpti calc_value_property_help from tiramisu.error import PropertiesOptionError, ConfigError, display_list import pytest -from .config import config_type, get_config +from .config import config_type, get_config, parse_od_get def test_properties(config_type): @@ -1106,19 +1106,19 @@ def test_leadership_requires(config_type): assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() is None cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.255') assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.255' - assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [{'ip_admin_eth0.ip_admin_eth0': '192.168.1.2', 'ip_admin_eth0.netmask_admin_eth0': None}, + assert parse_od_get(cfg.value.get()) == {'ip_admin_eth0.ip_admin_eth0': [{'ip_admin_eth0.ip_admin_eth0': '192.168.1.2', 'ip_admin_eth0.netmask_admin_eth0': None}, {'ip_admin_eth0.ip_admin_eth0': '192.168.1.2', 'ip_admin_eth0.netmask_admin_eth0': '255.255.255.255'}]} # cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1']) assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None with pytest.raises(PropertiesOptionError): cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() - assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [{'ip_admin_eth0.ip_admin_eth0': '192.168.1.2', + assert parse_od_get(cfg.value.get()) == {'ip_admin_eth0.ip_admin_eth0': [{'ip_admin_eth0.ip_admin_eth0': '192.168.1.2', 'ip_admin_eth0.netmask_admin_eth0': None}, {'ip_admin_eth0.ip_admin_eth0': '192.168.1.1'}]} # cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.255') - assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [{'ip_admin_eth0.ip_admin_eth0': '192.168.1.2', + assert parse_od_get(cfg.value.get()) == {'ip_admin_eth0.ip_admin_eth0': [{'ip_admin_eth0.ip_admin_eth0': '192.168.1.2', 'ip_admin_eth0.netmask_admin_eth0': '255.255.255.255'}, {'ip_admin_eth0.ip_admin_eth0': '192.168.1.1'}]} # assert not list_sessions() @@ -1158,7 +1158,7 @@ def test_leadership_requires_leader(config_type): cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() with pytest.raises(PropertiesOptionError): cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() - assert cfg.value.dict() == {'activate': False} + assert parse_od_get(cfg.value.get()) == {'activate': False} # assert not list_sessions() @@ -1200,7 +1200,7 @@ def test_leadership_requires_leadership(config_type): cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() with pytest.raises(PropertiesOptionError): cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() - assert cfg.value.dict() == {'activate': False} + assert parse_od_get(cfg.value.get()) == {'activate': False} # assert not list_sessions() @@ -1238,7 +1238,7 @@ def test_leadership_requires_no_leader(config_type): cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() with pytest.raises(PropertiesOptionError): cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() - assert cfg.value.dict() == {'activate': False, 'ip_admin_eth0.ip_admin_eth0': [{'ip_admin_eth0.ip_admin_eth0': '192.168.1.2'}, {'ip_admin_eth0.ip_admin_eth0': '192.168.1.1'}]} + assert parse_od_get(cfg.value.get()) == {'activate': False, 'ip_admin_eth0.ip_admin_eth0': [{'ip_admin_eth0.ip_admin_eth0': '192.168.1.2'}, {'ip_admin_eth0.ip_admin_eth0': '192.168.1.1'}]} # assert not list_sessions() @@ -1299,10 +1299,10 @@ def test_leadership_requires_complet(config_type): cfg = get_config(cfg, config_type) cfg.option('options.unicode.unicode').value.set(['test', 'trah']) cfg.option('options.unicode.unicode2', 0).value.set('test') - assert cfg.value.dict() == {'options.unicode.unicode': [{'options.unicode.unicode': 'test', 'options.unicode.unicode1': None, 'options.unicode.unicode2': 'test', 'options.unicode.unicode3': None, 'options.unicode.unicode4': None}, {'options.unicode.unicode': 'trah', 'options.unicode.unicode1': None, 'options.unicode.unicode2': None}], 'options.unicodetoto': None} + assert parse_od_get(cfg.value.get()) == {'options.unicode.unicode': [{'options.unicode.unicode': 'test', 'options.unicode.unicode1': None, 'options.unicode.unicode2': 'test', 'options.unicode.unicode3': None, 'options.unicode.unicode4': None}, {'options.unicode.unicode': 'trah', 'options.unicode.unicode1': None, 'options.unicode.unicode2': None}], 'options.unicodetoto': None} # cfg.option('options.unicodetoto').value.set('test') - assert cfg.value.dict() == {'options.unicode.unicode': [{'options.unicode.unicode': 'test', 'options.unicode.unicode1': None, 'options.unicode.unicode2': 'test', 'options.unicode.unicode3': None, 'options.unicode.unicode4': None, 'options.unicode.unicode5': None, 'options.unicode.unicode6': None, 'options.unicode.unicode7': None}, {'options.unicode.unicode': 'trah', 'options.unicode.unicode1': None, 'options.unicode.unicode2': None, 'options.unicode.unicode5': None}], 'options.unicodetoto': 'test'} + assert parse_od_get(cfg.value.get()) == {'options.unicode.unicode': [{'options.unicode.unicode': 'test', 'options.unicode.unicode1': None, 'options.unicode.unicode2': 'test', 'options.unicode.unicode3': None, 'options.unicode.unicode4': None, 'options.unicode.unicode5': None, 'options.unicode.unicode6': None, 'options.unicode.unicode7': None}, {'options.unicode.unicode': 'trah', 'options.unicode.unicode1': None, 'options.unicode.unicode2': None, 'options.unicode.unicode5': None}], 'options.unicodetoto': 'test'} # assert not list_sessions() @@ -1339,24 +1339,24 @@ def test_leadership_requires_transitive1(config_type): cfg = Config(od1) cfg.property.read_write() cfg = get_config(cfg, config_type) - assert cfg.value.dict() == {'options.unicode.unicode': [], 'options.unicodetoto': None} + assert parse_od_get(cfg.value.get()) == {'options.unicode.unicode': [], 'options.unicodetoto': None} # cfg.option('options.unicodetoto').value.set('test') - assert cfg.value.dict() == {'options.unicode.unicode': [], 'options.unicodetoto': 'test'} + assert parse_od_get(cfg.value.get()) == {'options.unicode.unicode': [], 'options.unicodetoto': 'test'} # cfg.option('options.unicode.unicode').value.set(['a', 'b', 'c']) - assert cfg.value.dict() == {'options.unicode.unicode': [{'options.unicode.unicode': 'a', 'options.unicode.unicode1': None, 'options.unicode.unicode2': None}, {'options.unicode.unicode': 'b', 'options.unicode.unicode1': None, 'options.unicode.unicode2': None}, {'options.unicode.unicode': 'c', 'options.unicode.unicode1': None, 'options.unicode.unicode2': None}], 'options.unicodetoto': 'test'} + assert parse_od_get(cfg.value.get()) == {'options.unicode.unicode': [{'options.unicode.unicode': 'a', 'options.unicode.unicode1': None, 'options.unicode.unicode2': None}, {'options.unicode.unicode': 'b', 'options.unicode.unicode1': None, 'options.unicode.unicode2': None}, {'options.unicode.unicode': 'c', 'options.unicode.unicode1': None, 'options.unicode.unicode2': None}], 'options.unicodetoto': 'test'} cfg.option('options.unicode.unicode2', 1).value.set('test') cfg.option('options.unicode.unicode3', 1).value.set('test') - assert cfg.value.dict() == {'options.unicode.unicode': [{'options.unicode.unicode': 'a', 'options.unicode.unicode1': None, 'options.unicode.unicode2': None}, {'options.unicode.unicode': 'b', 'options.unicode.unicode1': None, 'options.unicode.unicode2': 'test', 'options.unicode.unicode3': 'test', 'options.unicode.unicode4': None}, {'options.unicode.unicode': 'c', 'options.unicode.unicode1': None, 'options.unicode.unicode2': None}], 'options.unicodetoto': 'test'} + assert parse_od_get(cfg.value.get()) == {'options.unicode.unicode': [{'options.unicode.unicode': 'a', 'options.unicode.unicode1': None, 'options.unicode.unicode2': None}, {'options.unicode.unicode': 'b', 'options.unicode.unicode1': None, 'options.unicode.unicode2': 'test', 'options.unicode.unicode3': 'test', 'options.unicode.unicode4': None}, {'options.unicode.unicode': 'c', 'options.unicode.unicode1': None, 'options.unicode.unicode2': None}], 'options.unicodetoto': 'test'} # cfg.option('options.unicode.unicode2', 1).value.set('rah') - assert cfg.value.dict() == {'options.unicode.unicode': [{'options.unicode.unicode': 'a', 'options.unicode.unicode1': None, 'options.unicode.unicode2': None}, {'options.unicode.unicode': 'b', 'options.unicode.unicode1': None, 'options.unicode.unicode2': 'rah'}, {'options.unicode.unicode': 'c', 'options.unicode.unicode1': None, 'options.unicode.unicode2': None}], 'options.unicodetoto': 'test'} + assert parse_od_get(cfg.value.get()) == {'options.unicode.unicode': [{'options.unicode.unicode': 'a', 'options.unicode.unicode1': None, 'options.unicode.unicode2': None}, {'options.unicode.unicode': 'b', 'options.unicode.unicode1': None, 'options.unicode.unicode2': 'rah'}, {'options.unicode.unicode': 'c', 'options.unicode.unicode1': None, 'options.unicode.unicode2': None}], 'options.unicodetoto': 'test'} # cfg.option('options.unicode.unicode2', 1).value.set('test') cfg.option('options.unicodetoto').value.set('rah') - assert cfg.value.dict() == {'options.unicode.unicode': [{'options.unicode.unicode': 'a', 'options.unicode.unicode1': None}, {'options.unicode.unicode': 'b', 'options.unicode.unicode1': None}, {'options.unicode.unicode': 'c', 'options.unicode.unicode1': None}], 'options.unicodetoto': 'rah'} + assert parse_od_get(cfg.value.get()) == {'options.unicode.unicode': [{'options.unicode.unicode': 'a', 'options.unicode.unicode1': None}, {'options.unicode.unicode': 'b', 'options.unicode.unicode1': None}, {'options.unicode.unicode': 'c', 'options.unicode.unicode1': None}], 'options.unicodetoto': 'rah'} # assert not list_sessions() diff --git a/tests/test_submulti.py b/tests/test_submulti.py index 4e2f1b2..86b45a6 100644 --- a/tests/test_submulti.py +++ b/tests/test_submulti.py @@ -528,43 +528,43 @@ def test_submulti_unique(): # assert not list_sessions() -def test_multi_submulti_meta(): - multi = StrOption('multi', '', multi=submulti) - od1 = OptionDescription('od', '', [multi]) - cfg = Config(od1, name='cfg') - cfg.property.read_write() - cfg2 = Config(od1) - cfg2.property.read_write() - meta = MetaConfig([cfg, cfg2]) - meta.property.read_write() - meta.option('multi').value.set([['val']]) - assert meta.option('multi').value.get() == [['val']] - newcfg = meta.config('cfg') - newcfg.option('multi').value.set([['val', None]]) - assert cfg.option('multi').value.get() == [['val', None]] - newcfg = meta.config('cfg') - assert newcfg.option('multi').value.get() == [['val', None]] - assert meta.option('multi').value.get() == [['val']] -# assert not list_sessions() - - -def test_multi_submulti_meta_no_cache(): - multi = StrOption('multi', '', multi=submulti) - multi = StrOption('multi', '', multi=submulti) - od1 = OptionDescription('od', '', [multi]) - cfg = Config(od1, name='cfg') - cfg.property.read_write() - cfg2 = Config(od1) - cfg.property.read_write() - meta = MetaConfig([cfg, cfg2]) - meta.property.read_write() - meta.property.remove('cache') - meta.option('multi').value.set([['val']]) - assert meta.option('multi').value.get() == [['val']] - newcfg = meta.config('cfg') - newcfg.option('multi').value.set([['val', None]]) - assert cfg.option('multi').value.get() == [['val', None]] - newcfg = meta.config('cfg') - assert newcfg.option('multi').value.get() == [['val', None]] - assert meta.option('multi').value.get() == [['val']] -# assert not list_sessions() +#def test_multi_submulti_meta(): +# multi = StrOption('multi', '', multi=submulti) +# od1 = OptionDescription('od', '', [multi]) +# cfg = Config(od1, name='cfg') +# cfg.property.read_write() +# cfg2 = Config(od1) +# cfg2.property.read_write() +# meta = MetaConfig([cfg, cfg2]) +# meta.property.read_write() +# meta.option('multi').value.set([['val']]) +# assert meta.option('multi').value.get() == [['val']] +# newcfg = meta.config('cfg') +# newcfg.option('multi').value.set([['val', None]]) +# assert cfg.option('multi').value.get() == [['val', None]] +# newcfg = meta.config('cfg') +# assert newcfg.option('multi').value.get() == [['val', None]] +# assert meta.option('multi').value.get() == [['val']] +## assert not list_sessions() +# +# +#def test_multi_submulti_meta_no_cache(): +# multi = StrOption('multi', '', multi=submulti) +# multi = StrOption('multi', '', multi=submulti) +# od1 = OptionDescription('od', '', [multi]) +# cfg = Config(od1, name='cfg') +# cfg.property.read_write() +# cfg2 = Config(od1) +# cfg.property.read_write() +# meta = MetaConfig([cfg, cfg2]) +# meta.property.read_write() +# meta.property.remove('cache') +# meta.option('multi').value.set([['val']]) +# assert meta.option('multi').value.get() == [['val']] +# newcfg = meta.config('cfg') +# newcfg.option('multi').value.set([['val', None]]) +# assert cfg.option('multi').value.get() == [['val', None]] +# newcfg = meta.config('cfg') +# assert newcfg.option('multi').value.get() == [['val', None]] +# assert meta.option('multi').value.get() == [['val']] +## assert not list_sessions() diff --git a/tests/test_symlink.py b/tests/test_symlink.py index be64ae2..78bd3c0 100644 --- a/tests/test_symlink.py +++ b/tests/test_symlink.py @@ -2,7 +2,7 @@ import pytest from .autopath import do_autopath do_autopath() -from .config import config_type, get_config +from .config import config_type, get_config, parse_od_get from tiramisu import BoolOption, StrOption, SymLinkOption, submulti, \ OptionDescription, Leadership, Config, Calculation, calc_value, Params, ParamOption, ParamValue @@ -300,9 +300,9 @@ def test_symlink_with_leader(config_type): od1 = OptionDescription('root', '', [interface1, leader]) cfg = Config(od1) cfg = get_config(cfg, config_type) - assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [], 'leader': []} + assert parse_od_get(cfg.value.get()) == {'ip_admin_eth0.ip_admin_eth0': [], 'leader': []} cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val2']) - assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [{'ip_admin_eth0.ip_admin_eth0': 'val1', 'ip_admin_eth0.netmask_admin_eth0': None}, {'ip_admin_eth0.ip_admin_eth0': 'val2', 'ip_admin_eth0.netmask_admin_eth0': None}], 'leader': ['val1', 'val2']} + assert parse_od_get(cfg.value.get()) == {'ip_admin_eth0.ip_admin_eth0': [{'ip_admin_eth0.ip_admin_eth0': 'val1', 'ip_admin_eth0.netmask_admin_eth0': None}, {'ip_admin_eth0.ip_admin_eth0': 'val2', 'ip_admin_eth0.netmask_admin_eth0': None}], 'leader': ['val1', 'val2']} cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(0) with pytest.raises(ConfigError): cfg.option('leader').value.pop(0) @@ -318,9 +318,9 @@ def test_symlink_with_follower(config_type): cfg = Config(od1) cfg = get_config(cfg, config_type) assert not cfg.option('follower').isoptiondescription() - assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [], 'follower': []} + assert parse_od_get(cfg.value.get()) == {'ip_admin_eth0.ip_admin_eth0': [], 'follower': []} cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val2']) - assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [{'ip_admin_eth0.ip_admin_eth0': 'val1', 'ip_admin_eth0.netmask_admin_eth0': None}, {'ip_admin_eth0.ip_admin_eth0': 'val2', 'ip_admin_eth0.netmask_admin_eth0': None}], 'follower': [None, None]} + assert parse_od_get(cfg.value.get()) == {'ip_admin_eth0.ip_admin_eth0': [{'ip_admin_eth0.ip_admin_eth0': 'val1', 'ip_admin_eth0.netmask_admin_eth0': None}, {'ip_admin_eth0.ip_admin_eth0': 'val2', 'ip_admin_eth0.netmask_admin_eth0': None}], 'follower': [None, None]} # assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == 'default' assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).owner.get() == 'default' @@ -335,7 +335,7 @@ def test_symlink_with_follower(config_type): assert cfg.option('follower').value.get() == [None, None] # cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val3') - assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [{'ip_admin_eth0.ip_admin_eth0': 'val1', 'ip_admin_eth0.netmask_admin_eth0': None}, {'ip_admin_eth0.ip_admin_eth0': 'val2', 'ip_admin_eth0.netmask_admin_eth0': 'val3'}], 'follower': [None, 'val3']} + assert parse_od_get(cfg.value.get()) == {'ip_admin_eth0.ip_admin_eth0': [{'ip_admin_eth0.ip_admin_eth0': 'val1', 'ip_admin_eth0.netmask_admin_eth0': None}, {'ip_admin_eth0.ip_admin_eth0': 'val2', 'ip_admin_eth0.netmask_admin_eth0': 'val3'}], 'follower': [None, 'val3']} # assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == 'val3' @@ -372,9 +372,9 @@ def test_symlink_makedict(config_type): [linkopt, OptionDescription("s1", "", [boolopt])]) cfg = Config(od1) cfg = get_config(cfg, config_type) - assert cfg.value.dict() == {'c': False, 's1.b': False} + assert parse_od_get(cfg.value.get()) == {'c': False, 's1.b': False} cfg.option('s1.b').value.set(True) - assert cfg.value.dict() == {'c': True, 's1.b': True} + assert parse_od_get(cfg.value.get()) == {'c': True, 's1.b': True} # assert not list_sessions() @@ -382,18 +382,12 @@ def test_symlink_list(config_type): boolopt = BoolOption("b", "", default=False) linkopt = SymLinkOption("c", boolopt) od1 = OptionDescription("opt", "", - [linkopt, OptionDescription("s1", "", [boolopt])]) + [linkopt, OptionDescription("s1", "", [boolopt])]) cfg = Config(od1) cfg = get_config(cfg, config_type) - list_opt = [] - for opt in cfg.option.list(): - list_opt.append(opt.path()) - assert list_opt == ['c'] + assert [opt.path() for opt in cfg.option.list()] == ['c', 's1'] # - list_opt = [] - for opt in cfg.option.list(recursive=True): - list_opt.append(opt.path()) - assert list_opt == ['c', 's1.b'] + assert [opt.path() for opt in cfg.option('s1').list()] == ['s1.b'] # assert not list_sessions() diff --git a/tiramisu/api.py b/tiramisu/api.py index 9e340e6..56e87ec 100644 --- a/tiramisu/api.py +++ b/tiramisu/api.py @@ -23,9 +23,9 @@ from copy import deepcopy from .error import ConfigError, LeadershipError, ValueErrorWarning from .i18n import _ -from .setting import ConfigBag, OptionBag, owners, groups, undefined, \ +from .setting import ConfigBag, owners, groups, undefined, \ FORBIDDEN_SET_PROPERTIES, SPECIAL_PROPERTIES -from .config import KernelConfig, KernelGroupConfig, KernelMetaConfig, KernelMixConfig +from .config import KernelConfig, KernelGroupConfig, KernelMetaConfig, KernelMixConfig, SubConfig from .option import RegexpOption, OptionDescription, ChoiceOption, Leadership from .todict import TiramisuDict from .autolib import Calculation @@ -42,7 +42,7 @@ class TiramisuHelp: def display(doc=''): if _display: # pragma: no cover print(doc) - all_modules = dir(self) + all_modules = dir(self.__class__) modules = [] max_len = 0 force = False @@ -90,21 +90,20 @@ class TiramisuHelp: class CommonTiramisu(TiramisuHelp): _validate_properties = True - def _get_options_bag(self, - follower_not_apply_requires: bool, - ) -> OptionBag: + def _get_subconfig(self, + follower_not_apply_requires: bool, + ) -> "OptionBag": try: - options_bag = self._config_bag.context.get_sub_option_bag(self._config_bag, - self._path, - self._index, - self._validate_properties, - follower_not_apply_requires=follower_not_apply_requires, - ) + return self._config_bag.context.get_sub_config(self._config_bag, + self._path, + self._index, + validate_properties=self._validate_properties, + follower_not_apply_requires=follower_not_apply_requires, + ) except AssertionError as err: raise ConfigError(str(err)) except Exception as err: raise err - return options_bag def option_type(typ): @@ -126,8 +125,9 @@ def option_type(typ): )] kwargs['is_group'] = True return func(self, options_bag, *args[1:], **kwargs) - options_bag = self._get_options_bag('with_index' not in types) - option = options_bag[-1].option + if not self._subconfig: + self._subconfig = self._get_subconfig('with_index' not in types) + option = self._subconfig.option if option.impl_is_optiondescription() and 'optiondescription' in types or \ option.impl_is_optiondescription() and option.impl_is_leadership() and 'leadership' in types or \ not option.impl_is_optiondescription() and ( @@ -150,7 +150,7 @@ def option_type(typ): msg = _('please specify index with a follower option ' f'({self.__class__.__name__}.{func.__name__})') raise ConfigError(msg) - return func(self, options_bag, *args[1:], **kwargs) + return func(self, *args[1:], **kwargs) msg = _('please specify a valid sub function ' f'({self.__class__.__name__}.{func.__name__})') raise ConfigError(msg) @@ -166,10 +166,12 @@ class CommonTiramisuOption(CommonTiramisu): path: str, index: Optional[int], config_bag: ConfigBag, + subconfig: Optional[SubConfig]=None, ) -> None: self._path = path self._index = index self._config_bag = config_bag + self._subconfig = subconfig def __getattr__(self, subfunc): raise ConfigError(_(f'please specify a valid sub function ({self.__class__.__name__}.{subfunc})')) @@ -177,43 +179,16 @@ class CommonTiramisuOption(CommonTiramisu): class _TiramisuOptionWalk: def _list(self, - root_option_bag, - type, - group_type, - recursive, + subconfig: SubConfig, + validate_properties: bool, ): - assert type in ('all', 'option', 'optiondescription'), \ - _('unknown list type {}').format(type) - assert group_type is None or isinstance(group_type, groups.GroupType), \ - _("unknown group_type: {0}").format(group_type) options = [] - types = {'option': ['option'], - 'optiondescription': ['optiondescription'], - 'all': ['option', 'optiondescription']}[type] - for option_bag in self._config_bag.context.walk(root_option_bag, - recursive=recursive, - types=types, - group_type=group_type, - flatten_leadership=True, - ): - if isinstance(option_bag, dict): - for opts_bag in option_bag.values(): - if isinstance(opts_bag, OptionBag): - options.append(TiramisuOption(opts_bag.path, - opts_bag.index, - self._config_bag, - )) - else: - for opt_bag in opts_bag: - options.append(TiramisuOption(opt_bag.path, - opt_bag.index, - self._config_bag, - )) - else: - options.append(TiramisuOption(option_bag.path, - option_bag.index, - self._config_bag, - )) + for sub_subconfig in subconfig.get_children(validate_properties=validate_properties): + options.append(TiramisuOption(sub_subconfig.path, + sub_subconfig.index, + self._config_bag, + subconfig=sub_subconfig, + )) return options @@ -222,56 +197,49 @@ class _TiramisuOptionOptionDescription: _validate_properties = False @option_type(['optiondescription', 'option', 'with_or_without_index', 'symlink']) - def get(self, options_bag: List[OptionBag]): + def get(self): """Get Tiramisu option""" - option_bag = options_bag[-1] - return option_bag.option + return self._subconfig.option @option_type(['optiondescription']) - def isleadership(self, options_bag: List[OptionBag]): + def isleadership(self): """Test if option is a leader or a follower""" - option_bag = options_bag[-1] - return option_bag.option.impl_is_leadership() + return self._subconfig.option.impl_is_leadership() @option_type(['optiondescription', 'option', 'with_or_without_index']) - def doc(self, options_bag: List[OptionBag]): + def doc(self): """Get option document""" - option_bag = options_bag[-1] - return option_bag.option.impl_get_display_name() + return self._subconfig.option.impl_get_display_name() @option_type(['optiondescription', 'option', 'with_or_without_index']) - def description(self, options_bag: List[OptionBag]): + def description(self): """Get option description""" - option_bag = options_bag[-1] - return option_bag.option.impl_get_information('doc', None) + return self._subconfig.option.impl_get_information('doc', None) @option_type(['optiondescription', 'option', 'symlink', 'with_or_without_index']) - def name(self, options_bag: List[OptionBag]) -> str: + def name(self) -> str: """Get option name""" - option_bag = options_bag[-1] - return option_bag.option.impl_getname() + #FIXME impl_getname ? + return self._subconfig.true_path.rsplit('.', 1)[-1] @option_type(['optiondescription', 'option', 'with_or_without_index', 'symlink']) - def path(self, options_bag: List[OptionBag]) -> str: + def path(self, + ) -> str: """Get option path""" - option_bag = options_bag[-1] - return option_bag.path + return self._subconfig.true_path @option_type(['optiondescription', 'option', 'symlink', 'with_or_without_index']) def has_dependency(self, - options_bag: List[OptionBag], self_is_dep=True, ) -> bool: """Test if option has dependency""" - option_bag = options_bag[-1] - return option_bag.option.impl_has_dependency(self_is_dep) + return self._subconfig.option.impl_has_dependency(self_is_dep) @option_type(['optiondescription', 'option']) - def dependencies(self, options_bag: List[OptionBag]): + def dependencies(self): """Get dependencies from this option""" - option_bag = options_bag[-1] options = [] - for option in option_bag.option.get_dependencies(self._config_bag.context): + for option in self._subconfig.option.get_dependencies(self._config_bag.context): options.append(TiramisuOption(option().impl_getpath(), None, self._config_bag, @@ -279,29 +247,26 @@ class _TiramisuOptionOptionDescription: return options @option_type(['optiondescription', 'option', 'with_or_without_index', 'symlink']) - def isoptiondescription(self, options_bag: List[OptionBag]): + def isoptiondescription(self): """Test if option is an optiondescription""" - option_bag = options_bag[-1] - return option_bag.option.impl_is_optiondescription() + return self._subconfig.option.impl_is_optiondescription() @option_type(['optiondescription', 'option', 'with_or_without_index', 'symlink']) def properties(self, - options_bag: List[OptionBag], only_raises=False, uncalculated=False, ): """Get properties for an option""" - option_bag = options_bag[-1] settings = self._config_bag.context.get_settings() if uncalculated: - return settings.getproperties(option_bag, + return settings.getproperties(self._subconfig, uncalculated=True, ) if not only_raises: - return settings.getproperties(option_bag, + return settings.getproperties(self._subconfig, apply_requires=False, ) - return settings.calc_raises_properties(option_bag, + return settings.calc_raises_properties(self._subconfig, apply_requires=False, uncalculated=uncalculated, ) @@ -310,62 +275,59 @@ class _TiramisuOptionOptionDescription: class _TiramisuOptionOption(_TiramisuOptionOptionDescription): """Manage option""" @option_type(['option', 'symlink', 'with_or_without_index']) - def ismulti(self, options_bag: List[OptionBag]): + def ismulti(self): """Test if option could have multi value""" - option_bag = options_bag[-1] - return option_bag.option.impl_is_multi() + return self._subconfig.option.impl_is_multi() @option_type(['option', 'symlink', 'with_or_without_index']) - def issubmulti(self, options_bag: List[OptionBag]): + def issubmulti(self): """Test if option could have submulti value""" - option_bag = options_bag[-1] - return option_bag.option.impl_is_submulti() + return self._subconfig.option.impl_is_submulti() @option_type(['option', 'with_or_without_index']) - def isleader(self, options_bag: List[OptionBag]): + def isleader(self): """Test if option is a leader""" - return options_bag[-1].option.impl_is_leader() + return self._subconfig.option.impl_is_leader() @option_type(['option', 'with_or_without_index', 'symlink']) - def isfollower(self, options_bag: List[OptionBag]): + def isfollower(self): """Test if option is a follower""" - return options_bag[-1].option.impl_is_follower() + return self._subconfig.option.impl_is_follower() @option_type(['option', 'optiondescription', 'with_or_without_index']) - def isdynamic(self, options_bag: List[OptionBag]): + def isdynamic(self): """Test if option is a dynamic optiondescription""" - return options_bag[-1].option.impl_is_dynsymlinkoption() + return self._subconfig.is_dynamic @option_type(['option', 'symlink', 'with_or_without_index']) - def issymlinkoption(self, options_bag: List[OptionBag]) -> bool: + def issymlinkoption(self) -> bool: """Test if option is a symlink option""" - return options_bag[-1].option.impl_is_symlinkoption() + return self._subconfig.option.impl_is_symlinkoption() @option_type(['option', 'with_or_without_index', 'symlink']) - def default(self, options_bag: List[OptionBag]): + def default(self): """Get default value for an option (not for optiondescription)""" - return options_bag[-1].option.impl_getdefault() + return self._subconfig.option.impl_getdefault() @option_type(['option', 'with_or_without_index', 'symlink']) - def defaultmulti(self, options_bag: List[OptionBag]): + def defaultmulti(self): """Get default value when added a value for a multi option (not for optiondescription)""" - if not options_bag[-1].option.impl_is_multi(): + if not self._subconfig.option.impl_is_multi(): raise ConfigError(_('only multi value has defaultmulti')) - return options_bag[-1].option.impl_getdefault_multi() + return self._subconfig.option.impl_getdefault_multi() @option_type(['option', 'optiondescription', 'symlink', 'with_or_without_index']) - def type(self, options_bag: List[OptionBag]): + def type(self): """Get de option type""" - option_bag = options_bag[-1] - if option_bag.option.impl_is_optiondescription(): + option = self._subconfig.option + if option.impl_is_optiondescription(): return 'optiondescription' - return option_bag.option.get_type() + return option.get_type() @option_type(['option', 'with_or_without_index']) - def pattern(self, options_bag: List[OptionBag]) -> str: + def pattern(self) -> str: """Get the option pattern""" - option_bag = options_bag[-1] - option = option_bag.option + option = self._subconfig.option type = option.get_type() if isinstance(option, RegexpOption): return option._regexp.pattern @@ -379,25 +341,31 @@ class _TiramisuOptionOption(_TiramisuOptionOptionDescription): return r'^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$' @option_type(['option', 'leadership']) - def leader(self, options_bag: List[OptionBag]): + def leader(self): """Get the leader option for a follower option""" - option = options_bag[-1].option - leadership = options_bag[-1].option - if not isinstance(option, Leadership): - leadership = leadership.impl_get_leadership() - path = leadership.get_leader().impl_getpath() - return TiramisuOption(path, + option = self._subconfig.option + if isinstance(option, Leadership): + leadership = self._subconfig + else: + leadership = self._subconfig.parent + leader_subconfig = leadership.get_child(leadership.option.get_leader(), + None, + True, + ) + return TiramisuOption(leader_subconfig.path, None, self._config_bag, + subconfig=leader_subconfig, ) @option_type(['option', 'with_or_without_index']) - def index(self, options_bag: List[OptionBag]): + def index(self): """Get then index of option""" - return options_bag[-1].index + return self._subconfig.index class TiramisuOptionOption(CommonTiramisuOption): + """Manage option""" def __call__(self, name: str, index: Optional[int]=None, @@ -414,34 +382,26 @@ class TiramisuOptionOwner(CommonTiramisuOption): """Manage option's owner""" @option_type(['symlink', 'option', 'with_index']) - def get(self, options_bag: List[OptionBag]): + def get(self): """Get owner for a specified option""" - option_bag = options_bag[-1] - if len(options_bag) > 1: - parent_option_bag = options_bag[-2] - else: - parent_option_bag = None - return self._config_bag.context.get_owner(option_bag) + return self._config_bag.context.get_owner(self._subconfig) @option_type(['symlink', 'option', 'with_index']) - def isdefault(self, options_bag: List[OptionBag]): + def isdefault(self): """Is option has defaut value""" - option_bag = options_bag[-1] - return self._config_bag.context.get_values().is_default_owner(option_bag) + return self._config_bag.context.get_owner(self._subconfig) == owners.default @option_type(['option', 'with_index']) def set(self, - options_bag: List[OptionBag], owner: str, ) -> None: """Get owner for a specified option""" - option_bag = options_bag[-1] try: obj_owner = getattr(owners, owner) except AttributeError: owners.addowner(owner) obj_owner = getattr(owners, owner) - self._config_bag.context.get_values().set_owner(option_bag, + self._config_bag.context.get_values().set_owner(self._subconfig, obj_owner, ) @@ -452,81 +412,70 @@ class TiramisuOptionProperty(CommonTiramisuOption): @option_type(['option', 'optiondescription', 'with_or_without_index']) def get(self, - options_bag: List[OptionBag], only_raises=False, uncalculated=False, ): """Get properties for an option""" - option_bag = options_bag[-1] settings = self._config_bag.context.get_settings() if not only_raises: - return settings.getproperties(option_bag) - return settings.calc_raises_properties(option_bag, + return settings.getproperties(self._subconfig) + return settings.calc_raises_properties(self._subconfig, uncalculated=uncalculated, ) @option_type(['option', 'optiondescription', 'with_or_without_index']) - def add(self, - options_bag: List[OptionBag], - prop,): + def add(self, prop): """Add new property for an option""" - option_bag = options_bag[-1] if prop in FORBIDDEN_SET_PROPERTIES: raise ConfigError(_('cannot add this property: "{0}"').format( ' '.join(prop))) settings = self._config_bag.context.get_settings() - props = settings.get_stored_properties(option_bag.path, - option_bag.index, - option_bag.option.impl_getproperties(), + props = settings.get_stored_properties(self._path, + self._index, + self._subconfig.option.impl_getproperties(), ) - settings.setproperties(option_bag, + settings.setproperties(self._subconfig, props | {prop}, ) @option_type(['option', 'optiondescription', 'with_or_without_index']) def remove(self, - options_bag: List[OptionBag], prop, ): """Remove new property for an option""" - option_bag = options_bag[-1] settings = self._config_bag.context.get_settings() - props = settings.getproperties(option_bag) - settings.setproperties(option_bag, + props = settings.getproperties(self._subconfig) + settings.setproperties(self._subconfig, props - {prop}, ) @option_type(['option', 'optiondescription', 'with_or_without_index']) - def reset(self, options_bag: List[OptionBag]): + def reset(self): """Reset all personalised properties""" - option_bag = options_bag[-1] - self._config_bag.context.get_settings().reset(option_bag) + self._config_bag.context.get_settings().reset(self._subconfig) class TiramisuOptionPermissive(CommonTiramisuOption): """Manage option's permissive""" @option_type(['option', 'optiondescription', 'symlink', 'with_or_without_index']) - def get(self, options_bag: List[OptionBag]): + def get(self): """Get permissives value""" - return self._config_bag.context.get_settings().getpermissives(options_bag[-1]) + return self._config_bag.context.get_settings().getpermissives(self._subconfig) @option_type(['option', 'optiondescription', 'with_or_without_index']) def set(self, - options_bag: List[OptionBag], permissives, ): """Set permissives value""" - option_bag = options_bag[-1] - self._config_bag.context.get_settings().setpermissives(option_bag, + self._config_bag.context.get_settings().setpermissives(self._subconfig, permissives=permissives, ) @option_type(['option', 'optiondescription', 'with_index']) - def reset(self, options_bag: List[OptionBag]): + def reset(self): """Reset all personalised permissive""" - option_bag = options_bag[-1] - self._config_bag.context.get_settings().reset_permissives(option_bag) + self._config_bag.context.get_settings().reset_permissives(self._subconfig) class TiramisuOptionInformation(CommonTiramisuOption): @@ -534,132 +483,140 @@ class TiramisuOptionInformation(CommonTiramisuOption): @option_type(['option', 'optiondescription', 'with_or_without_index', 'symlink']) def get(self, - options_bag: List[OptionBag], name: str, default=undefined, ) -> Any: """Get information""" - option_bag = options_bag[-1] try: - return self._config_bag.context.get_values().get_information(option_bag, + return self._config_bag.context.get_values().get_information(self._subconfig, name, undefined, ) except ValueError: - return option_bag.option.impl_get_information(name, default) + return self._subconfig.option.impl_get_information(name, default) @option_type(['option', 'optiondescription']) def set(self, - options_bag: List[OptionBag], key: str, value: Any) -> None: """Set information""" - option_bag = options_bag[-1] - self._config_bag.context.get_values().set_information(option_bag, + self._config_bag.context.get_values().set_information(self._subconfig, key, value, ) @option_type(['option', 'optiondescription']) def reset(self, - options_bag: List[OptionBag], key: str, ) -> None: """Remove information""" - option_bag = options_bag[-1] self._config_bag.context.get_values().del_information(key, - path=option_bag.path, + path=self._path, ) @option_type(['option', 'optiondescription', 'with_or_without_index', 'symlink']) - def list(self, - options_bag: List[OptionBag], - ) -> list: + def list(self) -> list: """List information's keys""" - option_bag = options_bag[-1] - lst1 = set(option_bag.option.impl_list_information()) - lst2 = set(self._config_bag.context.get_values().list_information(option_bag.path)) + lst1 = set(self._subconfig.option.impl_list_information()) + lst2 = set(self._config_bag.context.get_values().list_information(self._path)) return lst1 | lst2 -class TiramisuOptionValue(CommonTiramisuOption): +class _TiramisuODGet(): + def _od_get(self, + root_subconfig: SubConfig, + ) -> dict: + """exports the whole config into a `dict` + :returns: dict of Option's name (or path) and values + """ + #for self._subconfig, value in self._config_bag.context.walk(root_self._subconfig): + def parse_od_get(values): + ret_ = {} + for subconfig, value in values.items(): + option = TiramisuOption(subconfig.path, + subconfig.index, + self._config_bag, + subconfig=subconfig, + ) + if option.isoptiondescription(): + value = parse_od_get(value) + ret_[option] = value + return ret_ +# else: +# leader_ret = [] +# leader = data['leader'] +# for idx, value in enumerate(self.get_value(leader, +# need_help=False, +# )): +# leader_dict = {leader: value} +# for follower in data.get(idx, []): +# leader_dict[follower] = self.get_value(follower, +# need_help=False, +# ) +# leader_ret.append(leader_dict) +# ret[leader] = leader_ret + return parse_od_get(self._config_bag.context.walk(root_subconfig)) + + +class TiramisuOptionValue(CommonTiramisuOption, _TiramisuODGet): """Manage option's value""" _validate_properties = True - @option_type('optiondescription') - def dict(self, options_bag: List[OptionBag]): - """Obsolete: dict with path as key and value""" - return self._config_bag.context.make_dict(options_bag[-1]) - @option_type(['option', 'symlink', 'with_index', 'optiondescription']) - def get(self, - options_bag: List[OptionBag], - ): - """Get value""" - if options_bag[-1].option.impl_is_optiondescription(): - return self._config_bag.context.make_dict(options_bag[-1]) - return self._get(options_bag) + def get(self): + """Get value for an option or option and sub option with values with optiondescription""" + if self._subconfig.option.impl_is_optiondescription(): + return self._od_get(self._subconfig) + return self._get() def _get(self, - options_bag: OptionBag, + need_help: bool=True, ): """Get option's value""" - option_bag = options_bag[-1] - if len(options_bag) > 1: - parent_option_bag = options_bag[-2] - else: - parent_option_bag = None - return self._config_bag.context.get_value(option_bag, - parent_option_bag, - ) + return self._config_bag.context.get_value(self._subconfig, need_help) @option_type(['option', 'with_index']) def set(self, - options_bag: List[OptionBag], value, ): """Change option's value""" - option_bag = options_bag[-1] - values = option_bag.config_bag.context.get_values() - if not isinstance(value, Calculation) and option_bag.option.impl_is_leader() and \ - len(value) < self._config_bag.context.get_length_leadership(options_bag[-2]): + option = self._subconfig.option + if not isinstance(value, Calculation) and option.impl_is_leader() and \ + len(value) < self._subconfig.parent.get_length_leadership(): raise LeadershipError(_('cannot reduce length of the leader "{}"' - '').format(option_bag.option.impl_get_display_name())) - return option_bag.config_bag.context.set_value(option_bag, - value, - ) + '').format(option.impl_get_display_name())) + return self._subconfig.config_bag.context.set_value(self._subconfig, + value, + ) @option_type(['group', 'option', 'with_index']) def reset(self, - options_bag: List[OptionBag], is_group: bool=False, ) -> None: """Reset value for an option""" - option_bag = options_bag[-1] if is_group: - self._config_bag.context.reset(option_bag.path, + self._config_bag.context.reset(self._subconfig.path, self._config_bag, ) else: values = self._config_bag.context.get_values() - if option_bag.index is not None: - values.reset_follower(option_bag) + if self._subconfig.index is not None: + values.reset_follower(self._subconfig) else: - values.reset(option_bag) + values.reset(self._subconfig) @option_type(['option', 'with_index', 'symlink']) - def default(self, options_bag: List[OptionBag]): + def default(self): """Get default value (default of option or calculated value)""" - return self._config_bag.context.get_values().get_default_value(options_bag[-1]) + return self._config_bag.context.get_values().get_default_value(self._subconfig) @option_type(['option', 'with_index']) - def valid(self, options_bag: List[OptionBag]): + def valid(self): """The if the option's value is valid""" - option_bag = options_bag[-1] try: with catch_warnings(record=True) as warns: simplefilter("always", ValueErrorWarning) - self._get(options_bag) + self._get(self._subconfig) for warn in warns: if isinstance(warn.message, ValueErrorWarning): return False @@ -668,26 +625,23 @@ class TiramisuOptionValue(CommonTiramisuOption): return True @option_type(['choice', 'with_or_without_index']) - def list(self, options_bag: List[OptionBag]): + def list(self): """All values available for a ChoiceOption""" - option_bag = options_bag[-1] - return option_bag.option.impl_get_values(option_bag) + return self._subconfig.option.impl_get_values(self._subconfig) @option_type('leader') def pop(self, - options_bag: List[OptionBag], index: int, ): """Pop a value""" - self._config_bag.context.get_values().reset_leadership(options_bag[-1], - options_bag[-2], + self._config_bag.context.get_values().reset_leadership(self._subconfig, index, ) @option_type(['leader', 'follower', 'with_or_without_index']) - def len(self, options_bag: List[OptionBag]): + def len(self): """Length for a follower option""" - return self._config_bag.context.get_length_leadership(options_bag[-2]) + return self._subconfig.parent.get_length_leadership() def _registers(_registers: Dict[str, type], @@ -705,7 +659,7 @@ def _registers(_registers: Dict[str, type], class TiramisuConfig(TiramisuHelp, _TiramisuOptionWalk): def __init__(self, config_bag: ConfigBag, - orig_config_bags: Optional[List[OptionBag]], + orig_config_bags: Optional[List["OptionBag"]], ) -> None: self._config_bag = config_bag self._orig_config_bags = orig_config_bags @@ -737,7 +691,10 @@ class TiramisuConfig(TiramisuHelp, _TiramisuOptionWalk): return self._config_bag.context.impl_getname() -class TiramisuOption(CommonTiramisu, _TiramisuOptionOption, TiramisuConfig): +class TiramisuOption(CommonTiramisu, + _TiramisuOptionOption, + TiramisuConfig, + ): """Manage selected option""" _validate_properties = False _registers = {} @@ -745,14 +702,24 @@ class TiramisuOption(CommonTiramisu, _TiramisuOptionOption, TiramisuConfig): path: Optional[str]=None, index: Optional[int]=None, config_bag: Optional[ConfigBag]=None, + *, + subconfig: Optional[SubConfig]=None, ) -> None: self._path = path self._index = index self._config_bag = config_bag + self._subconfig = subconfig self._tiramisu_dict = None if not self._registers: _registers(self._registers, 'TiramisuOption') + def __repr__(self): + msg = f' Any: if subfunc in self._registers: return self._registers[subfunc](self._path, @@ -760,49 +727,44 @@ class TiramisuOption(CommonTiramisu, _TiramisuOptionOption, TiramisuConfig): self._config_bag, ) raise ConfigError(_(f'please specify a valid sub function ({self.__class__.__name__}.{subfunc})')) +# +# @option_type('optiondescription') +# def find(self, +# subconfig: SubConfig, +# name: str, +# value=undefined, +# type=None, +# first: bool=False): +# """Find an option by name (only for optiondescription)""" +# option_bag = subconfig.option_bag +# if not first: +# ret = [] +# for path in self._config_bag.context.find(option_bag=option_bag, +# byname=name, +# byvalue=value, +# bytype=type, +# ): +# t_option = TiramisuOption(path, +# None, # index for a follower ? +# self._config_bag, +# ) +# if first: +# return t_option +# ret.append(t_option) +# return ret @option_type('optiondescription') - def find(self, - options_bag: List[OptionBag], - name: str, - value=undefined, - type=None, - first: bool=False): - """Find an option by name (only for optiondescription)""" - option_bag = options_bag[-1] - if not first: - ret = [] - for path in self._config_bag.context.find(option_bag=option_bag, - byname=name, - byvalue=value, - bytype=type, - ): - t_option = TiramisuOption(path, - None, # index for a follower ? - self._config_bag, - ) - if first: - return t_option - ret.append(t_option) - return ret - - @option_type('optiondescription') - def group_type(self, options_bag: List[OptionBag]): + def group_type(self): """Get type for an optiondescription (only for optiondescription)""" - return options_bag[-1].option.impl_get_group_type() + return self._subconfig.option.impl_get_group_type() @option_type('optiondescription') def list(self, - options_bag: List[OptionBag], - type='option', - recursive=False, - group_type=None, + validate_properties: bool=True, ): """List options inside an option description (by default list only option)""" - return self._list(options_bag[-1], - type, - group_type, - recursive, + return self._list(self._subconfig, + validate_properties, ) def _load_dict(self, @@ -817,7 +779,6 @@ class TiramisuOption(CommonTiramisu, _TiramisuOptionOption, TiramisuConfig): @option_type('optiondescription') def dict(self, - options_bag: List[OptionBag], clearable: str="all", remotable: str="minimum", form: List=[], @@ -830,7 +791,6 @@ class TiramisuOption(CommonTiramisu, _TiramisuOptionOption, TiramisuConfig): @option_type('optiondescription') def updates(self, - options_bag: List[OptionBag], body: List, ) -> Dict: """Updates value with tiramisu format""" @@ -886,25 +846,22 @@ class TiramisuContextInformation(TiramisuConfig): self._config_bag.context.get_values()._informations = deepcopy(informations) -class TiramisuContextValue(TiramisuConfig): +class TiramisuContextValue(TiramisuConfig, _TiramisuODGet): """Manage config value""" def mandatory(self): """Return path of options with mandatory property without any value""" config_bag = self._config_bag.copy() config_bag.properties -= {'mandatory', 'empty', 'warnings'} config_bag.set_permissive() - root_option_bag = OptionBag(self._config_bag.context.get_description(), - None, - config_bag, - ) + root = self._config_bag.context.get_root(config_bag) options = [] - for option_bag in self._config_bag.context.walk(root_option_bag, - recursive=True, - types=['mandatory'], - ): - options.append(TiramisuOption(option_bag.path, - option_bag.index, + for subconfig in self._config_bag.context.walk(root, + only_mandatory=True, + ): + options.append(TiramisuOption(subconfig.path, + subconfig.index, self._config_bag, + subconfig=subconfig, )) return options @@ -947,21 +904,10 @@ class TiramisuContextValue(TiramisuConfig): self._config_bag, ) - def dict(self): - """Obsolete: dict with path as key and value""" - option_bag = OptionBag(self._config_bag.context.get_description(), - None, - self._config_bag, - ) - return self._config_bag.context.make_dict(option_bag) - def get(self): - """Dict with path as key and value""" - option_bag = OptionBag(self._config_bag.context.get_description(), - None, - self._config_bag, - ) - return self._config_bag.context.make_dict(option_bag) + """Get option and sub option with values""" + root = self._config_bag.context.get_root(self._config_bag) + return self._od_get(root) def exportation(self, with_default_owner: bool=False, @@ -1008,9 +954,9 @@ class TiramisuContextProperty(TiramisuConfig): settings = self._config_bag.context.get_settings() settings.read_only(self._config_bag) self._reset_config_properties() - if 'force_store_value' not in old_props and \ - 'force_store_value' in self._config_bag.properties: - self._force_store_value() +# if 'force_store_value' not in old_props and \ +# 'force_store_value' in self._config_bag.properties: +# self._force_store_value() def read_write(self): """Set config to read and write mode""" @@ -1021,9 +967,9 @@ class TiramisuContextProperty(TiramisuConfig): permissives = frozenset(settings.get_context_permissives() | or_properties) settings.set_context_permissives(permissives) self._reset_config_properties() - if 'force_store_value' not in old_props and \ - 'force_store_value' in self._config_bag.properties: - self._force_store_value() +# if 'force_store_value' not in old_props and \ +# 'force_store_value' in self._config_bag.properties: +# self._force_store_value() def add(self, prop): """Add a config property""" @@ -1047,17 +993,17 @@ class TiramisuContextProperty(TiramisuConfig): props, ): """Personalise config properties""" - if 'force_store_value' in props: - force_store_value = 'force_store_value' not in self._config_bag.properties - else: - force_store_value = False +# if 'force_store_value' in props: +# force_store_value = 'force_store_value' not in self._config_bag.properties +# else: +# force_store_value = False context = self._config_bag.context context.get_settings().set_context_properties(props, self._config_bag.context, ) self._reset_config_properties() - if force_store_value: - self._force_store_value() +# if force_store_value: +# self._force_store_value() def reset(self): """Remove config properties""" @@ -1071,19 +1017,19 @@ class TiramisuContextProperty(TiramisuConfig): def importation(self, properties): """Import config properties""" - if 'force_store_value' in properties.get(None, {}).get(None, []): - force_store_value = 'force_store_value' not in self._config_bag.properties - else: - force_store_value = False +# if 'force_store_value' in properties.get(None, {}).get(None, []): +# force_store_value = 'force_store_value' not in self._config_bag.properties +# else: +# force_store_value = False self._config_bag.context.get_settings()._properties = deepcopy(properties) self._config_bag.context.reset_cache(None, None) self._reset_config_properties() - if force_store_value: - self._force_store_value() - - def _force_store_value(self): - descr = self._config_bag.context.get_description() - descr.impl_build_force_store_values(self._config_bag) +# if force_store_value: +# self._force_store_value() +# +# def _force_store_value(self): +# descr = self._config_bag.context.get_description() +# descr.impl_build_force_store_values(self._config_bag) def setdefault(self, properties: Set[str], @@ -1188,46 +1134,39 @@ class TiramisuContextOption(TiramisuConfig, _TiramisuOptionWalk): **kwargs) -> None: self._tiramisu_dict = None super().__init__(*args, **kwargs) - - def find(self, - name, - value=undefined, - type=None, - first=False): - """Find an or a list of options""" - options = [] - option_bag = OptionBag(self._config_bag.context.get_description(), - None, - self._config_bag, - ) - for path in self._config_bag.context.find(option_bag, - byname=name, - byvalue=value, - bytype=type, - ): - option = TiramisuOption(path, - None, - self._config_bag, - ) - if first: - return option - options.append(option) - return options +# +# def find(self, +# name, +# value=undefined, +# type=None, +# first=False): +# """Find an or a list of options""" +# options = [] +# option_bag = OptionBag(self._config_bag.context.get_description(), +# None, +# self._config_bag, +# ) +# for path in self._config_bag.context.find(option_bag, +# byname=name, +# byvalue=value, +# bytype=type, +# ): +# option = TiramisuOption(path, +# None, +# self._config_bag, +# ) +# if first: +# return option +# options.append(option) +# return options def list(self, - type='option', - group_type=None, - recursive=False, + validate_properties: bool=True, ): """List options (by default list only option)""" - root_option_bag = OptionBag(self._config_bag.context.get_description(), - None, - self._config_bag, - ) - return self._list(root_option_bag, - type, - group_type, - recursive, + root = self._config_bag.context.get_root(self._config_bag) + return self._list(root, + validate_properties, ) def _load_dict(self, @@ -1315,20 +1254,17 @@ class _TiramisuContextGroupConfig(TiramisuConfig): def list(self): """List children's config""" - ret = [] - for child in self._config_bag.context.get_children(): - ret.append(self._return_config(child)) - return ret - - def find(self, - name: str, - value=undefined, - ): - """Find an or a list of config with finding option""" - return GroupConfig(self._config_bag.context.find_group(byname=name, - byvalue=value, - config_bag=self._config_bag, - )) + return [self._return_config(child) for child in self._config_bag.context.get_children()] +# +# def find(self, +# name: str, +# value=undefined, +# ): +# """Find an or a list of config with finding option""" +# return GroupConfig(self._config_bag.context.find_group(byname=name, +# byvalue=value, +# config_bag=self._config_bag, +# )) def __call__(self, path: Optional[str]): diff --git a/tiramisu/autolib.py b/tiramisu/autolib.py index a62a27b..c10b5ea 100644 --- a/tiramisu/autolib.py +++ b/tiramisu/autolib.py @@ -19,11 +19,12 @@ # ____________________________________________________________ "enables us to carry out a calculation and return an option's value" from typing import Any, Optional, Union, Callable, Dict, List +from os.path import commonprefix from itertools import chain from .error import PropertiesOptionError, ConfigError, LeadershipError, ValueWarning from .i18n import _ -from .setting import undefined, ConfigBag, OptionBag, Undefined +from .setting import undefined, ConfigBag, Undefined from .function import FUNCTION_WAITING_FOR_DICT # ____________________________________________________________ @@ -55,6 +56,7 @@ class Params: class Param: + __slots__ = tuple() pass @@ -82,11 +84,14 @@ class ParamOption(Param): class ParamDynOption(ParamOption): - __slots__ = ('subpath',) + __slots__ = ('suffixes', + 'dynoptiondescription', + 'optional', + ) def __init__(self, option: 'Option', - subpath: str, - dynoptiondescription: 'DynOptionDescription', + suffixes: list[str], + dynoptiondescription: 'DynOptionDescription'=None, notraisepropertyerror: bool=False, raisepropertyerror: bool=False, optional: bool=False, @@ -95,7 +100,7 @@ class ParamDynOption(ParamOption): notraisepropertyerror, raisepropertyerror, ) - self.subpath = subpath + self.suffixes = suffixes self.dynoptiondescription = dynoptiondescription self.optional = optional @@ -179,17 +184,18 @@ class Calculation: self.warnings_only = warnings_only def execute(self, - option_bag: OptionBag, + subconfig: "SubConfig", + *, orig_value: Any=undefined, allow_value_error: bool=False, force_value_warning: bool=False, for_settings: bool=False, ) -> Any: - return carry_out_calculation(option_bag.option, + return carry_out_calculation(subconfig, callback=self.function, callback_params=self.params, - index=option_bag.index, - config_bag=option_bag.config_bag, + index=subconfig.index, + config_bag=subconfig.config_bag, orig_value=orig_value, allow_value_error=allow_value_error, force_value_warning=force_value_warning, @@ -197,18 +203,18 @@ class Calculation: ) def help(self, - option_bag: OptionBag, + subconfig: "SubConfig", for_settings: bool=False, ) -> str: if not self.help_function: - return self.execute(option_bag, + return self.execute(subconfig, for_settings=for_settings, ) - return carry_out_calculation(option_bag.option, + return carry_out_calculation(subconfig, callback=self.help_function, callback_params=self.params, - index=option_bag.index, - config_bag=option_bag.config_bag, + index=subconfig.index, + config_bag=subconfig.config_bag, for_settings=for_settings, ) @@ -218,113 +224,100 @@ class Calculation: def manager_callback(callback: Callable, param: Param, - option, + subconfig: 'SubConfig', index: Optional[int], orig_value, config_bag: ConfigBag, for_settings: bool, ) -> Any: """replace Param by true value""" - def calc_index(param, index, same_leadership): - if index is not None: - if hasattr(param, 'whole'): - whole = param.whole - else: - # if value is same_leadership, follower are isolate by default - # otherwise option is a whole option - whole = not same_leadership - if not whole: - return index - return None + option = subconfig.option + def calc_apply_index(param, + same_leadership, + ): + return index is not None and \ + not getattr(param, 'whole', not same_leadership) def calc_self(param, - option, index, value, config_bag, ): # index must be apply only if follower - is_follower = option.impl_is_follower() - apply_index = calc_index(param, index, is_follower) - if value is undefined or (apply_index is None and is_follower): - path = option.impl_getpath() - option_bag = OptionBag(option, - None, - config_bag, - properties=None, - ) - properties = config_bag.context.get_settings().getproperties(option_bag, + is_follower = subconfig.option.impl_is_follower() + # FIXME "same_leadership" or "is_follower"? + apply_index = calc_apply_index(param, + is_follower, + ) + if value is undefined or (apply_index is False and is_follower): + path = subconfig.path + properties = config_bag.context.get_settings().getproperties(subconfig, uncalculated=True, ) new_value = get_value(config_bag, - option, + subconfig, param, - apply_index, True, - properties, + apply_index=apply_index, + properties=properties, ) - if apply_index is None and is_follower: + if apply_index is False and is_follower: new_value[index] = value value = new_value - elif apply_index is not None and not is_follower: - value = value[apply_index] + elif apply_index is not False and not is_follower: + value = value[index] return value def get_value(config_bag, - option, + subconfig, param, - index, self_calc, + *, + apply_index=True, properties=undefined, ): - parent_option_bag, option_bag = get_option_bag(config_bag, - option, - param, - index, - self_calc, - properties=properties, - ) - if option.impl_is_follower() and index is None: + option = subconfig.option + if option.impl_is_follower() and apply_index is False: value = [] - for idx in range(config_bag.context.get_length_leadership(parent_option_bag)): - parent_option_bag, option_bag = get_option_bag(config_bag, - option, - param, - idx, - self_calc, - properties=properties, - ) + for idx in range(subconfig.parent.get_length_leadership()): + subconfig = get_option_bag(config_bag, + option, + param, + idx, + self_calc, + properties=properties, + ) value.append(_get_value(param, - option_bag, + subconfig, )) else: value = _get_value(param, - option_bag, + subconfig, ) return value def _get_value(param: Params, - option_bag: OptionBag, + subconfig: SubConfig, ) -> Any: try: # get value - value = config_bag.context.get_value(option_bag) + value = config_bag.context.get_value(subconfig) except PropertiesOptionError as err: # raise PropertiesOptionError (which is catched) because must not add value None in carry_out_calculation if param.notraisepropertyerror or param.raisepropertyerror: raise err from err - display_name = option_bag.option.impl_get_display_name() raise ConfigError(_('unable to carry out a calculation for "{}", {}').format(display_name, err)) from err except ValueError as err: - raise ValueError(_('the option "{0}" is used in a calculation but is invalid ({1})').format(option_bag.option.impl_get_display_name(), err)) from err + display_name = subconfig.option.impl_get_display_name() + raise ValueError(_('the option "{0}" is used in a calculation but is invalid ({1})').format(display_name, err)) from err except AttributeError as err: if isinstance(param, ParamDynOption) and param.optional: # cannot acces, simulate a propertyerror - raise PropertiesOptionError(option_bag, + raise PropertiesOptionError(subconfig, ['configerror'], config_bag.context.get_settings(), ) - display_name = option_bag.option.impl_get_display_name() + display_name = subconfig.option.impl_get_display_name() raise ConfigError(_(f'unable to get value for calculating "{display_name}", {err}')) from err return value @@ -333,6 +326,7 @@ def manager_callback(callback: Callable, param, index_, self_calc, + *, properties=undefined, ): # don't validate if option is option that we tried to validate @@ -345,17 +339,14 @@ def manager_callback(callback: Callable, if self_calc: config_bag.unrestraint() config_bag.remove_validation() - root_option_bag = OptionBag(config_bag.context.get_description(), - None, - config_bag, - ) +# root = config_bag.context.get_root(config_bag) try: - options_bag = config_bag.context.get_sub_option_bag(root_option_bag, - opt.impl_getpath(), - index_, - validate_properties=not self_calc, - properties=properties, - ) + subconfig = config_bag.context.get_sub_config(config_bag, + opt.impl_getpath(), + index_, + validate_properties=not self_calc, + properties=properties, + ) except PropertiesOptionError as err: # raise PropertiesOptionError (which is catched) because must not add value None in carry_out_calculation if param.notraisepropertyerror or param.raisepropertyerror: @@ -373,30 +364,36 @@ def manager_callback(callback: Callable, ) display_name = option.impl_get_display_name() raise ConfigError(_(f'unable to get value for calculating "{display_name}", {err}')) from err - if len(options_bag) > 1: - parent_option_bag = options_bag[-2] - else: - parent_option_bag = None - return parent_option_bag, options_bag[-1] + return subconfig + + def get_common_path(path1, path2): + common_path = commonprefix([path1, path2]) + if common_path in [path1, path2]: + return common_path + if common_path.endswith('.'): + return common_path[:-1] + if '.' in common_path: + return common_path.rsplit('.', 1)[0] + return None if isinstance(param, ParamValue): return param.value if isinstance(param, ParamInformation): if isinstance(param, ParamSelfInformation): - option_bag = OptionBag(option, - index, - config_bag, - ) + isubconfig = subconfig elif param.option: - option_bag = OptionBag(param.option, - None, - config_bag, - ) + isubconfig = get_option_bag(config_bag, + param.option, + param, + None, + False, + #properties=properties, + ) else: - option_bag = None + isubconfig = None try: - return config_bag.context.get_values().get_information(option_bag, + return config_bag.context.get_values().get_information(isubconfig, param.information_name, param.default_value, ) @@ -409,13 +406,12 @@ def manager_callback(callback: Callable, if isinstance(param, ParamSuffix): if not option.issubdyn(): - display_name = option_bag.option.impl_get_display_name() + display_name = subconfig.option.impl_get_display_name() raise ConfigError(_('option "{display_name}" is not in a dynoptiondescription')) - return option.get_suffixes()[-1] + return subconfig.suffixes[-1] if isinstance(param, ParamSelfOption): value = calc_self(param, - option, index, orig_value, config_bag, @@ -429,52 +425,31 @@ def manager_callback(callback: Callable, if isinstance(param, ParamOption): callbk_option = param.option callbk_options = None + subconfigs = None if callbk_option.issubdyn(): found = False + if isinstance(param, ParamDynOption): - od_path = param.dynoptiondescription.impl_getpath() - if "." in od_path: - rootpath = od_path.rsplit('.', 1)[0] + '.' - else: - rootpath = '' - full_path = rootpath + param.subpath - root_option_bag = OptionBag(config_bag.context.get_description(), - None, - config_bag, - ) - try: - soptions_bag = config_bag.context.get_sub_option_bag(root_option_bag, - full_path, - #FIXME index? - index=None, - validate_properties=True, - properties=None, - ) - except AttributeError as err: - raise ConfigError(_(f'option "{option.impl_get_display_name()}" is not in a dynoptiondescription: {err}')) - callbk_option = soptions_bag[-1].option + # SUBDYN INSIDE CURRENT != SUBDYN OUTSIDE ? + callbk_option = callbk_option.to_sub_dyoption(param.suffixes) + found = True + else: + search_option = param.option + current_option_path = option.impl_getpath() + search_option_path = search_option.impl_getpath() + common_path = get_common_path(current_option_path, search_option_path) + if common_path: + parent_number = current_option_path[len(common_path) + 2:].count('.') + if parent_number: + raise Exception('pfff') + subconfig = subconfig.parent.get_child(search_option, + None, + True, + ) + else: + raise Exception('pfff') + subconfigs = [subconfig] found = True - elif option.impl_is_dynsymlinkoption(): - rootpath = option.rootpath - call_path = callbk_option.impl_getpath() - in_same_dyn = False - if not option.opt.issubdyn() and callbk_option.getsubdyn() == option.opt: - # First dyn - in_same_dyn = True - elif option.opt.issubdyn(): - # Search if callback and option has a common subdyn - callbk_subdyn = callbk_option.getsubdyn() - sub_dyn = option - while True: - sub_dyn = sub_dyn.getsubdyn() - if sub_dyn == callbk_subdyn: - in_same_dyn = True - break - if not sub_dyn.issubdyn(): - break - if in_same_dyn: - callbk_option = callbk_option.to_sub_dyoption(option.get_suffixes()) - found = True if not found: callbk_options = [] for doption_bag in callbk_option.getsubdyn().get_sub_children(callbk_option, @@ -482,29 +457,40 @@ def manager_callback(callback: Callable, index=None, ): callbk_options.append(doption_bag.option) - if callbk_options is None: - callbk_options = [callbk_option] + if index is not None and callbk_option.impl_get_leadership() and \ + callbk_option.impl_get_leadership().in_same_leadership(option): + if not callbk_option.impl_is_follower(): + # leader + index_ = None + with_index = True + else: + # follower + index_ = index + with_index = False + else: + index_ = None + with_index = False + if subconfigs is None: + subconfigs = [get_option_bag(config_bag, + callbk_option, + param, + index_, + False, + #properties=properties, + ) + ] +# callbk_options = [callbk_option] values = None else: values = [] - for callbk_option in callbk_options: - if index is not None and callbk_option.impl_get_leadership() and \ - callbk_option.impl_get_leadership().in_same_leadership(option): - if not callbk_option.impl_is_follower(): - # leader - index_ = None - with_index = True - else: - # follower - index_ = index - with_index = False - else: - index_ = None - with_index = False + #FIXME + values = None +# for callbk_option in callbk_options: + for subconfig in subconfigs: + callbk_option = subconfig.option value = get_value(config_bag, - callbk_option, + subconfig, param, - index_, False, ) if with_index: @@ -519,7 +505,7 @@ def manager_callback(callback: Callable, 'value': value} -def carry_out_calculation(option, +def carry_out_calculation(subconfig: 'SubConfig', callback: Callable, callback_params: Optional[Params], index: Optional[int], @@ -545,6 +531,7 @@ def carry_out_calculation(option, - tuple with option and boolean's force_permissive (True when don't raise if PropertiesOptionError) Values could have multiple values only when key is ''.""" + option = subconfig.option if not option.impl_is_optiondescription() and option.impl_is_follower() and index is None: raise Exception('follower must have index in carry_out_calculation!') def fake_items(iterator): @@ -556,7 +543,7 @@ def carry_out_calculation(option, try: value = manager_callback(callback, param, - option, + subconfig, index, orig_value, config_bag, diff --git a/tiramisu/cacheobj.py b/tiramisu/cacheobj.py index f23d988..165c292 100644 --- a/tiramisu/cacheobj.py +++ b/tiramisu/cacheobj.py @@ -26,24 +26,24 @@ class Cache: def __init__(self): self._cache = {} - def _get_path_index(self, option_bag): - if option_bag is None: + def _get_path_index(self, subconfig): + if subconfig is None: path = None index = None else: - path = option_bag.path - index = option_bag.index + path = subconfig.path + index = subconfig.index return path, index def getcache(self, - option_bag, + subconfig, type_, expiration=True, ): """get the cache value fot a specified path """ no_cache = False, None, False - path, index = self._get_path_index(option_bag) + path, index = self._get_path_index(subconfig) if path not in self._cache or index not in self._cache[path]: return no_cache value, timestamp, validated = self._cache[path][index] @@ -52,26 +52,26 @@ class Cache: props = value self_props = {} else: - props = option_bag.config_bag.properties + props = subconfig.config_bag.properties if type_ == 'self_props': # cached value is self_props self_props = value else: - self_props = option_bag.properties + self_props = subconfig.properties if 'cache' in props or \ 'cache' in self_props: if expiration and timestamp and \ ('expire' in props or \ 'expire' in self_props): ntime = int(time()) - if timestamp + option_bag.config_bag.expiration_time >= ntime: + if timestamp + subconfig.config_bag.expiration_time >= ntime: return True, value, validated else: return True, value, validated return no_cache def setcache(self, - option_bag, + subconfig, val, type_='values', validated=True, @@ -80,13 +80,13 @@ class Cache: if follower, add index """ if type_ == 'values': - if 'cache' not in option_bag.config_bag.properties and \ - 'cache' not in option_bag.properties: + if 'cache' not in subconfig.config_bag.properties and \ + 'cache' not in subconfig.properties: return - elif (option_bag is None or 'cache' not in option_bag.config_bag.properties) and \ + elif (subconfig is None or 'cache' not in subconfig.config_bag.properties) and \ 'cache' not in val: return - path, index = self._get_path_index(option_bag) + path, index = self._get_path_index(subconfig) self._cache.setdefault(path, {})[index] = (val, int(time()), validated) def delcache(self, path): diff --git a/tiramisu/config.py b/tiramisu/config.py index ab19d4a..9c060b8 100644 --- a/tiramisu/config.py +++ b/tiramisu/config.py @@ -27,14 +27,365 @@ from typing import Optional, List, Any, Union from .error import PropertiesOptionError, ConfigError, ConflictError, \ LeadershipError from .option import DynOptionDescription, Leadership, Option -from .setting import OptionBag, ConfigBag, Settings, undefined, groups +from .setting import ConfigBag, Settings, undefined, groups from .value import Values, owners from .i18n import _ from .cacheobj import Cache from .autolib import Calculation +from . import autolib -class _SubConfig: +class CCache: + __slots__ = tuple() + # ============================================================================= + # CACHE + def reset_cache(self, + subconfig, + resetted_opts=None, + ): + """reset all settings in cache + """ + if resetted_opts is None: + resetted_opts = [] + if subconfig is not None: + if 'cache' not in subconfig.config_bag.properties: + return + subconfig.config_bag.properties = subconfig.config_bag.properties - {'cache'} + self.reset_one_option_cache(subconfig, + resetted_opts, + ) + subconfig.config_bag.properties = subconfig.config_bag.properties | {'cache'} + else: + self._impl_values_cache.reset_all_cache() # pylint: disable=no-member + self.properties_cache.reset_all_cache() # pylint: disable=no-member + + def reset_one_option_cache(self, + subconfig, + resetted_opts, + ): + """reset cache for one option + """ + if subconfig.path in resetted_opts: + return + resetted_opts.append(subconfig.path) + config_bag = subconfig.config_bag + for woption in subconfig.option.get_dependencies(subconfig.option): + option = woption() + if option.issubdyn(): + # it's an option in dynoptiondescription, remove cache for all generated option + self.reset_cache_dyn_option(config_bag, + option, + resetted_opts, + ) + elif option.impl_is_dynoptiondescription(): + self._reset_cache_dyn_optiondescription(option, + config_bag, + resetted_opts, + ) + else: + option_subconfig = self.get_sub_config(config_bag, + option.impl_getpath(), + None, + properties=None, + validate_properties=False, + ) + self.reset_one_option_cache(option_subconfig, + resetted_opts, + ) + del option + subconfig.option.reset_cache(subconfig.path, + config_bag, + resetted_opts, + ) + + def _reset_cache_dyn_optiondescription(self, + option, + config_bag, + resetted_opts, + ): + # reset cache for all chidren + path = option.impl_getpath() + if '.' in path: + parent_path = path.rsplit('.', 1)[0] + parent_subconfig = self.get_sub_config(config_bag, + parent_path, + None, + properties=None, + validate_properties=False, + ) + else: + parent_subconfig = self.get_root(config_bag) + for subconfig in parent_subconfig.dyn_to_subconfig(option, + False, + ): + self.reset_one_option_cache(subconfig, + resetted_opts, + ) + for walk_subconfig in self.walk(subconfig, + no_value=True, + validate_properties=False, + ): + self.reset_one_option_cache(walk_subconfig, + resetted_opts, + ) + + + def reset_cache_dyn_option(self, + config_bag, + option, + resetted_opts, + ): + currents = [self.get_root(config_bag)] + sub_paths = option.impl_getpath() + for sub_path in sub_paths.split('.'): + new_currents = [] + for current in currents: + sub_option = current.option.get_child(sub_path, + config_bag, + current, + allow_dynoption=True, + ) + if sub_option.impl_is_dynoptiondescription(): + new_currents.extend(list(current.dyn_to_subconfig(sub_option, + False, + ))) + + else: + new_currents.append(current.get_child(sub_option, + None, + False, + properties=None, + ), + ) + currents = new_currents + for dyn_option_subconfig in currents: + self.reset_one_option_cache(dyn_option_subconfig, + resetted_opts, + ) + +class SubConfig: + __slots__ = ('config_bag', + 'option', + 'parent', + 'index', + 'path', + 'true_path', + 'properties', + 'is_dynamic', + 'suffixes', + '_length', + ) + def __init__(self, + option: Option, + index: Optional[int], + path: str, + config_bag: ConfigBag, + parent: Optional['SubConfig'], + suffixes: Optional[list[str]], + *, + true_path: Optional[str]=None, + properties: Union[list[str], undefined]=undefined, + validate_properties: bool=True, + ) -> None: + if path and '.' in path and not parent: + raise Exception('pff connard') + self.index = index + self.suffixes = suffixes + self.option = option + self.config_bag = config_bag + self.parent = parent + self._length = None + self.path = path + if true_path is None: + true_path = path + self.true_path = true_path + if properties is undefined: + if path is None: + self.properties = frozenset() + else: + settings = config_bag.context.get_settings() + self.properties = frozenset() + if validate_properties: + self.properties = settings.getproperties(self, + apply_requires=False, + ) + self.config_bag.context.get_settings().validate_properties(self) + self.properties = settings.getproperties(self, + apply_requires=True, + ) + else: + self.properties = properties + if parent and parent.is_dynamic or option.impl_is_dynoptiondescription(): + self.is_dynamic = True + else: + self.is_dynamic = False + if validate_properties: + self.config_bag.context.get_settings().validate_properties(self) + + def __repr__(self): + return f'' + + def dyn_to_subconfig(self, + child: Option, + validate_properties: bool, + follower_not_apply_requires: bool=False, + ) -> List['SubConfig']: + config_bag = self.config_bag + for suffix in child.get_suffixes(self): + try: + name = child.impl_getname(suffix) + if not validate_properties: + properties = None + else: + properties = undefined + yield self.get_child(child, + None, + validate_properties, + follower_not_apply_requires=follower_not_apply_requires, + suffix=suffix, + name=name, + properties=properties, + ) + except PropertiesOptionError as err: + if err.proptype in (['mandatory'], ['empty']): + raise err + + def get_leadership_children(self, + validate_properties, + ): + # it's a leadership so walk to leader and follower + # followers has specific length + leader, *followers = self.option.get_children() + yield self.get_child(leader, + None, + validate_properties, + ) + for idx in range(self.get_length_leadership()): + for follower in followers: + try: + yield self.get_child(follower, + idx, + validate_properties, + ) + except PropertiesOptionError as err: + if err.proptype in (['mandatory'], ['empty']): + raise err from err + + def get_children(self, + validate_properties, + ): + if self.option.impl_is_leadership(): + yield from self.get_leadership_children(validate_properties) + else: + for child in self.option.get_children(): + if child.impl_is_dynoptiondescription(): + yield from self.dyn_to_subconfig(child, + validate_properties, + ) + else: + try: + yield self.get_child(child, + None, + validate_properties, + ) + except PropertiesOptionError as err: + if err.proptype in (['mandatory'], ['empty']): + raise err + + def get_child(self, + option: Option, + index: Optional[int], + validate_properties: bool, + *, + properties=undefined, + follower_not_apply_requires: bool=False, + allow_dynoption: bool=False, + suffix: Optional[str]=None, + name: Optional[str]=None, + check_index: bool=True, + config_bag: ConfigBag=None, + true_path: Optional[str]=None, + ) -> 'SubConfig': + # pylint: disable=too-many-branches,too-many-locals,too-many-arguments + if config_bag is None: + config_bag = self.config_bag + + if not self.option.impl_is_optiondescription(): + raise TypeError(f'"{self.path}" is not an optiondescription') + + if check_index and index is not None: + if option.impl_is_optiondescription() or \ + option.impl_is_symlinkoption() or \ + not option.impl_is_follower(): + raise ConfigError('index must be set only with a follower option') + length = self.get_length_leadership() + if index >= length: + raise LeadershipError(_(f'index "{index}" is greater than the leadership ' + f'length "{length}" for option ' + f'"{option.impl_get_display_name()}"')) + if properties is undefined and not validate_properties: + # not transitive property error + apply_requires = False + else: + apply_requires = not follower_not_apply_requires or \ + option.impl_is_optiondescription() or \ + not option.impl_is_follower() + path = self.get_path(name, + option, + ) + if suffix is None: + suffixes = self.suffixes + else: + if self.suffixes: + suffixes = self.suffixes + [suffix] + else: + suffixes = [suffix] + return SubConfig(option, + index, + path, + self.config_bag, + self, + suffixes, + properties=properties, + validate_properties=validate_properties, + true_path=true_path, + ) + + def get_path(self, + name: str, + option: Option, + ) -> str: + if name is None: + name = option.impl_getname() + if self.path is None: + path = name + else: + path = self.path + '.' + name + return path + + def get_length_leadership(self): + """Get the length of leader option (useful to know follower's length) + """ + if self._length is None: + cconfig_bag = self.config_bag.copy() + cconfig_bag.remove_validation() + leader = self.option.get_leader() + path = self.get_path(None, + leader, + ) + subconfig = SubConfig(leader, + None, + path, + cconfig_bag, + self, + self.suffixes, + ) + self._length = len(cconfig_bag.context.get_value(subconfig)) + return self._length +autolib.SubConfig = SubConfig + + +class _Config(CCache): """Sub configuration management entry. Tree if OptionDescription's responsability. SubConfig are generated on-demand. A Config is also a SubConfig. @@ -63,19 +414,6 @@ class _SubConfig: self._impl_context = context self._impl_path = subpath - def get_length_leadership(self, - option_bag, - ): - """Get the length of leader option (useful to know follower's length) - """ - cconfig_bag = option_bag.config_bag.copy() - cconfig_bag.remove_validation() - option_bag = OptionBag(option_bag.option.get_leader(), - None, - cconfig_bag, - ) - return len(self.get_value(option_bag)) - def get_description(self): """get root description """ @@ -93,185 +431,11 @@ class _SubConfig: """ return self._impl_values # pylint: disable=no-member - # ============================================================================= - # CACHE - def reset_cache(self, - option_bag, - resetted_opts=None, - ): - """reset all settings in cache - """ - if resetted_opts is None: - resetted_opts = [] - - if option_bag is not None: - if 'cache' not in option_bag.config_bag.properties: - return - option_bag.config_bag.properties = option_bag.config_bag.properties - {'cache'} - self.reset_one_option_cache(resetted_opts, - option_bag, - ) - option_bag.config_bag.properties = option_bag.config_bag.properties | {'cache'} - else: - self._impl_values_cache.reset_all_cache() # pylint: disable=no-member - self.properties_cache.reset_all_cache() # pylint: disable=no-member - def get_values_cache(self): """get cache for values """ return self._impl_values_cache # pylint: disable=no-member - def reset_one_option_cache(self, - resetted_opts, - option_bag, - ): - """reset cache for one option - """ - if option_bag.path in resetted_opts: - return - resetted_opts.append(option_bag.path) - for woption in option_bag.option.get_dependencies(option_bag.option): - option = woption() - if woption in option_bag.option._get_suffixes_dependencies() and \ - option_bag.option.issubdyn() and \ - option.impl_is_dynoptiondescription(): - paths = [subdyn().impl_getpath() for subdyn in option.get_sub_dyns()] - for weak_subdyn in option_bag.option.get_sub_dyns(): - subdyn = weak_subdyn() - if subdyn.impl_getpath() in paths: - root_path = option_bag.option.impl_getpath() - if '.' in root_path: - root_path = root_path.rsplit('.', 1)[0] - nb_elt = root_path.count('.') + 1 - else: - root_path = '' - nb_elt = 1 - config_bag = option_bag.config_bag - root_option_bag = OptionBag(config_bag.context.get_description(), - None, - config_bag, - ) - full_path = root_path + '.' + option.impl_getpath().split('.', nb_elt)[-1] - try: - options_bag = config_bag.context.get_sub_option_bag(root_option_bag, - full_path, - #FIXME index? - None, - validate_properties=False, - properties=None, - allow_dynoption=True, - ) - except AttributeError as err: - raise ConfigError(_(f'option "{option.impl_get_display_name()}" is not in a dynoptiondescription: {err}')) - if options_bag[-1].option.impl_is_dynoptiondescription(): - for suffix in options_bag[-1].option.get_suffixes(config_bag, dynoption=options_bag[-2].option): - dynopt = options_bag[-1].option.to_dynoption(options_bag[-2].path, - options_bag[-2].option._suffixes + [suffix], - ) - doption_bag = OptionBag(dynopt, None, option_bag.config_bag) - self.reset_one_option_cache(resetted_opts, - doption_bag, - ) - else: - self._reset_cache_dyn_optiondescription(options_bag[-1], - resetted_opts, - ) - break - else: - soption_bag = OptionBag(option, - option_bag.index, - option_bag.config_bag, - properties=None, - ) - if option.impl_is_dynoptiondescription(): - self._reset_cache_dyn_optiondescription(soption_bag, - resetted_opts, - ) - elif option.issubdyn(): - # it's an option in dynoptiondescription, remove cache for all generated option - config_bag = option_bag.config_bag - options = [soption_bag] - dynopt = option.get_sub_dyns()[-1]() - dyn_path = dynopt.impl_getpath() - if '.' in dyn_path: - root_path = dyn_path.rsplit('.', 1)[0] - else: - root_path = '' - for suffix in dynopt.get_suffixes(config_bag): - suffix_dynopt = dynopt.to_dynoption(root_path, - [suffix], - ) - soption_bag = OptionBag(suffix_dynopt, None, config_bag) - for data in self.walk(soption_bag, validate_properties=False): - if isinstance(data, dict): - leader = data.pop('leader') - resetted_opts.append(leader.path) - leader.option.reset_cache(leader.path, - config_bag, - resetted_opts, - ) - for followers in data.values(): - for follower in followers: - resetted_opts.append(follower.path) - follower.option.reset_cache(follower.path, - config_bag, - resetted_opts, - ) - else: - resetted_opts.append(data.path) - data.option.reset_cache(data.path, - config_bag, - resetted_opts, - ) - else: - self.reset_one_option_cache(resetted_opts, - soption_bag, - ) - del option - option_bag.option.reset_cache(option_bag.path, - option_bag.config_bag, - resetted_opts, - ) - - def _reset_cache_dyn_optiondescription(self, - option_bag, - resetted_opts, - ): - # reset cache for all chidren - for doption_bag in option_bag.option.get_sub_children(option_bag.option, - option_bag.config_bag, - index=option_bag.index, - properties=None, - ): - for coption in doption_bag.option.get_children_recursively(None, - None, - option_bag.config_bag, - ): - coption_bag = self.get_sub_option_bag(doption_bag, # pylint: disable=no-member - coption.impl_getpath(), - None, - False, - )[-1] - self.reset_one_option_cache(resetted_opts, - coption_bag, - ) - self._reset_cache_dyn_option(option_bag, - resetted_opts, - ) - - def _reset_cache_dyn_option(self, - option_bag, - resetted_opts, - ): - for doption_bag in option_bag.option.get_sub_children(option_bag.option, - option_bag.config_bag, - index=option_bag.index, - properties=None - ): - self.reset_one_option_cache(resetted_opts, - doption_bag, - ) - # ============================================================================= # WALK def find(self, @@ -318,11 +482,12 @@ class _SubConfig: if option_bag.config_bag.properties: #remove option with propertyerror, ... try: - self.get_sub_option_bag(option_bag, # pylint: disable=no-member - path, - None, - True, - )[-1] + self.get_sub_config(option_bag.config_bag, # pylint: disable=no-member + path, + None, + validate_properties=True, + follower_not_apply_requires=False, + ) except PropertiesOptionError: continue found = True @@ -342,254 +507,268 @@ class _SubConfig: " with these criteria")) def _walk_valid_value(self, - option_bag, - types, - value=undefined, + subconfig, + only_mandatory, ): - if value is undefined: - value = self.get_value(option_bag, - need_help=False, - ) - l_option_bag = option_bag.copy() - l_option_bag.config_bag = option_bag.config_bag.copy() - if 'mandatory' in types: - l_option_bag.config_bag.properties |= {'mandatory', 'empty'} - self.get_settings().validate_mandatory(value, - l_option_bag, + value = self.get_value(subconfig, + need_help=False, + ) + ori_config_bag = subconfig.config_bag + config_bag = ori_config_bag.copy() + if only_mandatory: + config_bag.properties |= {'mandatory', 'empty'} + subconfig.config_bag = config_bag + self.get_settings().validate_mandatory(subconfig, + value, ) + subconfig.config_bag = ori_config_bag return value + def get_root(self, + config_bag: ConfigBag, + ) -> SubConfig: + return SubConfig(config_bag.context.get_description(), + None, + None, + config_bag, + None, + None, + ) + + def get_sub_config(self, + config_bag, + path, + index, + *, + validate_properties: bool=True, + follower_not_apply_requires: bool=False, + properties=undefined, + true_path: Optional[str]=None, + ): + subconfig = self.get_root(config_bag) + if path is None: + paths = [] + len_path = 0 + else: + if '.' in path: + paths = path.split('.') + else: + paths = [path] + len_path = len(paths) - 1 + for idx, name in enumerate(paths): + if idx != len_path: + index_ = None + true_path_ = None + else: + index_ = index + true_path_ = true_path + + if not subconfig.option.impl_is_optiondescription(): + raise TypeError(f'"{subconfig.true_path}" is not an optiondescription') + option = subconfig.option.get_child(name, + config_bag, + subconfig, + with_suffix=True, + ) + if isinstance(option, tuple): + suffix, option = option + else: + suffix = None + subconfig = subconfig.get_child(option, + index_, + validate_properties, + follower_not_apply_requires=follower_not_apply_requires, + properties=properties, + name=name, + suffix=suffix, + true_path=true_path_, + ) + return subconfig + def walk(self, - option_bag: OptionBag, + root_subconfig: SubConfig, *, - types: List[str]=('option',), - group_type=None, - recursive: bool=True, - walked: bool=False, - flatten_leadership: bool=False, + no_value: bool=False, + only_mandatory: bool=False, validate_properties: bool=True, ): - """walk to tree - """ - # pylint: disable=too-many-branches,too-many-locals,too-many-arguments, - if option_bag.option.impl_is_optiondescription(): - # do not return root option - if walked: - if 'optiondescription' in types and (group_type is None or - option_bag.option.impl_get_group_type() == group_type): - yield option_bag - if not recursive: - # it's not recursive, so stop to walk - return - if not option_bag.option.impl_is_leadership() or flatten_leadership: - for opt in option_bag.option.get_children(option_bag.config_bag): - try: - yield from self.walk(self.get_sub_option_bag(option_bag, # pylint: disable=no-member - opt.impl_getpath(), - None, - validate_properties, - follower_not_apply_requires=flatten_leadership, - )[-1], - types=types, - recursive=recursive, - group_type=group_type, - walked=True, - validate_properties=validate_properties, - ) - except PropertiesOptionError as err: - if err.proptype in (['mandatory'], ['empty']): - raise err - elif 'option' in types or 'mandatory' in types: - # it's a leadership so walk to leader and followers - # followers has specific length - leader, *followers = option_bag.option.get_children(option_bag.config_bag) - leader_option_bag = self.get_sub_option_bag(option_bag, # pylint: disable=no-member - leader.impl_getpath(), - None, - validate_properties, - )[-1] - followers_dict = {'leader': leader_option_bag} - values = self.get_value(leader_option_bag, - need_help=False, - ) - ls_length = len(values) - try: - self._walk_valid_value(leader_option_bag, - types, - value=values, - ) - except PropertiesOptionError as err: - if err.proptype in (['mandatory'], ['empty']): - yield leader_option_bag - for idx in range(ls_length): - followers_dict[idx] = [] - for follower in followers: - follower_path = follower.impl_getpath() - try: - options_bag = self.get_sub_option_bag(option_bag, # pylint: disable=no-member - follower_path, - idx, - validate_properties, - leadership_length=ls_length, - ) - for f_follower_bag in self.walk(options_bag[-1], - types=types, - recursive=recursive, - group_type=group_type, - walked=True, - validate_properties=validate_properties, - ): - if 'mandatory' in types: - yield f_follower_bag - followers_dict[idx].append(f_follower_bag) - except PropertiesOptionError as err: - continue - if 'option' in types: - yield followers_dict + if only_mandatory or no_value: + ret = [] else: - if 'mandatory' in types and not option_bag.option.impl_is_symlinkoption(): - try: - self._walk_valid_value(option_bag, - types, - ) - except PropertiesOptionError as err: - if err.proptype in (['mandatory'], ['empty']): - yield option_bag - if 'option' in types: - yield option_bag - - def make_dict(self, option_bag): - """exports the whole config into a `dict` - :returns: dict of Option's name (or path) and values - """ - ret = {} - for data in self.walk(option_bag): - if isinstance(data, OptionBag): - option_bag = data - ret[option_bag.path] = self.get_value(option_bag, - need_help=False, - ) + ret = {} + for subconfig in root_subconfig.get_children(validate_properties): + # pylint: disable=too-many-branches,too-many-locals,too-many-arguments, + if only_mandatory and subconfig.option.impl_is_symlinkoption(): + continue + if subconfig.option.impl_is_optiondescription(): + values = self.walk(subconfig, + no_value=no_value, + only_mandatory=only_mandatory, + validate_properties=validate_properties, + ) + if only_mandatory or no_value: + ret.extend(values) + else: + ret[subconfig] = values else: - leader_ret = [] - leader_path = data['leader'].path - for idx, value in enumerate(self.get_value(data['leader'], - need_help=False, - )): - leader_dict = {leader_path: value} - for follower in data.get(idx, []): - leader_dict[follower.path] = self.get_value(follower, - need_help=False, - ) - leader_ret.append(leader_dict) - ret[leader_path] = leader_ret - + if no_value: + ret.append(subconfig) + else: + option = self.walk_option(subconfig, + only_mandatory, + ) + if only_mandatory: + if option: + ret.append(subconfig) + elif option[0]: + ret[subconfig] = option[1] return ret + def walk_option(self, + subconfig: SubConfig, + only_mandatory: bool, + ): + try: + value = self._walk_valid_value(subconfig, + only_mandatory, + ) + except PropertiesOptionError as err: + if err.proptype in (['mandatory'], ['empty']): + if only_mandatory: + return True + else: + raise err from err + else: + if not only_mandatory: + return True, value + if only_mandatory: + return False + return False, None + # ============================================================================= # Manage value def set_value(self, - option_bag: OptionBag, + subconfig: SubConfig, value: Any, ) -> Any: """set value """ - self.get_settings().validate_properties(option_bag) - return self.get_values().set_value(option_bag, + self.get_settings().validate_properties(subconfig) + return self.get_values().set_value(subconfig, value ) def get_value(self, - option_bag, - parent_option_bag=None, + subconfig, need_help=True, ): """ :return: option's value if name is an option name, OptionDescription otherwise """ - option_bag = self._get(option_bag, - need_help, - ) - if isinstance(option_bag, list): + subconfig = self._get(subconfig, + need_help, + ) + if isinstance(subconfig, list): value = [] - for opt_bag in option_bag: - value.append(self.get_value(opt_bag, + follower_subconfig = None + for sconfig in subconfig: + if follower_subconfig is None: + follower_subconfig = self.get_sub_config(sconfig.config_bag, + sconfig.path, + sconfig.index, + ) + else: + follower_subconfig = follower_subconfig.parent.get_child(sconfig.option, + sconfig.index, + False, + ) + value.append(self.get_value(follower_subconfig, need_help=need_help, )) else: - value = self.get_values().get_cached_value(option_bag) - if parent_option_bag and option_bag.option.impl_is_follower() : - length = self.get_length_leadership(parent_option_bag) - follower_len = self.get_values().get_max_length(option_bag.path) + value = self.get_values().get_cached_value(subconfig) + if subconfig.option.impl_is_follower(): + length = subconfig.parent.get_length_leadership() + follower_len = self.get_values().get_max_length(subconfig.path) if follower_len > length: - option_name = option_bag.option.impl_get_display_name() + option_name = subconfig.option.impl_get_display_name() raise LeadershipError(_(f'the follower option "{option_name}" ' f'has greater length ({follower_len}) than the leader ' f'length ({length})')) - self.get_settings().validate_mandatory(value, - option_bag, + self.get_settings().validate_mandatory(subconfig, + value, ) return value def _get(self, - option_bag: OptionBag, + subconfig: "SubConfig", need_help: bool, - ) -> OptionBag: + ) -> "OptionBag": # pylint: disable=too-many-locals - option = option_bag.option - if option.impl_is_symlinkoption(): - suboption = option.impl_getopt() - if suboption.issubdyn(): - dynopt = suboption.getsubdyn() - return list(dynopt.get_sub_children(suboption, - option_bag.config_bag, - index=option_bag.index, - )) - if suboption.impl_is_follower(): - options_bag = self.get_sub_option_bag(option_bag.config_bag, # pylint: disable=no-member - suboption.impl_getpath(), - None, - True, - ) - leadership_length = self.get_length_leadership(options_bag[-2]) - ret = [] - for idx in range(leadership_length): - f_option_bag = OptionBag(suboption, - idx, - option_bag.config_bag, - ) - ret.append(f_option_bag) - return ret + option = subconfig.option + if not option.impl_is_symlinkoption(): + return subconfig + suboption = option.impl_getopt() + if suboption.issubdyn(): + dynopt = suboption.getsubdyn() + return list(dynopt.get_sub_children(suboption, + suboption.config_bag, + index=suboption.index, + true_path=subconfig.path, + )) + if suboption.impl_is_follower(): + subconfig = self.get_sub_config(subconfig.config_bag, # pylint: disable=no-member + suboption.impl_getpath(), + None, + validate_properties=True, + follower_not_apply_requires=False, + true_path=subconfig.path, + ) + leadership_length = subconfig.parent.get_length_leadership() + ret = [] + follower = subconfig.option + parent = subconfig.parent + for idx in range(leadership_length): + ret.append(parent.get_child(follower, + idx, + True, + )) + return ret - soption_bag = OptionBag(suboption, - option_bag.index, - option_bag.config_bag, - ori_option=option, - ) - return self._get(soption_bag, - need_help, - ) - return option_bag + s_subconfig = self.get_sub_config(subconfig.config_bag, # pylint: disable=no-member + suboption.impl_getpath(), + None, + validate_properties=True, + follower_not_apply_requires=False, + true_path=subconfig.path, + ) + return self._get(s_subconfig, + need_help, + ) - def get_owner(self, option_bag: OptionBag): + def get_owner(self, + subconfig: "SubConfig", + ): """get owner """ - options_bag = self._get(option_bag, - need_help=True, - ) - if isinstance(options_bag, list): - for opt_bag in options_bag: - owner = self.get_owner(opt_bag) + subconfigs = self._get(subconfig, + need_help=True, + ) + if isinstance(subconfigs, list): + for sc in subconfigs: + owner = self.get_owner(sc, + ) if owner != owners.default: break else: owner = owners.default else: - owner = self.get_values().getowner(options_bag) + owner = self.get_values().getowner(subconfigs) return owner -class _CommonConfig(_SubConfig): +class _CommonConfig(_Config): "abstract base class for the Config, KernelGroupConfig and the KernelMetaConfig" __slots__ = ('_impl_values', '_impl_values_cache', @@ -630,11 +809,12 @@ class _CommonConfig(_SubConfig): value, ) for option in self.get_description()._cache_dependencies_information.get(key, []): # pylint: disable=protected-access - option_bag = OptionBag(option, - None, - config_bag, - properties=None, - ) + #option_bag = OptionBag(option, + # None, + # config_bag, + # properties=None, + # ) + option_bag = None self.reset_cache(option_bag) def impl_get_information(self, @@ -665,17 +845,17 @@ class _CommonConfig(_SubConfig): """ return self._impl_values.list_information() # pylint: disable=no-member - def gen_fake_values(self) -> 'KernelConfig': + def gen_fake_context(self) -> 'KernelConfig': """generate a fake values to improve validation when assign a new value """ export = deepcopy(self.get_values()._values) # pylint: disable=protected-access - fake_config = KernelConfig(self._impl_descr, - force_values=export, - force_settings=self.get_settings(), - name=self._impl_name, # pylint: disable=no-member - ) - fake_config.parents = self.parents # pylint: disable=no-member - return fake_config + fake_context = KernelConfig(self._impl_descr, + force_values=export, + force_settings=self.get_settings(), + name=self._impl_name, # pylint: disable=no-member + ) + fake_context.parents = self.parents # pylint: disable=no-member + return fake_context def duplicate(self, force_values=None, @@ -749,81 +929,6 @@ class _CommonConfig(_SubConfig): path = parent().get_config_path() + '.' + path return path - def get_sub_option_bag(self, - bag: Union[OptionBag, ConfigBag], - path: str, - index: Optional[int], - validate_properties: bool, - *, - leadership_length: int=None, - properties=undefined, - follower_not_apply_requires: bool=False, - allow_dynoption: bool=False, - ) -> List[OptionBag]: - """Get the suboption for path and the name of the option - :returns: option_bag - """ - # pylint: disable=too-many-branches,too-many-locals,too-many-arguments - if isinstance(bag, ConfigBag): - option_bag = OptionBag(self.get_description(), - None, - bag, - ) - else: - option_bag = bag - if option_bag.option != option_bag.config_bag.context.get_description(): - path = path[len(option_bag.path) + 1:] - split_path = path.split('.') - last_idx = len(split_path) - 1 - suboption = option_bag.option - options_bag = [] - sub_option_bag = option_bag - for idx, step in enumerate(split_path): - if not suboption.impl_is_optiondescription(): - raise TypeError(f'{suboption.impl_getpath()} is not an optiondescription') - - option = suboption.get_child(step, - option_bag.config_bag, - allow_dynoption=allow_dynoption, - ) - if idx == last_idx: - option_index = index - apply_requires = not follower_not_apply_requires or \ - option.impl_is_optiondescription() or \ - not option.impl_is_follower() - if option_index is not None: - if option.impl_is_optiondescription() or \ - option.impl_is_symlinkoption() or \ - not option.impl_is_follower(): - raise ConfigError('index must be set only with a follower option') - if leadership_length is not None: - length = leadership_length - else: - length = self.get_length_leadership(sub_option_bag) - if index >= length: - raise LeadershipError(_(f'index "{index}" is greater than the leadership ' - f'length "{length}" for option ' - f'"{option.impl_get_display_name()}"')) - option_properties = properties - else: - option_index = None - apply_requires = True - option_properties = undefined - if option_properties is undefined and not validate_properties: - # not transitive property error - apply_requires = False - sub_option_bag = OptionBag(option, - option_index, - option_bag.config_bag, - properties=option_properties, - apply_requires=apply_requires, - ) - if validate_properties: - self.get_settings().validate_properties(sub_option_bag) - suboption = option - options_bag.append(sub_option_bag) - return options_bag - def impl_getname(self): """get config name """ @@ -976,11 +1081,12 @@ class KernelGroupConfig(_CommonConfig): cconfig_bag.properties = properties cconfig_bag.permissives = permissives try: + # GROUP coption_bag = child.get_sub_option_bag(cconfig_bag, option_bag.path, option_bag.index, False, - )[-1] + ) child.set_value(coption_bag, value, ) @@ -1083,6 +1189,7 @@ class KernelGroupConfig(_CommonConfig): cconfig_bag.properties = properties cconfig_bag.permissives = permissives cconfig_bag.remove_validation() + # GROUP option_bag = child.get_sub_option_bag(cconfig_bag, path, None, @@ -1174,6 +1281,7 @@ class KernelMixConfig(KernelGroupConfig): else: obj = child validate_properties = not force_default and not force_default_if_same + # MIX moption_bag = obj.get_sub_option_bag(cconfig_bag, option_bag.path, option_bag.index, @@ -1206,6 +1314,7 @@ class KernelMixConfig(KernelGroupConfig): ret.append(err) try: + # MIX moption_bag = self.get_sub_option_bag(option_bag.config_bag, option_bag.path, option_bag.index, @@ -1236,6 +1345,7 @@ class KernelMixConfig(KernelGroupConfig): rconfig_bag = config_bag.copy() rconfig_bag.remove_validation() if self.impl_type == 'meta': + # MIX option_bag = self.get_sub_option_bag(config_bag, path, None, @@ -1243,6 +1353,7 @@ class KernelMixConfig(KernelGroupConfig): )[-1] elif not only_children: try: + # MIX option_bag = self.get_sub_option_bag(rconfig_bag, path, None, @@ -1257,6 +1368,7 @@ class KernelMixConfig(KernelGroupConfig): moption_bag = option_bag moption_bag.config_bag = rconfig_bag else: + # MIX moption_bag = child.get_sub_option_bag(rconfig_bag, path, None, diff --git a/tiramisu/error.py b/tiramisu/error.py index 7df1672..f559daa 100644 --- a/tiramisu/error.py +++ b/tiramisu/error.py @@ -54,7 +54,7 @@ def display_list(lst, separator='and', add_quote=False): class PropertiesOptionError(AttributeError): "attempt to access to an option with a property that is not allowed" def __init__(self, - option_bag, + subconfig, proptype, settings, opt_type=None, @@ -66,13 +66,12 @@ class PropertiesOptionError(AttributeError): self._name = name self._orig_opt = orig_opt else: - if option_bag.option.impl_is_optiondescription(): + if subconfig.option.impl_is_optiondescription(): self._opt_type = 'optiondescription' else: self._opt_type = 'option' - self._name = option_bag.option.impl_get_display_name() + self._name = subconfig.option.impl_get_display_name() self._orig_opt = None - self._option_bag = option_bag self.proptype = proptype self.help_properties = help_properties self._settings = settings diff --git a/tiramisu/option/__init__.py b/tiramisu/option/__init__.py index 9a2938c..af45ee0 100644 --- a/tiramisu/option/__init__.py +++ b/tiramisu/option/__init__.py @@ -22,11 +22,10 @@ """ from .optiondescription import OptionDescription from .dynoptiondescription import DynOptionDescription -from .syndynoptiondescription import SynDynOptionDescription, SynDynLeadership from .leadership import Leadership from .baseoption import submulti from .symlinkoption import SymLinkOption -from .syndynoption import SynDynOption +#from .syndynoption import SynDynOption, SynDynOptionDescription, SynDynLeadership from .option import Option from .choiceoption import ChoiceOption from .booloption import BoolOption @@ -50,8 +49,9 @@ from .permissionsoption import PermissionsOption __all__ = ('Leadership', 'OptionDescription', 'DynOptionDescription', - 'SynDynOptionDescription', 'SynDynLeadership', 'Option', 'SymLinkOption', - 'SynDynOption', 'ChoiceOption', 'BoolOption', 'DateOption', +# 'SynDynOptionDescription', 'SynDynLeadership','SynDynOption', + 'Option', 'SymLinkOption', + 'ChoiceOption', 'BoolOption', 'DateOption', 'IntOption', 'FloatOption', 'StrOption', 'IPOption', 'PortOption', 'NetworkOption', 'NetmaskOption', 'BroadcastOption', 'DomainnameOption', 'EmailOption', 'URLOption', diff --git a/tiramisu/option/choiceoption.py b/tiramisu/option/choiceoption.py index 49a5b5c..86bb43d 100644 --- a/tiramisu/option/choiceoption.py +++ b/tiramisu/option/choiceoption.py @@ -22,7 +22,7 @@ """ from typing import Any -from ..setting import undefined, OptionBag +from ..setting import undefined from ..i18n import _ from .option import Option from ..autolib import Calculation @@ -57,12 +57,12 @@ class ChoiceOption(Option): **kwargs) def impl_get_values(self, - option_bag: OptionBag, + subconfig: "SubConfig", ): """get values allowed by option """ if isinstance(self._choice_values, Calculation): - values = self._choice_values.execute(option_bag) + values = self._choice_values.execute(subconfig) if values is not undefined and not isinstance(values, list): raise ConfigError(_('the calculated values "{0}" for "{1}" is not a list' '').format(values, self.impl_getname())) @@ -78,12 +78,12 @@ class ChoiceOption(Option): def validate_with_option(self, value: Any, - option_bag: OptionBag, + subconfig: "SubConfig", loaded: bool, ) -> None: if loaded and isinstance(self._choice_values, Calculation): return - values = self.impl_get_values(option_bag) + values = self.impl_get_values(subconfig) self.validate_values(value, values) def validate_values(self, diff --git a/tiramisu/option/dynoptiondescription.py b/tiramisu/option/dynoptiondescription.py index 8208969..8a57d35 100644 --- a/tiramisu/option/dynoptiondescription.py +++ b/tiramisu/option/dynoptiondescription.py @@ -20,26 +20,22 @@ # ____________________________________________________________ """DynOptionDescription """ -import re import weakref -from typing import List, Any, Optional, Tuple +from typing import List, Any, Optional from itertools import chain from ..autolib import ParamOption from ..i18n import _ from .optiondescription import OptionDescription -from .syndynoptiondescription import SynDynLeadership +from .syndynoption import CommonDyn #, SynDynLeadership from .baseoption import BaseOption -from ..setting import OptionBag, ConfigBag, undefined +from ..setting import ConfigBag, undefined from ..error import ConfigError from ..autolib import Calculation -NAME_REGEXP = re.compile(r'^[a-zA-Z\d\-_]*$') - - -class DynOptionDescription(OptionDescription): +class DynOptionDescription(OptionDescription, CommonDyn): """dyn option description """ __slots__ = ('_suffixes', @@ -86,111 +82,13 @@ class DynOptionDescription(OptionDescription): suffix = suffix.replace('.', '_') return suffix - def get_suffixes(self, - config_bag: ConfigBag, - *, - dynoption=None, - ) -> List[str]: - """get dynamic suffixes - """ - if dynoption: - self_opt = dynoption - else: - self_opt = self - option_bag = OptionBag(self_opt, - None, - config_bag, - properties=None, - ) - values = self._suffixes.execute(option_bag) - if values is None: - values = [] - values_ = [] - if __debug__: - if not isinstance(values, list): - raise ValueError(_('DynOptionDescription suffixes for ' - f'option "{self.impl_get_display_name()}", is not ' - f'a list ({values})')) - for val in values: - cval = self.convert_suffix_to_path(val) - if not isinstance(cval, str) or re.match(NAME_REGEXP, cval) is None: - if __debug__ and cval is not None: - raise ValueError(_('invalid suffix "{}" for option "{}"' - '').format(cval, - self.impl_get_display_name())) - else: - values_.append(val) - if __debug__ and len(values_) > len(set(values_)): - raise ValueError(_(f'DynOptionDescription "{self._name}" suffixes return a list with ' - f'same values "{values_}"''')) - return values_ - def impl_is_dynoptiondescription(self) -> bool: return True def option_is_self(self, option, ) -> bool: - return option == self or \ - (option.impl_is_sub_dyn_optiondescription() and option.opt == self) - - def split_path(self, - option, - *, - dynoption=None, - ) -> Tuple[str, str]: - """self.impl_getpath() is something like root.xxx.dynoption_path - option.impl_getpath() is something like root.xxx.dynoption_path.sub.path - must return ('root.xxx.', '.sub') - """ - if dynoption is None: - self_path = self.impl_getpath() - else: - self_path = dynoption.impl_getpath() - root_path = self_path.rsplit('.', 1)[0] if '.' in self_path else None - # - if self.option_is_self(option): - sub_path = '' - else: - option_path = option.impl_getpath() - if root_path: - if isinstance(option, SynDynLeadership): - count_root_path = option_path.count('.') - root_path.count('.') - root_path = option_path.rsplit('.', count_root_path)[0] - root_path += '.' - self_number_child = self_path.count('.') + 1 - option_sub_path = option_path.split('.', self_number_child)[-1] - sub_path = '.' + option_sub_path.rsplit('.', 1)[0] if '.' in option_sub_path else '' - return root_path, sub_path - - def get_sub_children(self, - option, - config_bag, - *, - index=None, - properties=undefined, - dynoption=None, - ): - root_path, sub_path = self.split_path(option, - dynoption=dynoption, - ) - for suffix in self.get_suffixes(config_bag, - dynoption=dynoption, - ): - if self.option_is_self(option): - parent_path = root_path - elif root_path: - parent_path = root_path + self.impl_getname(suffix) + sub_path - else: - parent_path = self.impl_getname(suffix) + sub_path - yield OptionBag(option.to_dynoption(parent_path, - [suffix], - ), - index, - config_bag, - properties=properties, - ori_option=option - ) + return option == self def impl_getname(self, suffix=None) -> str: """get name diff --git a/tiramisu/option/leadership.py b/tiramisu/option/leadership.py index efa4dc0..a7765a5 100644 --- a/tiramisu/option/leadership.py +++ b/tiramisu/option/leadership.py @@ -24,9 +24,9 @@ from typing import List, Iterator, Optional from ..i18n import _ -from ..setting import groups, undefined, OptionBag, ALLOWED_LEADER_PROPERTIES +from ..setting import groups, undefined, ALLOWED_LEADER_PROPERTIES from .optiondescription import OptionDescription -from .syndynoptiondescription import SynDynLeadership +# from .syndynoption import SynDynLeadership from .baseoption import BaseOption from .option import Option from ..error import LeadershipError @@ -116,7 +116,9 @@ class Leadership(OptionDescription): """the option is the leader """ leader = self.get_leader() - return opt == leader or (opt.impl_is_dynsymlinkoption() and opt.opt == leader) + if opt.impl_is_dynsymlinkoption(): + opt = opt.opt + return opt == leader def get_leader(self) -> Option: """get leader @@ -138,60 +140,66 @@ class Leadership(OptionDescription): opt = opt.opt return opt in self._children[1] - def reset(self, config_bag: 'ConfigBag') -> None: + def reset(self, parent: "SubConfig") -> None: """reset follower value """ - values = config_bag.context.get_values() - config_bag = config_bag.copy() - config_bag.remove_validation() + #config_bag = parent.option_bag.config_bag + values = parent.config_bag.context.get_values() + #config_bag = config_bag.copy() + #config_bag.remove_validation() for follower in self.get_followers(): - soption_bag = OptionBag(follower, - None, - config_bag, - ) - values.reset(soption_bag) - - def follower_force_store_value(self, - value, - config_bag: 'ConfigBag', - owner, - dyn=None, - ) -> None: - """apply force_store_value to follower - """ - if value: - if dyn is None: - dyn = self - values = config_bag.context.get_values() - for idx, follower in enumerate(dyn.get_children(config_bag)): - if not idx: - # it's a master - apply_requires = True - indexes = [None] - else: - apply_requires = False - indexes = range(len(value)) - foption_bag = OptionBag(follower, - None, - config_bag, - apply_requires=apply_requires, - ) - if 'force_store_value' not in foption_bag.properties: - continue - for index in indexes: - foption_bag_index = OptionBag(follower, - index, - config_bag, + subconfig_follower = parent.get_child(follower, + None, + False, ) - values.set_storage_value(foption_bag_index.path, - index, - values.get_value(foption_bag_index)[0], - owner, - ) +# OptionBag(follower, +# None, +# config_bag, +# ) + values.reset(subconfig_follower) +# +# def follower_force_store_value(self, +# value, +# config_bag: 'ConfigBag', +# owner, +# dyn=None, +# ) -> None: +# """apply force_store_value to follower +# """ +# if value: +# if dyn is None: +# dyn = self +# values = config_bag.context.get_values() +# for idx, follower in enumerate(dyn.get_children(config_bag)): +# if not idx: +# # it's a master +# apply_requires = True +# indexes = [None] +# else: +# apply_requires = False +# indexes = range(len(value)) +# foption_bag = OptionBag(follower, +# None, +# config_bag, +# apply_requires=apply_requires, +# ) +# if 'force_store_value' not in foption_bag.properties: +# continue +# for index in indexes: +# foption_bag_index = OptionBag(follower, +# index, +# config_bag, +# ) +# values.set_storage_value(foption_bag_index.path, +# index, +# values.get_value(foption_bag_index)[0], +# owner, +# ) def pop(self, + subconfig: 'SubConfig', index: int, - config_bag: 'ConfigBag', + *, followers: Optional[List[Option]]=undefined, ) -> None: """pop leader value and follower's one @@ -199,17 +207,18 @@ class Leadership(OptionDescription): if followers is undefined: # followers are not undefined only in SynDynLeadership followers = self.get_followers() - config_bag = config_bag.copy() + config_bag = subconfig.config_bag.copy() config_bag.remove_validation() values = config_bag.context.get_values() for follower in followers: - soption_bag = OptionBag(follower, - index, - config_bag, - properties=set(), # do not check force_default_on_freeze - # or force_metaconfig_on_freeze - ) - values.reduce_index(soption_bag) + sub_subconfig = subconfig.parent.get_child(follower, + index, + True, + properties=set(), # do not check force_default_on_freeze + # or force_metaconfig_on_freeze + config_bag=config_bag, + ) + values.reduce_index(sub_subconfig) def reset_cache(self, path: str, @@ -234,23 +243,28 @@ class Leadership(OptionDescription): config_bag, resetted_opts, ) - leader.reset_cache(leader.impl_getpath(), - config_bag, - None) + leader_path = leader.impl_getpath() + if leader_path not in resetted_opts: + leader.reset_cache(leader_path, + config_bag, + resetted_opts, + ) for follower in followers: - follower.reset_cache(follower.impl_getpath(), - config_bag, - None, - ) + follower_path = follower.impl_getpath() + if follower_path not in resetted_opts: + follower.reset_cache(follower_path, + config_bag, + resetted_opts, + ) def impl_is_leadership(self) -> None: return True - - def to_dynoption(self, - rootpath: str, - suffixes: Optional[list], - ) -> SynDynLeadership: - return SynDynLeadership(self, - rootpath, - suffixes, - ) +# +# def to_dynoption(self, +# rootpath: str, +# suffixes: Optional[list], +# ) -> SynDynLeadership: +# return SynDynLeadership(self, +# rootpath, +# suffixes, +# ) diff --git a/tiramisu/option/option.py b/tiramisu/option/option.py index 1985edf..3276e86 100644 --- a/tiramisu/option/option.py +++ b/tiramisu/option/option.py @@ -25,7 +25,7 @@ from itertools import chain from .baseoption import BaseOption, submulti from ..i18n import _ -from ..setting import undefined, OptionBag +from ..setting import undefined from ..autolib import Calculation, ParamOption, ParamInformation, ParamSelfInformation from ..error import ValueWarning, ValueErrorWarning, ValueOptionError from .syndynoption import SynDynOption @@ -110,15 +110,15 @@ class Option(BaseOption): def test_multi_value(value): if isinstance(value, Calculation): return - option_bag = OptionBag(self, - None, - undefined, - properties=None, - ) +# option_bag = OptionBag(self, +# None, +# undefined, +# properties=None, +# ) try: self.validate(value) self.validate_with_option(value, - option_bag, + None, loaded=True, ) except ValueError as err: @@ -143,17 +143,17 @@ class Option(BaseOption): else: test_multi_value(default_multi) _setattr(self, '_default_multi', default_multi) - option_bag = OptionBag(self, - None, - undefined, - properties=None, - ) - self.impl_validate(default, - option_bag, +# option_bag = OptionBag(self, +# None, +# undefined, +# properties=None, +# ) + self.impl_validate(None, + default, loaded=True, ) - self.impl_validate(default, - option_bag, + self.impl_validate(None, + default, check_error=False, loaded=True, ) @@ -262,25 +262,28 @@ class Option(BaseOption): #__________________________________________________________________________ # validator def impl_validate(self, + subconfig: Optional["SubConfig"], value: Any, - option_bag: OptionBag, + *, check_error: bool=True, loaded: bool=False, ) -> bool: """Return True if value is really valid If not validate or invalid return it returns False """ - config_bag = option_bag.config_bag - force_index = option_bag.index - is_warnings_only = getattr(self, '_warnings_only', False) - if check_error and config_bag is not undefined and \ - not 'validator' in config_bag.properties: + if check_error and subconfig and \ + not 'validator' in subconfig.config_bag.properties: return False + if subconfig: + force_index = subconfig.index + else: + force_index = None + is_warnings_only = getattr(self, '_warnings_only', False) - def _is_not_unique(value, option_bag): + def _is_not_unique(value): # if set(value) has not same length than value - if config_bag is undefined or not check_error or \ - 'unique' not in option_bag.properties: + if not subconfig or not check_error or \ + 'unique' not in subconfig.properties: return lvalue = [val for val in value if val is not None] if len(set(lvalue)) == len(lvalue): @@ -303,14 +306,23 @@ class Option(BaseOption): kwargs = {'allow_value_error': True, 'force_value_warning': calc_is_warnings_only, } - if _index is not None and option_bag.index == _index: - soption_bag = option_bag + if _index is not None and subconfig.index == _index: + lsubconfig = subconfig else: - soption_bag = option_bag.copy() - soption_bag.index = _index + suffix = subconfig.suffixes + if suffix is not None: + suffix = suffix[-1] + lsubconfig = subconfig.parent.get_child(subconfig.option, + _index, + False, + properties=subconfig.properties, + suffix=suffix, + name=subconfig.path.rsplit('.', 1)[-1], + check_index=False, + ) kwargs['orig_value'] = value - validator.execute(soption_bag, + validator.execute(lsubconfig, **kwargs, ) except ValueWarning as warn: @@ -327,46 +339,49 @@ class Option(BaseOption): _index, ): # + if _value is None: + return if isinstance(_value, list): raise ValueError(_('which must not be a list').format(_value, self.impl_get_display_name()), ) - if isinstance(_value, Calculation) and config_bag is undefined: + if isinstance(_value, Calculation) and not subconfig: return - - if _value is not None: - if check_error: - # option validation - self.validate(_value) - self.validate_with_option(_value, - option_bag, - loaded=loaded, - ) - if ((check_error and not is_warnings_only) or - (not check_error and is_warnings_only)): - try: - self.second_level_validation(_value, - is_warnings_only) - except ValueError as err: - if is_warnings_only: - warnings.warn_explicit(ValueWarning(_value, - self.get_type(), - self, - str(err), - _index), - ValueWarning, - self.__class__.__name__, 0) - else: - raise err - if not loaded: - calculation_validator(_value, - _index, + # option validation + if check_error: + self.validate(_value) + self.validate_with_option(_value, + subconfig, + loaded=loaded, ) + # second level validation + if (check_error and not is_warnings_only) or (not check_error and is_warnings_only): + try: + self.second_level_validation(_value, + is_warnings_only) + except ValueError as err: + if is_warnings_only: + warnings.warn_explicit(ValueWarning(_value, + self.get_type(), + self, + str(err), + _index), + ValueWarning, + self.__class__.__name__, 0) + else: + raise err from err + # ? + if not loaded: + calculation_validator(_value, + _index, + ) val = value err_index = force_index try: if not self.impl_is_multi(): - do_validation(val, None) + do_validation(val, + None, + ) elif force_index is not None: if self.impl_is_submulti(): if not isinstance(value, list): @@ -375,14 +390,12 @@ class Option(BaseOption): do_validation(val, force_index, ) - _is_not_unique(value, - option_bag, - ) + _is_not_unique(value) else: do_validation(val, force_index, ) - elif isinstance(value, Calculation) and config_bag is undefined: + elif isinstance(value, Calculation) and not subconfig: pass elif self.impl_is_submulti(): for err_index, lval in enumerate(value): @@ -394,7 +407,7 @@ class Option(BaseOption): for val in lval: do_validation(val, err_index) - _is_not_unique(lval, option_bag) + _is_not_unique(lval) elif not isinstance(value, list): raise ValueError(_('which must be a list')) else: @@ -403,18 +416,18 @@ class Option(BaseOption): do_validation(val, err_index, ) - _is_not_unique(value, option_bag) + _is_not_unique(value) except ValueError as err: - if config_bag is undefined or \ - 'demoting_error_warning' not in config_bag.properties: + if not subconfig or \ + 'demoting_error_warning' not in subconfig.config_bag.properties: raise ValueOptionError(val, self.get_type(), - option_bag.ori_option, + self, str(err), err_index) from err warnings.warn_explicit(ValueErrorWarning(val, self.get_type(), - option_bag.ori_option, + self, str(err), err_index), ValueErrorWarning, @@ -424,7 +437,8 @@ class Option(BaseOption): def validate_with_option(self, value: Any, - option_bag: OptionBag, + subconfig: "SubConfig", + *, loaded: bool, ) -> None: """validation function with option diff --git a/tiramisu/option/optiondescription.py b/tiramisu/option/optiondescription.py index 5dce1e0..5e9bdc5 100644 --- a/tiramisu/option/optiondescription.py +++ b/tiramisu/option/optiondescription.py @@ -25,9 +25,9 @@ from typing import Optional, Iterator, Union, List from ..i18n import _ -from ..setting import ConfigBag, OptionBag, groups, undefined, owners, Undefined +from ..setting import ConfigBag, groups, undefined, owners, Undefined from .baseoption import BaseOption -from .syndynoptiondescription import SubDynOptionDescription, SynDynOptionDescription +# from .syndynoption import SubDynOptionDescription, SynDynOptionDescription from ..error import ConfigError, ConflictError @@ -71,9 +71,7 @@ class CacheOptionDescription(BaseOption): # cache already set raise ConfigError(_('option description seems to be part of an other ' 'config')) - for option in self.get_children(config_bag=undefined, # pylint: disable=no-member - dyn=False, - ): + for option in self.get_children(): if __debug__: cache_option.append(option) sub_currpath = currpath + [option.impl_getname()] @@ -107,71 +105,71 @@ class CacheOptionDescription(BaseOption): self._cache_dependencies_information = dependencies_information # pylint: disable=attribute-defined-outside-init self._path = None # pylint: disable=attribute-defined-outside-init,no-member self._set_readonly() - - def impl_build_force_store_values(self, - config_bag: ConfigBag, - ) -> None: - """set value to force_store_values option - """ - # pylint: disable=too-many-branches - def do_option_bags(option): - if option.issubdyn(): - dynopt = option.getsubdyn() - yield from dynopt.get_sub_children(option, - config_bag, - index=None, - ) - else: - yield OptionBag(option, - None, - config_bag, - properties=None, - ) - if 'force_store_value' not in config_bag.properties: - return - values = config_bag.context.get_values() - for option in self._cache_force_store_values: - if option.impl_is_follower(): - leader = option.impl_get_leadership().get_leader() - for leader_option_bag in do_option_bags(leader): - leader_option_bag.properties = frozenset() - follower_len = len(values.get_value(leader_option_bag)[0]) - if option.issubdyn(): - doption = option.to_dynoption(leader_option_bag.option.rootpath, - leader_option_bag.option.get_suffixes(), - ) - else: - doption = option - subpath = doption.impl_getpath() - for index in range(follower_len): - option_bag = OptionBag(doption, - index, - config_bag, - properties=frozenset(), - ) - if values.hasvalue(subpath, index=index): - continue - value = values.get_value(option_bag)[0] - if value is None: - continue - values.set_storage_value(subpath, - index, - value, - owners.forced, - ) - else: - for option_bag in do_option_bags(option): - option_bag.properties = frozenset() - value = values.get_value(option_bag)[0] - if value is None: - continue - if values.hasvalue(option_bag.path): - continue - values.set_storage_value(option_bag.path, - None, - value, - owners.forced, - ) +# +# def impl_build_force_store_values(self, +# config_bag: ConfigBag, +# ) -> None: +# """set value to force_store_values option +# """ +# # pylint: disable=too-many-branches +# def do_option_bags(option): +# if option.issubdyn(): +# dynopt = option.getsubdyn() +# yield from dynopt.get_sub_children(option, +# config_bag, +# index=None, +# ) +# else: +# yield OptionBag(option, +# None, +# config_bag, +# properties=None, +# ) +# if 'force_store_value' not in config_bag.properties: +# return +# values = config_bag.context.get_values() +# for option in self._cache_force_store_values: +# if option.impl_is_follower(): +# leader = option.impl_get_leadership().get_leader() +# for leader_option_bag in do_option_bags(leader): +# leader_option_bag.properties = frozenset() +# follower_len = len(values.get_value(leader_option_bag)[0]) +# if option.issubdyn(): +# doption = option.to_dynoption(leader_option_bag.option.rootpath, +# leader_option_bag.option.get_current_suffixes(), +# ) +# else: +# doption = option +# subpath = doption.impl_getpath() +# for index in range(follower_len): +# option_bag = OptionBag(doption, +# index, +# config_bag, +# properties=frozenset(), +# ) +# if values.hasvalue(subpath, index=index): +# continue +# value = values.get_value(option_bag)[0] +# if value is None: +# continue +# values.set_storage_value(subpath, +# index, +# value, +# owners.forced, +# ) +# else: +# for option_bag in do_option_bags(option): +# option_bag.properties = frozenset() +# value = values.get_value(option_bag)[0] +# if value is None: +# continue +# if values.hasvalue(option_bag.path): +# continue +# values.set_storage_value(option_bag.path, +# None, +# value, +# owners.forced, +# ) class OptionDescriptionWalk(CacheOptionDescription): @@ -179,6 +177,14 @@ class OptionDescriptionWalk(CacheOptionDescription): """ __slots__ = ('_children',) + def get_path(self, + config_bag, + ): + if config_bag is undefined or \ + config_bag.context.get_description() == self: + return '' + return self.impl_getpath() + def get_child_not_dynamic(self, name, allow_dynoption, @@ -194,9 +200,11 @@ class OptionDescriptionWalk(CacheOptionDescription): def get_child(self, name: str, config_bag: ConfigBag, + parent: 'SubConfig', *, + with_suffix: bool=False, allow_dynoption: bool=False, - ) -> Union[BaseOption, SynDynOptionDescription]: + ) -> Union[BaseOption]: """get a child """ # if not dyn @@ -209,12 +217,12 @@ class OptionDescriptionWalk(CacheOptionDescription): for child in self._children[1]: # pylint: disable=no-member if not child.impl_is_dynoptiondescription(): continue - for suffix in child.get_suffixes(config_bag): + for suffix in child.get_suffixes(parent): if name != child.impl_getname(suffix): continue - return child.to_dynoption(self.impl_getpath(), - [suffix], - ) + if not with_suffix: + return child + return suffix, child if self.impl_get_group_type() == groups.root: # pylint: disable=no-member raise AttributeError(_(f'unknown option "{name}" ' 'in root optiondescription' @@ -223,52 +231,18 @@ class OptionDescriptionWalk(CacheOptionDescription): f'in optiondescription "{self.impl_get_display_name()}"' )) - def get_children(self, - config_bag: Union[ConfigBag, Undefined], - *, - dyn: bool=True, - #path: Optional[str]=None, - dynoption=None, - ) -> Union[BaseOption, SynDynOptionDescription]: + def get_children(self) -> List[BaseOption]: """get children """ - for child in self._children[1]: - if dyn and child.impl_is_dynoptiondescription(): - yield from self.get_suffixed_children(dynoption, - [], - config_bag, - child, - ) - else: - yield child - - def get_path(self, - config_bag, - dynoption, - ): - if dynoption: - self_opt = dynoption - else: - self_opt = self - if config_bag is undefined or \ - config_bag.context.get_description() == self: - return '' - return self_opt.impl_getpath() - - def get_suffixed_children(self, - dynoption, - option_suffixes: list, - config_bag: ConfigBag, - child, - ): - root_path = self.get_path(config_bag, dynoption) - for suffix in child.get_suffixes(config_bag, - dynoption=dynoption, - ): - yield child.to_dynoption(root_path, - option_suffixes + [suffix], - ) - + return self._children[1] +# for child in self._children[1]: +# if config_bag is not undefined and child.impl_is_dynoptiondescription(): +# yield from self.get_suffixed_children([], +# config_bag, +# child, +# ) +# else: +# yield child def get_children_recursively(self, bytype: Optional[BaseOption], @@ -277,12 +251,12 @@ class OptionDescriptionWalk(CacheOptionDescription): self_opt: BaseOption=None, *, option_suffixes: Optional[list]=None - ) -> Iterator[Union[BaseOption, SynDynOptionDescription]]: + ) -> Iterator[Union[BaseOption]]: """get children recursively """ if self_opt is None: self_opt = self - for option in self_opt.get_children(config_bag): + for option in self_opt.get_children(): if option.impl_is_optiondescription(): for subopt in option.get_children_recursively(bytype, byname, @@ -391,22 +365,22 @@ class OptionDescription(OptionDescriptionWalk): """get the group type of option description """ return self._group_type - - def to_dynoption(self, - rootpath: str, - suffixes: Optional[list], - #ori_dyn, - ) -> Union[SubDynOptionDescription, SynDynOptionDescription]: - """get syn dyn option description - """ - if self.impl_is_dynoptiondescription(): - obj = SynDynOptionDescription - else: - obj = SubDynOptionDescription - return obj(self, - rootpath, - suffixes, - ) +# +# def to_dynoption(self, +# rootpath: str, +# suffixes: Optional[list], +# #ori_dyn, +# ) -> Union[SubDynOptionDescription]: +# """get syn dyn option description +# """ +# if self.impl_is_dynoptiondescription(): +# obj = SynDynOptionDescription +# else: +# obj = SubDynOptionDescription +# return obj(self, +# rootpath, +# suffixes, +# ) def impl_is_dynsymlinkoption(self) -> bool: """option is not a dyn symlink option diff --git a/tiramisu/option/syndynoption.py b/tiramisu/option/syndynoption.py index fcb0c6b..80d94a0 100644 --- a/tiramisu/option/syndynoption.py +++ b/tiramisu/option/syndynoption.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright (C) 2018-2023 Team tiramisu (see AUTHORS for all contributors) +# Copyright (C) 2017-2024 Team tiramisu (see AUTHORS for all contributors) # # This program is free software: you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by the @@ -20,16 +20,93 @@ # ____________________________________________________________ """SynDynOption internal option, it's an instanciate synoption """ -from typing import Any +import re +from typing import Optional, Iterator, Any, List, Tuple + from .baseoption import BaseOption +from ..i18n import _ +from ..setting import ConfigBag, undefined -class SynDynOption: - """SynDynOption is an Option include un DynOptionDescription with specified prefix - """ +NAME_REGEXP = re.compile(r'^[a-zA-Z\d\-_]*$') + + +class CommonDyn: + def get_path(self, + config_bag, + ): + if config_bag is undefined or \ + config_bag.context.get_description() == self: + return '' + return self.impl_getpath() + + def get_suffixes(self, + parent: 'SubConfig', + ) -> List[str]: + """get dynamic suffixes + """ + subconfig = parent.get_child(self, + None, + False, + properties=None, + ) + values = self._suffixes.execute(subconfig) + if values is None: + values = [] + values_ = [] + if __debug__: + if not isinstance(values, list): + raise ValueError(_('DynOptionDescription suffixes for ' + f'option "{self.impl_get_display_name()}", is not ' + f'a list ({values})')) + for val in values: + cval = self.convert_suffix_to_path(val) + if not isinstance(cval, str) or re.match(NAME_REGEXP, cval) is None: + if __debug__ and cval is not None: + raise ValueError(_('invalid suffix "{}" for option "{}"' + '').format(cval, + self.impl_get_display_name())) + else: + values_.append(val) + if __debug__ and len(values_) > len(set(values_)): + raise ValueError(_(f'DynOptionDescription "{self._name}" suffixes return a list with ' + f'same values "{values_}"''')) + return values_ + + def split_path(self, + option, + *, + dynoption=None, + ) -> Tuple[str, str]: + """self.impl_getpath() is something like root.xxx.dynoption_path + option.impl_getpath() is something like root.xxx.dynoption_path.sub.path + must return ('root.xxx.', '.sub') + """ + if dynoption is None: + self_path = self.impl_getpath() + else: + self_path = dynoption.impl_getpath() + root_path = self_path.rsplit('.', 1)[0] if '.' in self_path else None + # + if self.option_is_self(option): + sub_path = '' + else: + option_path = option.impl_getpath() + if root_path: + if isinstance(option, SynDynLeadership): + count_root_path = option_path.count('.') - root_path.count('.') + root_path = option_path.rsplit('.', count_root_path)[0] + root_path += '.' + self_number_child = self_path.count('.') + 1 + option_sub_path = option_path.split('.', self_number_child)[-1] + sub_path = '.' + option_sub_path.rsplit('.', 1)[0] if '.' in option_sub_path else '' + return root_path, sub_path + + +class Syn: __slots__ = ('rootpath', 'opt', - 'suffixes', + '_current_suffixes', '__weakref__') def __init__(self, @@ -39,28 +116,28 @@ class SynDynOption: ) -> None: self.opt = opt self.rootpath = rootpath - self.suffixes = suffixes + self._current_suffixes = suffixes def __getattr__(self, - name: str) -> Any: + name: str, + ) -> Any: + # if not in SynDynOptionDescription, get value in self.opt return getattr(self.opt, name, ) - def impl_getname(self) -> str: - """get option name - """ - return self.opt.impl_getname() - def impl_get_display_name(self) -> str: - """get option display name - """ return self.opt.impl_get_display_name(self) - def get_suffixes(self) -> str: - """get suffix + def get_current_suffixes(self) -> str: + """get suffixes """ - return self.suffixes + return self.current__suffixes + + def impl_is_dynsymlinkoption(self) -> bool: + """it's a dynsymlinkoption + """ + return True def impl_getpath(self) -> str: """get path @@ -70,10 +147,109 @@ class SynDynOption: path = f'{self.rootpath}.{path}' return path - def impl_is_dynsymlinkoption(self) -> bool: - """it's a dynsymlinkoption + +class SynDescr(Syn): + __slots__ = ('opt', + 'rootpath', + '_current_suffixes', + ) + + def get_child(self, + name: str, + config_bag: ConfigBag, + *, + allow_dynoption: bool=False, + ): + """get children """ - return True + # if not dyn + option = self.get_child_not_dynamic(name, + allow_dynoption, + ) + if option: + if allow_dynoption and option.impl_is_dynoptiondescription(): + return option + return option.to_dynoption(self.impl_getpath(), + self._current_suffixes, + ) + for child in self.opt._children[1]: # pylint: disable=no-member + if not child.impl_is_dynoptiondescription(): + continue + for suffix in child.get_suffixes(config_bag): + if name != child.impl_getname(suffix): + continue + return child.to_dynoption(self.impl_getpath(), + self._current_suffixes + [suffix], + ) + raise AttributeError(_(f'unknown option "{name}" ' + f'in optiondescription "{self.impl_get_display_name()}"' + )) + + def get_children(self, + config_bag: ConfigBag, + ): + # pylint: disable=unused-argument + """get children + """ + for child in self.opt._children[1]: + if child.impl_is_dynoptiondescription(): + dynchild = self.get_child(child.impl_getname(), + config_bag, + allow_dynoption=True, + ) + for d in dynchild.get_sub_children(dynchild, + config_bag, + ): + yield d.option +# yield from dynchild.get_sub_children(dynchild, +# config_bag, +# ) + #for suffix in dynchild.get_suffixes(config_bag): + # yield child.to_dynoption(self.impl_getpath(), + # self._suffixes + [suffix], + # ) + else: + yield child.to_dynoption(self.impl_getpath(), + self._current_suffixes, + ) + + def get_children_recursively(self, + bytype: Optional[BaseOption], + byname: Optional[str], + config_bag: ConfigBag, + self_opt: BaseOption=None, + ) -> BaseOption: + # pylint: disable=unused-argument + """get children recursively + """ + for option in self.opt.get_children_recursively(bytype, + byname, + config_bag, + self, + ): + yield option + + def get_child_not_dynamic(self, + name, + allow_dynoption, + ): + children = self.opt._children + if name in children[0]: # pylint: disable=no-member + option = children[1][children[0].index(name)] # pylint: disable=no-member + if option.impl_is_dynoptiondescription() and not allow_dynoption: + raise AttributeError(_(f'unknown option "{name}" ' + "in root optiondescription (it's a dynamic option)" + )) + return SubDynOptionDescription(option, + self.impl_getpath(), + self._current_suffixes, + ) + + +class SynDynOption(Syn): + """SynDynOption is an Option include un DynOptionDescription with specified prefix + """ + __slots__ = () def impl_get_leadership(self): # pylint: disable=inconsistent-return-statements """is it a leadership? @@ -82,5 +258,94 @@ class SynDynOption: if leadership: rootpath = self.rootpath.rsplit('.', 1)[0] return leadership.to_dynoption(rootpath, - self.suffixes, + self._current_suffixes, ) +# +# +#class SubDynOptionDescription(SynDescr, CommonDyn): +# def option_is_self(self, +# option, +# ) -> bool: +# return self.opt.option_is_self(option.opt) +# +# def get_sub_children(self, +# option, +# config_bag, +# *, +# index=None, +# properties=undefined, +# ): +# root_path, sub_path = self.split_path(option) +# for suffix in self.get_suffixes(config_bag): +# if self.option_is_self(option): +# parent_path = root_path +# elif root_path: +# parent_path = root_path + self.impl_getname(suffix) + sub_path +# else: +# parent_path = self.impl_getname(suffix) + sub_path +# yield OptionBag(option.to_dynoption(parent_path, +# [suffix], +# ), +# index, +# config_bag, +# properties=properties, +# ori_option=option +# ) +# +# +#class SynDynOptionDescription(SynDescr): +# """SynDynOptionDescription internal option, it's an instanciate synoptiondescription +# """ +# def impl_getname(self) -> str: +# """get name +# """ +# if self.opt.impl_is_dynoptiondescription(): +# return self.opt.impl_getname(self._current_suffixes[-1]) +# return self.opt.impl_getname() +# +# def getsubdyn(self): +# return self.opt +# +# +#class SynDynLeadership(SynDynOptionDescription): +# """SynDynLeadership internal option, it's an instanciate synoptiondescription +# """ +# def get_leader(self) -> SynDynOption: +# """get the leader +# """ +# return self.opt.get_leader().to_dynoption(self.impl_getpath(), +# self._current_suffixes, +# ) +# +# def get_followers(self) -> Iterator[SynDynOption]: +# """get followers +# """ +# subpath = self.impl_getpath() +# for follower in self.opt.get_followers(): +# yield follower.to_dynoption(subpath, +# self._current_suffixes, +# ) +# +# def pop(self, +# *args, +# **kwargs, +# ) -> None: +# """pop value for a follower +# """ +# self.opt.pop(*args, +# followers=self.get_followers(), +# **kwargs, +# ) +# +# def follower_force_store_value(self, +# value, +# config_bag, +# owner, +# ) -> None: +# """force store value for a follower +# """ +# self.opt.follower_force_store_value(value, +# config_bag, +# owner, +# dyn=self, +# ) diff --git a/tiramisu/setting.py b/tiramisu/setting.py index dce19f4..c920b60 100644 --- a/tiramisu/setting.py +++ b/tiramisu/setting.py @@ -156,72 +156,63 @@ class Undefined: undefined = Undefined() - - -class OptionBag: - """Object to store information for an option - """ - __slots__ = ('option', # current option - 'path', - 'index', - 'config_bag', - 'ori_option', # original option (for example useful for symlinkoption) - 'properties', # properties of current option - 'apply_requires', # apply requires or not for this option - ) - - # pylint: disable=too-many-arguments - def __init__(self, - option, - index, - config_bag, - path=None, - properties=undefined, - ori_option=None, - apply_requires=True, - ): - self.index = index - self.config_bag = config_bag - self.option = option - if ori_option is not None: - self.ori_option = ori_option - if config_bag is undefined: - self.path = path - elif path: - self.path = path - elif option: - self.path = option.impl_getpath() - context = config_bag.context - if self.path is None: - self.properties = None - elif properties is undefined: - settings = context.get_settings() - try: - self.properties = settings.getproperties(self, - apply_requires=apply_requires, - ) - except ConfigError: - self.properties = None - if properties is not undefined: - self.properties = properties - - def __getattr__(self, key): - if key == 'ori_option': - return self.option - if key == 'apply_requires': - return True - return None - - def copy(self): - """copy OptionBag - """ - option_bag = OptionBag(None, - None, - None, - ) - for key in self.__slots__: - setattr(option_bag, key, getattr(self, key)) - return option_bag +# +# +#class OptionBag: +# """Object to store information for an option +# """ +# __slots__ = ('option', # current option +# 'path', +# 'index', +# 'config_bag', +# 'ori_option', # original option (for example useful for symlinkoption) +# 'properties', # properties of current option +# 'apply_requires', # apply requires or not for this option +# 'suffixes', +# ) +# +# # pylint: disable=too-many-arguments +# def __init__(self, +# option, +# index, +# config_bag, +# *, +# path=None, +# properties=undefined, +# parent: 'SubConfig'=None, +# ori_option=None, +# apply_requires=True, +# suffixes=None +# ): +# self.index = index +# self.config_bag = config_bag +# self.option = option +# if ori_option is not None: +# self.ori_option = ori_option +# if config_bag is undefined: +# self.path = path +# elif option: +# if properties is not undefined: +# self.properties = properties +# self.suffixes = suffixes +# +# def __getattr__(self, key): +# if key == 'ori_option': +# return self.option +# if key == 'apply_requires': +# return True +# return None +# +# def copy(self): +# """copy OptionBag +# """ +# option_bag = OptionBag(None, +# None, +# None, +# ) +# for key in self.__slots__: +# setattr(option_bag, key, getattr(self, key)) +# return option_bag class ConfigBag: @@ -453,7 +444,8 @@ class Settings: return self._properties[path][index] def getproperties(self, - option_bag, + subconfig: 'SubConfig', + *, apply_requires=True, uncalculated=False, help_property=False, @@ -462,12 +454,12 @@ class Settings: """get properties """ # pylint: disable=too-many-branches - option = option_bag.option + option = subconfig.option if option.impl_is_symlinkoption(): option = option.impl_getopt() if apply_requires and not uncalculated and not help_property: - cache = option_bag.config_bag.context.properties_cache - is_cached, props, validated = cache.getcache(option_bag, # pylint: disable=unused-variable + cache = subconfig.config_bag.context.properties_cache + is_cached, props, validated = cache.getcache(subconfig, # pylint: disable=unused-variable 'self_props', ) else: @@ -475,14 +467,14 @@ class Settings: if not is_cached: props = set() # if index, get option's properties (without index) too - p_props = self.get_stored_properties(option_bag.path, + p_props = self.get_stored_properties(subconfig.path, None, option.impl_getproperties(), ) - if option_bag.index is not None: + if subconfig.index is not None: p_props = chain(p_props, - self.get_stored_properties(option_bag.path, - option_bag.index, + self.get_stored_properties(subconfig.path, + subconfig.index, option.impl_getproperties(), ) ) @@ -495,11 +487,11 @@ class Settings: elif apply_requires: try: if not help_property: - new_prop = prop.execute(option_bag, + new_prop = prop.execute(subconfig, for_settings=True, ) else: - new_prop = prop.help(option_bag, + new_prop = prop.help(subconfig, for_settings=True, ) if isinstance(new_prop, str): @@ -513,18 +505,18 @@ class Settings: if (not help_property and not isinstance(new_prop, str)) or \ (help_property and not isinstance(new_prop, tuple)): raise ValueError(_('invalid property type {type(new_prop)} for ' - '{option_bag.option.impl_getname()} with ' + '{subconfig.option.impl_getname()} with ' '{prop.function.__name__} function')) if not option.impl_is_optiondescription() and \ option.impl_is_leader() and \ new_prop not in ALLOWED_LEADER_PROPERTIES: raise LeadershipError(_('leader cannot have "{new_prop}" property')) props.add(new_prop) - props -= self.getpermissives(option_bag) + props -= self.getpermissives(subconfig) if not uncalculated and apply_requires and \ - not option_bag.config_bag.is_unrestraint and \ + not subconfig.config_bag.is_unrestraint and \ not help_property and transitive_raise: - cache.setcache(option_bag, + cache.setcache(subconfig, props, type_='properties', ) @@ -546,21 +538,21 @@ class Settings: return ret def getpermissives(self, - option_bag, + subconfig: "SubConfig", ): """get permissive """ - if option_bag is None: + if subconfig is None: path = None index = None else: - opt = option_bag.option + opt = subconfig.option if opt.impl_is_symlinkoption(): opt = opt.impl_getopt() path = opt.impl_getpath() else: - path = option_bag.path - index = option_bag.index + path = subconfig.path + index = subconfig.index permissives = self._getpermissives(path, None, ) @@ -578,13 +570,13 @@ class Settings: context.reset_cache(None) def setproperties(self, - option_bag, + subconfig, properties, ): """save properties for specified path (never save properties if same has option properties) """ - opt = option_bag.option + opt = subconfig.option if not opt.impl_is_optiondescription() and opt.impl_is_leader(): not_allowed_properties = properties - ALLOWED_LEADER_PROPERTIES if not_allowed_properties: @@ -595,10 +587,10 @@ class Settings: raise LeadershipError(_('a leader ({opt.impl_get_display_name()}) cannot have ' '"force_default_on_freeze" or ' '"force_metaconfig_on_freeze" property without "frozen"')) - self._properties.setdefault(option_bag.path, {})[option_bag.index] = properties + self._properties.setdefault(subconfig.path, {})[subconfig.index] = properties # values too because of follower values could have a PropertiesOptionError has value - option_bag.config_bag.context.reset_cache(option_bag) - option_bag.properties = properties + subconfig.config_bag.context.reset_cache(subconfig) + subconfig.properties = properties def set_context_permissives(self, permissives, @@ -610,7 +602,7 @@ class Settings: ) def setpermissives(self, - option_bag, + subconfig, permissives, ): """ @@ -624,9 +616,9 @@ class Settings: """ if not isinstance(permissives, frozenset): raise TypeError(_('permissive must be a frozenset')) - if option_bag is not None: - path = option_bag.path - index = option_bag.index + if subconfig is not None: + path = subconfig.path + index = subconfig.index else: path = None index = None @@ -635,165 +627,166 @@ class Settings: raise ConfigError(_('cannot add those permissives: {0}').format( ' '.join(forbidden_permissives))) self._permissives.setdefault(path, {})[index] = permissives - if option_bag is not None: - option_bag.config_bag.context.reset_cache(option_bag) + if subconfig is not None: + subconfig.config_bag.context.reset_cache(subconfig) #____________________________________________________________ # reset methods def _get_path_index_config_option(self, - bag: Union[OptionBag, ConfigBag], + bag: Union['SubConfig', ConfigBag], msg: str, ): if isinstance(bag, ConfigBag): path = None index = None config_bag = bag - option_bag = None + subconfig= None else: assert not bag.option.impl_is_symlinkoption(), \ _(msg).format(bag.option.impl_get_display_name()) path = bag.path index = bag.index config_bag = bag.config_bag - option_bag = bag - return path, index, config_bag, option_bag + subconfig = bag + return path, index, config_bag, subconfig def reset(self, - bag: Union[OptionBag, ConfigBag], + bag: Union['SubConfig', ConfigBag], ): """reset property """ - path, index, config_bag, option_bag = \ + path, index, config_bag, subconfig = \ self._get_path_index_config_option(bag, "can't reset properties to " "the symlinkoption \"{}\"", ) if path in self._properties and index in self._properties[path]: del self._properties[path][index] - config_bag.context.reset_cache(option_bag) + config_bag.context.reset_cache(subconfig) def reset_permissives(self, - bag: Union[OptionBag, ConfigBag], + bag: Union['SubConfig', ConfigBag], ): """reset permission """ - path, index, config_bag, option_bag = \ + path, index, config_bag, subconfig = \ self._get_path_index_config_option(bag, "can't reset permissives to " "the symlinkoption \"{}\"", ) if path in self._permissives and index in self._permissives[path]: del self._permissives[path][index] - config_bag.context.reset_cache(option_bag) + config_bag.context.reset_cache(subconfig) #____________________________________________________________ # validate properties def calc_raises_properties(self, - option_bag, + subconfig, apply_requires=True, uncalculated=False, transitive_raise=True, ): """raise if needed """ - if not uncalculated and apply_requires and option_bag.properties is not None: - option_properties = option_bag.properties + if not uncalculated and apply_requires and subconfig.properties is not None: + option_properties = subconfig.properties else: - option_properties = self.getproperties(option_bag, + option_properties = self.getproperties(subconfig, apply_requires=apply_requires, uncalculated=uncalculated, transitive_raise=transitive_raise, ) - return self._calc_raises_properties(option_bag, + return self._calc_raises_properties(subconfig, option_properties, ) def _calc_raises_properties(self, - option_bag, + subconfig, option_properties, ): - raises_properties = option_bag.config_bag.properties - SPECIAL_PROPERTIES + raises_properties = subconfig.config_bag.properties - SPECIAL_PROPERTIES # remove global permissive properties if raises_properties and 'permissive' in raises_properties: - raises_properties -= option_bag.config_bag.permissives + raises_properties -= subconfig.config_bag.permissives properties = option_properties & raises_properties # at this point it should not remain any property for the option return properties def validate_properties(self, - option_bag, + subconfig, + *, need_help=True, ): """check properties """ - config_properties = option_bag.config_bag.properties + config_properties = subconfig.config_bag.properties if not config_properties or config_properties == frozenset(['cache']): # if no global property return for transitive_raise in [False, True]: - properties = self.calc_raises_properties(option_bag, + properties = self.calc_raises_properties(subconfig, transitive_raise=transitive_raise, ) if properties != frozenset(): if need_help: - help_properties = dict(self.getproperties(option_bag, + help_properties = dict(self.getproperties(subconfig, help_property=True, transitive_raise=transitive_raise, )) calc_properties = [] - for property_ in self._calc_raises_properties(option_bag, + for property_ in self._calc_raises_properties(subconfig, set(help_properties.keys()), ): calc_properties.append(help_properties[property_]) calc_properties = frozenset(calc_properties) else: calc_properties = properties - raise PropertiesOptionError(option_bag, + raise PropertiesOptionError(subconfig, properties, self, help_properties=calc_properties, ) def validate_mandatory(self, + subconfig, value, - option_bag, ): """verify if option is mandatory without value """ - if 'mandatory' not in option_bag.config_bag.properties: + if 'mandatory' not in subconfig.config_bag.properties: return - values = option_bag.config_bag.context.get_values() - if not ('permissive' in option_bag.config_bag.properties and - 'mandatory' in option_bag.config_bag.permissives) and \ - 'mandatory' in option_bag.properties and values.isempty(option_bag, - value, - False, - ): - raise PropertiesOptionError(option_bag, + values = subconfig.config_bag.context.get_values() + if not ('permissive' in subconfig.config_bag.properties and + 'mandatory' in subconfig.config_bag.permissives) and \ + 'mandatory' in subconfig.properties and values.isempty(subconfig, + value, + False, + ): + raise PropertiesOptionError(subconfig, ['mandatory'], self, ) - if 'empty' in option_bag.properties and values.isempty(option_bag, - value, - True, - ): - raise PropertiesOptionError(option_bag, + if 'empty' in subconfig.properties and values.isempty(subconfig, + value, + True, + ): + raise PropertiesOptionError(subconfig, ['empty'], self, ) def validate_frozen(self, - option_bag, + subconfig, ): """verify if option is frozen """ - if option_bag.config_bag.properties and \ - ('everything_frozen' in option_bag.config_bag.properties or - ('frozen' in option_bag.config_bag.properties and \ - 'frozen' in option_bag.properties)) and \ - not (('permissive' in option_bag.config_bag.properties) and - 'frozen' in option_bag.config_bag.permissives): - raise PropertiesOptionError(option_bag, + if subconfig.config_bag.properties and \ + ('everything_frozen' in subconfig.config_bag.properties or + ('frozen' in subconfig.config_bag.properties and \ + 'frozen' in subconfig.properties)) and \ + not (('permissive' in subconfig.config_bag.properties) and + 'frozen' in subconfig.config_bag.permissives): + raise PropertiesOptionError(subconfig, ['frozen'], self, ) diff --git a/tiramisu/todict.py b/tiramisu/todict.py index 56f922f..26a14ec 100644 --- a/tiramisu/todict.py +++ b/tiramisu/todict.py @@ -6,7 +6,8 @@ from copy import copy from itertools import chain from .error import ValueWarning, ValueErrorWarning, PropertiesOptionError, ConfigError from .setting import undefined -from . import SynDynOption, RegexpOption, ChoiceOption, ParamOption +from .option.syndynoption import SynDynOption +from . import RegexpOption, ChoiceOption, ParamOption from .i18n import _ diff --git a/tiramisu/value.py b/tiramisu/value.py index a4aaab8..b3a5384 100644 --- a/tiramisu/value.py +++ b/tiramisu/value.py @@ -17,7 +17,7 @@ # ____________________________________________________________ from typing import Union, Optional, List, Any from .error import ConfigError -from .setting import owners, undefined, forbidden_owners, OptionBag +from .setting import owners, undefined, forbidden_owners from .autolib import Calculation from .i18n import _ @@ -50,7 +50,7 @@ class Values: #______________________________________________________________________ # get value def get_cached_value(self, - option_bag: OptionBag, + subconfig: "SubConfig", ) -> Any: """get value directly in cache if set otherwise calculated value and set it in cache @@ -58,28 +58,28 @@ class Values: :returns: value """ # try to retrive value in cache - setting_properties = option_bag.config_bag.properties - cache = option_bag.config_bag.context.get_values_cache() - is_cached, value, validated = cache.getcache(option_bag, + setting_properties = subconfig.config_bag.properties + cache = subconfig.config_bag.context.get_values_cache() + is_cached, value, validated = cache.getcache(subconfig, 'values', ) # no cached value so get value if not is_cached: - value, has_calculation = self.get_value(option_bag) + value, has_calculation = self.get_value(subconfig) # validates and warns value if not validated: - validate = option_bag.option.impl_validate(value, - option_bag, - check_error=True, - ) + validate = subconfig.option.impl_validate(subconfig, + value, + check_error=True, + ) if 'warnings' in setting_properties: - option_bag.option.impl_validate(value, - option_bag, - check_error=False, - ) + subconfig.option.impl_validate(subconfig, + value, + check_error=False, + ) # set value to cache if not is_cached and not has_calculation: - cache.setcache(option_bag, + cache.setcache(subconfig, value, validated=validate, ) @@ -90,7 +90,7 @@ class Values: return value def get_value(self, - option_bag: OptionBag, + subconfig: "SubConfig", ) -> Any: """actually retrieves the stored value or the default value (value modified by user) @@ -98,80 +98,82 @@ class Values: """ # get owner and value from store default_value = [undefined, owners.default] - value, owner = self._values.get(option_bag.path, {}).get(option_bag.index, default_value) + value, owner = self._values.get(subconfig.path, {}).get(subconfig.index, default_value) if owner == owners.default or \ - ('frozen' in option_bag.properties and \ - ('force_default_on_freeze' in option_bag.properties or \ - self.check_force_to_metaconfig(option_bag))): + ('frozen' in subconfig.properties and \ + ('force_default_on_freeze' in subconfig.properties or \ + self.check_force_to_metaconfig(subconfig))): # the value is a default value # get it - value = self.get_default_value(option_bag) - value, has_calculation = self.get_calculated_value(option_bag, + value = self.get_default_value(subconfig) + value, has_calculation = self.get_calculated_value(subconfig, value, ) return value, has_calculation def get_default_value(self, - option_bag: OptionBag, + subconfig: "SubConfig", ) -> Any: """get default value: - get parents config value or - get calculated value or - get default value """ - moption_bag = self._get_modified_parent(option_bag) - if moption_bag is not None: + msubconfig = self._get_modified_parent(subconfig) + if msubconfig is not None: # retrieved value from parent config - return moption_bag.config_bag.context.get_values().get_cached_value(moption_bag) + return msubconfig.config_bag.context.get_values().get_cached_value(msubconfig) # now try to get calculated value: - value, _has_calculation = self.get_calculated_value(option_bag, - option_bag.option.impl_getdefault(), + value, _has_calculation = self.get_calculated_value(subconfig, + subconfig.option.impl_getdefault(), ) - if option_bag.index is not None and isinstance(value, (list, tuple)) \ - and (not option_bag.option.impl_is_submulti() or \ + if subconfig.index is not None and isinstance(value, (list, tuple)) \ + and (not subconfig.option.impl_is_submulti() or \ not value or isinstance(value[0], list)): # if index (so slave), must return good value for this index # for submulti, first index is a list, assume other data are list too - if len(value) > option_bag.index: - value = value[option_bag.index] + index = subconfig.index + if len(value) > index: + value = value[index] else: # no value for this index, retrieve default multi value # default_multi is already a list for submulti - value, _has_calculation = self.get_calculated_value(option_bag, - option_bag.option.impl_getdefault_multi(), + value, _has_calculation = self.get_calculated_value(subconfig, + subconfig.option.impl_getdefault_multi(), ) return value def get_calculated_value(self, - option_bag, - value, - reset_cache=True, + subconfig: "SubConfig", + value: Any, + *, + reset_cache: bool=True, ) -> Any: """value could be a calculation, in this case do calculation """ has_calculation = False if isinstance(value, Calculation): - value = value.execute(option_bag) + value = value.execute(subconfig) has_calculation = True elif isinstance(value, list): # if value is a list, do subcalculation for idx, val in enumerate(value): - value[idx], _has_calculation = self.get_calculated_value(option_bag, + value[idx], _has_calculation = self.get_calculated_value(subconfig, val, reset_cache=False, ) if _has_calculation: has_calculation = True if reset_cache: - self.reset_cache_after_calculation(option_bag, + self.reset_cache_after_calculation(subconfig, value, ) return value, has_calculation #______________________________________________________________________ def check_force_to_metaconfig(self, - option_bag: OptionBag, + subconfig: "OptionBag", ) -> bool: """Check if the value must be retrieve from parent metaconfig or not """ @@ -179,25 +181,25 @@ class Values: # => to metaconfig # force_metaconfig_on_freeze is set *explicitly* to an option and context is a # kernelmetaconfig => to sub metaconfig - if 'force_metaconfig_on_freeze' in option_bag.properties: - settings = option_bag.config_bag.context.get_settings() - if option_bag.config_bag.context.impl_type == 'config': + if 'force_metaconfig_on_freeze' in subconfig.properties: + settings = subconfig.config_bag.context.get_settings() + if subconfig.config_bag.context.impl_type == 'config': return True # it's a not a config, force to metaconfig only in *explicitly* set - return 'force_metaconfig_on_freeze' in settings.get_stored_properties(option_bag.path, - option_bag.index, + return 'force_metaconfig_on_freeze' in settings.get_stored_properties(subconfig.path, + subconfig.index, frozenset(), ) return False def reset_cache_after_calculation(self, - option_bag, + subconfig, value, ): """if value is modification after calculation, invalid cache """ - cache = option_bag.config_bag.context.get_values_cache() - is_cache, cache_value, _ = cache.getcache(option_bag, + cache = subconfig.config_bag.context.get_values_cache() + is_cache, cache_value, _ = cache.getcache(subconfig, 'values', expiration=False, ) @@ -206,27 +208,29 @@ class Values: # so do not invalidate cache return # calculated value is a new value, so reset cache - option_bag.config_bag.context.reset_cache(option_bag) + subconfig.config_bag.context.reset_cache(subconfig) # and manage force_store_value - self._set_force_value_suffix(option_bag) +# self._set_force_value_suffix(subconfig) def isempty(self, - option_bag: OptionBag, + subconfig: "SubConfig", value: Any, force_allow_empty_list: bool, ) -> bool: """convenience method to know if an option is empty """ - if option_bag.index is None and option_bag.option.impl_is_submulti(): + index = subconfig.index + option = subconfig.option + if index is None and option.impl_is_submulti(): # index is not set isempty = True for val in value: isempty = self._isempty_multi(val, force_allow_empty_list) if isempty: break - elif (option_bag.index is None or \ - (option_bag.index is not None and option_bag.option.impl_is_submulti())) and \ - option_bag.option.impl_is_multi(): + elif (index is None or \ + (index is not None and option.impl_is_submulti())) and \ + option.impl_is_multi(): # it's a single list isempty = self._isempty_multi(value, force_allow_empty_list) else: @@ -244,86 +248,86 @@ class Values: #______________________________________________________________________ # set value def set_value(self, - option_bag: OptionBag, + subconfig: "SubConfig", value: Any, ) -> None: """set value to option """ owner = self.get_context_owner() - setting_properties = option_bag.config_bag.properties + setting_properties = subconfig.config_bag.properties ori_value = value if 'validator' in setting_properties: - value, has_calculation = self.setvalue_validation(value, - option_bag, + value, has_calculation = self.setvalue_validation(subconfig, + value, ) elif isinstance(value, list): # copy value = value.copy() - self._setvalue(option_bag, + self._setvalue(subconfig, ori_value, owner, ) validator = 'validator' in setting_properties and \ 'demoting_error_warning' not in setting_properties if validator and not has_calculation: - cache = option_bag.config_bag.context.get_values_cache() - cache.setcache(option_bag, + cache = subconfig.config_bag.context.get_values_cache() + cache.setcache(subconfig, value, validated=validator, ) elif 'validator' in setting_properties and has_calculation: - cache = option_bag.config_bag.context.get_values_cache() - cache.delcache(option_bag.path) - if 'force_store_value' in setting_properties and option_bag.option.impl_is_leader(): - leader = option_bag.option.impl_get_leadership() - leader.follower_force_store_value(value, - option_bag.config_bag, - owners.forced, - ) + cache = subconfig.config_bag.context.get_values_cache() + cache.delcache(subconfig.path) +# if 'force_store_value' in setting_properties and option_bag.option.impl_is_leader(): +# leader = option_bag.option.impl_get_leadership() +# leader.follower_force_store_value(value, +# option_bag.config_bag, +# owners.forced, +# ) def setvalue_validation(self, - value, - option_bag, + subconfig: "SubConfig", + value: Any, ): """validate value before set value """ - settings = option_bag.config_bag.context.get_settings() + settings = subconfig.config_bag.context.get_settings() # First validate properties with this value - opt = option_bag.option - settings.validate_frozen(option_bag) - val, has_calculation = self.get_calculated_value(option_bag, + opt = subconfig.option + settings.validate_frozen(subconfig) + val, has_calculation = self.get_calculated_value(subconfig, value, - False, + reset_cache=False, ) - settings.validate_mandatory(val, - option_bag, + settings.validate_mandatory(subconfig, + val, ) # Value must be valid for option - opt.impl_validate(val, - option_bag, + opt.impl_validate(subconfig, + val, check_error=True, ) - if 'warnings' in option_bag.config_bag.properties: + if 'warnings' in subconfig.config_bag.properties: # No error found so emit warnings - opt.impl_validate(val, - option_bag, + opt.impl_validate(subconfig, + val, check_error=False, ) return val, has_calculation def _setvalue(self, - option_bag: OptionBag, + subconfig: "SubConfig", value: Any, owner: str, ) -> None: - option_bag.config_bag.context.reset_cache(option_bag) - self.set_storage_value(option_bag.path, - option_bag.index, + subconfig.config_bag.context.reset_cache(subconfig) + self.set_storage_value(subconfig.path, + subconfig.index, value, owner, ) - self._set_force_value_suffix(option_bag) +# self._set_force_value_suffix(option_bag) def set_storage_value(self, path, @@ -335,64 +339,66 @@ class Values: """ self._values.setdefault(path, {})[index] = [value, owner] - def _set_force_value_suffix(self, option_bag: OptionBag) -> None: - """ force store value for an option for suffixes - """ - # pylint: disable=too-many-locals - if 'force_store_value' not in option_bag.config_bag.properties: - return - - for woption in option_bag.option._get_suffixes_dependencies(): # pylint: disable=protected-access - # options from dependencies are weakref - option = woption() - force_store_options = [] - for coption in option.get_children_recursively(None, - None, - option_bag.config_bag, - option_suffixes=[], - ): - if 'force_store_value' in coption.impl_getproperties(): - force_store_options.append(coption) - if not force_store_options: - continue - for coption in force_store_options: - if coption.impl_is_follower(): - leader = coption.impl_get_leadership().get_leader() - loption_bag = OptionBag(leader, - None, - option_bag.config_bag, - properties=frozenset(), - ) - indexes = range(len(self.get_value(loption_bag)[0])) - else: - indexes = [None] - for index in indexes: - for coption_bag in option.get_sub_children(coption, - option_bag.config_bag, - index=index, - properties=frozenset(), - ): - default_value = [self.get_value(coption_bag)[0], owners.forced] - self._values.setdefault(coption_bag.path, {})[index] = default_value +# def _set_force_value_suffix(self, +# option_bag: OptionBag, +# ) -> None: +# """ force store value for an option for suffixes +# """ +# # pylint: disable=too-many-locals +# if 'force_store_value' not in option_bag.config_bag.properties: +# return +# +# for woption in option_bag.option._get_suffixes_dependencies(): # pylint: disable=protected-access +# # options from dependencies are weakref +# option = woption() +# force_store_options = [] +# for coption in option.get_children_recursively(None, +# None, +# option_bag.config_bag, +# option_suffixes=[], +# ): +# if 'force_store_value' in coption.impl_getproperties(): +# force_store_options.append(coption) +# if not force_store_options: +# continue +# for coption in force_store_options: +# if coption.impl_is_follower(): +# leader = coption.impl_get_leadership().get_leader() +# loption_bag = OptionBag(leader, +# None, +# option_bag.config_bag, +# properties=frozenset(), +# ) +# indexes = range(len(self.get_value(loption_bag)[0])) +# else: +# indexes = [None] +# for index in indexes: +# for coption_bag in option.get_sub_children(coption, +# option_bag.config_bag, +# index=index, +# properties=frozenset(), +# ): +# default_value = [self.get_value(coption_bag)[0], owners.forced] +# self._values.setdefault(coption_bag.path, {})[index] = default_value def _get_modified_parent(self, - option_bag: OptionBag, - ) -> Optional[OptionBag]: + subconfig: "SubConfig", + ) -> Optional["SubConfig"]: """ Search in differents parents a Config with a modified value If not found, return None For follower option, return the Config where leader is modified """ - def build_option_bag(option_bag, parent): - doption_bag = option_bag.copy() - config_bag = option_bag.config_bag.copy() + def build_option_bag(subconfig, parent): + doption_bag = subconfig.copy() + config_bag = subconfig.config_bag.copy() config_bag.context = parent config_bag.unrestraint() doption_bag.config_bag = config_bag return doption_bag - for parent in option_bag.config_bag.context.get_parents(): - doption_bag = build_option_bag(option_bag, parent) - if 'force_metaconfig_on_freeze' in option_bag.properties: + for parent in subconfig.config_bag.context.get_parents(): + doption_bag = build_option_bag(subconfig, parent) + if 'force_metaconfig_on_freeze' in subconfig.properties: # remove force_metaconfig_on_freeze only if option in metaconfig # hasn't force_metaconfig_on_freeze properties ori_properties = doption_bag.properties @@ -403,6 +409,7 @@ class Values: else: doption_bag.properties = ori_properties parent_owner = parent.get_values().getowner(doption_bag, + parent, only_default=True, ) if parent_owner != owners.default: @@ -415,18 +422,20 @@ class Values: # owner def is_default_owner(self, - option_bag: OptionBag, + subconfig: "SubConfig", + *, validate_meta: bool=True, ) -> bool: """is default owner for an option """ - return self.getowner(option_bag, + return self.getowner(subconfig, validate_meta=validate_meta, only_default=True, ) == owners.default def hasvalue(self, path, + *, index=None, ): """if path has a value @@ -440,7 +449,8 @@ class Values: return False def getowner(self, - option_bag, + subconfig: "SubConfig", + *, validate_meta=True, only_default=False, ): @@ -452,111 +462,114 @@ class Values: was present :returns: a `setting.owners.Owner` object """ - context = option_bag.config_bag.context - opt = option_bag.option - if opt.impl_is_symlinkoption(): - option_bag.ori_option = opt - opt = opt.impl_getopt() - option_bag.option = opt - option_bag.path = opt.impl_getpath() + context = subconfig.config_bag.context settings = context.get_settings() - settings.validate_properties(option_bag) - if 'frozen' in option_bag.properties and \ - 'force_default_on_freeze' in option_bag.properties: + settings.validate_properties(subconfig) + if 'frozen' in subconfig.properties and \ + 'force_default_on_freeze' in subconfig.properties: return owners.default if only_default: - if self.hasvalue(option_bag.path, - index=option_bag.index, + if self.hasvalue(subconfig.path, + index=subconfig.index, ): owner = 'not_default' else: owner = owners.default else: - owner = self._values.get(option_bag.path, {}).get(option_bag.index, + owner = self._values.get(subconfig.path, {}).get(subconfig.index, [undefined, owners.default], )[1] if validate_meta is not False and (owner is owners.default or - 'frozen' in option_bag.properties and - 'force_metaconfig_on_freeze' in option_bag.properties): - moption_bag = self._get_modified_parent(option_bag) - if moption_bag is not None: - values = moption_bag.config_bag.context.get_values() - owner = values.getowner(moption_bag, + 'frozen' in subconfig.properties and + 'force_metaconfig_on_freeze' in subconfig.properties): + msubconfig = self._get_modified_parent(subconfig) + if msubconfig is not None: + values = msubconfig.config_bag.context.get_values() + owner = values.getowner(msubconfig, + parent, only_default=only_default, ) - elif 'force_metaconfig_on_freeze' in option_bag.properties: + elif 'force_metaconfig_on_freeze' in subconfig.properties: return owners.default return owner def set_owner(self, - option_bag, + subconfig, owner, ): """ sets a owner to an option - :param option_bag: the `OptionBag` object + :param subconfig: the `OptionBag` object :param owner: a valid owner, that is a `setting.owners.Owner` object """ if owner in forbidden_owners: raise ValueError(_('set owner "{0}" is forbidden').format(str(owner))) - if not self.hasvalue(option_bag.path, - index=option_bag.index, + if not self.hasvalue(subconfig.path, + index=subconfig.index, ): - raise ConfigError(_(f'no value for {option_bag.path} cannot change owner to {owner}')) - option_bag.config_bag.context.get_settings().validate_frozen(option_bag) - self._values[option_bag.path][option_bag.index][1] = owner + raise ConfigError(_(f'no value for {subconfig.path} cannot change owner to {owner}')) + subconfig.config_bag.context.get_settings().validate_frozen(subconfig) + self._values[subconfig.path][subconfig.index][1] = owner #______________________________________________________________________ # reset - def reset(self, option_bag: OptionBag) -> None: + def reset(self, + subconfig: "SubConfig", + ) -> None: """reset value for an option """ - context = option_bag.config_bag.context - hasvalue = self.hasvalue(option_bag.path) - setting_properties = option_bag.config_bag.properties - - if hasvalue and 'validator' in option_bag.config_bag.properties: - fake_context = context.gen_fake_values() - config_bag = option_bag.config_bag.copy() - config_bag.remove_validation() - config_bag.context = fake_context - soption_bag = option_bag.copy() - soption_bag.config_bag = config_bag - fake_value = fake_context.get_values() - fake_value.reset(soption_bag) - soption_bag.config_bag.properties = option_bag.config_bag.properties - value = fake_value.get_default_value(soption_bag) - fake_value.setvalue_validation(value, - soption_bag, - ) - opt = option_bag.option + config_bag = subconfig.config_bag + context = config_bag.context + hasvalue = self.hasvalue(subconfig.path) + setting_properties = config_bag.properties + if hasvalue and 'validator' in config_bag.properties: + fake_context = context.gen_fake_context() + fake_config_bag = config_bag.copy() + fake_config_bag.remove_validation() + fake_config_bag.context = fake_context + fake_subconfig = fake_context.get_sub_config(fake_config_bag, + subconfig.path, + subconfig.index, + validate_properties=False, + follower_not_apply_requires=False, + ) + fake_values = fake_context.get_values() + fake_values.reset(fake_subconfig) + fake_subconfig.config_bag.properties = setting_properties + value = fake_values.get_default_value(fake_subconfig) + fake_values.setvalue_validation(fake_subconfig, + value, + ) + opt = subconfig.option if opt.impl_is_leader(): - opt.impl_get_leadership().reset(option_bag.config_bag) + opt.impl_get_leadership().reset(subconfig.parent) if hasvalue: - if 'force_store_value' in option_bag.config_bag.properties and \ - 'force_store_value' in option_bag.properties: - value = self.get_default_value(option_bag) + if 'force_store_value' in subconfig.config_bag.properties and \ + 'force_store_value' in subconfig.properties: + value = self.get_default_value(subconfig) - self._setvalue(option_bag, + self._setvalue(subconfig, value, owners.forced, ) else: # for leader only value = None - if option_bag.path in self._values: - del self._values[option_bag.path] - context.reset_cache(option_bag) - if 'force_store_value' in setting_properties and option_bag.option.impl_is_leader(): - if value is None: - value = self.get_default_value(option_bag) - leader = option_bag.option.impl_get_leadership() - leader.follower_force_store_value(value, - option_bag.config_bag, - owners.forced, - ) + if subconfig.path in self._values: + del self._values[subconfig.path] + context.reset_cache(subconfig) +# if 'force_store_value' in setting_properties and option_bag.option.impl_is_leader(): +# if value is None: +# value = self.get_default_value(option_bag, +# parent, +# ) +# leader = option_bag.option.impl_get_leadership() +# leader.follower_force_store_value(value, +# option_bag.config_bag, +# owners.forced, +# ) #______________________________________________________________________ # Follower @@ -569,73 +582,86 @@ class Values: return 0 def reset_follower(self, - option_bag: OptionBag, + subconfig: "SubConfig", ) -> None: """reset value for a follower """ - if not self.hasvalue(option_bag.path, - index=option_bag.index, + if not self.hasvalue(subconfig.path, + index=subconfig.index, ): return - context = option_bag.config_bag.context - setting_properties = option_bag.config_bag.properties + config_bag = subconfig.config_bag + context = config_bag.context + setting_properties = config_bag.properties if 'validator' in setting_properties: - fake_context = context.gen_fake_values() - fake_value = fake_context.get_values() - config_bag = option_bag.config_bag.copy() - config_bag.remove_validation() - config_bag.context = fake_context - soption_bag = option_bag.copy() - soption_bag.config_bag = config_bag - fake_value.reset_follower(soption_bag) - value = fake_value.get_default_value(soption_bag) - fake_value.setvalue_validation(value, - soption_bag) - if 'force_store_value' in setting_properties and \ - 'force_store_value' in option_bag.properties: - value = self.get_default_value(option_bag) + fake_context = context.gen_fake_context() + fake_config_bag = config_bag.copy() + fake_config_bag.remove_validation() + fake_config_bag.context = fake_context + fake_subconfig = fake_context.get_sub_config(fake_config_bag, + subconfig.path, + subconfig.index, + validate_properties=False, + follower_not_apply_requires=False, + ) + fake_values = fake_context.get_values() + fake_values.reset_follower(fake_subconfig) + fake_subconfig.config_bag.properties = setting_properties + value = fake_values.get_default_value(fake_subconfig) + fake_values.setvalue_validation(fake_subconfig, + value, + ) +# if 'force_store_value' in setting_properties and \ +# 'force_store_value' in option_bag.properties: +# value = self.get_default_value(option_bag, +# parent, +# ) +# +# self._setvalue(option_bag, +# value, +# owners.forced, +# ) +# else: + self.resetvalue_index(subconfig) + context.reset_cache(subconfig) - self._setvalue(option_bag, - value, - owners.forced, - ) - else: - self.resetvalue_index(option_bag) - context.reset_cache(option_bag) - - def resetvalue_index(self, option_bag: OptionBag) -> None: + def resetvalue_index(self, + subconfig: "SubConfig", + ) -> None: """reset a value for a follower at an index """ - if option_bag.path in self._values and option_bag.index in self._values[option_bag.path]: - del self._values[option_bag.path][option_bag.index] + if subconfig.path in self._values and subconfig.index in self._values[subconfig.path]: + del self._values[subconfig.path][subconfig.index] - def reduce_index(self, option_bag: OptionBag) -> None: + def reduce_index(self, + subconfig: "SubConfig", + ) -> None: """reduce follower's value from a specified index """ - self.resetvalue_index(option_bag) - for index in range(option_bag.index + 1, self.get_max_length(option_bag.path)): - if self.hasvalue(option_bag.path, + self.resetvalue_index(subconfig) + for index in range(subconfig.index + 1, self.get_max_length(subconfig.path)): + if self.hasvalue(subconfig.path, index=index, ): - self._values[option_bag.path][index - 1] = self._values[option_bag.path].pop(index) + self._values[subconfig.path][index - 1] = self._values[subconfig.path].pop(index) def reset_leadership(self, - option_bag: OptionBag, - leadership_option_bag: OptionBag, + subconfig: "SubConfig", index: int, ) -> None: - """reset leadershop from an index + """reset leadership from an index """ - current_value = self.get_cached_value(option_bag) + current_value = self.get_cached_value(subconfig) length = len(current_value) if index >= length: raise IndexError(_('index {index} is greater than the length {length} ' - 'for option "{option_bag.option.impl_get_display_name()}"')) + 'for option "{subconfig.option.impl_get_display_name()}"')) current_value.pop(index) - leadership_option_bag.option.pop(index, - option_bag.config_bag, - ) - self.set_value(option_bag, + leadership_subconfig = subconfig.parent + leadership_subconfig.option.pop(subconfig, + index, + ) + self.set_value(subconfig, current_value, ) @@ -643,7 +669,7 @@ class Values: # information def set_information(self, - option_bag, + subconfig, key, value, ): @@ -652,24 +678,27 @@ class Values: :param key: information's key (ex: "help", "doc" :param value: information's value (ex: "the help string") """ - if option_bag is None: + if subconfig is None: path = None else: - path = option_bag.path + path = subconfig.path self._informations.setdefault(path, {})[key] = value if path is None: return - for key, options in option_bag.option.get_dependencies_information().items(): + config_bag = subconfig.config_bag + context = config_bag.context + for key, options in subconfig.option.get_dependencies_information().items(): for option in options: - cache_option_bag = OptionBag(option, - None, - option_bag.config_bag, - properties=None, - ) - cache_option_bag.config_bag.context.reset_cache(cache_option_bag) + option_subconfig = context.get_sub_config(config_bag, + option.impl_getpath(), + None, + validate_properties=False, + follower_not_apply_requires=False, + ) + context.reset_cache(option_subconfig) def get_information(self, - option_bag, + subconfig, name, default, ): @@ -677,15 +706,15 @@ class Values: :param name: the item string (ex: "help") """ - if option_bag is None: + if subconfig is None: path = None else: - path = option_bag.path + path = subconfig.path try: return self._informations[path][name] except KeyError as err: - if option_bag: - return option_bag.option.impl_get_information(name, default) + if subconfig: + return subconfig.option.impl_get_information(name, default) if default is not undefined: return default raise ValueError(_("information's item not found: {0}").format(name)) from err