valid child type for Mix|MetaConfig
This commit is contained in:
parent
f83937a143
commit
c1eed3ad0a
|
@ -1,8 +1,7 @@
|
|||
from py.test import raises
|
||||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
|
||||
from py.test import raises
|
||||
|
||||
from tiramisu.setting import groups, owners
|
||||
from tiramisu import IntOption, StrOption, NetworkOption, NetmaskOption, \
|
||||
OptionDescription, MasterSlaves, Config, GroupConfig, MetaConfig, \
|
||||
|
|
|
@ -90,6 +90,15 @@ def make_mixconfig(double=False):
|
|||
return mix
|
||||
|
||||
|
||||
def test_mix_not_group():
|
||||
i1 = IntOption('i1', '')
|
||||
od1 = OptionDescription('od1', '', [i1])
|
||||
od2 = OptionDescription('od2', '', [od1])
|
||||
conf1 = Config(od2, session_id='conf1')
|
||||
grp = GroupConfig([conf1])
|
||||
raises(TypeError, "MixConfig(od2, [grp])")
|
||||
|
||||
|
||||
def test_unknown_config():
|
||||
mix = make_mixconfig()
|
||||
raises(ConfigError, "mix.config('unknown')")
|
||||
|
@ -271,63 +280,6 @@ def test_mix_mix_set():
|
|||
raises(ValueError, "mix.value.set('od1.i6', 7, only_config=True, force_dont_change_value=True)")
|
||||
|
||||
|
||||
def test_not_mix():
|
||||
i1 = IntOption('i1', '')
|
||||
od1 = OptionDescription('od1', '', [i1])
|
||||
od2 = OptionDescription('od2', '', [od1])
|
||||
conf1 = Config(od2, session_id='conf1')
|
||||
conf2 = Config(od2, session_id='conf2')
|
||||
conf3 = Config(od2)
|
||||
conf4 = Config(od2, session_id='conf4')
|
||||
raises(TypeError, "GroupConfig(conf1)")
|
||||
#same name
|
||||
#raises(ConflictError, "GroupConfig([conf2, conf4], session_id='conf2')")
|
||||
raises(ConflictError, "GroupConfig([conf2, conf2], session_id='conf8')")
|
||||
grp = GroupConfig([conf1, conf2])
|
||||
raises(APIError, "grp.option('od1.i1').value.get()")
|
||||
conf1, conf2 = grp.config.list()
|
||||
errors = grp.value.set('od1.i1', 7)
|
||||
assert len(errors) == 0
|
||||
assert grp.config('conf1').option('od1.i1').value.get() == grp.config('conf2').option('od1.i1').value.get() == 7
|
||||
assert grp.config('conf1').option('od1.i1').owner.get() is grp.config('conf2').option('od1.i1').owner.get() is owners.user
|
||||
grp.option('od1.i1').value.reset()
|
||||
assert grp.config('conf1').option('od1.i1').owner.get() is grp.config('conf2').option('od1.i1').owner.get() is owners.default
|
||||
|
||||
|
||||
def test_group_find_firsts():
|
||||
i1 = IntOption('i1', '')
|
||||
od1 = OptionDescription('od1', '', [i1])
|
||||
od2 = OptionDescription('od2', '', [od1])
|
||||
conf1 = Config(od2, session_id='conf1')
|
||||
conf2 = Config(od2, session_id='conf2')
|
||||
grp = GroupConfig([conf1, conf2])
|
||||
itr = grp.config.find('i1').config.list()
|
||||
conf1._config_bag.context == next(itr)._config_bag.context
|
||||
conf2._config_bag.context == next(itr)._config_bag.context
|
||||
try:
|
||||
next(itr)
|
||||
except StopIteration:
|
||||
pass
|
||||
except:
|
||||
raise Exception('no')
|
||||
else:
|
||||
raise Exception('no')
|
||||
|
||||
|
||||
def test_group_group():
|
||||
i1 = IntOption('i1', '')
|
||||
od1 = OptionDescription('od1', '', [i1])
|
||||
od2 = OptionDescription('od2', '', [od1])
|
||||
conf1 = Config(od2, session_id='conf9')
|
||||
conf2 = Config(od2, session_id='conf10')
|
||||
grp = GroupConfig([conf1, conf2], 'grp')
|
||||
grp2 = GroupConfig([grp])
|
||||
errors = grp2.value.set('od1.i1', 2)
|
||||
assert len(errors) == 0
|
||||
assert grp2.config('grp.conf9').option('od1.i1').value.get() == 2
|
||||
assert grp2.config('grp.conf9').option('od1.i1').owner.get() is owners.user
|
||||
|
||||
|
||||
def test_mix_unconsistent():
|
||||
i1 = IntOption('i1', '')
|
||||
i2 = IntOption('i2', '', default=1)
|
||||
|
|
|
@ -980,6 +980,8 @@ class KernelMixConfig(KernelGroupConfig):
|
|||
"should be config, not {}"
|
||||
).format(self.impl_type,
|
||||
type(child)))
|
||||
if not isinstance(child, (KernelConfig, KernelMixConfig)):
|
||||
raise TypeError(_("child must be a Config, MixConfig or MetaConfig"))
|
||||
if child.cfgimpl_get_meta() is not None:
|
||||
raise ValueError(_("child has already a {}config's").format(self.impl_type))
|
||||
child._impl_meta = weakref.ref(self)
|
||||
|
@ -1193,6 +1195,8 @@ class KernelMetaConfig(KernelMixConfig):
|
|||
"should be config, not {}"
|
||||
).format(self.impl_type,
|
||||
type(child)))
|
||||
if not isinstance(child, (KernelConfig, KernelMetaConfig)):
|
||||
raise TypeError(_("child must be a Config or MetaConfig"))
|
||||
if descr is None:
|
||||
descr = child.cfgimpl_get_description()
|
||||
elif descr is not child.cfgimpl_get_description():
|
||||
|
|
Loading…
Reference in New Issue