# coding: utf-8 from .autopath import do_autopath do_autopath() import pytest from tiramisu.setting import groups, owners 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, \ Config, \ Params, ParamOption, ParamValue, ParamSuffix, ParamSelfOption, ParamDynOption, ParamIndex, \ Calculation, calc_value from tiramisu.error import PropertiesOptionError, ConfigError, ConflictError, ValueOptionError class ConvertDynOptionDescription(DynOptionDescription): def convert_suffix_to_path(self, suffix): # remove dot with is illegal return suffix.replace('.', '') def return_true(value, param=None, suffix=None): if value == 'val' and param in [None, 'yes']: return raise ValueError('no value') def return_dynval(value='val', suffix=None): return value def return_list2(suffix): return [str(suffix), 'val2'] def return_list(val=None, suffix=None): if val: return val else: return ['val1', 'val2'] def return_list_dot(val=None, suffix=None): return ['val.1', 'val.2'] def return_same_list(*args, **kwargs): return ['val1', 'val1'] def return_wrong_list(*args, **kwargs): return ['---', ' '] def return_raise(suffix): raise Exception('error') def return_str(*args, **kwargs): return 'str' def test_build_dyndescription(): st1 = StrOption('st', '') 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 cfg.option('dodval1').isdynamic() assert cfg.option('dodval1.st').isdynamic() # assert not list_sessions() def test_build_dyndescription_with_int(): int1 = IntOption('int', '', default=Calculation(calc_value, Params(ParamSuffix()))) 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 not list_sessions() def test_build_dyndescription_with_dot(): st1 = StrOption('st', '', default=Calculation(calc_value, Params(ParamSuffix()))) 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 not list_sessions() def test_build_dyndescription_raise(): st1 = StrOption('st', '') dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(return_raise)) od1 = OptionDescription('od', '', [dod]) cfg = Config(od1) with pytest.raises(ConfigError): cfg.value.get() # assert not list_sessions() def test_build_dyndescription_not_list(): st1 = StrOption('st', '') dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(return_str)) od1 = OptionDescription('od', '', [dod]) cfg = Config(od1) with pytest.raises(ValueError): cfg.value.get() # assert not list_sessions() def test_subpath_dyndescription(): st1 = StrOption('st', '') dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(return_list)) od1 = OptionDescription('od', '', [dod]) od2 = OptionDescription('od', '', [od1]) cfg = Config(od2) assert cfg.value.get() == {'od.dodval1.st': None, 'od.dodval2.st': None} # assert not list_sessions() def test_list_dyndescription(): st = StrOption('st', '') dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) od = OptionDescription('od', '', [dod]) od2 = OptionDescription('od', '', [od]) cfg = Config(od2) assert cfg.option('od.dodval1.st').value.get() is None assert cfg.option('od.dodval2.st').value.get() is None # assert not list_sessions() def test_unknown_dyndescription(): st = StrOption('st', '') dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) od = OptionDescription('od', '', [dod]) od2 = OptionDescription('od', '', [od]) cfg = Config(od2) with pytest.raises(AttributeError): cfg.option('od.dodval3').value.get() with pytest.raises(AttributeError): cfg.option('od.dodval1.novalue').value.get() with pytest.raises(AttributeError): cfg.option('od.dodval1.stnoval1').value.get() with pytest.raises(AttributeError): cfg.option('od.dod.st').value.get() # assert not list_sessions() def test_getdoc_dyndescription(): st1 = StrOption('st', 'doc1') dod = DynOptionDescription('dod', 'doc2', [st1], suffixes=Calculation(return_list)) od1 = OptionDescription('od', '', [dod]) od2 = OptionDescription('od', '', [od1]) cfg = Config(od2) assert cfg.option('od.dodval1.st').name() == 'st' assert cfg.option('od.dodval2.st').name() == 'st' assert cfg.option('od.dodval1').name() == 'dodval1' assert cfg.option('od.dodval2').name() == 'dodval2' assert cfg.option('od.dodval1.st').doc() == 'doc1val1' assert cfg.option('od.dodval2.st').doc() == 'doc1val2' assert cfg.option('od.dodval1').doc() == 'doc2val1' assert cfg.option('od.dodval2').doc() == 'doc2val2' # assert not list_sessions() def test_mod_dyndescription(): st = StrOption('st', '') dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) od = OptionDescription('od', '', [dod]) od2 = OptionDescription('od', '', [od]) cfg = Config(od2) owner = cfg.owner.get() # assert cfg.option('od.dodval1.st').value.get() is None assert cfg.option('od.dodval2.st').value.get() is None assert cfg.option('od.dodval1.st').owner.isdefault() assert cfg.option('od.dodval2.st').owner.isdefault() # cfg.option('od.dodval1.st').value.set('yes') assert cfg.option('od.dodval1.st').value.get() == 'yes' assert cfg.option('od.dodval2.st').value.get() is None assert cfg.option('od.dodval1.st').owner.get() == owner assert cfg.option('od.dodval2.st').owner.isdefault() # cfg.option('od.dodval2.st').value.set('no') assert cfg.option('od.dodval1.st').value.get() == 'yes' assert cfg.option('od.dodval2.st').value.get() == 'no' assert cfg.option('od.dodval1.st').owner.get() == owner assert cfg.option('od.dodval2.st').owner.get() == owner # assert not list_sessions() def test_del_dyndescription(): st = StrOption('st', '') dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) od = OptionDescription('od', '', [dod]) od2 = OptionDescription('od', '', [od]) cfg = Config(od2) owner = cfg.owner.get() assert cfg.option('od.dodval1.st').value.get() is None assert cfg.option('od.dodval2.st').value.get() is None cfg.option('od.dodval1.st').value.set('yes') assert cfg.option('od.dodval1.st').owner.get() == owner cfg.option('od.dodval1.st').value.reset() assert cfg.option('od.dodval1.st').owner.isdefault() # assert not list_sessions() def test_multi_dyndescription(): st = StrOption('st', '', multi=True) dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) od = OptionDescription('od', '', [dod]) od2 = OptionDescription('od', '', [od]) cfg = Config(od2) owner = cfg.owner.get() assert cfg.option('od.dodval1.st').value.get() == [] assert cfg.option('od.dodval2.st').value.get() == [] assert cfg.option('od.dodval1.st').owner.isdefault() assert cfg.option('od.dodval2.st').owner.isdefault() cfg.option('od.dodval1.st').value.set(['yes']) assert cfg.option('od.dodval1.st').value.get() == ['yes'] assert cfg.option('od.dodval2.st').value.get() == [] assert cfg.option('od.dodval1.st').owner.get() == owner assert cfg.option('od.dodval2.st').owner.isdefault() cfg.option('od.dodval2.st').value.set(['no']) assert cfg.option('od.dodval1.st').value.get() == ['yes'] assert cfg.option('od.dodval2.st').value.get() == ['no'] assert cfg.option('od.dodval1.st').owner.get() == owner assert cfg.option('od.dodval2.st').owner.get() == owner cfg.option('od.dodval1.st').value.set(['yes', 'no']) assert cfg.option('od.dodval1.st').value.get() == ['yes', 'no'] cfg.option('od.dodval1.st').value.set(['yes']) assert cfg.option('od.dodval1.st').value.get() == ['yes'] # assert not list_sessions() def test_prop_dyndescription(): st = StrOption('st', '', properties=('test',)) dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) od = OptionDescription('od', '', [dod]) od2 = OptionDescription('od', '', [od]) cfg = Config(od2) assert set(cfg.option('od.dodval1.st').property.get()) == set(['test']) assert set(cfg.option('od.dodval2.st').property.get()) == set(['test']) cfg.option('od.dodval2.st').property.add('test2') assert set(cfg.option('od.dodval1.st').property.get()) == set(['test']) assert set(cfg.option('od.dodval2.st').property.get()) == set(['test', 'test2']) cfg.option('od.dodval1.st').property.remove('test') assert set(cfg.option('od.dodval1.st').property.get()) == set([]) # assert set(cfg.option('od.dodval1').property.get()) == set([]) assert set(cfg.option('od.dodval2').property.get()) == set([]) cfg.option('od.dodval1').property.add('test1') assert set(cfg.option('od.dodval1').property.get()) == set(['test1']) assert set(cfg.option('od.dodval2').property.get()) == set([]) cfg.option('od.dodval1').property.remove('test1') 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'} # assert not list_sessions() def test_callback_dyndescription(): st = StrOption('st', '', Calculation(return_dynval)) dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) od = OptionDescription('od', '', [dod]) od2 = OptionDescription('od', '', [od]) cfg = Config(od2) owner = cfg.owner.get() assert cfg.option('od.dodval1.st').value.get() == 'val' assert cfg.option('od.dodval2.st').value.get() == 'val' assert cfg.option('od.dodval1.st').owner.isdefault() assert cfg.option('od.dodval2.st').owner.isdefault() cfg.option('od.dodval1.st').value.set('val2') assert cfg.option('od.dodval1.st').value.get() == 'val2' assert cfg.option('od.dodval2.st').value.get() == 'val' assert cfg.option('od.dodval1.st').owner.get() == owner assert cfg.option('od.dodval2.st').owner.isdefault() cfg.option('od.dodval1.st').value.reset() assert cfg.option('od.dodval1.st').value.get() == 'val' assert cfg.option('od.dodval2.st').value.get() == 'val' 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_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, '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']} 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']} 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 not list_sessions() def test_callback_dyndescription_outside2(): lst = StrOption('lst', '', ['val1', 'val2'], multi=True) out = StrOption('out', '') st = StrOption('st', '', Calculation(return_dynval, Params(ParamOption(out)))) dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(lst)))) 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']} 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 not list_sessions() def test_callback_list_dyndescription(): st = StrOption('st', '', Calculation(return_list2, Params(ParamSuffix())), multi=True, properties=('notunique',)) dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) od = OptionDescription('od', '', [dod]) od2 = OptionDescription('od', '', [od]) cfg = Config(od2) owner = cfg.owner.get() assert cfg.option('od.dodval1.st').value.get() == ['val1', 'val2'] assert cfg.option('od.dodval2.st').value.get() == ['val2', 'val2'] assert cfg.option('od.dodval1.st').owner.isdefault() assert cfg.option('od.dodval2.st').owner.isdefault() cfg.option('od.dodval1.st').value.set(['val3', 'val2']) assert cfg.option('od.dodval1.st').value.get() == ['val3', 'val2'] assert cfg.option('od.dodval2.st').value.get() == ['val2', 'val2'] assert cfg.option('od.dodval1.st').owner.get() == owner assert cfg.option('od.dodval2.st').owner.isdefault() # assert not list_sessions() 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() with pytest.raises(PropertiesOptionError): cfg.option('od.dodval1.st').value.get() with pytest.raises(PropertiesOptionError): cfg.option('od.dodval2.st').value.get() cfg.property.read_write() cfg.option('od.dodval1.st').value.set('val') cfg.property.read_only() assert cfg.option('od.dodval1.st').value.get() == 'val' with pytest.raises(PropertiesOptionError): cfg.option('od.dodval2.st').value.get() cfg.property.read_write() cfg.option('od.dodval1.st').value.reset() cfg.property.read_only() with pytest.raises(PropertiesOptionError): cfg.option('od.dodval1.st').value.get() # assert not list_sessions() def test_build_dyndescription_context(): val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) st1 = StrOption('st', '') 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 not list_sessions() def test_subpath_dyndescription_context(): val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) st1 = StrOption('st', '') dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(return_list, Params(ParamOption(val1)))) 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 not list_sessions() def test_list_dyndescription_context(): val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) st = StrOption('st', '') dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(val1)))) od = OptionDescription('od', '', [dod, val1]) od2 = OptionDescription('od', '', [od]) cfg = Config(od2) assert cfg.option('od.dodval1.st').value.get() is None assert cfg.option('od.dodval2.st').value.get() is None with pytest.raises(AttributeError): cfg.option('od.dodval3').value.get() # assert not list_sessions() def test_mod_dyndescription_context(): val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) st = StrOption('st', '') dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(val1)))) od = OptionDescription('od', '', [dod, val1]) od2 = OptionDescription('od', '', [od]) cfg = Config(od2) owner = cfg.owner.get() assert cfg.option('od.dodval1.st').value.get() is None assert cfg.option('od.dodval2.st').value.get() is None assert cfg.option('od.dodval1.st').owner.isdefault() assert cfg.option('od.dodval2.st').owner.isdefault() cfg.option('od.dodval1.st').value.set('yes') assert cfg.option('od.dodval1.st').value.get() == 'yes' assert cfg.option('od.dodval2.st').value.get() is None assert cfg.option('od.dodval1.st').owner.get() == owner assert cfg.option('od.dodval2.st').owner.isdefault() cfg.option('od.dodval2.st').value.set('no') assert cfg.option('od.dodval1.st').value.get() == 'yes' assert cfg.option('od.dodval2.st').value.get() == 'no' assert cfg.option('od.dodval1.st').owner.get() == owner assert cfg.option('od.dodval2.st').owner.get() == owner # assert not list_sessions() def test_del_dyndescription_context(): val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) st = StrOption('st', '') dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(val1)))) od = OptionDescription('od', '', [dod, val1]) od2 = OptionDescription('od', '', [od]) cfg = Config(od2) owner = cfg.owner.get() assert cfg.option('od.dodval1.st').value.get() is None assert cfg.option('od.dodval2.st').value.get() is None cfg.option('od.dodval1.st').value.set('yes') assert cfg.option('od.dodval1.st').owner.get() == owner cfg.option('od.dodval1.st').value.reset() assert cfg.option('od.dodval1.st').owner.isdefault() # assert not list_sessions() def test_multi_dyndescription_context(): val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) st = StrOption('st', '', multi=True, properties=('notunique',)) dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(val1)))) od = OptionDescription('od', '', [dod, val1]) od2 = OptionDescription('od', '', [od]) cfg = Config(od2) owner = cfg.owner.get() assert cfg.option('od.dodval1.st').value.get() == [] assert cfg.option('od.dodval2.st').value.get() == [] assert cfg.option('od.dodval1.st').owner.isdefault() assert cfg.option('od.dodval2.st').owner.isdefault() cfg.option('od.dodval1.st').value.set(['yes']) assert cfg.option('od.dodval1.st').value.get() == ['yes'] assert cfg.option('od.dodval2.st').value.get() == [] assert cfg.option('od.dodval1.st').owner.get() == owner assert cfg.option('od.dodval2.st').owner.isdefault() cfg.option('od.dodval2.st').value.set(['no']) assert cfg.option('od.dodval1.st').value.get() == ['yes'] assert cfg.option('od.dodval2.st').value.get() == ['no'] assert cfg.option('od.dodval1.st').owner.get() == owner assert cfg.option('od.dodval2.st').owner.get() == owner cfg.option('od.dodval1.st').value.set(['yes', 'yes']) assert cfg.option('od.dodval1.st').value.get() == ['yes', 'yes'] cfg.option('od.dodval1.st').value.set(['yes']) assert cfg.option('od.dodval1.st').value.get() == ['yes'] # assert not list_sessions() def test_prop_dyndescription_context(): val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) st = StrOption('st', '', properties=('test',)) dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(val1)))) od = OptionDescription('od', '', [dod, val1]) od2 = OptionDescription('od', '', [od]) cfg = Config(od2) assert set(cfg.option('od.dodval1.st').property.get()) == set(['test']) assert set(cfg.option('od.dodval2.st').property.get()) == set(['test']) cfg.option('od.dodval2.st').property.add('test2') assert set(cfg.option('od.dodval1.st').property.get()) == set(['test']) assert set(cfg.option('od.dodval2.st').property.get()) == set(['test', 'test2']) cfg.option('od.dodval1.st').property.remove('test') assert set(cfg.option('od.dodval1.st').property.get()) == set([]) assert set(cfg.option('od.dodval2.st').property.get()) == set(['test', 'test2']) # assert not list_sessions() def test_callback_dyndescription_context(): val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) st = StrOption('st', '', Calculation(return_dynval)) dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) od = OptionDescription('od', '', [dod, val1]) od2 = OptionDescription('od', '', [od]) cfg = Config(od2) owner = cfg.owner.get() assert cfg.option('od.dodval1.st').value.get() == 'val' assert cfg.option('od.dodval2.st').value.get() == 'val' assert cfg.option('od.dodval1.st').owner.isdefault() assert cfg.option('od.dodval2.st').owner.isdefault() cfg.option('od.dodval1.st').value.set('val2') assert cfg.option('od.dodval1.st').value.get() == 'val2' assert cfg.option('od.dodval2.st').value.get() == 'val' assert cfg.option('od.dodval1.st').owner.get() == owner assert cfg.option('od.dodval2.st').owner.isdefault() cfg.option('od.dodval1.st').value.reset() assert cfg.option('od.dodval1.st').value.get() == 'val' assert cfg.option('od.dodval2.st').value.get() == 'val' assert cfg.option('od.dodval1.st').owner.isdefault() assert cfg.option('od.dodval2.st').owner.isdefault() # assert not list_sessions() 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() with pytest.raises(PropertiesOptionError): cfg.option('od.dodval1.st').value.get() with pytest.raises(PropertiesOptionError): cfg.option('od.dodval2.st').value.get() cfg.property.read_write() cfg.option('od.dodval1.st').value.set('val') cfg.property.read_only() assert cfg.option('od.dodval1.st').value.get() == 'val' with pytest.raises(PropertiesOptionError): cfg.option('od.dodval2.st').value.get() cfg.property.read_write() cfg.option('od.dodval1.st').value.reset() cfg.property.read_only() with pytest.raises(PropertiesOptionError): cfg.option('od.dodval1.st').value.get() # assert not list_sessions() def test_increase_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_write() assert cfg.option('od.dodval1.st').value.get() is None assert cfg.option('od.dodval2.st').value.get() is None with pytest.raises(AttributeError): cfg.option('od.dodval3.st').value.get() cfg.option('od.val1').value.set(['val1', 'val2', 'val3']) assert cfg.option('od.dodval1.st').value.get() is None assert cfg.option('od.dodval2.st').value.get() is None assert cfg.option('od.dodval3.st').value.get() is None # assert not list_sessions() def test_decrease_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) owner = cfg.owner.get() cfg.property.read_write() assert cfg.option('od.dodval1.st').value.get() is None assert cfg.option('od.dodval2.st').value.get() is None cfg.option('od.dodval2.st').value.set('yes') assert cfg.option('od.dodval1.st').value.get() is None assert cfg.option('od.dodval2.st').value.get() == 'yes' assert cfg.option('od.dodval1.st').owner.isdefault() assert cfg.option('od.dodval2.st').owner.get() == owner with pytest.raises(AttributeError): cfg.option('od.dodval3').value.get() cfg.option('od.val1').value.set(['val1']) assert cfg.option('od.dodval1.st').value.get() is None with pytest.raises(AttributeError): cfg.option('od.dodval2').value.get() with pytest.raises(AttributeError): cfg.option('od.dodval3').value.get() assert cfg.option('od.dodval1.st').owner.isdefault() with pytest.raises(AttributeError): cfg.option('od.dodval2.st').owner.get() with pytest.raises(AttributeError): cfg.option('od.dodval2.st').value.get() # assert not list_sessions() def test_dyndescription_root(): boolean = BoolOption('boolean', '', True) disabled_property = Calculation(calc_value, Params(ParamValue('disabled'), kwargs={'condition': ParamOption(boolean), 'expected': ParamValue(False), 'default': ParamValue(None)})) st1 = StrOption('st', '', properties=(disabled_property,)) dod = DynOptionDescription('dod', '', [boolean, st1], suffixes=Calculation(return_list)) with pytest.raises(ConfigError): cfg = Config(dod) # assert not list_sessions() def test_dyndescription_disable_suffix_root(): boolean = BoolOption('boolean', '', True) disabled_property = Calculation(calc_value, Params(ParamValue('disabled'), kwargs={'condition': ParamOption(boolean), 'expected': ParamValue(False), 'default': ParamValue(None)})) val = StrOption('val', '', ['ext1', 'ext2'], properties=(disabled_property,), multi=True) st1 = StrOption('st', '') dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(calc_value, Params(ParamOption(val, notraisepropertyerror=True))), properties=(disabled_property,)) 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} # cfg.option('boolean').value.set(False) assert cfg.value.get() == {'boolean': False} # assert not list_sessions() def test_dyndescription_disable_suffix_root_2(): boolean = BoolOption('boolean', '', False) disabled_property = Calculation(calc_value, Params(ParamValue('disabled'), kwargs={'condition': ParamOption(boolean), 'expected': ParamValue(False), 'default': ParamValue(None)})) val = StrOption('val', '', ['ext1', 'ext2'], properties=(disabled_property,), multi=True) st1 = StrOption('st', '') dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(calc_value, Params(ParamOption(val, notraisepropertyerror=True))), properties=(disabled_property,)) od1 = OptionDescription('root', 'root', [boolean, val, dod]) cfg = Config(od1) cfg.property.read_write() assert 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 not list_sessions() def test_dyndescription_disable_suffix(): boolean = BoolOption('boolean', '', True) disabled_property = Calculation(calc_value, Params(ParamValue('disabled'), kwargs={'condition': ParamOption(boolean), 'expected': ParamValue(False), 'default': ParamValue(None)})) val = StrOption('val', '', ['ext1', 'ext2'], properties=(disabled_property,), multi=True) st1 = StrOption('st', '') dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(calc_value, Params(ParamOption(val, notraisepropertyerror=True))), properties=(disabled_property,)) od = OptionDescription('root', 'root', [boolean, val, dod]) 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} # cfg.option('root.boolean').value.set(False) assert cfg.value.get() == {'root.boolean': False} # assert not list_sessions() def test_requires_dyndescription(): boolean = BoolOption('boolean', '', True) disabled_property = Calculation(calc_value, Params(ParamValue('disabled'), kwargs={'condition': ParamOption(boolean, raisepropertyerror=True), 'expected': ParamValue(False), 'default': ParamValue(None)})) st1 = StrOption('st', '', properties=(disabled_property,)) dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(return_list)) od1 = OptionDescription('od', '', [dod]) od2 = OptionDescription('od', '', [od1, boolean]) cfg = Config(od2) cfg.property.read_write() assert cfg.option('od.dodval1.st').value.get() is None assert cfg.option('od.dodval2.st').value.get() is None # cfg.option('boolean').value.set(False) props = [] try: cfg.option('od.dodval1.st').value.get() except PropertiesOptionError as err: props = err.proptype assert frozenset(props) == frozenset(['disabled']) props = [] try: cfg.option('od.dodval2.st').value.get() except PropertiesOptionError as err: props = err.proptype assert frozenset(props) == frozenset(['disabled']) # cfg.option('boolean').value.set(True) assert cfg.option('od.dodval1.st').value.get() is None assert cfg.option('od.dodval2.st').value.get() is None #transitive cfg.option('boolean').property.add('disabled') props = [] try: cfg.option('od.dodval1.st').value.get() except PropertiesOptionError as err: props = err.proptype assert frozenset(props) == frozenset(['disabled']) props = [] try: cfg.option('od.dodval2.st').value.get() except PropertiesOptionError as err: props = err.proptype assert frozenset(props) == frozenset(['disabled']) # assert not list_sessions() def test_requires_dyndescription_boolean(): boolean1 = BoolOption('boolean1', '', True) disabled_property = Calculation(calc_value, Params(ParamValue('disabled'), kwargs={'condition': ParamOption(boolean1, raisepropertyerror=True), 'expected': ParamValue(False), 'default': ParamValue(None)})) boolean = BoolOption('boolean', '', True, properties=(disabled_property,)) disabled_property = Calculation(calc_value, Params(ParamValue('disabled'), kwargs={'condition': ParamOption(boolean, raisepropertyerror=True), 'expected': ParamValue(False), 'default': ParamValue(None)})) st = StrOption('st', '', properties=(disabled_property,)) dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) od = OptionDescription('od', '', [dod]) 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} # cfg.option('boolean').value.set(False) assert 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} # cfg.option('boolean1').value.set(False) assert cfg.value.get() == {'boolean1': False} # assert not list_sessions() def test_requires_dyndescription_in_dyn(): boolean = BoolOption('boolean', '', True) disabled_property = Calculation(calc_value, Params(ParamValue('disabled'), kwargs={'condition': ParamOption(boolean, raisepropertyerror=True), 'expected': ParamValue(False), 'default': ParamValue(None)})) st = StrOption('st', '', properties=(disabled_property,)) dod = DynOptionDescription('dod', '', [boolean, st], suffixes=Calculation(return_list)) od = OptionDescription('od', '', [dod]) od2 = OptionDescription('od', '', [od]) cfg = Config(od2) cfg.property.read_write() assert cfg.option('od.dodval1.st').value.get() is None assert cfg.option('od.dodval2.st').value.get() is None # cfg.option('od.dodval1.boolean').value.set(False) props = [] try: cfg.option('od.dodval1.st').value.get() except PropertiesOptionError as err: props = err.proptype assert props == frozenset(['disabled']) props = [] cfg.option('od.dodval2.st').value.get() # cfg.option('od.dodval1.boolean').value.set(True) assert cfg.option('od.dodval1.st').value.get() is None assert cfg.option('od.dodval2.st').value.get() is None # assert not list_sessions() def calc_value_not_same(param, condition, expected, default, suffix): if suffix == 'val1': index = 0 else: index = 1 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_dyndescription2(): boolean = BoolOption('boolean', '', True) st1 = StrOption('st', '') disabled_property = Calculation(calc_value, Params(ParamValue('disabled'), kwargs={'condition': ParamOption(boolean, raisepropertyerror=True), 'expected': ParamValue(False), 'default': ParamValue(None)})) dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(return_list), properties=(disabled_property,)) od1 = OptionDescription('od', '', [dod]) od2 = OptionDescription('od', '', [od1, boolean]) cfg = Config(od2) cfg.property.read_write() assert cfg.option('od.dodval1.st').value.get() is None assert cfg.option('od.dodval2.st').value.get() is None # cfg.option('boolean').value.set(False) props = [] try: cfg.option('od.dodval1.st').value.get() except PropertiesOptionError as err: props = err.proptype assert frozenset(props) == frozenset(['disabled']) props = [] try: cfg.option('od.dodval2.st').value.get() except PropertiesOptionError as err: props = err.proptype assert frozenset(props) == frozenset(['disabled']) # cfg.option('boolean').value.set(True) assert cfg.option('od.dodval1.st').value.get() is None assert cfg.option('od.dodval2.st').value.get() is None #transitive cfg.option('boolean').property.add('disabled') props = [] try: cfg.option('od.dodval1.st').value.get() except PropertiesOptionError as err: props = err.proptype assert frozenset(props) == frozenset(['disabled']) props = [] try: cfg.option('od.dodval2.st').value.get() except PropertiesOptionError as err: props = err.proptype assert frozenset(props) == frozenset(['disabled']) # assert not list_sessions() def test_validator_dyndescription(): val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) st = StrOption('st', '', validators=[Calculation(return_true, Params((ParamSelfOption(), ParamValue('yes'))))], default='val') dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) od = OptionDescription('od', '', [dod, val1]) od2 = OptionDescription('od', '', [od]) cfg = Config(od2) assert cfg.option('od.dodval1.st').value.get() == 'val' with pytest.raises(ValueError): cfg.option('od.dodval1.st').value.set('no') cfg.option('od.dodval1.st').value.set('val') # assert not list_sessions() def test_makedict_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') 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 not list_sessions() def test_information_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]) dod.impl_set_information('testod', 'val1') st.impl_set_information('testst', 'val2') cfg = Config(od2) cfg.information.set('testcfgod', 'val3') assert cfg.option('od.dodval1').information.get('testod') == 'val1' assert cfg.option('od.dodval2').information.get('testod') == 'val1' assert cfg.option('od.dodval1.st').information.get('testst') == 'val2' assert cfg.option('od.dodval2.st').information.get('testst') == 'val2' assert cfg.information.get('testcfgod') == 'val3' # assert not list_sessions() def test_all_dyndescription(): st = StrOption('st', '') ip = IPOption('ip', '') network = NetworkOption('network', '') netmask = NetmaskOption('netmask', '') ch = ChoiceOption('ch', '', ('val1', 'val2', 'val3')) ch1 = ChoiceOption('ch1', '', Calculation(return_list)) boo = BoolOption('boo', '') intr = IntOption('intr', '') floa = FloatOption('floa', '') uni = StrOption('uni', '') port = PortOption('port', '') broad = BroadcastOption('broad', '') domain = DomainnameOption('domain', '') email = EmailOption('email', '') url = URLOption('url', '') username = UsernameOption('username', '') filename = FilenameOption('filename', '') dod = DynOptionDescription('dod', '', [st, ip, network, netmask, ch, ch1, boo, intr, floa, uni, port, broad, domain, email, url, username, filename], suffixes=Calculation(return_list)) od1 = OptionDescription('od', '', [dod]) cfg = Config(od1) assert cfg.option('dodval1.st').value.get() is None assert cfg.option('dodval1.ip').value.get() is None assert cfg.option('dodval1.network').value.get() is None assert cfg.option('dodval1.netmask').value.get() is None assert cfg.option('dodval1.ch').value.get() is None assert cfg.option('dodval1.ch1').value.get() is None assert cfg.option('dodval1.boo').value.get() is None assert cfg.option('dodval1.intr').value.get() is None assert cfg.option('dodval1.floa').value.get() is None assert cfg.option('dodval1.uni').value.get() is None assert cfg.option('dodval1.port').value.get() is None assert cfg.option('dodval1.broad').value.get() is None assert cfg.option('dodval1.domain').value.get() is None assert cfg.option('dodval1.email').value.get() is None assert cfg.option('dodval1.url').value.get() is None assert cfg.option('dodval1.username').value.get() is None assert cfg.option('dodval1.filename').value.get() is None # cfg.option('dodval1.st').value.set("no") cfg.option('dodval1.ip').value.set("1.1.1.1") cfg.option('dodval1.network').value.set("1.1.1.0") cfg.option('dodval1.netmask').value.set("255.255.255.0") cfg.option('dodval1.ch').value.set("val1") cfg.option('dodval1.ch1').value.set("val2") cfg.option('dodval1.boo').value.set(True) cfg.option('dodval1.intr').value.set(1) cfg.option('dodval1.floa').value.set(0.1) cfg.option('dodval1.uni').value.set(u"no") cfg.option('dodval1.port').value.set('80') cfg.option('dodval1.broad').value.set("1.1.1.255") cfg.option('dodval1.domain').value.set("test.com") cfg.option('dodval1.email').value.set("test@test.com") cfg.option('dodval1.url').value.set("http://test.com") cfg.option('dodval1.username').value.set("user1") cfg.option('dodval1.filename').value.set("/tmp") assert cfg.option('dodval1.st').value.get() == "no" assert cfg.option('dodval1.ip').value.get() == "1.1.1.1" assert cfg.option('dodval1.network').value.get() == "1.1.1.0" assert cfg.option('dodval1.netmask').value.get() == "255.255.255.0" assert cfg.option('dodval1.ch').value.get() == "val1" assert cfg.option('dodval1.ch1').value.get() == "val2" assert cfg.option('dodval1.boo').value.get() is True assert cfg.option('dodval1.intr').value.get() == 1 assert cfg.option('dodval1.floa').value.get() == 0.1 assert cfg.option('dodval1.uni').value.get() == u"no" assert cfg.option('dodval1.port').value.get() == '80' assert cfg.option('dodval1.broad').value.get() == "1.1.1.255" assert cfg.option('dodval1.domain').value.get() == "test.com" assert cfg.option('dodval1.email').value.get() == "test@test.com" assert cfg.option('dodval1.url').value.get() == "http://test.com" assert cfg.option('dodval1.username').value.get() == "user1" assert cfg.option('dodval1.filename').value.get() == "/tmp" assert cfg.option('dodval2.st').value.get() is None assert cfg.option('dodval2.ip').value.get() is None assert cfg.option('dodval2.network').value.get() is None assert cfg.option('dodval2.netmask').value.get() is None assert cfg.option('dodval2.ch').value.get() is None assert cfg.option('dodval2.ch1').value.get() is None assert cfg.option('dodval2.boo').value.get() is None assert cfg.option('dodval2.intr').value.get() is None assert cfg.option('dodval2.floa').value.get() is None assert cfg.option('dodval2.uni').value.get() is None assert cfg.option('dodval2.port').value.get() is None assert cfg.option('dodval2.broad').value.get() is None assert cfg.option('dodval2.domain').value.get() is None assert cfg.option('dodval2.email').value.get() is None assert cfg.option('dodval2.url').value.get() is None assert cfg.option('dodval2.username').value.get() is None assert cfg.option('dodval2.filename').value.get() is None # 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(): 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)) dodinvalid = StrOption('dodinvalid', '') dod, dodinvalid with pytest.raises(ConflictError): OptionDescription('od', '', [dod, dodinvalid]) # assert not list_sessions() def test_invalid_subod_dyndescription(): st2 = StrOption('st2', '') od1 = OptionDescription('od1', '', [st2]) od1 with pytest.raises(ConfigError): DynOptionDescription('dod', '', [od1], suffixes=Calculation(return_list)) # assert not list_sessions() def test_invalid_subdynod_dyndescription(): st2 = StrOption('st2', '') od1 = DynOptionDescription('od1', '', [st2], suffixes=Calculation(return_list)) od1 with pytest.raises(ConfigError): DynOptionDescription('dod', '', [od1], suffixes=Calculation(return_list)) # assert not list_sessions() def test_invalid_symlink_dyndescription(): st = StrOption('st', '') st2 = SymLinkOption('st2', st) with pytest.raises(ConfigError): DynOptionDescription('dod', '', [st, st2], suffixes=Calculation(return_list)) # assert not list_sessions() def test_nocallback_dyndescription(): st = StrOption('st', '') st2 = StrOption('st2', '') with pytest.raises(TypeError): DynOptionDescription('dod', '', [st, st2]) # assert not list_sessions() def test_invalid_samevalue_dyndescription(): st1 = StrOption('st', '') dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(return_same_list)) od1 = OptionDescription('od', '', [dod]) cfg = Config(od1) with pytest.raises(ValueError): cfg.value.get() # assert not list_sessions() def test_invalid_name_dyndescription(): st1 = StrOption('st', '') dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(return_wrong_list)) od1 = OptionDescription('od', '', [dod]) cfg = Config(od1) with pytest.raises(ValueError): cfg.value.get() # 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) 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()