force_metaconfig_on_freeze in option (not in config)
This commit is contained in:
parent
b5497ab517
commit
9812975aa7
@ -14,6 +14,7 @@ def teardown_function(function):
|
||||
assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
|
||||
|
||||
|
||||
owners.addowner('config')
|
||||
owners.addowner('meta1')
|
||||
owners.addowner('meta2')
|
||||
|
||||
@ -975,10 +976,49 @@ def test_meta_properties_meta_set_value():
|
||||
|
||||
|
||||
def test_metaconfig_force_metaconfig_on_freeze():
|
||||
dummy1 = StrOption('dummy1', 'doc dummy', default='default', properties=('force_metaconfig_on_freeze',))
|
||||
group = OptionDescription('group', '', [dummy1])
|
||||
config = Config(group, session_id='config')
|
||||
config.owner.set(owners.config)
|
||||
meta1 = MetaConfig([config], session_id='meta1')
|
||||
meta1.owner.set(owners.meta1)
|
||||
meta2 = MetaConfig([meta1], session_id='meta2')
|
||||
meta2.owner.set(owners.meta2)
|
||||
config.property.read_write()
|
||||
|
||||
config.option('dummy1').property.add('frozen')
|
||||
#
|
||||
assert config.option('dummy1').value.get() == 'default'
|
||||
assert config.option('dummy1').owner.get() == 'default'
|
||||
#
|
||||
meta2.option('dummy1').value.set('meta2')
|
||||
#
|
||||
assert config.option('dummy1').value.get() == 'meta2'
|
||||
assert config.option('dummy1').owner.get() == 'meta2'
|
||||
#
|
||||
config.option('dummy1').property.pop('frozen')
|
||||
config.option('dummy1').value.set('config')
|
||||
config.option('dummy1').property.add('frozen')
|
||||
#
|
||||
assert config.option('dummy1').value.get() == 'meta2'
|
||||
assert config.option('dummy1').owner.get() == 'meta2'
|
||||
#
|
||||
meta1.option('dummy1').value.set('meta1')
|
||||
#
|
||||
assert config.option('dummy1').value.get() == 'meta1'
|
||||
assert config.option('dummy1').owner.get() == 'meta1'
|
||||
#
|
||||
config.option('dummy1').property.pop('frozen')
|
||||
assert config.option('dummy1').value.get() == 'config'
|
||||
assert config.option('dummy1').owner.get() == 'config'
|
||||
|
||||
|
||||
def test_metaconfig_force_metaconfig_on_freeze_option():
|
||||
dummy1 = StrOption('dummy1', 'doc dummy', default='default')
|
||||
dummy2 = StrOption('dummy2', 'doc dummy', default='default', properties=('force_default_on_freeze',))
|
||||
group = OptionDescription('group', '', [dummy1, dummy2])
|
||||
config = Config(group)
|
||||
config = Config(group, session_id='config')
|
||||
config.owner.set(owners.config)
|
||||
meta1 = MetaConfig([config], session_id='meta1')
|
||||
meta1.owner.set(owners.meta1)
|
||||
meta2 = MetaConfig([meta1], session_id='meta2')
|
||||
@ -1033,3 +1073,7 @@ def test_metaconfig_force_metaconfig_on_freeze():
|
||||
meta1.option('dummy1').property.pop('force_metaconfig_on_freeze')
|
||||
assert config.option('dummy1').value.get() == 'meta1'
|
||||
assert config.option('dummy1').owner.get() == 'meta1'
|
||||
#
|
||||
config.option('dummy1').property.pop('frozen')
|
||||
assert config.option('dummy1').value.get() == 'config'
|
||||
assert config.option('dummy1').owner.get() == 'config'
|
||||
|
@ -93,6 +93,20 @@ class Values(object):
|
||||
# and return it
|
||||
return value
|
||||
|
||||
def force_to_metaconfig(self, option_bag):
|
||||
# force_metaconfig_on_freeze in config => to metaconfig
|
||||
# force_metaconfig_on_freeze in option + config is kernelconfig => to metaconfig
|
||||
settings = option_bag.config_bag.context.cfgimpl_get_settings()
|
||||
if 'force_metaconfig_on_freeze' in option_bag.properties:
|
||||
settings = option_bag.config_bag.context.cfgimpl_get_settings()
|
||||
if 'force_metaconfig_on_freeze' in option_bag.option.impl_getproperties() and \
|
||||
not settings._p_.getproperties(option_bag.path, frozenset()):
|
||||
# if force_metaconfig_on_freeze is only in option (not in config)
|
||||
return option_bag.config_bag.context.impl_type == 'config'
|
||||
else:
|
||||
return True
|
||||
return False
|
||||
|
||||
def getvalue(self,
|
||||
option_bag):
|
||||
"""actually retrieves the value
|
||||
@ -116,10 +130,7 @@ class Values(object):
|
||||
with_value=True)
|
||||
if owner != owners.default and \
|
||||
not ('frozen' in option_bag.properties and 'force_default_on_freeze' in option_bag.properties) and \
|
||||
not ('frozen' in option_bag.properties and 'force_metaconfig_on_freeze' in option_bag.properties):
|
||||
# if a value is store in storage, check if not frozen + force_default_on_freeze
|
||||
# if frozen + force_default_on_freeze => force default value
|
||||
# if frozen + force_metaconfig_on_freeze => force value of metaconfig
|
||||
not ('frozen' in option_bag.properties and self.force_to_metaconfig(option_bag)):
|
||||
return value
|
||||
return self.getdefaultvalue(option_bag)
|
||||
|
||||
@ -333,7 +344,7 @@ class Values(object):
|
||||
# hasn't force_metaconfig_on_freeze properties
|
||||
ori_properties = doption_bag.properties
|
||||
del doption_bag.properties
|
||||
if 'force_metaconfig_on_freeze' not in doption_bag.properties:
|
||||
if not self.force_to_metaconfig(doption_bag):
|
||||
doption_bag.properties = ori_properties - {'force_metaconfig_on_freeze'}
|
||||
else:
|
||||
doption_bag.properties = ori_properties
|
||||
@ -390,7 +401,7 @@ class Values(object):
|
||||
owners.default,
|
||||
index=option_bag.index)
|
||||
if validate_meta is not False and (owner is owners.default or \
|
||||
'force_metaconfig_on_freeze' in option_bag.properties):
|
||||
'frozen' in option_bag.properties and 'force_metaconfig_on_freeze' in option_bag.properties):
|
||||
moption_bag = self._get_meta(option_bag)
|
||||
if moption_bag:
|
||||
owner = moption_bag.config_bag.context.cfgimpl_get_values().getowner(moption_bag,
|
||||
|
Loading…
Reference in New Issue
Block a user