find in api return an api object
This commit is contained in:
@ -1074,6 +1074,7 @@ def autocheck_option_get(api, pathread, pathwrite, confread, confwrite, **kwargs
|
||||
@autocheck
|
||||
def autocheck_find(api, pathread, pathwrite, confread, confwrite, **kwargs):
|
||||
def _getoption(opt):
|
||||
opt = opt.option.get()
|
||||
if opt.impl_is_dynsymlinkoption():
|
||||
opt = opt.impl_getopt()
|
||||
return opt
|
||||
@ -1088,7 +1089,7 @@ def autocheck_find(api, pathread, pathwrite, confread, confwrite, **kwargs):
|
||||
name = pathread.rsplit('.', 1)[1]
|
||||
else:
|
||||
name = pathread
|
||||
option = _getoption(api.unrestraint.option(pathread).option.get())
|
||||
option = _getoption(api.unrestraint.option(pathread))
|
||||
|
||||
def do(conf):
|
||||
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
||||
@ -1102,8 +1103,6 @@ def autocheck_find(api, pathread, pathwrite, confread, confwrite, **kwargs):
|
||||
raises(AttributeError, "api.forcepermissive.config(conf).option.find(name, first=True)")
|
||||
assert option == _getoption(api.unrestraint.config(conf).option.find(name, first=True))
|
||||
assert [option] == _getoptions(api.unrestraint.config(conf).option.find(name))
|
||||
assert pathread == api.unrestraint.config(conf).option.find(name, 'path', first=True)
|
||||
assert [pathread] == api.unrestraint.config(conf).option.find(name, 'path')
|
||||
do(confread)
|
||||
if confread != confwrite:
|
||||
do(confwrite)
|
||||
|
@ -14,8 +14,8 @@ from tiramisu.error import PropertiesOptionError
|
||||
def make_description():
|
||||
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
prop = BoolOption('prop', '', properties=('disabled',))
|
||||
prop2 = BoolOption('prop', '', properties=('hidden',))
|
||||
prop = BoolOption('prop', 'prop 1', properties=('disabled',))
|
||||
prop2 = BoolOption('prop', 'prop 2', properties=('hidden',))
|
||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||
('std', 'thunk'), 'std')
|
||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||
@ -165,96 +165,111 @@ def test_find_in_config():
|
||||
api.permissive.set(frozenset(['hidden']))
|
||||
ret = api.option.find('dummy')
|
||||
assert len(ret) == 1
|
||||
_is_same_opt(ret[0], api.option('gc.dummy').option.get())
|
||||
_is_same_opt(ret[0].option.get(), api.option('gc.dummy').option.get())
|
||||
#
|
||||
ret = api.option.find('dummy', first=True)
|
||||
ret = api.option.find('dummy', first=True).option.get()
|
||||
_is_same_opt(ret, api.option('gc.dummy').option.get())
|
||||
#
|
||||
ret = api.option.find('float')
|
||||
assert len(ret) == 2
|
||||
_is_same_opt(ret[0], api.option('gc.float').option.get())
|
||||
_is_same_opt(ret[1], api.option('float').option.get())
|
||||
_is_same_opt(ret[0].option.get(), api.option('gc.float').option.get())
|
||||
_is_same_opt(ret[1].option.get(), api.option('float').option.get())
|
||||
#
|
||||
_is_same_opt(api.option.find('bool', first=True), api.option('gc.gc2.bool').option.get())
|
||||
#_is_same_opt(conf.find_first(byname='bool', byvalue=True), conf.unwrap_from_path('bool'))
|
||||
#_is_same_opt(conf.find_first(byname='dummy'), conf.unwrap_from_path('gc.dummy'))
|
||||
#_is_same_opt(conf.find_first(byname='float'), conf.unwrap_from_path('gc.float'))
|
||||
_is_same_opt(api.option.find('bool', first=True).option.get(), api.option('gc.gc2.bool').option.get())
|
||||
_is_same_opt(api.option.find('bool', value=True, first=True).option.get(), api.option('bool').option.get())
|
||||
_is_same_opt(api.option.find('dummy', first=True).option.get(), api.option('gc.dummy').option.get())
|
||||
_is_same_opt(api.option.find('float', first=True).option.get(), api.option('gc.float').option.get())
|
||||
#FIXME cannot find an option without name
|
||||
#ret = conf.find(bytype=ChoiceOption)
|
||||
#assert len(ret) == 2
|
||||
#_is_same_opt(ret[0], conf.unwrap_from_path('gc.name'))
|
||||
#_is_same_opt(ret[1], conf.unwrap_from_path('objspace'))
|
||||
#
|
||||
#_is_same_opt(conf.find_first(bytype=ChoiceOption), conf.unwrap_from_path('gc.name'))
|
||||
#ret = conf.find(byvalue='ref')
|
||||
#assert len(ret) == 1
|
||||
#_is_same_opt(ret[0], conf.unwrap_from_path('gc.name'))
|
||||
#_is_same_opt(conf.find_first(byvalue='ref'), conf.unwrap_from_path('gc.name'))
|
||||
#ret = conf.find(byname='prop')
|
||||
#assert len(ret) == 1
|
||||
#_is_same_opt(ret[0], conf.unwrap_from_path('gc.prop'))
|
||||
#conf.read_write()
|
||||
#raises(AttributeError, "assert conf.find(byname='prop')")
|
||||
#ret = conf.find(byname='prop', check_properties=False)
|
||||
#assert len(ret) == 2
|
||||
#_is_same_opt(ret[0], conf.cfgimpl_get_description().impl_get_opt_by_path('gc.gc2.prop'))
|
||||
#_is_same_opt(ret[1], conf.unwrap_from_path('gc.prop', force_permissive=True))
|
||||
#ret = conf.find(byname='prop', force_permissive=True)
|
||||
#assert len(ret) == 1
|
||||
#_is_same_opt(ret[0], conf.unwrap_from_path('gc.prop', force_permissive=True))
|
||||
#_is_same_opt(conf.find_first(byname='prop', force_permissive=True), conf.unwrap_from_path('gc.prop', force_permissive=True))
|
||||
##assert conf.find_first(byname='prop') == conf.unwrap_from_path('gc.prop')
|
||||
## combinaison of filters
|
||||
#
|
||||
ret = api.option.find('prop')
|
||||
assert len(ret) == 1
|
||||
_is_same_opt(ret[0].option.get(), api.option('gc.prop').option.get())
|
||||
#
|
||||
api.property.read_write()
|
||||
raises(AttributeError, "assert api.option.find('prop').option.get()")
|
||||
ret = api.unrestraint.option.find(name='prop')
|
||||
assert len(ret) == 2
|
||||
_is_same_opt(ret[0].option.get(), api.unrestraint.option('gc.gc2.prop').option.get())
|
||||
_is_same_opt(ret[1].option.get(), api.forcepermissive.option('gc.prop').option.get())
|
||||
#
|
||||
ret = api.forcepermissive.option.find('prop')
|
||||
assert len(ret) == 1
|
||||
_is_same_opt(ret[0].option.get(), api.forcepermissive.option('gc.prop').option.get())
|
||||
#
|
||||
_is_same_opt(api.forcepermissive.option.find('prop', first=True).option.get(), api.forcepermissive.option('gc.prop').option.get())
|
||||
#FIXME cannot find an option without name
|
||||
# combinaison of filters
|
||||
#ret = conf.find(bytype=BoolOption, byname='dummy')
|
||||
#assert len(ret) == 1
|
||||
#_is_same_opt(ret[0], conf.unwrap_from_path('gc.dummy'))
|
||||
#_is_same_opt(conf.find_first(bytype=BoolOption, byname='dummy'), conf.unwrap_from_path('gc.dummy'))
|
||||
#ret = conf.find(byvalue=False, byname='dummy')
|
||||
#assert len(ret) == 1
|
||||
#_is_same_opt(ret[0], conf.unwrap_from_path('gc.dummy'))
|
||||
#_is_same_opt(conf.find_first(byvalue=False, byname='dummy'), conf.unwrap_from_path('gc.dummy'))
|
||||
##subconfig
|
||||
#ret = conf.gc.find(byname='dummy')
|
||||
#assert len(ret) == 1
|
||||
#_is_same_opt(ret[0], conf.unwrap_from_path('gc.dummy'))
|
||||
#ret = conf.gc.find(byname='float')
|
||||
#assert len(ret) == 1
|
||||
#_is_same_opt(ret[0], conf.unwrap_from_path('gc.float'))
|
||||
#ret = conf.gc.find(byname='bool')
|
||||
#assert len(ret) == 1
|
||||
#_is_same_opt(ret[0], conf.unwrap_from_path('gc.gc2.bool'))
|
||||
#_is_same_opt(conf.gc.find_first(byname='bool', byvalue=False), conf.unwrap_from_path('gc.gc2.bool'))
|
||||
#raises(AttributeError, "assert conf.gc.find_first(byname='bool', byvalue=True)")
|
||||
#raises(AttributeError, "conf.gc.find(byname='wantref').first()")
|
||||
#ret = conf.gc.find(byname='prop', check_properties=False)
|
||||
#assert len(ret) == 2
|
||||
#_is_same_opt(ret[0], conf.cfgimpl_get_description().impl_get_opt_by_path('gc.gc2.prop'))
|
||||
#_is_same_opt(ret[1], conf.unwrap_from_path('gc.prop', force_permissive=True))
|
||||
#conf.read_only()
|
||||
#ret = conf.gc.find(byname='prop')
|
||||
#assert len(ret) == 1
|
||||
#_is_same_opt(ret[0], conf.unwrap_from_path('gc.prop'))
|
||||
## not OptionDescription
|
||||
#raises(AttributeError, "conf.find_first(byname='gc')")
|
||||
#raises(AttributeError, "conf.gc.find_first(byname='gc2')")
|
||||
#raises(ValueError, "conf.find(byname='bool', type_='unknown')")
|
||||
#
|
||||
ret = api.option.find('dummy', value=False)
|
||||
assert len(ret) == 1
|
||||
_is_same_opt(ret[0].option.get(), api.option('gc.dummy').option.get())
|
||||
#
|
||||
_is_same_opt(api.option.find('dummy', value=False, first=True).option.get(), api.option('gc.dummy').option.get())
|
||||
#subconfig
|
||||
ret = api.option('gc').find('dummy')
|
||||
assert len(ret) == 1
|
||||
_is_same_opt(ret[0].option.get(), api.option('gc.dummy').option.get())
|
||||
#
|
||||
ret = api.option('gc').find('float')
|
||||
assert len(ret) == 1
|
||||
_is_same_opt(ret[0].option.get(), api.option('gc.float').option.get())
|
||||
#
|
||||
ret = api.option('gc').find('bool')
|
||||
assert len(ret) == 1
|
||||
_is_same_opt(ret[0].option.get(), api.option('gc.gc2.bool').option.get())
|
||||
_is_same_opt(api.option('gc').find('bool', value=False, first=True).option.get(), api.option('gc.gc2.bool').option.get())
|
||||
#
|
||||
raises(AttributeError, "assert api.option('gc').find('bool', value=True, first=True).option.get()")
|
||||
#
|
||||
raises(AttributeError, "api.option('gc').find('wantref').option.get()")
|
||||
#
|
||||
ret = api.unrestraint.option('gc').find('prop')
|
||||
assert len(ret) == 2
|
||||
_is_same_opt(ret[0].option.get(), api.unrestraint.option('gc.gc2.prop').option.get())
|
||||
_is_same_opt(ret[1].option.get(), api.forcepermissive.option('gc.prop').option.get())
|
||||
#
|
||||
api.property.read_only()
|
||||
ret = api.option('gc').find('prop')
|
||||
assert len(ret) == 1
|
||||
_is_same_opt(ret[0].option.get(), api.option('gc.prop').option.get())
|
||||
# not OptionDescription
|
||||
raises(AttributeError, "api.option.find('gc', first=True)")
|
||||
raises(AttributeError, "api.option.find('gc2', first=True)")
|
||||
|
||||
|
||||
#def test_find_multi():
|
||||
# b = BoolOption('bool', '', multi=True)
|
||||
# o = OptionDescription('od', '', [b])
|
||||
# conf = Config(o)
|
||||
# raises(AttributeError, "conf.find(byvalue=True)")
|
||||
# raises(AttributeError, "conf.find_first(byvalue=True)")
|
||||
# conf.bool.append(False)
|
||||
# raises(AttributeError, "conf.find(byvalue=True)")
|
||||
# raises(AttributeError, "conf.find_first(byvalue=True)")
|
||||
# conf.bool.append(False)
|
||||
# raises(AttributeError, "conf.find(byvalue=True)")
|
||||
# raises(AttributeError, "conf.find_first(byvalue=True)")
|
||||
# conf.bool.append(True)
|
||||
# ret = conf.find(byvalue=True)
|
||||
# assert len(ret) == 1
|
||||
# _is_same_opt(ret[0], b)
|
||||
# _is_same_opt(conf.find_first(byvalue=True), b)
|
||||
def test_find_multi():
|
||||
b = BoolOption('bool', '', multi=True)
|
||||
o = OptionDescription('od', '', [b])
|
||||
conf = Config(o)
|
||||
api = getapi(conf)
|
||||
#
|
||||
raises(AttributeError, "api.option.find('bool', value=True)")
|
||||
raises(AttributeError, "api.option.find('bool', value=True, first=True)")
|
||||
api.option('bool').value.set([False])
|
||||
raises(AttributeError, "api.option.find('bool', value=True)")
|
||||
raises(AttributeError, "api.option.find('bool', value=True, first=True)")
|
||||
api.option('bool').value.set([False, False])
|
||||
raises(AttributeError, "api.option.find('bool', value=True)")
|
||||
raises(AttributeError, "api.option.find('bool', value=True, first=True)")
|
||||
api.option('bool').value.set([False, False, True])
|
||||
ret = api.option.find('bool', value=True)
|
||||
assert len(ret) == 1
|
||||
_is_same_opt(ret[0].option.get(), b)
|
||||
_is_same_opt(api.option.find('bool', value=True, first=True).option.get(), b)
|
||||
|
||||
|
||||
def test_does_not_find_in_config():
|
||||
|
@ -36,7 +36,7 @@ def return_list(val=None, suffix=None):
|
||||
return ['val1', 'val2']
|
||||
|
||||
|
||||
def return_same_list(suffix):
|
||||
def return_same_list(*args, **kwargs):
|
||||
return ['val1', 'val1']
|
||||
|
||||
|
||||
@ -48,6 +48,10 @@ 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], callback=return_list)
|
||||
@ -66,6 +70,15 @@ def test_build_dyndescription_raise():
|
||||
raises(ConfigError, "api.option.make_dict()")
|
||||
|
||||
|
||||
def test_build_dyndescription_not_list():
|
||||
st1 = StrOption('st', '')
|
||||
dod = DynOptionDescription('dod', '', [st1], callback=return_str)
|
||||
od1 = OptionDescription('od', '', [dod])
|
||||
cfg = Config(od1)
|
||||
api = getapi(cfg)
|
||||
raises(ValueError, "api.option.make_dict()")
|
||||
|
||||
|
||||
def test_subpath_dyndescription():
|
||||
st1 = StrOption('st', '')
|
||||
dod = DynOptionDescription('dod', '', [st1], callback=return_list)
|
||||
@ -492,9 +505,7 @@ def test_requires_dyndescription():
|
||||
assert api.option('od.dodval1.stval1').value.get() is None
|
||||
assert api.option('od.dodval2.stval2').value.get() is None
|
||||
#
|
||||
print('-----------------')
|
||||
api.option('boolean').value.set(False)
|
||||
print('-----------------')
|
||||
props = []
|
||||
try:
|
||||
api.option('od.dodval1.stval1').value.get()
|
||||
@ -608,8 +619,8 @@ def test_find_dyndescription_context():
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
api = getapi(Config(od2))
|
||||
api.option('od.dodval1.stval1').value.set('yes')
|
||||
assert api.option.find('stval1', type='value', first=True) == "yes"
|
||||
assert isinstance(api.option.find('stval1', type='option', first=True), DynSymLinkOption)
|
||||
assert api.option.find('stval1', first=True).value.get() == "yes"
|
||||
assert isinstance(api.option.find('stval1', first=True).option.get(), DynSymLinkOption)
|
||||
#assert api.option.find(bytype=StrOption, type='path') == ['od.dodval1.stval1', 'od.dodval2.stval2', 'od.val1']
|
||||
#opts = api.option.find(byvalue='yes')
|
||||
#assert len(opts) == 1
|
||||
@ -1185,7 +1196,7 @@ def test_invalid_samevalue_dyndescription():
|
||||
od1 = OptionDescription('od', '', [dod])
|
||||
cfg = Config(od1)
|
||||
api = getapi(cfg)
|
||||
raises(ConfigError, "api.option.make_dict()")
|
||||
raises(ValueError, "api.option.make_dict()")
|
||||
|
||||
|
||||
def test_invalid_name_dyndescription():
|
||||
|
@ -52,7 +52,7 @@ def test_base_config():
|
||||
api.property.read_write()
|
||||
assert api.option('creole.general.activer_proxy_client').value.get() is False
|
||||
assert api.option('creole.general.nom_machine').value.get() == "eoleng"
|
||||
assert api.option.find('nom_machine', type='value', first=True) == "eoleng"
|
||||
assert api.option.find('nom_machine', first=True).value.get() == "eoleng"
|
||||
result = {'general.numero_etab': None, 'general.nombre_interfaces': 1,
|
||||
'general.serveur_ntp': [], 'interface1.ip_admin_eth0.ip_admin_eth0': None,
|
||||
'general.mode_conteneur_actif': False, 'general.time_zone': 'Paris',
|
||||
|
@ -126,8 +126,10 @@ def test_contexts():
|
||||
|
||||
def test_find():
|
||||
api = make_metaconfig()
|
||||
assert [1] == api.option.find('i2', type='value')
|
||||
assert 1 == api.option.find('i2', type='value', first=True)
|
||||
ret = api.option.find('i2')
|
||||
assert len(ret) == 1
|
||||
assert 1 == ret[0].value.get()
|
||||
assert 1 == api.option.find('i2', first=True).value.get()
|
||||
assert api.option.make_dict() == {'od1.i4': 2, 'od1.i1': None, 'od1.i3': None,
|
||||
'od1.i2': 1, 'od1.i5': [2]}
|
||||
|
||||
@ -203,14 +205,14 @@ def test_meta_meta_set():
|
||||
conf1 = meta.getconfig('conf1')
|
||||
conf2 = meta.getconfig('conf2')
|
||||
assert api.config('meta.conf1').option('od1.i1').value.get() == api.config('meta.conf2').option('od1.i1').value.get() == 7
|
||||
assert [conf1, conf2] == api.config.find('i1', byvalue=7, first=True).cfgimpl_get_children()
|
||||
assert [conf1, conf2] == api.config.find('i1', value=7, first=True).cfgimpl_get_children()
|
||||
api.config('meta.conf1').option('od1.i1').value.set(8)
|
||||
assert [conf1, conf2] == api.config.find('i1', first=True).cfgimpl_get_children()
|
||||
assert [conf2] == api.config.find('i1', byvalue=7, first=True).cfgimpl_get_children()
|
||||
assert [conf1] == api.config.find('i1', byvalue=8, first=True).cfgimpl_get_children()
|
||||
assert [conf1, conf2] == api.config.find('i5', byvalue=2, first=True).cfgimpl_get_children()
|
||||
raises(AttributeError, "api.config.find('i1', byvalue=10, first=True)")
|
||||
raises(AttributeError, "api.config.find('not', byvalue=10, first=True)")
|
||||
assert [conf2] == api.config.find('i1', value=7, first=True).cfgimpl_get_children()
|
||||
assert [conf1] == api.config.find('i1', value=8, first=True).cfgimpl_get_children()
|
||||
assert [conf1, conf2] == api.config.find('i5', value=2, first=True).cfgimpl_get_children()
|
||||
raises(AttributeError, "api.config.find('i1', value=10, first=True)")
|
||||
raises(AttributeError, "api.config.find('not', value=10, first=True)")
|
||||
raises(AttributeError, "api.config.find('i6', first=True)")
|
||||
raises(ValueError, "api.value.set('od1.i6', 7, only_config=True, force_default=True)")
|
||||
raises(ValueError, "api.value.set('od1.i6', 7, only_config=True, force_default_if_same=True)")
|
||||
|
@ -384,8 +384,8 @@ def test_access_by_get():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
raises(AttributeError, "api.option.find('idontexist')")
|
||||
assert api.option.find('wantref', type='value', first=True) is False
|
||||
assert api.option.find('dummy', type='value', first=True) is False
|
||||
assert api.option.find('wantref', first=True).value.get() is False
|
||||
assert api.option.find('dummy', first=True).value.get() is False
|
||||
|
||||
|
||||
def test_access_by_get_whith_hide():
|
||||
@ -398,7 +398,7 @@ def test_access_by_get_whith_hide():
|
||||
BoolOption("d1", "")])
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
raises(AttributeError, "api.option.find('b1', type='value')")
|
||||
raises(AttributeError, "api.option.find('b1').value.get()")
|
||||
|
||||
|
||||
def test_append_properties():
|
||||
|
@ -35,6 +35,24 @@ def test_symlink_option():
|
||||
assert api.option('c').value.get() is False
|
||||
|
||||
|
||||
def test_symlink_assign_option():
|
||||
boolopt = BoolOption("b", "", default=False)
|
||||
linkopt = SymLinkOption("c", boolopt)
|
||||
descr = OptionDescription("opt", "",
|
||||
[linkopt, OptionDescription("s1", "", [boolopt])])
|
||||
api = getapi(Config(descr))
|
||||
raises(ConfigError, "api.option('c').value.set(True)")
|
||||
|
||||
|
||||
def test_symlink_del_option():
|
||||
boolopt = BoolOption("b", "", default=False)
|
||||
linkopt = SymLinkOption("c", boolopt)
|
||||
descr = OptionDescription("opt", "",
|
||||
[linkopt, OptionDescription("s1", "", [boolopt])])
|
||||
api = getapi(Config(descr))
|
||||
raises(TypeError, "api.option('c').value.reset()")
|
||||
|
||||
|
||||
def test_symlink_getproperties():
|
||||
boolopt = BoolOption('b', '', default=True, properties=('test',))
|
||||
linkopt = SymLinkOption("c", boolopt)
|
||||
|
Reference in New Issue
Block a user