ConfigBag optimisation
This commit is contained in:
@ -246,7 +246,7 @@ def test_reset_cache():
|
||||
api.option('u1').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
c.cfgimpl_reset_cache(None, None, None)
|
||||
c.cfgimpl_reset_cache(None, None)
|
||||
assert 'u1' not in values._p_.get_cached()
|
||||
assert 'u1' not in settings._p_.get_cached()
|
||||
api.option('u1').value.get()
|
||||
@ -258,7 +258,7 @@ def test_reset_cache():
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
assert 'u2' in values._p_.get_cached()
|
||||
assert 'u2' in settings._p_.get_cached()
|
||||
c.cfgimpl_reset_cache(None, None, None)
|
||||
c.cfgimpl_reset_cache(None, None)
|
||||
assert 'u1' not in values._p_.get_cached()
|
||||
assert 'u1' not in settings._p_.get_cached()
|
||||
assert 'u2' not in values._p_.get_cached()
|
||||
@ -273,7 +273,7 @@ def test_reset_cache():
|
||||
# values = c.cfgimpl_get_values()
|
||||
# api.option('od1.u1').value.get()
|
||||
# assert 'od1.u1' in values._p_.get_cached()
|
||||
# c.od1.cfgimpl_reset_cache(None, None, None)
|
||||
# c.od1.cfgimpl_reset_cache(None, None)
|
||||
# assert 'od1.u1' not in values._p_.get_cached()
|
||||
|
||||
|
||||
|
@ -429,10 +429,10 @@ def test_invalid_option():
|
||||
raises(ValueError, "DomainnameOption('a', '', multi=True, default_multi=1)")
|
||||
|
||||
|
||||
def test_help():
|
||||
stro = StrOption('s', '', multi=True)
|
||||
od1 = OptionDescription('o', '', [stro])
|
||||
od2 = OptionDescription('o', '', [od1])
|
||||
cfg = Config(od2)
|
||||
api = getapi(cfg)
|
||||
api.help(_display=False, _valid=True)
|
||||
#def test_help():
|
||||
# stro = StrOption('s', '', multi=True)
|
||||
# od1 = OptionDescription('o', '', [stro])
|
||||
# od2 = OptionDescription('o', '', [od1])
|
||||
# cfg = Config(od2)
|
||||
# api = getapi(cfg)
|
||||
# api.help(_display=False, _valid=True)
|
||||
|
@ -110,8 +110,8 @@ def test_iter_on_groups():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
result = list(api.option('creole').list('optiondescription', group_type=groups.family))
|
||||
group_names = [res[0] for res in result]
|
||||
result = api.option('creole').list('optiondescription', group_type=groups.family)
|
||||
group_names = [res.option.name() for res in result]
|
||||
assert group_names == ['general', 'interface1']
|
||||
for i in api.option('creole').list('optiondescription', group_type=groups.family):
|
||||
#test StopIteration
|
||||
@ -123,13 +123,15 @@ def test_iter_on_groups_force_permissive():
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
api.permissive.set(frozenset(['hidden']))
|
||||
#result = list(config.creole.general.__iter__(force_permissive=True))
|
||||
group_names = list(api.forcepermissive.option('creole.general').list())
|
||||
result = api.forcepermissive.option('creole.general').list()
|
||||
group_names = [res.option.name() for res in result]
|
||||
ass = ['numero_etab', 'nom_machine', 'nombre_interfaces',
|
||||
'activer_proxy_client', 'mode_conteneur_actif',
|
||||
'mode_conteneur_actif2', 'serveur_ntp', 'time_zone']
|
||||
assert group_names == ass
|
||||
group_names = list(api.option('creole.general').list())
|
||||
# mode_conteneur_actif2 is not visible is not forcepermissive
|
||||
result = api.option('creole.general').list()
|
||||
group_names = [res.option.name() for res in result]
|
||||
ass.remove('mode_conteneur_actif2')
|
||||
assert group_names == ass
|
||||
|
||||
@ -139,8 +141,8 @@ def test_iter_group_on_groups_force_permissive():
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
api.permissive.set(frozenset(['hidden']))
|
||||
result = list(api.forcepermissive.option('creole').list(type='optiondescription', group_type=groups.family))
|
||||
group_names = [res[0] for res in result]
|
||||
result = api.forcepermissive.option('creole').list(type='optiondescription', group_type=groups.family)
|
||||
group_names = [res.option.name() for res in result]
|
||||
assert group_names == ['general', 'interface1', 'new']
|
||||
|
||||
|
||||
@ -149,8 +151,8 @@ def test_iter_on_groups_props():
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
api.option('creole.interface1').property.add('disabled')
|
||||
result = list(api.option('creole').list(type='optiondescription', group_type=groups.family))
|
||||
group_names = [res[0] for res in result]
|
||||
result = api.option('creole').list(type='optiondescription', group_type=groups.family)
|
||||
group_names = [res.option.name() for res in result]
|
||||
assert group_names == ['general']
|
||||
|
||||
|
||||
|
@ -796,33 +796,32 @@ def test_callback_master_and_slaves_slave_cal():
|
||||
val1 = StrOption('val1', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val3)))
|
||||
val2 = StrOption('val2', "", multi=True, callback=return_val)
|
||||
interface1 = MasterSlaves('val1', '', [val1, val2])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('rootconfig', '', [interface1, val3])
|
||||
api = getapi(Config(maconfig))
|
||||
api.property.read_write()
|
||||
#
|
||||
assert api.option('val3').value.get() == []
|
||||
assert api.option('val1.val1').value.get() == []
|
||||
#
|
||||
api.option('val1.val1').value.set(['val1'])
|
||||
api.option('val3').value.set(['val1'])
|
||||
assert api.option('val1.val1').value.get() == ['val1']
|
||||
assert api.option('val1.val2', 0).value.get() == 'val'
|
||||
#
|
||||
api.option('val1.val1').value.reset()
|
||||
api.option('val1.val2', 0).value.set('val')
|
||||
#
|
||||
api.option('val3').value.set(['val1', 'val2'])
|
||||
assert api.option('val1.val2', 0).value.get() == 'val'
|
||||
assert api.option('val1.val2', 1).value.get() == 'val'
|
||||
assert api.option('val1.val1').value.get() == ['val1', 'val2']
|
||||
# len of slave is higher than master's one
|
||||
api.option('val1.val2', 0).value.set('val1')
|
||||
api.option('val1.val2', 1).value.set('val2')
|
||||
api.option('val3').value.set(['val1'])
|
||||
# cannot remove slave's value because master is calculated
|
||||
# so raise
|
||||
if TIRAMISU_VERSION == 2:
|
||||
raises(SlaveError, "api.option('val1.val1').value.get()")
|
||||
raises(SlaveError, "api.option('val1.val2', 0).value.get()")
|
||||
else:
|
||||
assert api.option('val1.val1').value.get() == ['val1']
|
||||
raises(SlaveError, "api.option('val1.val2', 0).value.get()")
|
||||
assert api.option('val1.val1').value.get() == ['val1']
|
||||
raises(SlaveError, "api.option('val1.val2', 0).value.get()")
|
||||
#
|
||||
api.option('val3').value.set(['val1', 'val2', 'val3'])
|
||||
assert api.option('val1.val2', 0).value.get() == 'val1'
|
||||
assert api.option('val1.val2', 1).value.get() == 'val2'
|
||||
@ -1020,6 +1019,7 @@ def test_callback_hidden():
|
||||
api = getapi(Config(maconfig))
|
||||
api.property.read_write()
|
||||
raises(PropertiesOptionError, "api.option('od1.opt1').value.get()")
|
||||
# do not raise, forcepermissive
|
||||
api.option('od2.opt2').value.get()
|
||||
|
||||
|
||||
|
@ -5,7 +5,7 @@ do_autopath()
|
||||
from py.test import raises
|
||||
|
||||
try:
|
||||
from tiramisu.setting import ConfigBag
|
||||
from tiramisu.setting import OptionBag, ConfigBag
|
||||
tiramisu_version = 3
|
||||
except:
|
||||
tiramisu_version = 2
|
||||
@ -151,10 +151,12 @@ def test_slots_config():
|
||||
c = Config(od2)
|
||||
raises(AttributeError, "c.x = 1")
|
||||
raises(AttributeError, "c.cfgimpl_x = 1")
|
||||
if tiramisu_version == 2:
|
||||
sc = c.getattr('a')
|
||||
else:
|
||||
sc = c.getattr('a', None, ConfigBag(c))
|
||||
option_bag = OptionBag()
|
||||
option_bag.set_option(od2,
|
||||
'a',
|
||||
None,
|
||||
ConfigBag(c))
|
||||
sc = c.getattr('a', option_bag)
|
||||
assert isinstance(sc, SubConfig)
|
||||
raises(AttributeError, "sc.x = 1")
|
||||
raises(AttributeError, "sc.cfgimpl_x = 1")
|
||||
|
Reference in New Issue
Block a user