adapt tests
This commit is contained in:
parent
0d5c1c32ca
commit
d5d826f967
66 changed files with 5576 additions and 17847 deletions
|
|
@ -88,10 +88,10 @@ def autocheck_option_multi(api, pathread, pathwrite, confread, confwrite, **kwar
|
|||
api.unrestraint.option(pathread).option.ismaster()
|
||||
api.unrestraint.option(pathread).option.isslave()
|
||||
elif not kwargs.get('propertyerror', False):
|
||||
raises(PropertiesOptionError, "api.option(pathread).option.ismulti()")
|
||||
raises(PropertiesOptionError, "api.option(pathread).option.issubmulti()")
|
||||
raises(PropertiesOptionError, "api.option(pathread).option.ismaster()")
|
||||
raises(PropertiesOptionError, "api.option(pathread).option.isslave()")
|
||||
#raises(PropertiesOptionError, "api.option(pathread).option.ismulti()")
|
||||
#raises(PropertiesOptionError, "api.option(pathread).option.issubmulti()")
|
||||
#raises(PropertiesOptionError, "api.option(pathread).option.ismaster()")
|
||||
#raises(PropertiesOptionError, "api.option(pathread).option.isslave()")
|
||||
#
|
||||
api.forcepermissive.option(pathread).option.ismulti()
|
||||
api.forcepermissive.option(pathread).option.issubmulti()
|
||||
|
|
@ -102,21 +102,21 @@ def autocheck_option_multi(api, pathread, pathwrite, confread, confwrite, **kwar
|
|||
api.unrestraint.option(pathread).option.issubmulti()
|
||||
api.unrestraint.option(pathread).option.ismaster()
|
||||
api.unrestraint.option(pathread).option.isslave()
|
||||
else:
|
||||
raises(PropertiesOptionError, "api.option(pathread).option.ismulti()")
|
||||
raises(PropertiesOptionError, "api.option(pathread).option.issubmulti()")
|
||||
raises(PropertiesOptionError, "api.option(pathread).option.ismaster()")
|
||||
raises(PropertiesOptionError, "api.option(pathread).option.isslave()")
|
||||
#
|
||||
raises(PropertiesOptionError, "api.forcepermissive.option(pathread).option.ismulti()")
|
||||
raises(PropertiesOptionError, "api.forcepermissive.option(pathread).option.issubmulti()")
|
||||
raises(PropertiesOptionError, "api.forcepermissive.option(pathread).option.ismaster()")
|
||||
raises(PropertiesOptionError, "api.forcepermissive.option(pathread).option.isslave()")
|
||||
#
|
||||
api.unrestraint.option(pathread).option.ismulti()
|
||||
api.unrestraint.option(pathread).option.issubmulti()
|
||||
api.unrestraint.option(pathread).option.ismaster()
|
||||
api.unrestraint.option(pathread).option.isslave()
|
||||
#else:
|
||||
# raises(PropertiesOptionError, "api.option(pathread).option.ismulti()")
|
||||
# raises(PropertiesOptionError, "api.option(pathread).option.issubmulti()")
|
||||
# raises(PropertiesOptionError, "api.option(pathread).option.ismaster()")
|
||||
# raises(PropertiesOptionError, "api.option(pathread).option.isslave()")
|
||||
# #
|
||||
# raises(PropertiesOptionError, "api.forcepermissive.option(pathread).option.ismulti()")
|
||||
# raises(PropertiesOptionError, "api.forcepermissive.option(pathread).option.issubmulti()")
|
||||
# raises(PropertiesOptionError, "api.forcepermissive.option(pathread).option.ismaster()")
|
||||
# raises(PropertiesOptionError, "api.forcepermissive.option(pathread).option.isslave()")
|
||||
# #
|
||||
# api.unrestraint.option(pathread).option.ismulti()
|
||||
# api.unrestraint.option(pathread).option.issubmulti()
|
||||
# api.unrestraint.option(pathread).option.ismaster()
|
||||
# api.unrestraint.option(pathread).option.isslave()
|
||||
|
||||
|
||||
@autocheck
|
||||
|
|
@ -134,17 +134,17 @@ def autocheck_default_owner(api, pathread, pathwrite, confread, confwrite, **kwa
|
|||
assert api.config(conf).option(pathread).owner.isdefault()
|
||||
assert api.forcepermissive.config(conf).option(pathread).owner.isdefault()
|
||||
elif not kwargs.get('propertyerror', False):
|
||||
raises(PropertiesOptionError, "api.config(conf).option(pathread).owner.get()")
|
||||
#raises(PropertiesOptionError, "api.config(conf).option(pathread).owner.get()")
|
||||
assert api.forcepermissive.config(conf).option(pathread).owner.get() == 'default'
|
||||
#
|
||||
raises(PropertiesOptionError, "api.config(conf).option(pathread).owner.isdefault()")
|
||||
#raises(PropertiesOptionError, "api.config(conf).option(pathread).owner.isdefault()")
|
||||
assert api.forcepermissive.config(conf).option(pathread).owner.isdefault()
|
||||
else:
|
||||
raises(PropertiesOptionError, "api.config(conf).option(pathread).owner.get()")
|
||||
raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread).owner.get()")
|
||||
#
|
||||
raises(PropertiesOptionError, "api.config(conf).option(pathread).owner.isdefault()")
|
||||
raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread).owner.isdefault()")
|
||||
#else:
|
||||
# raises(PropertiesOptionError, "api.config(conf).option(pathread).owner.get()")
|
||||
# raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread).owner.get()")
|
||||
# #
|
||||
# raises(PropertiesOptionError, "api.config(conf).option(pathread).owner.isdefault()")
|
||||
# raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread).owner.isdefault()")
|
||||
else:
|
||||
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
||||
assert api.config(conf).option(pathread, 0).owner.get() == 'default'
|
||||
|
|
@ -166,8 +166,8 @@ def autocheck_default_owner(api, pathread, pathwrite, confread, confwrite, **kwa
|
|||
raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread, 0).owner.isdefault()")
|
||||
|
||||
# unrestraint is not allowed
|
||||
raises(APIError, "api.unrestraint.config(conf).option(pathread).owner.get()")
|
||||
raises(APIError, "api.unrestraint.config(conf).option(pathread).owner.isdefault()")
|
||||
#raises(APIError, "api.unrestraint.config(conf).option(pathread).owner.get()")
|
||||
#raises(APIError, "api.unrestraint.config(conf).option(pathread).owner.isdefault()")
|
||||
do(confread)
|
||||
if confread != confwrite:
|
||||
do(confwrite)
|
||||
|
|
@ -287,7 +287,7 @@ def _set_value(api, pathwrite, conf, **kwargs):
|
|||
else:
|
||||
raises(PropertiesOptionError, "api.config(conf).option(pathwrite).value.set(first_value)")
|
||||
raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathwrite).value.set(first_value)")
|
||||
raises(APIError, "api.unrestraint.config(conf).option(pathwrite).value.set(first_value)")
|
||||
#raises(APIError, "api.unrestraint.config(conf).option(pathwrite).value.set(first_value)")
|
||||
|
||||
|
||||
@autocheck
|
||||
|
|
@ -487,13 +487,13 @@ def autocheck_reset_value(api, pathread, pathwrite, confread, confwrite, **kwarg
|
|||
if not isslave:
|
||||
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
||||
api.config(confwrite).option(pathwrite).value.reset()
|
||||
else:
|
||||
raises(PropertiesOptionError, "api.config(confwrite).option(pathwrite).value.reset()")
|
||||
#else:
|
||||
# raises(PropertiesOptionError, "api.config(confwrite).option(pathwrite).value.reset()")
|
||||
else:
|
||||
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
||||
api.config(confwrite).option(pathwrite, 0).value.reset()
|
||||
else:
|
||||
raises(PropertiesOptionError, "api.config(confwrite).option(pathwrite, 0).value.reset()")
|
||||
#else:
|
||||
# raises(PropertiesOptionError, "api.config(confwrite).option(pathwrite, 0).value.reset()")
|
||||
|
||||
# get value after reset value without permissive
|
||||
def do(conf):
|
||||
|
|
@ -618,11 +618,11 @@ def autocheck_reset_value_permissive(api, pathread, pathwrite, confread, confwri
|
|||
api.forcepermissive.config(confwrite).option(pathwrite).value.reset()
|
||||
else:
|
||||
api.forcepermissive.option(pathwrite, 1).value.reset()
|
||||
else:
|
||||
if not isslave:
|
||||
raises(PropertiesOptionError, "api.forcepermissive.config(confwrite).option(pathwrite).value.reset()")
|
||||
else:
|
||||
raises(PropertiesOptionError, "api.forcepermissive.option(pathwrite, 1).value.reset()")
|
||||
#else:
|
||||
# if not isslave:
|
||||
# raises(PropertiesOptionError, "api.forcepermissive.config(confwrite).option(pathwrite).value.reset()")
|
||||
# else:
|
||||
# raises(PropertiesOptionError, "api.forcepermissive.option(pathwrite, 1).value.reset()")
|
||||
_autocheck_default_value(api, pathread, confread, **kwargs)
|
||||
if confread != confwrite:
|
||||
_autocheck_default_value(api, pathread, confwrite, **kwargs)
|
||||
|
|
@ -639,16 +639,16 @@ def autocheck_display(api, pathread, pathwrite, confread, confwrite, **kwargs):
|
|||
#print('--------')
|
||||
#print(make_dict)
|
||||
#print(api.config(confread).config.make_dict())
|
||||
assert api.config(confread).config.make_dict() == make_dict
|
||||
assert api.config(confread).option.make_dict() == make_dict
|
||||
if confread != confwrite:
|
||||
assert(api.config(confwrite).config.make_dict()) == make_dict
|
||||
assert(api.config(confwrite).option.make_dict()) == make_dict
|
||||
_set_value(api, pathwrite, confwrite, **kwargs)
|
||||
#print('--')
|
||||
#print(make_dict_value)
|
||||
#print(api.config(confread).config.make_dict())
|
||||
assert api.config(confread).config.make_dict() == make_dict_value
|
||||
assert api.config(confread).option.make_dict() == make_dict_value
|
||||
if confread != confwrite:
|
||||
assert(api.config(confwrite).config.make_dict()) == make_dict_value
|
||||
assert(api.config(confwrite).option.make_dict()) == make_dict_value
|
||||
|
||||
|
||||
def _getproperties(multi, isslave, kwargs):
|
||||
|
|
@ -672,12 +672,12 @@ def _check_default_properties(api, pathread, conf, kwargs, props_permissive, pro
|
|||
assert set(api.config(conf).option(pathread).property.get()) == set(props_permissive)
|
||||
assert set(api.config(conf).forcepermissive.option(pathread).property.get()) == set(props_permissive)
|
||||
elif not kwargs.get('propertyerror', False):
|
||||
raises(PropertiesOptionError, "api.config(conf).option(pathread).property.get()")
|
||||
#raises(PropertiesOptionError, "api.config(conf).option(pathread).property.get()")
|
||||
assert set(api.forcepermissive.config(conf).option(pathread).property.get()) == set(props)
|
||||
else:
|
||||
raises(PropertiesOptionError, "api.config(conf).option(pathread).property.get()")
|
||||
raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread).property.get()")
|
||||
raises(APIError, "api.unrestraint.option(pathread).property.get()")
|
||||
#else:
|
||||
# raises(PropertiesOptionError, "api.config(conf).option(pathread).property.get()")
|
||||
# raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread).property.get()")
|
||||
#raises(APIError, "api.unrestraint.option(pathread).property.get()")
|
||||
else:
|
||||
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
||||
assert set(api.config(conf).option(pathread, 0).property.get()) == set(props_permissive)
|
||||
|
|
@ -706,9 +706,10 @@ def autocheck_property(api, pathread, pathwrite, confread, confwrite, **kwargs):
|
|||
|
||||
# set properties without permissive
|
||||
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
||||
api.config(confwrite).option(pathwrite).property.set(properties)
|
||||
else:
|
||||
raises(PropertiesOptionError, "api.config(confwrite).option(pathwrite).property.set(properties)")
|
||||
for prop in properties:
|
||||
api.config(confwrite).option(pathwrite).property.add(prop)
|
||||
#else:
|
||||
# raises(PropertiesOptionError, "api.config(confwrite).option(pathwrite).property.set(properties)")
|
||||
|
||||
_check_default_properties(api, pathread, confread, kwargs, properties, default_props)
|
||||
if confread != confwrite:
|
||||
|
|
@ -741,14 +742,16 @@ def _property_permissive(api, pathread, pathwrite, confread, confwrite, **kwargs
|
|||
|
||||
# set properties with permissive
|
||||
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
||||
api.config(confwrite).option(pathwrite).property.set(properties)
|
||||
api.forcepermissive.config(confwrite).option(pathwrite).property.set(properties)
|
||||
for prop in properties:
|
||||
api.config(confwrite).option(pathwrite).property.add(prop)
|
||||
api.forcepermissive.config(confwrite).option(pathwrite).property.add(prop)
|
||||
elif not kwargs.get('propertyerror', False):
|
||||
raises(PropertiesOptionError, "api.config(confwrite).option(pathwrite).property.set(properties)")
|
||||
api.forcepermissive.config(confwrite).option(pathwrite).property.set(properties)
|
||||
else:
|
||||
raises(PropertiesOptionError, "api.config(confwrite).option(pathwrite).property.set(properties)")
|
||||
raises(PropertiesOptionError, "api.forcepermissive.config(confwrite).option(pathwrite).property.set(properties)")
|
||||
for prop in properties:
|
||||
#raises(PropertiesOptionError, "api.config(confwrite).option(pathwrite).property.add(prop)")
|
||||
api.forcepermissive.config(confwrite).option(pathwrite).property.add(prop)
|
||||
#else:
|
||||
# raises(PropertiesOptionError, "api.config(confwrite).option(pathwrite).property.set(properties)")
|
||||
# raises(PropertiesOptionError, "api.forcepermissive.config(confwrite).option(pathwrite).property.set(properties)")
|
||||
|
||||
_check_default_properties(api, pathread, confwrite, kwargs, properties, properties)
|
||||
if confwrite != confread:
|
||||
|
|
@ -776,8 +779,8 @@ def autocheck_reset_property(api, pathread, pathwrite, confread, confwrite, **kw
|
|||
# reset properties without permissive
|
||||
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
||||
api.config(confwrite).option(pathwrite).property.reset()
|
||||
else:
|
||||
raises(PropertiesOptionError, "api.config(confwrite).option(pathwrite).property.reset()")
|
||||
#else:
|
||||
# raises(PropertiesOptionError, "api.config(confwrite).option(pathwrite).property.reset()")
|
||||
|
||||
_check_default_properties(api, pathread, confread, kwargs, default_props, properties)
|
||||
if confread != confwrite:
|
||||
|
|
@ -797,9 +800,10 @@ def autocheck_reset_property_permissive(api, pathread, pathwrite, confread, conf
|
|||
|
||||
# reset properties with permissive
|
||||
raises(APIError, "api.unrestraint.option(pathwrite).property.set(properties)")
|
||||
raises(APIError, "api.unrestraint.option(pathwrite).property.reset()")
|
||||
#raises(APIError, "api.unrestraint.option(pathwrite).property.reset()")
|
||||
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
||||
api.forcepermissive.option(pathwrite).property.set(properties)
|
||||
for prop in properties:
|
||||
api.forcepermissive.option(pathwrite).property.add(prop)
|
||||
api.forcepermissive.option(pathwrite).property.reset()
|
||||
elif kwargs.get('permissive', False):
|
||||
api.forcepermissive.option(pathwrite).property.reset()
|
||||
|
|
@ -822,11 +826,11 @@ def _check_owner(api, pathread, conf, kwargs, owner, permissive_owner):
|
|||
assert api.config(conf).option(pathread).owner.get() == owner
|
||||
assert api.forcepermissive.config(conf).option(pathread).owner.get() == owner
|
||||
elif not kwargs.get('propertyerror', False):
|
||||
raises(PropertiesOptionError, "api.config(conf).option(pathread).owner.get()")
|
||||
#raises(PropertiesOptionError, "api.config(conf).option(pathread).owner.get()")
|
||||
assert api.forcepermissive.config(conf).option(pathread).owner.get() == permissive_owner
|
||||
else:
|
||||
raises(PropertiesOptionError, "api.config(conf).option(pathread).owner.get()")
|
||||
raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread).owner.get()")
|
||||
#else:
|
||||
# raises(PropertiesOptionError, "api.config(conf).option(pathread).owner.get()")
|
||||
# raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread).owner.get()")
|
||||
else:
|
||||
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
||||
assert api.config(conf).option(pathread, 0).owner.get() == 'default'
|
||||
|
|
@ -864,9 +868,9 @@ def autocheck_default_owner_with_value(api, pathread, pathwrite, confread, confw
|
|||
assert api.config(confwrite).option(pathread).owner.isdefault() is False
|
||||
if confwrite != confread:
|
||||
assert api.config(confread).option(pathread).owner.isdefault() is False
|
||||
else:
|
||||
raises(PropertiesOptionError, "api.config(confwrite).option(pathread).owner.isdefault()")
|
||||
raises(PropertiesOptionError, "api.config(confread).option(pathread).owner.isdefault()")
|
||||
#else:
|
||||
# raises(PropertiesOptionError, "api.config(confwrite).option(pathread).owner.isdefault()")
|
||||
# raises(PropertiesOptionError, "api.config(confread).option(pathread).owner.isdefault()")
|
||||
else:
|
||||
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
||||
assert api.config(confwrite).option(pathread, 0).owner.isdefault() is True
|
||||
|
|
@ -894,8 +898,8 @@ def autocheck_default_owner_with_value_permissive(api, pathread, pathwrite, conf
|
|||
else:
|
||||
assert api.forcepermissive.config(conf).option(pathread, 0).owner.isdefault() is True
|
||||
assert api.forcepermissive.config(conf).option(pathread, 1).owner.isdefault() is False
|
||||
else:
|
||||
raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread).owner.isdefault()")
|
||||
#else:
|
||||
# raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread).owner.isdefault()")
|
||||
do(confwrite)
|
||||
if confwrite != confread:
|
||||
do(confread)
|
||||
|
|
@ -925,8 +929,8 @@ def autocheck_set_owner(api, pathread, pathwrite, confread, confwrite, **kwargs)
|
|||
raises(ConfigError, "api.config(confwrite).option(pathwrite).owner.set('default')")
|
||||
raises(ConfigError, "api.config(confwrite).option(pathwrite).owner.set('forced')")
|
||||
raises(ConfigError, "api.config(confwrite).option(pathwrite).owner.set('meta')")
|
||||
else:
|
||||
raises(PropertiesOptionError, "api.config(confwrite).option(pathwrite).owner.set('new_user')")
|
||||
#else:
|
||||
# raises(PropertiesOptionError, "api.config(confwrite).option(pathwrite).owner.set('new_user')")
|
||||
else:
|
||||
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
||||
api.option(pathwrite, 1).owner.set('new_user')
|
||||
|
|
@ -950,13 +954,13 @@ def autocheck_set_owner_permissive(api, pathread, pathwrite, confread, confwrite
|
|||
api.forcepermissive.config(confwrite).option(pathwrite).owner.set('new_user1')
|
||||
else:
|
||||
api.forcepermissive.option(pathwrite, 1).owner.set('new_user1')
|
||||
else:
|
||||
if not isslave:
|
||||
raises(PropertiesOptionError,
|
||||
"api.forcepermissive.config(confwrite).option(pathwrite).owner.set('new_user1')")
|
||||
else:
|
||||
raises(PropertiesOptionError,
|
||||
"api.forcepermissive.option(pathwrite, 1).owner.set('new_user1')")
|
||||
#else:
|
||||
# if not isslave:
|
||||
# raises(PropertiesOptionError,
|
||||
# "api.forcepermissive.config(confwrite).option(pathwrite).owner.set('new_user1')")
|
||||
# else:
|
||||
# raises(PropertiesOptionError,
|
||||
# "api.forcepermissive.option(pathwrite, 1).owner.set('new_user1')")
|
||||
|
||||
_check_owner(api, pathread, confwrite, kwargs, 'new_user1', 'new_user1')
|
||||
if confwrite != confread:
|
||||
|
|
@ -967,26 +971,26 @@ def autocheck_set_owner_permissive(api, pathread, pathwrite, confread, confwrite
|
|||
def autocheck_option(api, pathread, pathwrite, confread, confwrite, **kwargs):
|
||||
expected_name = pathread.split('.')[-1]
|
||||
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
||||
current_name = api.option(pathread).option.getname()
|
||||
assert current_name == api.forcepermissive.option(pathread).option.getname()
|
||||
assert current_name == api.unrestraint.option(pathread).option.getname()
|
||||
doc = api.option(pathread).option.getdoc()
|
||||
assert doc == api.forcepermissive.option(pathread).option.getdoc()
|
||||
assert doc == api.unrestraint.option(pathread).option.getdoc()
|
||||
current_name = api.option(pathread).option.name
|
||||
assert current_name == api.forcepermissive.option(pathread).option.name
|
||||
assert current_name == api.unrestraint.option(pathread).option.name
|
||||
doc = api.option(pathread).option.doc()
|
||||
assert doc == api.forcepermissive.option(pathread).option.doc()
|
||||
assert doc == api.unrestraint.option(pathread).option.doc()
|
||||
elif not kwargs.get('propertyerror', False):
|
||||
raises(PropertiesOptionError, "api.option(pathread).option.getname()")
|
||||
current_name = api.forcepermissive.option(pathread).option.getname()
|
||||
assert current_name == api.unrestraint.option(pathread).option.getname()
|
||||
raises(PropertiesOptionError, "api.option(pathread).option.getdoc()")
|
||||
doc = api.forcepermissive.option(pathread).option.getdoc()
|
||||
assert doc == api.unrestraint.option(pathread).option.getdoc()
|
||||
#raises(PropertiesOptionError, "api.option(pathread).option.name")
|
||||
current_name = api.forcepermissive.option(pathread).option.name
|
||||
assert current_name == api.unrestraint.option(pathread).option.name
|
||||
#raises(PropertiesOptionError, "api.option(pathread).option.doc()")
|
||||
doc = api.forcepermissive.option(pathread).option.doc()
|
||||
assert doc == api.unrestraint.option(pathread).option.doc()
|
||||
else:
|
||||
raises(PropertiesOptionError, "api.option(pathread).option.getname()")
|
||||
raises(PropertiesOptionError, "api.forcepermissive.option(pathread).option.getname()")
|
||||
current_name = api.unrestraint.option(pathread).option.getname()
|
||||
raises(PropertiesOptionError, "api.option(pathread).option.getdoc()")
|
||||
raises(PropertiesOptionError, "api.forcepermissive.option(pathread).option.getdoc()")
|
||||
doc = api.unrestraint.option(pathread).option.getdoc()
|
||||
# raises(PropertiesOptionError, "api.option(pathread).option.name")
|
||||
# raises(PropertiesOptionError, "api.forcepermissive.option(pathread).option.name")
|
||||
current_name = api.unrestraint.option(pathread).option.name
|
||||
# raises(PropertiesOptionError, "api.option(pathread).option.doc()")
|
||||
# raises(PropertiesOptionError, "api.forcepermissive.option(pathread).option.doc()")
|
||||
doc = api.unrestraint.option(pathread).option.doc()
|
||||
assert current_name == expected_name
|
||||
if expected_name.endswith('val1') or expected_name.endswith('val2'):
|
||||
expected_name = expected_name[:-4]
|
||||
|
|
|
|||
|
|
@ -1,14 +0,0 @@
|
|||
"""automatically sets the PYTHONPATH before running the unit tests
|
||||
|
||||
This is supposed to be used in development mode (i.e. testing from a fresh
|
||||
checkout)
|
||||
"""
|
||||
|
||||
from os.path import dirname, abspath, join, normpath
|
||||
import sys
|
||||
|
||||
def do_autopath():
|
||||
HERE = dirname(abspath(__file__))
|
||||
PATH = normpath(join(HERE, '..', 'tiramisu'))
|
||||
if PATH not in sys.path:
|
||||
sys.path.insert(1, PATH)
|
||||
|
|
@ -1,793 +0,0 @@
|
|||
# coding: utf-8
|
||||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
|
||||
from tiramisu import setting, value
|
||||
setting.expires_time = 1
|
||||
value.expires_time = 1
|
||||
from tiramisu.option import BoolOption, IPOption, IntOption, StrOption, OptionDescription, MasterSlaves
|
||||
from tiramisu.config import Config
|
||||
from tiramisu.error import ConfigError, PropertiesOptionError
|
||||
from tiramisu.setting import groups
|
||||
from tiramisu import getapi, undefined
|
||||
from tiramisu.api import TIRAMISU_VERSION
|
||||
|
||||
|
||||
from time import sleep, time
|
||||
from py.test import raises
|
||||
|
||||
|
||||
global incr
|
||||
incr = 0
|
||||
def return_incr():
|
||||
global incr
|
||||
incr += 1
|
||||
return incr
|
||||
|
||||
|
||||
def return_value(val):
|
||||
return val
|
||||
|
||||
|
||||
def make_description():
|
||||
u1 = IntOption('u1', '', multi=True)
|
||||
u2 = IntOption('u2', '')
|
||||
u3 = IntOption('u3', '', multi=True)
|
||||
return OptionDescription('od1', '', [u1, u2, u3])
|
||||
|
||||
|
||||
def test_cache_config():
|
||||
od1 = make_description()
|
||||
assert od1.impl_already_build_caches() is False
|
||||
c = Config(od1)
|
||||
assert od1.impl_already_build_caches() is True
|
||||
c
|
||||
|
||||
|
||||
def test_cache():
|
||||
od1 = make_description()
|
||||
c = Config(od1)
|
||||
api = getapi(c)
|
||||
values = c.cfgimpl_get_values()
|
||||
settings = c.cfgimpl_get_settings()
|
||||
api.option('u1').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
api.option('u2').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
assert 'u2' in values._p_.get_cached()
|
||||
assert 'u2' in settings._p_.get_cached()
|
||||
|
||||
|
||||
#def test_get_cache():
|
||||
# # force a value in cache, try if reget corrupted value
|
||||
# od1 = make_description()
|
||||
# c = Config(od1)
|
||||
# api = getapi(c)
|
||||
# values = c.cfgimpl_get_values()
|
||||
# settings = c.cfgimpl_get_settings()
|
||||
# ntime = time() + 1
|
||||
# settings._p_.setcache('u1', set(['inject']), ntime, None)
|
||||
# assert 'inject' in settings[od1.u1]
|
||||
# values._p_.setcache('u1', 100, ntime, None)
|
||||
# assert api.option('u1').value.get() == [100]
|
||||
|
||||
|
||||
#def test_get_cache_no_expire():
|
||||
# # force a value in cache, try if reget corrupted value
|
||||
# od1 = make_description()
|
||||
# c = Config(od1)
|
||||
# api = getapi(c)
|
||||
# values = c.cfgimpl_get_values()
|
||||
# settings = c.cfgimpl_get_settings()
|
||||
# settings._p_.setcache('u1', set(['inject2']), None, None)
|
||||
# assert 'inject2' in settings[od1.u1]
|
||||
# values._p_.setcache('u1', 200, None, None)
|
||||
# assert api.option('u1').value.get() == [200]
|
||||
|
||||
|
||||
def test_cache_reset():
|
||||
od1 = make_description()
|
||||
c = Config(od1)
|
||||
api = getapi(c)
|
||||
values = c.cfgimpl_get_values()
|
||||
settings = c.cfgimpl_get_settings()
|
||||
#when change a value
|
||||
api.option('u1').value.get()
|
||||
api.option('u2').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
assert 'u2' in values._p_.get_cached()
|
||||
assert 'u2' in settings._p_.get_cached()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
api.option('u2').value.set(1)
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
assert 'u2' not in values._p_.get_cached()
|
||||
assert 'u2' not in settings._p_.get_cached()
|
||||
#when remove a value
|
||||
api.option('u1').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
api.option('u2').value.reset()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
assert 'u2' not in values._p_.get_cached()
|
||||
assert 'u2' not in settings._p_.get_cached()
|
||||
#when add/del property
|
||||
api.option('u1').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
api.option('u2').property.add('test')
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
assert 'u2' not in values._p_.get_cached()
|
||||
assert 'u2' not in settings._p_.get_cached()
|
||||
api.option('u1').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
api.option('u2').property.pop('test')
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
assert 'u2' not in values._p_.get_cached()
|
||||
assert 'u2' not in settings._p_.get_cached()
|
||||
#when enable/disabled property
|
||||
api.option('u1').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
api.property.add('test')
|
||||
assert 'u1' not in values._p_.get_cached()
|
||||
assert 'u1' not in settings._p_.get_cached()
|
||||
api.option('u1').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
api.property.pop('test')
|
||||
assert 'u1' not in values._p_.get_cached()
|
||||
assert 'u1' not in settings._p_.get_cached()
|
||||
|
||||
|
||||
def test_cache_reset_multi():
|
||||
od1 = make_description()
|
||||
c = Config(od1)
|
||||
api = getapi(c)
|
||||
values = c.cfgimpl_get_values()
|
||||
settings = c.cfgimpl_get_settings()
|
||||
api.option('u1').value.get()
|
||||
api.option('u3').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
assert 'u3' in values._p_.get_cached()
|
||||
assert 'u3' in settings._p_.get_cached()
|
||||
#when change a value
|
||||
api.option('u3').value.set([1])
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
assert 'u3' not in values._p_.get_cached()
|
||||
assert 'u3' not in settings._p_.get_cached()
|
||||
#when append value
|
||||
api.option('u1').value.get()
|
||||
api.option('u3').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
assert 'u3' in values._p_.get_cached()
|
||||
assert 'u3' in settings._p_.get_cached()
|
||||
api.option('u3').value.set([1, 1])
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
assert 'u3' not in values._p_.get_cached()
|
||||
assert 'u3' not in settings._p_.get_cached()
|
||||
#when pop value
|
||||
api.option('u1').value.get()
|
||||
api.option('u3').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
assert 'u3' in values._p_.get_cached()
|
||||
assert 'u3' in settings._p_.get_cached()
|
||||
api.option('u3').value.set([1])
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
assert 'u3' not in values._p_.get_cached()
|
||||
assert 'u3' not in settings._p_.get_cached()
|
||||
#when remove a value
|
||||
api.option('u1').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
api.option('u3').value.reset()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
assert 'u3' not in values._p_.get_cached()
|
||||
assert 'u3' not in settings._p_.get_cached()
|
||||
|
||||
|
||||
def test_reset_cache():
|
||||
od1 = make_description()
|
||||
c = Config(od1)
|
||||
api = getapi(c)
|
||||
values = c.cfgimpl_get_values()
|
||||
settings = c.cfgimpl_get_settings()
|
||||
api.option('u1').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
c.cfgimpl_reset_cache()
|
||||
assert 'u1' not in values._p_.get_cached()
|
||||
assert 'u1' not in settings._p_.get_cached()
|
||||
api.option('u1').value.get()
|
||||
sleep(1)
|
||||
api.option('u1').value.get()
|
||||
sleep(1)
|
||||
api.option('u2').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
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()
|
||||
assert 'u1' not in values._p_.get_cached()
|
||||
assert 'u1' not in settings._p_.get_cached()
|
||||
assert 'u2' not in values._p_.get_cached()
|
||||
assert 'u2' not in settings._p_.get_cached()
|
||||
|
||||
|
||||
#def test_reset_cache_subconfig():
|
||||
# od1 = make_description()
|
||||
# od2 = OptionDescription('od2', '', [od1])
|
||||
# c = Config(od2)
|
||||
# api = getapi(c)
|
||||
# values = c.cfgimpl_get_values()
|
||||
# api.option('od1.u1').value.get()
|
||||
# assert 'od1.u1' in values._p_.get_cached()
|
||||
# c.od1.cfgimpl_reset_cache()
|
||||
# assert 'od1.u1' not in values._p_.get_cached()
|
||||
|
||||
|
||||
def test_reset_cache_only_expired():
|
||||
od1 = make_description()
|
||||
c = Config(od1)
|
||||
api = getapi(c)
|
||||
api.property.add('expire')
|
||||
values = c.cfgimpl_get_values()
|
||||
settings = c.cfgimpl_get_settings()
|
||||
api.option('u1').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
c.cfgimpl_reset_cache(True)
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
sleep(1)
|
||||
api.option('u1').value.get()
|
||||
sleep(1)
|
||||
api.option('u2').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
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(True)
|
||||
assert 'u1' not in values._p_.get_cached()
|
||||
assert 'u1' not in settings._p_.get_cached()
|
||||
assert 'u2' in values._p_.get_cached()
|
||||
assert 'u2' in settings._p_.get_cached()
|
||||
|
||||
|
||||
def test_cache_not_expire():
|
||||
od1 = make_description()
|
||||
c = Config(od1)
|
||||
api = getapi(c)
|
||||
values = c.cfgimpl_get_values()
|
||||
settings = c.cfgimpl_get_settings()
|
||||
#api.property.pop('expire')
|
||||
api.option('u1').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
c.cfgimpl_reset_cache(True)
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
sleep(1)
|
||||
api.option('u2').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
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(True)
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
assert 'u2' in values._p_.get_cached()
|
||||
assert 'u2' in settings._p_.get_cached()
|
||||
|
||||
|
||||
def test_cache_not_cache():
|
||||
od1 = make_description()
|
||||
c = Config(od1)
|
||||
api = getapi(c)
|
||||
values = c.cfgimpl_get_values()
|
||||
settings = c.cfgimpl_get_settings()
|
||||
api.property.pop('cache')
|
||||
api.option('u1').value.get()
|
||||
assert 'u1' not in values._p_.get_cached()
|
||||
assert 'u1' not in settings._p_.get_cached()
|
||||
|
||||
|
||||
#def test_reset_cache_only():
|
||||
# od1 = make_description()
|
||||
# c = Config(od1)
|
||||
# api = getapi(c)
|
||||
# values = c.cfgimpl_get_values()
|
||||
# settings = c.cfgimpl_get_settings()
|
||||
# api.option('u1').value.get()
|
||||
# assert 'u1' in values._p_.get_cached()
|
||||
# assert 'u1' in settings._p_.get_cached()
|
||||
# c.cfgimpl_reset_cache(only=('values',))
|
||||
# assert 'u1' not in values._p_.get_cached()
|
||||
# assert 'u1' in settings._p_.get_cached()
|
||||
# api.option('u1').value.get()
|
||||
# assert 'u1' in values._p_.get_cached()
|
||||
# assert 'u1' in settings._p_.get_cached()
|
||||
# c.cfgimpl_reset_cache(only=('settings',))
|
||||
# assert 'u1' in values._p_.get_cached()
|
||||
# assert 'u1' not in settings._p_.get_cached()
|
||||
|
||||
|
||||
#def test_force_cache():
|
||||
# u1 = IntOption('u1', '', multi=True)
|
||||
# u2 = IntOption('u2', '')
|
||||
# u3 = IntOption('u3', '', multi=True)
|
||||
# u4 = IntOption('u4', '', properties=('disabled',))
|
||||
# od = OptionDescription('od1', '', [u1, u2, u3, u4])
|
||||
# c = Config(od)
|
||||
# api = getapi(c)
|
||||
# api.property.read_write()
|
||||
# api.property.pop('expire')
|
||||
# api.property.pop('disabled')
|
||||
#
|
||||
# c.cfgimpl_get_values().force_cache()
|
||||
# assert c.cfgimpl_get_values()._p_.get_cached() == {'u1': {None: ([], None)},
|
||||
# 'u2': {None: (None, None)},
|
||||
# 'u3': {None: ([], None)},
|
||||
# 'u4': {None: (None, None)}}
|
||||
# assert c.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
# 'u1': {None: (set(['empty']), None)},
|
||||
# 'u2': {None: (set([]), None)},
|
||||
# 'u3': {None: (set(['empty']), None)},
|
||||
# 'u4': {None: (set(['disabled']), None)}}
|
||||
# api.property.read_only()
|
||||
#
|
||||
# c.cfgimpl_get_values().force_cache()
|
||||
# assert c.cfgimpl_get_values()._p_.get_cached() == {'u1': {None: ([], None)},
|
||||
# 'u2': {None: (None, None)},
|
||||
# 'u3': {None: ([], None)}}
|
||||
# assert c.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'empty', 'everything_frozen', 'frozen', 'mandatory', 'validator', 'warnings']), None)},
|
||||
# 'u1': {None: (set(['empty']), None)},
|
||||
# 'u2': {None: (set([]), None)},
|
||||
# 'u3': {None: (set(['empty']), None)},
|
||||
# 'u4': {None: (set(['disabled']), None)}}
|
||||
#
|
||||
# c.cfgimpl_get_settings().remove('cache')
|
||||
# raises(ConfigError, "c.cfgimpl_get_values().force_cache()")
|
||||
|
||||
|
||||
def test_cache_master_slave():
|
||||
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)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
api = getapi(cfg)
|
||||
api.property.read_write()
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {}
|
||||
#assert cfg.cfgimpl_get_settings()._p_.get_cached() == {}
|
||||
#
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.get()
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()
|
||||
cache = cfg.cfgimpl_get_values()._p_.get_cached()
|
||||
if TIRAMISU_VERSION == 2:
|
||||
assert set(cache.keys()) == set(['ip_admin_eth0.ip_admin_eth0'])
|
||||
else:
|
||||
assert set(cache.keys()) == set(['ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
|
||||
assert set(cache['ip_admin_eth0.ip_admin_eth0'].keys()) == set([None])
|
||||
assert cache['ip_admin_eth0.ip_admin_eth0'][None][0] == ['192.168.1.2']
|
||||
#assert set(cache['ip_admin_eth0.netmask_admin_eth0'].keys()) == set([None])
|
||||
#assert cache['ip_admin_eth0.netmask_admin_eth0'][None][0] == [None]
|
||||
#assert cache['ip_admin_eth0.netmask_admin_eth0'][0][0] is None
|
||||
cache = cfg.cfgimpl_get_settings()._p_.get_cached()
|
||||
assert set(cache.keys()) == set([None, 'ip_admin_eth0', 'ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
|
||||
assert set(cache['ip_admin_eth0'].keys()) == set([None])
|
||||
assert set(cache['ip_admin_eth0.ip_admin_eth0'].keys()) == set([None])
|
||||
if TIRAMISU_VERSION == 2:
|
||||
assert set(cache['ip_admin_eth0.netmask_admin_eth0'].keys()) == set([None, 0])
|
||||
else:
|
||||
assert set(cache['ip_admin_eth0.netmask_admin_eth0'].keys()) == set([0])
|
||||
#
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1'])
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.get()
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()
|
||||
cache = cfg.cfgimpl_get_values()._p_.get_cached()
|
||||
if TIRAMISU_VERSION == 2:
|
||||
assert set(cache.keys()) == set(['ip_admin_eth0.ip_admin_eth0'])
|
||||
else:
|
||||
assert set(cache.keys()) == set(['ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
|
||||
assert set(cache['ip_admin_eth0.ip_admin_eth0'].keys()) == set([None])
|
||||
assert cache['ip_admin_eth0.ip_admin_eth0'][None][0] == ['192.168.1.2', '192.168.1.1']
|
||||
#assert set(cache['ip_admin_eth0.netmask_admin_eth0'].keys()) == set([None])
|
||||
#assert cache['ip_admin_eth0.netmask_admin_eth0'][None][0] == [None, None]
|
||||
#assert cache['ip_admin_eth0.netmask_admin_eth0'][0][0] is None
|
||||
#assert cache['ip_admin_eth0.netmask_admin_eth0'][1][0] is None
|
||||
cache = cfg.cfgimpl_get_settings()._p_.get_cached()
|
||||
assert set(cache.keys()) == set([None, 'ip_admin_eth0', 'ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
|
||||
assert set(cache['ip_admin_eth0'].keys()) == set([None])
|
||||
assert set(cache['ip_admin_eth0.ip_admin_eth0'].keys()) == set([None])
|
||||
if TIRAMISU_VERSION == 2:
|
||||
assert set(cache['ip_admin_eth0.netmask_admin_eth0'].keys()) == set([None, 0, 1])
|
||||
else:
|
||||
assert set(cache['ip_admin_eth0.netmask_admin_eth0'].keys()) == set([0, 1])
|
||||
#DEL, insert, ...
|
||||
|
||||
|
||||
def return_value(value=None):
|
||||
return value
|
||||
|
||||
|
||||
def test_cache_callback():
|
||||
val1 = StrOption('val1', "", 'val')
|
||||
val2 = StrOption('val2', "", callback=return_value, callback_params={'': ((val1, False),)}, properties=('mandatory',))
|
||||
val3 = StrOption('val3', "", callback=return_value, callback_params={'': ('yes',)})
|
||||
val4 = StrOption('val4', "", callback=return_value, callback_params={'value': ((val1, False),)})
|
||||
val5 = StrOption('val5', "", callback=return_value, callback_params={'value': ('yes',)}, multi=True)
|
||||
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4, val5])
|
||||
cfg = Config(maconfig)
|
||||
api = getapi(cfg)
|
||||
api.property.read_write()
|
||||
#api.property.pop('expire')
|
||||
api.option.make_dict()
|
||||
#assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
# 'val1': {None: (set([]), None)}}
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1': {None: ('val', None)},
|
||||
'val2': {None: ('val', None)},
|
||||
'val3': {None: ('yes', None)},
|
||||
'val4': {None: ('val', None)},
|
||||
'val5': {None: (['yes'], None)}}
|
||||
api.option('val1').value.set('new')
|
||||
#assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
# 'val1': {None: (set([]), None)}}
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val3': {None: ('yes', None)},
|
||||
'val5': {None: (['yes'], None)}}
|
||||
api.option.make_dict()
|
||||
#assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
# 'val1': {None: (set([]), None)}}
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1': {None: ('new', None)},
|
||||
'val2': {None: ('new', None)},
|
||||
'val3': {None: ('yes', None)},
|
||||
'val4': {None: ('new', None)},
|
||||
'val5': {None: (['yes'], None)}}
|
||||
api.option('val3').value.set('new2')
|
||||
#assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
# 'val1': {None: (set([]), None)},
|
||||
# 'val3': {None: (set([]), None)}}
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1': {None: ('new', None)},
|
||||
'val2': {None: ('new', None)},
|
||||
'val4': {None: ('new', None)},
|
||||
'val5': {None: (['yes'], None)}}
|
||||
api.option.make_dict()
|
||||
#assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
# 'val1': {None: (set([]), None)},
|
||||
# 'val3': {None: (set([]), None)}}
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1': {None: ('new', None)},
|
||||
'val2': {None: ('new', None)},
|
||||
'val3': {None: ('new2', None)},
|
||||
'val4': {None: ('new', None)},
|
||||
'val5': {None: (['yes'], None)}}
|
||||
api.option('val4').value.set('new3')
|
||||
#assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
# 'val1': {None: (set([]), None)},
|
||||
# 'val3': {None: (set([]), None)},
|
||||
# 'val4': {None: (set([]), None)}}
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1': {None: ('new', None)},
|
||||
'val2': {None: ('new', None)},
|
||||
'val3': {None: ('new2', None)},
|
||||
'val5': {None: (['yes'], None)}}
|
||||
api.option.make_dict()
|
||||
#assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
# 'val1': {None: (set([]), None)},
|
||||
# 'val3': {None: (set([]), None)},
|
||||
# 'val4': {None: (set([]), None)}}
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1': {None: ('new', None)},
|
||||
'val2': {None: ('new', None)},
|
||||
'val3': {None: ('new2', None)},
|
||||
'val4': {None: ('new3', None)},
|
||||
'val5': {None: (['yes'], None)}}
|
||||
api.option('val5').value.set([undefined, 'new4'])
|
||||
#assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
# 'val1': {None: (set([]), None)},
|
||||
# 'val3': {None: (set([]), None)},
|
||||
# 'val4': {None: (set([]), None)},
|
||||
# 'val5': {None: (set(['empty']), None)}}
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1': {None: ('new', None)},
|
||||
'val2': {None: ('new', None)},
|
||||
'val3': {None: ('new2', None)},
|
||||
'val4': {None: ('new3', None)}}
|
||||
api.option.make_dict()
|
||||
#assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
# 'val1': {None: (set([]), None)},
|
||||
# 'val3': {None: (set([]), None)},
|
||||
# 'val4': {None: (set([]), None)},
|
||||
# 'val5': {None: (set(['empty']), None)}}
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1': {None: ('new', None)},
|
||||
'val2': {None: ('new', None)},
|
||||
'val3': {None: ('new2', None)},
|
||||
'val4': {None: ('new3', None)},
|
||||
'val5': {None: (['yes', 'new4'], None)}}
|
||||
|
||||
|
||||
def test_cache_master_and_slaves_master():
|
||||
val1 = StrOption('val1', "", multi=True)
|
||||
val2 = StrOption('val2', "", multi=True)
|
||||
interface1 = MasterSlaves('val1', '', [val1, val2])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('rootconfig', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
api = getapi(cfg)
|
||||
api.property.read_write()
|
||||
#api.property.pop('expire')
|
||||
api.option.make_dict()
|
||||
global_props = ['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']
|
||||
val1_props = []
|
||||
val1_val1_props = ['empty']
|
||||
val1_val2_props = []
|
||||
if TIRAMISU_VERSION == 2:
|
||||
global_props = set(global_props)
|
||||
val1_props = set(val1_props)
|
||||
val1_val1_props = set(val1_val1_props)
|
||||
val1_val2_props = set(val1_val2_props)
|
||||
else:
|
||||
global_props = frozenset(global_props)
|
||||
val1_props = frozenset(val1_props)
|
||||
val1_val1_props = frozenset(val1_val1_props)
|
||||
val1_val2_props = frozenset(val1_val2_props)
|
||||
#None because no value
|
||||
idx_val2 = None
|
||||
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (global_props, None)},
|
||||
'val1': {None: (val1_props, None)},
|
||||
'val1.val1': {None: (val1_val1_props, None)},
|
||||
'val1.val2': {idx_val2: (val1_val2_props, None)}}
|
||||
if TIRAMISU_VERSION == 2:
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([], None)}, 'val1.val2': {None: ([], None)}}
|
||||
else:
|
||||
# len is 0 so don't get any value
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([], None)}}
|
||||
#
|
||||
api.option('val1.val1').value.set([undefined])
|
||||
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
'val1': {None: (set([]), None)}}
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {}
|
||||
api.option.make_dict()
|
||||
if TIRAMISU_VERSION == 2:
|
||||
val_val2 = [None]
|
||||
val_val2_props = {None: (set(), None), 0: (set(), None)}
|
||||
else:
|
||||
#has value
|
||||
idx_val2 = 0
|
||||
val_val2 = None
|
||||
val_val2_props = {idx_val2: (val1_val2_props, None)}
|
||||
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (global_props, None)},
|
||||
'val1': {None: (val1_props, None)},
|
||||
'val1.val1': {None: (val1_val1_props, None)},
|
||||
'val1.val2': val_val2_props}
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([None], None)},
|
||||
'val1.val2': {idx_val2: (val_val2, None)}}
|
||||
api.option('val1.val1').value.set([undefined, undefined])
|
||||
api.option.make_dict()
|
||||
api.option('val1.val2', 1).value.set('oui')
|
||||
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
'val1': {None: (set([]), None)}}
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {}
|
||||
if TIRAMISU_VERSION == 2:
|
||||
val1_val2_props = {None: (set([]), None), 0: (set([]), None), 1: (set([]), None)}
|
||||
else:
|
||||
val1_val2_props = {0: (frozenset([]), None), 1: (frozenset([]), None)}
|
||||
#assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (global_props, None)},
|
||||
# 'val1': {None: (val1_props, None)},
|
||||
# 'val1.val1': {None: (val1_val1_props, None)},
|
||||
# 'val1.val2': val1_val2_props}
|
||||
#if TIRAMISU_VERSION == 2:
|
||||
# assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([None, None], None)},
|
||||
# 'val1.val2': {None: ([None, 'oui'], None)}}
|
||||
#else:
|
||||
# assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([None, None], None)},
|
||||
# 'val1.val2': {0: (None, None), 1: ('oui', None)}}
|
||||
|
||||
|
||||
def test_cache_master_callback():
|
||||
val1 = StrOption('val1', "", multi=True)
|
||||
val2 = StrOption('val2', "", multi=True, callback=return_value, callback_params={'value': ((val1, False),)})
|
||||
interface1 = MasterSlaves('val1', '', [val1, val2])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('rootconfig', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
api = getapi(cfg)
|
||||
api.property.read_write()
|
||||
#api.property.pop('expire')
|
||||
api.option.make_dict()
|
||||
global_props = ['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']
|
||||
val1_props = []
|
||||
val1_val1_props = ['empty']
|
||||
val1_val2_props = []
|
||||
if TIRAMISU_VERSION == 2:
|
||||
global_props = set(global_props)
|
||||
val1_props = set(val1_props)
|
||||
val1_val1_props = set(val1_val1_props)
|
||||
val1_val2_props = set(val1_val2_props)
|
||||
else:
|
||||
global_props = frozenset(global_props)
|
||||
val1_props = frozenset(val1_props)
|
||||
val1_val1_props = frozenset(val1_val1_props)
|
||||
val1_val2_props = frozenset(val1_val2_props)
|
||||
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (global_props, None)},
|
||||
'val1': {None: (val1_props, None)},
|
||||
'val1.val1': {None: (val1_val1_props, None)},
|
||||
'val1.val2': {None: (val1_val2_props, None)}}
|
||||
if TIRAMISU_VERSION == 2:
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([], None)}, 'val1.val2': {None: ([], None)}}
|
||||
else:
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([], None)}}
|
||||
api.option('val1.val1').value.set([undefined])
|
||||
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
'val1': {None: (set([]), None)}}
|
||||
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {}
|
||||
api.option.make_dict()
|
||||
#FIXMEassert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
# 'val1': {None: (set([]), None)}}
|
||||
#FIXMEassert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([None], None)},
|
||||
# 'val1.val2': {None: ([None], None)}
|
||||
# }
|
||||
|
||||
|
||||
#def test_cache_master_slave_different():
|
||||
# b = IntOption('int', 'Test int option', default=[0], multi=True)
|
||||
# c = StrOption('str', 'Test string option', multi=True)
|
||||
# d = StrOption('str1', 'Test string option', requires=[{'option': c, 'expected': None, 'action': 'hidden', 'inverse': True}], multi=True)
|
||||
# descr = MasterSlaves("int", "", [b, c, d])
|
||||
# #descr.impl_set_group_type(groups.master)
|
||||
# cfg = Config(descr)
|
||||
# api = getapi(cfg)
|
||||
# api.property.read_write()
|
||||
# api.property.pop('expire')
|
||||
# api.option.make_dict()
|
||||
# assert cfg.cfgimpl_get_values()._p_.get_cached() == {'int': {None: ([0], None)},
|
||||
# 'str': {None: ([None], None)},
|
||||
# 'str1': {None: ([None], None)}}
|
||||
# assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
# 'int': {None: (set(['empty']), None)},
|
||||
# 'str': {None: (set([]), None), 0: (set([]), None)},
|
||||
# 'str1': {None: (set([]), None), 0: (set([]), None)}}
|
||||
# api.option('int').value.set([0, 1])
|
||||
# api.option.make_dict()
|
||||
# assert cfg.cfgimpl_get_values()._p_.get_cached() == {'int': {None: ([0, 1], None)},
|
||||
# 'str': {None: ([None, None], None)},
|
||||
# 'str1': {None: ([None, None], None)}}
|
||||
# assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
# 'int': {None: (set(['empty']), None)},
|
||||
# 'str': {None: (set([]), None), 0: (set([]), None), 1: (set([]), None)},
|
||||
# 'str1': {None: (set([]), None), 0: (set([]), None), 1: (set([]), None)}}
|
||||
#
|
||||
# api.option('str', 1).value.set('1')
|
||||
# api.option.make_dict()
|
||||
# assert set(cfg.cfgimpl_get_values()._p_.get_cached().keys()) == set(['int', 'str', 'str1'])
|
||||
# assert cfg.cfgimpl_get_values()._p_.get_cached()['int'] == {None: ([0, 1], None)}
|
||||
# assert cfg.cfgimpl_get_values()._p_.get_cached()['str'] == {None: ([None, '1'], None)}
|
||||
# assert cfg.cfgimpl_get_values()._p_.get_cached()['str1'][None][0][0] == None
|
||||
# raises(PropertiesOptionError, "cfg.cfgimpl_get_values()._p_.get_cached()['str1'][None][0][1]")
|
||||
# assert cfg.cfgimpl_get_values()._p_.get_cached()['str1'][None][1] == None
|
||||
# assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
# 'int': {None: (set(['empty']), None)},
|
||||
# 'str': {None: (set([]), None), 0: (set([]), None), 1: (set([]), None)},
|
||||
# 'str1': {None: (set([]), None), 0: (set([]), None), 1: (set(['hidden']), None)}}
|
||||
# api.property.read_only()
|
||||
# assert cfg.cfgimpl_get_values()._p_.get_cached() == {}
|
||||
# assert cfg.cfgimpl_get_settings()._p_.get_cached() == {}
|
||||
# api.option.make_dict()
|
||||
# assert cfg.cfgimpl_get_values()._p_.get_cached() == {'int': {None: ([0, 1], None)},
|
||||
# 'str': {None: ([None, '1'], None)},
|
||||
# 'str1': {None: ([None, None], None)}}
|
||||
# assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'everything_frozen', 'validator', 'warnings', 'empty', 'mandatory', ]), None)},
|
||||
# 'int': {None: (set(['empty']), None)},
|
||||
# 'str': {None: (set([]), None), 0: (set([]), None), 1: (set([]), None)},
|
||||
# 'str1': {None: (set([]), None), 0: (set([]), None), 1: (set(['hidden']), None)}}
|
||||
|
||||
|
||||
|
||||
def test_cache_requires():
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = IPOption('ip_address_service', '',
|
||||
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
||||
od = OptionDescription('service', '', [a, b])
|
||||
c = Config(od)
|
||||
api = getapi(c)
|
||||
api.property.read_write()
|
||||
#api.property.pop('expire')
|
||||
#assert c.cfgimpl_get_settings()._p_.get_cached() == {}
|
||||
assert c.cfgimpl_get_values()._p_.get_cached() == {}
|
||||
assert api.option('ip_address_service').value.get() == None
|
||||
assert c.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
'activate_service': {None: (set([]), None)},
|
||||
'ip_address_service': {None: (set([]), None)}}
|
||||
|
||||
assert c.cfgimpl_get_values()._p_.get_cached() == {'ip_address_service': {None: (None, None)},
|
||||
'activate_service': {None: (True, None)}}
|
||||
api.option.make_dict()
|
||||
assert c.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
'activate_service': {None: (set([]), None)},
|
||||
'ip_address_service': {None: (set([]), None)}}
|
||||
|
||||
assert c.cfgimpl_get_values()._p_.get_cached() == {'ip_address_service': {None: (None, None)},
|
||||
'activate_service': {None: (True, None)}}
|
||||
api.option('ip_address_service').value.set('1.1.1.1')
|
||||
assert c.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
'activate_service': {None: (set([]), None)}}
|
||||
|
||||
assert c.cfgimpl_get_values()._p_.get_cached() == {'activate_service': {None: (True, None)}}
|
||||
api.option.make_dict()
|
||||
assert c.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
'activate_service': {None: (set([]), None)},
|
||||
'ip_address_service': {None: (set([]), None)}}
|
||||
|
||||
assert c.cfgimpl_get_values()._p_.get_cached() == {'ip_address_service': {None: ('1.1.1.1', None)},
|
||||
'activate_service': {None: (True, None)}}
|
||||
api.option('activate_service').value.set(False)
|
||||
assert c.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}}
|
||||
|
||||
assert c.cfgimpl_get_values()._p_.get_cached() == {}
|
||||
api.option.make_dict()
|
||||
assert c.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
'activate_service': {None: (set([]), None)},
|
||||
'ip_address_service': {None: (set(['disabled']), None)}}
|
||||
|
||||
assert c.cfgimpl_get_values()._p_.get_cached() == {'activate_service': {None: (False, None)}}
|
||||
|
||||
|
||||
def test_cache_global_properties():
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = IPOption('ip_address_service', '',
|
||||
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
||||
od = OptionDescription('service', '', [a, b])
|
||||
c = Config(od)
|
||||
api = getapi(c)
|
||||
api.property.read_write()
|
||||
#api.property.pop('expire')
|
||||
#assert c.cfgimpl_get_settings()._p_.get_cached() == {}
|
||||
assert c.cfgimpl_get_values()._p_.get_cached() == {}
|
||||
assert api.option('ip_address_service').value.get() == None
|
||||
assert c.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
'activate_service': {None: (set([]), None)},
|
||||
'ip_address_service': {None: (set([]), None)}}
|
||||
|
||||
assert c.cfgimpl_get_values()._p_.get_cached() == {'ip_address_service': {None: (None, None)},
|
||||
'activate_service': {None: (True, None)}}
|
||||
api.property.pop('disabled')
|
||||
assert api.option('ip_address_service').value.get() == None
|
||||
assert c.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
'activate_service': {None: (set([]), None)},
|
||||
'ip_address_service': {None: (set([]), None)}}
|
||||
api.property.add('test')
|
||||
assert api.option('ip_address_service').value.get() == None
|
||||
assert c.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'frozen', 'hidden', 'validator', 'warnings', 'test']), None)},
|
||||
'activate_service': {None: (set([]), None)},
|
||||
'ip_address_service': {None: (set([]), None)}}
|
||||
|
||||
|
||||
def test_callback_value_incr():
|
||||
val1 = IntOption('val1', "", callback=return_incr)
|
||||
val2 = IntOption('val2', "", callback=return_value, callback_params={'value': ((val1, False),)})
|
||||
maconfig = OptionDescription('rootconfig', '', [val1, val2])
|
||||
cfg = Config(maconfig)
|
||||
api = getapi(cfg)
|
||||
api.property.read_write()
|
||||
api.property.add('expire')
|
||||
assert api.option('val1').value.get() == 1
|
||||
sleep(1)
|
||||
assert api.option('val2').value.get() == 1
|
||||
sleep(1)
|
||||
assert api.option('val1').value.get() == 2
|
||||
assert api.option('val2').value.get() == 2
|
||||
|
|
@ -1,199 +0,0 @@
|
|||
# coding: utf-8
|
||||
from py.test import raises
|
||||
|
||||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
|
||||
from tiramisu.setting import owners
|
||||
from tiramisu.option import ChoiceOption, StrOption, OptionDescription
|
||||
from tiramisu.config import Config
|
||||
from tiramisu.error import ConfigError
|
||||
from tiramisu import getapi, undefined
|
||||
|
||||
|
||||
def return_val(val):
|
||||
return val
|
||||
|
||||
|
||||
def return_list():
|
||||
return ['val1', 'val2']
|
||||
|
||||
|
||||
def return_calc_list(val):
|
||||
return [val]
|
||||
|
||||
|
||||
def return_error():
|
||||
raise Exception('test')
|
||||
|
||||
|
||||
def test_choiceoption():
|
||||
choice = ChoiceOption('choice', '', values=('val1', 'val2'))
|
||||
odesc = OptionDescription('od', '', [choice])
|
||||
cfg = Config(odesc)
|
||||
api = getapi(cfg)
|
||||
api.property.read_write()
|
||||
owner = api.owner.get()
|
||||
assert api.option('choice').owner.get() == owners.default
|
||||
assert api.option('choice').owner.isdefault()
|
||||
#
|
||||
api.option('choice').value.set('val1')
|
||||
assert api.option('choice').owner.get() == owner
|
||||
assert not api.option('choice').owner.isdefault()
|
||||
#
|
||||
api.option('choice').value.reset()
|
||||
assert api.option('choice').owner.get() == owners.default
|
||||
assert api.option('choice').owner.isdefault()
|
||||
#
|
||||
raises(ValueError, "api.option('choice').value.set('no')")
|
||||
assert api.option('choice').owner.get() == owners.default
|
||||
assert api.option('choice').owner.isdefault()
|
||||
#
|
||||
assert api.option('choice').value.list() == ('val1', 'val2')
|
||||
|
||||
|
||||
def test_choiceoption_function():
|
||||
choice = ChoiceOption('choice', '', values=return_list)
|
||||
odesc = OptionDescription('od', '', [choice])
|
||||
cfg = Config(odesc)
|
||||
api = getapi(cfg)
|
||||
api.property.read_write()
|
||||
owner = api.owner.get()
|
||||
assert api.option('choice').owner.isdefault()
|
||||
#
|
||||
api.option('choice').value.set('val1')
|
||||
assert api.option('choice').owner.get() == owner
|
||||
#
|
||||
api.option('choice').value.reset()
|
||||
assert api.option('choice').owner.isdefault()
|
||||
#
|
||||
raises(ValueError, "api.option('choice').value.set('no')")
|
||||
assert api.option('choice').owner.isdefault()
|
||||
#
|
||||
assert api.option('choice').value.list() == ['val1', 'val2']
|
||||
|
||||
|
||||
def test_choiceoption_function_error():
|
||||
choice = ChoiceOption('choice', '', values=return_error)
|
||||
odesc = OptionDescription('od', '', [choice])
|
||||
cfg = Config(odesc)
|
||||
api = getapi(cfg)
|
||||
api.property.read_write()
|
||||
raises(ConfigError, "api.option('choice').value.set('val1')")
|
||||
|
||||
|
||||
def test_choiceoption_calc_function():
|
||||
choice = ChoiceOption('choice', "", values=return_calc_list, values_params={'': ('val1',)})
|
||||
odesc = OptionDescription('od', '', [choice])
|
||||
cfg = Config(odesc)
|
||||
api = getapi(cfg)
|
||||
api.property.read_write()
|
||||
owner = api.owner.get()
|
||||
assert api.option('choice').owner.isdefault()
|
||||
#
|
||||
api.option('choice').value.set('val1')
|
||||
assert api.option('choice').owner.get() == owner
|
||||
#
|
||||
api.option('choice').value.reset()
|
||||
assert api.option('choice').owner.isdefault()
|
||||
#
|
||||
raises(ValueError, "api.option('choice').value.set('no')")
|
||||
assert api.option('choice').owner.isdefault()
|
||||
|
||||
|
||||
def test_choiceoption_calc_opt_function():
|
||||
str_ = StrOption('str', '', 'val1')
|
||||
choice = ChoiceOption('choice',
|
||||
"",
|
||||
values=return_calc_list,
|
||||
values_params={'': ((str_, False),)})
|
||||
odesc = OptionDescription('od', '', [str_, choice])
|
||||
cfg = Config(odesc)
|
||||
api = getapi(cfg)
|
||||
api.property.read_write()
|
||||
owner = api.owner.get()
|
||||
assert api.option('choice').owner.isdefault()
|
||||
#
|
||||
api.option('choice').value.set('val1')
|
||||
assert api.option('choice').owner.get() == owner
|
||||
#
|
||||
api.option('choice').value.reset()
|
||||
assert api.option('choice').owner.isdefault()
|
||||
#
|
||||
raises(ValueError, "api.option('choice').value.set('no')")
|
||||
assert api.option('choice').owner.isdefault()
|
||||
|
||||
|
||||
def test_choiceoption_calc_opt_function_propertyerror():
|
||||
str_ = StrOption('str', '', 'val1', properties=('disabled',))
|
||||
choice = ChoiceOption('choice',
|
||||
"",
|
||||
values=return_calc_list,
|
||||
values_params={'': ((str_, False),)})
|
||||
odesc = OptionDescription('od', '', [str_, choice])
|
||||
cfg = Config(odesc)
|
||||
api = getapi(cfg)
|
||||
api.property.read_write()
|
||||
raises(ValueError, "api.option('choice').value.set('no')")
|
||||
|
||||
|
||||
def test_choiceoption_calc_opt_multi_function():
|
||||
str_ = StrOption('str', '', ['val1'], multi=True)
|
||||
choice = ChoiceOption('choice',
|
||||
"",
|
||||
default_multi='val2',
|
||||
values=return_val,
|
||||
values_params={'': ((str_, False),)},
|
||||
multi=True)
|
||||
ch2 = ChoiceOption('ch2',
|
||||
"",
|
||||
default=['val2'],
|
||||
values=return_val,
|
||||
values_params={'': ((str_, False),)},
|
||||
multi=True)
|
||||
odesc = OptionDescription('od', '', [str_, choice, ch2])
|
||||
cfg = Config(odesc)
|
||||
api = getapi(cfg)
|
||||
api.property.read_write()
|
||||
owner = api.owner.get()
|
||||
assert api.option('choice').owner.isdefault()
|
||||
assert api.option('choice').value.get() == []
|
||||
#
|
||||
api.option('choice').value.set(['val1'])
|
||||
assert api.option('choice').owner.get() == owner
|
||||
#
|
||||
raises(ValueError, "api.option('choice').value.set([undefined])")
|
||||
#
|
||||
api.option('choice').value.set(['val1'])
|
||||
assert api.option('choice').owner.get() == owner
|
||||
#
|
||||
api.option('choice').value.reset()
|
||||
assert api.option('choice').owner.isdefault()
|
||||
#
|
||||
raises(ValueError, "api.option('choice').value.set('no')")
|
||||
assert api.option('choice').owner.isdefault()
|
||||
#
|
||||
raises(ValueError, "api.option('ch2').value.get()")
|
||||
|
||||
|
||||
def test_choiceoption_calc_invalid():
|
||||
str_ = StrOption('str', '', ['val1'], multi=True)
|
||||
str_
|
||||
raises(ValueError,
|
||||
"choice = ChoiceOption('choice', '', default_multi='val2', values=[1, 2, 3], \
|
||||
values_params={'': ((str_, False),)}, multi=True)")
|
||||
|
||||
|
||||
def test_choiceoption_calc_not_list():
|
||||
str_ = StrOption('str', '', 'val1')
|
||||
choice = ChoiceOption('choice',
|
||||
"",
|
||||
default_multi='val2',
|
||||
values=return_val,
|
||||
values_params={'': ((str_, False),)},
|
||||
multi=True)
|
||||
odesc = OptionDescription('od', '', [str_, choice])
|
||||
cfg = Config(odesc)
|
||||
api = getapi(cfg)
|
||||
api.property.read_write()
|
||||
raises(ConfigError, "api.option('choice').value.set(['val1'])")
|
||||
|
|
@ -1,403 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""theses tests are much more to test that config, option description, vs...
|
||||
**it's there** and answers via attribute access"""
|
||||
from py.test import raises
|
||||
import weakref
|
||||
|
||||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
|
||||
from tiramisu.config import Config, SubConfig
|
||||
from tiramisu.i18n import _
|
||||
from tiramisu import Config, IntOption, FloatOption, StrOption, ChoiceOption, \
|
||||
BoolOption, UnicodeOption, OptionDescription, getapi, undefined
|
||||
from tiramisu.error import ConflictError, ConfigError, PropertiesOptionError, APIError
|
||||
|
||||
|
||||
def make_description():
|
||||
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||
('std', 'thunk'), 'std')
|
||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||
stroption = StrOption('str', 'Test string option', default="abc", properties=('mandatory', ))
|
||||
boolop = BoolOption('boolop', 'Test boolean option op', default=True, properties=('hidden',))
|
||||
wantref_option = BoolOption('wantref', 'Test requires', default=False)
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False)
|
||||
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
||||
descr = OptionDescription('tiram', '', [gcgroup, booloption, objspaceoption,
|
||||
wantref_option, stroption,
|
||||
wantframework_option,
|
||||
intoption, boolop])
|
||||
return descr
|
||||
|
||||
|
||||
def test_base_config():
|
||||
"""making a :class:`tiramisu.config.Config()` object
|
||||
and a :class:`tiramisu.option.OptionDescription()` object
|
||||
"""
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
descr = OptionDescription('tiramisu', '', [gcdummy])
|
||||
cfg = Config(descr)
|
||||
api = getapi(cfg)
|
||||
assert api.option('dummy').value.get() is False
|
||||
#dmo = cfg.unwrap_from_path('dummy')
|
||||
#assert dmo.impl_getname() == 'dummy'
|
||||
|
||||
|
||||
def test_base_config_name():
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
descr = OptionDescription('tiramisu', '', [gcdummy])
|
||||
cfg = Config(descr, session_id='cfg')
|
||||
cfg.impl_getname() == 'cfg'
|
||||
raises(ValueError, "Config(descr, session_id='unvalid name')")
|
||||
|
||||
|
||||
def test_not_config():
|
||||
assert raises(TypeError, "Config('str')")
|
||||
|
||||
|
||||
#def test_base_path():
|
||||
# gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
# descr = OptionDescription('tiramisu', '', [gcdummy])
|
||||
# cfg = Config(descr)
|
||||
# assert cfg._impl_path is None
|
||||
# base = OptionDescription('config', '', [descr])
|
||||
# cfg = Config(base)
|
||||
# assert cfg._impl_path is None
|
||||
# assert cfg.getattr('tiramisu', None, validate_properties=False)._impl_path == 'tiramisu'
|
||||
# nbase = OptionDescription('baseconfig', '', [base])
|
||||
# cfg = Config(nbase)
|
||||
# assert cfg._impl_path is None
|
||||
# assert cfg.getattr('config', None, validate_properties=False)._impl_path == 'config'
|
||||
# assert cfg.getattr('config.tiramisu', None, validate_properties=False)._impl_path == 'config.tiramisu'
|
||||
|
||||
|
||||
def test_base_config_force_permissive():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
api = getapi(config)
|
||||
api.property.read_write()
|
||||
api.permissive.set(frozenset(['hidden']))
|
||||
raises(PropertiesOptionError, "api.option('boolop').value.get()")
|
||||
assert api.forcepermissive.option('boolop').value.get() is True
|
||||
|
||||
|
||||
def test_base_config_in_a_tree():
|
||||
"how options are organized into a tree, see :ref:`tree`"
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
api = getapi(config)
|
||||
#
|
||||
api.option('bool').value.set(False)
|
||||
#
|
||||
assert api.option('gc.name').value.get() == 'ref'
|
||||
api.option('gc.name').value.set('framework')
|
||||
assert api.option('gc.name').value.get() == 'framework'
|
||||
#
|
||||
assert api.option('objspace').value.get() == 'std'
|
||||
api.option('objspace').value.set('thunk')
|
||||
assert api.option('objspace').value.get() == 'thunk'
|
||||
#
|
||||
assert api.option('gc.float').value.get() == 2.3
|
||||
api.option('gc.float').value.set(3.4)
|
||||
assert api.option('gc.float').value.get() == 3.4
|
||||
#
|
||||
assert api.option('int').value.get() == 0
|
||||
api.option('int').value.set(123)
|
||||
assert api.option('int').value.get() == 123
|
||||
#
|
||||
assert api.option('wantref').value.get() is False
|
||||
api.option('wantref').value.set(True)
|
||||
assert api.option('wantref').value.get() is True
|
||||
#
|
||||
assert api.option('str').value.get() == 'abc'
|
||||
api.option('str').value.set('def')
|
||||
assert api.option('str').value.get() == 'def'
|
||||
#
|
||||
raises(AttributeError, "api.option('gc.foo').value.get()")
|
||||
##
|
||||
config = Config(descr)
|
||||
api = getapi(config)
|
||||
assert api.option('bool').value.get() is True
|
||||
assert api.option('gc.name').value.get() == 'ref'
|
||||
assert api.option('wantframework').value.get() is False
|
||||
|
||||
|
||||
#def test_cfgimpl_get_home_by_path():
|
||||
# " :meth:`tiramisu.config.SubConfig.cfgimpl_get_home_by_path()` to retrieve a path"
|
||||
# descr = make_description()
|
||||
# config = Config(descr)
|
||||
# api = getapi(config)
|
||||
# api.option('bool').value.set(False)
|
||||
# assert config.cfgimpl_get_home_by_path('gc.dummy', None)[1] == 'dummy'
|
||||
# assert config.cfgimpl_get_home_by_path('dummy', None)[1] == 'dummy'
|
||||
|
||||
|
||||
def test_not_valid_properties():
|
||||
raises(TypeError, "stroption = StrOption('str', 'Test string option', default='abc', properties=['mandatory',])")
|
||||
|
||||
|
||||
def test_information_config():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
api = getapi(config)
|
||||
string = 'some informations'
|
||||
#
|
||||
api.information.set('info', string)
|
||||
assert api.information.get('info') == string
|
||||
#
|
||||
raises(ValueError, "api.information.get('noinfo')")
|
||||
assert api.information.get('noinfo', 'default') == 'default'
|
||||
api.information.reset('info')
|
||||
raises(ValueError, "api.information.get('info')")
|
||||
raises(ValueError, "api.information.reset('noinfo')")
|
||||
|
||||
|
||||
def test_config_impl_get_path_by_opt():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
api = getapi(config)
|
||||
dummy = api.option.get('gc.dummy')
|
||||
boo = api.option.get('bool')
|
||||
unknown = IntOption('test', '')
|
||||
unknown
|
||||
assert config.cfgimpl_get_description().impl_get_path_by_opt(boo) == 'bool'
|
||||
assert config.cfgimpl_get_description().impl_get_path_by_opt(dummy) == 'gc.dummy'
|
||||
raises(AttributeError, "config.cfgimpl_get_description().impl_get_path_by_opt(unknown)")
|
||||
|
||||
|
||||
#def test_config_impl_get_path_by_opt_od():
|
||||
# descr = make_description()
|
||||
# config = Config(descr)
|
||||
# api = getapi(config)
|
||||
# dummy = api.option.get('gc.dummy')
|
||||
# dummy
|
||||
# raises(ConfigError, "config.getattr('gc', None).cfgimpl_get_description().impl_get_path_by_opt(dummy)")
|
||||
#
|
||||
#
|
||||
#def test_config_impl_get_opt_by_path():
|
||||
# descr = make_description()
|
||||
# config = Config(descr)
|
||||
# api = getapi(config)
|
||||
# dummy = api.option.get('gc.dummy')
|
||||
# boo = api.option.get('bool')
|
||||
# assert config.cfgimpl_get_description().impl_get_opt_by_path('bool') == boo
|
||||
# assert config.cfgimpl_get_description().impl_get_opt_by_path('gc.dummy') == dummy
|
||||
# raises(AttributeError, "config.cfgimpl_get_description().impl_get_opt_by_path('gc.unknown')")
|
||||
# raises(ConfigError, "config.getattr('gc', None).cfgimpl_get_description().impl_get_opt_by_path('gc.unknown')")
|
||||
|
||||
|
||||
#def test_information_display():
|
||||
# g1 = IntOption('g1', '', 1)
|
||||
# g2 = StrOption('g2', '', 'héhé')
|
||||
# g3 = UnicodeOption('g3', '', u'héhé')
|
||||
# g4 = BoolOption('g4', '', True)
|
||||
# g5 = StrOption('g5', '')
|
||||
# d1 = OptionDescription('od', '', [g1, g2, g3, g4, g5])
|
||||
# root = OptionDescription('root', '', [d1])
|
||||
# config = Config(root)
|
||||
# assert str(config.od) == """g1 = 1
|
||||
#g2 = héhé
|
||||
#g3 = héhé
|
||||
#g4 = True
|
||||
#g5 = None"""
|
||||
# assert str(config) == '[od]'
|
||||
|
||||
|
||||
def test_get_modified_values():
|
||||
g1 = IntOption('g1', '', 1)
|
||||
g2 = StrOption('g2', '', 'héhé')
|
||||
g3 = UnicodeOption('g3', '', u'héhé')
|
||||
g4 = BoolOption('g4', '', True)
|
||||
g5 = StrOption('g5', '')
|
||||
g6 = StrOption('g6', '', multi=True)
|
||||
d1 = OptionDescription('od', '', [g1, g2, g3, g4, g5, g6])
|
||||
root = OptionDescription('root', '', [d1])
|
||||
config = Config(root)
|
||||
api = getapi(config)
|
||||
assert config.cfgimpl_get_values().get_modified_values() == {}
|
||||
api.option('od.g5').value.set('yes')
|
||||
assert config.cfgimpl_get_values().get_modified_values() == {'od.g5': ('user', 'yes')}
|
||||
api.option('od.g4').value.set(True)
|
||||
assert config.cfgimpl_get_values().get_modified_values() == {'od.g5': ('user', 'yes'), 'od.g4': ('user', True)}
|
||||
api.option('od.g4').value.reset()
|
||||
assert config.cfgimpl_get_values().get_modified_values() == {'od.g5': ('user', 'yes')}
|
||||
api.option('od.g6').value.set([undefined])
|
||||
assert config.cfgimpl_get_values().get_modified_values() == {'od.g5': ('user', 'yes'), 'od.g6': ('user', (None,))}
|
||||
api.option('od.g6').value.set([])
|
||||
assert config.cfgimpl_get_values().get_modified_values() == {'od.g5': ('user', 'yes'), 'od.g6': ('user', tuple())}
|
||||
api.option('od.g6').value.set(['3'])
|
||||
assert config.cfgimpl_get_values().get_modified_values() == {'od.g5': ('user', 'yes'), 'od.g6': ('user', ('3',))}
|
||||
api.option('od.g6').value.set([])
|
||||
assert config.cfgimpl_get_values().get_modified_values() == {'od.g5': ('user', 'yes'), 'od.g6': ('user', tuple())}
|
||||
|
||||
|
||||
#def test_has_value():
|
||||
# g1 = IntOption('g1', '', 1)
|
||||
# g2 = StrOption('g2', '', 'héhé')
|
||||
# g3 = UnicodeOption('g3', '', u'héhé')
|
||||
# g4 = BoolOption('g4', '', True)
|
||||
# g5 = StrOption('g5', '')
|
||||
# d1 = OptionDescription('od', '', [g1, g2, g3, g4, g5])
|
||||
# root = OptionDescription('root', '', [d1])
|
||||
# config = Config(root)
|
||||
# api = getapi(config)
|
||||
# assert not g5 in config.cfgimpl_get_values()
|
||||
# api.option('od.g5').value.set('yes')
|
||||
# assert g5 in config.cfgimpl_get_values()
|
||||
|
||||
|
||||
#def test_values_not_setitem():
|
||||
# g1 = IntOption('g1', '', 1)
|
||||
# g2 = StrOption('g2', '', 'héhé')
|
||||
# g3 = UnicodeOption('g3', '', u'héhé')
|
||||
# g4 = BoolOption('g4', '', True)
|
||||
# g5 = StrOption('g5', '')
|
||||
# d1 = OptionDescription('od', '', [g1, g2, g3, g4, g5])
|
||||
# root = OptionDescription('root', '', [d1])
|
||||
# config = Config(root)
|
||||
# config
|
||||
# raises(ConfigError, "config.cfgimpl_get_values()[g1] = 2")
|
||||
|
||||
|
||||
def test_duplicated_option():
|
||||
g1 = IntOption('g1', '', 1)
|
||||
g1
|
||||
#in same OptionDescription
|
||||
raises(ConflictError, "d1 = OptionDescription('od', '', [g1, g1])")
|
||||
|
||||
|
||||
def test_duplicated_option_diff_od():
|
||||
g1 = IntOption('g1', '', 1)
|
||||
d1 = OptionDescription('od1', '', [g1])
|
||||
#in different OptionDescription
|
||||
d2 = OptionDescription('od2', '', [g1, d1])
|
||||
d2
|
||||
raises(ConflictError, 'Config(d2)')
|
||||
|
||||
|
||||
def test_cannot_assign_value_to_option_description():
|
||||
descr = make_description()
|
||||
cfg = Config(descr)
|
||||
api = getapi(cfg)
|
||||
api
|
||||
raises(APIError, "api.option('gc').value.set(3)")
|
||||
|
||||
|
||||
def test_config_multi():
|
||||
i1 = IntOption('test1', '', multi=True)
|
||||
i2 = IntOption('test2', '', multi=True, default_multi=1)
|
||||
i3 = IntOption('test3', '', default=[2], multi=True, default_multi=1)
|
||||
od = OptionDescription('test', '', [i1, i2, i3])
|
||||
config = Config(od)
|
||||
api = getapi(config)
|
||||
assert api.option('test1').value.get() == []
|
||||
assert api.option('test2').value.get() == []
|
||||
api.option('test2').value.set([undefined])
|
||||
assert api.option('test2').value.get() == [1]
|
||||
assert api.option('test3').value.get() == [2]
|
||||
api.option('test3').value.set([undefined, undefined])
|
||||
assert api.option('test3').value.get() == [2, 1]
|
||||
|
||||
|
||||
def test_no_validation():
|
||||
i1 = IntOption('test1', '')
|
||||
od = OptionDescription('test', '', [i1])
|
||||
cfg = Config(od)
|
||||
api = getapi(cfg)
|
||||
api.property.read_write()
|
||||
api.option('test1').value.set(1)
|
||||
raises(ValueError, "api.option('test1').value.set('yes')")
|
||||
assert api.option('test1').value.get() == 1
|
||||
api.property.pop('validator')
|
||||
api.option('test1').value.set('yes')
|
||||
assert api.option('test1').value.get() == 'yes'
|
||||
api.property.add('validator')
|
||||
raises(ValueError, "api.option('test1').value.get()")
|
||||
api.option('test1').value.reset()
|
||||
assert api.option('test1').value.get() is None
|
||||
|
||||
|
||||
#def test_delete_config_with_subconfig():
|
||||
# test = IntOption('test', '')
|
||||
# multi = IntOption('multi', '', multi=True)
|
||||
# od = OptionDescription('od', '', [test, multi])
|
||||
# odroot = OptionDescription('odroot', '', [od])
|
||||
# cfg = Config(odroot)
|
||||
# api = getapi(cfg)
|
||||
# sub = cfg.od
|
||||
# val = cfg.cfgimpl_get_values()
|
||||
# setting = cfg.cfgimpl_get_settings()
|
||||
# assert api.option('od.test').value.get() is None
|
||||
# assert api.option('od.multi').value.get() == []
|
||||
# api.config.make_dict()
|
||||
# del(api)
|
||||
# del(cfg)
|
||||
# raises(ConfigError, 'val[test]')
|
||||
# raises(ConfigError, 'val[multi]')
|
||||
# raises(ConfigError, 'setting[test]')
|
||||
# raises(ConfigError, 'sub.make_dict()')
|
||||
|
||||
|
||||
def test_subconfig():
|
||||
i = IntOption('i', '')
|
||||
o = OptionDescription('val', '', [i])
|
||||
o2 = OptionDescription('val', '', [o])
|
||||
c = Config(o2)
|
||||
c
|
||||
raises(TypeError, "SubConfig(i, weakref.ref(c))")
|
||||
|
||||
|
||||
#def test_config_weakref():
|
||||
# o = OptionDescription('val', '', [])
|
||||
# o2 = OptionDescription('val', '', [o])
|
||||
# c = Config(o2)
|
||||
# SubConfig(o, weakref.ref(c))
|
||||
# raises(ValueError, "SubConfig(o, c)")
|
||||
# s = SubConfig(o, weakref.ref(c))
|
||||
# assert s._cfgimpl_get_context() == c
|
||||
# del(c)
|
||||
# raises(ConfigError, "s._cfgimpl_get_context()")
|
||||
|
||||
|
||||
#def test_config_str():
|
||||
# gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
# gcdummy1 = BoolOption('dummy1', 'dummy', default=False, properties=('disabled',))
|
||||
# o = OptionDescription('o', '', [gcdummy, gcdummy1])
|
||||
# descr = OptionDescription('tiramisu', '', [o])
|
||||
# cfg = Config(descr)
|
||||
# api = getapi(cfg)
|
||||
# api.property.read_only()
|
||||
# str(cfg)
|
||||
# str(cfg.o)
|
||||
|
||||
|
||||
#def test_config_od_function():
|
||||
# gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
# gcdummy1 = BoolOption('dummy1', 'dummy', default=False, properties=('disabled',))
|
||||
# o = OptionDescription('o', '', [gcdummy, gcdummy1])
|
||||
# descr = OptionDescription('tiramisu', '', [o])
|
||||
# cfg = Config(descr)
|
||||
# try:
|
||||
# print(cfg.impl_get_opt_by_path())
|
||||
# except AttributeError as err:
|
||||
# assert str(err) == _('unknown Option {0} in OptionDescription {1}'
|
||||
# '').format('impl_get_opt_by_path', descr.impl_getname())
|
||||
|
||||
|
||||
def test_config_subconfig():
|
||||
i1 = IntOption('i1', '')
|
||||
i2 = IntOption('i2', '', default=1)
|
||||
i3 = IntOption('i3', '')
|
||||
i4 = IntOption('i4', '', default=2)
|
||||
od1 = OptionDescription('od1', '', [i1, i2, i3, i4])
|
||||
od2 = OptionDescription('od2', '', [od1])
|
||||
conf1 = Config(od2, session_id='conf1')
|
||||
api = getapi(conf1)
|
||||
raises(ConfigError, "conf2 = Config(od1, session_id='conf2')")
|
||||
|
|
@ -1,387 +0,0 @@
|
|||
"configuration objects global API"
|
||||
from py.test import raises
|
||||
|
||||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
|
||||
from tiramisu import Config, IntOption, FloatOption, StrOption, ChoiceOption, \
|
||||
BoolOption, FilenameOption, UnicodeOption, SymLinkOption, IPOption, \
|
||||
PortOption, NetworkOption, NetmaskOption, BroadcastOption, \
|
||||
DomainnameOption, OptionDescription, getapi
|
||||
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',))
|
||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||
('std', 'thunk'), 'std')
|
||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||
booloption2 = BoolOption('bool', 'Test boolean option', default=False)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
floatoption2 = FloatOption('float', 'Test float option', default=2.3)
|
||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
|
||||
wantref_option = BoolOption('wantref', 'Tests', default=False)
|
||||
wantframework_option = BoolOption('wantframework', 'Test', default=False)
|
||||
gcgroup2 = OptionDescription('gc2', '', [booloption2, prop])
|
||||
gcgroup = OptionDescription('gc', '', [gcgroup2, gcoption, gcdummy, floatoption, prop2])
|
||||
descr = OptionDescription('tiramisu', '', [gcgroup, booloption, objspaceoption,
|
||||
wantref_option, stroption,
|
||||
wantframework_option,
|
||||
intoption, boolop, floatoption2])
|
||||
return descr
|
||||
|
||||
|
||||
def _is_same_opt(opt1, opt2):
|
||||
if "id" in dir(opt1):
|
||||
assert opt1.id == opt2.id
|
||||
else:
|
||||
assert opt1 == opt2
|
||||
|
||||
|
||||
#def test_iter_config():
|
||||
# "iteration on config object"
|
||||
# s = StrOption("string", "", default="string")
|
||||
# s2 = StrOption("string2", "", default="string2")
|
||||
# descr = OptionDescription("options", "", [s, s2])
|
||||
# config = Config(descr)
|
||||
# assert [(name, value) for name, value in config] == \
|
||||
# [('string', 'string'), ('string2', 'string2')]
|
||||
#
|
||||
#
|
||||
#def test_iter_config_property():
|
||||
# "iteration on config object"
|
||||
# s = StrOption("string", "", default="string", properties=('disabled',))
|
||||
# s2 = StrOption("string2", "", default="string2")
|
||||
# descr = OptionDescription("options", "", [s, s2])
|
||||
# config = Config(descr)
|
||||
# config.read_only()
|
||||
# assert [(name, value) for name, value in config] == \
|
||||
# [('string2', 'string2')]
|
||||
#
|
||||
#
|
||||
#def test_iter_subconfig():
|
||||
# "iteration on config sub object"
|
||||
# descr = make_description()
|
||||
# conf = Config(descr)
|
||||
# for (name, value), (gname, gvalue) in \
|
||||
# zip(conf.gc, [("name", "ref"), ("dummy", False)]):
|
||||
# assert name == gname
|
||||
# assert value == gvalue
|
||||
|
||||
|
||||
def test_str():
|
||||
descr = make_description()
|
||||
c = Config(descr)
|
||||
c # does not crash
|
||||
|
||||
|
||||
def test_make_dict():
|
||||
"serialization of the whole config to a dict"
|
||||
descr = OptionDescription("opt", "", [
|
||||
OptionDescription("s1", "", [
|
||||
BoolOption("a", "", default=False),
|
||||
BoolOption("b", "", default=False, properties=('hidden',))]),
|
||||
IntOption("int", "", default=42)])
|
||||
config = Config(descr)
|
||||
api = getapi(config)
|
||||
api.property.read_write()
|
||||
api.permissive.set(frozenset(['hidden']))
|
||||
d = api.option.make_dict()
|
||||
assert d == {"s1.a": False, "int": 42}
|
||||
api.option('int').value.set(43)
|
||||
api.option('s1.a').value.set(True)
|
||||
d = api.option.make_dict()
|
||||
assert d == {"s1.a": True, "int": 43}
|
||||
d2 = api.option.make_dict(flatten=True)
|
||||
assert d2 == {'a': True, 'int': 43}
|
||||
raises(ValueError, 'd2 = api.option.make_dict(withvalue="3")')
|
||||
d = api.forcepermissive.option.make_dict()
|
||||
assert d == {"s1.a": True, "s1.b": False, "int": 43}
|
||||
|
||||
|
||||
def test_make_dict_with_disabled():
|
||||
descr = OptionDescription("opt", "", [
|
||||
OptionDescription("s1", "", [
|
||||
BoolOption("a", "", default=False),
|
||||
BoolOption("b", "", default=False, properties=('disabled',))]),
|
||||
OptionDescription("s2", "", [
|
||||
BoolOption("a", "", default=False),
|
||||
BoolOption("b", "", default=False)], properties=('disabled',)),
|
||||
IntOption("int", "", default=42)])
|
||||
config = Config(descr)
|
||||
api = getapi(config)
|
||||
api.property.read_only()
|
||||
d = api.option.make_dict()
|
||||
assert d == {"s1.a": False, "int": 42}
|
||||
|
||||
|
||||
def test_make_dict_with_disabled_in_callback():
|
||||
descr = OptionDescription("opt", "", [
|
||||
OptionDescription("s1", "", [
|
||||
BoolOption("a", "", default=False),
|
||||
BoolOption("b", "", default=False, properties=('disabled',))]),
|
||||
OptionDescription("s2", "", [
|
||||
BoolOption("a", "", default=False),
|
||||
BoolOption("b", "", default=False)], properties=('disabled',)),
|
||||
IntOption("int", "", default=42)])
|
||||
config = Config(descr)
|
||||
api = getapi(config)
|
||||
api.property.read_only()
|
||||
d = api.option.make_dict()
|
||||
assert d == {"s1.a": False, "int": 42}
|
||||
|
||||
|
||||
def test_make_dict_fullpath():
|
||||
descr = OptionDescription("root", "", [
|
||||
OptionDescription("opt", "", [
|
||||
OptionDescription("s1", "", [
|
||||
BoolOption("a", "", default=False),
|
||||
BoolOption("b", "", default=False, properties=('disabled',))]),
|
||||
OptionDescription("s2", "", [
|
||||
BoolOption("a", "", default=False),
|
||||
BoolOption("b", "", default=False)], properties=('disabled',)),
|
||||
IntOption("int", "", default=42)]),
|
||||
IntOption("introot", "", default=42)])
|
||||
config = Config(descr)
|
||||
api = getapi(config)
|
||||
api.property.read_only()
|
||||
assert api.option.make_dict() == {"opt.s1.a": False, "opt.int": 42, "introot": 42}
|
||||
assert api.option('opt').make_dict() == {"s1.a": False, "int": 42}
|
||||
assert api.option.make_dict(fullpath=True) == {"opt.s1.a": False, "opt.int": 42, "introot": 42}
|
||||
assert api.option('opt').make_dict(fullpath=True) == {"opt.s1.a": False, "opt.int": 42}
|
||||
|
||||
|
||||
def test_find_in_config():
|
||||
"finds option in config"
|
||||
descr = make_description()
|
||||
conf = Config(descr)
|
||||
api = getapi(conf)
|
||||
api.property.read_only()
|
||||
api.permissive.set(frozenset(['hidden']))
|
||||
ret = api.option.find('dummy')
|
||||
assert len(ret) == 1
|
||||
_is_same_opt(ret[0], api.option.get('gc.dummy'))
|
||||
#
|
||||
ret = api.option.find_first('dummy')
|
||||
_is_same_opt(ret, api.option.get('gc.dummy'))
|
||||
#
|
||||
ret = api.option.find('float')
|
||||
assert len(ret) == 2
|
||||
_is_same_opt(ret[0], api.option.get('gc.float'))
|
||||
_is_same_opt(ret[1], api.option.get('float'))
|
||||
#
|
||||
_is_same_opt(api.option.find_first('bool'), api.option.get('gc.gc2.bool'))
|
||||
#_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'))
|
||||
#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 = 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')")
|
||||
|
||||
|
||||
#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_does_not_find_in_config():
|
||||
descr = make_description()
|
||||
conf = Config(descr)
|
||||
api = getapi(conf)
|
||||
api
|
||||
raises(AttributeError, "api.option.find('IDontExist')")
|
||||
|
||||
|
||||
def test_filename():
|
||||
a = FilenameOption('a', '')
|
||||
o = OptionDescription('o', '', [a])
|
||||
cfg = Config(o)
|
||||
api = getapi(cfg)
|
||||
api.option('a').value.set('/')
|
||||
api.option('a').value.set('/tmp')
|
||||
api.option('a').value.set('/tmp/')
|
||||
api.option('a').value.set('/tmp/text.txt')
|
||||
api.option('a').value.set('tmp')
|
||||
api.option('a').value.set('tmp/')
|
||||
api.option('a').value.set('tmp/text.txt')
|
||||
raises(ValueError, "api.option('a').value.set('/tmp/with space.txt')")
|
||||
raises(ValueError, "api.option('a').value.set('/tmp/with$.txt')")
|
||||
|
||||
|
||||
#def test_iter_all():
|
||||
# s = StrOption("string", "", default="string")
|
||||
# s2 = StrOption("string2", "", default="string2")
|
||||
# descr = OptionDescription("options", "", [s, s2])
|
||||
# config = Config(descr)
|
||||
# assert list(config.iter_all()) == [('string', 'string'), ('string2', 'string2')]
|
||||
# for i in config.iter_all():
|
||||
# #test StopIteration
|
||||
# break
|
||||
#
|
||||
#
|
||||
#def test_iter_all_force_permissive():
|
||||
# s = StrOption("string", "", default="string")
|
||||
# s2 = StrOption("string2", "", default="string2")
|
||||
# s3 = StrOption("string3", "", default="string3", properties=('hidden',))
|
||||
# descr = OptionDescription("options", "", [s, s2, s3])
|
||||
# config = Config(descr)
|
||||
# api = getapi(config)
|
||||
# api.property.read_write()
|
||||
# api.permissive.set(('hidden',))
|
||||
# assert list(config.iter_all()) == [('string', 'string'), ('string2', 'string2')]
|
||||
# assert list(config.iter_all(force_permissive=True)) == [('string', 'string'),
|
||||
# ('string2', 'string2'),
|
||||
# ('string3', 'string3')]
|
||||
#
|
||||
#
|
||||
#def test_iter_all_prop():
|
||||
# s = StrOption("string", "", default="string", properties=('disabled',))
|
||||
# s2 = StrOption("string2", "", default="string2")
|
||||
# descr = OptionDescription("options", "", [s, s2])
|
||||
# config = Config(descr)
|
||||
# api = getapi(config)
|
||||
# api.property.read_only()
|
||||
# assert list(config.iter_all()) == [('string2', 'string2')]
|
||||
|
||||
|
||||
#def test_impl_getpaths():
|
||||
# s = StrOption("string", "", default="string", properties=('disabled',))
|
||||
# s2 = StrOption("string2", "", default="string2")
|
||||
# s3 = StrOption("string3", "", default="string3")
|
||||
# s4 = StrOption("string4", "", default="string4", properties=('hidden',))
|
||||
# od = OptionDescription('od', '', [s3, s4])
|
||||
# descr = OptionDescription("options", "", [s, s2, od])
|
||||
# config = Config(descr)
|
||||
# assert ['string', 'string2', 'od.string3', 'od.string4'] == config.cfgimpl_get_description().impl_getpaths()
|
||||
# assert ['string', 'string2', 'od', 'od.string3', 'od.string4'] == config.cfgimpl_get_description().impl_getpaths(include_groups=True)
|
||||
# config.read_write()
|
||||
# raises(PropertiesOptionError, "config.od.string4")
|
||||
# assert ['string', 'string2', 'od.string3', 'od.string4'] == config.cfgimpl_get_description().impl_getpaths()
|
||||
# assert ['string', 'string2', 'od', 'od.string3', 'od.string4'] == config.cfgimpl_get_description().impl_getpaths(include_groups=True)
|
||||
|
||||
|
||||
def test_invalid_option():
|
||||
ChoiceOption('a', '', ('1', '2'))
|
||||
raises(TypeError, "ChoiceOption('a', '', [1, 2])")
|
||||
raises(TypeError, "ChoiceOption('a', '', 1)")
|
||||
raises(ValueError, "ChoiceOption('a', '', (1,), 3)")
|
||||
FloatOption('a', '')
|
||||
raises(ValueError, "FloatOption('a', '', 'string')")
|
||||
UnicodeOption('a', '')
|
||||
raises(ValueError, "UnicodeOption('a', '', 1)")
|
||||
u = UnicodeOption('a', '')
|
||||
SymLinkOption('a', u)
|
||||
raises(ValueError, "SymLinkOption('a', 'string')")
|
||||
IPOption('a', '')
|
||||
raises(ValueError, "IPOption('a', '', 1)")
|
||||
raises(ValueError, "IPOption('a', '', 'string')")
|
||||
PortOption('a', '')
|
||||
raises(ValueError, "PortOption('a', '', 'string')")
|
||||
raises(ValueError, "PortOption('a', '', '11:12:13', allow_range=True)")
|
||||
raises(ValueError, "PortOption('a', '', 11111111111111111111)")
|
||||
raises(ValueError, "PortOption('a', '', allow_zero=True, allow_wellknown=False, allow_registred=True, allow_private=False)")
|
||||
raises(ValueError, "PortOption('a', '', allow_zero=True, allow_wellknown=True, allow_registred=False, allow_private=True)")
|
||||
raises(ValueError, "PortOption('a', '', allow_zero=True, allow_wellknown=False, allow_registred=False, allow_private=True)")
|
||||
raises(ValueError, "PortOption('a', '', allow_zero=True, allow_wellknown=False, allow_registred=True, allow_private=True)")
|
||||
raises(ValueError, "PortOption('a', '', allow_zero=False, allow_wellknown=False, allow_registred=False, allow_private=False)")
|
||||
NetworkOption('a', '')
|
||||
raises(ValueError, "NetworkOption('a', '', 'string')")
|
||||
NetmaskOption('a', '')
|
||||
raises(ValueError, "NetmaskOption('a', '', 'string')")
|
||||
BroadcastOption('a', '')
|
||||
raises(ValueError, "BroadcastOption('a', '', 'string')")
|
||||
DomainnameOption('a', '')
|
||||
raises(ValueError, "DomainnameOption('a', '', 'string')")
|
||||
raises(ValueError, "DomainnameOption('a', '', type_='string')")
|
||||
raises(ValueError, "DomainnameOption('a', '', allow_ip='string')")
|
||||
raises(ValueError, "DomainnameOption('a', '', allow_without_dot='string')")
|
||||
raises(ValueError, "DomainnameOption('a', '', 1)")
|
||||
#
|
||||
ChoiceOption('a', '', (1,), multi=True, default_multi=1)
|
||||
raises(ValueError, "ChoiceOption('a', '', (1,), default_multi=1)")
|
||||
raises(ValueError, "ChoiceOption('a', '', (1,), multi=True, default=[1,], default_multi=2)")
|
||||
raises(ValueError, "FloatOption('a', '', multi=True, default_multi='string')")
|
||||
raises(ValueError, "UnicodeOption('a', '', multi=True, default_multi=1)")
|
||||
raises(ValueError, "IPOption('a', '', multi=True, default_multi=1)")
|
||||
raises(ValueError, "IPOption('a', '', multi=True, default_multi='string')")
|
||||
raises(ValueError, "PortOption('a', '', multi=True, default_multi='string')")
|
||||
raises(ValueError, "PortOption('a', '', multi=True, default_multi='11:12:13', allow_range=True)")
|
||||
raises(ValueError, "PortOption('a', '', multi=True, default_multi=11111111111111111111)")
|
||||
raises(ValueError, "NetworkOption('a', '', multi=True, default_multi='string')")
|
||||
raises(ValueError, "NetmaskOption('a', '', multi=True, default_multi='string')")
|
||||
raises(ValueError, "BroadcastOption('a', '', multi=True, default_multi='string')")
|
||||
raises(ValueError, "DomainnameOption('a', '', multi=True, default_multi='string')")
|
||||
raises(ValueError, "DomainnameOption('a', '', multi=True, default_multi=1)")
|
||||
|
|
@ -1,178 +0,0 @@
|
|||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
|
||||
import warnings, sys
|
||||
from py.test import raises
|
||||
|
||||
from tiramisu.config import Config
|
||||
from tiramisu.option import DomainnameOption, EmailOption, URLOption, OptionDescription
|
||||
from tiramisu.error import ValueWarning
|
||||
from tiramisu.i18n import _
|
||||
from tiramisu import getapi
|
||||
|
||||
|
||||
def test_domainname():
|
||||
d = DomainnameOption('d', '')
|
||||
f = DomainnameOption('f', '', allow_without_dot=True)
|
||||
g = DomainnameOption('g', '', allow_ip=True)
|
||||
od = OptionDescription('a', '', [d, f, g])
|
||||
c = Config(od)
|
||||
api = getapi(c)
|
||||
api.property.read_write()
|
||||
api.option('d').value.set('toto.com')
|
||||
raises(ValueError, "api.option('d').value.set('toto')")
|
||||
api.option('d').value.set('toto3.com')
|
||||
raises(ValueError, "api.option('d').value.set('toto_super.com')")
|
||||
api.option('d').value.set('toto-.com')
|
||||
raises(ValueError, "api.option('d').value.set('toto..com')")
|
||||
#
|
||||
api.option('f').value.set('toto.com')
|
||||
api.option('f').value.set('toto')
|
||||
api.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea')
|
||||
raises(ValueError, "api.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamean')")
|
||||
api.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nd')
|
||||
api.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnameto.olongthathavemorethanmaximumsizeforatruedomainnameanditsnoteas.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowie')
|
||||
raises(ValueError, "api.option('d').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnameto.olongthathavemorethanmaximumsizeforatruedomainnameanditsnoteas.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowien')")
|
||||
api.option('f').value.set('d')
|
||||
api.option('f').value.set('d.t')
|
||||
#
|
||||
raises(ValueError, "api.option('f').value.set('192.168.1.1')")
|
||||
api.option('g').value.set('toto.com')
|
||||
api.option('g').value.set('192.168.1.0')
|
||||
api.option('g').value.set('192.168.1.29')
|
||||
|
||||
|
||||
def test_domainname_upper():
|
||||
d = DomainnameOption('d', '')
|
||||
od = OptionDescription('a', '', [d])
|
||||
c = Config(od)
|
||||
api = getapi(c)
|
||||
api.property.read_write()
|
||||
api.option('d').value.set('toto.com')
|
||||
msg = _('some characters are uppercase')
|
||||
has_error = False
|
||||
try:
|
||||
api.option('d').value.set('TOTO.COM')
|
||||
except ValueError as err:
|
||||
assert msg in str(err)
|
||||
has_error = True
|
||||
assert has_error is True
|
||||
has_error = False
|
||||
try:
|
||||
api.option('d').value.set('toTo.com')
|
||||
except ValueError as err:
|
||||
assert msg in str(err)
|
||||
has_error = True
|
||||
assert has_error is True
|
||||
|
||||
|
||||
def test_domainname_warning():
|
||||
d = DomainnameOption('d', '', warnings_only=True)
|
||||
f = DomainnameOption('f', '', allow_without_dot=True, warnings_only=True)
|
||||
g = DomainnameOption('g', '', allow_ip=True, warnings_only=True)
|
||||
od = OptionDescription('a', '', [d, f, g])
|
||||
warnings.simplefilter("always", ValueWarning)
|
||||
c = Config(od)
|
||||
api = getapi(c)
|
||||
api.property.read_write()
|
||||
api.option('d').value.set('toto.com')
|
||||
raises(ValueError, "api.option('d').value.set('toto')")
|
||||
api.option('d').value.set('toto3.com')
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('d').value.set('toto_super.com')
|
||||
assert len(w) == 1
|
||||
api.option('d').value.set('toto-.com')
|
||||
raises(ValueError, "api.option('d').value.set('toto..com')")
|
||||
#
|
||||
api.option('f').value.set('toto.com')
|
||||
api.option('f').value.set('toto')
|
||||
api.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea')
|
||||
raises(ValueError, "api.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamean')")
|
||||
api.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nd')
|
||||
api.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnameto.olongthathavemorethanmaximumsizeforatruedomainnameanditsnoteas.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowie')
|
||||
raises(ValueError, "api.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainname.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnamet.olongthathavemorethanmaximumsizeforatruedomainnameanditsnotea.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowie.xxxx')")
|
||||
api.option('f').value.set('d')
|
||||
api.option('f').value.set('d.t')
|
||||
#
|
||||
raises(ValueError, "api.option('f').value.set('192.168.1.1')")
|
||||
api.option('g').value.set('toto.com')
|
||||
api.option('g').value.set('192.168.1.0')
|
||||
api.option('g').value.set('192.168.1.29')
|
||||
|
||||
|
||||
def test_special_domain_name():
|
||||
"""domain name option that starts with a number or not
|
||||
"""
|
||||
d = DomainnameOption('d', '')
|
||||
e = DomainnameOption('e', '', type_='netbios')
|
||||
od = OptionDescription('a', '', [d, e])
|
||||
c = Config(od)
|
||||
api = getapi(c)
|
||||
api.property.read_write()
|
||||
api.option('d').value.set('1toto.com')
|
||||
api.option('d').value.set('123toto.com')
|
||||
api.option('e').value.set('toto')
|
||||
api.option('e').value.set('1toto')
|
||||
|
||||
|
||||
def test_domainname_netbios():
|
||||
d = DomainnameOption('d', '', type_='netbios')
|
||||
e = DomainnameOption('e', '', "toto", type_='netbios')
|
||||
od = OptionDescription('a', '', [d, e])
|
||||
c = Config(od)
|
||||
api = getapi(c)
|
||||
api.property.read_write()
|
||||
raises(ValueError, "api.option('d').value.set('toto.com')")
|
||||
api.option('d').value.set('toto')
|
||||
raises(ValueError, "api.option('d').value.set('domainnametoolong')")
|
||||
|
||||
|
||||
def test_domainname_hostname():
|
||||
d = DomainnameOption('d', '', type_='hostname')
|
||||
e = DomainnameOption('e', '', "toto", type_='hostname')
|
||||
od = OptionDescription('a', '', [d, e])
|
||||
c = Config(od)
|
||||
api = getapi(c)
|
||||
api.property.read_write()
|
||||
raises(ValueError, "api.option('d').value.set('toto.com')")
|
||||
api.option('d').value.set('toto')
|
||||
api.option('d').value.set('domainnametoolong')
|
||||
|
||||
|
||||
def test_email():
|
||||
e = EmailOption('e', '')
|
||||
od = OptionDescription('a', '', [e])
|
||||
c = Config(od)
|
||||
api = getapi(c)
|
||||
api.property.read_write()
|
||||
api.option('e').value.set('foo-bar.baz@example.com')
|
||||
api.option('e').value.set('root@foo.com')
|
||||
api.option('e').value.set('root@domain')
|
||||
raises(ValueError, "api.option('e').value.set(1)")
|
||||
raises(ValueError, "api.option('e').value.set('root')")
|
||||
raises(ValueError, "api.option('e').value.set('root[]@domain')")
|
||||
|
||||
|
||||
def test_url():
|
||||
u = URLOption('u', '')
|
||||
od = OptionDescription('a', '', [u])
|
||||
c = Config(od)
|
||||
api = getapi(c)
|
||||
api.property.read_write()
|
||||
api.option('u').value.set('http://foo.com')
|
||||
api.option('u').value.set('https://foo.com')
|
||||
api.option('u').value.set('https://foo.com/')
|
||||
raises(ValueError, "api.option('u').value.set(1)")
|
||||
raises(ValueError, "api.option('u').value.set('ftp://foo.com')")
|
||||
raises(ValueError, "api.option('u').value.set('foo.com')")
|
||||
raises(ValueError, "api.option('u').value.set(':/foo.com')")
|
||||
raises(ValueError, "api.option('u').value.set('foo.com/http://')")
|
||||
api.option('u').value.set('https://foo.com/index.html')
|
||||
api.option('u').value.set('https://foo.com/index.html?var=value&var2=val2')
|
||||
raises(ValueError, "api.option('u').value.set('https://foo.com/index\\n.html')")
|
||||
api.option('u').value.set('https://foo.com:8443')
|
||||
api.option('u').value.set('https://foo.com:8443/')
|
||||
api.option('u').value.set('https://foo.com:8443/index.html')
|
||||
raises(ValueError, "api.option('u').value.set('https://foo.com:84438989')")
|
||||
api.option('u').value.set('https://foo.com:8443/INDEX')
|
||||
raises(ValueError, "api.option('u').value.set('https://FOO.COM:8443')")
|
||||
|
|
@ -1,254 +0,0 @@
|
|||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
|
||||
import warnings
|
||||
from py.test import raises
|
||||
from tiramisu import Config ,IPOption, NetworkOption, NetmaskOption, \
|
||||
PortOption, BroadcastOption, OptionDescription, getapi
|
||||
from tiramisu.error import ValueWarning
|
||||
|
||||
|
||||
def test_ip():
|
||||
a = IPOption('a', '')
|
||||
b = IPOption('b', '', private_only=True)
|
||||
d = IPOption('d', '', warnings_only=True, private_only=True)
|
||||
warnings.simplefilter("always", ValueWarning)
|
||||
od = OptionDescription('od', '', [a, b, d])
|
||||
c = Config(od)
|
||||
api = getapi(c)
|
||||
api.option('a').value.set('192.168.1.1')
|
||||
api.option('a').value.set('192.168.1.0')
|
||||
api.option('a').value.set('88.88.88.88')
|
||||
api.option('a').value.set('0.0.0.0')
|
||||
raises(ValueError, "api.option('a').value.set('255.255.255.0')")
|
||||
api.option('b').value.set('192.168.1.1')
|
||||
api.option('b').value.set('192.168.1.0')
|
||||
raises(ValueError, "api.option('b').value.set('88.88.88.88')")
|
||||
api.option('b').value.set('0.0.0.0')
|
||||
raises(ValueError, "api.option('b').value.set('255.255.255.0')")
|
||||
raises(ValueError, "api.option('a').value.set('333.0.1.20')")
|
||||
|
||||
raises(ValueError, "IPOption('a', 'ip', default='192.000.023.01')")
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('d').value.set('88.88.88.88')
|
||||
assert len(w) == 1
|
||||
|
||||
|
||||
def test_ip_default():
|
||||
a = IPOption('a', '', '88.88.88.88')
|
||||
od = OptionDescription('od', '', [a])
|
||||
c = Config(od)
|
||||
api = getapi(c)
|
||||
api.option('a').value.get() == '88.88.88.88'
|
||||
|
||||
|
||||
def test_ip_reserved():
|
||||
a = IPOption('a', '')
|
||||
b = IPOption('b', '', allow_reserved=True)
|
||||
c = IPOption('c', '', warnings_only=True)
|
||||
od = OptionDescription('od', '', [a, b, c])
|
||||
warnings.simplefilter("always", ValueWarning)
|
||||
cfg = Config(od)
|
||||
api = getapi(cfg)
|
||||
raises(ValueError, "api.option('a').value.set('226.94.1.1')")
|
||||
api.option('b').value.set('226.94.1.1')
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('c').value.set('226.94.1.1')
|
||||
assert len(w) == 1
|
||||
|
||||
|
||||
def test_network():
|
||||
a = NetworkOption('a', '')
|
||||
b = NetworkOption('b', '', warnings_only=True)
|
||||
od = OptionDescription('od', '', [a, b])
|
||||
warnings.simplefilter("always", ValueWarning)
|
||||
c = Config(od)
|
||||
api = getapi(c)
|
||||
api.option('a').value.set('192.168.1.1')
|
||||
api.option('a').value.set('192.168.1.0')
|
||||
api.option('a').value.set('88.88.88.88')
|
||||
api.option('a').value.set('0.0.0.0')
|
||||
raises(ValueError, "api.option('a').value.set(1)")
|
||||
raises(ValueError, "api.option('a').value.set('1.1.1.1.1')")
|
||||
raises(ValueError, "api.option('a').value.set('255.255.255.0')")
|
||||
raises(ValueError, "api.option('a').value.set('192.168.001.0')")
|
||||
raises(ValueError, "api.option('a').value.set('333.168.1.1')")
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('b').value.set('255.255.255.0')
|
||||
assert len(w) == 1
|
||||
|
||||
|
||||
def test_network_invalid():
|
||||
raises(ValueError, "NetworkOption('a', '', default='toto')")
|
||||
|
||||
|
||||
def test_netmask():
|
||||
a = NetmaskOption('a', '')
|
||||
od = OptionDescription('od', '', [a])
|
||||
c = Config(od)
|
||||
api = getapi(c)
|
||||
raises(ValueError, "api.option('a').value.set('192.168.1.1.1')")
|
||||
raises(ValueError, "api.option('a').value.set('192.168.1.1')")
|
||||
raises(ValueError, "api.option('a').value.set('192.168.1.0')")
|
||||
raises(ValueError, "api.option('a').value.set('88.88.88.88')")
|
||||
raises(ValueError, "api.option('a').value.set('255.255.255.000')")
|
||||
raises(ValueError, "api.option('a').value.set(2)")
|
||||
api.option('a').value.set('0.0.0.0')
|
||||
api.option('a').value.set('255.255.255.0')
|
||||
|
||||
|
||||
def test_broadcast():
|
||||
a = BroadcastOption('a', '')
|
||||
od = OptionDescription('od', '', [a])
|
||||
c = Config(od)
|
||||
api = getapi(c)
|
||||
raises(ValueError, "api.option('a').value.set('192.168.1.255.1')")
|
||||
raises(ValueError, "api.option('a').value.set('192.168.001.255')")
|
||||
raises(ValueError, "api.option('a').value.set('192.168.0.300')")
|
||||
raises(ValueError, "api.option('a').value.set(1)")
|
||||
raises(ValueError, "api.option('a').value.set(2)")
|
||||
api.option('a').value.set('0.0.0.0')
|
||||
api.option('a').value.set('255.255.255.0')
|
||||
|
||||
|
||||
def test_port():
|
||||
a = PortOption('a', '')
|
||||
b = PortOption('b', '', allow_zero=True)
|
||||
c = PortOption('c', '', allow_zero=True, allow_registred=False)
|
||||
d = PortOption('d', '', allow_zero=True, allow_wellknown=False, allow_registred=False)
|
||||
e = PortOption('e', '', allow_zero=True, allow_private=True)
|
||||
f = PortOption('f', '', allow_private=True)
|
||||
od = OptionDescription('od', '', [a, b, c, d, e, f])
|
||||
c = Config(od)
|
||||
api = getapi(c)
|
||||
raises(ValueError, "api.option('a').value.set(0)")
|
||||
api.option('a').value.set(1)
|
||||
api.option('a').value.set(1023)
|
||||
api.option('a').value.set(1024)
|
||||
api.option('a').value.set(49151)
|
||||
raises(ValueError, "api.option('a').value.set(49152)")
|
||||
raises(ValueError, "api.option('a').value.set(65535)")
|
||||
raises(ValueError, "api.option('a').value.set(65536)")
|
||||
|
||||
api.option('b').value.set(0)
|
||||
api.option('b').value.set(1)
|
||||
api.option('b').value.set(1023)
|
||||
api.option('b').value.set(1024)
|
||||
api.option('b').value.set(49151)
|
||||
raises(ValueError, "api.option('b').value.set(49152)")
|
||||
raises(ValueError, "api.option('b').value.set(65535)")
|
||||
raises(ValueError, "api.option('b').value.set(65536)")
|
||||
|
||||
api.option('c').value.set(0)
|
||||
api.option('c').value.set(1)
|
||||
api.option('c').value.set(1023)
|
||||
raises(ValueError, "api.option('c').value.set(1024)")
|
||||
raises(ValueError, "api.option('c').value.set(49151)")
|
||||
raises(ValueError, "api.option('c').value.set(49152)")
|
||||
raises(ValueError, "api.option('c').value.set(65535)")
|
||||
raises(ValueError, "api.option('c').value.set(65536)")
|
||||
|
||||
api.option('d').value.set(0)
|
||||
raises(ValueError, "api.option('d').value.set(1)")
|
||||
raises(ValueError, "api.option('d').value.set(1023)")
|
||||
raises(ValueError, "api.option('d').value.set(1024)")
|
||||
raises(ValueError, "api.option('d').value.set(49151)")
|
||||
raises(ValueError, "api.option('d').value.set(49152)")
|
||||
raises(ValueError, "api.option('d').value.set(65535)")
|
||||
raises(ValueError, "api.option('d').value.set(65536)")
|
||||
|
||||
api.option('e').value.set(0)
|
||||
api.option('e').value.set(1)
|
||||
api.option('e').value.set(1023)
|
||||
api.option('e').value.set(1024)
|
||||
api.option('e').value.set(49151)
|
||||
api.option('e').value.set(49152)
|
||||
api.option('e').value.set(65535)
|
||||
|
||||
raises(ValueError, "api.option('f').value.set(0)")
|
||||
api.option('f').value.set(1)
|
||||
api.option('f').value.set(1023)
|
||||
api.option('f').value.set(1024)
|
||||
api.option('f').value.set(49151)
|
||||
api.option('f').value.set(49152)
|
||||
api.option('f').value.set(65535)
|
||||
raises(ValueError, "api.option('f').value.set(65536)")
|
||||
|
||||
|
||||
def test_port_range():
|
||||
a = PortOption('a', '', allow_range=True)
|
||||
b = PortOption('b', '', allow_range=True, allow_zero=True)
|
||||
c = PortOption('c', '', allow_range=True, allow_zero=True, allow_registred=False)
|
||||
d = PortOption('d', '', allow_range=True, allow_zero=True, allow_wellknown=False, allow_registred=False)
|
||||
e = PortOption('e', '', allow_range=True, allow_zero=True, allow_private=True)
|
||||
f = PortOption('f', '', allow_range=True, allow_private=True)
|
||||
od = OptionDescription('od', '', [a, b, c, d, e, f])
|
||||
c = Config(od)
|
||||
api = getapi(c)
|
||||
raises(ValueError, "api.option('a').value.set(0)")
|
||||
api.option('a').value.set(1)
|
||||
api.option('a').value.set(1023)
|
||||
api.option('a').value.set(1024)
|
||||
api.option('a').value.set(49151)
|
||||
raises(ValueError, "api.option('a').value.set(49152)")
|
||||
raises(ValueError, "api.option('a').value.set(65535)")
|
||||
raises(ValueError, "api.option('a').value.set(65536)")
|
||||
api.option('a').value.set('1:49151')
|
||||
raises(ValueError, "api.option('a').value.set('0:49151')")
|
||||
raises(ValueError, "api.option('a').value.set('1:49152')")
|
||||
|
||||
api.option('b').value.set(0)
|
||||
api.option('b').value.set(1)
|
||||
api.option('b').value.set(1023)
|
||||
api.option('b').value.set(1024)
|
||||
api.option('b').value.set(49151)
|
||||
raises(ValueError, "api.option('b').value.set(49152)")
|
||||
raises(ValueError, "api.option('b').value.set(65535)")
|
||||
raises(ValueError, "api.option('b').value.set(65536)")
|
||||
api.option('b').value.set('0:49151')
|
||||
raises(ValueError, "api.option('b').value.set('0:49152')")
|
||||
|
||||
api.option('c').value.set(0)
|
||||
api.option('c').value.set(1)
|
||||
api.option('c').value.set(1023)
|
||||
raises(ValueError, "api.option('c').value.set(1024)")
|
||||
raises(ValueError, "api.option('c').value.set(49151)")
|
||||
raises(ValueError, "api.option('c').value.set(49152)")
|
||||
raises(ValueError, "api.option('c').value.set(65535)")
|
||||
raises(ValueError, "api.option('c').value.set(65536)")
|
||||
api.option('c').value.set('0:1023')
|
||||
raises(ValueError, "api.option('c').value.set('0:1024')")
|
||||
|
||||
api.option('d').value.set(0)
|
||||
raises(ValueError, "api.option('d').value.set(1)")
|
||||
raises(ValueError, "api.option('d').value.set(1023)")
|
||||
raises(ValueError, "api.option('d').value.set(1024)")
|
||||
raises(ValueError, "api.option('d').value.set(49151)")
|
||||
raises(ValueError, "api.option('d').value.set(49152)")
|
||||
raises(ValueError, "api.option('d').value.set(65535)")
|
||||
raises(ValueError, "api.option('d').value.set(65536)")
|
||||
raises(ValueError, "api.option('d').value.set('0:0')")
|
||||
raises(ValueError, "api.option('d').value.set('0:1')")
|
||||
|
||||
api.option('e').value.set(0)
|
||||
api.option('e').value.set(1)
|
||||
api.option('e').value.set(1023)
|
||||
api.option('e').value.set(1024)
|
||||
api.option('e').value.set(49151)
|
||||
api.option('e').value.set(49152)
|
||||
api.option('e').value.set(65535)
|
||||
api.option('e').value.set('0:65535')
|
||||
raises(ValueError, "api.option('e').value.set('0:65536')")
|
||||
|
||||
raises(ValueError, "api.option('f').value.set(0)")
|
||||
api.option('f').value.set(1)
|
||||
api.option('f').value.set(1023)
|
||||
api.option('f').value.set(1024)
|
||||
api.option('f').value.set(49151)
|
||||
api.option('f').value.set(49152)
|
||||
api.option('f').value.set(65535)
|
||||
raises(ValueError, "api.option('f').value.set(65536)")
|
||||
api.option('f').value.set('1:65535')
|
||||
api.option('f').value.set('3:4')
|
||||
raises(ValueError, "api.option('f').value.set('0:65535')")
|
||||
raises(ValueError, "api.option('f').value.set('4:3')")
|
||||
|
|
@ -1,334 +0,0 @@
|
|||
# coding: utf-8
|
||||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
|
||||
from tiramisu import BoolOption, IntOption, StrOption, IPOption, NetmaskOption, \
|
||||
SymLinkOption, OptionDescription, DynOptionDescription, submulti, \
|
||||
Config, GroupConfig, MetaConfig, getapi
|
||||
import weakref
|
||||
|
||||
|
||||
IS_DEREFABLE = True
|
||||
|
||||
|
||||
def funcname(*args, **kwargs):
|
||||
return value
|
||||
|
||||
|
||||
def test_deref_storage():
|
||||
b = BoolOption('b', '')
|
||||
o = OptionDescription('od', '', [b])
|
||||
c = Config(o)
|
||||
w = weakref.ref(c.cfgimpl_get_values()._p_)
|
||||
del(c)
|
||||
assert w() is None
|
||||
|
||||
|
||||
def test_deref_value():
|
||||
b = BoolOption('b', '')
|
||||
o = OptionDescription('od', '', [b])
|
||||
c = Config(o)
|
||||
w = weakref.ref(c.cfgimpl_get_values())
|
||||
del(c)
|
||||
assert w() is None
|
||||
|
||||
|
||||
def test_deref_setting():
|
||||
b = BoolOption('b', '')
|
||||
o = OptionDescription('od', '', [b])
|
||||
c = Config(o)
|
||||
w = weakref.ref(c.cfgimpl_get_settings())
|
||||
del(c)
|
||||
assert w() is None
|
||||
|
||||
|
||||
def test_deref_config():
|
||||
b = BoolOption('b', '')
|
||||
o = OptionDescription('od', '', [b])
|
||||
c = Config(o)
|
||||
w = weakref.ref(c)
|
||||
del(c)
|
||||
assert w() is None
|
||||
|
||||
|
||||
def test_deref_option():
|
||||
global IS_DEREFABLE
|
||||
b = BoolOption('b', '')
|
||||
o = OptionDescription('od', '', [b])
|
||||
w = weakref.ref(b)
|
||||
del(b)
|
||||
try:
|
||||
assert w() is not None
|
||||
except AssertionError:
|
||||
IS_DEREFABLE = False
|
||||
return
|
||||
del(o)
|
||||
assert w() is None
|
||||
|
||||
|
||||
def test_deref_optiondescription():
|
||||
if not IS_DEREFABLE:
|
||||
return
|
||||
b = BoolOption('b', '')
|
||||
o = OptionDescription('od', '', [b])
|
||||
w = weakref.ref(o)
|
||||
del(b)
|
||||
assert w() is not None
|
||||
del(o)
|
||||
assert w() is None
|
||||
|
||||
|
||||
def test_deref_option_cache():
|
||||
if not IS_DEREFABLE:
|
||||
return
|
||||
b = BoolOption('b', '')
|
||||
o = OptionDescription('od', '', [b])
|
||||
o._build_cache_option()
|
||||
w = weakref.ref(b)
|
||||
del(b)
|
||||
assert w() is not None
|
||||
del(o)
|
||||
assert w() is None
|
||||
|
||||
|
||||
def test_deref_optiondescription_cache():
|
||||
if not IS_DEREFABLE:
|
||||
return
|
||||
b = BoolOption('b', '')
|
||||
o = OptionDescription('od', '', [b])
|
||||
o._build_cache_option()
|
||||
w = weakref.ref(o)
|
||||
del(b)
|
||||
assert w() is not None
|
||||
del(o)
|
||||
assert w() is None
|
||||
|
||||
|
||||
def test_deref_option_config():
|
||||
if not IS_DEREFABLE:
|
||||
return
|
||||
b = BoolOption('b', '')
|
||||
o = OptionDescription('od', '', [b])
|
||||
c = Config(o)
|
||||
w = weakref.ref(b)
|
||||
del(b)
|
||||
assert w() is not None
|
||||
del(o)
|
||||
assert w() is not None
|
||||
del(c)
|
||||
assert w() is None
|
||||
|
||||
|
||||
def test_deref_optiondescription_config():
|
||||
if not IS_DEREFABLE:
|
||||
return
|
||||
b = BoolOption('b', '')
|
||||
o = OptionDescription('od', '', [b])
|
||||
c = Config(o)
|
||||
w = weakref.ref(o)
|
||||
del(b)
|
||||
assert w() is not None
|
||||
del(o)
|
||||
assert w() is not None
|
||||
del(c)
|
||||
assert w() is None
|
||||
|
||||
|
||||
def test_deref_groupconfig():
|
||||
if not IS_DEREFABLE:
|
||||
return
|
||||
i1 = IntOption('i1', '')
|
||||
od1 = OptionDescription('od1', '', [i1])
|
||||
od2 = OptionDescription('od2', '', [od1])
|
||||
conf1 = Config(od2, 'conf1')
|
||||
conf2 = Config(od2, 'conf2')
|
||||
meta = GroupConfig([conf1, conf2])
|
||||
w = weakref.ref(conf1)
|
||||
del(conf1)
|
||||
assert w() is not None
|
||||
del(meta)
|
||||
assert w() is None
|
||||
|
||||
|
||||
def test_deref_metaconfig():
|
||||
if not IS_DEREFABLE:
|
||||
return
|
||||
i1 = IntOption('i1', '')
|
||||
od1 = OptionDescription('od1', '', [i1])
|
||||
od2 = OptionDescription('od2', '', [od1])
|
||||
conf1 = Config(od2, 'conf1')
|
||||
conf2 = Config(od2, 'conf2')
|
||||
meta = MetaConfig([conf1, conf2])
|
||||
w = weakref.ref(conf1)
|
||||
del(conf1)
|
||||
assert w() is not None
|
||||
del(meta)
|
||||
assert w() is None
|
||||
|
||||
|
||||
def test_deref_consistency():
|
||||
if not IS_DEREFABLE:
|
||||
return
|
||||
a = IPOption('a', '')
|
||||
b = NetmaskOption('b', '')
|
||||
od = OptionDescription('od', '', [a, b])
|
||||
b.impl_add_consistency('ip_netmask', a)
|
||||
cfg = Config(od)
|
||||
w = weakref.ref(a)
|
||||
x = weakref.ref(b)
|
||||
y = weakref.ref(od)
|
||||
z = weakref.ref(cfg)
|
||||
assert w() is not None
|
||||
assert x() is not None
|
||||
assert y() is not None
|
||||
assert z() is not None
|
||||
del(a)
|
||||
del(b)
|
||||
assert w() is not None
|
||||
assert x() is not None
|
||||
assert y() is not None
|
||||
assert z() is not None
|
||||
del(od)
|
||||
assert w() is not None
|
||||
assert x() is not None
|
||||
assert y() is not None
|
||||
assert z() is not None
|
||||
del(cfg)
|
||||
assert y() is None
|
||||
assert z() is None
|
||||
#assert w() is None
|
||||
#assert x() is None
|
||||
|
||||
|
||||
def test_deref_validator():
|
||||
if not IS_DEREFABLE:
|
||||
return
|
||||
a = StrOption('a', '', default='yes')
|
||||
b = StrOption('b', '', validator=funcname, validator_params={'': ((a, False),)}, default='val')
|
||||
od = OptionDescription('root', '', [a, b])
|
||||
cfg = Config(od)
|
||||
w = weakref.ref(a)
|
||||
x = weakref.ref(b)
|
||||
y = weakref.ref(od)
|
||||
z = weakref.ref(cfg)
|
||||
assert w() is not None
|
||||
assert x() is not None
|
||||
assert w() is not None
|
||||
assert x() is not None
|
||||
del(a)
|
||||
del(b)
|
||||
assert w() is not None
|
||||
assert x() is not None
|
||||
assert w() is not None
|
||||
assert x() is not None
|
||||
del(od)
|
||||
assert w() is not None
|
||||
assert x() is not None
|
||||
assert w() is not None
|
||||
assert x() is not None
|
||||
del(cfg)
|
||||
assert y() is None
|
||||
assert z() is None
|
||||
#assert w() is None
|
||||
#assert x() is None
|
||||
|
||||
|
||||
def test_deref_callback():
|
||||
if not IS_DEREFABLE:
|
||||
return
|
||||
a = StrOption('a', "", 'val')
|
||||
b = StrOption('b', "", callback=funcname, callback_params={'': ((a, False),)})
|
||||
od = OptionDescription('root', '', [a, b])
|
||||
cfg = Config(od)
|
||||
w = weakref.ref(a)
|
||||
x = weakref.ref(b)
|
||||
y = weakref.ref(od)
|
||||
z = weakref.ref(cfg)
|
||||
assert w() is not None
|
||||
assert x() is not None
|
||||
assert w() is not None
|
||||
assert x() is not None
|
||||
del(a)
|
||||
del(b)
|
||||
assert w() is not None
|
||||
assert x() is not None
|
||||
assert w() is not None
|
||||
assert x() is not None
|
||||
del(od)
|
||||
assert w() is not None
|
||||
assert x() is not None
|
||||
assert w() is not None
|
||||
assert x() is not None
|
||||
del(cfg)
|
||||
assert y() is None
|
||||
assert z() is None
|
||||
#assert w() is None
|
||||
#assert x() is None
|
||||
|
||||
|
||||
def test_deref_symlink():
|
||||
if not IS_DEREFABLE:
|
||||
return
|
||||
a = BoolOption("a", "", default=False)
|
||||
b = SymLinkOption("b", a)
|
||||
od = OptionDescription('root', '', [a, b])
|
||||
cfg = Config(od)
|
||||
w = weakref.ref(a)
|
||||
x = weakref.ref(b)
|
||||
y = weakref.ref(od)
|
||||
z = weakref.ref(cfg)
|
||||
assert w() is not None
|
||||
assert x() is not None
|
||||
assert w() is not None
|
||||
assert x() is not None
|
||||
del(a)
|
||||
del(b)
|
||||
assert w() is not None
|
||||
assert x() is not None
|
||||
assert w() is not None
|
||||
assert x() is not None
|
||||
del(od)
|
||||
assert w() is not None
|
||||
assert x() is not None
|
||||
assert w() is not None
|
||||
assert x() is not None
|
||||
del(cfg)
|
||||
#assert w() is None
|
||||
#assert x() is None
|
||||
assert y() is None
|
||||
assert z() is None
|
||||
|
||||
|
||||
def test_deref_dyn():
|
||||
if not IS_DEREFABLE:
|
||||
return
|
||||
a = StrOption('a', '', ['val1', 'val2'], multi=True)
|
||||
b = StrOption('b', '')
|
||||
dod = DynOptionDescription('dod', '', [b], callback=funcname, callback_params={'': ((a, False),)})
|
||||
od = OptionDescription('od', '', [dod, a])
|
||||
cfg = Config(od)
|
||||
w = weakref.ref(a)
|
||||
x = weakref.ref(b)
|
||||
y = weakref.ref(od)
|
||||
z = weakref.ref(cfg)
|
||||
assert w() is not None
|
||||
assert x() is not None
|
||||
assert w() is not None
|
||||
assert x() is not None
|
||||
del(a)
|
||||
del(b)
|
||||
assert w() is not None
|
||||
assert x() is not None
|
||||
assert w() is not None
|
||||
assert x() is not None
|
||||
del(od)
|
||||
del(dod)
|
||||
assert w() is not None
|
||||
assert x() is not None
|
||||
assert w() is not None
|
||||
assert x() is not None
|
||||
del(cfg)
|
||||
#assert w() is None
|
||||
#assert x() is None
|
||||
assert y() is None
|
||||
assert z() is None
|
||||
|
|
@ -1,75 +0,0 @@
|
|||
# coding: utf-8
|
||||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
|
||||
from tiramisu.setting import groups
|
||||
from tiramisu.config import Config
|
||||
from tiramisu import ChoiceOption, BoolOption, IntOption, \
|
||||
StrOption, OptionDescription, getapi
|
||||
from .test_state import _diff_opts, _diff_conf
|
||||
from py.test import raises
|
||||
|
||||
|
||||
def make_description():
|
||||
numero_etab = StrOption('numero_etab', "identifiant de l'établissement")
|
||||
nom_machine = StrOption('nom_machine', "nom de la machine", default="eoleng")
|
||||
nombre_interfaces = IntOption('nombre_interfaces', "nombre d'interfaces à activer",
|
||||
default=1)
|
||||
activer_proxy_client = BoolOption('activer_proxy_client', "utiliser un proxy",
|
||||
default=False)
|
||||
mode_conteneur_actif = BoolOption('mode_conteneur_actif', "le serveur est en mode conteneur",
|
||||
default=False)
|
||||
mode_conteneur_actif2 = BoolOption('mode_conteneur_actif2', "le serveur est en mode conteneur2",
|
||||
default=False, properties=('hidden',))
|
||||
|
||||
adresse_serveur_ntp = StrOption('serveur_ntp', "adresse serveur ntp", multi=True)
|
||||
time_zone = ChoiceOption('time_zone', 'fuseau horaire du serveur',
|
||||
('Paris', 'Londres'), 'Paris')
|
||||
wantref_option = BoolOption('wantref', 'Test requires', default=False, properties=('force_store_value',))
|
||||
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé")
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau")
|
||||
|
||||
master = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
interface1 = OptionDescription('interface1', '', [master])
|
||||
interface1.impl_set_group_type(groups.family)
|
||||
|
||||
general = OptionDescription('general', '', [numero_etab, nom_machine,
|
||||
nombre_interfaces, activer_proxy_client,
|
||||
mode_conteneur_actif, mode_conteneur_actif2,
|
||||
adresse_serveur_ntp, time_zone, wantref_option])
|
||||
general.impl_set_group_type(groups.family)
|
||||
new = OptionDescription('new', '', [], properties=('hidden',))
|
||||
new.impl_set_group_type(groups.family)
|
||||
creole = OptionDescription('creole', 'first tiramisu configuration', [general, interface1, new])
|
||||
descr = OptionDescription('baseconfig', 'baseconifgdescr', [creole])
|
||||
return descr
|
||||
|
||||
|
||||
def test_duplicate():
|
||||
cfg = Config(make_description())
|
||||
ncfg = cfg.duplicate()
|
||||
api = getapi(cfg)
|
||||
api2 = getapi(ncfg)
|
||||
assert api.option('creole.general.numero_etab').value.get() == None
|
||||
api.option('creole.general.numero_etab').value.set('oui')
|
||||
assert api.option('creole.general.numero_etab').value.get() == 'oui'
|
||||
assert api2.option('creole.general.numero_etab').value.get() == None
|
||||
# _diff_opts(cfg.cfgimpl_get_description(), ncfg.cfgimpl_get_description())
|
||||
# _diff_conf(cfg, ncfg)
|
||||
# cfg.creole.general.numero_etab = 'oui'
|
||||
# raises(AssertionError, "_diff_conf(cfg, ncfg)")
|
||||
# ncfg.creole.general.numero_etab = 'oui'
|
||||
# _diff_conf(cfg, ncfg)
|
||||
|
||||
|
||||
def test_duplicate_force_store_value():
|
||||
descr = make_description()
|
||||
conf = Config(descr)
|
||||
conf2 = Config(descr)
|
||||
api = getapi(conf)
|
||||
assert conf.cfgimpl_get_values().get_modified_values() == {'creole.general.wantref': ('forced', False)}
|
||||
assert conf2.cfgimpl_get_values().get_modified_values() == {'creole.general.wantref': ('forced', False)}
|
||||
api.option('creole.general.wantref').value.set(True)
|
||||
assert conf.cfgimpl_get_values().get_modified_values() == {'creole.general.wantref': ('user', True)}
|
||||
assert conf2.cfgimpl_get_values().get_modified_values() == {'creole.general.wantref': ('forced', False)}
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,221 +0,0 @@
|
|||
# coding: utf-8
|
||||
"frozen and hidden values"
|
||||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
|
||||
from py.test import raises
|
||||
|
||||
from tiramisu.setting import owners, groups
|
||||
from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \
|
||||
StrOption, OptionDescription, SymLinkOption, MasterSlaves, Config, \
|
||||
getapi
|
||||
from tiramisu.error import PropertiesOptionError, ConfigError
|
||||
|
||||
|
||||
#____________________________________________________________
|
||||
#freeze
|
||||
def make_description_freeze():
|
||||
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||
('std', 'thunk'), 'std')
|
||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
boolop = BoolOption('boolop', 'Test boolean option op', default=[True], multi=True)
|
||||
wantref_option = BoolOption('wantref', 'Test requires', default=False, properties=('force_store_value',),
|
||||
requires=({'option': booloption, 'expected': True, 'action': 'hidden'},))
|
||||
wantref2_option = BoolOption('wantref2', 'Test requires', default=False, properties=('force_store_value', 'hidden'))
|
||||
wantref3_option = BoolOption('wantref3', 'Test requires', default=[False], multi=True, properties=('force_store_value',))
|
||||
st2 = SymLinkOption('st2', wantref3_option)
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False,
|
||||
requires=({'option': booloption, 'expected': True, 'action': 'hidden'},))
|
||||
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
||||
descr = OptionDescription('tiramisu', '', [gcgroup, booloption, objspaceoption,
|
||||
wantref_option, wantref2_option, wantref3_option, st2, stroption,
|
||||
wantframework_option,
|
||||
intoption, boolop])
|
||||
return descr
|
||||
|
||||
|
||||
def return_val():
|
||||
return 1
|
||||
|
||||
|
||||
def return_val2(value):
|
||||
return value
|
||||
|
||||
|
||||
def return_val3(context, value):
|
||||
return value
|
||||
|
||||
|
||||
def test_freeze_whole_config():
|
||||
descr = make_description_freeze()
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
api.property.add('everything_frozen')
|
||||
assert api.option('gc.dummy').value.get() is False
|
||||
prop = []
|
||||
try:
|
||||
api.option('gc.dummy').value.set(True)
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'frozen' in prop
|
||||
assert api.option('gc.dummy').value.get() is False
|
||||
#
|
||||
api.property.pop('everything_frozen')
|
||||
api.option('gc.dummy').value.set(True)
|
||||
assert api.option('gc.dummy').value.get() is True
|
||||
#
|
||||
api.property.add('everything_frozen')
|
||||
owners.addowner("everythingfrozen")
|
||||
prop = []
|
||||
try:
|
||||
api.option('gc.dummy').owner.set('everythingfrozen')
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'frozen' in prop
|
||||
|
||||
|
||||
def test_freeze_one_option():
|
||||
"freeze an option "
|
||||
descr = make_description_freeze()
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
#freeze only one option
|
||||
api.option('gc.dummy').property.add('frozen')
|
||||
assert api.option('gc.dummy').value.get() is False
|
||||
prop = []
|
||||
try:
|
||||
api.option('gc.dummy').value.set(True)
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'frozen' in prop
|
||||
|
||||
|
||||
def test_frozen_value():
|
||||
"setattr a frozen value at the config level"
|
||||
s = StrOption("string", "", default="string")
|
||||
descr = OptionDescription("options", "", [s])
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
api.property.add('frozen')
|
||||
api.option('string').property.add('frozen')
|
||||
prop = []
|
||||
try:
|
||||
api.option('string').value.set('egg')
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'frozen' in prop
|
||||
|
||||
|
||||
def test_freeze():
|
||||
"freeze a whole configuration object"
|
||||
descr = make_description_freeze()
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
api.property.add('frozen')
|
||||
api.option('gc.name').property.add('frozen')
|
||||
prop = []
|
||||
try:
|
||||
api.option('gc.name').value.set('framework')
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'frozen' in prop
|
||||
|
||||
|
||||
def test_freeze_multi():
|
||||
descr = make_description_freeze()
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
api.property.add('frozen')
|
||||
api.option('boolop').property.add('frozen')
|
||||
prop = []
|
||||
try:
|
||||
api.option('boolop').value.set([True])
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'frozen' in prop
|
||||
|
||||
|
||||
def test_force_store_value():
|
||||
descr = make_description_freeze()
|
||||
conf = Config(descr)
|
||||
api = getapi(conf)
|
||||
assert api.value.get_modified() == {'wantref': ('forced', False),
|
||||
'wantref2': ('forced', False),
|
||||
'wantref3': ('forced', (False,))}
|
||||
api.option('wantref').value.set(True)
|
||||
assert api.value.get_modified() == {'wantref': ('user', True),
|
||||
'wantref2': ('forced', False),
|
||||
'wantref3': ('forced', (False,))}
|
||||
api.option('wantref').value.reset()
|
||||
assert api.value.get_modified() == {'wantref': ('forced', False),
|
||||
'wantref2': ('forced', False),
|
||||
'wantref3': ('forced', (False,))}
|
||||
|
||||
|
||||
def test_force_store_value_no_requirement():
|
||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||
try:
|
||||
BoolOption('wantref', 'Test requires', default=False,
|
||||
requires=({'option': booloption, 'expected': True, 'action': 'force_store_value'},))
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
|
||||
def test_force_store_value_masterslaves_slave():
|
||||
b = IntOption('int', 'Test int option', multi=True)
|
||||
c = StrOption('str', 'Test string option', multi=True, properties=('force_store_value',))
|
||||
descr = MasterSlaves("int", "", [b, c])
|
||||
raises(ConfigError, "conf = Config(descr)")
|
||||
|
||||
|
||||
#def test_force_store_value_masterslaves():
|
||||
# b = IntOption('int', 'Test int option', multi=True, properties=('force_store_value',))
|
||||
# c = StrOption('str', 'Test string option', multi=True)
|
||||
# descr = MasterSlaves("int", "", [b, c])
|
||||
# api = getapi(Config(descr))
|
||||
# assert api.value.get() == {'int': ('forced', ())}
|
||||
|
||||
|
||||
def test_force_store_value_masterslaves_sub():
|
||||
b = IntOption('int', 'Test int option', multi=True, properties=('force_store_value',))
|
||||
c = StrOption('str', 'Test string option', multi=True)
|
||||
descr = MasterSlaves("int", "", [b, c])
|
||||
odr = OptionDescription('odr', '', [descr])
|
||||
api = getapi(Config(odr))
|
||||
assert api.value.get_modified() == {'int.int': ('forced', ())}
|
||||
|
||||
|
||||
def test_force_store_value_callback():
|
||||
b = IntOption('int', 'Test int option', properties=('force_store_value',), callback=return_val)
|
||||
descr = OptionDescription("int", "", [b])
|
||||
api = getapi(Config(descr))
|
||||
assert api.value.get_modified() == {'int': ('forced', 1)}
|
||||
|
||||
|
||||
def test_force_store_value_callback_params():
|
||||
b = IntOption('int', 'Test int option', properties=('force_store_value',), callback=return_val2, callback_params={'value': (2,)})
|
||||
descr = OptionDescription("int", "", [b])
|
||||
api = getapi(Config(descr))
|
||||
assert api.value.get_modified() == {'int': ('forced', 2)}
|
||||
|
||||
|
||||
def test_force_store_value_callback_params_2():
|
||||
b = IntOption('int', 'Test int option', properties=('force_store_value',), callback=return_val3, callback_params={'': ((None,),), 'value': (2,)})
|
||||
descr = OptionDescription("int", "", [b])
|
||||
api = getapi(Config(descr))
|
||||
assert api.value.get_modified() == {'int': ('forced', 2)}
|
||||
|
||||
|
||||
def test_force_store_value_callback_params_with_opt():
|
||||
a = IntOption('val1', "", 2)
|
||||
b = IntOption('int', 'Test int option', properties=('force_store_value',), callback=return_val2, callback_params={'value': ((a, False),)})
|
||||
descr = OptionDescription("int", "", [a, b])
|
||||
api = getapi(Config(descr))
|
||||
assert api.value.get_modified() == {'int': ('forced', 2)}
|
||||
|
|
@ -1,575 +0,0 @@
|
|||
# coding: utf-8
|
||||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
|
||||
from py.test import raises
|
||||
from tiramisu.config import Config
|
||||
from tiramisu import IntOption, StrOption, UnicodeOption, OptionDescription, \
|
||||
SymLinkOption, MasterSlaves, getapi, undefined
|
||||
from tiramisu.error import PropertiesOptionError, ConfigError
|
||||
from tiramisu.setting import groups
|
||||
|
||||
|
||||
def make_description():
|
||||
stroption = StrOption('str', 'Test string option', default="abc",
|
||||
properties=('mandatory', ))
|
||||
stroption1 = StrOption('str1', 'Test string option',
|
||||
properties=('mandatory', ))
|
||||
stroption2 = UnicodeOption('unicode2', 'Test string option',
|
||||
properties=('mandatory', ))
|
||||
stroption3 = StrOption('str3', 'Test string option', multi=True,
|
||||
properties=('mandatory', ))
|
||||
stroption4 = StrOption('str4', 'Test string option', multi=True,
|
||||
properties=('mandatory', ), allow_empty_list=True)
|
||||
descr = OptionDescription('tiram', '', [stroption, stroption1, stroption2, stroption3, stroption4])
|
||||
return descr
|
||||
|
||||
|
||||
def return_value(value):
|
||||
return value
|
||||
|
||||
|
||||
def make_description2():
|
||||
stroption = StrOption('str', 'Test string option', default="abc",
|
||||
properties=('mandatory', ))
|
||||
stroption1 = StrOption('str1', 'Test string option',
|
||||
properties=('mandatory', ))
|
||||
stroption2 = SymLinkOption('unicode2', stroption1)
|
||||
stroption3 = StrOption('str3', 'Test string option', multi=True,
|
||||
properties=('mandatory', ))
|
||||
unicode1 = UnicodeOption('unicode1', 'Test string option', callback=return_value, callback_params={'': ((stroption, False),)}, properties=('mandatory', ))
|
||||
descr = OptionDescription('tiram', '', [stroption, stroption1, stroption2, stroption3, unicode1])
|
||||
return descr
|
||||
|
||||
|
||||
def make_description_sym():
|
||||
stroption = StrOption('str', 'Test string option', default="abc",
|
||||
properties=('mandatory', ))
|
||||
stroption1 = StrOption('str1', 'Test string option',
|
||||
properties=('mandatory', ))
|
||||
stroption2 = SymLinkOption('unicode2', stroption1)
|
||||
stroption3 = StrOption('str3', 'Test string option', multi=True,
|
||||
properties=('mandatory', ))
|
||||
descr = OptionDescription('tiram', '', [stroption, stroption1, stroption2, stroption3])
|
||||
return descr
|
||||
|
||||
|
||||
def make_description3():
|
||||
stroption = StrOption('str', 'Test string option', default="abc",
|
||||
properties=('mandatory', ))
|
||||
stroption1 = StrOption('str1', 'Test string option',
|
||||
properties=('mandatory', ))
|
||||
stroption2 = SymLinkOption('unicode2', stroption1)
|
||||
stroption3 = StrOption('str3', 'Test string option', multi=True,
|
||||
properties=('mandatory', ))
|
||||
unicode1 = UnicodeOption('unicode1', 'Test string option', callback=return_value, callback_params={'': ((stroption, False),)}, properties=('mandatory', ))
|
||||
int1 = IntOption('int1', '', callback=return_value, callback_params={'': ((stroption, False),)}, properties=('mandatory', ))
|
||||
descr = OptionDescription('tiram', '', [stroption, stroption1, stroption2, stroption3, unicode1, int1])
|
||||
return descr
|
||||
|
||||
|
||||
def make_description4():
|
||||
stroption = StrOption('str', 'Test string option', default="abc",
|
||||
properties=('mandatory', ))
|
||||
stroption1 = StrOption('str1', 'Test string option',
|
||||
properties=('mandatory', ))
|
||||
stroption2 = UnicodeOption('unicode2', 'Test string option',
|
||||
properties=('mandatory', ))
|
||||
stroption3 = StrOption('str3', 'Test string option', multi=True, requires=[{'option': stroption, 'expected': 'yes', 'action': 'mandatory', 'transitive': False}])
|
||||
descr = OptionDescription('tiram', '', [stroption, stroption1, stroption2, stroption3])
|
||||
return descr
|
||||
|
||||
|
||||
def test_mandatory_ro():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_only()
|
||||
prop = []
|
||||
try:
|
||||
api.option('str1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
api.property.read_write()
|
||||
api.option('str1').value.set('yes')
|
||||
api.property.read_only()
|
||||
assert api.option('str1').value.get() == 'yes'
|
||||
|
||||
|
||||
def test_mandatory_rw():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
#not mandatory in rw
|
||||
api.option('str1').value.get()
|
||||
api.option('str1').value.set('yes')
|
||||
assert api.option('str1').value.get() == 'yes'
|
||||
|
||||
|
||||
def test_mandatory_default():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_only()
|
||||
#not mandatory in rw
|
||||
api.option('str').value.get()
|
||||
api.property.read_write()
|
||||
api.option('str').value.set('yes')
|
||||
api.property.read_only()
|
||||
api.option('str').value.get()
|
||||
api.property.read_write()
|
||||
api.option('str').value.set(None)
|
||||
api.property.read_only()
|
||||
prop = []
|
||||
try:
|
||||
api.option('str').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
|
||||
|
||||
def test_mandatory_delete():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_only()
|
||||
api.option('str').value.get()
|
||||
try:
|
||||
api.option('str1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
api.property.read_write()
|
||||
api.option('str1').value.set('yes')
|
||||
api.property.read_only()
|
||||
assert api.option('str1').value.get() == 'yes'
|
||||
api.property.pop('everything_frozen')
|
||||
prop = []
|
||||
try:
|
||||
api.option('str1').value.reset()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
api.option('str').value.reset()
|
||||
|
||||
assert api.option('str1').value.get() == 'yes'
|
||||
|
||||
|
||||
#valeur vide : None, '', u'', ...
|
||||
def test_mandatory_none():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.option('str1').value.set(None)
|
||||
assert api.option('str1').owner.get() == 'user'
|
||||
api.property.read_only()
|
||||
prop = []
|
||||
try:
|
||||
api.option('str1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
|
||||
|
||||
def test_mandatory_empty():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.option('str1').value.set('')
|
||||
assert api.option('str1').owner.get() == 'user'
|
||||
api.property.read_only()
|
||||
prop = []
|
||||
try:
|
||||
api.option('str1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
|
||||
|
||||
def test_mandatory_multi_none():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.option('str3').value.set([None])
|
||||
assert api.option('str3').owner.get() == 'user'
|
||||
api.property.read_only()
|
||||
prop = []
|
||||
try:
|
||||
api.option('str3').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
api.property.read_write()
|
||||
api.option('str3').value.set(['yes', None])
|
||||
assert api.option('str3').owner.get() == 'user'
|
||||
api.property.read_only()
|
||||
prop = []
|
||||
try:
|
||||
api.option('str3').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
|
||||
|
||||
def test_mandatory_multi_empty():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.option('str3').value.set([])
|
||||
assert api.option('str3').owner.get() == 'user'
|
||||
api.property.read_only()
|
||||
prop = []
|
||||
try:
|
||||
api.option('str3').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
#
|
||||
api.property.read_write()
|
||||
api.option('str3').value.set([''])
|
||||
assert api.option('str3').owner.get() == 'user'
|
||||
api.property.read_only()
|
||||
prop = []
|
||||
try:
|
||||
api.option('str3').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
#
|
||||
api.property.read_write()
|
||||
api.option('str3').value.set(['yes', ''])
|
||||
assert api.option('str3').owner.get() == 'user'
|
||||
api.property.read_only()
|
||||
prop = []
|
||||
try:
|
||||
api.option('str3').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
|
||||
|
||||
def test_mandatory_multi_empty_allow_empty_list():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.option('str4').value.set([])
|
||||
assert api.option('str4').owner.get() == 'user'
|
||||
api.property.read_only()
|
||||
prop = []
|
||||
api.option('str4').value.get()
|
||||
#
|
||||
api.property.read_write()
|
||||
api.option('str4').value.set([''])
|
||||
assert api.option('str4').owner.get() == 'user'
|
||||
api.property.read_only()
|
||||
prop = []
|
||||
try:
|
||||
api.option('str4').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
#
|
||||
api.property.read_write()
|
||||
api.option('str4').value.set(['yes', ''])
|
||||
assert api.option('str4').owner.get() == 'user'
|
||||
api.property.read_only()
|
||||
prop = []
|
||||
try:
|
||||
api.option('str4').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
|
||||
|
||||
def test_mandatory_multi_append():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.option('str3').value.set(['yes'])
|
||||
api.property.read_write()
|
||||
api.option('str3').value.get().append(None)
|
||||
|
||||
|
||||
def test_mandatory_disabled():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.option('str1').value.get()
|
||||
api.option('str1').property.add('disabled')
|
||||
api.property.read_only()
|
||||
pop = []
|
||||
try:
|
||||
api.option('str1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert set(prop) == {'disabled'}
|
||||
|
||||
|
||||
def test_mandatory_unicode():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.option('unicode2').value.get()
|
||||
api.property.read_only()
|
||||
prop = []
|
||||
try:
|
||||
api.option('unicode2').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
api.property.read_write()
|
||||
api.option('unicode2').value.set('')
|
||||
api.property.read_only()
|
||||
prop = []
|
||||
try:
|
||||
api.option('unicode2').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
|
||||
|
||||
def test_mandatory_warnings_ro():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.option('str').value.set('')
|
||||
api.property.read_only()
|
||||
proc = []
|
||||
try:
|
||||
api.option('str').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
assert list(api.value.mandatory_warnings()) == ['str', 'str1', 'unicode2', 'str3']
|
||||
api.property.read_write()
|
||||
api.option('str').value.set('a')
|
||||
api.property.read_only()
|
||||
assert list(api.value.mandatory_warnings()) == ['str1', 'unicode2', 'str3']
|
||||
|
||||
|
||||
def test_mandatory_warnings_rw():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.option('str').value.set('')
|
||||
api.property.read_write()
|
||||
api.option('str').value.get()
|
||||
assert list(api.value.mandatory_warnings()) == ['str', 'str1', 'unicode2', 'str3']
|
||||
api.option('str').value.set('a')
|
||||
assert list(api.value.mandatory_warnings()) == ['str1', 'unicode2', 'str3']
|
||||
|
||||
|
||||
def test_mandatory_warnings_disabled():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.option('str').value.set('')
|
||||
api.property.read_write()
|
||||
api.option('str').value.get()
|
||||
assert set(api.value.mandatory_warnings()) == {'str', 'str1', 'unicode2', 'str3'}
|
||||
api.option('str').property.add('disabled')
|
||||
assert set(api.value.mandatory_warnings()) == {'str1', 'unicode2', 'str3'}
|
||||
|
||||
|
||||
def test_mandatory_warnings_hidden():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.option('str').value.set('')
|
||||
api.property.read_write()
|
||||
api.permissive.set(frozenset(['hidden']))
|
||||
api.option('str').value.get()
|
||||
assert set(api.value.mandatory_warnings()) == {'str', 'str1', 'unicode2', 'str3'}
|
||||
api.option('str').property.add('hidden')
|
||||
assert set(api.value.mandatory_warnings()) == {'str', 'str1', 'unicode2', 'str3'}
|
||||
|
||||
|
||||
def test_mandatory_warnings_frozen():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.option('str').value.set('')
|
||||
api.property.read_write()
|
||||
api.option('str').value.get()
|
||||
assert set(api.value.mandatory_warnings()) == {'str', 'str1', 'unicode2', 'str3'}
|
||||
api.option('str').property.add('frozen')
|
||||
api.property.read_only()
|
||||
assert set(api.value.mandatory_warnings()) == {'str', 'str1', 'unicode2', 'str3'}
|
||||
|
||||
|
||||
def test_mandatory_master():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True,
|
||||
properties=('mandatory', ))
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau",
|
||||
multi=True)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
descr = OptionDescription('o', '', [interface1])
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_only()
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()")
|
||||
|
||||
|
||||
def test_mandatory_warnings_master():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True,
|
||||
properties=('mandatory', ))
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau",
|
||||
multi=True)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
descr = OptionDescription('o', '', [interface1])
|
||||
api = getapi(Config(descr))
|
||||
assert list(api.value.mandatory_warnings()) == ['ip_admin_eth0.ip_admin_eth0']
|
||||
|
||||
|
||||
def test_mandatory_master_empty():
|
||||
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)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
descr = OptionDescription('o', '', [interface1])
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
#
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set([undefined])
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [None]
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
|
||||
api.property.read_only()
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()")
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
|
||||
api.property.read_write()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
#
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set([''])
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['']
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
|
||||
api.property.read_only()
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()")
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
|
||||
api.property.read_write()
|
||||
#
|
||||
api.property.read_write()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
|
||||
api.property.read_only()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
|
||||
#
|
||||
api.property.read_write()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip2'])
|
||||
api.property.read_only()
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.reset()")
|
||||
api.property.read_write()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
|
||||
|
||||
|
||||
def test_mandatory_warnings_master_empty():
|
||||
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)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
descr = OptionDescription('o', '', [interface1])
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set([undefined])
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [None]
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
|
||||
assert list(api.value.mandatory_warnings()) == ['ip_admin_eth0.ip_admin_eth0']
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
|
||||
#
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set([''])
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['']
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
|
||||
assert list(api.value.mandatory_warnings()) == ['ip_admin_eth0.ip_admin_eth0']
|
||||
#
|
||||
api.property.read_write()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
|
||||
assert list(api.value.mandatory_warnings()) == []
|
||||
|
||||
|
||||
def test_mandatory_slave():
|
||||
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=('mandatory', ))
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
descr = OptionDescription('o', '', [interface1])
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_only()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
#
|
||||
api.property.read_write()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
|
||||
api.property.read_only()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
|
||||
#
|
||||
api.property.read_write()
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('')
|
||||
api.property.read_only()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
|
||||
#
|
||||
api.property.read_write()
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('ip')
|
||||
api.property.read_only()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == 'ip'
|
||||
|
||||
|
||||
def test_mandatory_warnings_slave():
|
||||
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=('mandatory', ))
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
descr = OptionDescription('o', '', [interface1])
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_only()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
#
|
||||
api.property.read_write()
|
||||
assert list(api.value.mandatory_warnings()) == []
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
|
||||
assert list(api.value.mandatory_warnings()) == ['ip_admin_eth0.netmask_admin_eth0']
|
||||
|
||||
|
||||
def test_mandatory_warnings_symlink():
|
||||
descr = make_description_sym()
|
||||
api = getapi(Config(descr))
|
||||
api.option('str').value.set('')
|
||||
api.property.read_write()
|
||||
api.option('str').value.get()
|
||||
assert list(api.value.mandatory_warnings()) == ['str', 'str1', 'str3']
|
||||
api.option('str').property.add('frozen')
|
||||
api.property.read_only()
|
||||
assert list(api.value.mandatory_warnings()) == ['str', 'str1', 'str3']
|
||||
|
||||
|
||||
#def test_mandatory_warnings_validate():
|
||||
# descr = make_description3()
|
||||
# api = getapi(Config(descr))
|
||||
# api.option('str').value.set('')
|
||||
# raises(ValueError, "list(api.value.mandatory_warnings())")
|
||||
# api.option('str').value.set('test')
|
||||
# raises(ValueError, "list(api.value.mandatory_warnings())")
|
||||
|
||||
|
||||
def test_mandatory_warnings_validate_empty():
|
||||
descr = make_description2()
|
||||
api = getapi(Config(descr))
|
||||
api.option('str').value.set('')
|
||||
api.property.read_only()
|
||||
assert list(api.value.mandatory_warnings()) == ['str', 'str1', 'str3', 'unicode1']
|
||||
|
||||
|
||||
def test_mandatory_warnings_requires():
|
||||
descr = make_description4()
|
||||
api = getapi(Config(descr))
|
||||
api.option('str').value.set('')
|
||||
api.property.read_write()
|
||||
api.option('str').value.get()
|
||||
assert list(api.value.mandatory_warnings()) == ['str', 'str1', 'unicode2']
|
||||
api.property.read_only()
|
||||
assert list(api.value.mandatory_warnings()) == ['str', 'str1', 'unicode2']
|
||||
api.property.read_write()
|
||||
api.option('str').value.set('yes')
|
||||
assert list(api.value.mandatory_warnings()) == ['str1', 'unicode2', 'str3']
|
||||
|
||||
|
||||
def test_mandatory_od_disabled():
|
||||
descr = make_description()
|
||||
descr = OptionDescription('od', '', [descr])
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_only()
|
||||
assert list(api.value.mandatory_warnings()) == ['tiram.str1', 'tiram.unicode2', 'tiram.str3']
|
||||
api.option('tiram').property.add('disabled')
|
||||
assert list(api.value.mandatory_warnings()) == []
|
||||
|
|
@ -1,722 +0,0 @@
|
|||
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, \
|
||||
getapi
|
||||
from tiramisu.error import ConfigError, ConflictError, PropertiesOptionError
|
||||
|
||||
owners.addowner('meta1')
|
||||
owners.addowner('meta2')
|
||||
|
||||
|
||||
def return_value(value=None):
|
||||
return value
|
||||
|
||||
|
||||
def raise_exception():
|
||||
raise Exception('test')
|
||||
|
||||
|
||||
def make_description():
|
||||
i1 = IntOption('i1', '')
|
||||
i2 = IntOption('i2', '', default=1)
|
||||
i3 = IntOption('i3', '')
|
||||
i4 = IntOption('i4', '', default=2)
|
||||
i5 = IntOption('i5', '', default=[2], multi=True)
|
||||
i6 = IntOption('i6', '', properties=('disabled',))
|
||||
od1 = OptionDescription('od1', '', [i1, i2, i3, i4, i5, i6])
|
||||
od2 = OptionDescription('od2', '', [od1])
|
||||
return od2
|
||||
|
||||
|
||||
def make_metaconfig(double=False):
|
||||
od2 = make_description()
|
||||
conf1 = Config(od2, session_id='conf1')
|
||||
conf2 = Config(od2, session_id='conf2')
|
||||
meta = MetaConfig([conf1, conf2], session_id='meta')
|
||||
api = getapi(meta)
|
||||
if double:
|
||||
api.owner.set(owners.meta2)
|
||||
meta = MetaConfig([meta])
|
||||
api = getapi(meta)
|
||||
api.property.read_write()
|
||||
api.owner.set(owners.meta1)
|
||||
return api
|
||||
|
||||
|
||||
#FIXME ne pas mettre 2 meta dans une config
|
||||
#FIXME ne pas mettre 2 OD differents dans un meta
|
||||
def test_none():
|
||||
api = make_metaconfig()
|
||||
assert api.option('od1.i3').value.get() is api.config('conf1').option('od1.i3').value.get() is api.config('conf2').option('od1.i3').value.get() is None
|
||||
assert api.option('od1.i3').owner.get() is api.config('conf1').option('od1.i3').owner.get() is api.config('conf2').option('od1.i3').owner.get() is owners.default
|
||||
#
|
||||
api.option('od1.i3').value.set(3)
|
||||
assert api.option('od1.i3').value.get() == api.config('conf1').option('od1.i3').value.get() == api.config('conf2').option('od1.i3').value.get() == 3
|
||||
assert api.option('od1.i3').owner.get() is api.config('conf1').option('od1.i3').owner.get() is api.config('conf2').option('od1.i3').owner.get() is owners.meta1
|
||||
#
|
||||
api.config('conf1').option('od1.i3').value.set(2)
|
||||
assert api.option('od1.i3').value.get() == api.config('conf2').option('od1.i3').value.get() == 3
|
||||
assert api.config('conf1').option('od1.i3').value.get() == 2
|
||||
assert api.option('od1.i3').owner.get() is api.config('conf2').option('od1.i3').owner.get() is owners.meta1
|
||||
assert api.config('conf1').option('od1.i3').owner.get() is owners.user
|
||||
#
|
||||
api.option('od1.i3').value.set(4)
|
||||
assert api.option('od1.i3').value.get() == api.config('conf2').option('od1.i3').value.get() == 4
|
||||
assert api.config('conf1').option('od1.i3').value.get() == 2
|
||||
assert api.option('od1.i3').owner.get() is api.config('conf2').option('od1.i3').owner.get() is owners.meta1
|
||||
assert api.config('conf1').option('od1.i3').owner.get() is owners.user
|
||||
#
|
||||
api.option('od1.i3').value.reset()
|
||||
assert api.option('od1.i3').value.get() is api.config('conf2').option('od1.i3').value.get() is None
|
||||
assert api.config('conf1').option('od1.i3').value.get() == 2
|
||||
assert api.option('od1.i3').owner.get() is api.config('conf2').option('od1.i3').owner.get() is owners.default
|
||||
assert api.config('conf1').option('od1.i3').owner.get() is owners.user
|
||||
#
|
||||
api.config('conf1').option('od1.i3').value.reset()
|
||||
assert api.option('od1.i3').value.get() is api.config('conf1').option('od1.i3').value.get() is api.config('conf2').option('od1.i3').value.get() is None
|
||||
assert api.option('od1.i3').owner.get() is api.config('conf1').option('od1.i3').owner.get() is api.config('conf2').option('od1.i3').owner.get() is owners.default
|
||||
#del(conf1)
|
||||
#del(conf2)
|
||||
|
||||
|
||||
def test_default():
|
||||
api = make_metaconfig()
|
||||
assert api.option('od1.i2').value.get() == api.config('conf1').option('od1.i2').value.get() == api.config('conf2').option('od1.i2').value.get() == 1
|
||||
assert api.option('od1.i2').owner.get() is api.config('conf1').option('od1.i2').owner.get() is api.config('conf2').option('od1.i2').owner.get() is owners.default
|
||||
#
|
||||
api.option('od1.i2').value.set(3)
|
||||
assert api.option('od1.i2').value.get() == api.config('conf1').option('od1.i2').value.get() == api.config('conf2').option('od1.i2').value.get() == 3
|
||||
assert api.option('od1.i2').owner.get() is api.config('conf1').option('od1.i2').owner.get() is api.config('conf2').option('od1.i2').owner.get() is owners.meta1
|
||||
#
|
||||
api.config('conf1').option('od1.i2').value.set(2)
|
||||
assert api.option('od1.i2').value.get() == api.config('conf2').option('od1.i2').value.get() == 3
|
||||
assert api.config('conf1').option('od1.i2').value.get() == 2
|
||||
assert api.option('od1.i2').owner.get() is api.config('conf2').option('od1.i2').owner.get() is owners.meta1
|
||||
assert api.config('conf1').option('od1.i2').owner.get() is owners.user
|
||||
#
|
||||
api.option('od1.i2').value.set(4)
|
||||
assert api.option('od1.i2').value.get() == api.config('conf2').option('od1.i2').value.get() == 4
|
||||
assert api.config('conf1').option('od1.i2').value.get() == 2
|
||||
assert api.option('od1.i2').owner.get() is api.config('conf2').option('od1.i2').owner.get() is owners.meta1
|
||||
assert api.config('conf1').option('od1.i2').owner.get() is owners.user
|
||||
#
|
||||
api.option('od1.i2').value.reset()
|
||||
assert api.option('od1.i2').value.get() == api.config('conf2').option('od1.i2').value.get() == 1
|
||||
assert api.config('conf1').option('od1.i2').value.get() == 2
|
||||
assert api.option('od1.i2').owner.get() is api.config('conf2').option('od1.i2').owner.get() is owners.default
|
||||
assert api.config('conf1').option('od1.i2').owner.get() is owners.user
|
||||
#
|
||||
api.config('conf1').option('od1.i2').value.reset()
|
||||
assert api.option('od1.i2').value.get() == api.config('conf1').option('od1.i2').value.get() == api.config('conf2').option('od1.i2').value.get() == 1
|
||||
assert api.option('od1.i2').owner.get() is api.config('conf1').option('od1.i2').owner.get() is api.config('conf2').option('od1.i2').owner.get() is owners.default
|
||||
|
||||
|
||||
def test_contexts():
|
||||
api = make_metaconfig()
|
||||
errors = api.value.set('od1.i2', 6, only_config=True)
|
||||
assert api.option('od1.i2').value.get() == 1
|
||||
assert api.option('od1.i2').owner.get() == owners.default
|
||||
assert api.config('conf1').option('od1.i2').value.get() == api.config('conf1').option('od1.i2').value.get() == 6
|
||||
assert api.config('conf1').option('od1.i2').owner.get() == api.config('conf1').option('od1.i2').owner.get() is owners.user
|
||||
assert len(errors) == 0
|
||||
|
||||
|
||||
def test_find():
|
||||
api = make_metaconfig()
|
||||
assert [1] == api.option.find('i2', type='value')
|
||||
assert 1 == api.option.find_first('i2', type='value')
|
||||
assert api.option.make_dict() == {'od1.i4': 2, 'od1.i1': None, 'od1.i3': None,
|
||||
'od1.i2': 1, 'od1.i5': [2]}
|
||||
|
||||
|
||||
def test_group_error():
|
||||
raises(ValueError, "GroupConfig('str')")
|
||||
raises(ValueError, "GroupConfig(['str'])")
|
||||
|
||||
|
||||
def test_meta_meta():
|
||||
api = make_metaconfig(double=True)
|
||||
assert api.option('od1.i2').value.get() == api.config('meta').option('od1.i2').value.get() == api.config('meta.conf1').option('od1.i2').value.get() == api.config('meta.conf2').option('od1.i2').value.get() == 1
|
||||
assert api.option('od1.i2').owner.get() is api.config('meta').option('od1.i2').owner.get() is api.config('meta.conf1').option('od1.i2').owner.get() is api.config('meta.conf2').option('od1.i2').owner.get() is owners.default
|
||||
#
|
||||
api.option('od1.i2').value.set(3)
|
||||
assert api.option('od1.i2').value.get() == api.config('meta').option('od1.i2').value.get() == api.config('meta.conf1').option('od1.i2').value.get() == api.config('meta.conf2').option('od1.i2').value.get() == 3
|
||||
assert api.option('od1.i2').owner.get() is api.config('meta').option('od1.i2').owner.get() is api.config('meta.conf1').option('od1.i2').owner.get() is api.config('meta.conf2').option('od1.i2').owner.get() is owners.meta1
|
||||
#
|
||||
api.config('meta.conf1').option('od1.i2').value.set(2)
|
||||
assert api.option('od1.i2').value.get() == api.config('meta').option('od1.i2').value.get() == api.config('meta.conf2').option('od1.i2').value.get() == 3
|
||||
assert api.config('meta.conf1').option('od1.i2').value.get() == 2
|
||||
assert api.option('od1.i2').owner.get() is api.config('meta').option('od1.i2').owner.get() is api.config('meta.conf2').option('od1.i2').owner.get() is owners.meta1
|
||||
assert api.config('meta.conf1').option('od1.i2').owner.get() is owners.user
|
||||
#
|
||||
api.config('meta').option('od1.i2').value.set(4)
|
||||
assert api.option('od1.i2').value.get() == 3
|
||||
assert api.config('meta').option('od1.i2').value.get() == api.config('meta.conf2').option('od1.i2').value.get() == 4
|
||||
assert api.config('meta.conf1').option('od1.i2').value.get() == 2
|
||||
assert api.option('od1.i2').owner.get() is owners.meta1
|
||||
assert api.config('meta').option('od1.i2').owner.get() is api.config('meta.conf2').option('od1.i2').owner.get() is owners.meta2
|
||||
assert api.config('meta.conf1').option('od1.i2').owner.get() is owners.user
|
||||
#
|
||||
api.config('meta').option('od1.i2').value.reset()
|
||||
assert api.option('od1.i2').value.get() == api.config('meta').option('od1.i2').value.get() == api.config('meta.conf2').option('od1.i2').value.get() == 3
|
||||
assert api.config('meta.conf1').option('od1.i2').value.get() == 2
|
||||
assert api.option('od1.i2').owner.get() is api.config('meta').option('od1.i2').owner.get() is api.config('meta.conf2').option('od1.i2').owner.get() is owners.meta1
|
||||
assert api.config('meta.conf1').option('od1.i2').owner.get() is owners.user
|
||||
#
|
||||
api.option('od1.i2').value.reset()
|
||||
assert api.option('od1.i2').value.get() == api.config('meta').option('od1.i2').value.get() == api.config('meta.conf2').option('od1.i2').value.get() == 1
|
||||
assert api.config('meta.conf1').option('od1.i2').value.get() == 2
|
||||
assert api.option('od1.i2').owner.get() is api.config('meta').option('od1.i2').owner.get() is api.config('meta.conf2').option('od1.i2').owner.get() is owners.default
|
||||
assert api.config('meta.conf1').option('od1.i2').owner.get() is owners.user
|
||||
#
|
||||
api.config('meta.conf1').option('od1.i2').value.reset()
|
||||
assert api.option('od1.i2').value.get() == api.config('meta').option('od1.i2').value.get() == api.config('meta.conf1').option('od1.i2').value.get() == api.config('meta.conf2').option('od1.i2').value.get() == 1
|
||||
assert api.option('od1.i2').owner.get() is api.config('meta').option('od1.i2').owner.get() is api.config('meta.conf1').option('od1.i2').owner.get() is api.config('meta.conf2').option('od1.i2').owner.get() is owners.default
|
||||
|
||||
|
||||
def test_meta_new_config():
|
||||
od = make_description()
|
||||
meta = MetaConfig(['name1', 'name2'], optiondescription=od)
|
||||
assert len(meta.cfgimpl_get_children()) == 2
|
||||
meta.new_config('newconf1')
|
||||
assert len(meta.cfgimpl_get_children()) == 3
|
||||
|
||||
|
||||
def test_meta_new_config_wrong_name():
|
||||
od = make_description()
|
||||
meta = MetaConfig(['name1', 'name2'], optiondescription=od)
|
||||
assert len(meta.cfgimpl_get_children()) == 2
|
||||
raises(ConflictError, "meta.new_config('name1')")
|
||||
assert len(meta.cfgimpl_get_children()) == 2
|
||||
|
||||
|
||||
def test_meta_meta_set():
|
||||
api = make_metaconfig(double=True)
|
||||
errors1 = api.value.set('od1.i1', 7, only_config=True)
|
||||
errors2 = api.value.set('od1.i6', 7, only_config=True)
|
||||
assert len(errors1) == 0
|
||||
assert len(errors2) == 2
|
||||
meta = api._config.getconfig('meta')
|
||||
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_first('i1', byvalue=7).cfgimpl_get_children()
|
||||
api.config('meta.conf1').option('od1.i1').value.set(8)
|
||||
assert [conf1, conf2] == api.config.find_first('i1').cfgimpl_get_children()
|
||||
assert [conf2] == api.config.find_first('i1', byvalue=7).cfgimpl_get_children()
|
||||
assert [conf1] == api.config.find_first('i1', byvalue=8).cfgimpl_get_children()
|
||||
assert [conf1, conf2] == api.config.find_first('i5', byvalue=2).cfgimpl_get_children()
|
||||
raises(AttributeError, "api.config.find_first('i1', byvalue=10)")
|
||||
raises(AttributeError, "api.config.find_first('not', byvalue=10)")
|
||||
raises(AttributeError, "api.config.find_first('i6')")
|
||||
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)")
|
||||
raises(ValueError, "api.value.set('od1.i6', 7, only_config=True, force_dont_change_value=True)")
|
||||
|
||||
|
||||
def test_not_meta():
|
||||
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(ValueError, "GroupConfig(conf1)")
|
||||
#same name
|
||||
raises(ConflictError, "GroupConfig([conf2, conf4], session_id='conf2')")
|
||||
grp = GroupConfig([conf1, conf2])
|
||||
api = getapi(grp)
|
||||
raises(ConfigError, "api.option('od1.i1').value.get()")
|
||||
conf1, conf2 = grp.cfgimpl_get_children()
|
||||
errors = api.value.set('od1.i1', 7)
|
||||
assert len(errors) == 0
|
||||
assert api.config('conf1').option('od1.i1').value.get() == api.config('conf2').option('od1.i1').value.get() == 7
|
||||
assert api.config('conf1').option('od1.i1').owner.get() is api.config('conf2').option('od1.i1').owner.get() is owners.user
|
||||
|
||||
|
||||
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])
|
||||
api = getapi(grp)
|
||||
assert [conf1, conf2] == api.config.find_first('i1').cfgimpl_get_children()
|
||||
|
||||
|
||||
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])
|
||||
api = getapi(grp2)
|
||||
errors = api.value.set('od1.i1', 2)
|
||||
assert len(errors) == 0
|
||||
assert api.config('grp.conf9').option('od1.i1').value.get() == 2
|
||||
assert api.config('grp.conf9').option('od1.i1').owner.get() is owners.user
|
||||
|
||||
|
||||
def test_meta_unconsistent():
|
||||
i1 = IntOption('i1', '')
|
||||
i2 = IntOption('i2', '', default=1)
|
||||
i3 = IntOption('i3', '')
|
||||
i4 = IntOption('i4', '', default=2)
|
||||
od1 = OptionDescription('od1', '', [i1, i2, i3, i4])
|
||||
od2 = OptionDescription('od2', '', [od1])
|
||||
od3 = OptionDescription('od3', '', [od1])
|
||||
conf1 = Config(od2, session_id='conf1')
|
||||
conf2 = Config(od2, session_id='conf2')
|
||||
conf3 = Config(od2, session_id='conf3')
|
||||
conf4 = Config(od3, session_id='conf4')
|
||||
api = getapi(MetaConfig([conf1, conf2]))
|
||||
api.owner.set(owners.meta1)
|
||||
raises(TypeError, 'MetaConfig("string")')
|
||||
#same descr but conf1 already in meta
|
||||
raises(ValueError, "MetaConfig([conf1, conf3])")
|
||||
#not same descr
|
||||
raises(ValueError, "MetaConfig([conf3, conf4])")
|
||||
raises(ConfigError, "api.config('conf1').property.read_only()")
|
||||
|
||||
|
||||
def test_meta_master_slaves():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
od = OptionDescription('root', '', [interface1])
|
||||
conf1 = Config(od, session_id='conf1')
|
||||
conf2 = Config(od, session_id='conf2')
|
||||
api = getapi(MetaConfig([conf1, conf2]))
|
||||
api.property.read_only()
|
||||
assert [conf1, conf2] == api.config.find_first('ip_admin_eth0').cfgimpl_get_children()
|
||||
assert [conf1, conf2] == api.config.find_first('netmask_admin_eth0').cfgimpl_get_children()
|
||||
api.property.read_write()
|
||||
raises(AttributeError, "api.config.find_first('netmask_admin_eth0')")
|
||||
assert [conf1, conf2] == api.unrestraint.config.find_first('netmask_admin_eth0').cfgimpl_get_children()
|
||||
api.property.read_only()
|
||||
assert [conf1, conf2] == api.config.find_first('netmask_admin_eth0').cfgimpl_get_children()
|
||||
|
||||
|
||||
def test_meta_master_slaves_value2():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
od = OptionDescription('root', '', [interface1])
|
||||
conf1 = Config(od, session_id='conf1')
|
||||
conf2 = Config(od, session_id='conf2')
|
||||
meta = MetaConfig([conf1, conf2], session_id="meta")
|
||||
api = getapi(meta)
|
||||
api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.8'])
|
||||
assert api.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
|
||||
#FIXME devrait raise ! assert api.config('conf1').option('ip_admin_eth0.ip_admin_eth0', 0).value.get() == None
|
||||
#
|
||||
api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.reset()
|
||||
#
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
|
||||
assert api.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
|
||||
assert api.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.0.0')
|
||||
assert api.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0'
|
||||
#
|
||||
api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
|
||||
assert api.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
|
||||
|
||||
|
||||
def test_meta_master_slaves_value_default():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1'])
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
od = OptionDescription('root', '', [interface1])
|
||||
conf1 = Config(od, session_id='conf1')
|
||||
conf2 = Config(od, session_id='conf2')
|
||||
api = getapi(MetaConfig([conf1, conf2]))
|
||||
assert api.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
|
||||
#
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
|
||||
assert api.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
|
||||
#
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
|
||||
assert api.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
|
||||
#
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.0.0')
|
||||
assert api.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0'
|
||||
#
|
||||
api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
|
||||
assert api.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
|
||||
|
||||
|
||||
def test_meta_master_slaves_owners():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
od = OptionDescription('root', '', [interface1])
|
||||
conf1 = Config(od, session_id='conf1')
|
||||
conf2 = Config(od, session_id='conf2')
|
||||
api = getapi(MetaConfig([conf1, conf2]))
|
||||
api.owner.set(owners.meta1)
|
||||
assert api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
|
||||
assert api.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
|
||||
#
|
||||
api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
|
||||
assert api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.user
|
||||
assert api.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
|
||||
#
|
||||
api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.reset()
|
||||
assert api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
|
||||
assert api.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
|
||||
#
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
|
||||
assert api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.meta1
|
||||
assert api.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
|
||||
#
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
|
||||
assert api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.meta1
|
||||
assert api.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.meta1
|
||||
#
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.0.0')
|
||||
assert api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.meta1
|
||||
assert api.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.meta1
|
||||
#
|
||||
api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
|
||||
assert api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.user
|
||||
assert api.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.default
|
||||
|
||||
|
||||
def test_meta_force_default():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
od = OptionDescription('root', '', [interface1])
|
||||
conf1 = Config(od, session_id='conf1')
|
||||
conf2 = Config(od, session_id='conf2')
|
||||
api = getapi(MetaConfig([conf1, conf2]))
|
||||
api.property.read_write()
|
||||
api.owner.set('meta1')
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
assert api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
assert api.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
#
|
||||
errors = api.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.1'])
|
||||
assert len(errors) == 0
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
|
||||
assert api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
|
||||
assert api.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
|
||||
#
|
||||
api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
|
||||
assert api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
|
||||
assert api.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
|
||||
#
|
||||
errors = api.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.3'])
|
||||
assert len(errors) == 0
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3']
|
||||
assert api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
|
||||
assert api.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3']
|
||||
#
|
||||
errors = api.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_default=True)
|
||||
assert len(errors) == 0
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
|
||||
assert api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
|
||||
assert api.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
|
||||
|
||||
|
||||
def test_meta_force_dont_change_value():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
od = OptionDescription('root', '', [interface1])
|
||||
conf1 = Config(od, session_id='conf1')
|
||||
conf2 = Config(od, session_id='conf2')
|
||||
api = getapi(MetaConfig([conf1, conf2]))
|
||||
api.property.read_write()
|
||||
api.owner.set('meta1')
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
assert api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
assert api.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.4'])
|
||||
assert api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
|
||||
assert api.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
assert api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
|
||||
assert api.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
|
||||
errors = api.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_dont_change_value=True)
|
||||
assert len(errors) == 0
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
|
||||
assert api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
|
||||
assert api.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
assert api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
|
||||
assert api.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
|
||||
|
||||
|
||||
def test_meta_force_default_if_same():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
od = OptionDescription('root', '', [interface1])
|
||||
conf1 = Config(od, session_id='conf1')
|
||||
conf2 = Config(od, session_id='conf2')
|
||||
api = getapi(MetaConfig([conf1, conf2]))
|
||||
api.property.read_write()
|
||||
api.owner.set('meta1')
|
||||
#
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
assert api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
assert api.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
#
|
||||
api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.4'])
|
||||
assert api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
|
||||
assert api.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
assert api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
|
||||
assert api.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
|
||||
errors = api.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_default_if_same=True)
|
||||
assert len(errors) == 0
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
|
||||
assert api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
|
||||
assert api.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
|
||||
assert api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.meta1
|
||||
assert api.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.meta1
|
||||
#
|
||||
api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.3'])
|
||||
assert api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3']
|
||||
assert api.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
|
||||
assert api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
|
||||
assert api.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.meta1
|
||||
errors = api.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.5'], force_default_if_same=True)
|
||||
assert len(errors) == 0
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.5']
|
||||
assert api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3']
|
||||
assert api.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.5']
|
||||
assert api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
|
||||
assert api.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.meta1
|
||||
|
||||
|
||||
def test_meta_force_default_if_same_and_dont_change():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
od = OptionDescription('root', '', [interface1])
|
||||
conf1 = Config(od, session_id='conf1')
|
||||
conf2 = Config(od, session_id='conf2')
|
||||
api = getapi(MetaConfig([conf1, conf2]))
|
||||
api.property.read_write()
|
||||
api.owner.set('meta1')
|
||||
#
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
assert api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
assert api.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
#
|
||||
api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.4'])
|
||||
assert api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
|
||||
assert api.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
assert api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
|
||||
assert api.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
|
||||
errors = api.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_default_if_same=True, force_dont_change_value=True)
|
||||
assert len(errors) == 0
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
|
||||
assert api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
|
||||
assert api.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
assert api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.meta1
|
||||
assert api.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
|
||||
#
|
||||
api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.3'])
|
||||
assert api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3']
|
||||
assert api.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
assert api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
|
||||
assert api.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
|
||||
errors = api.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.5'], force_default_if_same=True, force_dont_change_value=True)
|
||||
assert len(errors) == 0
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.5']
|
||||
assert api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3']
|
||||
assert api.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
assert api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
|
||||
assert api.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
|
||||
|
||||
|
||||
def test_meta_force_default_and_dont_change():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
od = OptionDescription('root', '', [interface1])
|
||||
conf1 = Config(od, session_id='rconf1')
|
||||
conf2 = Config(od, session_id='rconf2')
|
||||
api = getapi(MetaConfig([conf1, conf2]))
|
||||
api.property.read_write()
|
||||
api.owner.set('meta1')
|
||||
raises(ValueError, "api.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_default=True, force_dont_change_value=True)")
|
||||
|
||||
|
||||
def test_meta_properties_meta():
|
||||
ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1'])
|
||||
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, properties=('disabled',))
|
||||
netmask_admin_eth0.impl_add_consistency('network_netmask', ip_admin_eth0)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
od = OptionDescription('root', '', [interface1])
|
||||
conf1 = Config(od, session_id='conf1')
|
||||
conf2 = Config(od, session_id='conf2')
|
||||
api = getapi(MetaConfig([conf1, conf2]))
|
||||
api.property.read_write()
|
||||
assert api.config('conf1').option.make_dict() == {}
|
||||
|
||||
|
||||
def test_meta_exception_meta():
|
||||
ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1'])
|
||||
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, callback=raise_exception)
|
||||
netmask_admin_eth0.impl_add_consistency('network_netmask', ip_admin_eth0)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
od = OptionDescription('root', '', [interface1])
|
||||
conf1 = Config(od, session_id='conf1')
|
||||
conf2 = Config(od, session_id='conf2')
|
||||
api = getapi(MetaConfig([conf1, conf2]))
|
||||
api.property.read_write()
|
||||
raises(Exception, "conf1.make_dict()")
|
||||
|
||||
|
||||
def test_meta_callback():
|
||||
val1 = StrOption('val1', "", 'val')
|
||||
val2 = StrOption('val2', "", callback=return_value, callback_params={'': ((val1, False),)})
|
||||
val3 = StrOption('val3', "", callback=return_value, callback_params={'': ('yes',)})
|
||||
val4 = StrOption('val4', "", callback=return_value, callback_params={'value': ((val1, False),)})
|
||||
val5 = StrOption('val5', "", callback=return_value, callback_params={'value': ('yes',)})
|
||||
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4, val5])
|
||||
cfg = Config(maconfig, session_id='cfg')
|
||||
api = getapi(MetaConfig([cfg]))
|
||||
api.property.read_write()
|
||||
assert api.config('cfg').option.make_dict() == {'val3': 'yes', 'val2': 'val', 'val1': 'val', 'val5': 'yes', 'val4': 'val'}
|
||||
api.config('cfg').option('val1').value.set('new')
|
||||
assert api.config('cfg').option.make_dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new'}
|
||||
api.config('cfg').option('val1').value.reset()
|
||||
api.option('val1').value.set('new')
|
||||
assert api.config('cfg').option.make_dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new'}
|
||||
api.config('cfg').option('val4').value.set('new1')
|
||||
assert api.config('cfg').option.make_dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new1'}
|
||||
api.config('cfg').option('val4').value.reset()
|
||||
api.option('val4').value.set('new1')
|
||||
assert api.config('cfg').option.make_dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new1'}
|
||||
api.option('val4').value.reset()
|
||||
|
||||
|
||||
def test_meta_callback_slave():
|
||||
val = StrOption('val', "", default='val')
|
||||
val1 = StrOption('val1', "", multi=True, callback=return_value, callback_params={'': ((val, False),)})
|
||||
val3 = StrOption('val2', "", multi=True, callback=return_value, callback_params={'': ((val1, False),)})
|
||||
val4 = StrOption('val3', "", multi=True, callback=return_value, callback_params={'': ((val1, False),)})
|
||||
interface1 = MasterSlaves('val1', '', [val1, val3, val4])
|
||||
od = OptionDescription('root', '', [interface1])
|
||||
maconfig = OptionDescription('rootconfig', '', [val, interface1])
|
||||
cfg = Config(maconfig, session_id='cfg1')
|
||||
api = getapi(MetaConfig([cfg]))
|
||||
api.property.read_write()
|
||||
assert api.config('cfg1').option.make_dict() == {'val1.val2': ['val'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
|
||||
api.config('cfg1').option('val').value.set('val1')
|
||||
assert api.config('cfg1').option.make_dict() == {'val1.val2': ['val1'], 'val1.val1': ['val1'], 'val1.val3': ['val1'], 'val': 'val1'}
|
||||
api.config('cfg1').option('val').value.reset()
|
||||
api.option('val').value.set('val1')
|
||||
assert api.config('cfg1').option.make_dict() == {'val1.val2': ['val1'], 'val1.val1': ['val1'], 'val1.val3': ['val1'], 'val': 'val1'}
|
||||
api.option('val').value.reset()
|
||||
api.config('cfg1').option('val1.val2', 0).value.set('val2')
|
||||
assert api.config('cfg1').option.make_dict() == {'val1.val2': ['val2'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
|
||||
api.config('cfg1').option('val1.val2', 0).value.reset()
|
||||
assert api.config('cfg1').option.make_dict() == {'val1.val2': ['val'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
|
||||
api.option('val1.val2', 0).value.set('val2')
|
||||
assert api.config('cfg1').option.make_dict() == {'val1.val2': ['val2'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
|
||||
api.config('cfg1').option('val1.val3', 0).value.set('val6')
|
||||
assert api.config('cfg1').option.make_dict() == {'val1.val2': ['val2'], 'val1.val1': ['val'], 'val1.val3': ['val6'], 'val': 'val'}
|
||||
api.option('val1.val2', 0).value.reset()
|
||||
api.config('cfg1').option('val1.val3', 0).value.reset()
|
||||
api.config('cfg1').option('val1.val1').value.set(['val3'])
|
||||
assert api.config('cfg1').option.make_dict() == {'val1.val2': ['val3'], 'val1.val1': ['val3'], 'val1.val3': ['val3'], 'val': 'val'}
|
||||
api.config('cfg1').option('val1.val1').value.reset()
|
||||
assert api.config('cfg1').option.make_dict() == {'val1.val2': ['val'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
|
||||
api.option('val1.val1').value.set(['val3'])
|
||||
assert api.config('cfg1').option.make_dict() == {'val1.val2': ['val3'], 'val1.val1': ['val3'], 'val1.val3': ['val3'], 'val': 'val'}
|
||||
api.config('cfg1').option('val1.val2', 0).value.set('val2')
|
||||
assert api.config('cfg1').option.make_dict() == {'val1.val2': ['val2'], 'val1.val1': ['val3'], 'val1.val3': ['val3'], 'val': 'val'}
|
||||
api.option('val1.val1').value.set(['val3', 'rah'])
|
||||
assert api.config('cfg1').option.make_dict() == {'val1.val2': ['val2', 'rah'], 'val1.val1': ['val3', 'rah'], 'val1.val3': ['val3', 'rah'], 'val': 'val'}
|
||||
api.option('val1.val1').value.pop(1)
|
||||
api.option('val1.val1').value.set(['val4'])
|
||||
assert api.config('cfg1').option.make_dict() == {'val1.val2': ['val2'], 'val1.val1': ['val4'], 'val1.val3': ['val4'], 'val': 'val'}
|
||||
|
||||
|
||||
def test_meta_reset():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
od = OptionDescription('root', '', [interface1])
|
||||
conf1 = Config(od, session_id='conf1')
|
||||
conf2 = Config(od, session_id='conf2')
|
||||
api = getapi(MetaConfig([conf1, conf2]))
|
||||
api.property.read_write()
|
||||
api.owner.set('meta1')
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
assert api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
assert api.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
errors = api.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.1'])
|
||||
assert len(errors) == 0
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
|
||||
assert api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
|
||||
assert api.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
|
||||
api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
|
||||
assert api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
|
||||
assert api.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
|
||||
api.value.reset('ip_admin_eth0.ip_admin_eth0')
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
assert api.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
assert api.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
|
||||
|
||||
def test_meta_properties_meta_set_value():
|
||||
ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1'])
|
||||
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, properties=('disabled',))
|
||||
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
conf1 = Config(interface1, session_id='conf1')
|
||||
conf2 = Config(interface1, session_id='conf2')
|
||||
api = getapi(MetaConfig([conf1, conf2]))
|
||||
api.property.read_write()
|
||||
assert api.config('conf1').option.make_dict() == {'ip_admin_eth0': ['192.168.1.1']}
|
||||
ret = api.value.set('netmask_admin_eth0', ['255.255.255.255'], only_config=True)
|
||||
assert len(ret) == 2
|
||||
assert isinstance(ret[0], PropertiesOptionError)
|
||||
assert isinstance(ret[1], PropertiesOptionError)
|
||||
del(ret)
|
||||
ret = api.value.set('netmask_admin_eth0', ['255.255.255.255'], force_default=True)
|
||||
assert len(ret) == 1
|
||||
assert isinstance(ret[0], PropertiesOptionError)
|
||||
del(ret)
|
||||
ret = api.value.set('netmask_admin_eth0', ['255.255.255.255'], force_dont_change_value=True)
|
||||
assert len(ret) == 3
|
||||
assert isinstance(ret[0], PropertiesOptionError)
|
||||
assert isinstance(ret[1], PropertiesOptionError)
|
||||
assert isinstance(ret[2], PropertiesOptionError)
|
||||
del(ret)
|
||||
ret = api.value.set('netmask_admin_eth0', ['255.255.255.255'], force_default_if_same=True)
|
||||
assert len(ret) == 1
|
||||
assert isinstance(ret[0], PropertiesOptionError)
|
||||
del(ret)
|
||||
ret = api.value.set('ip_admin_eth0', '255.255.255.255', only_config=True)
|
||||
assert len(ret) == 2
|
||||
assert isinstance(ret[0], ValueError)
|
||||
assert isinstance(ret[1], ValueError)
|
||||
del(ret)
|
||||
ret = api.value.set('ip_admin_eth0', '255.255.255.255', force_default=True)
|
||||
assert len(ret) == 1
|
||||
assert isinstance(ret[0], ValueError)
|
||||
del(ret)
|
||||
ret = api.value.set('ip_admin_eth0', '255.255.255.255', force_dont_change_value=True)
|
||||
assert len(ret) == 1
|
||||
assert isinstance(ret[0], ValueError)
|
||||
del(ret)
|
||||
ret = api.value.set('ip_admin_eth0', '255.255.255.255', force_default_if_same=True)
|
||||
assert len(ret) == 1
|
||||
assert isinstance(ret[0], ValueError)
|
||||
del(ret)
|
||||
|
|
@ -1,99 +0,0 @@
|
|||
"""these tests are here to create some :class:`tiramisu.option.Option`'s
|
||||
and to compare them
|
||||
"""
|
||||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
|
||||
from py.test import raises
|
||||
|
||||
from tiramisu.option import IntOption, OptionDescription
|
||||
from tiramisu.config import Config
|
||||
|
||||
|
||||
def a_func():
|
||||
return None
|
||||
|
||||
|
||||
def test_option_valid_name():
|
||||
IntOption('test', '')
|
||||
raises(ValueError, 'IntOption(1, "")')
|
||||
raises(ValueError, 'IntOption("1test", "")')
|
||||
IntOption("test1", "")
|
||||
raises(ValueError, 'IntOption("impl_test", "")')
|
||||
raises(ValueError, 'IntOption("_test", "")')
|
||||
raises(ValueError, 'IntOption("unwrap_from_path", "")')
|
||||
raises(ValueError, 'IntOption(" ", "")')
|
||||
|
||||
|
||||
def test_option_with_callback():
|
||||
#no default value with callback
|
||||
raises(ValueError, "IntOption('test', '', default=1, callback=a_func)")
|
||||
|
||||
|
||||
def test_option_get_information():
|
||||
description = "it's ok"
|
||||
string = 'some informations'
|
||||
i = IntOption('test', description)
|
||||
raises(ValueError, "i.impl_get_information('noinfo')")
|
||||
i.impl_set_information('info', string)
|
||||
assert i.impl_get_information('info') == string
|
||||
raises(ValueError, "i.impl_get_information('noinfo')")
|
||||
assert i.impl_get_information('noinfo', 'default') == 'default'
|
||||
assert i.impl_get_information('doc') == description
|
||||
assert i.impl_getdoc() == description
|
||||
|
||||
|
||||
def test_option_get_information_config():
|
||||
description = "it's ok"
|
||||
string = 'some informations'
|
||||
string
|
||||
i = IntOption('test', description)
|
||||
od = OptionDescription('od', '', [i])
|
||||
Config(od)
|
||||
raises(ValueError, "i.impl_get_information('noinfo')")
|
||||
raises(AttributeError, "i.impl_set_information('info', string)")
|
||||
# assert i.impl_get_information('info') == string
|
||||
raises(ValueError, "i.impl_get_information('noinfo')")
|
||||
assert i.impl_get_information('noinfo', 'default') == 'default'
|
||||
assert i.impl_get_information('doc') == description
|
||||
assert i.impl_getdoc() == description
|
||||
|
||||
|
||||
def test_option_get_information_config2():
|
||||
description = "it's ok"
|
||||
string = 'some informations'
|
||||
i = IntOption('test', description)
|
||||
i.impl_set_information('info', string)
|
||||
od = OptionDescription('od', '', [i])
|
||||
Config(od)
|
||||
raises(ValueError, "i.impl_get_information('noinfo')")
|
||||
raises(AttributeError, "i.impl_set_information('info', 'hello')")
|
||||
assert i.impl_get_information('info') == string
|
||||
raises(ValueError, "i.impl_get_information('noinfo')")
|
||||
assert i.impl_get_information('noinfo', 'default') == 'default'
|
||||
assert i.impl_get_information('doc') == description
|
||||
assert i.impl_getdoc() == description
|
||||
|
||||
|
||||
def test_optiondescription_get_information():
|
||||
description = "it's ok"
|
||||
string = 'some informations'
|
||||
o = OptionDescription('test', description, [])
|
||||
o.impl_set_information('info', string)
|
||||
assert o.impl_get_information('info') == string
|
||||
raises(ValueError, "o.impl_get_information('noinfo')")
|
||||
assert o.impl_get_information('noinfo', 'default') == 'default'
|
||||
assert o.impl_get_information('doc') == description
|
||||
assert o.impl_getdoc() == description
|
||||
|
||||
|
||||
def test_option_multi():
|
||||
IntOption('test', '', multi=True)
|
||||
IntOption('test', '', multi=True, default_multi=1)
|
||||
IntOption('test', '', default=[1], multi=True, default_multi=1)
|
||||
#add default_multi to not multi's option
|
||||
raises(ValueError, "IntOption('test', '', default_multi=1)")
|
||||
#unvalid default_multi
|
||||
raises(ValueError, "IntOption('test', '', multi=True, default_multi='yes')")
|
||||
#not default_multi with callback
|
||||
raises(ValueError, "IntOption('test', '', multi=True, default_multi=1, callback=a_func)")
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,837 +0,0 @@
|
|||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
|
||||
from py.test import raises
|
||||
|
||||
from tiramisu.setting import owners, groups
|
||||
from tiramisu import IPOption, NetworkOption, NetmaskOption, IntOption,\
|
||||
BroadcastOption, StrOption, SymLinkOption, OptionDescription, submulti, MasterSlaves,\
|
||||
Config, getapi, undefined
|
||||
from tiramisu.error import ConfigError, ValueWarning, PropertiesOptionError
|
||||
import warnings
|
||||
|
||||
|
||||
def return_value(value=None):
|
||||
return value
|
||||
|
||||
|
||||
def test_consistency():
|
||||
a = IntOption('a', '')
|
||||
b = IntOption('b', '')
|
||||
a.impl_add_consistency('not_equal', b)
|
||||
#consistency to itself
|
||||
raises(ConfigError, "a.impl_add_consistency('not_equal', a)")
|
||||
|
||||
|
||||
def test_consistency_not_exists():
|
||||
a = IntOption('a', '')
|
||||
b = IntOption('b', '')
|
||||
a, b
|
||||
raises(ConfigError, "a.impl_add_consistency('not_exists', b)")
|
||||
|
||||
|
||||
def test_consistency_unknown_params():
|
||||
a = IntOption('a', '')
|
||||
b = IntOption('b', '')
|
||||
a, b
|
||||
raises(ValueError, "a.impl_add_consistency('not_equal', b, unknown=False)")
|
||||
|
||||
|
||||
def test_consistency_warnings_only_default():
|
||||
a = IntOption('a', '', 1)
|
||||
b = IntOption('b', '', 1)
|
||||
warnings.simplefilter("always", ValueWarning)
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
a.impl_add_consistency('not_equal', b, warnings_only=True)
|
||||
assert w != []
|
||||
|
||||
|
||||
def test_consistency_warnings_only():
|
||||
a = IntOption('a', '')
|
||||
b = IntOption('b', '')
|
||||
od = OptionDescription('od', '', [a, b])
|
||||
a.impl_add_consistency('not_equal', b, warnings_only=True)
|
||||
api = getapi(Config(od))
|
||||
api.option('a').value.set(1)
|
||||
warnings.simplefilter("always", ValueWarning)
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('b').value.set(1)
|
||||
assert w != []
|
||||
|
||||
|
||||
def test_consistency_warnings_only_more_option():
|
||||
a = IntOption('a', '')
|
||||
b = IntOption('b', '')
|
||||
d = IntOption('d', '')
|
||||
od = OptionDescription('od', '', [a, b, d])
|
||||
a.impl_add_consistency('not_equal', b, d, warnings_only=True)
|
||||
api = getapi(Config(od))
|
||||
api.option('a').value.set(1)
|
||||
warnings.simplefilter("always", ValueWarning)
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('b').value.set(1)
|
||||
assert w != []
|
||||
assert len(w) == 1
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('d').value.get()
|
||||
assert w != []
|
||||
assert len(w) == 1
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('d').value.set(1)
|
||||
assert w != []
|
||||
assert len(w) == 1
|
||||
|
||||
|
||||
def test_consistency_not_equal():
|
||||
a = IntOption('a', '')
|
||||
b = IntOption('b', '')
|
||||
od = OptionDescription('od', '', [a, b])
|
||||
a.impl_add_consistency('not_equal', b)
|
||||
api = getapi(Config(od))
|
||||
assert api.option('a').value.get() is None
|
||||
assert api.option('b').value.get() is None
|
||||
api.option('a').value.set(1)
|
||||
api.option('a').value.reset()
|
||||
api.option('a').value.set(1)
|
||||
raises(ValueError, "api.option('b').value.set(1)")
|
||||
api.option('b').value.set(2)
|
||||
|
||||
|
||||
def test_consistency_not_equal_many_opts():
|
||||
a = IntOption('a', '')
|
||||
b = IntOption('b', '')
|
||||
c = IntOption('c', '')
|
||||
d = IntOption('d', '')
|
||||
e = IntOption('e', '')
|
||||
f = IntOption('f', '')
|
||||
od = OptionDescription('od', '', [a, b, c, d, e, f])
|
||||
a.impl_add_consistency('not_equal', b, c, d, e, f)
|
||||
api = getapi(Config(od))
|
||||
assert api.option('a').value.get() is None
|
||||
assert api.option('b').value.get() is None
|
||||
#
|
||||
api.option('a').value.set(1)
|
||||
api.option('a').value.reset()
|
||||
#
|
||||
api.option('a').value.set(1)
|
||||
raises(ValueError, "api.option('b').value.set(1)")
|
||||
#
|
||||
api.option('b').value.set(2)
|
||||
raises(ValueError, "api.option('f').value.set(2)")
|
||||
raises(ValueError, "api.option('f').value.set(1)")
|
||||
#
|
||||
api.option('d').value.set(3)
|
||||
raises(ValueError, "api.option('f').value.set(3)")
|
||||
raises(ValueError, "api.option('a').value.set(3)")
|
||||
api.option('d').value.set(3)
|
||||
raises(ValueError, "api.option('c').value.set(3)")
|
||||
raises(ValueError, "api.option('e').value.set(3)")
|
||||
|
||||
|
||||
def test_consistency_not_equal_many_opts_one_disabled():
|
||||
a = IntOption('a', '')
|
||||
b = IntOption('b', '')
|
||||
c = IntOption('c', '')
|
||||
d = IntOption('d', '')
|
||||
e = IntOption('e', '')
|
||||
f = IntOption('f', '')
|
||||
g = IntOption('g', '', properties=('disabled',))
|
||||
od = OptionDescription('od', '', [a, b, c, d, e, f, g])
|
||||
a.impl_add_consistency('not_equal', b, c, d, e, f, g, transitive=False)
|
||||
api = getapi(Config(od))
|
||||
api.property.read_write()
|
||||
assert api.option('a').value.get() is None
|
||||
assert api.option('b').value.get() is None
|
||||
#
|
||||
api.option('a').value.set(1)
|
||||
api.option('a').value.reset()
|
||||
#
|
||||
api.option('a').value.set(1)
|
||||
raises(ValueError, "api.option('b').value.set(1)")
|
||||
#
|
||||
api.option('b').value.set(2)
|
||||
raises(ValueError, "api.option('f').value.set(2)")
|
||||
raises(ValueError, "api.option('f').value.set(1)")
|
||||
#
|
||||
api.option('d').value.set(3)
|
||||
raises(ValueError, "api.option('f').value.set(3)")
|
||||
raises(ValueError, "api.option('a').value.set(3)")
|
||||
raises(ValueError, "api.option('c').value.set(3)")
|
||||
raises(ValueError, "api.option('e').value.set(3)")
|
||||
|
||||
|
||||
def test_consistency_not_in_config_1():
|
||||
a = IntOption('a', '')
|
||||
b = IntOption('b', '')
|
||||
a.impl_add_consistency('not_equal', b)
|
||||
od1 = OptionDescription('od1', '', [a])
|
||||
od = OptionDescription('root', '', [od1])
|
||||
od
|
||||
raises(ConfigError, "Config(od)")
|
||||
|
||||
|
||||
def test_consistency_not_in_config_2():
|
||||
a = IntOption('a', '')
|
||||
b = IntOption('b', '')
|
||||
a.impl_add_consistency('not_equal', b)
|
||||
od1 = OptionDescription('od1', '', [a])
|
||||
od2 = OptionDescription('od2', '', [b])
|
||||
od = OptionDescription('root', '', [od1, od2])
|
||||
Config(od)
|
||||
|
||||
|
||||
def test_consistency_not_in_config_3():
|
||||
a = IntOption('a', '')
|
||||
b = IntOption('b', '')
|
||||
a.impl_add_consistency('not_equal', b)
|
||||
od1 = OptionDescription('od1', '', [a])
|
||||
od2 = OptionDescription('od2', '', [b])
|
||||
od = OptionDescription('root', '', [od1, od2])
|
||||
od
|
||||
#with subconfig
|
||||
raises(ConfigError, "Config(od1)")
|
||||
|
||||
|
||||
def test_consistency_after_config():
|
||||
a = IntOption('a', '')
|
||||
b = IntOption('b', '')
|
||||
od1 = OptionDescription('od1', '', [a])
|
||||
od2 = OptionDescription('od2', '', [b])
|
||||
od = OptionDescription('root', '', [od1, od2])
|
||||
Config(od)
|
||||
raises(AttributeError, "a.impl_add_consistency('not_equal', b)")
|
||||
|
||||
|
||||
def test_consistency_not_equal_symlink():
|
||||
a = IntOption('a', '')
|
||||
b = IntOption('b', '')
|
||||
c = SymLinkOption('c', a)
|
||||
od = OptionDescription('od', '', [a, b, c])
|
||||
a.impl_add_consistency('not_equal', b)
|
||||
api = getapi(Config(od))
|
||||
assert set(od._cache_consistencies.keys()) == set([a, b])
|
||||
|
||||
|
||||
def test_consistency_not_equal_submulti():
|
||||
a = IntOption('a', '', multi=submulti)
|
||||
b = IntOption('b', '', multi=submulti)
|
||||
od = OptionDescription('a', '', [a, b])
|
||||
raises(ConfigError, 'a.impl_add_consistency("not_equal", b)')
|
||||
|
||||
|
||||
def test_consistency_not_equal_default_submulti():
|
||||
a = IntOption('a', '', [[1, 2]], multi=submulti)
|
||||
b = IntOption('b', '', [[1]], multi=submulti)
|
||||
od = OptionDescription('od', '', [a, b])
|
||||
od
|
||||
raises(ConfigError, "a.impl_add_consistency('not_equal', b)")
|
||||
|
||||
|
||||
def test_consistency_not_equal_masterslave():
|
||||
a = IntOption('a', '', multi=True)
|
||||
b = IntOption('b', '', multi=True)
|
||||
od = MasterSlaves('a', '', [a, b])
|
||||
od2 = OptionDescription('b', '', [od])
|
||||
#od.impl_set_group_type(groups.master)
|
||||
a.impl_add_consistency('not_equal', b)
|
||||
api = getapi(Config(od2))
|
||||
assert api.option('a.a').value.get() == []
|
||||
api.option('a.a').value.set([1])
|
||||
api.option('a.a').value.reset()
|
||||
api.option('a.a').value.set([1])
|
||||
raises(ValueError, "api.option('a.b', 0).value.set(1)")
|
||||
api.option('a.b', 0).value.set(2)
|
||||
api.option('a.a').value.reset()
|
||||
api.option('a.a').value.set([1])
|
||||
api.option.make_dict()
|
||||
|
||||
|
||||
def test_consistency_not_equal_masterslave_error_multi1():
|
||||
a = IPOption('a', '', multi=True)
|
||||
b = NetmaskOption('b', '', multi=True)
|
||||
c = NetmaskOption('c', '', multi=True)
|
||||
od = MasterSlaves('a', '', [a, b])
|
||||
#od.impl_set_group_type(groups.master)
|
||||
od2 = OptionDescription('b', '', [od, c])
|
||||
c.impl_add_consistency('ip_netmask', a)
|
||||
raises(ConfigError, "Config(od2)")
|
||||
|
||||
|
||||
def test_consistency_not_equal_masterslave_error_multi2():
|
||||
a = IPOption('a', '', multi=True)
|
||||
b = NetmaskOption('b', '', multi=True)
|
||||
c = IPOption('c', '', multi=True)
|
||||
od = MasterSlaves('a', '', [a, b])
|
||||
#od.impl_set_group_type(groups.master)
|
||||
od2 = OptionDescription('b', '', [od, c])
|
||||
b.impl_add_consistency('ip_netmask', c)
|
||||
raises(ConfigError, "Config(od2)")
|
||||
|
||||
|
||||
def test_consistency_not_equal_masterslave_error_othermaster():
|
||||
a = IPOption('a', '', multi=True)
|
||||
b = NetmaskOption('b', '', multi=True)
|
||||
c = IPOption('c', '', multi=True)
|
||||
d = NetmaskOption('d', '', multi=True)
|
||||
od = MasterSlaves('a', '', [a, b])
|
||||
#od.impl_set_group_type(groups.master)
|
||||
od2 = MasterSlaves('c', '', [c, d])
|
||||
#od2.impl_set_group_type(groups.master)
|
||||
od3 = OptionDescription('b', '', [od, od2])
|
||||
d.impl_add_consistency('ip_netmask', a)
|
||||
raises(ConfigError, "Config(od2)")
|
||||
|
||||
|
||||
def test_consistency_not_equal_masterslaves_default():
|
||||
a = IntOption('a', '', multi=True)
|
||||
b = IntOption('b', '', multi=True, default_multi=1)
|
||||
od = MasterSlaves('a', '', [a, b])
|
||||
od2 = OptionDescription('a', '', [od])
|
||||
#od.impl_set_group_type(groups.master)
|
||||
a.impl_add_consistency('not_equal', b)
|
||||
api = getapi(Config(od2))
|
||||
assert api.option('a.a').value.get() == []
|
||||
raises(ValueError, "api.option('a.a').value.set([1])")
|
||||
api.option('a.a').value.set([2])
|
||||
api.option('a.a').value.reset()
|
||||
|
||||
|
||||
def test_consistency_not_equal_multi():
|
||||
a = IntOption('a', '', multi=True)
|
||||
b = IntOption('b', '', multi=True)
|
||||
od = OptionDescription('a', '', [a, b])
|
||||
a.impl_add_consistency('not_equal', b)
|
||||
api = getapi(Config(od))
|
||||
assert api.option('a').value.get() == []
|
||||
assert api.option('b').value.get() == []
|
||||
api.option('a').value.set([1])
|
||||
api.option('a').value.reset()
|
||||
api.option('a').value.set([1])
|
||||
raises(ValueError, "api.option('b').value.set([1])")
|
||||
api.option('a').value.set([2])
|
||||
raises(ValueError, "api.option('b').value.set([2, 1])")
|
||||
api.option('a').value.set([2, 3])
|
||||
raises(ValueError, "api.option('a').value.set([2, 3, 3])")
|
||||
raises(ValueError, "api.option('b').value.set([2, 3])")
|
||||
|
||||
|
||||
def test_consistency_not_equal_multi_default():
|
||||
a = IntOption('a', '', multi=True, default=[1])
|
||||
b = IntOption('b', '', multi=True, default=[1, 2])
|
||||
od = OptionDescription('a', '', [a, b])
|
||||
raises(ValueError, "a.impl_add_consistency('not_equal', b)")
|
||||
|
||||
|
||||
def test_consistency_not_equal_multi_default_modif():
|
||||
a = IntOption('a', '', multi=True)
|
||||
b = IntOption('b', '', multi=True, default=[1, 2])
|
||||
od = OptionDescription('a', '', [a, b])
|
||||
a.impl_add_consistency('not_equal', b)
|
||||
api = getapi(Config(od))
|
||||
assert api.option('a').value.get() == []
|
||||
assert api.option('b').value.get() == [1, 2]
|
||||
raises(ValueError, "api.option('a').value.set([1])")
|
||||
raises(ValueError, "api.option('b').value.set([1, 2, 1])")
|
||||
|
||||
|
||||
def test_consistency_default():
|
||||
a = IntOption('a', '', 1)
|
||||
b = IntOption('b', '', 1)
|
||||
a, b
|
||||
raises(ValueError, "a.impl_add_consistency('not_equal', b)")
|
||||
|
||||
|
||||
def test_consistency_default_multi():
|
||||
a = IntOption('a', '', [2, 1], multi=True)
|
||||
b = IntOption('b', '', [1, 1], multi=True)
|
||||
c = IntOption('c', '', [1, 2], multi=True)
|
||||
b
|
||||
raises(ValueError, "a.impl_add_consistency('not_equal', b)")
|
||||
raises(ValueError, "a.impl_add_consistency('not_equal', c)")
|
||||
|
||||
|
||||
def test_consistency_default_diff():
|
||||
a = IntOption('a', '', 3)
|
||||
b = IntOption('b', '', 1)
|
||||
od = OptionDescription('od', '', [a, b])
|
||||
a.impl_add_consistency('not_equal', b)
|
||||
api = getapi(Config(od))
|
||||
raises(ValueError, "api.option('a').value.set(1)")
|
||||
api.option('a').value.set(2)
|
||||
api.option('b').value.set(3)
|
||||
owner = api.owner.get()
|
||||
assert api.option('a').owner.get() == owner
|
||||
raises(ValueError, "api.option('a').value.reset()")
|
||||
assert api.option('a').owner.get() == owner
|
||||
|
||||
|
||||
def test_consistency_ip_netmask():
|
||||
a = IPOption('a', '')
|
||||
b = NetmaskOption('b', '')
|
||||
od = OptionDescription('od', '', [a, b])
|
||||
b.impl_add_consistency('ip_netmask', a)
|
||||
api = getapi(Config(od))
|
||||
api.option('a').value.set('192.168.1.1')
|
||||
api.option('b').value.set('255.255.255.0')
|
||||
api.option('a').value.set('192.168.1.2')
|
||||
api.option('b').value.set('255.255.255.255')
|
||||
api.option('b').value.set('255.255.255.0')
|
||||
raises(ValueError, "api.option('a').value.set('192.168.1.0')")
|
||||
raises(ValueError, "api.option('a').value.set('192.168.1.255')")
|
||||
|
||||
|
||||
def test_consistency_network_netmask():
|
||||
a = NetworkOption('a', '')
|
||||
b = NetmaskOption('b', '')
|
||||
od = OptionDescription('od', '', [a, b])
|
||||
b.impl_add_consistency('network_netmask', a)
|
||||
api = getapi(Config(od))
|
||||
api.option('a').value.set('192.168.1.1')
|
||||
api.option('b').value.set('255.255.255.255')
|
||||
api.option('b').value.reset()
|
||||
api.option('a').value.set('192.168.1.0')
|
||||
api.option('b').value.set('255.255.255.0')
|
||||
raises(ValueError, "api.option('a').value.set('192.168.1.1')")
|
||||
|
||||
|
||||
def test_consistency_ip_in_network():
|
||||
a = NetworkOption('a', '')
|
||||
b = NetmaskOption('b', '')
|
||||
c = IPOption('c', '')
|
||||
d = IPOption('d', '')
|
||||
od = OptionDescription('od', '', [a, b, c, d])
|
||||
c.impl_add_consistency('in_network', a, b)
|
||||
d.impl_add_consistency('in_network', a, b, warnings_only=True)
|
||||
warnings.simplefilter("always", ValueWarning)
|
||||
api = getapi(Config(od))
|
||||
api.option('a').value.set('192.168.1.0')
|
||||
api.option('b').value.set('255.255.255.0')
|
||||
api.option('c').value.set('192.168.1.1')
|
||||
raises(ValueError, "api.option('c').value.set('192.168.2.1')")
|
||||
raises(ValueError, "api.option('c').value.set('192.168.1.0')")
|
||||
raises(ValueError, "api.option('c').value.set('192.168.1.255')")
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('d').value.set('192.168.2.1')
|
||||
assert len(w) == 1
|
||||
|
||||
|
||||
def test_consistency_ip_in_network_len_error():
|
||||
a = NetworkOption('a', '')
|
||||
b = NetmaskOption('b', '')
|
||||
c = IPOption('c', '')
|
||||
od = OptionDescription('od', '', [a, b, c])
|
||||
raises(ConfigError, "c.impl_add_consistency('in_network', a)")
|
||||
|
||||
|
||||
def test_consistency_ip_netmask_network_error():
|
||||
a = IPOption('a', '')
|
||||
b = NetworkOption('b', '')
|
||||
c = NetmaskOption('c', '')
|
||||
od = OptionDescription('od', '', [a, b, c])
|
||||
c.impl_add_consistency('ip_netmask', a, b)
|
||||
api = getapi(Config(od))
|
||||
api.option('a').value.set('192.168.1.1')
|
||||
api.option('b').value.set('192.168.1.0')
|
||||
raises(ConfigError, "api.option('c').value.set('255.255.255.0')")
|
||||
|
||||
|
||||
def test_consistency_ip_netmask_error_multi():
|
||||
a = IPOption('a', '', multi=True)
|
||||
b = NetmaskOption('b', '')
|
||||
OptionDescription('od', '', [a, b])
|
||||
raises(ConfigError, "b.impl_add_consistency('ip_netmask', a)")
|
||||
|
||||
|
||||
def test_consistency_ip_netmask_multi():
|
||||
a = IPOption('a', '', multi=True)
|
||||
b = NetmaskOption('b', '', multi=True)
|
||||
od = MasterSlaves('a', '', [a, b])
|
||||
b.impl_add_consistency('ip_netmask', a)
|
||||
od2 = OptionDescription('od2', '', [od])
|
||||
api = getapi(Config(od2))
|
||||
api.option('a.a').value.set(['192.168.1.1'])
|
||||
api.option('a.b', 0).value.set('255.255.255.0')
|
||||
api.option('a.a').value.set(['192.168.1.2'])
|
||||
api.option('a.b', 0).value.set('255.255.255.255')
|
||||
api.option('a.b', 0).value.set('255.255.255.0')
|
||||
raises(ValueError, "api.option('a.a').value.set(['192.168.1.0'])")
|
||||
|
||||
|
||||
def test_consistency_network_netmask_multi():
|
||||
a = NetworkOption('a', '', multi=True)
|
||||
b = NetmaskOption('b', '', multi=True)
|
||||
od = MasterSlaves('a', '', [a, b])
|
||||
b.impl_add_consistency('network_netmask', a)
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
api = getapi(Config(od2))
|
||||
api.option('a.a').value.set(['192.168.1.1'])
|
||||
api.option('a.b', 0).value.set('255.255.255.255')
|
||||
api.option('a.b', 0).value.reset()
|
||||
api.option('a.a').value.set(['192.168.1.0'])
|
||||
api.option('a.b', 0).value.set('255.255.255.0')
|
||||
raises(ValueError, "api.option('a.a').value.set(['192.168.1.1'])")
|
||||
|
||||
|
||||
def test_consistency_network_netmask_multi_slave_default_multi():
|
||||
a = NetworkOption('a', '', default_multi=u'192.168.1.0', multi=True, properties=('mandatory',))
|
||||
b = NetmaskOption('b', '', default_multi=u'255.255.255.0', multi=True, properties=('mandatory',))
|
||||
od = MasterSlaves('a', '', [a, b])
|
||||
od2 = OptionDescription('od2', '', [od])
|
||||
#od.impl_set_group_type(groups.master)
|
||||
b.impl_add_consistency('network_netmask', a)
|
||||
api = getapi(Config(od2))
|
||||
api.property.read_write()
|
||||
api.option('a.a').value.set([undefined])
|
||||
assert api.option('a.a').value.get() == ['192.168.1.0']
|
||||
assert api.option('a.b', 0).value.get() == '255.255.255.0'
|
||||
|
||||
|
||||
def test_consistency_network_netmask_multi_slave_default():
|
||||
a = NetworkOption('a', '', multi=True, properties=('mandatory',))
|
||||
b = NetmaskOption('b', '', default_multi=u'255.255.255.0', multi=True, properties=('mandatory',))
|
||||
od = MasterSlaves('a', '', [a, b])
|
||||
#od.impl_set_group_type(groups.master)
|
||||
b.impl_add_consistency('network_netmask', a)
|
||||
od2 = OptionDescription('od2', '', [od])
|
||||
api = getapi(Config(od2))
|
||||
api.property.read_write()
|
||||
api.property.pop('cache')
|
||||
assert api.option('a.a').value.get() == []
|
||||
api.option('a.a').value.set(['192.168.1.0'])
|
||||
api.property.read_only()
|
||||
assert api.option('a.a').value.get() == [u'192.168.1.0']
|
||||
assert api.option('a.b', 0).value.get() == u'255.255.255.0'
|
||||
api.property.read_write()
|
||||
raises(ValueError, "api.option('a.a').value.set([u'192.168.1.0', u'192.168.1.1'])")
|
||||
api.option('a.a').value.set(['192.168.1.0', undefined])
|
||||
api.option('a.b', 0).value.set('255.255.255.0')
|
||||
api.option('a.b', 1).value.set('255.255.255.255')
|
||||
api.option('a.a').value.set([u'192.168.1.0', u'192.168.1.1'])
|
||||
|
||||
|
||||
def return_netmask(*args, **kwargs):
|
||||
return u'255.255.255.0'
|
||||
|
||||
|
||||
def return_netmask2(master):
|
||||
if master is not None:
|
||||
if master.endswith('2.1'):
|
||||
return u'255.255.255.0'
|
||||
if not master.endswith('.0'):
|
||||
return u'255.255.255.255'
|
||||
return u'255.255.255.0'
|
||||
|
||||
|
||||
def test_consistency_network_netmask_multi_slave_callback():
|
||||
a = NetworkOption('a', '', multi=True, properties=('mandatory',))
|
||||
b = NetmaskOption('b', '', callback=return_netmask, multi=True, properties=('mandatory',))
|
||||
od = MasterSlaves('a', '', [a, b])
|
||||
#od.impl_set_group_type(groups.master)
|
||||
b.impl_add_consistency('network_netmask', a)
|
||||
od2 = OptionDescription('od2', '', [od])
|
||||
api = getapi(Config(od2))
|
||||
api.property.read_write()
|
||||
api.property.pop('cache')
|
||||
assert api.option('a.a').value.get() == []
|
||||
api.option('a.a').value.set(['192.168.1.0'])
|
||||
api.property.read_only()
|
||||
assert api.option('a.a').value.get() == [u'192.168.1.0']
|
||||
assert api.option('a.b', 0).value.get() == '255.255.255.0'
|
||||
api.property.read_write()
|
||||
raises(ValueError, "assert api.option('a.a').value.set([u'192.168.1.0', u'192.168.1.1'])")
|
||||
api.option('a.a').value.set(['192.168.1.0', undefined])
|
||||
api.option('a.b', 0).value.set('255.255.255.0')
|
||||
api.option('a.b', 1).value.set('255.255.255.255')
|
||||
api.option('a.a').value.set(['192.168.1.0', '192.168.1.1'])
|
||||
|
||||
|
||||
def test_consistency_network_netmask_multi_slave_callback_value():
|
||||
a = NetworkOption('a', '', multi=True, properties=('mandatory',))
|
||||
b = NetmaskOption('b', '', callback=return_netmask2, callback_params={'': ((a, False),)}, multi=True, properties=('mandatory',))
|
||||
od = MasterSlaves('a', '', [a, b])
|
||||
#od.impl_set_group_type(groups.master)
|
||||
b.impl_add_consistency('network_netmask', a)
|
||||
od2 = OptionDescription('od2', '', [od])
|
||||
api = getapi(Config(od2))
|
||||
api.property.read_write()
|
||||
api.property.pop('cache')
|
||||
assert api.option('a.a').value.get() == []
|
||||
api.option('a.a').value.set(['192.168.1.0'])
|
||||
assert api.option('a.a').value.get() == ['192.168.1.0']
|
||||
assert api.option('a.b', 0).value.get() == '255.255.255.0'
|
||||
raises(ValueError, "api.option('a.a').value.set(['192.168.1.0', '192.168.2.1'])")
|
||||
assert api.option('a.a').value.get() == [u'192.168.1.0']
|
||||
assert api.option('a.b', 0).value.get() == '255.255.255.0'
|
||||
raises(ValueError, "api.option('a.a').value.set(['192.168.2.1'])")
|
||||
assert api.option('a.a').value.get() == [u'192.168.1.0']
|
||||
assert api.option('a.b', 0).value.get() == '255.255.255.0'
|
||||
api.option('a.a').value.set(['192.168.1.0', '192.168.1.1'])
|
||||
api.option('a.b', 0).value.set('255.255.255.0')
|
||||
api.option('a.b', 1).value.set('255.255.255.255')
|
||||
|
||||
|
||||
def test_consistency_ip_netmask_multi_master():
|
||||
a = IPOption('a', '', multi=True)
|
||||
b = NetmaskOption('b', '', multi=True)
|
||||
od = MasterSlaves('a', '', [a, b])
|
||||
#od.impl_set_group_type(groups.master)
|
||||
b.impl_add_consistency('ip_netmask', a)
|
||||
od2 = OptionDescription('od2', '', [od])
|
||||
api = getapi(Config(od2))
|
||||
api.option('a.a').value.set(['192.168.1.1'])
|
||||
api.option('a.b', 0).value.set('255.255.255.0')
|
||||
api.option('a.a').value.set(['192.168.1.2'])
|
||||
api.option('a.b', 0).value.set('255.255.255.255')
|
||||
api.option('a.b', 0).value.set('255.255.255.0')
|
||||
raises(ValueError, "api.option('a.a').value.set(['192.168.1.0'])")
|
||||
api.option('a.a').value.set(['192.168.1.128'])
|
||||
raises(ValueError, "api.option('a.b', 0).value.set('255.255.255.128')")
|
||||
api.option('a.a').value.set(['192.168.1.2', '192.168.1.3'])
|
||||
|
||||
|
||||
def test_consistency_network_netmask_multi_master():
|
||||
a = NetworkOption('a', '', multi=True)
|
||||
b = NetmaskOption('b', '', multi=True)
|
||||
od = MasterSlaves('a', '', [a, b])
|
||||
#od.impl_set_group_type(groups.master)
|
||||
b.impl_add_consistency('network_netmask', a)
|
||||
od2 = OptionDescription('od2', '', [od])
|
||||
api = getapi(Config(od2))
|
||||
api.option('a.a').value.set(['192.168.1.1'])
|
||||
api.option('a.b', 0).value.set('255.255.255.255')
|
||||
api.option('a.b', 0).value.reset()
|
||||
api.option('a.a').value.set(['192.168.1.0'])
|
||||
api.option('a.b', 0).value.set('255.255.255.0')
|
||||
raises(ValueError, "api.option('a.a').value.set(['192.168.1.1'])")
|
||||
|
||||
|
||||
def test_consistency_broadcast():
|
||||
a = NetworkOption('a', '', multi=True)
|
||||
b = NetmaskOption('b', '', multi=True)
|
||||
c = BroadcastOption('c', '', multi=True)
|
||||
od = MasterSlaves('a', '', [a, b, c])
|
||||
#od.impl_set_group_type(groups.master)
|
||||
b.impl_add_consistency('network_netmask', a)
|
||||
c.impl_add_consistency('broadcast', a, b)
|
||||
od2 = OptionDescription('od2', '', [od])
|
||||
api = getapi(Config(od2))
|
||||
#first, test network_netmask
|
||||
api.option('a.a').value.set(['192.168.1.128'])
|
||||
raises(ValueError, "api.option('a.a').value.set(['255.255.255.0'])")
|
||||
#
|
||||
api.option('a.a').value.set(['192.168.1.0'])
|
||||
api.option('a.b', 0).value.set('255.255.255.0')
|
||||
api.option('a.c', 0).value.set('192.168.1.255')
|
||||
raises(ValueError, "api.option('a.a').value.set(['192.168.1.1'])")
|
||||
#
|
||||
api.option('a.a').value.set(['192.168.1.0', '192.168.2.128'])
|
||||
api.option('a.b', 0).value.set('255.255.255.0')
|
||||
api.option('a.b', 1).value.set('255.255.255.128')
|
||||
api.option('a.c', 0).value.set('192.168.1.255')
|
||||
api.option('a.c', 1).value.set('192.168.2.255')
|
||||
raises(ValueError, "api.option('a.c', 1).value.set('192.168.2.128')")
|
||||
api.option('a.c', 1).value.set('192.168.2.255')
|
||||
|
||||
|
||||
def test_consistency_broadcast_error():
|
||||
a = NetworkOption('a', '', multi=True)
|
||||
b = NetmaskOption('b', '', multi=True)
|
||||
c = BroadcastOption('c', '', multi=True)
|
||||
od = MasterSlaves('a', '', [a, b, c])
|
||||
od2 = OptionDescription('od2', '', [od])
|
||||
b.impl_add_consistency('network_netmask', a)
|
||||
c.impl_add_consistency('broadcast', a)
|
||||
api = getapi(Config(od2))
|
||||
raises(ConfigError, "api.option('a.a').value.set(['192.168.1.0'])")
|
||||
|
||||
|
||||
def test_consistency_broadcast_warnings():
|
||||
warnings.simplefilter("always", ValueWarning)
|
||||
a = NetworkOption('a', '', properties=('mandatory', 'disabled'))
|
||||
b = NetmaskOption('b', '', properties=('mandatory', 'disabled'))
|
||||
c = NetmaskOption('c', '', properties=('mandatory', 'disabled'))
|
||||
od = OptionDescription('a', '', [a, b, c])
|
||||
b.impl_add_consistency('network_netmask', a, warnings_only=True)
|
||||
api = getapi(Config(od))
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('a').value.set('192.168.1.4')
|
||||
api.option('b').value.set('255.255.255.0')
|
||||
assert len(w) == 1
|
||||
api.property.read_write()
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
list(api.value.mandatory_warnings())
|
||||
assert len(w) == 0
|
||||
|
||||
|
||||
def test_consistency_broadcast_default_1():
|
||||
a = NetworkOption('a', '', '192.168.1.0')
|
||||
b = NetmaskOption('b', '', '255.255.255.128')
|
||||
c = BroadcastOption('c', '', '192.168.2.127')
|
||||
od = OptionDescription('a', '', [a, b, c])
|
||||
od
|
||||
raises(ValueError, "c.impl_add_consistency('broadcast', a, b)")
|
||||
|
||||
|
||||
def test_consistency_broadcast_default_2():
|
||||
a = NetworkOption('a', '', '192.168.1.0')
|
||||
b = NetmaskOption('b', '', '255.255.255.128')
|
||||
d = BroadcastOption('d', '', '192.168.1.127')
|
||||
od2 = OptionDescription('a', '', [a, b, d])
|
||||
od2
|
||||
d.impl_add_consistency('broadcast', a, b)
|
||||
|
||||
|
||||
def test_consistency_not_all():
|
||||
#_cache_consistencies is not None by not options has consistencies
|
||||
a = NetworkOption('a', '', multi=True)
|
||||
b = NetmaskOption('b', '', multi=True)
|
||||
c = BroadcastOption('c', '', multi=True)
|
||||
od = MasterSlaves('a', '', [a, b, c])
|
||||
#od.impl_set_group_type(groups.master)
|
||||
b.impl_add_consistency('network_netmask', a)
|
||||
od2 = OptionDescription('od2', '', [od])
|
||||
api = getapi(Config(od2))
|
||||
api.option('a.a').value.set(['192.168.1.0'])
|
||||
api.option('a.b', 0).value.set('255.255.255.0')
|
||||
api.option('a.c', 0).value.set('192.168.1.255')
|
||||
|
||||
|
||||
def test_consistency_permissive():
|
||||
a = IntOption('a', '', 1)
|
||||
b = IntOption('b', '', 2, properties=('hidden',))
|
||||
od = OptionDescription('od', '', [a, b])
|
||||
a.impl_add_consistency('not_equal', b)
|
||||
api = getapi(Config(od))
|
||||
api.property.read_write()
|
||||
api.permissive.set(frozenset(['hidden']))
|
||||
api.option('a').value.set(1)
|
||||
|
||||
|
||||
def test_consistency_disabled():
|
||||
a = IntOption('a', '')
|
||||
b = IntOption('b', '', properties=('disabled',))
|
||||
od = OptionDescription('od', '', [a, b])
|
||||
a.impl_add_consistency('not_equal', b)
|
||||
api = getapi(Config(od))
|
||||
api.property.read_write()
|
||||
raises(PropertiesOptionError, "api.option('a').value.set(1)")
|
||||
|
||||
|
||||
def test_consistency_disabled_transitive():
|
||||
a = IntOption('a', '')
|
||||
b = IntOption('b', '', properties=('disabled',))
|
||||
od = OptionDescription('od', '', [a, b])
|
||||
a.impl_add_consistency('not_equal', b, transitive=False)
|
||||
api = getapi(Config(od))
|
||||
api.property.read_write()
|
||||
api.option('a').value.set(1)
|
||||
|
||||
|
||||
def test_consistency_disabled_transitive_2():
|
||||
a = IPOption('a', '')
|
||||
b = IPOption('b', '')
|
||||
c = NetworkOption('c', '', default='192.168.1.0')
|
||||
d = NetmaskOption('d', '', default='255.255.255.0', properties=('disabled',))
|
||||
od = OptionDescription('od', '', [a, b, c, d])
|
||||
a.impl_add_consistency('not_equal', b)
|
||||
a.impl_add_consistency('in_network', c, d, transitive=False)
|
||||
api = getapi(Config(od))
|
||||
api.property.read_write()
|
||||
api.option('a').value.set('192.168.1.1')
|
||||
raises(ValueError, "api.option('b').value.set('192.168.1.1')")
|
||||
api.option('a').value.set('192.168.2.1')
|
||||
#
|
||||
api.option('a').value.set('192.168.1.1')
|
||||
api.property.pop('disabled')
|
||||
raises(ValueError, "api.option('a').value.set('192.168.2.1')")
|
||||
|
||||
|
||||
def return_val(*args, **kwargs):
|
||||
return '192.168.1.1'
|
||||
|
||||
|
||||
def test_consistency_with_callback():
|
||||
a = NetworkOption('a', '', default='192.168.1.0')
|
||||
b = NetmaskOption('b', '', default='255.255.255.0')
|
||||
c = IPOption('c', '', callback=return_val, callback_params={'': ((a, False),)})
|
||||
od = OptionDescription('od', '', [a, b, c])
|
||||
c.impl_add_consistency('in_network', a, b)
|
||||
api = getapi(Config(od))
|
||||
api.option('c').value.get()
|
||||
|
||||
|
||||
def test_consistency_double_warnings():
|
||||
a = IntOption('a', '')
|
||||
b = IntOption('b', '', 1)
|
||||
c = IntOption('c', '', 1)
|
||||
od = OptionDescription('od', '', [a, b, c])
|
||||
warnings.simplefilter("always", ValueWarning)
|
||||
a.impl_add_consistency('not_equal', b, warnings_only=True)
|
||||
a.impl_add_consistency('not_equal', c, warnings_only=True)
|
||||
od2 = OptionDescription('od2', '', [od])
|
||||
api = getapi(Config(od2))
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('od.a').value.set(1)
|
||||
assert w != []
|
||||
assert len(w) == 2
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('od.c').value.set(2)
|
||||
assert len(w) == 1
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('od.a').value.set(2)
|
||||
assert w != []
|
||||
assert len(w) == 1
|
||||
api.property.pop('warnings')
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('od.a').value.set(1)
|
||||
assert w == []
|
||||
|
||||
|
||||
def test_consistency_warnings_error():
|
||||
a = IntOption('a', '')
|
||||
b = IntOption('b', '', 1)
|
||||
c = IntOption('c', '', 1)
|
||||
od = OptionDescription('od', '', [a, b, c])
|
||||
warnings.simplefilter("always", ValueWarning)
|
||||
a.impl_add_consistency('not_equal', b, warnings_only=True)
|
||||
a.impl_add_consistency('not_equal', c)
|
||||
api = getapi(Config(od))
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
raises(ValueError, "api.option('a').value.set(1)")
|
||||
assert w == []
|
||||
|
||||
|
||||
def test_consistency_network_netmask_mandatory():
|
||||
a = NetworkOption('a', '', multi=True, properties=('mandatory',), default=[u'0.0.0.0'])
|
||||
b = NetmaskOption('b', '', multi=True, properties=('mandatory',), default_multi=u'0.0.0.0')
|
||||
od = MasterSlaves('a', '', [a, b])
|
||||
b.impl_add_consistency('network_netmask', a)
|
||||
od2 = OptionDescription('od2', '', [od])
|
||||
api = getapi(Config(od2))
|
||||
api.property.read_only()
|
||||
api.property.pop('mandatory')
|
||||
api.option.make_dict()
|
||||
|
||||
|
||||
def test_consistency_has_dependency():
|
||||
a = IPOption('a', '')
|
||||
b = NetmaskOption('b', '')
|
||||
od = OptionDescription('od', '', [a, b])
|
||||
b.impl_add_consistency('ip_netmask', a)
|
||||
api = getapi(Config(od))
|
||||
assert api.option('a').option.has_dependency() is True
|
||||
assert api.option('b').option.has_dependency() is True
|
||||
assert api.option('a').option.has_dependency(False) is True
|
||||
assert api.option('b').option.has_dependency(False) is True
|
||||
|
||||
|
||||
def test_consistency_not_equal_has_dependency():
|
||||
a = IntOption('a', '')
|
||||
b = IntOption('b', '')
|
||||
od = OptionDescription('od', '', [a, b])
|
||||
a.impl_add_consistency('not_equal', b)
|
||||
api = getapi(Config(od))
|
||||
assert api.option('a').option.has_dependency() is False
|
||||
assert api.option('b').option.has_dependency() is False
|
||||
assert api.option('a').option.has_dependency(False) is True
|
||||
assert api.option('b').option.has_dependency(False) is True
|
||||
|
|
@ -1,185 +0,0 @@
|
|||
"test all types of option default values for options, add new option in a descr"
|
||||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
|
||||
from py.test import raises
|
||||
|
||||
from tiramisu.setting import owners
|
||||
from tiramisu.error import PropertiesOptionError, ConfigError
|
||||
from tiramisu import IntOption, FloatOption, StrOption, ChoiceOption, \
|
||||
BoolOption, OptionDescription, MasterSlaves, Config, getapi, undefined
|
||||
|
||||
|
||||
def make_description():
|
||||
gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||
['std', 'thunk'], 'std')
|
||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
|
||||
wantref_option = BoolOption('wantref', 'Test requires', default=False,
|
||||
requires=['boolop'])
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False,
|
||||
requires=['boolop'])
|
||||
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
||||
descr = OptionDescription('tiramisu', '', [gcgroup, booloption, objspaceoption,
|
||||
wantref_option, stroption,
|
||||
wantframework_option,
|
||||
intoption, boolop])
|
||||
return descr
|
||||
|
||||
|
||||
#____________________________________________________________
|
||||
# default values
|
||||
def test_default_is_none():
|
||||
"""
|
||||
Most constructors take a ``default`` argument that specifies the default
|
||||
value of the option. If this argument is not supplied the default value is
|
||||
assumed to be ``None``.
|
||||
"""
|
||||
dummy1 = BoolOption('dummy1', 'doc dummy')
|
||||
dummy2 = BoolOption('dummy2', 'doc dummy')
|
||||
group = OptionDescription('group', '', [dummy1, dummy2])
|
||||
api = getapi(Config(group))
|
||||
# so when the default value is not set, there is actually a default value
|
||||
assert api.option('dummy1').value.get() is None
|
||||
assert api.option('dummy2').value.get() is None
|
||||
|
||||
|
||||
def test_set_defaut_value_from_option_object():
|
||||
"""Options have an available default setting and can give it back"""
|
||||
b = BoolOption("boolean", "", default=False)
|
||||
assert b.impl_getdefault() is False
|
||||
|
||||
|
||||
def test_force_default_on_freeze():
|
||||
"a frozen option wich is forced returns his default"
|
||||
dummy1 = BoolOption('dummy1', 'doc dummy', default=False, properties=('force_default_on_freeze',))
|
||||
dummy2 = BoolOption('dummy2', 'doc dummy', default=True)
|
||||
group = OptionDescription('group', '', [dummy1, dummy2])
|
||||
api = getapi(Config(group))
|
||||
api.property.read_write()
|
||||
owner = api.owner.get()
|
||||
api.option('dummy1').value.set(True)
|
||||
api.option('dummy2').value.set(False)
|
||||
assert api.option('dummy1').owner.get() == owner
|
||||
assert api.option('dummy2').owner.get() == owner
|
||||
api.option('dummy1').property.add('frozen')
|
||||
api.option('dummy2').property.add('frozen')
|
||||
assert api.option('dummy1').value.get() is False
|
||||
assert api.option('dummy2').value.get() is False
|
||||
assert api.option('dummy1').owner.isdefault()
|
||||
assert api.option('dummy2').owner.get() == owner
|
||||
raises(PropertiesOptionError, "api.option('dummy2').owner.set('frozen')")
|
||||
raises(PropertiesOptionError, "api.option('dummy1').value.reset()")
|
||||
api.option('dummy1').property.pop('frozen')
|
||||
api.option('dummy1').value.reset()
|
||||
api.option('dummy1').property.add('frozen')
|
||||
raises(PropertiesOptionError, "api.option('dummy2').owner.set('frozen')")
|
||||
|
||||
|
||||
def test_force_default_on_freeze_multi():
|
||||
dummy1 = BoolOption('dummy1', 'doc dummy', default=[False], properties=('force_default_on_freeze',), multi=True)
|
||||
dummy2 = BoolOption('dummy2', 'doc dummy', default=[True], multi=True)
|
||||
group = OptionDescription('group', '', [dummy1, dummy2])
|
||||
api = getapi(Config(group))
|
||||
api.property.read_write()
|
||||
api.option('dummy1').value.set([undefined, True])
|
||||
api.option('dummy2').value.set([undefined, False])
|
||||
owner = api.owner.get()
|
||||
assert api.option('dummy1').owner.get() == owner
|
||||
assert api.option('dummy2').owner.get() == owner
|
||||
api.option('dummy1').property.add('frozen')
|
||||
api.option('dummy2').property.add('frozen')
|
||||
assert api.option('dummy1').value.get() == [False]
|
||||
assert api.option('dummy2').value.get() == [True, False]
|
||||
assert api.option('dummy1').owner.isdefault()
|
||||
assert api.option('dummy2').owner.get() == owner
|
||||
raises(PropertiesOptionError, "api.option('dummy2').owner.set('owner')")
|
||||
raises(PropertiesOptionError, "api.option('dummy2').value.reset()")
|
||||
api.option('dummy1').property.pop('frozen')
|
||||
api.option('dummy1').value.reset()
|
||||
api.option('dummy1').property.add('frozen')
|
||||
|
||||
|
||||
def test_force_default_on_freeze_master():
|
||||
dummy1 = BoolOption('dummy1', 'Test int option', multi=True, properties=('force_default_on_freeze',))
|
||||
dummy2 = BoolOption('dummy2', 'Test string option', multi=True)
|
||||
descr = MasterSlaves("dummy1", "", [dummy1, dummy2])
|
||||
descr = OptionDescription("root", "", [descr])
|
||||
raises(ConfigError, "Config(descr)")
|
||||
|
||||
|
||||
def test_force_default_on_freeze_slave():
|
||||
dummy1 = BoolOption('dummy1', 'Test int option', multi=True)
|
||||
dummy2 = BoolOption('dummy2', 'Test string option', multi=True, properties=('force_default_on_freeze',))
|
||||
descr = MasterSlaves("dummy1", "", [dummy1, dummy2])
|
||||
descr = OptionDescription("root", "", [descr])
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
owners.addowner("frozenmultislave")
|
||||
api.option('dummy1.dummy1').value.set([True])
|
||||
api.option('dummy1.dummy2', 0).value.set(False)
|
||||
assert api.option('dummy1.dummy1').value.get() == [True]
|
||||
assert api.option('dummy1.dummy2', 0).value.get() == False
|
||||
assert api.option('dummy1.dummy1').owner.get() == 'user'
|
||||
assert api.option('dummy1.dummy2', 0).owner.get() == 'user'
|
||||
#
|
||||
api.option('dummy1.dummy2').property.add('frozen')
|
||||
assert api.option('dummy1.dummy1').value.get() == [True]
|
||||
assert api.option('dummy1.dummy2', 0).value.get() == None
|
||||
assert api.option('dummy1.dummy1').owner.get() == 'user'
|
||||
assert api.option('dummy1.dummy2', 0).owner.isdefault()
|
||||
raises(PropertiesOptionError, "api.option('dummy1.dummy2', 0).owner.set('frozenmultislave')")
|
||||
#
|
||||
api.option('dummy1.dummy2').property.pop('frozen')
|
||||
api.option('dummy1.dummy1').value.set([True, True])
|
||||
api.option('dummy1.dummy2', 1).value.set(False)
|
||||
assert api.option('dummy1.dummy1').value.get() == [True, True]
|
||||
assert api.option('dummy1.dummy2', 0).value.get() == False
|
||||
assert api.option('dummy1.dummy2', 1).value.get() == False
|
||||
#
|
||||
api.option('dummy1.dummy2').property.add('frozen')
|
||||
assert api.option('dummy1.dummy1').value.get() == [True, True]
|
||||
assert api.option('dummy1.dummy2', 0).value.get() == None
|
||||
assert api.option('dummy1.dummy2', 1).value.get() == None
|
||||
#
|
||||
api.option('dummy1.dummy1').value.pop(1)
|
||||
assert api.option('dummy1.dummy1').value.get() == [True]
|
||||
assert api.option('dummy1.dummy2', 0).value.get() == None
|
||||
#
|
||||
api.option('dummy1.dummy2').property.pop('frozen')
|
||||
assert api.option('dummy1.dummy1').value.get() == [True]
|
||||
assert api.option('dummy1.dummy2', 0).value.get() == False
|
||||
#
|
||||
api.option('dummy1.dummy1').value.set([True, True])
|
||||
assert api.option('dummy1.dummy2', 0).value.get() == False
|
||||
assert api.option('dummy1.dummy2', 1).value.get() == None
|
||||
|
||||
|
||||
def test_overrides_changes_option_value():
|
||||
"with config.override(), the default is changed and the value is changed"
|
||||
descr = OptionDescription("test", "", [
|
||||
BoolOption("b", "", default=False)])
|
||||
api = getapi(Config(descr))
|
||||
api.option('b').value.set(True)
|
||||
|
||||
|
||||
def test_choice_with_no_default():
|
||||
descr = OptionDescription("test", "", [
|
||||
ChoiceOption("backend", "", ("c", "cli"))])
|
||||
api = getapi(Config(descr))
|
||||
assert api.option('backend').value.get() is None
|
||||
api.option('backend').value.set('c')
|
||||
|
||||
|
||||
def test_choice_with_default():
|
||||
descr = OptionDescription("test", "", [
|
||||
ChoiceOption("backend", "", ("c", "cli"), default="cli")])
|
||||
api = getapi(Config(descr))
|
||||
assert api.option('backend').value.get() == 'cli'
|
||||
|
|
@ -1,168 +0,0 @@
|
|||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
|
||||
from py.test import raises
|
||||
|
||||
from tiramisu.setting import owners, groups
|
||||
from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \
|
||||
StrOption, OptionDescription, SymLinkOption, MasterSlaves, Config, getapi
|
||||
from tiramisu.error import ConfigError, ConstError, PropertiesOptionError, APIError
|
||||
|
||||
|
||||
def make_description():
|
||||
gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||
['std', 'thunk'], 'std')
|
||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
|
||||
wantref_option = BoolOption('wantref', 'Test requires', default=False)
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False)
|
||||
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
||||
descr = OptionDescription('tiram', '', [gcgroup, booloption, objspaceoption,
|
||||
wantref_option, stroption,
|
||||
wantframework_option,
|
||||
intoption, boolop])
|
||||
return descr
|
||||
|
||||
|
||||
def test_default_owner():
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
descr = OptionDescription('tiramisu', '', [gcdummy])
|
||||
api = getapi(Config(descr))
|
||||
assert api.option('dummy').value.get() is False
|
||||
assert api.option('dummy').owner.get() == 'default'
|
||||
api.option('dummy').value.set(True)
|
||||
owner = api.owner.get()
|
||||
assert api.option('dummy').owner.get() == owner
|
||||
|
||||
|
||||
def test_hidden_owner():
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False, properties=('hidden',))
|
||||
descr = OptionDescription('tiramisu', '', [gcdummy])
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
#raises(PropertiesOptionError, "api.forcepermissive.option('dummy').owner.get()")
|
||||
#raises(PropertiesOptionError, "api.option('dummy').owner.isdefault()")
|
||||
#raises(PropertiesOptionError, "api.forcepermissive.option('dummy').owner.isdefault()")
|
||||
api.permissive.set(frozenset(['hidden']))
|
||||
api.forcepermissive.option('dummy').value.get()
|
||||
api.forcepermissive.option('dummy').owner.isdefault()
|
||||
|
||||
|
||||
def test_addowner():
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
descr = OptionDescription('tiramisu', '', [gcdummy])
|
||||
api = getapi(Config(descr))
|
||||
assert api.option('dummy').value.get() is False
|
||||
assert api.option('dummy').owner.get() == 'default'
|
||||
assert api.option('dummy').owner.isdefault()
|
||||
api.owner.set('gen_config')
|
||||
api.option('dummy').value.set(True)
|
||||
assert api.option('dummy').owner.get() == owners.gen_config
|
||||
assert not api.option('dummy').owner.isdefault()
|
||||
|
||||
|
||||
def test_addowner_multiple_time():
|
||||
owners.addowner("testowner")
|
||||
raises(ConstError, 'owners.addowner("testowner")')
|
||||
|
||||
|
||||
def test_delete_owner():
|
||||
owners.addowner('deleted')
|
||||
raises(ConstError, 'del(owners.deleted)')
|
||||
|
||||
|
||||
def test_owner_is_not_a_string():
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
descr = OptionDescription('tiramisu', '', [gcdummy])
|
||||
api = getapi(Config(descr))
|
||||
assert api.option('dummy').value.get() is False
|
||||
assert api.option('dummy').owner.get() == owners.default
|
||||
assert api.option('dummy').owner.get() == 'default'
|
||||
assert isinstance(api.option('dummy').owner.get(), owners.Owner)
|
||||
api.option('dummy').value.set(True)
|
||||
assert api.option('dummy').owner.get() == 'user'
|
||||
|
||||
|
||||
def test_setowner_without_valid_owner():
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
descr = OptionDescription('tiramisu', '', [gcdummy])
|
||||
api = getapi(Config(descr))
|
||||
assert api.option('dummy').value.get() is False
|
||||
assert api.option('dummy').owner.get() == 'default'
|
||||
|
||||
|
||||
def test_setowner_for_value():
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
descr = OptionDescription('tiramisu', '', [gcdummy])
|
||||
api = getapi(Config(descr))
|
||||
assert api.option('dummy').value.get() is False
|
||||
assert api.option('dummy').owner.get() == 'default'
|
||||
owners.addowner("new")
|
||||
raises(ConfigError, "api.option('dummy').owner.set('new')")
|
||||
api.option('dummy').value.set(False)
|
||||
assert api.option('dummy').owner.get() == owners.user
|
||||
api.option('dummy').owner.set('new')
|
||||
assert api.option('dummy').owner.get() == owners.new
|
||||
|
||||
|
||||
def test_setowner_read_only():
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
descr = OptionDescription('tiramisu', '', [gcdummy])
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
assert api.option('dummy').value.get() is False
|
||||
assert api.option('dummy').owner.get() == 'default'
|
||||
owners.addowner("readonly")
|
||||
api.option('dummy').value.set(False)
|
||||
assert api.option('dummy').owner.get() == owners.user
|
||||
api.property.read_only()
|
||||
raises(PropertiesOptionError,
|
||||
"api.option('dummy').owner.set('readonly')")
|
||||
assert api.option('dummy').owner.get() == owners.user
|
||||
|
||||
|
||||
def test_setowner_optiondescription():
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
descr1 = OptionDescription('tiramisu', '', [gcdummy])
|
||||
descr = OptionDescription('tiramisu', '', [descr1])
|
||||
api = getapi(Config(descr))
|
||||
raises(APIError, "api.option('tiramisu').owner.get()")
|
||||
raises(APIError, "api.option('tiramisu').owner.set('user')")
|
||||
|
||||
|
||||
def test_setowner_symlinkoption():
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
s = SymLinkOption('symdummy', gcdummy)
|
||||
descr1 = OptionDescription('tiramisu', '', [gcdummy, s])
|
||||
descr = OptionDescription('tiramisu', '', [descr1])
|
||||
api = getapi(Config(descr))
|
||||
assert api.option('tiramisu.symdummy').owner.isdefault()
|
||||
api.option('tiramisu.dummy').value.set(True)
|
||||
assert not api.option('tiramisu.symdummy').owner.isdefault()
|
||||
raises(ConfigError, "api.option('tiramisu.symdummy').owner.set('user')")
|
||||
|
||||
|
||||
def test_owner_masterslaves():
|
||||
b = IntOption('int', 'Test int option', default=[0], multi=True)
|
||||
c = StrOption('str', 'Test string option', multi=True)
|
||||
descr = MasterSlaves("int", "", [b, c])
|
||||
od = OptionDescription('od', '', [descr])
|
||||
api = getapi(Config(od))
|
||||
raises(ConfigError, "api.option('int.str', 0).owner.set('user')")
|
||||
|
||||
api.option('int.int').value.set([0, 1])
|
||||
api.option('int.str', 0).value.set('yes')
|
||||
assert not api.option('int.str', 0).owner.isdefault()
|
||||
assert api.option('int.str', 1).owner.isdefault()
|
||||
api.option('int.str', 0).owner.set('user')
|
||||
assert api.option('int.str', 0).owner.get() == owners.user
|
||||
assert api.option('int.str', 1).owner.isdefault()
|
||||
assert api.option('int.str', 0).value.get() == 'yes'
|
||||
assert api.option('int.str', 1).value.get() == None
|
||||
|
|
@ -1,553 +0,0 @@
|
|||
"config.set() or config.setoption() or option.setoption()"
|
||||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
|
||||
from py.test import raises
|
||||
|
||||
from tiramisu.i18n import _
|
||||
from tiramisu.error import display_list, ConfigError
|
||||
from tiramisu.setting import owners, groups
|
||||
from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \
|
||||
StrOption, OptionDescription, MasterSlaves, Config, getapi, undefined
|
||||
from tiramisu.error import PropertiesOptionError
|
||||
|
||||
|
||||
def make_description():
|
||||
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||
('std', 'thunk'), 'std')
|
||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
|
||||
wantref_option = BoolOption('wantref', 'Test requires', default=False)
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False)
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
||||
descr = OptionDescription('tiramisu', '', [gcgroup, booloption, objspaceoption,
|
||||
wantref_option, stroption,
|
||||
wantframework_option,
|
||||
intoption, boolop])
|
||||
return descr
|
||||
|
||||
|
||||
#____________________________________________________________
|
||||
# change with __setattr__
|
||||
def test_attribute_access():
|
||||
"Once set, option values can't be changed again by attribute access"
|
||||
s = StrOption("string", "", default="string")
|
||||
descr = OptionDescription("options", "", [s])
|
||||
api = getapi(Config(descr))
|
||||
# let's try to change it again
|
||||
api.option('string').value.set('foo')
|
||||
assert api.option('string').value.get() == 'foo'
|
||||
|
||||
|
||||
def test_setitem():
|
||||
s = StrOption("string", "", default=["string", "sdfsdf"], default_multi="prout", multi=True)
|
||||
descr = OptionDescription("options", "", [s])
|
||||
api = getapi(Config(descr))
|
||||
api.option('string').value.set([undefined, 'foo'])
|
||||
assert api.option('string').value.get() == ['string', 'foo']
|
||||
|
||||
|
||||
def test_reset():
|
||||
"if value is None, resets to default owner"
|
||||
s = StrOption("string", "", default="string")
|
||||
descr = OptionDescription("options", "", [s])
|
||||
api = getapi(Config(descr))
|
||||
api.option('string').value.set('foo')
|
||||
assert api.option('string').value.get() == "foo"
|
||||
assert api.option('string').owner.get() ==owners.user
|
||||
api.option('string').value.reset()
|
||||
assert api.option('string').value.get() == 'string'
|
||||
assert api.option('string').owner.get() ==owners.default
|
||||
|
||||
|
||||
def test_reset_with_multi():
|
||||
s = StrOption("string", "", default=["string"], default_multi="string", multi=True)
|
||||
descr = OptionDescription("options", "", [s])
|
||||
api = getapi(Config(descr))
|
||||
# api.option('string').value.set([])
|
||||
api.option('string').value.reset()
|
||||
assert api.option('string').value.get() == ["string"]
|
||||
assert api.option('string').owner.get() =='default'
|
||||
api.option('string').value.set(["eggs", "spam", "foo"])
|
||||
assert api.option('string').owner.get() =='user'
|
||||
api.option('string').value.set([])
|
||||
api.option('string').value.reset()
|
||||
# assert api.option('string').value.get() == ["string"]
|
||||
assert api.option('string').owner.get() =='default'
|
||||
raises(ValueError, "api.option('string').value.set(None)")
|
||||
|
||||
|
||||
def test_default_with_multi():
|
||||
"default with multi is a list"
|
||||
s = StrOption("string", "", default=[], default_multi="string", multi=True)
|
||||
descr = OptionDescription("options", "", [s])
|
||||
api = getapi(Config(descr))
|
||||
assert api.option('string').value.get() == []
|
||||
s = StrOption("string", "", default=None, default_multi="string", multi=True)
|
||||
descr = OptionDescription("options", "", [s])
|
||||
api = getapi(Config(descr))
|
||||
assert api.option('string').value.get() == []
|
||||
|
||||
|
||||
def test_idontexist():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.option.make_dict()
|
||||
raises(AttributeError, "api.option('idontexist').value.get()")
|
||||
|
||||
|
||||
# ____________________________________________________________
|
||||
def test_attribute_access_with_multi():
|
||||
s = StrOption("string", "", default=["string"], default_multi="string", multi=True)
|
||||
descr = OptionDescription("options", "", [s])
|
||||
api = getapi(Config(descr))
|
||||
api.option('string').value.set(["foo", "bar"])
|
||||
assert api.option('string').value.get() == ["foo", "bar"]
|
||||
|
||||
|
||||
def test_item_access_with_multi():
|
||||
s = StrOption("string", "", default=["string"], multi=True)
|
||||
descr = OptionDescription("options", "", [s])
|
||||
api = getapi(Config(descr))
|
||||
api.option('string').value.set(["foo", "bar"])
|
||||
assert api.option('string').value.get() == ["foo", "bar"]
|
||||
api.option('string').value.set(["changetest", "bar"])
|
||||
assert api.option('string').value.get() == ["changetest", "bar"]
|
||||
|
||||
|
||||
def test_access_with_multi_default():
|
||||
s = StrOption("string", "", default=["string"], multi=True)
|
||||
descr = OptionDescription("options", "", [s])
|
||||
api = getapi(Config(descr))
|
||||
assert api.option('string').owner.get() =='default'
|
||||
api.option('string').value.set(["foo", "bar"])
|
||||
assert api.option('string').value.get() == ["foo", "bar"]
|
||||
assert api.option('string').owner.get() =='user'
|
||||
|
||||
|
||||
def test_multi_with_requires():
|
||||
s = StrOption("string", "", default=["string"], default_multi="string", multi=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
stroption = StrOption('str', 'Test string option', default=["abc"], default_multi="abc",
|
||||
requires=[{'option': intoption, 'expected': 1, 'action': 'hidden'}], multi=True)
|
||||
descr = OptionDescription("options", "", [s, intoption, stroption])
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
assert not 'hidden' in api.option('str').property.get()
|
||||
api.option('int').value.set(1)
|
||||
raises(PropertiesOptionError, "api.option('str').value.set(['a', 'b'])")
|
||||
assert 'hidden' in api.option('str').property.get()
|
||||
|
||||
|
||||
def test__requires_with_inverted():
|
||||
s = StrOption("string", "", default=["string"], multi=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
stroption = StrOption('str', 'Test string option', default=["abc"], default_multi="abc",
|
||||
requires=[{'option': intoption, 'expected': 1, 'action': 'hide', 'inverse': True}], multi=True)
|
||||
descr = OptionDescription("options", "", [s, intoption, stroption])
|
||||
api = getapi(Config(descr))
|
||||
assert not 'hidden' in api.option('str').property.get()
|
||||
api.option('int').value.set(1)
|
||||
assert not 'hidden' in api.option('str').property.get()
|
||||
|
||||
|
||||
def test_multi_with_requires_in_another_group():
|
||||
s = StrOption("string", "", default=["string"], multi=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
stroption = StrOption('str', 'Test string option', default=["abc"],
|
||||
requires=[{'option': intoption, 'expected': 1, 'action': 'hidden'}], multi=True)
|
||||
descr = OptionDescription("opt", "", [stroption])
|
||||
descr2 = OptionDescription("opt2", "", [intoption, s, descr])
|
||||
api = getapi(Config(descr2))
|
||||
api.property.read_write()
|
||||
assert not 'hidden' in api.option('opt.str').property.get()
|
||||
api.option('int').value.set(1)
|
||||
raises(PropertiesOptionError, "api.option('opt.str').value.set(['a', 'b'])")
|
||||
assert 'hidden' in api.option('opt.str').property.get()
|
||||
|
||||
|
||||
def test_multi_with_requires_in_another_group_inverse():
|
||||
s = StrOption("string", "", default=["string"], multi=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
stroption = StrOption('str', 'Test string option', default=["abc"],
|
||||
requires=[{'option': intoption, 'expected': 0, 'action': 'hidden', 'inverse': True}], multi=True)
|
||||
descr = OptionDescription("opt", "", [stroption])
|
||||
descr2 = OptionDescription("opt2", "", [intoption, s, descr])
|
||||
api = getapi(Config(descr2))
|
||||
api.property.read_write()
|
||||
assert not 'hidden' in api.option('opt.str').property.get()
|
||||
api.option('int').value.set(1)
|
||||
raises(PropertiesOptionError, "api.option('opt.str').value.set(['a', 'b'])")
|
||||
assert 'hidden' in api.option('opt.str').property.get()
|
||||
|
||||
|
||||
def test_apply_requires_from_config():
|
||||
s = StrOption("string", "", default=["string"], multi=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
stroption = StrOption('str', 'Test string option', default=["abc"],
|
||||
requires=[{'option': intoption, 'expected': 1, 'action': 'hidden'}], multi=True)
|
||||
descr = OptionDescription("opt", "", [stroption])
|
||||
descr2 = OptionDescription("opt2", "", [intoption, s, descr])
|
||||
api = getapi(Config(descr2))
|
||||
api.property.read_write()
|
||||
assert not 'hidden' in api.option('opt.str').property.get()
|
||||
api.option('int').value.set(1)
|
||||
raises(PropertiesOptionError, "api.option('opt.str').value.get()")
|
||||
assert 'hidden' in api.option('opt.str').property.get()
|
||||
|
||||
|
||||
def test_apply_requires_with_disabled():
|
||||
s = StrOption("string", "", default=["string"], multi=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
stroption = StrOption('str', 'Test string option', default=["abc"],
|
||||
requires=[{'option': intoption, 'expected': 1, 'action': 'disabled'}], multi=True)
|
||||
descr = OptionDescription("opt", "", [stroption])
|
||||
descr2 = OptionDescription("opt2", "", [intoption, s, descr])
|
||||
api = getapi(Config(descr2))
|
||||
api.property.read_write()
|
||||
assert not 'disabled' in api.option('opt.str').property.get()
|
||||
api.option('int').value.set(1)
|
||||
raises(PropertiesOptionError, "api.option('opt.str').value.get()")
|
||||
assert 'disabled' in api.option('opt.str').property.get()
|
||||
|
||||
|
||||
def test_multi_with_requires_with_disabled_in_another_group():
|
||||
s = StrOption("string", "", default=["string"], multi=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
stroption = StrOption('str', 'Test string option', default=["abc"],
|
||||
requires=[{'option': intoption, 'expected': 1, 'action': 'disabled'}], multi=True)
|
||||
descr = OptionDescription("opt", "", [stroption])
|
||||
descr2 = OptionDescription("opt2", "", [intoption, s, descr])
|
||||
api = getapi(Config(descr2))
|
||||
api.property.read_write()
|
||||
assert not 'disabled' in api.option('opt.str').property.get()
|
||||
api.option('int').value.set(1)
|
||||
raises(PropertiesOptionError, "api.option('opt.str').value.set(['a', 'b'])")
|
||||
assert 'disabled' in api.option('opt.str').property.get()
|
||||
|
||||
|
||||
def test_multi_with_requires_that_is_multi():
|
||||
b = IntOption('int', 'Test int option', default=[0], multi=True)
|
||||
c = StrOption('str', 'Test string option', default=['abc'], requires=[{'option': b, 'expected': 1, 'action': 'hidden'}], multi=True)
|
||||
descr = OptionDescription("opt", "", [b, c])
|
||||
descr
|
||||
raises(ValueError, "Config(descr)")
|
||||
|
||||
|
||||
def test_multi_with_requires_that_is_multi_inverse():
|
||||
b = IntOption('int', 'Test int option', default=[0], multi=True)
|
||||
c = StrOption('str', 'Test string option', default=['abc'], requires=[{'option': b, 'expected': 0, 'action': 'hidden', 'inverse': True}], multi=True)
|
||||
descr = OptionDescription("opt", "", [b, c])
|
||||
descr
|
||||
raises(ValueError, "Config(descr)")
|
||||
|
||||
|
||||
def test_multi_with_requires_that_is_masterslave():
|
||||
b = IntOption('int', 'Test int option', default=[0], multi=True)
|
||||
c = StrOption('str', 'Test string option', requires=[{'option': b, 'expected': 1, 'action': 'hidden'}], multi=True)
|
||||
descr = MasterSlaves("int", "", [b, c])
|
||||
od = OptionDescription('root', '', [descr])
|
||||
Config(od)
|
||||
|
||||
|
||||
def test_multi_with_requires_that_is_masterslave_master():
|
||||
b = IntOption('int', 'Test int option', multi=True)
|
||||
c = StrOption('str', 'Test string option', requires=[{'option': b, 'expected': 1, 'action': 'hidden'}], multi=True)
|
||||
descr = MasterSlaves("str", "", [c, b])
|
||||
descr2 = OptionDescription('descr', '', [descr])
|
||||
raises(ValueError, "Config(descr2)")
|
||||
|
||||
|
||||
def test_multi_with_requires_that_is_masterslave_slave():
|
||||
b = IntOption('int', 'Test int option', default=[0], multi=True)
|
||||
c = StrOption('str', 'Test string option', multi=True)
|
||||
d = StrOption('str1', 'Test string option', requires=[{'option': c, 'expected': '1', 'action': 'hidden'}], multi=True)
|
||||
descr = MasterSlaves("int", "", [b, c, d])
|
||||
descr2 = OptionDescription('od', '', [descr])
|
||||
api = getapi(Config(descr2))
|
||||
api.property.read_write()
|
||||
assert api.option('int.int').value.get() == [0]
|
||||
assert api.option('int.str', 0).value.get() == None
|
||||
assert api.option('int.str1', 0).value.get() == None
|
||||
api.option('int.int').value.set([0, 1])
|
||||
assert api.option('int.int').value.get() == [0, 1]
|
||||
assert api.option('int.str', 0).value.get() == None
|
||||
assert api.option('int.str', 1).value.get() == None
|
||||
assert api.option('int.str1', 0).value.get() == None
|
||||
assert api.option('int.str1', 1).value.get() == None
|
||||
api.option('int.str', 1).value.set('1')
|
||||
api.property.read_only()
|
||||
assert api.option('int.str1', 0).value.get() == None
|
||||
assert api.option('int.str1', 1).value.get() == None
|
||||
api.property.read_write()
|
||||
assert api.option('int.str1', 0).value.get() == None
|
||||
raises(PropertiesOptionError, "api.option('int.str1', 1).value.get()")
|
||||
|
||||
|
||||
def test_multi_with_requires_that_is_masterslave_slave_inverse():
|
||||
b = IntOption('int', 'Test int option', default=[0], multi=True)
|
||||
c = StrOption('str', 'Test string option', multi=True)
|
||||
d = StrOption('str1', 'Test string option', requires=[{'option': c, 'expected': None, 'action': 'hidden', 'inverse': True}], multi=True)
|
||||
descr = MasterSlaves("int", "", [b, c, d])
|
||||
descr2 = OptionDescription('od', '', [descr])
|
||||
api = getapi(Config(descr2))
|
||||
api.property.read_write()
|
||||
assert api.option('int.int').value.get() == [0]
|
||||
assert api.option('int.str', 0).value.get() is None
|
||||
assert api.option('int.str1', 0).value.get() is None
|
||||
api.option('int.int').value.set([0, 1])
|
||||
assert api.option('int.int').value.get() == [0, 1]
|
||||
assert api.option('int.str', 0).value.get() is None
|
||||
assert api.option('int.str', 1).value.get() is None
|
||||
assert api.option('int.str1', 0).value.get() is None
|
||||
assert api.option('int.str1', 1).value.get() is None
|
||||
api.option('int.str', 1).value.set('1')
|
||||
api.property.read_only()
|
||||
assert api.option('int.str1', 0).value.get() is None
|
||||
assert api.option('int.str1', 1).value.get() is None
|
||||
api.property.read_write()
|
||||
assert api.option('int.str1', 0).value.get() is None
|
||||
raises(PropertiesOptionError, "api.option('int.str1', 1).value.get()")
|
||||
|
||||
|
||||
def test_multi_with_requires_that_is_not_same_masterslave():
|
||||
b = IntOption('int', 'Test int option', default=[0], multi=True)
|
||||
c = StrOption('str', 'Test string option', requires=[{'option': b, 'expected': 1, 'action': 'hidden'}], multi=True)
|
||||
descr1 = MasterSlaves("int", "", [b, c])
|
||||
#descr1.impl_set_group_type(groups.master)
|
||||
d = IntOption('int1', 'Test int option', default=[0], multi=True)
|
||||
e = StrOption('str', 'Test string option', requires=[{'option': b, 'expected': 1, 'action': 'hidden'}], multi=True)
|
||||
descr2 = MasterSlaves("int1", "", [d, e])
|
||||
#descr2.impl_set_group_type(groups.master)
|
||||
descr3 = OptionDescription('val', '', [descr1, descr2])
|
||||
descr3
|
||||
raises(ValueError, "Config(descr3)")
|
||||
|
||||
|
||||
def test_multi_with_bool():
|
||||
s = BoolOption("bool", "", default=[False], multi=True)
|
||||
descr = OptionDescription("options", "", [s])
|
||||
api = getapi(Config(descr))
|
||||
api.option('bool').value.set([True, False])
|
||||
assert api.option('bool').value.get() == [True, False]
|
||||
|
||||
|
||||
def test_choice_access_with_multi():
|
||||
ch = ChoiceOption("t1", "", ("a", "b"), default=["a"], multi=True)
|
||||
descr = OptionDescription("options", "", [ch])
|
||||
api = getapi(Config(descr))
|
||||
api.option('t1').value.set(["a", "b", "a", "b"])
|
||||
assert api.option('t1').value.get() == ["a", "b", "a", "b"]
|
||||
|
||||
|
||||
#____________________________________________________________
|
||||
def test_accepts_multiple_changes_from_option():
|
||||
s = StrOption("string", "", default="string")
|
||||
descr = OptionDescription("options", "", [s])
|
||||
api = getapi(Config(descr))
|
||||
api.option('string').value.set("egg")
|
||||
assert api.option('string').option.default() == "string"
|
||||
assert api.option('string').value.get() == "egg"
|
||||
api.option('string').value.set('blah')
|
||||
assert api.option('string').option.default() == "string"
|
||||
assert api.option('string').value.get() == "blah"
|
||||
api.option('string').value.set('bol')
|
||||
assert api.option('string').value.get() == 'bol'
|
||||
|
||||
|
||||
def test_allow_multiple_changes_from_config():
|
||||
"""
|
||||
a `setoption` from the config object is much like the attribute access,
|
||||
except the fact that value owner can bet set
|
||||
"""
|
||||
s = StrOption("string", "", default="string")
|
||||
s2 = StrOption("string2", "", default="string")
|
||||
suboption = OptionDescription("bip", "", [s2])
|
||||
descr = OptionDescription("options", "", [s, suboption])
|
||||
api = getapi(Config(descr))
|
||||
api.option('string').value.set("oh")
|
||||
assert api.option('string').value.get() == "oh"
|
||||
api.option('string').value.set("blah")
|
||||
assert api.option('string').value.get() == "blah"
|
||||
|
||||
|
||||
# ____________________________________________________________
|
||||
# accessing a value by the get method
|
||||
def test_access_by_get():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
raises(AttributeError, "api.option.find('idontexist')")
|
||||
assert api.option.find_first('wantref', type='value') is False
|
||||
assert api.option.find_first('dummy', type='value') is False
|
||||
|
||||
|
||||
def test_access_by_get_whith_hide():
|
||||
b1 = BoolOption("b1", "", properties=(('hidden'),))
|
||||
descr = OptionDescription("opt", "",
|
||||
[OptionDescription("sub", "",
|
||||
[b1, ChoiceOption("c1", "", ('a', 'b', 'c'), 'a'),
|
||||
BoolOption("d1", "")]),
|
||||
BoolOption("b2", ""),
|
||||
BoolOption("d1", "")])
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
raises(AttributeError, "api.option.find('b1', type='value')")
|
||||
|
||||
|
||||
def test_append_properties():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
assert api.option('gc.dummy').property.get() == set()
|
||||
api.option('gc.dummy').property.add('test')
|
||||
assert api.option('gc.dummy').property.get() == {'test'}
|
||||
raises(ConfigError, "api.option('gc.dummy').property.add('force_store_value')")
|
||||
assert api.option('gc.dummy').property.get() == {'test'}
|
||||
|
||||
|
||||
def test_reset_properties():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
assert api.option('gc.dummy').property.get() == set()
|
||||
api.option('gc.dummy').property.add('frozen')
|
||||
assert api.option('gc.dummy').property.get() == {'frozen'}
|
||||
api.option('gc.dummy').property.reset()
|
||||
assert api.option('gc.dummy').property.get() == set()
|
||||
|
||||
|
||||
def test_properties_cached():
|
||||
b1 = BoolOption("b1", "", properties=('test',))
|
||||
descr = OptionDescription("opt", "", [OptionDescription("sub", "", [b1])])
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
assert api.option('sub.b1').property.get() == {'test'}
|
||||
|
||||
|
||||
def test_append_properties_force_store_value():
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False, properties=('force_store_value',))
|
||||
gcgroup = OptionDescription('gc', '', [gcdummy])
|
||||
descr = OptionDescription('tiramisu', '', [gcgroup])
|
||||
api = getapi(Config(descr))
|
||||
assert api.option('gc.dummy').property.get() == {'force_store_value'}
|
||||
api.option('gc.dummy').property.add('test')
|
||||
assert api.option('gc.dummy').property.get() == {'force_store_value', 'test'}
|
||||
|
||||
|
||||
def test_reset_properties_force_store_value():
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False, properties=('force_store_value',))
|
||||
gcgroup = OptionDescription('gc', '', [gcdummy])
|
||||
descr = OptionDescription('tiramisu', '', [gcgroup])
|
||||
api = getapi(Config(descr))
|
||||
assert api.property.get_modified() == {}
|
||||
api.property.add('frozen')
|
||||
assert api.property.get_modified() == \
|
||||
{None: set(('frozen', 'cache', 'validator', 'warnings'))}
|
||||
api.property.reset()
|
||||
assert api.property.get_modified() == {}
|
||||
api.option('gc.dummy').property.add('test')
|
||||
assert api.property.get_modified() == {'gc.dummy': set(('test', 'force_store_value'))}
|
||||
api.property.reset()
|
||||
assert api.property.get_modified() == {'gc.dummy': set(('test', 'force_store_value'))}
|
||||
api.property.add('frozen')
|
||||
assert api.property.get_modified() == \
|
||||
{None: set(('frozen', 'validator', 'cache', 'warnings')),
|
||||
'gc.dummy': set(('test', 'force_store_value'))}
|
||||
api.property.add('frozen')
|
||||
assert api.property.get_modified() == \
|
||||
{None: set(('frozen', 'validator', 'cache', 'warnings')),
|
||||
'gc.dummy': set(('test', 'force_store_value'))}
|
||||
api.option('gc.dummy').property.add('test')
|
||||
assert api.property.get_modified() == \
|
||||
{None: set(('frozen', 'validator', 'cache', 'warnings')),
|
||||
'gc.dummy': set(('test', 'force_store_value'))}
|
||||
|
||||
|
||||
def test_set_modified_value():
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False, properties=('force_store_value',))
|
||||
gcgroup = OptionDescription('gc', '', [gcdummy])
|
||||
descr = OptionDescription('tiramisu', '', [gcgroup])
|
||||
api = getapi(Config(descr))
|
||||
assert api.property.get_modified() == {}
|
||||
api.property.set_modified({None: set(('frozen', 'cache', 'validator', 'warnings'))})
|
||||
assert api.property.get_modified() == \
|
||||
{None: set(('frozen', 'cache', 'validator', 'warnings'))}
|
||||
|
||||
|
||||
def test_pprint():
|
||||
msg_error = _("cannot access to {0} \"{1}\" because has {2} {3}")
|
||||
msg_is = _('the value of "{0}" is "{1}"')
|
||||
msg_is_not = _('the value of "{0}" is not {1}')
|
||||
properties = _('properties')
|
||||
prop = _('property')
|
||||
|
||||
s = StrOption("string", "", default=["string"], default_multi="string", multi=True, properties=('hidden', 'disabled'))
|
||||
s2 = StrOption("string2", "", default="string")
|
||||
s3 = StrOption("string3", "", default=["string"], default_multi="string", multi=True, properties=('hidden',))
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
stroption = StrOption('str', 'Test string option', default="abc",
|
||||
requires=[{'option': intoption, 'expected': 2, 'action': 'hidden', 'inverse': True},
|
||||
{'option': intoption, 'expected': 3, 'action': 'hidden', 'inverse': True},
|
||||
{'option': intoption, 'expected': 4, 'action': 'hidden', 'inverse': True},
|
||||
{'option': intoption, 'expected': 1, 'action': 'disabled'},
|
||||
{'option': s2, 'expected': 'string', 'action': 'disabled'}])
|
||||
|
||||
val2 = StrOption('val2', "")
|
||||
descr2 = OptionDescription("options", "", [val2], requires=[{'option': intoption, 'expected': 1, 'action': 'hidden'}])
|
||||
|
||||
val3 = StrOption('val3', "", requires=[{'option': stroption, 'expected': '2', 'action': 'hidden', 'inverse': True}])
|
||||
|
||||
descr = OptionDescription("options", "", [s, s2, s3, intoption, stroption, descr2, val3])
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
api.option('int').value.set(1)
|
||||
err = None
|
||||
try:
|
||||
api.option('str').value.get()
|
||||
except PropertiesOptionError as error:
|
||||
err = error
|
||||
|
||||
list_disabled = '"disabled" (' + display_list([msg_is.format('Test int option', '1'), msg_is.format('string2', 'string')]) + ')'
|
||||
list_hidden = '"hidden" (' + msg_is_not.format('Test int option', display_list([2, 3, 4], 'or', add_quote=True)) + ')'
|
||||
assert str(err) == _(msg_error.format('option', 'Test string option', properties, display_list([list_disabled, list_hidden])))
|
||||
|
||||
err = None
|
||||
try:
|
||||
api.option('options.val2').value.get()
|
||||
except PropertiesOptionError as error:
|
||||
err = error
|
||||
|
||||
assert str(err) == msg_error.format('optiondescription', 'options', prop, '"hidden" (' + msg_is.format('Test int option', 1) + ')')
|
||||
|
||||
err = None
|
||||
try:
|
||||
api.option('val3').value.get()
|
||||
except PropertiesOptionError as error:
|
||||
err = error
|
||||
|
||||
msg_1 = msg_is.format('string2', 'string')
|
||||
msg_2 = msg_is.format('Test int option', 1)
|
||||
msg_3 = msg_is_not.format('Test int option', display_list([2, 3, 4], 'or', add_quote=True))
|
||||
|
||||
list_hidden = '"hidden" (' + display_list([msg_2, msg_3, msg_1]) + ')'
|
||||
assert str(err) == msg_error.format('option', 'val3', prop, list_hidden)
|
||||
|
||||
err = None
|
||||
try:
|
||||
api.option('string').value.get()
|
||||
except Exception as error:
|
||||
err = error
|
||||
|
||||
assert str(err) == msg_error.format('option', 'string', properties, display_list(['disabled', 'hidden'], add_quote=True))
|
||||
|
||||
err = None
|
||||
try:
|
||||
api.option('string3').value.get()
|
||||
except Exception as error:
|
||||
err = error
|
||||
|
||||
assert str(err) == msg_error.format('option', 'string3', prop, '"hidden"')
|
||||
|
|
@ -1,134 +0,0 @@
|
|||
# coding: utf-8
|
||||
"frozen and hidden values"
|
||||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
|
||||
from py.test import raises
|
||||
|
||||
from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \
|
||||
PasswordOption, StrOption, DateOption, OptionDescription, Config, getapi
|
||||
from tiramisu.error import PropertiesOptionError
|
||||
|
||||
|
||||
def make_description():
|
||||
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False, properties=(('hidden'),))
|
||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||
('std', 'thunk'), ['std'], multi=True)
|
||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
|
||||
wantref_option = BoolOption('wantref', 'Test requires', default=False,
|
||||
requires=({'option': gcoption, 'expected': 'ref', 'action': 'hidden'},))
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False,
|
||||
requires=({'option': gcoption, 'expected': 'framework', 'action': 'hidden'},))
|
||||
|
||||
# ____________________________________________________________
|
||||
booloptiontwo = BoolOption('booltwo', 'Test boolean option two', default=False)
|
||||
subgroup = OptionDescription('subgroup', '', [booloptiontwo])
|
||||
# ____________________________________________________________
|
||||
|
||||
gcgroup = OptionDescription('gc', '', [subgroup, gcoption, gcdummy, floatoption])
|
||||
descr = OptionDescription('trs', '', [gcgroup, booloption, objspaceoption,
|
||||
wantref_option, stroption,
|
||||
wantframework_option,
|
||||
intoption])
|
||||
return descr
|
||||
|
||||
|
||||
# ____________________________________________________________
|
||||
def test_is_hidden():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
assert not 'frozen' in api.option('gc.dummy').property.get()
|
||||
# setattr
|
||||
raises(PropertiesOptionError, "api.option('gc.dummy').value.get() == False")
|
||||
# getattr
|
||||
raises(PropertiesOptionError, "api.option('gc.dummy').value.get()")
|
||||
|
||||
|
||||
def test_group_is_hidden():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
api.option('gc').property.add('hidden')
|
||||
raises(PropertiesOptionError, "api.option('gc.dummy').value.get()")
|
||||
assert 'hidden' in api.option('gc').property.get()
|
||||
raises(PropertiesOptionError, "api.option('gc.float').value.get()")
|
||||
# manually set the subconfigs to "show"
|
||||
api.option('gc').property.pop('hidden')
|
||||
assert not 'hidden' in api.option('gc').property.get()
|
||||
assert api.option('gc.float').value.get() == 2.3
|
||||
#dummy est en hide
|
||||
prop = []
|
||||
try:
|
||||
api.option('gc.dummy').value.set(False)
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'hidden' in prop
|
||||
|
||||
|
||||
def test_group_is_hidden_multi():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
api.option('objspace').property.add('hidden')
|
||||
raises(PropertiesOptionError, "api.option('objspace').value.get()")
|
||||
assert 'hidden' in api.option('objspace').property.get()
|
||||
prop = []
|
||||
try:
|
||||
api.option('objspace').value.set(['std'])
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'hidden' in prop
|
||||
api.option('objspace').property.pop('hidden')
|
||||
assert not 'hidden' in api.option('objspace').property.get()
|
||||
api.option('objspace').value.set(['std', 'std'])
|
||||
|
||||
|
||||
def test_global_show():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
api.option('gc.dummy').property.add('hidden')
|
||||
assert 'hidden' in api.option('gc.dummy').property.get()
|
||||
raises(PropertiesOptionError, "api.option('gc.dummy').value.get() == False")
|
||||
|
||||
|
||||
def test_with_many_subgroups():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
#booltwo = config.unwrap_from_path('gc.subgroup.booltwo')
|
||||
#setting = config.cfgimpl_get_settings()
|
||||
assert not 'hidden' in api.option('gc.subgroup.booltwo').property.get()
|
||||
assert api.option('gc.subgroup.booltwo').value.get() is False
|
||||
api.option('gc.subgroup.booltwo').property.add('hidden')
|
||||
|
||||
|
||||
def test_password_option():
|
||||
o = PasswordOption('o', '')
|
||||
d = OptionDescription('d', '', [o])
|
||||
api = getapi(Config(d))
|
||||
|
||||
api.option('o').value.set('a_valid_password')
|
||||
raises(ValueError, "api.option('o').value.set(1)")
|
||||
|
||||
|
||||
def test_date_option():
|
||||
o = DateOption('o', '')
|
||||
d = OptionDescription('d', '', [o])
|
||||
api = getapi(Config(d))
|
||||
|
||||
api.option('o').value.set('2017-02-04')
|
||||
api.option('o').value.set('2017-2-4')
|
||||
raises(ValueError, "api.option('o').value.set(1)")
|
||||
raises(ValueError, "api.option('o').value.set('2017-13-20')")
|
||||
raises(ValueError, "api.option('o').value.set('2017-11-31')")
|
||||
raises(ValueError, "api.option('o').value.set('2017-12-32')")
|
||||
raises(ValueError, "api.option('o').value.set('2017-2-29')")
|
||||
raises(ValueError, "api.option('o').value.set('2-2-2017')")
|
||||
raises(ValueError, "api.option('o').value.set('2017/2/2')")
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
"configuration objects global API"
|
||||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
|
||||
from py.test import raises
|
||||
|
||||
from tiramisu.option import UsernameOption
|
||||
|
||||
def test_username():
|
||||
UsernameOption('a', '', 'string')
|
||||
UsernameOption('a', '', '_string')
|
||||
UsernameOption('a', '', 's_tring')
|
||||
UsernameOption('a', '', 'string_')
|
||||
UsernameOption('a', '', 'string$')
|
||||
UsernameOption('a', '', '_string$')
|
||||
raises(ValueError, "UsernameOption('a', '', 'strin$g')")
|
||||
UsernameOption('a', '', 's-tring')
|
||||
raises(ValueError, "UsernameOption('a', '', '-string')")
|
||||
UsernameOption('a', '', 's9tring')
|
||||
raises(ValueError, "UsernameOption('a', '', '9string')")
|
||||
raises(ValueError, "UsernameOption('a', '', '')")
|
||||
UsernameOption('a', '', 's')
|
||||
UsernameOption('a', '', 's2345678901234567890123456789012')
|
||||
raises(ValueError, "UsernameOption('a', '', 's23456789012345678901234567890123')")
|
||||
UsernameOption('a', '', 's234567890123456789012345678901$')
|
||||
raises(ValueError, "UsernameOption('a', '', 's2345678901234567890123456789012$')")
|
||||
|
|
@ -1,483 +0,0 @@
|
|||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
|
||||
import warnings
|
||||
from py.test import raises
|
||||
|
||||
from tiramisu import BoolOption, StrOption, OptionDescription, MasterSlaves, Config, getapi
|
||||
from tiramisu.setting import groups
|
||||
from tiramisu.error import ValueWarning, ConfigError
|
||||
from tiramisu.i18n import _
|
||||
|
||||
|
||||
msg_err = _('attention, "{0}" could be an invalid {1} for "{2}", {3}')
|
||||
|
||||
|
||||
def return_true(value, param=None):
|
||||
if value == 'val' and param in [None, 'yes']:
|
||||
return True
|
||||
raise ValueError('test error')
|
||||
|
||||
|
||||
def return_false(value, param=None):
|
||||
if value == 'val' and param in [None, 'yes']:
|
||||
raise ValueError('test error')
|
||||
|
||||
|
||||
def return_val(value, param=None):
|
||||
return 'val'
|
||||
|
||||
|
||||
def return_if_val(value):
|
||||
if value != 'val':
|
||||
raise ValueError('test error')
|
||||
|
||||
|
||||
def is_context(value, context):
|
||||
api = getapi(context)
|
||||
api.property.pop('validator')
|
||||
if not isinstance(context, Config):
|
||||
raise ValueError('not context')
|
||||
|
||||
|
||||
def value_values(value, values):
|
||||
if not (value == 'val' and values == ['val'] or
|
||||
value == 'val1' and values == ['val1'] or
|
||||
value == 'val1' and values == ['val1', 'val2'] or
|
||||
value == 'val2' and values == ['val1', 'val2'] or
|
||||
value == 'val1' and values == ['val1', None]):
|
||||
raise ValueError('error')
|
||||
|
||||
|
||||
def value_values_index(value, values, index):
|
||||
value_values(value, values)
|
||||
if not (index == 0 or (value == 'val2' and index == 1)):
|
||||
raise ValueError('error 2')
|
||||
|
||||
|
||||
def value_values_auto(value, values, auto=False):
|
||||
if auto != False:
|
||||
raise ValueError('auto should be False')
|
||||
if not (value == 'val' and values == ['val'] or
|
||||
value == 'val1' and values == ['val1'] or
|
||||
value == 'val2' and values == ['val1', 'val2'] or
|
||||
value == 'val1' and values == ['val1', None]):
|
||||
raise ValueError('error')
|
||||
|
||||
|
||||
def value_values_auto2(value, values, auto=False):
|
||||
if auto != False:
|
||||
raise ValueError('auto should be False')
|
||||
if not (value == 'val1' and values == 'val' or
|
||||
value == 'val2' and values == 'val'):
|
||||
raise ValueError('error')
|
||||
|
||||
|
||||
|
||||
def value_values_index2(value, values, index, auto=False):
|
||||
if auto != False:
|
||||
raise ValueError('auto should be False')
|
||||
if not (value == 'val1' and values == ['val1'] and index == 'val' or
|
||||
value == 'val1' and values == ['val1', None] and index == 'val' or
|
||||
value == 'val2' and values == ['val1', 'val2'] and index == 'val'):
|
||||
raise ValueError('error')
|
||||
|
||||
|
||||
def value_empty(value, empty, values):
|
||||
if not value == 'val' or empty is not False and not values == ['val']:
|
||||
raise ValueError('error')
|
||||
|
||||
|
||||
def valid_from_config(value, config):
|
||||
api = getapi(config)
|
||||
if api.option('opt1').value.get() != u'yes':
|
||||
raise ValueError("c'est une erreur")
|
||||
|
||||
|
||||
def test_validator():
|
||||
opt1 = StrOption('opt1', '', validator=return_true, default='val')
|
||||
raises(ValueError, "StrOption('opt2', '', validator=return_false, default='val')")
|
||||
opt2 = StrOption('opt2', '', validator=return_false)
|
||||
root = OptionDescription('root', '', [opt1, opt2])
|
||||
api = getapi(Config(root))
|
||||
assert api.option('opt1').value.get() == 'val'
|
||||
raises(ValueError, "api.option('opt2').value.set('val')")
|
||||
try:
|
||||
api.option('opt2').value.set('val')
|
||||
except ValueError as err:
|
||||
msg = _('"{0}" is an invalid {1} for "{2}", {3}').format('val', _('string'), 'opt2', 'test error')
|
||||
assert str(err) == msg
|
||||
|
||||
|
||||
def test_validator_params():
|
||||
opt1 = StrOption('opt1', '', validator=return_true, validator_params={'': ('yes',)}, default='val')
|
||||
raises(ValueError, "StrOption('opt2', '', validator=return_false, validator_params={'': ('yes',)}, default='val')")
|
||||
opt2 = StrOption('opt2', '', validator=return_false, validator_params={'': ('yes',)})
|
||||
root = OptionDescription('root', '', [opt1, opt2])
|
||||
api = getapi(Config(root))
|
||||
assert api.option('opt1').value.get() == 'val'
|
||||
raises(ValueError, "api.option('opt2').value.set('val')")
|
||||
|
||||
|
||||
def test_validator_params_value_values():
|
||||
opt1 = StrOption('opt1', '', validator=value_values, default=['val'], multi=True)
|
||||
root = OptionDescription('root', '', [opt1])
|
||||
api = getapi(Config(root))
|
||||
assert api.option('opt1').value.get() == ['val']
|
||||
api.option('opt1').value.set(['val1', 'val2'])
|
||||
|
||||
|
||||
def test_validator_params_value_values_index():
|
||||
opt1 = StrOption('opt1', '', validator=value_values_index, default=['val'], multi=True)
|
||||
root = OptionDescription('root', '', [opt1])
|
||||
api = getapi(Config(root))
|
||||
assert api.option('opt1').value.get() == ['val']
|
||||
api.option('opt1').value.set(['val1', 'val2'])
|
||||
|
||||
|
||||
def test_validator_params_value_values_master():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True, validator=value_values)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-reseau", multi=True)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
root = OptionDescription('root', '', [interface1])
|
||||
api = getapi(Config(root))
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val2'])
|
||||
|
||||
|
||||
def test_validator_params_value_values_index_master():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True, validator=value_values_index)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-reseau", multi=True)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
root = OptionDescription('root', '', [interface1])
|
||||
api = getapi(Config(root))
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val2'])
|
||||
|
||||
|
||||
def test_validator_params_value_values_slave():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-reseau", multi=True, validator=value_values)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
root = OptionDescription('root', '', [interface1])
|
||||
api = getapi(Config(root))
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1')
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val2')
|
||||
|
||||
|
||||
def test_validator_params_value_values_index_slave():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-reseau", multi=True, validator=value_values_index)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
root = OptionDescription('root', '', [interface1])
|
||||
api = getapi(Config(root))
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1')
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val2')
|
||||
|
||||
|
||||
def test_validator_params_value_values_notmulti():
|
||||
raises(ConfigError, "opt1 = StrOption('opt1', '', validator=value_values, default='val')")
|
||||
|
||||
|
||||
def test_validator_params_value_values_kwargs_empty():
|
||||
v = BoolOption('v', '', default=False)
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True, default=["ip"])
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0',
|
||||
"masque du sous-reseau",
|
||||
multi=True,
|
||||
validator=value_empty,
|
||||
validator_params={'': ((v, False),)})
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
root = OptionDescription('root', '', [v, interface1])
|
||||
api = getapi(Config(root))
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip', 'val'])
|
||||
#cfg.ip_admin_eth0.ip_admin_eth0.append('val')
|
||||
#cfg.ip_admin_eth0.netmask_admin_eth0[1] = 'val2'
|
||||
|
||||
|
||||
def test_validator_params_value_values_kwargs():
|
||||
v = BoolOption('v', '', default=False)
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True, default=["ip"])
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0',
|
||||
"masque du sous-reseau",
|
||||
multi=True,
|
||||
validator=value_values_auto,
|
||||
validator_params={'auto': ((v, False),)})
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
root = OptionDescription('root', '', [v, interface1])
|
||||
api = getapi(Config(root))
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1')
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip', 'val'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val2')
|
||||
|
||||
|
||||
def test_validator_params_value_values_kwargs_values():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0',
|
||||
"masque du sous-reseau",
|
||||
multi=True,
|
||||
validator=value_values_auto2,
|
||||
validator_params={'values': ((ip_admin_eth0, False),)})
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
root = OptionDescription('root', '', [interface1])
|
||||
api = getapi(Config(root))
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1')
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val2')
|
||||
|
||||
|
||||
def test_validator_params_value_values_kwargs2():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0',
|
||||
"masque du sous-reseau",
|
||||
multi=True,
|
||||
validator=value_values_index2,
|
||||
validator_params={'': (['val1'],), 'index': ((ip_admin_eth0, False),)})
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
root = OptionDescription('root', '', [interface1])
|
||||
api = getapi(Config(root))
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1')
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val'])
|
||||
|
||||
|
||||
def test_validator_params_value_values_kwargs_index():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0',
|
||||
"masque du sous-reseau",
|
||||
multi=True,
|
||||
validator=value_values_index2,
|
||||
validator_params={'index': ((ip_admin_eth0, False),)})
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
root = OptionDescription('root', '', [interface1])
|
||||
api = getapi(Config(root))
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1')
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val2')
|
||||
|
||||
|
||||
def test_validator_params_context():
|
||||
opt1 = StrOption('opt1', '', validator=is_context, validator_params={'': ((None,),)}, default='val')
|
||||
root = OptionDescription('root', '', [opt1])
|
||||
api = getapi(Config(root))
|
||||
assert 'validator' in api.property.get()
|
||||
assert api.option('opt1').value.get() == 'val'
|
||||
assert 'validator' in api.property.get()
|
||||
|
||||
|
||||
def test_validator_params_context_value():
|
||||
opt1 = StrOption('opt1', '', 'yes')
|
||||
opt2 = StrOption('opt2', '', validator=valid_from_config, validator_params={'': ((None,),)}, default='val')
|
||||
root = OptionDescription('root', '', [opt1, opt2])
|
||||
api = getapi(Config(root))
|
||||
assert api.option('opt1').value.get() == 'yes'
|
||||
assert api.option('opt2').value.get() == 'val'
|
||||
api.option('opt1').value.set('no')
|
||||
raises(ValueError, "assert api.option('opt2').value.get()")
|
||||
|
||||
|
||||
def test_validator_params_key():
|
||||
opt1 = StrOption('opt1', '', validator=return_true, validator_params={'param': ('yes',)}, default='val')
|
||||
raises(ConfigError, "StrOption('opt2', '', validator=return_true, validator_params={'param_unknown': ('yes',)}, default='val')")
|
||||
root = OptionDescription('root', '', [opt1])
|
||||
api = getapi(Config(root))
|
||||
assert api.option('opt1').value.get() == 'val'
|
||||
|
||||
|
||||
def test_validator_params_option():
|
||||
opt0 = StrOption('opt0', '', default='yes')
|
||||
opt1 = StrOption('opt1', '', validator=return_true, validator_params={'': ((opt0, False),)}, default='val')
|
||||
r = OptionDescription('root', '', [opt0, opt1])
|
||||
api = getapi(Config(r))
|
||||
assert api.option('opt1').value.get() == 'val'
|
||||
api.option('opt0').value.set('val')
|
||||
raises(ValueError, "api.option('opt1').value.get()")
|
||||
|
||||
|
||||
def test_validator_multi():
|
||||
opt1 = StrOption('opt1', '', validator=return_if_val, multi=True)
|
||||
root = OptionDescription('root', '', [opt1])
|
||||
api = getapi(Config(root))
|
||||
assert api.option('opt1').value.get() == []
|
||||
api.option('opt1').value.set(['val'])
|
||||
assert api.option('opt1').value.get() == ['val']
|
||||
raises(ValueError, "api.option('opt1').value.set(['val', 'val1'])")
|
||||
|
||||
|
||||
def test_validator_warning():
|
||||
opt1 = StrOption('opt1', '', validator=return_true, default='val', warnings_only=True)
|
||||
opt2 = StrOption('opt2', '', validator=return_false, warnings_only=True)
|
||||
opt3 = StrOption('opt3', '', validator=return_if_val, multi=True, warnings_only=True)
|
||||
root = OptionDescription('root', '', [opt1, opt2, opt3])
|
||||
api = getapi(Config(root))
|
||||
assert api.option('opt1').value.get() == 'val'
|
||||
warnings.simplefilter("always", ValueWarning)
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('opt1').value.set('val')
|
||||
assert w == []
|
||||
#
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('opt2').value.set('val')
|
||||
assert len(w) == 1
|
||||
assert w[0].message.opt == opt2
|
||||
assert str(w[0].message) == msg_err.format('val', opt2._display_name, 'opt2', 'test error')
|
||||
#
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('opt3').value.set(['val'])
|
||||
assert w == []
|
||||
#
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('opt3').value.set(['val', 'val1'])
|
||||
assert len(w) == 1
|
||||
assert w[0].message.opt == opt3
|
||||
assert str(w[0].message) == msg_err.format('val1', opt3._display_name, 'opt3', 'test error')
|
||||
raises(ValueError, "api.option('opt2').value.set(1)")
|
||||
#
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('opt2').value.set('val')
|
||||
api.option('opt3').value.set(['val', 'val1', 'val'])
|
||||
assert len(w) == 2
|
||||
assert w[0].message.opt == opt2
|
||||
assert str(w[0].message) == msg_err.format('val', opt2._display_name, 'opt2', 'test error')
|
||||
assert w[1].message.opt == opt3
|
||||
assert str(w[0].message) == msg_err.format('val', opt2._display_name, 'opt2', 'test error')
|
||||
|
||||
|
||||
def test_validator_warning_disabled():
|
||||
opt1 = StrOption('opt1', '', validator=return_true, default='val', warnings_only=True)
|
||||
opt2 = StrOption('opt2', '', validator=return_false, warnings_only=True)
|
||||
opt3 = StrOption('opt3', '', validator=return_if_val, multi=True, warnings_only=True)
|
||||
root = OptionDescription('root', '', [opt1, opt2, opt3])
|
||||
api = getapi(Config(root))
|
||||
api.property.pop('warnings')
|
||||
assert api.option('opt1').value.get() == 'val'
|
||||
warnings.simplefilter("always", ValueWarning)
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('opt1').value.set('val')
|
||||
assert w == []
|
||||
#
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('opt2').value.set('val')
|
||||
assert w == []
|
||||
#
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('opt3').value.set(['val'])
|
||||
assert w == []
|
||||
#
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('opt3').value.set(['val', 'val1'])
|
||||
assert w == []
|
||||
raises(ValueError, "api.option('opt2').value.set(1)")
|
||||
#
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('opt2').value.set('val')
|
||||
api.option('opt3').value.set(['val', 'val1', 'val'])
|
||||
assert w == []
|
||||
|
||||
|
||||
def test_validator_warning_master_slave():
|
||||
display_name_ip = "ip reseau autorise"
|
||||
display_name_netmask = "masque du sous-reseau"
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', display_name_ip, multi=True, validator=return_false, warnings_only=True)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', display_name_netmask, multi=True, validator=return_if_val, warnings_only=True)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
assert interface1.impl_get_group_type() == groups.master
|
||||
root = OptionDescription('root', '', [interface1])
|
||||
api = getapi(Config(root))
|
||||
warnings.simplefilter("always", ValueWarning)
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set([None])
|
||||
assert w == []
|
||||
#
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1')
|
||||
assert len(w) == 1
|
||||
assert w[0].message.opt == netmask_admin_eth0
|
||||
assert str(w[0].message) == msg_err.format('val1', netmask_admin_eth0._display_name, display_name_netmask, 'test error')
|
||||
#
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val'])
|
||||
assert len(w) == 1
|
||||
assert w[0].message.opt == ip_admin_eth0
|
||||
assert str(w[0].message) == msg_err.format('val', ip_admin_eth0._display_name, display_name_ip, 'test error')
|
||||
#
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val1', 'val1'])
|
||||
#FIXME
|
||||
#assert len(w) == 1
|
||||
assert w[0].message.opt == ip_admin_eth0
|
||||
assert str(w[0].message) == msg_err.format('val', ip_admin_eth0._display_name, display_name_ip, 'test error')
|
||||
#
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val', 'val1'])
|
||||
#FIXME
|
||||
#assert len(w) == 1
|
||||
assert w[0].message.opt == ip_admin_eth0
|
||||
assert str(w[0].message) == msg_err.format('val', ip_admin_eth0._display_name, display_name_ip, 'test error')
|
||||
#
|
||||
warnings.resetwarnings()
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val1', 'val'])
|
||||
#FIXME
|
||||
#assert len(w) == 1
|
||||
assert w[0].message.opt == ip_admin_eth0
|
||||
assert str(w[0].message) == msg_err.format('val', ip_admin_eth0._display_name, display_name_ip, 'test error')
|
||||
|
||||
|
||||
def test_validator_slave_param():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0',
|
||||
"masque du sous-reseau",
|
||||
multi=True,
|
||||
validator=return_true,
|
||||
validator_params={'param': ((ip_admin_eth0, False),)})
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
root = OptionDescription('root', '', [interface1])
|
||||
api = getapi(Config(root))
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['yes'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val')
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['yes', 'yes'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val')
|
||||
|
||||
|
||||
def test_validator_dependencies():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise")
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0',
|
||||
"masque du sous-reseau",
|
||||
validator=return_true,
|
||||
validator_params={'param': ((ip_admin_eth0, False),)})
|
||||
opt2 = StrOption('opt2', '', validator=return_false)
|
||||
root = OptionDescription('root', '', [ip_admin_eth0, netmask_admin_eth0, opt2])
|
||||
api = getapi(Config(root))
|
||||
assert api.option('ip_admin_eth0').option.has_dependency() is False
|
||||
assert api.option('netmask_admin_eth0').option.has_dependency() is True
|
||||
assert api.option('opt2').option.has_dependency() is False
|
||||
#
|
||||
assert api.option('ip_admin_eth0').option.has_dependency(False) is True
|
||||
assert api.option('netmask_admin_eth0').option.has_dependency(False) is False
|
||||
assert api.option('opt2').option.has_dependency(False) is False
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
#this test is much more to test that **it's there** and answers attribute access
|
||||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
|
||||
from py.test import raises
|
||||
|
||||
from tiramisu import BoolOption, OptionDescription, ChoiceOption,\
|
||||
IntOption, FloatOption, StrOption, Config, getapi
|
||||
|
||||
|
||||
def make_description():
|
||||
gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
gcdummy2 = BoolOption('hide', 'dummy', default=True)
|
||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||
['std', 'thunk'], 'std')
|
||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
|
||||
wantref_option = BoolOption('wantref', 'Test requires', default=False)
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False)
|
||||
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption, gcdummy2])
|
||||
descr = OptionDescription('tiram', '', [gcgroup, booloption, objspaceoption,
|
||||
wantref_option, stroption,
|
||||
wantframework_option,
|
||||
intoption, boolop])
|
||||
return descr
|
||||
|
||||
|
||||
def test_root_config_answers_ok():
|
||||
"if you hide the root config, the options in this namespace behave normally"
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
|
||||
descr = OptionDescription('tiramisu', '', [gcdummy, boolop])
|
||||
api = getapi(Config(descr))
|
||||
#settings = cfg.cfgimpl_get_settings()
|
||||
#settings.append('hidden')
|
||||
|
||||
assert api.option('dummy').value.get() is False
|
||||
assert api.option('boolop').value.get() is True
|
||||
|
||||
|
||||
def test_optname_shall_not_start_with_numbers():
|
||||
raises(ValueError, "gcdummy = BoolOption('123dummy', 'dummy', default=False)")
|
||||
raises(ValueError, "descr = OptionDescription('123tiramisu', '', [])")
|
||||
|
||||
|
||||
def test_option_has_an_api_name():
|
||||
raises(ValueError, "BoolOption('cfgimpl_get_settings', 'dummy', default=False)")
|
||||
raises(ValueError, "BoolOption('unwrap_from_path', 'dummy', default=False)")
|
||||
raises(ValueError, "BoolOption('impl_getdoc', 'dummy', default=False)")
|
||||
raises(ValueError, "BoolOption('_unvalid', 'dummy', default=False)")
|
||||
raises(ValueError, "BoolOption('6unvalid', 'dummy', default=False)")
|
||||
BoolOption('unvalid6', 'dummy', default=False)
|
||||
BoolOption('unvalid_', 'dummy', default=False)
|
||||
|
|
@ -1,594 +0,0 @@
|
|||
# coding: utf-8
|
||||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
|
||||
from tiramisu.setting import groups, owners
|
||||
from tiramisu import ChoiceOption, BoolOption, IntOption, \
|
||||
StrOption, OptionDescription, MasterSlaves, Config, getapi
|
||||
from tiramisu.error import SlaveError, PropertiesOptionError, APIError, ConfigError
|
||||
|
||||
from py.test import raises
|
||||
|
||||
|
||||
def make_description():
|
||||
numero_etab = StrOption('numero_etab', "identifiant de l'établissement")
|
||||
nom_machine = StrOption('nom_machine', "nom de la machine", default="eoleng")
|
||||
nombre_interfaces = IntOption('nombre_interfaces', "nombre d'interfaces à activer",
|
||||
default=1)
|
||||
activer_proxy_client = BoolOption('activer_proxy_client', "utiliser un proxy",
|
||||
default=False)
|
||||
mode_conteneur_actif = BoolOption('mode_conteneur_actif', "le serveur est en mode conteneur",
|
||||
default=False)
|
||||
mode_conteneur_actif2 = BoolOption('mode_conteneur_actif2', "le serveur est en mode conteneur2",
|
||||
default=False, properties=('hidden',))
|
||||
|
||||
adresse_serveur_ntp = StrOption('serveur_ntp', "adresse serveur ntp", multi=True)
|
||||
time_zone = ChoiceOption('time_zone', 'fuseau horaire du serveur',
|
||||
('Paris', 'Londres'), 'Paris')
|
||||
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé")
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau")
|
||||
|
||||
master = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
interface1 = OptionDescription('interface1', '', [master])
|
||||
interface1.impl_set_group_type(groups.family)
|
||||
|
||||
general = OptionDescription('general', '', [numero_etab, nom_machine,
|
||||
nombre_interfaces, activer_proxy_client,
|
||||
mode_conteneur_actif, mode_conteneur_actif2,
|
||||
adresse_serveur_ntp, time_zone])
|
||||
general.impl_set_group_type(groups.family)
|
||||
new = OptionDescription('new', '', [], properties=('hidden',))
|
||||
new.impl_set_group_type(groups.family)
|
||||
creole = OptionDescription('creole', 'first tiramisu configuration', [general, interface1, new])
|
||||
descr = OptionDescription('baseconfig', 'baseconifgdescr', [creole])
|
||||
return descr
|
||||
|
||||
|
||||
def test_base_config():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
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_first('nom_machine', type='value') == "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',
|
||||
'interface1.ip_admin_eth0.netmask_admin_eth0': None, 'general.nom_machine':
|
||||
'eoleng', 'general.activer_proxy_client': False}
|
||||
assert api.option('creole').make_dict() == result
|
||||
result = {'serveur_ntp': [], 'mode_conteneur_actif': False,
|
||||
'ip_admin_eth0': None, 'time_zone': 'Paris', 'numero_etab': None,
|
||||
'netmask_admin_eth0': None, 'nom_machine': 'eoleng', 'activer_proxy_client':
|
||||
False, 'nombre_interfaces': 1}
|
||||
assert api.option('creole').make_dict(flatten=True) == result
|
||||
|
||||
|
||||
def test_make_dict_filter():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
subresult = {'numero_etab': None, 'nombre_interfaces': 1,
|
||||
'serveur_ntp': [], 'mode_conteneur_actif': False,
|
||||
'time_zone': 'Paris', 'nom_machine': 'eoleng',
|
||||
'activer_proxy_client': False}
|
||||
result = {}
|
||||
for key, value in subresult.items():
|
||||
result['general.' + key] = value
|
||||
assert api.option('creole').make_dict(withoption='numero_etab') == result
|
||||
raises(AttributeError, "api.option('creole').make_dict(withoption='numero_etab', withvalue='toto')")
|
||||
assert api.option('creole').make_dict(withoption='numero_etab', withvalue=None) == result
|
||||
assert api.option('creole.general').make_dict(withoption='numero_etab') == subresult
|
||||
|
||||
|
||||
def test_get_group_type():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
grp = api.option('creole.general')
|
||||
assert grp.group_type() == groups.family
|
||||
assert grp.group_type() == 'family'
|
||||
assert isinstance(grp.group_type(), groups.GroupType)
|
||||
#raises(TypeError, 'grp.impl_set_group_type(groups.default)')
|
||||
|
||||
|
||||
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]
|
||||
assert group_names == ['general', 'interface1']
|
||||
for i in api.option('creole').list('optiondescription', group_type=groups.family):
|
||||
#test StopIteration
|
||||
break
|
||||
|
||||
|
||||
def test_iter_on_groups_force_permissive():
|
||||
descr = make_description()
|
||||
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())
|
||||
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())
|
||||
ass.remove('mode_conteneur_actif2')
|
||||
assert group_names == ass
|
||||
|
||||
|
||||
def test_iter_group_on_groups_force_permissive():
|
||||
descr = make_description()
|
||||
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]
|
||||
assert group_names == ['general', 'interface1', 'new']
|
||||
|
||||
|
||||
def test_iter_on_groups_props():
|
||||
descr = make_description()
|
||||
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]
|
||||
assert group_names == ['general']
|
||||
|
||||
|
||||
def test_iter_on_empty_group():
|
||||
api = getapi(Config(OptionDescription("name", "descr", [])))
|
||||
api.property.read_write()
|
||||
result = list(api.option.list(type='optiondescription'))
|
||||
assert result == []
|
||||
|
||||
|
||||
def test_iter_not_group():
|
||||
api = getapi(Config(OptionDescription("name", "descr", [])))
|
||||
api.property.read_write()
|
||||
raises(TypeError, "list(api.option.list(type='optiondescription', group_type='family'))")
|
||||
|
||||
|
||||
def test_groups_with_master():
|
||||
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)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
assert interface1.impl_get_group_type() == groups.master
|
||||
|
||||
|
||||
def test_groups_with_master_in_root():
|
||||
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)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
raises(ConfigError, "Config(interface1)")
|
||||
|
||||
|
||||
def test_groups_with_master_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)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
od = OptionDescription('root', '', [interface1])
|
||||
Config(od)
|
||||
assert interface1.impl_get_group_type() == groups.master
|
||||
|
||||
|
||||
def test_groups_with_master_hidden_in_config():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True, properties=('hidden',))
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, properties=('hidden',))
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
od = OptionDescription('root', '', [interface1])
|
||||
api = getapi(Config(od))
|
||||
api.property.read_write()
|
||||
api.permissive.set(frozenset(['hidden']))
|
||||
assert api.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
api.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
|
||||
assert api.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()")
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
|
||||
|
||||
|
||||
def test_groups_with_master_hidden_in_config2():
|
||||
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 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
od = OptionDescription('root', '', [interface1])
|
||||
api = getapi(Config(od))
|
||||
api.property.read_write()
|
||||
api.permissive.set(frozenset(['hidden']))
|
||||
assert api.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
api.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
|
||||
assert api.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
#del
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
|
||||
api.property.pop('hidden')
|
||||
assert api.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
api.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
|
||||
assert api.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
|
||||
api.property.add('hidden')
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
|
||||
api.property.pop('hidden')
|
||||
assert api.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
|
||||
|
||||
def test_groups_with_master_hidden_in_config3():
|
||||
#if master is hidden, slave are hidden too
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True, properties=('hidden',))
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
od = OptionDescription('root', '', [interface1])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
api = getapi(Config(od))
|
||||
api.property.read_write()
|
||||
api.permissive.set(frozenset(['hidden']))
|
||||
assert api.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
api.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
|
||||
assert api.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()")
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
|
||||
|
||||
|
||||
def test_allowed_groups():
|
||||
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)
|
||||
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
interface1
|
||||
raises(ValueError, "interface1.impl_set_group_type('toto')")
|
||||
|
||||
|
||||
def test_values_with_master_disabled_master():
|
||||
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)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
api = getapi(Config(maconfig))
|
||||
api.property.read_write()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set("192.168.230.145")
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').property.add('disabled')
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('192.168.230.145')")
|
||||
|
||||
|
||||
def test_sub_group_in_master_group():
|
||||
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)
|
||||
subgroup = OptionDescription("subgroup", '', [])
|
||||
raises(ValueError, "MasterSlaves('ip_admin_eth0', '', [subgroup, ip_admin_eth0, netmask_admin_eth0])")
|
||||
|
||||
|
||||
def test_group_always_has_multis():
|
||||
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")
|
||||
raises(ValueError, "MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])")
|
||||
|
||||
|
||||
#____________________________________________________________
|
||||
def test_values_with_master_and_slaves():
|
||||
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)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
api = getapi(Config(maconfig))
|
||||
api.property.read_write()
|
||||
owner = api.owner.get()
|
||||
assert interface1.impl_get_group_type() == groups.master
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
|
||||
#
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ["192.168.230.145"]
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", "192.168.230.147"])
|
||||
raises(APIError, "api.option('ip_admin_eth0.netmask_admin_eth0').value.set([None])")
|
||||
raises(APIError, "api.option('ip_admin_eth0.netmask_admin_eth0').value.pop(0)")
|
||||
|
||||
|
||||
def test_reset_values_with_master_and_slaves():
|
||||
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)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
api = getapi(Config(maconfig))
|
||||
api.property.read_write()
|
||||
owner = api.owner.get()
|
||||
assert interface1.impl_get_group_type() == groups.master
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
#reset
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
|
||||
|
||||
def test_reset_values_with_master_and_slaves_default_value():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True, default=['192.168.230.145'])
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, default=['255.255.255.0'])
|
||||
raises(ValueError, "MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])")
|
||||
|
||||
|
||||
def test_reset_values_with_master_and_slaves_default():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True, default=['192.168.230.145'])
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
api = getapi(Config(maconfig))
|
||||
api.property.read_write()
|
||||
owner = api.owner.get()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
|
||||
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.146'])
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.230.145']
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(None)
|
||||
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.146'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owner
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.default
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.230.145']
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(None)
|
||||
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owner
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.230.145']
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(None)
|
||||
|
||||
|
||||
def test_values_with_master_and_slaves_slave():
|
||||
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)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
api = getapi(Config(maconfig))
|
||||
api.property.read_write()
|
||||
raises(SlaveError,
|
||||
"api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')")
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset()
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
|
||||
#
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145', '192.168.230.145'])
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() is None
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.0')
|
||||
raises(APIError, "api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.pop(1)")
|
||||
#reset
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145',
|
||||
'192.168.230.145',
|
||||
'192.168.230.145'])
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
|
||||
|
||||
def test_values_with_master_and_slaves_pop():
|
||||
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)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
api = getapi(Config(maconfig))
|
||||
api.property.read_write()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145', '192.168.230.146'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.0.0')
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.230.145', '192.168.230.146']
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.0.0'
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.230.146']
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0'
|
||||
|
||||
|
||||
def test_values_with_master_and_slaves_master():
|
||||
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)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
api = getapi(Config(maconfig))
|
||||
api.property.read_write()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", "192.168.230.145"])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.0')
|
||||
raises(SlaveError, "api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])")
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.0'
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(1)
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ["192.168.230.145"]
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
|
||||
|
||||
def test_values_with_master_and_slaves_master_pop():
|
||||
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)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
api = getapi(Config(maconfig))
|
||||
api.property.read_write()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", "192.168.230.146"])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.0.0')
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ["192.168.230.145", "192.168.230.146"]
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.0.0'
|
||||
assert api.value.get_modified() == {'ip_admin_eth0.ip_admin_eth0': (
|
||||
'user',
|
||||
('192.168.230.145', '192.168.230.146')),
|
||||
'ip_admin_eth0.netmask_admin_eth0': (
|
||||
{'1': 'user'},
|
||||
{'1': '255.255.0.0'})}
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
|
||||
assert api.value.get_modified() == {'ip_admin_eth0.ip_admin_eth0': (
|
||||
'user',
|
||||
('192.168.230.146',)),
|
||||
'ip_admin_eth0.netmask_admin_eth0': (
|
||||
{'0': 'user'},
|
||||
{'0': '255.255.0.0'})}
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ["192.168.230.146"]
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0'
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.146', "192.168.230.145", "192.168.230.146", "192.168.230.147", "192.168.230.148", "192.168.230.149"])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 3).value.set('255.255.0.0')
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 4).value.set('255.255.0.0')
|
||||
assert api.value.get_modified() == {'ip_admin_eth0.ip_admin_eth0': (
|
||||
'user',
|
||||
('192.168.230.146', "192.168.230.145", "192.168.230.146", "192.168.230.147", "192.168.230.148", "192.168.230.149")),
|
||||
'ip_admin_eth0.netmask_admin_eth0': (
|
||||
{'0': 'user', '3': 'user', '4': 'user'},
|
||||
{'0': '255.255.0.0', '3': '255.255.0.0', '4': '255.255.0.0'})}
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(5)
|
||||
assert api.value.get_modified() == {'ip_admin_eth0.ip_admin_eth0': (
|
||||
'user',
|
||||
('192.168.230.146', "192.168.230.145", "192.168.230.146", "192.168.230.147", "192.168.230.148")),
|
||||
'ip_admin_eth0.netmask_admin_eth0': (
|
||||
{'0': 'user', '3': 'user', '4': 'user'},
|
||||
{'0': '255.255.0.0', '3': '255.255.0.0', '4': '255.255.0.0'})}
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(2)
|
||||
assert api.value.get_modified() == {'ip_admin_eth0.ip_admin_eth0': (
|
||||
'user',
|
||||
('192.168.230.146', "192.168.230.145", "192.168.230.147", "192.168.230.148")),
|
||||
'ip_admin_eth0.netmask_admin_eth0': (
|
||||
{'0': 'user', '2': 'user', '3': 'user'},
|
||||
{'0': '255.255.0.0', '2': '255.255.0.0', '3': '255.255.0.0'})}
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(2)
|
||||
assert api.value.get_modified() == {'ip_admin_eth0.ip_admin_eth0': ('user',
|
||||
('192.168.230.146',
|
||||
"192.168.230.145",
|
||||
"192.168.230.148")),
|
||||
'ip_admin_eth0.netmask_admin_eth0': ({'0': 'user', '2': 'user'},
|
||||
{'0': '255.255.0.0', '2': '255.255.0.0'})}
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(2)
|
||||
assert api.value.get_modified() == {'ip_admin_eth0.ip_admin_eth0': ('user',
|
||||
('192.168.230.146',
|
||||
"192.168.230.145")),
|
||||
'ip_admin_eth0.netmask_admin_eth0': ({'0': 'user'},
|
||||
{'0': '255.255.0.0'})}
|
||||
|
||||
|
||||
def test_values_with_master_owner():
|
||||
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)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
api = getapi(Config(maconfig))
|
||||
api.property.read_write()
|
||||
owner = api.owner.get()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
|
||||
|
||||
|
||||
def test_values_with_master_disabled():
|
||||
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)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
api = getapi(Config(maconfig))
|
||||
api.property.read_write()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set("192.168.230.145")
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0').property.add('disabled')
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
|
||||
|
||||
#delete with value in disabled var
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0').property.pop('disabled')
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set("192.168.230.145")
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0').property.add('disabled')
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
|
||||
|
||||
#append with value in disabled var
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0').property.pop('disabled')
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set("192.168.230.145")
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0').property.add('disabled')
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", '192.168.230.43'])
|
||||
|
||||
|
||||
def test_multi_non_valid_value():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
|
||||
maconfig = OptionDescription('toto', '', [ip_admin_eth0])
|
||||
api = getapi(Config(maconfig))
|
||||
api.property.read_write()
|
||||
api.option('ip_admin_eth0').value.set(['a'])
|
||||
raises(ValueError, "api.option('ip_admin_eth0').value.set([1])")
|
||||
|
||||
|
||||
def test_multi_master_default_slave():
|
||||
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", default_multi="255.255.255.0", multi=True)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
api = getapi(Config(maconfig))
|
||||
api.property.read_write()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
|
||||
|
||||
|
||||
def test_groups_with_master_get_modified_value():
|
||||
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)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
api = getapi(Config(maconfig))
|
||||
api.property.read_write()
|
||||
assert api.value.get_modified() == {}
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
|
||||
assert api.value.get_modified() == {'ip_admin_eth0.ip_admin_eth0': ('user', ('192.168.1.1',))}
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.255')
|
||||
assert api.value.get_modified() == {'ip_admin_eth0.ip_admin_eth0': ('user', ('192.168.1.1',)), 'ip_admin_eth0.netmask_admin_eth0': ({'0': 'user'}, {'0': '255.255.255.255'})}
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1', '192.168.1.1'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.255')
|
||||
assert api.value.get_modified() == {'ip_admin_eth0.ip_admin_eth0': ('user', ('192.168.1.1', '192.168.1.1')), 'ip_admin_eth0.netmask_admin_eth0': ({'0': 'user', '1': 'user'}, {'0': '255.255.255.255', '1': '255.255.255.255'})}
|
||||
|
|
@ -1,258 +0,0 @@
|
|||
# coding: utf-8
|
||||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
|
||||
from py.test import raises
|
||||
|
||||
from tiramisu import IntOption, UnicodeOption, OptionDescription, Config, getapi
|
||||
from tiramisu.error import PropertiesOptionError
|
||||
|
||||
|
||||
def make_description():
|
||||
u1 = IntOption('u1', '', properties=('frozen', 'mandatory', 'disabled', ))
|
||||
u2 = IntOption('u2', '', properties=('frozen', 'mandatory', 'disabled', ))
|
||||
return OptionDescription('od1', '', [u1, u2])
|
||||
|
||||
|
||||
def test_permissive():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
api.property.read_write()
|
||||
props = frozenset()
|
||||
try:
|
||||
api.option('u1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == {'disabled'}
|
||||
api.permissive.set(frozenset(['disabled']))
|
||||
props = frozenset()
|
||||
try:
|
||||
api.option('u1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == {'disabled'}
|
||||
api.property.add('permissive')
|
||||
api.option('u1').value.get()
|
||||
api.property.pop('permissive')
|
||||
props = frozenset()
|
||||
try:
|
||||
api.option('u1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == {'disabled'}
|
||||
|
||||
|
||||
def test_permissive_mandatory():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_only()
|
||||
props = frozenset()
|
||||
try:
|
||||
api.option('u1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == frozenset(['disabled'])
|
||||
api.permissive.set(frozenset(['mandatory', 'disabled']))
|
||||
api.property.add('permissive')
|
||||
api.option('u1').value.get()
|
||||
api.property.pop('permissive')
|
||||
try:
|
||||
api.option('u1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_permissive_frozen():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
api.permissive.set(frozenset(['frozen', 'disabled']))
|
||||
try:
|
||||
api.option('u1').value.set(1)
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == frozenset(['disabled'])
|
||||
api.property.add('permissive')
|
||||
api.option('u1').value.set(1)
|
||||
assert api.option('u1').value.get() == 1
|
||||
api.property.pop('permissive')
|
||||
try:
|
||||
api.option('u1').value.set(1)
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_invalid_permissive():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
raises(TypeError, "api.permissive.set(['frozen', 'disabled'])")
|
||||
|
||||
|
||||
def test_permissive_option():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
|
||||
props = frozenset()
|
||||
try:
|
||||
api.option('u1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == {'disabled'}
|
||||
props = frozenset()
|
||||
try:
|
||||
api.option('u2').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == {'disabled'}
|
||||
|
||||
api.option('u1').permissive.set(frozenset(['disabled']))
|
||||
props = frozenset()
|
||||
try:
|
||||
api.option('u1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == frozenset()
|
||||
props = frozenset()
|
||||
try:
|
||||
api.option('u2').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == {'disabled'}
|
||||
|
||||
api.property.add('permissive')
|
||||
api.option('u1').value.get()
|
||||
props = frozenset()
|
||||
try:
|
||||
api.option('u2').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == {'disabled'}
|
||||
|
||||
api.property.pop('permissive')
|
||||
props = frozenset()
|
||||
try:
|
||||
api.option('u1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == frozenset()
|
||||
props = frozenset()
|
||||
try:
|
||||
api.option('u2').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == {'disabled'}
|
||||
|
||||
|
||||
def test_permissive_option_cache():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
|
||||
props = frozenset()
|
||||
try:
|
||||
api.option('u1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == {'disabled'}
|
||||
props = frozenset()
|
||||
try:
|
||||
api.option('u2').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == {'disabled'}
|
||||
|
||||
api.option('u1').permissive.set(frozenset(['disabled']))
|
||||
props = frozenset()
|
||||
try:
|
||||
api.option('u1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == frozenset()
|
||||
props = frozenset()
|
||||
try:
|
||||
api.option('u2').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == {'disabled'}
|
||||
|
||||
api.property.add('permissive')
|
||||
api.option('u1').value.get()
|
||||
props = frozenset()
|
||||
try:
|
||||
api.option('u2').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == {'disabled'}
|
||||
|
||||
api.property.pop('permissive')
|
||||
props = frozenset()
|
||||
try:
|
||||
api.option('u1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == frozenset()
|
||||
props = frozenset()
|
||||
try:
|
||||
api.option('u2').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == {'disabled'}
|
||||
|
||||
|
||||
def test_permissive_option_mandatory():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_only()
|
||||
props = frozenset()
|
||||
try:
|
||||
api.option('u1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == frozenset(['disabled'])
|
||||
api.option('u1').permissive.set(frozenset(['mandatory', 'disabled']))
|
||||
api.property.add('permissive')
|
||||
api.option('u1').value.get()
|
||||
api.property.pop('permissive')
|
||||
try:
|
||||
api.option('u1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_permissive_option_frozen():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
api.option('u1').permissive.set(frozenset(['frozen', 'disabled']))
|
||||
api.option('u1').value.set(1)
|
||||
assert api.option('u1').value.get() == 1
|
||||
api.property.add('permissive')
|
||||
assert api.option('u1').value.get() == 1
|
||||
api.property.pop('permissive')
|
||||
assert api.option('u1').value.get() == 1
|
||||
|
||||
|
||||
def test_invalid_option_permissive():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
raises(TypeError, "api.option('u1').permissive.set(['frozen', 'disabled'])")
|
||||
|
||||
|
||||
def test_remove_option_permissive():
|
||||
var1 = UnicodeOption('var1', '', u'value', properties=('hidden',))
|
||||
od1 = OptionDescription('od1', '', [var1])
|
||||
rootod = OptionDescription('rootod', '', [od1])
|
||||
api = getapi(Config(rootod))
|
||||
api.property.read_write()
|
||||
raises(PropertiesOptionError, "api.option('od1.var1').value.get()")
|
||||
api.option('od1.var1').permissive.set(frozenset(['hidden']))
|
||||
assert api.option('od1.var1').value.get() == 'value'
|
||||
api.option('od1.var1').permissive.set(frozenset())
|
||||
raises(PropertiesOptionError, "api.option('od1.var1').value.get()")
|
||||
|
|
@ -1,880 +0,0 @@
|
|||
# coding: utf-8
|
||||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
|
||||
from copy import copy
|
||||
from tiramisu.setting import groups
|
||||
from tiramisu import setting
|
||||
setting.expires_time = 1
|
||||
from tiramisu import IPOption, OptionDescription, BoolOption, IntOption, StrOption, \
|
||||
MasterSlaves, Config, getapi
|
||||
from tiramisu.error import PropertiesOptionError, RequirementError
|
||||
from py.test import raises
|
||||
|
||||
|
||||
def test_requires():
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = IPOption('ip_address_service', '',
|
||||
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
||||
od = OptionDescription('service', '', [a, b])
|
||||
api = getapi(Config(od))
|
||||
api.property.read_write()
|
||||
api.option('ip_address_service').value.get()
|
||||
api.option('activate_service').value.set(False)
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == frozenset(['disabled'])
|
||||
api.option('activate_service').value.set(True)
|
||||
api.option('ip_address_service').value.get()
|
||||
|
||||
|
||||
def test_requires_with_requires():
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = IPOption('ip_address_service', '',
|
||||
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
||||
od = OptionDescription('service', '', [a, b])
|
||||
api = getapi(Config(od))
|
||||
api.property.read_write()
|
||||
api.option('ip_address_service').property.add('test')
|
||||
api.option('ip_address_service').value.get()
|
||||
api.option('activate_service').value.set(False)
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == frozenset(['disabled'])
|
||||
api.option('activate_service').value.set(True)
|
||||
api.option('ip_address_service').value.get()
|
||||
|
||||
|
||||
def test_requires_invalid():
|
||||
a = BoolOption('activate_service', '', True)
|
||||
a
|
||||
raises(ValueError, "IPOption('ip_address_service', '', requires='string')")
|
||||
raises(ValueError, "IPOption('ip_address_service', '', requires=[{'option': a, 'expected': False, 'action': 'disabled', 'unknown': True}])")
|
||||
raises(ValueError, "IPOption('ip_address_service', '', requires=[{'option': a, 'expected': False}])")
|
||||
raises(ValueError, "IPOption('ip_address_service', '', requires=[{'option': a, 'action': 'disabled'}])")
|
||||
raises(ValueError, "IPOption('ip_address_service', '', requires=[{'expected': False, 'action': 'disabled'}])")
|
||||
raises(ValueError, "IPOption('ip_address_service', '', requires=[{'option': a, 'expected': False, 'action': 'disabled', 'inverse': 'string'}])")
|
||||
raises(ValueError, "IPOption('ip_address_service', '', requires=[{'option': a, 'expected': False, 'action': 'disabled', 'transitive': 'string'}])")
|
||||
raises(ValueError, "IPOption('ip_address_service', '', requires=[{'option': a, 'expected': False, 'action': 'disabled', 'same_action': 'string'}])")
|
||||
raises(ValueError, "IPOption('ip_address_service', '', requires=[{'option': 'string', 'expected': False, 'action': 'disabled'}])")
|
||||
raises(ValueError, "IPOption('ip_address_service', '', requires=[{'option': a, 'expected': 'string', 'action': 'disabled'}])")
|
||||
|
||||
|
||||
def test_requires_same_action():
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = BoolOption('activate_service_web', '', True,
|
||||
requires=[{'option': a, 'expected': False, 'action': 'new'}])
|
||||
|
||||
d = IPOption('ip_address_service_web', '',
|
||||
requires=[{'option': b, 'expected': False,
|
||||
'action': 'disabled', 'inverse': False,
|
||||
'transitive': True, 'same_action': False}])
|
||||
od = OptionDescription('service', '', [a, b, d])
|
||||
api = getapi(Config(od))
|
||||
api.property.read_write()
|
||||
api.property.add('new')
|
||||
api.option('activate_service').value.get()
|
||||
api.option('activate_service_web').value.get()
|
||||
api.option('ip_address_service_web').value.get()
|
||||
api.option('activate_service').value.set(False)
|
||||
#
|
||||
props = []
|
||||
try:
|
||||
api.option('activate_service_web').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == frozenset(['new'])
|
||||
#
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service_web').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_multiple_requires():
|
||||
a = StrOption('activate_service', '')
|
||||
b = IPOption('ip_address_service', '',
|
||||
requires=[{'option': a, 'expected': 'yes', 'action': 'disabled'},
|
||||
{'option': a, 'expected': 'ok', 'action': 'disabled'}])
|
||||
od = OptionDescription('service', '', [a, b])
|
||||
api = getapi(Config(od))
|
||||
api.property.read_write()
|
||||
api.option('ip_address_service').value.get()
|
||||
api.option('activate_service').value.set('yes')
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == frozenset(['disabled'])
|
||||
|
||||
api.option('activate_service').value.set('ok')
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == frozenset(['disabled'])
|
||||
|
||||
api.option('activate_service').value.set('no')
|
||||
api.option('ip_address_service').value.get()
|
||||
|
||||
|
||||
def test_multiple_requires_cumulative():
|
||||
a = StrOption('activate_service', '')
|
||||
b = IPOption('ip_address_service', '',
|
||||
requires=[{'option': a, 'expected': 'yes', 'action': 'disabled'},
|
||||
{'option': a, 'expected': 'yes', 'action': 'hidden'}])
|
||||
od = OptionDescription('service', '', [a, b])
|
||||
api = getapi(Config(od))
|
||||
api.property.read_write()
|
||||
api.option('ip_address_service').value.get()
|
||||
api.option('activate_service').value.set('yes')
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert set(props) == set(['hidden', 'disabled'])
|
||||
|
||||
api.option('activate_service').value.set('ok')
|
||||
api.option('ip_address_service').value.get()
|
||||
|
||||
api.option('activate_service').value.set('no')
|
||||
api.option('ip_address_service').value.get()
|
||||
|
||||
|
||||
def test_multiple_requires_cumulative_inverse():
|
||||
a = StrOption('activate_service', '')
|
||||
b = IPOption('ip_address_service', '',
|
||||
requires=[{'option': a, 'expected': 'yes', 'action': 'disabled', 'inverse': True},
|
||||
{'option': a, 'expected': 'yes', 'action': 'hidden', 'inverse': True}])
|
||||
od = OptionDescription('service', '', [a, b])
|
||||
api = getapi(Config(od))
|
||||
api.property.read_write()
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert set(props) == set(['hidden', 'disabled'])
|
||||
api.option('activate_service').value.set('yes')
|
||||
api.option('ip_address_service').value.get()
|
||||
|
||||
api.option('activate_service').value.set('ok')
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert set(props) == set(['hidden', 'disabled'])
|
||||
|
||||
api.option('activate_service').value.set('no')
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert set(props) == set(['hidden', 'disabled'])
|
||||
|
||||
|
||||
def test_multiple_requires_inverse():
|
||||
a = StrOption('activate_service', '')
|
||||
b = IPOption('ip_address_service', '',
|
||||
requires=[{'option': a, 'expected': 'yes', 'action': 'disabled', 'inverse': True},
|
||||
{'option': a, 'expected': 'ok', 'action': 'disabled', 'inverse': True}])
|
||||
od = OptionDescription('service', '', [a, b])
|
||||
api = getapi(Config(od))
|
||||
api.property.read_write()
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == frozenset(['disabled'])
|
||||
|
||||
api.option('activate_service').value.set('yes')
|
||||
api.option('ip_address_service').value.get()
|
||||
|
||||
api.option('activate_service').value.set('ok')
|
||||
api.option('ip_address_service').value.get()
|
||||
|
||||
api.option('activate_service').value.set('no')
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_requires_transitive():
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = BoolOption('activate_service_web', '', True,
|
||||
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
||||
|
||||
d = IPOption('ip_address_service_web', '',
|
||||
requires=[{'option': b, 'expected': False, 'action': 'disabled'}])
|
||||
od = OptionDescription('service', '', [a, b, d])
|
||||
api = getapi(Config(od))
|
||||
api.property.read_write()
|
||||
api.option('activate_service').value.get()
|
||||
api.option('activate_service_web').value.get()
|
||||
api.option('ip_address_service_web').value.get()
|
||||
api.option('activate_service').value.set(False)
|
||||
#
|
||||
props = []
|
||||
try:
|
||||
api.option('activate_service_web').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == frozenset(['disabled'])
|
||||
#
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service_web').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_requires_transitive_owner():
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = BoolOption('activate_service_web', '', True,
|
||||
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
||||
|
||||
d = IPOption('ip_address_service_web', '',
|
||||
requires=[{'option': b, 'expected': False, 'action': 'disabled'}])
|
||||
od = OptionDescription('service', '', [a, b, d])
|
||||
api = getapi(Config(od))
|
||||
api.property.read_write()
|
||||
api.option('activate_service').value.get()
|
||||
api.option('activate_service_web').value.get()
|
||||
api.option('ip_address_service_web').value.get()
|
||||
#no more default value
|
||||
api.option('ip_address_service_web').value.set('1.1.1.1')
|
||||
api.option('activate_service').value.set(False)
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service_web').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_requires_transitive_bis():
|
||||
a = BoolOption('activate_service', '', True)
|
||||
abis = BoolOption('activate_service_bis', '', True)
|
||||
b = BoolOption('activate_service_web', '', True,
|
||||
requires=[{'option': a, 'expected': True, 'action': 'disabled', 'inverse': True}])
|
||||
|
||||
d = IPOption('ip_address_service_web', '',
|
||||
requires=[{'option': b, 'expected': True, 'action': 'disabled', 'inverse': True}])
|
||||
od = OptionDescription('service', '', [a, abis, b, d])
|
||||
api = getapi(Config(od))
|
||||
api.property.read_write()
|
||||
#
|
||||
api.option('activate_service_web').value.get()
|
||||
api.option('ip_address_service_web').value.get()
|
||||
api.option('activate_service').value.set(False)
|
||||
#
|
||||
props = []
|
||||
try:
|
||||
api.option('activate_service_web').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == frozenset(['disabled'])
|
||||
#
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service_web').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_requires_transitive_hidden_disabled():
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = BoolOption('activate_service_web', '', True,
|
||||
requires=[{'option': a, 'expected': False, 'action': 'hidden'}])
|
||||
d = IPOption('ip_address_service_web', '',
|
||||
requires=[{'option': b, 'expected': False, 'action': 'disabled'}])
|
||||
od = OptionDescription('service', '', [a, b, d])
|
||||
api = getapi(Config(od))
|
||||
api.property.read_write()
|
||||
api.option('activate_service').value.get()
|
||||
api.option('activate_service_web').value.get()
|
||||
api.option('ip_address_service_web').value.get()
|
||||
api.option('activate_service').value.set(False)
|
||||
#
|
||||
props = []
|
||||
try:
|
||||
api.option('activate_service_web').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == frozenset(['hidden'])
|
||||
raises(RequirementError, "api.option('ip_address_service_web').value.get()")
|
||||
|
||||
|
||||
def test_requires_transitive_hidden_disabled_multiple():
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = BoolOption('activate_service_web', '', True,
|
||||
requires=[{'option': a, 'expected': False, 'action': 'hidden'},
|
||||
{'option': a, 'expected': False, 'action': 'disabled'}])
|
||||
d = IPOption('ip_address_service_web', '',
|
||||
requires=[{'option': b, 'expected': False, 'action': 'mandatory'}])
|
||||
od = OptionDescription('service', '', [a, b, d])
|
||||
api = getapi(Config(od))
|
||||
api.property.read_write()
|
||||
api.option('activate_service').value.get()
|
||||
api.option('activate_service_web').value.get()
|
||||
api.option('ip_address_service_web').value.get()
|
||||
api.option('activate_service').value.set(False)
|
||||
#
|
||||
props = []
|
||||
try:
|
||||
api.option('activate_service_web').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert set(props) == {'disabled', 'hidden'}
|
||||
raises(RequirementError, "api.option('ip_address_service_web').value.get()")
|
||||
|
||||
|
||||
def test_requires_not_transitive():
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = BoolOption('activate_service_web', '', True,
|
||||
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
||||
d = IPOption('ip_address_service_web', '',
|
||||
requires=[{'option': b, 'expected': False,
|
||||
'action': 'disabled', 'transitive': False}])
|
||||
od = OptionDescription('service', '', [a, b, d])
|
||||
api = getapi(Config(od))
|
||||
api.property.read_write()
|
||||
api.option('activate_service').value.get()
|
||||
api.option('activate_service_web').value.get()
|
||||
api.option('ip_address_service_web').value.get()
|
||||
api.option('activate_service').value.set(False)
|
||||
#
|
||||
props = []
|
||||
try:
|
||||
api.option('activate_service_web').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == frozenset(['disabled'])
|
||||
#
|
||||
api.option('ip_address_service_web').value.get()
|
||||
|
||||
|
||||
def test_requires_not_transitive_not_same_action():
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = BoolOption('activate_service_web', '', True,
|
||||
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
||||
d = IPOption('ip_address_service_web', '',
|
||||
requires=[{'option': b, 'expected': False,
|
||||
'action': 'hidden', 'transitive': False}])
|
||||
od = OptionDescription('service', '', [a, b, d])
|
||||
api = getapi(Config(od))
|
||||
api.property.read_write()
|
||||
api.option('activate_service').value.get()
|
||||
api.option('activate_service_web').value.get()
|
||||
api.option('ip_address_service_web').value.get()
|
||||
api.option('activate_service').value.set(False)
|
||||
#
|
||||
props = []
|
||||
try:
|
||||
api.option('activate_service_web').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == frozenset(['disabled'])
|
||||
#
|
||||
raises(RequirementError, "api.option('ip_address_service_web').value.get()")
|
||||
|
||||
|
||||
def test_requires_None():
|
||||
a = BoolOption('activate_service', '')
|
||||
b = IPOption('ip_address_service', '',
|
||||
requires=[{'option': a, 'expected': None, 'action': 'disabled'}])
|
||||
od = OptionDescription('service', '', [a, b])
|
||||
api = getapi(Config(od))
|
||||
api.property.read_write()
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == frozenset(['disabled'])
|
||||
api.option('activate_service').value.set(False)
|
||||
api.option('ip_address_service').value.get()
|
||||
|
||||
|
||||
def test_requires_multi_disabled():
|
||||
a = BoolOption('activate_service', '')
|
||||
b = IntOption('num_service', '')
|
||||
c = IPOption('ip_address_service', '',
|
||||
requires=[{'option': a, 'expected': True, 'action': 'disabled'},
|
||||
{'option': b, 'expected': 1, 'action': 'disabled'}])
|
||||
od = OptionDescription('service', '', [a, b, c])
|
||||
api = getapi(Config(od))
|
||||
api.property.read_write()
|
||||
|
||||
api.option('ip_address_service').value.get()
|
||||
|
||||
api.option('activate_service').value.set(True)
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == frozenset(['disabled'])
|
||||
|
||||
api.option('activate_service').value.set(False)
|
||||
api.option('ip_address_service').value.get()
|
||||
|
||||
api.option('num_service').value.set(1)
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == frozenset(['disabled'])
|
||||
|
||||
api.option('activate_service').value.set(True)
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_requires_multi_disabled_new_format():
|
||||
a = BoolOption('activate_service', '')
|
||||
b = IntOption('num_service', '')
|
||||
c = IPOption('ip_address_service', '',
|
||||
requires=[{'expected': [{'option': a, 'value': True}, {'option': b, 'value': 1}], 'action': 'disabled'}])
|
||||
od = OptionDescription('service', '', [a, b, c])
|
||||
api = getapi(Config(od))
|
||||
api.property.read_write()
|
||||
|
||||
api.option('ip_address_service').value.get()
|
||||
|
||||
api.option('activate_service').value.set(True)
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == frozenset(['disabled'])
|
||||
|
||||
api.option('activate_service').value.set(False)
|
||||
api.option('ip_address_service').value.get()
|
||||
|
||||
api.option('num_service').value.set(1)
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == frozenset(['disabled'])
|
||||
|
||||
api.option('activate_service').value.set(True)
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_requires_unknown_operator():
|
||||
a = BoolOption('activate_service', '')
|
||||
b = IntOption('num_service', '')
|
||||
raises(ValueError, """IPOption('ip_address_service', '',
|
||||
requires=[{'expected': [{'option': a, 'value': True}, {'option': b, 'value': 1}],
|
||||
'action': 'disabled', 'operator': 'unknown'}])""")
|
||||
|
||||
|
||||
def test_requires_keys():
|
||||
a = BoolOption('activate_service', '')
|
||||
b = IntOption('num_service', '')
|
||||
raises(ValueError, """IPOption('ip_address_service', '',
|
||||
requires=[{'expected': [{'option': a, 'value2': True}, {'option': b, 'value': 1}],
|
||||
'action': 'disabled', 'operator': 'and'}])""")
|
||||
|
||||
|
||||
def test_requires_unvalid():
|
||||
a = BoolOption('activate_service', '')
|
||||
b = IntOption('num_service', '')
|
||||
raises(ValueError, """IPOption('ip_address_service', '',
|
||||
requires=[{'expected': [{'option': a, 'value': 'unvalid'}, {'option': b, 'value': 1}],
|
||||
'action': 'disabled', 'operator': 'and'}])""")
|
||||
|
||||
|
||||
def test_requires_multi_disabled_new_format_and():
|
||||
a = BoolOption('activate_service', '')
|
||||
b = IntOption('num_service', '')
|
||||
c = IPOption('ip_address_service', '',
|
||||
requires=[{'expected': [{'option': a, 'value': True}, {'option': b, 'value': 1}], 'action': 'disabled', 'operator': 'and'}])
|
||||
od = OptionDescription('service', '', [a, b, c])
|
||||
api = getapi(Config(od))
|
||||
api.property.read_write()
|
||||
|
||||
api.option('ip_address_service').value.get()
|
||||
|
||||
api.option('activate_service').value.set(True)
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == []
|
||||
|
||||
api.option('activate_service').value.set(False)
|
||||
api.option('ip_address_service').value.get()
|
||||
|
||||
api.option('num_service').value.set(1)
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == []
|
||||
|
||||
api.option('activate_service').value.set(True)
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_requires_multi_disabled_new_format_and_2():
|
||||
a = BoolOption('activate_service', '')
|
||||
b = IntOption('num_service', '')
|
||||
c = IPOption('ip_address_service', '',
|
||||
requires=[{'expected': [{'option': a, 'value': True}, {'option': b, 'value': 1}], 'action': 'disabled', 'operator': 'and'},
|
||||
{'expected': [{'option': a, 'value': False}, {'option': b, 'value': 1}], 'action': 'expert'}])
|
||||
od = OptionDescription('service', '', [a, b, c])
|
||||
api = getapi(Config(od))
|
||||
api.property.add('expert')
|
||||
api.property.read_write()
|
||||
api.option('ip_address_service').value.get()
|
||||
|
||||
api.option('activate_service').value.set(True)
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == []
|
||||
|
||||
api.option('activate_service').value.set(False)
|
||||
api.option('num_service').value.set(1)
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == frozenset(['expert'])
|
||||
|
||||
api.option('activate_service').value.set(True)
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == frozenset(['disabled', 'expert'])
|
||||
|
||||
|
||||
def test_requires_multi_disabled_inverse():
|
||||
a = BoolOption('activate_service', '')
|
||||
b = IntOption('num_service', '')
|
||||
c = IPOption('ip_address_service', '',
|
||||
requires=[{'option': a, 'expected': True,
|
||||
'action': 'disabled', 'inverse': True},
|
||||
{'option': b, 'expected': 1,
|
||||
'action': 'disabled', 'inverse': True}])
|
||||
od = OptionDescription('service', '', [a, b, c])
|
||||
api = getapi(Config(od))
|
||||
api.property.read_write()
|
||||
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == frozenset(['disabled'])
|
||||
|
||||
api.option('activate_service').value.set(True)
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == frozenset(['disabled'])
|
||||
|
||||
api.option('activate_service').value.set(False)
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == frozenset(['disabled'])
|
||||
|
||||
api.option('num_service').value.set(1)
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == frozenset(['disabled'])
|
||||
|
||||
api.option('activate_service').value.set(True)
|
||||
api.option('ip_address_service').value.get()
|
||||
|
||||
|
||||
def test_requires_multi_disabled_2():
|
||||
a = BoolOption('a', '')
|
||||
b = BoolOption('b', '')
|
||||
c = BoolOption('c', '')
|
||||
d = BoolOption('d', '')
|
||||
e = BoolOption('e', '')
|
||||
f = BoolOption('f', '')
|
||||
g = BoolOption('g', '')
|
||||
h = BoolOption('h', '')
|
||||
i = BoolOption('i', '')
|
||||
j = BoolOption('j', '')
|
||||
k = BoolOption('k', '')
|
||||
l = BoolOption('l', '')
|
||||
m = BoolOption('m', '')
|
||||
list_bools = [a, b, c, d, e, f, g, h, i, j, k, l, m]
|
||||
requires = []
|
||||
for boo in list_bools:
|
||||
requires.append({'option': boo, 'expected': True, 'action': 'disabled'})
|
||||
z = IPOption('z', '', requires=requires)
|
||||
y = copy(list_bools)
|
||||
y.append(z)
|
||||
od = OptionDescription('service', '', y)
|
||||
api = getapi(Config(od))
|
||||
api.property.read_write()
|
||||
|
||||
api.option('z').value.get()
|
||||
for boo in list_bools:
|
||||
api.option(boo.impl_getname()).value.set(True)
|
||||
props = []
|
||||
try:
|
||||
api.option('z').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == frozenset(['disabled'])
|
||||
for boo in list_bools:
|
||||
api.option(boo.impl_getname()).value.set(False)
|
||||
if boo == m:
|
||||
api.option('z').value.get()
|
||||
else:
|
||||
props = []
|
||||
try:
|
||||
api.option('z').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_requires_multi_disabled_inverse_2():
|
||||
a = BoolOption('a', '')
|
||||
b = BoolOption('b', '')
|
||||
c = BoolOption('c', '')
|
||||
d = BoolOption('d', '')
|
||||
e = BoolOption('e', '')
|
||||
f = BoolOption('f', '')
|
||||
g = BoolOption('g', '')
|
||||
h = BoolOption('h', '')
|
||||
i = BoolOption('i', '')
|
||||
j = BoolOption('j', '')
|
||||
k = BoolOption('k', '')
|
||||
l = BoolOption('l', '')
|
||||
m = BoolOption('m', '')
|
||||
list_bools = [a, b, c, d, e, f, g, h, i, j, k, l, m]
|
||||
requires = []
|
||||
for boo in list_bools:
|
||||
requires.append({'option': boo, 'expected': True, 'action': 'disabled',
|
||||
'inverse': True})
|
||||
z = IPOption('z', '', requires=requires)
|
||||
y = copy(list_bools)
|
||||
y.append(z)
|
||||
od = OptionDescription('service', '', y)
|
||||
api = getapi(Config(od))
|
||||
api.property.read_write()
|
||||
|
||||
props = []
|
||||
try:
|
||||
api.option('z').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == frozenset(['disabled'])
|
||||
for boo in list_bools:
|
||||
api.option(boo.impl_getname()).value.set(True)
|
||||
if boo == m:
|
||||
api.option('z').value.get()
|
||||
else:
|
||||
props = []
|
||||
try:
|
||||
api.option('z').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == frozenset(['disabled'])
|
||||
for boo in list_bools:
|
||||
api.option(boo.impl_getname()).value.set(False)
|
||||
props = []
|
||||
try:
|
||||
api.option('z').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_requires_requirement_append():
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = IPOption('ip_address_service', '',
|
||||
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
||||
od = OptionDescription('service', '', [a, b])
|
||||
api = getapi(Config(od))
|
||||
api.property.read_write()
|
||||
api.property.get()
|
||||
api.option('ip_address_service').property.get()
|
||||
raises(ValueError, "api.option('ip_address_service').property.add('disabled')")
|
||||
api.option('activate_service').value.set(False)
|
||||
# disabled is now set, test to remove disabled before store in storage
|
||||
api.option('ip_address_service').property.add("test")
|
||||
|
||||
|
||||
def test_requires_different_inverse():
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = IPOption('ip_address_service', '', requires=[
|
||||
{'option': a, 'expected': True, 'action': 'disabled', 'inverse': True},
|
||||
{'option': a, 'expected': True, 'action': 'disabled', 'inverse': False}])
|
||||
od = OptionDescription('service', '', [a, b])
|
||||
api = getapi(Config(od))
|
||||
api.property.read_write()
|
||||
raises(PropertiesOptionError, "api.option('ip_address_service').value.get()")
|
||||
api.option('activate_service').value.set(False)
|
||||
raises(PropertiesOptionError, "api.option('ip_address_service').value.get()")
|
||||
|
||||
|
||||
def test_requires_different_inverse_unicode():
|
||||
a = BoolOption('activate_service', '', True)
|
||||
d = StrOption('activate_other_service', '', 'val2')
|
||||
b = IPOption('ip_address_service', '', requires=[
|
||||
{'option': a, 'expected': True, 'action': 'disabled', 'inverse': True},
|
||||
{'option': d, 'expected': 'val1', 'action': 'disabled', 'inverse': False}])
|
||||
od = OptionDescription('service', '', [a, d, b])
|
||||
api = getapi(Config(od))
|
||||
api.property.read_write()
|
||||
assert api.option('ip_address_service').value.get() == None
|
||||
api.option('activate_service').value.set(False)
|
||||
raises(PropertiesOptionError, "api.option('ip_address_service').value.get()")
|
||||
api.option('activate_service').value.set(True)
|
||||
assert api.option('ip_address_service').value.get() == None
|
||||
api.option('activate_other_service').value.set('val1')
|
||||
raises(PropertiesOptionError, "api.option('ip_address_service').value.get()")
|
||||
api.option('activate_service').value.set(False)
|
||||
raises(PropertiesOptionError, "api.option('ip_address_service').value.get()")
|
||||
|
||||
|
||||
def test_requires_recursive_path():
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = IPOption('ip_address_service', '',
|
||||
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
||||
od1 = OptionDescription('service', '', [a, b], requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
||||
od = OptionDescription('base', '', [od1])
|
||||
api = getapi(Config(od))
|
||||
api.property.read_write()
|
||||
raises(RequirementError, "api.option('service.a').value.get()")
|
||||
|
||||
|
||||
def test_optiondescription_requires():
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = BoolOption('ip_address_service', '', multi=True)
|
||||
a, b
|
||||
OptionDescription('service', '', [b], requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
||||
|
||||
|
||||
def test_optiondescription_requires_multi():
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = IPOption('ip_address_service', '', multi=True)
|
||||
a, b
|
||||
raises(ValueError, "OptionDescription('service', '', [a], requires=[{'option': b, 'expected': False, 'action': 'disabled'}])")
|
||||
|
||||
|
||||
def test_properties_conflict():
|
||||
a = BoolOption('activate_service', '', True)
|
||||
a
|
||||
raises(ValueError, "IPOption('ip_address_service', '', properties=('disabled',), requires=[{'option': a, 'expected': False, 'action': 'disabled'}])")
|
||||
raises(ValueError, "od1 = OptionDescription('service', '', [a], properties=('disabled',), requires=[{'option': a, 'expected': False, 'action': 'disabled'}])")
|
||||
|
||||
|
||||
def test_master_slave_requires():
|
||||
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,
|
||||
requires=[{'option': ip_admin_eth0, 'expected': '192.168.1.1', 'action': 'disabled'}])
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
api = getapi(Config(maconfig))
|
||||
api.property.read_write()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
|
||||
#
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1'])
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()")
|
||||
#
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.2'])
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() is None
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.255')
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.255'
|
||||
#
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1'])
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()")
|
||||
|
||||
|
||||
def test_master_slave_requires_no_master():
|
||||
activate = BoolOption('activate', "Activer l'accès au réseau", True)
|
||||
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,
|
||||
requires=[{'option': activate, 'expected': False, 'action': 'disabled'}])
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [activate, interface1])
|
||||
api = getapi(Config(maconfig))
|
||||
api.property.read_write()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
|
||||
api.option('activate').value.set(False)
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1'])
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2', '192.168.1.1']
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()")
|
||||
api.option('activate').value.set(True)
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() is None
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.255')
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.255'
|
||||
api.option('activate').value.set(False)
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()")
|
||||
|
|
@ -1,171 +0,0 @@
|
|||
## coding: utf-8
|
||||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
|
||||
from py.test import raises
|
||||
|
||||
from tiramisu.setting import ConfigBag
|
||||
from tiramisu.config import Config, SubConfig
|
||||
from tiramisu.option import ChoiceOption, BoolOption, IntOption, FloatOption,\
|
||||
StrOption, SymLinkOption, UnicodeOption, IPOption, OptionDescription, \
|
||||
PortOption, NetworkOption, NetmaskOption, DomainnameOption, EmailOption, \
|
||||
URLOption, FilenameOption
|
||||
|
||||
|
||||
def test_slots_option():
|
||||
c = ChoiceOption('a', '', ('a',))
|
||||
raises(AttributeError, "c.x = 1")
|
||||
c = BoolOption('a', '')
|
||||
raises(AttributeError, "c.x = 1")
|
||||
c = IntOption('a', '')
|
||||
raises(AttributeError, "c.x = 1")
|
||||
c = FloatOption('a', '')
|
||||
raises(AttributeError, "c.x = 1")
|
||||
c = StrOption('a', '')
|
||||
raises(AttributeError, "c.x = 1")
|
||||
c = SymLinkOption('b', c)
|
||||
raises(AttributeError, "c.x = 1")
|
||||
c = UnicodeOption('a', '')
|
||||
raises(AttributeError, "c.x = 1")
|
||||
c = IPOption('a', '')
|
||||
raises(AttributeError, "c.x = 1")
|
||||
c = OptionDescription('a', '', [])
|
||||
raises(AttributeError, "c.x = 1")
|
||||
c = PortOption('a', '')
|
||||
raises(AttributeError, "c.x = 1")
|
||||
c = NetworkOption('a', '')
|
||||
raises(AttributeError, "c.x = 1")
|
||||
c = NetmaskOption('a', '')
|
||||
raises(AttributeError, "c.x = 1")
|
||||
c = DomainnameOption('a', '')
|
||||
raises(AttributeError, "c.x = 1")
|
||||
c = EmailOption('a', '')
|
||||
raises(AttributeError, "c.x = 1")
|
||||
c = URLOption('a', '')
|
||||
raises(AttributeError, "c.x = 1")
|
||||
c = FilenameOption('a', '')
|
||||
raises(AttributeError, "c.x = 1")
|
||||
|
||||
|
||||
def test_slots_option_readonly():
|
||||
a = ChoiceOption('a', '', ('a',))
|
||||
b = BoolOption('b', '')
|
||||
c = IntOption('c', '')
|
||||
d = FloatOption('d', '')
|
||||
e = StrOption('e', '')
|
||||
g = UnicodeOption('g', '')
|
||||
h = IPOption('h', '')
|
||||
i = PortOption('i', '')
|
||||
j = NetworkOption('j', '')
|
||||
k = NetmaskOption('k', '')
|
||||
l = DomainnameOption('l', '')
|
||||
o = EmailOption('o', '')
|
||||
p = URLOption('p', '')
|
||||
q = FilenameOption('q', '')
|
||||
m = OptionDescription('m', '', [a, b, c, d, e, g, h, i, j, k, l, o, p, q])
|
||||
a._requires = (((a,),),)
|
||||
b._requires = (((a,),),)
|
||||
c._requires = (((a,),),)
|
||||
d._requires = (((a,),),)
|
||||
e._requires = (((a,),),)
|
||||
g._requires = (((a,),),)
|
||||
h._requires = (((a,),),)
|
||||
i._requires = (((a,),),)
|
||||
j._requires = (((a,),),)
|
||||
k._requires = (((a,),),)
|
||||
l._requires = (((a,),),)
|
||||
m._requires = (((a,),),)
|
||||
o._requires = (((a,),),)
|
||||
p._requires = (((a,),),)
|
||||
q._requires = (((a,),),)
|
||||
Config(m)
|
||||
raises(AttributeError, "a._requires = 'a'")
|
||||
raises(AttributeError, "b._requires = 'b'")
|
||||
raises(AttributeError, "c._requires = 'c'")
|
||||
raises(AttributeError, "d._requires = 'd'")
|
||||
raises(AttributeError, "e._requires = 'e'")
|
||||
raises(AttributeError, "g._requires = 'g'")
|
||||
raises(AttributeError, "h._requires = 'h'")
|
||||
raises(AttributeError, "i._requires = 'i'")
|
||||
raises(AttributeError, "j._requires = 'j'")
|
||||
raises(AttributeError, "k._requires = 'k'")
|
||||
raises(AttributeError, "l._requires = 'l'")
|
||||
raises(AttributeError, "m._requires = 'm'")
|
||||
raises(AttributeError, "o._requires = 'o'")
|
||||
raises(AttributeError, "p._requires = 'p'")
|
||||
raises(AttributeError, "q._requires = 'q'")
|
||||
|
||||
|
||||
def test_slots_option_readonly_name():
|
||||
a = ChoiceOption('a', '', ('a',))
|
||||
b = BoolOption('b', '')
|
||||
c = IntOption('c', '')
|
||||
d = FloatOption('d', '')
|
||||
e = StrOption('e', '')
|
||||
f = SymLinkOption('f', c)
|
||||
g = UnicodeOption('g', '')
|
||||
h = IPOption('h', '')
|
||||
i = PortOption('i', '')
|
||||
j = NetworkOption('j', '')
|
||||
k = NetmaskOption('k', '')
|
||||
l = DomainnameOption('l', '')
|
||||
o = DomainnameOption('o', '')
|
||||
p = DomainnameOption('p', '')
|
||||
q = DomainnameOption('q', '')
|
||||
m = OptionDescription('m', '', [a, b, c, d, e, f, g, h, i, j, k, l, o, p, q])
|
||||
m
|
||||
raises(AttributeError, "a._name = 'a'")
|
||||
raises(AttributeError, "b._name = 'b'")
|
||||
raises(AttributeError, "c._name = 'c'")
|
||||
raises(AttributeError, "d._name = 'd'")
|
||||
raises(AttributeError, "e._name = 'e'")
|
||||
raises(AttributeError, "f._name = 'f'")
|
||||
raises(AttributeError, "g._name = 'g'")
|
||||
raises(AttributeError, "h._name = 'h'")
|
||||
raises(AttributeError, "i._name = 'i'")
|
||||
raises(AttributeError, "j._name = 'j'")
|
||||
raises(AttributeError, "k._name = 'k'")
|
||||
raises(AttributeError, "l._name = 'l'")
|
||||
raises(AttributeError, "m._name = 'm'")
|
||||
raises(AttributeError, "o._name = 'o'")
|
||||
raises(AttributeError, "p._name = 'p'")
|
||||
raises(AttributeError, "q._name = 'q'")
|
||||
|
||||
|
||||
#def test_slots_description():
|
||||
# # __slots__ for OptionDescription should be complete for __getattr__
|
||||
# slots = set()
|
||||
# for subclass in OptionDescription.__mro__:
|
||||
# if subclass is not object:
|
||||
# slots.update(subclass.__slots__)
|
||||
# assert slots == set(OptionDescription.__slots__)
|
||||
|
||||
|
||||
def test_slots_config():
|
||||
od1 = OptionDescription('a', '', [])
|
||||
od2 = OptionDescription('a', '', [od1])
|
||||
c = Config(od2)
|
||||
raises(AttributeError, "c.x = 1")
|
||||
raises(AttributeError, "c.cfgimpl_x = 1")
|
||||
sc = c.getattr('a', None, ConfigBag(c))
|
||||
assert isinstance(sc, SubConfig)
|
||||
raises(AttributeError, "sc.x = 1")
|
||||
raises(AttributeError, "sc.cfgimpl_x = 1")
|
||||
|
||||
|
||||
def test_slots_setting():
|
||||
od1 = OptionDescription('a', '', [])
|
||||
od2 = OptionDescription('a', '', [od1])
|
||||
c = Config(od2)
|
||||
s = c.cfgimpl_get_settings()
|
||||
s
|
||||
raises(AttributeError, "s.x = 1")
|
||||
|
||||
|
||||
def test_slots_value():
|
||||
od1 = OptionDescription('a', '', [])
|
||||
od2 = OptionDescription('a', '', [od1])
|
||||
c = Config(od2)
|
||||
v = c.cfgimpl_get_values()
|
||||
v
|
||||
raises(AttributeError, "v.x = 1")
|
||||
|
|
@ -1,232 +0,0 @@
|
|||
#from autopath import do_autopath
|
||||
#do_autopath()
|
||||
#
|
||||
from tiramisu.option import BoolOption, UnicodeOption, SymLinkOption, \
|
||||
OptionDescription, DynOptionDescription
|
||||
from tiramisu.config import Config
|
||||
from pickle import dumps
|
||||
from py.test import raises
|
||||
import sys
|
||||
|
||||
|
||||
def _get_slots(opt):
|
||||
slots = set()
|
||||
for subclass in opt.__class__.__mro__:
|
||||
if subclass is not object and '__slots__' in dir(subclass):
|
||||
slots.update(subclass.__slots__)
|
||||
return slots
|
||||
|
||||
|
||||
def _no_state(opt):
|
||||
for attr in _get_slots(opt):
|
||||
if 'state' in attr:
|
||||
try:
|
||||
getattr(opt, attr)
|
||||
except:
|
||||
pass
|
||||
else:
|
||||
raise Exception('opt should have already attribute {0}'.format(attr))
|
||||
|
||||
|
||||
def _diff_opt(opt1, opt2):
|
||||
attr1 = set(_get_slots(opt1))
|
||||
attr2 = set(_get_slots(opt2))
|
||||
diff1 = attr1 - attr2
|
||||
diff2 = attr2 - attr1
|
||||
if diff1 != set():
|
||||
raise Exception('more attribute in opt1 {0}'.format(list(diff1)))
|
||||
if diff2 != set():
|
||||
raise Exception('more attribute in opt2 {0}'.format(list(diff2)))
|
||||
for attr in attr1:
|
||||
if attr in ['_cache_paths', '_cache_consistencies']:
|
||||
continue
|
||||
err1 = False
|
||||
err2 = False
|
||||
val1 = None
|
||||
val2 = None
|
||||
try:
|
||||
val1 = getattr(opt1, attr)
|
||||
msg1 = "exists"
|
||||
tval = val1
|
||||
except:
|
||||
err1 = True
|
||||
msg1 = "not exists"
|
||||
|
||||
try:
|
||||
val2 = getattr(opt2, attr)
|
||||
msg2 = "exists"
|
||||
tval = val2
|
||||
except:
|
||||
err2 = True
|
||||
msg2 = "not exists"
|
||||
|
||||
if not err1 == err2:
|
||||
raise ValueError("{0} {1} before but {2} after for {3}: {4}".format(attr, msg1, msg2, opt1.impl_getname(), tval))
|
||||
if val1 is None:
|
||||
assert val1 == val2
|
||||
elif attr == '_children':
|
||||
assert val1[0] == val2[0]
|
||||
for index, _opt in enumerate(val1[1]):
|
||||
assert _opt._name == val2[1][index]._name
|
||||
elif attr == '_requires':
|
||||
if val1 == val2 == []:
|
||||
pass
|
||||
else:
|
||||
for idx1, req1 in enumerate(val1):
|
||||
for idx2, req2 in enumerate(val1[idx1]):
|
||||
for idx3, req3 in enumerate(val1[idx1][idx2][0]):
|
||||
assert val1[idx1][idx2][0][idx3][0].impl_getname() == val2[idx1][idx2][0][idx3][0].impl_getname()
|
||||
assert val1[idx1][idx2][0][idx3][1] == val2[idx1][idx2][0][idx3][1]
|
||||
assert val1[idx1][idx2][1:] == val2[idx1][idx2][1:], '{} - {}\n{} - {}'.format(val1, val2, val1[0][0][1:], val2[0][0][1:])
|
||||
elif attr == '_opt':
|
||||
assert val1._name == val2._name
|
||||
elif attr == '_consistencies':
|
||||
# dict is only a cache
|
||||
if isinstance(val1, list):
|
||||
for index, consistency in enumerate(val1):
|
||||
assert consistency[0] == val2[index][0]
|
||||
for idx, opt in enumerate(consistency[1]):
|
||||
assert opt._name == val2[index][1][idx]._name
|
||||
elif attr == '_val_call':
|
||||
for idx, v in enumerate(val1):
|
||||
if v is None:
|
||||
assert val2[idx] is None
|
||||
else:
|
||||
assert v[0] == val2[idx][0]
|
||||
if len(v) == 2:
|
||||
if v[1] is not None:
|
||||
for key, values in v[1].items():
|
||||
for i, value in enumerate(values):
|
||||
if isinstance(value, tuple) and value[0] is not None:
|
||||
assert v[1][key][i][0].impl_getname() == val2[idx][1][key][i][0].impl_getname()
|
||||
assert v[1][key][i][1] == val2[idx][1][key][i][1]
|
||||
else:
|
||||
assert v[1][key][i] == val2[idx][1][key][i]
|
||||
else:
|
||||
assert v[1] == val2[idx][1]
|
||||
elif attr == '_master_slaves':
|
||||
assert val1._p_._sm_getmaster().impl_getname() == val2._p_._sm_getmaster().impl_getname()
|
||||
sval1 = [opt.impl_getname() for opt in val1._p_._sm_getslaves()]
|
||||
sval2 = [opt.impl_getname() for opt in val2._p_._sm_getslaves()]
|
||||
assert sval1 == sval2
|
||||
elif attr == '_subdyn':
|
||||
try:
|
||||
assert val1.impl_getname() == val2.impl_getname()
|
||||
except AttributeError:
|
||||
assert val1 == val2
|
||||
elif attr == '_dependencies':
|
||||
assert len(val1) == len(val2), "_dependencies has not same len: {} - {}".format(val1, val2)
|
||||
lst1 = []
|
||||
lst2 = []
|
||||
for idx, val in enumerate(val1):
|
||||
if isinstance(val, MasterSlaves):
|
||||
lst1.append(val._p_.master.impl_getname())
|
||||
else:
|
||||
lst1.append(val.impl_getname())
|
||||
for idx, val in enumerate(val2):
|
||||
if isinstance(val, MasterSlaves):
|
||||
lst2.append(val._p_.master.impl_getname())
|
||||
else:
|
||||
lst2.append(val.impl_getname())
|
||||
assert set(lst1) == set(lst2), '{} - {}'.format(lst1, lst2)
|
||||
elif attr == '_cache_force_store_values':
|
||||
for idx, tup in enumerate(val1):
|
||||
assert tup[0] == val2[idx][0]
|
||||
assert tup[1].impl_getname() == val2[idx][1].impl_getname()
|
||||
elif attr in ['_extra', '_information']:
|
||||
dico1 = {}
|
||||
dico2 = {}
|
||||
assert len(val1[0]) == len(val2[0])
|
||||
assert set(val1[0]) == set(val2[0])
|
||||
for idx, val in enumerate(val1[0]):
|
||||
idx2 = val1[0].index(val)
|
||||
assert val1[1][idx] == val1[1][idx2]
|
||||
else:
|
||||
#print(attr, val1, val2)
|
||||
assert val1 == val2, "error for {}".format(attr)
|
||||
|
||||
|
||||
def _diff_opts(opt1, opt2):
|
||||
_diff_opt(opt1, opt2)
|
||||
if isinstance(opt1, OptionDescription) or isinstance(opt1, DynOptionDescription):
|
||||
children1 = set([opt.impl_getname() for opt in opt1.impl_getchildren(dyn=False)])
|
||||
children2 = set([opt.impl_getname() for opt in opt2.impl_getchildren(dyn=False)])
|
||||
diff1 = children1 - children2
|
||||
diff2 = children2 - children1
|
||||
if diff1 != set():
|
||||
raise Exception('more attribute in opt1 {0}'.format(list(diff1)))
|
||||
if diff2 != set():
|
||||
raise Exception('more attribute in opt2 {0}'.format(list(diff2)))
|
||||
for child in children1:
|
||||
_diff_opts(opt1._getattr(child, dyn=False), opt2._getattr(child, dyn=False))
|
||||
|
||||
|
||||
def _diff_conf(cfg1, cfg2):
|
||||
attr1 = set(_get_slots(cfg1))
|
||||
attr2 = set(_get_slots(cfg2))
|
||||
diff1 = attr1 - attr2
|
||||
diff2 = attr2 - attr1
|
||||
if diff1 != set():
|
||||
raise Exception('more attribute in cfg1 {0}'.format(list(diff1)))
|
||||
if diff2 != set():
|
||||
raise Exception('more attribute in cfg2 {0}'.format(list(diff2)))
|
||||
for attr in attr1:
|
||||
if attr in ('_impl_context', '__weakref__'):
|
||||
continue
|
||||
err1 = False
|
||||
err2 = False
|
||||
val1 = None
|
||||
val2 = None
|
||||
try:
|
||||
val1 = getattr(cfg1, attr)
|
||||
except:
|
||||
err1 = True
|
||||
|
||||
try:
|
||||
val2 = getattr(cfg2, attr)
|
||||
except:
|
||||
err2 = True
|
||||
assert err1 == err2
|
||||
if val1 is None:
|
||||
assert val1 == val2
|
||||
elif attr == '_impl_values':
|
||||
assert cfg1.cfgimpl_get_values().get_modified_values() == cfg2.cfgimpl_get_values().get_modified_values()
|
||||
elif attr == '_impl_settings':
|
||||
assert cfg1.cfgimpl_get_settings().get_modified_properties() == cfg2.cfgimpl_get_settings().get_modified_properties()
|
||||
assert cfg1.cfgimpl_get_settings().get_modified_permissives() == cfg2.cfgimpl_get_settings().get_modified_permissives()
|
||||
elif attr == '_impl_descr':
|
||||
_diff_opt(cfg1.cfgimpl_get_description(), cfg2.cfgimpl_get_description())
|
||||
elif attr == '_impl_children':
|
||||
for index, _opt in enumerate(val1):
|
||||
_diff_conf(_opt, val2[index])
|
||||
elif attr == '_impl_name':
|
||||
#FIXME
|
||||
pass
|
||||
else:
|
||||
assert val1 == val2
|
||||
|
||||
|
||||
def test_diff_opt():
|
||||
b = BoolOption('b', '')
|
||||
u = UnicodeOption('u', '', requires=[{'option': b, 'expected': True, 'action': 'disabled', 'inverse': True}])
|
||||
s = SymLinkOption('s', u)
|
||||
o = OptionDescription('o', '', [b, u, s])
|
||||
o1 = OptionDescription('o1', '', [o])
|
||||
|
||||
raises(NotImplementedError, "dumps(o1)")
|
||||
|
||||
|
||||
def test_diff_information_config():
|
||||
b = BoolOption('b', '')
|
||||
b.impl_set_information('info', 'oh')
|
||||
b.impl_set_information('info1', 'oh')
|
||||
b.impl_set_information('info2', 'oh')
|
||||
o = OptionDescription('o', '', [b])
|
||||
o1 = OptionDescription('o1', '', [o])
|
||||
raises(NotImplementedError, "dumps(Config(o1))")
|
||||
|
||||
|
||||
def test_only_optiondescription():
|
||||
b = BoolOption('b', '')
|
||||
b
|
||||
raises(NotImplementedError, "a = dumps(b)")
|
||||
|
|
@ -1,302 +0,0 @@
|
|||
# coding: utf-8
|
||||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
|
||||
from py.test import raises
|
||||
|
||||
from tiramisu.error import ConfigError
|
||||
from tiramisu.config import Config
|
||||
from tiramisu.option import BoolOption, OptionDescription, MasterSlaves
|
||||
from tiramisu.setting import groups, owners
|
||||
from tiramisu.storage import list_sessions, delete_session
|
||||
|
||||
|
||||
def test_non_persistent():
|
||||
b = BoolOption('b', '')
|
||||
o = OptionDescription('od', '', [b])
|
||||
Config(o, session_id='test_non_persistent')
|
||||
|
||||
|
||||
#def test_list():
|
||||
# b = BoolOption('b', '')
|
||||
# o = OptionDescription('od', '', [b])
|
||||
# c = Config(o, session_id='test_non_persistent')
|
||||
# c.cfgimpl_get_settings().remove('cache')
|
||||
# c.b = True
|
||||
# assert 'test_non_persistent' in list_sessions('config')
|
||||
# del(c)
|
||||
# assert 'test_non_persistent' not in list_sessions('config')
|
||||
#
|
||||
#
|
||||
#def test_create_persistent():
|
||||
# b = BoolOption('b', '')
|
||||
# o = OptionDescription('od', '', [b])
|
||||
# try:
|
||||
# Config(o, session_id='test_persistent', persistent=True)
|
||||
# except ValueError:
|
||||
# # storage is not persistent
|
||||
# pass
|
||||
#
|
||||
#
|
||||
#def test_create_delete_not_persistent():
|
||||
# b = BoolOption('b', '')
|
||||
# o = OptionDescription('od', '', [b])
|
||||
# try:
|
||||
# Config(o, session_id='test_persistent', persistent=True)
|
||||
# except ValueError:
|
||||
# raises(ValueError, "delete_session('option', 'test_persistent')")
|
||||
#
|
||||
#
|
||||
#def test_list_sessions_persistent():
|
||||
# b = BoolOption('b', '')
|
||||
# o = OptionDescription('od', '', [b])
|
||||
# try:
|
||||
# c = Config(o, session_id='test_persistent', persistent=True)
|
||||
# c.b = True
|
||||
# except ValueError:
|
||||
# # storage is not persistent
|
||||
# pass
|
||||
# else:
|
||||
# assert 'test_persistent' in list_sessions('config')
|
||||
#
|
||||
#
|
||||
#def test_delete_session_persistent():
|
||||
# b = BoolOption('b', '')
|
||||
# o = OptionDescription('od', '', [b])
|
||||
# try:
|
||||
# Config(o, session_id='test_persistent', persistent=True)
|
||||
# except ValueError:
|
||||
# # storage is not persistent
|
||||
# pass
|
||||
# else:
|
||||
# assert 'test_persistent' in list_sessions('config')
|
||||
# delete_session('config', 'test_persistent')
|
||||
# assert 'test_persistent' not in list_sessions('config')
|
||||
#
|
||||
#
|
||||
#def test_create_persistent_retrieve():
|
||||
# b = BoolOption('b', '')
|
||||
# o = OptionDescription('od', '', [b])
|
||||
# try:
|
||||
# c = Config(o, session_id='test_persistent', persistent=True)
|
||||
# except ValueError:
|
||||
# # storage is not persistent
|
||||
# pass
|
||||
# else:
|
||||
# assert c.b is None
|
||||
# c.b = True
|
||||
# assert c.b is True
|
||||
# del(c)
|
||||
# c = Config(o, session_id='test_persistent', persistent=True)
|
||||
# assert c.b is True
|
||||
# assert 'test_persistent' in list_sessions('config')
|
||||
# delete_session('config', c.impl_getsessionid())
|
||||
# del(c)
|
||||
# c = Config(o, session_id='test_persistent', persistent=True)
|
||||
# assert c.b is None
|
||||
# delete_session('config', c.impl_getsessionid())
|
||||
# del(c)
|
||||
#
|
||||
#
|
||||
#def test_two_persistent():
|
||||
# b = BoolOption('b', '')
|
||||
# o = OptionDescription('od', '', [b])
|
||||
# try:
|
||||
# c = Config(o, session_id='test_persistent', persistent=True)
|
||||
# except ValueError:
|
||||
# # storage is not persistent
|
||||
# pass
|
||||
# else:
|
||||
# c.cfgimpl_get_settings().remove('cache')
|
||||
# c2 = Config(o, session_id='test_persistent', persistent=True)
|
||||
# c2.cfgimpl_get_settings().remove('cache')
|
||||
# assert c.b is None
|
||||
# assert c2.b is None
|
||||
# c.b = False
|
||||
# assert c.b is False
|
||||
# assert c2.b is False
|
||||
# c2.b = True
|
||||
# assert c.b is True
|
||||
# assert c2.b is True
|
||||
# delete_session('config', 'test_persistent')
|
||||
#
|
||||
#
|
||||
#def test_create_persistent_retrieve_owner():
|
||||
# b = BoolOption('b', '')
|
||||
# o = OptionDescription('od', '', [b])
|
||||
# try:
|
||||
# c = Config(o, session_id='test_persistent', persistent=True)
|
||||
# except ValueError:
|
||||
# # storage is not persistent
|
||||
# pass
|
||||
# else:
|
||||
# assert c.getowner(b) == owners.default
|
||||
# c.b = True
|
||||
# assert c.b is True
|
||||
# assert c.getowner(b) == owners.user
|
||||
# owners.addowner('persistentowner')
|
||||
# c.cfgimpl_get_values().setowner(b, owners.persistentowner)
|
||||
# assert c.getowner(b) == owners.persistentowner
|
||||
# del(c)
|
||||
# #
|
||||
# c = Config(o, session_id='test_persistent', persistent=True)
|
||||
# c.cfgimpl_get_values().setowner(b, owners.persistentowner)
|
||||
# delete_session('config', c.impl_getsessionid())
|
||||
# del(c)
|
||||
# #
|
||||
# c = Config(o, session_id='test_persistent', persistent=True)
|
||||
# assert c.b is None
|
||||
# assert c.getowner(b) == owners.default
|
||||
# delete_session('config', c.impl_getsessionid())
|
||||
# del(c)
|
||||
#
|
||||
#
|
||||
#def test_create_persistent_retrieve_owner_masterslaves():
|
||||
# a = BoolOption('a', '', multi=True)
|
||||
# b = BoolOption('b', '', multi=True)
|
||||
# o = MasterSlaves('a', '', [a, b])
|
||||
# #o.impl_set_group_type(groups.master)
|
||||
# o1 = OptionDescription('a', '', [o])
|
||||
# try:
|
||||
# c = Config(o1, session_id='test_persistent', persistent=True)
|
||||
# except ValueError:
|
||||
# # storage is not persistent
|
||||
# pass
|
||||
# else:
|
||||
# assert c.getowner(a) == owners.default
|
||||
# assert c.getowner(b) == owners.default
|
||||
# c.a.a = [True]
|
||||
# c.a.a.append(False)
|
||||
# c.a.b[1] = True
|
||||
# assert c.getowner(a) == owners.user
|
||||
# assert c.getowner(b, 0) == owners.default
|
||||
# assert c.getowner(b, 1) == owners.user
|
||||
# owners.addowner('persistentowner2')
|
||||
# c.cfgimpl_get_values().setowner(b, owners.persistentowner2, 1)
|
||||
# c.a.b[0] = True
|
||||
# assert c.getowner(b, 0) == owners.user
|
||||
# assert c.getowner(b, 1) == owners.persistentowner2
|
||||
# del(c)
|
||||
# #
|
||||
# c = Config(o1, session_id='test_persistent', persistent=True)
|
||||
# assert c.getowner(b, 0) == owners.user
|
||||
# assert c.getowner(b, 1) == owners.persistentowner2
|
||||
# delete_session('config', c.impl_getsessionid())
|
||||
# del(c)
|
||||
# #
|
||||
# c = Config(o1, session_id='test_persistent', persistent=True)
|
||||
# assert c.a.b == []
|
||||
# assert c.getowner(b) == owners.default
|
||||
# delete_session('config', c.impl_getsessionid())
|
||||
# del(c)
|
||||
#
|
||||
#
|
||||
#def test_two_persistent_owner():
|
||||
# b = BoolOption('b', '')
|
||||
# o = OptionDescription('od', '', [b])
|
||||
# try:
|
||||
# c = Config(o, session_id='test_persistent', persistent=True)
|
||||
# c.cfgimpl_get_settings().remove('cache')
|
||||
# except ValueError:
|
||||
# # storage is not persistent
|
||||
# pass
|
||||
# else:
|
||||
# c2 = Config(o, session_id='test_persistent', persistent=True)
|
||||
# c2.cfgimpl_get_settings().remove('cache')
|
||||
# assert c.getowner(b) == owners.default
|
||||
# assert c2.getowner(b) == owners.default
|
||||
# c.b = False
|
||||
# assert c.getowner(b) == owners.user
|
||||
# assert c2.getowner(b) == owners.user
|
||||
# owners.addowner('persistent')
|
||||
# c.cfgimpl_get_values().setowner(b, owners.persistent)
|
||||
# assert c.getowner(b) == owners.persistent
|
||||
# assert c2.getowner(b) == owners.persistent
|
||||
# delete_session('config', 'test_persistent')
|
||||
#
|
||||
#
|
||||
#def test_create_persistent_retrieve_information():
|
||||
# b = BoolOption('b', '')
|
||||
# o = OptionDescription('od', '', [b])
|
||||
# try:
|
||||
# c = Config(o, session_id='test_persistent', persistent=True)
|
||||
# except ValueError:
|
||||
# # storage is not persistent
|
||||
# pass
|
||||
# else:
|
||||
# c.impl_set_information('info', 'string')
|
||||
# assert c.impl_get_information('info') == 'string'
|
||||
# del(c)
|
||||
# #
|
||||
# c = Config(o, session_id='test_persistent', persistent=True)
|
||||
# assert c.impl_get_information('info') == 'string'
|
||||
# delete_session('config', c.impl_getsessionid())
|
||||
# del(c)
|
||||
# #
|
||||
# c = Config(o, session_id='test_persistent', persistent=True)
|
||||
# assert c.impl_get_information('info', None) == None
|
||||
# delete_session('config', c.impl_getsessionid())
|
||||
# del(c)
|
||||
#
|
||||
#
|
||||
#def test_two_persistent_information():
|
||||
# b = BoolOption('b', '')
|
||||
# o = OptionDescription('od', '', [b])
|
||||
# try:
|
||||
# c = Config(o, session_id='test_persistent', persistent=True)
|
||||
# c.cfgimpl_get_settings().remove('cache')
|
||||
# except ValueError:
|
||||
# # storage is not persistent
|
||||
# pass
|
||||
# else:
|
||||
# c.impl_set_information('info', 'string')
|
||||
# assert c.impl_get_information('info') == 'string'
|
||||
# c2 = Config(o, session_id='test_persistent', persistent=True)
|
||||
# c2.cfgimpl_get_settings().remove('cache')
|
||||
# c2.cfgimpl_get_settings().remove('cache')
|
||||
# assert c2.impl_get_information('info') == 'string'
|
||||
# delete_session('config', 'test_persistent')
|
||||
#
|
||||
#
|
||||
#def test_two_different_persistents():
|
||||
# b = BoolOption('b', '')
|
||||
# o = OptionDescription('od', '', [b])
|
||||
# try:
|
||||
# c = Config(o, session_id='test_persistent', persistent=True)
|
||||
# c.cfgimpl_get_settings().remove('cache')
|
||||
# d = Config(o, session_id='test_persistent2', persistent=True)
|
||||
# d.cfgimpl_get_settings().remove('cache')
|
||||
# except ValueError:
|
||||
# # storage is not persistent
|
||||
# pass
|
||||
# else:
|
||||
# c.cfgimpl_get_settings()[b].append('test')
|
||||
# assert str(c.cfgimpl_get_settings()[b]) in ["['test']", "[u'test']"]
|
||||
# assert str(d.cfgimpl_get_settings()[b]) == "[]"
|
||||
# assert c.b is None
|
||||
# assert d.b is None
|
||||
# c.b = True
|
||||
# assert c.b == True
|
||||
# assert d.b is None
|
||||
#
|
||||
# delete_session('config', 'test_persistent')
|
||||
# delete_session('config', 'test_persistent2')
|
||||
#
|
||||
#
|
||||
#def test_two_different_information():
|
||||
# b = BoolOption('b', '')
|
||||
# o = OptionDescription('od', '', [b])
|
||||
# try:
|
||||
# c = Config(o, session_id='test_persistent', persistent=True)
|
||||
# c.impl_set_information('a', 'a')
|
||||
# d = Config(o, session_id='test_persistent2', persistent=True)
|
||||
# d.impl_set_information('a', 'b')
|
||||
# except ValueError:
|
||||
# # storage is not persistent
|
||||
# pass
|
||||
# else:
|
||||
# assert c.impl_get_information('a') == 'a'
|
||||
# assert d.impl_get_information('a') == 'b'
|
||||
#
|
||||
# delete_session('config', 'test_persistent')
|
||||
# delete_session('config', 'test_persistent2')
|
||||
|
|
@ -1,416 +0,0 @@
|
|||
# coding: utf-8
|
||||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
from py.test import raises
|
||||
|
||||
|
||||
from tiramisu.setting import groups, owners
|
||||
from tiramisu import StrOption, IntOption, OptionDescription, submulti, MasterSlaves, Config, \
|
||||
MetaConfig, getapi, undefined
|
||||
from tiramisu.error import SlaveError
|
||||
|
||||
|
||||
|
||||
def return_val(val=None):
|
||||
if val is None:
|
||||
return 'val'
|
||||
else:
|
||||
return val
|
||||
|
||||
|
||||
def return_list(value=None):
|
||||
return ['val', 'val']
|
||||
|
||||
|
||||
def return_list2(value=None):
|
||||
return [['val', 'val']]
|
||||
|
||||
|
||||
def test_submulti():
|
||||
multi = StrOption('multi', '', multi=submulti)
|
||||
multi2 = StrOption('multi2', '', default_multi=['yes'], multi=submulti)
|
||||
multi3 = StrOption('multi3', '', default=[['yes']], multi=submulti)
|
||||
od = OptionDescription('od', '', [multi, multi2, multi3])
|
||||
api = getapi(Config(od))
|
||||
assert api.option('multi').owner.get() == owners.default
|
||||
assert api.option('multi').value.get() == []
|
||||
assert api.option('multi').owner.get() == owners.default
|
||||
assert api.option('multi').owner.get() == owners.default
|
||||
assert api.option('multi3').value.get() == [['yes']]
|
||||
assert api.option('multi').owner.get() == owners.default
|
||||
|
||||
|
||||
def test_append_submulti():
|
||||
multi = StrOption('multi', '', multi=submulti)
|
||||
multi2 = StrOption('multi2', '', default_multi=['yes'], multi=submulti)
|
||||
multi3 = StrOption('multi3', '', default=[['yes']], multi=submulti)
|
||||
od = OptionDescription('od', '', [multi, multi2, multi3])
|
||||
api = getapi(Config(od))
|
||||
owner = api.owner.get()
|
||||
assert api.option('multi').value.get() == []
|
||||
assert api.option('multi').owner.get() == owners.default
|
||||
api.option('multi').value.set([undefined])
|
||||
assert api.option('multi').owner.get() == owner
|
||||
assert api.option('multi').value.get() == [[]]
|
||||
api.option('multi').value.set([undefined, ['no']])
|
||||
assert api.option('multi').value.get() == [[], ['no']]
|
||||
#
|
||||
assert api.option('multi2').value.get() == []
|
||||
assert api.option('multi2').owner.get() == owners.default
|
||||
api.option('multi2').value.set([undefined])
|
||||
assert api.option('multi2').owner.get() == owner
|
||||
assert api.option('multi2').value.get() == [['yes']]
|
||||
api.option('multi2').value.set([undefined, ['no']])
|
||||
assert api.option('multi2').value.get() == [['yes'], ['no']]
|
||||
#
|
||||
assert api.option('multi3').value.get() == [['yes']]
|
||||
assert api.option('multi3').owner.get() == owners.default
|
||||
api.option('multi3').value.set([undefined, undefined])
|
||||
assert api.option('multi3').owner.get() == owner
|
||||
assert api.option('multi3').value.get() == [['yes'], []]
|
||||
api.option('multi3').value.set([undefined, undefined, ['no']])
|
||||
assert api.option('multi3').value.get() == [['yes'], [], ['no']]
|
||||
|
||||
|
||||
def test_append_unvalide_submulti():
|
||||
multi = StrOption('multi', '', multi=submulti)
|
||||
multi2 = StrOption('multi2', '', default_multi=['yes'], multi=submulti)
|
||||
multi3 = StrOption('multi3', '', default=[['yes']], multi=submulti)
|
||||
od = OptionDescription('od', '', [multi, multi2, multi3])
|
||||
api = getapi(Config(od))
|
||||
assert api.option('multi').value.get() == []
|
||||
assert api.option('multi').owner.get() == owners.default
|
||||
raises(ValueError, "api.option('multi').value.set([[1]])")
|
||||
assert api.option('multi').value.get() == []
|
||||
assert api.option('multi').owner.get() == owners.default
|
||||
#
|
||||
assert api.option('multi2').value.get() == []
|
||||
raises(ValueError, "api.option('multi2').value.set(['no'])")
|
||||
assert api.option('multi').owner.get() == owners.default
|
||||
assert api.option('multi2').value.get() == []
|
||||
#
|
||||
assert api.option('multi3').value.get() == [['yes']]
|
||||
assert api.option('multi3').owner.get() == owners.default
|
||||
raises(ValueError, "api.option('multi3').value.set([[1]])")
|
||||
assert api.option('multi3').value.get() == [['yes']]
|
||||
assert api.option('multi3').owner.get() == owners.default
|
||||
|
||||
|
||||
def test_pop_submulti():
|
||||
multi = StrOption('multi', '', multi=submulti)
|
||||
multi2 = StrOption('multi2', '', default_multi=['yes'], multi=submulti)
|
||||
multi3 = StrOption('multi3', '', default=[['yes']], multi=submulti)
|
||||
od = OptionDescription('od', '', [multi, multi2, multi3])
|
||||
api = getapi(Config(od))
|
||||
owner = api.owner.get()
|
||||
assert api.option('multi').value.get() == []
|
||||
assert api.option('multi3').owner.get() == owners.default
|
||||
api.option('multi').value.set([['no', 'yes'], ['peharps']])
|
||||
assert api.option('multi').owner.get() == owner
|
||||
assert api.option('multi').value.get() == [['no', 'yes'], ['peharps']]
|
||||
#
|
||||
assert api.option('multi3').value.get() == [['yes']]
|
||||
assert api.option('multi3').owner.get() == owners.default
|
||||
api.option('multi3').value.set([])
|
||||
assert api.option('multi').owner.get() == owner
|
||||
assert api.option('multi3').value.get() == []
|
||||
api.option('multi3').value.reset()
|
||||
assert api.option('multi3').owner.get() == owners.default
|
||||
api.option('multi3').value.set([[]])
|
||||
assert api.option('multi3').owner.get() == owner
|
||||
assert api.option('multi3').value.get() == [[]]
|
||||
|
||||
|
||||
def test_callback_submulti_str():
|
||||
multi = StrOption('multi', '', multi=submulti, callback=return_val)
|
||||
od = OptionDescription('od', '', [multi])
|
||||
api = getapi(Config(od))
|
||||
api.property.read_write()
|
||||
owner = api.owner.get()
|
||||
assert api.option('multi').owner.get() == owners.default
|
||||
assert api.option('multi').value.get() == [['val']]
|
||||
api.option('multi').value.set([['val'], undefined])
|
||||
assert api.option('multi').owner.get() == owner
|
||||
assert api.option('multi').value.get() == [['val'], ['val']]
|
||||
api.option('multi').value.reset()
|
||||
assert api.option('multi').owner.get() == owners.default
|
||||
|
||||
|
||||
def test_callback_submulti_list():
|
||||
multi = StrOption('multi', '', multi=submulti, callback=return_list)
|
||||
od = OptionDescription('od', '', [multi])
|
||||
api = getapi(Config(od))
|
||||
api.property.read_write()
|
||||
owner = api.owner.get()
|
||||
assert api.option('multi').value.get() == [['val', 'val']]
|
||||
assert api.option('multi').owner.get() == owners.default
|
||||
api.option('multi').value.set([['val', 'val'], undefined])
|
||||
assert api.option('multi').owner.get() == owner
|
||||
assert api.option('multi').value.get() == [['val', 'val'], ['val', 'val']]
|
||||
api.option('multi').value.set([['val', 'val'], undefined, undefined])
|
||||
assert api.option('multi').value.get() == [['val', 'val'], ['val', 'val'], ['val', 'val']]
|
||||
api.option('multi').value.reset()
|
||||
assert api.option('multi').owner.get() == owners.default
|
||||
|
||||
|
||||
def test_callback_submulti_list_list():
|
||||
multi = StrOption('multi', '', multi=submulti, callback=return_list2)
|
||||
od = OptionDescription('od', '', [multi])
|
||||
api = getapi(Config(od))
|
||||
api.property.read_write()
|
||||
owner = api.owner.get()
|
||||
assert api.option('multi').value.get() == [['val', 'val']]
|
||||
assert api.option('multi').owner.get() == owners.default
|
||||
api.option('multi').value.set([['val', 'val'], undefined])
|
||||
assert api.option('multi').owner.get() == owner
|
||||
assert api.option('multi').value.get() == [['val', 'val'], []]
|
||||
api.option('multi').value.reset()
|
||||
assert api.option('multi').owner.get() == owners.default
|
||||
|
||||
|
||||
def test_groups_with_master_submulti():
|
||||
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=submulti)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
assert interface1.impl_get_group_type() == groups.master
|
||||
|
||||
|
||||
def test_groups_with_master_in_config_submulti():
|
||||
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=submulti)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
od = OptionDescription('root', '', [interface1])
|
||||
Config(od)
|
||||
assert interface1.impl_get_group_type() == groups.master
|
||||
|
||||
|
||||
def test_values_with_master_and_slaves_submulti():
|
||||
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=submulti)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
api = getapi(Config(maconfig))
|
||||
api.property.read_write()
|
||||
owner = api.owner.get()
|
||||
assert interface1.impl_get_group_type() == groups.master
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.default
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ["192.168.230.145"]
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == []
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.default
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", "192.168.230.147"])
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == []
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == []
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(['255.255.255.0'])
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == ['255.255.255.0']
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == []
|
||||
raises(ValueError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')")
|
||||
raises(ValueError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set([['255.255.255.0']])")
|
||||
|
||||
|
||||
def test_reset_values_with_master_and_slaves_submulti():
|
||||
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=submulti)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
api = getapi(Config(maconfig))
|
||||
api.property.read_write()
|
||||
owner = api.owner.get()
|
||||
assert interface1.impl_get_group_type() == groups.master
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.default
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.default
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.default
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
#
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(['255.255.255.0'])
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owner
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.default
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
|
||||
|
||||
def test_values_with_master_and_slaves_slave_submulti():
|
||||
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=submulti)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
api = getapi(Config(maconfig))
|
||||
api.property.read_write()
|
||||
raises(SlaveError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(['255.255.255.0'])")
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(['255.255.255.0'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(['255.255.255.0', '255.255.255.0'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset()
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(['255.255.255.0'])
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145', '192.168.230.145'])
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == ['255.255.255.0']
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == []
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(['255.255.255.0'])
|
||||
|
||||
|
||||
def test_values_with_master_and_slaves_master_submulti():
|
||||
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=submulti)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
api = getapi(Config(maconfig))
|
||||
api.property.read_write()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", "192.168.230.145"])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(['255.255.255.0'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set(['255.255.255.0'])
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == ['255.255.255.0']
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == ['255.255.255.0']
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(1)
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ["192.168.230.145"]
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == ['255.255.255.0']
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
|
||||
|
||||
def test_values_with_master_owner_submulti():
|
||||
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=submulti)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
api = getapi(Config(maconfig))
|
||||
api.property.read_write()
|
||||
owner = api.owner.get()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.default
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.default
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.default
|
||||
|
||||
|
||||
def test_values_with_master_disabled_submulti():
|
||||
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=submulti)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
api = getapi(Config(maconfig))
|
||||
api.property.read_write()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(['192.168.230.145'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset()
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0').property.add('disabled')
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145', '192.168.230.145'])
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(1)
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
|
||||
|
||||
#delete with value in disabled var
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0').property.pop('disabled')
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(['192.168.230.145'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0').property.add('disabled')
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
|
||||
|
||||
|
||||
def test__master_is_submulti():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=submulti)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
api = getapi(Config(maconfig))
|
||||
api.property.read_write()
|
||||
owner = api.owner.get()
|
||||
assert interface1.impl_get_group_type() == groups.master
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set([["192.168.230.145"]])
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [["192.168.230.145"]]
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set([["192.168.230.145"], ["192.168.230.147"]])
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == None
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set([["192.168.230.145", '192.168.1.1'], ["192.168.230.147"]])
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [["192.168.230.145", '192.168.1.1'], ["192.168.230.147"]]
|
||||
raises(ValueError, "api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1', '192.168.1.1'])")
|
||||
|
||||
|
||||
def test_callback_submulti():
|
||||
multi = StrOption('multi', '', multi=submulti)
|
||||
multi2 = StrOption('multi2', '', multi=submulti, callback=return_val, callback_params={'': ((multi, False),)})
|
||||
od = OptionDescription('multi', '', [multi, multi2])
|
||||
api = getapi(Config(od))
|
||||
api.property.read_write()
|
||||
owner = api.owner.get()
|
||||
assert api.option('multi').owner.get() == owners.default
|
||||
assert api.option('multi').value.get() == []
|
||||
assert api.option('multi2').value.get() == []
|
||||
api.option('multi').value.set([['val']])
|
||||
assert api.option('multi').owner.get() == owner
|
||||
assert api.option('multi2').owner.get() == owners.default
|
||||
assert api.option('multi').value.get() == [['val']]
|
||||
assert api.option('multi2').value.get() == [['val']]
|
||||
|
||||
|
||||
def test_submulti_unique():
|
||||
i = IntOption('int', '', multi=submulti, unique=True)
|
||||
o = OptionDescription('od', '', [i])
|
||||
api = getapi(Config(o))
|
||||
assert api.option('int').value.get() == []
|
||||
api.option('int').value.set([[0]])
|
||||
assert api.option('int').value.get() == [[0]]
|
||||
raises(ValueError, "api.option('int').value.set([[0, 0]])")
|
||||
api.option('int').value.set([[0], [0]])
|
||||
raises(ValueError, "api.option('int').value.set([[1, 0, 2, 3, 4, 5, 6, 0, 7], [0]])")
|
||||
api.option('int').value.set([[0, 4, 5, 6], [0]])
|
||||
#
|
||||
#
|
||||
#def test_multi_submulti_meta():
|
||||
# multi = StrOption('multi', '', multi=submulti)
|
||||
# od = OptionDescription('od', '', [multi])
|
||||
# conf1 = Config(od, session_id='conf1')
|
||||
# api1 = getapi(conf1)
|
||||
# api1.property.read_write()
|
||||
# conf2 = Config(od, session_id='conf2')
|
||||
# api2 = getapi(conf2)
|
||||
# api2.property.read_write()
|
||||
# meta = MetaConfig([conf1, conf2])
|
||||
# api3 = getapi(meta)
|
||||
# api3.property.read_write()
|
||||
# api3.option('multi').value.set([['val']])
|
||||
# assert api3.option('multi').value.get() == [['val']]
|
||||
# api3.config('conf1').option('multi').value.set([['val', None]])
|
||||
# assert api1.option('multi').value.get() == [['val', None]]
|
||||
# assert api3.config('conf1').option('multi').value.get() == [['val', None]]
|
||||
# assert api3.option('multi').value.get() == [['val']]
|
||||
#
|
||||
#
|
||||
#def test_multi_submulti_meta_no_cache():
|
||||
# multi = StrOption('multi', '', multi=submulti)
|
||||
# od = OptionDescription('od', '', [multi])
|
||||
# conf1 = Config(od, session_id='conf1_1')
|
||||
# api1 = getapi(conf1)
|
||||
# api1.property.read_write()
|
||||
# conf2 = Config(od, session_id='conf2_1')
|
||||
# api2 = getapi(conf2)
|
||||
# api2.property.read_write()
|
||||
# meta = MetaConfig([conf1, conf2])
|
||||
# api3 = getapi(api2)
|
||||
# api3.property.read_write()
|
||||
# api3.property.pop('cache')
|
||||
# api3.option('multi').value.set([['val']])
|
||||
# assert api3.option('multi').value.get() == [['val']]
|
||||
# api3.config('conf1').option('multi').value.set([['val', None]])
|
||||
# assert api1.option('multi').value.get() == [['val', None]]
|
||||
# assert api3.config('conf1').option('multi').value.get() == [['val', None]]
|
||||
# assert api3.option('multi').value.get() == [['val']]
|
||||
|
|
@ -1,164 +0,0 @@
|
|||
# coding: utf-8
|
||||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
|
||||
from tiramisu import BoolOption, StrOption, SymLinkOption, \
|
||||
OptionDescription, MasterSlaves, Config, getapi
|
||||
from tiramisu.error import PropertiesOptionError, ConfigError
|
||||
from tiramisu.setting import groups, owners
|
||||
|
||||
from py.test import raises
|
||||
|
||||
|
||||
def return_value():
|
||||
pass
|
||||
|
||||
|
||||
#____________________________________________________________
|
||||
def test_symlink_option():
|
||||
boolopt = BoolOption("b", "", default=False)
|
||||
linkopt = SymLinkOption("c", boolopt)
|
||||
descr = OptionDescription("opt", "",
|
||||
[linkopt, OptionDescription("s1", "", [boolopt])])
|
||||
api = getapi(Config(descr))
|
||||
assert api.option('s1.b').value.get() is False
|
||||
api.option("s1.b").value.set(True)
|
||||
api.option("s1.b").value.set(False)
|
||||
assert api.option('s1.b').value.get() is False
|
||||
assert api.option('c').value.get() is False
|
||||
api.option('s1.b').value.set(True)
|
||||
assert api.option('s1.b').value.get() is True
|
||||
assert api.option('c').value.get() is True
|
||||
api.option('s1.b').value.set(False)
|
||||
assert api.option('s1.b').value.get() is False
|
||||
assert api.option('c').value.get() is False
|
||||
|
||||
|
||||
def test_symlink_getproperties():
|
||||
boolopt = BoolOption('b', '', default=True, properties=('test',))
|
||||
linkopt = SymLinkOption("c", boolopt)
|
||||
descr = OptionDescription('opt', '', [boolopt, linkopt])
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
assert boolopt.impl_getproperties() == linkopt.impl_getproperties() == {'test'}
|
||||
assert boolopt.impl_has_callback() == linkopt.impl_has_callback() == False
|
||||
|
||||
|
||||
def test_symlink_getcallback():
|
||||
boolopt = BoolOption('b', '', callback=return_value)
|
||||
linkopt = SymLinkOption("c", boolopt)
|
||||
descr = OptionDescription('opt', '', [boolopt, linkopt])
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
assert boolopt.impl_has_callback() == linkopt.impl_has_callback() == True
|
||||
assert boolopt.impl_get_callback() == linkopt.impl_get_callback() == (return_value, {})
|
||||
|
||||
|
||||
def test_symlink_requires():
|
||||
boolopt = BoolOption('b', '', default=True)
|
||||
stropt = StrOption('s', '', requires=[{'option': boolopt,
|
||||
'expected': False,
|
||||
'action': 'disabled'}])
|
||||
linkopt = SymLinkOption("c", stropt)
|
||||
descr = OptionDescription('opt', '', [boolopt, stropt, linkopt])
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
assert api.option('b').value.get() is True
|
||||
assert api.option('s').value.get() is None
|
||||
assert api.option('c').value.get() is None
|
||||
api.option('b').value.set(False)
|
||||
#
|
||||
props = []
|
||||
try:
|
||||
api.option('s').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == {'disabled'}
|
||||
#
|
||||
props = []
|
||||
try:
|
||||
api.option('c').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == {'disabled'}
|
||||
|
||||
|
||||
def test_symlink_multi():
|
||||
boolopt = BoolOption("b", "", default=[False], multi=True)
|
||||
linkopt = SymLinkOption("c", boolopt)
|
||||
descr = OptionDescription("opt", "",
|
||||
[linkopt, OptionDescription("s1", "", [boolopt])])
|
||||
api = getapi(Config(descr))
|
||||
assert api.option('s1.b').value.get() == [False]
|
||||
assert api.option('c').value.get() == [False]
|
||||
api.option('s1.b').value.set([True])
|
||||
assert api.option('s1.b').value.get() == [True]
|
||||
assert api.option('c').value.get() == [True]
|
||||
api.option('s1.b').value.set([False])
|
||||
assert api.option('s1.b').value.get() == [False]
|
||||
assert api.option('c').value.get() == [False]
|
||||
api.option('s1.b').value.set([False, True])
|
||||
assert api.option('s1.b').value.get() == [False, True]
|
||||
assert api.option('c').value.get() == [False, True]
|
||||
assert boolopt.impl_is_multi() is True
|
||||
assert linkopt.impl_is_multi() is True
|
||||
|
||||
|
||||
def test_symlink_assign():
|
||||
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_owner():
|
||||
boolopt = BoolOption("b", "", default=False)
|
||||
linkopt = SymLinkOption("c", boolopt)
|
||||
descr = OptionDescription("opt", "",
|
||||
[linkopt, OptionDescription("s1", "", [boolopt])])
|
||||
api = getapi(Config(descr))
|
||||
assert api.option('s1.b').owner.isdefault()
|
||||
assert api.option('c').owner.isdefault()
|
||||
api.option('s1.b').value.set(True)
|
||||
assert not api.option('s1.b').owner.isdefault()
|
||||
assert not api.option('c').owner.isdefault()
|
||||
|
||||
|
||||
def test_symlink_get_information():
|
||||
boolopt = BoolOption("b", "", default=False)
|
||||
linkopt = SymLinkOption("c", boolopt)
|
||||
boolopt.impl_set_information('test', 'test')
|
||||
assert boolopt.impl_get_information('test') == 'test'
|
||||
assert linkopt.impl_get_information('test') == 'test'
|
||||
boolopt.impl_set_information('test', 'test2')
|
||||
assert boolopt.impl_get_information('test') == 'test2'
|
||||
assert linkopt.impl_get_information('test') == 'test2'
|
||||
|
||||
|
||||
def test_symlink_master():
|
||||
a = StrOption('a', "", multi=True)
|
||||
ip_admin_eth0 = SymLinkOption('ip_admin_eth0', a)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "", multi=True)
|
||||
raises(ValueError, "MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])")
|
||||
|
||||
|
||||
def test_symlink_slaves():
|
||||
a = StrOption('a', "", multi=True)
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
|
||||
netmask_admin_eth0 = SymLinkOption('netmask_admin_eth0', a)
|
||||
raises(ValueError, "MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])")
|
||||
|
||||
|
||||
#____________________________________________________________
|
||||
def test_symlink_dependency():
|
||||
boolopt = BoolOption("b", "", default=False)
|
||||
linkopt = SymLinkOption("c", boolopt)
|
||||
descr = OptionDescription("opt", "",
|
||||
[linkopt, OptionDescription("s1", "", [boolopt])])
|
||||
api = getapi(Config(descr))
|
||||
assert api.option('s1.b').option.has_dependency() is False
|
||||
assert api.option('c').option.has_dependency() is True
|
||||
assert api.option('s1.b').option.has_dependency(False) is True
|
||||
assert api.option('c').option.has_dependency(False) is False
|
||||
|
|
@ -9,6 +9,8 @@ from tiramisu.option import BoolOption, IPOption, IntOption, StrOption, OptionDe
|
|||
from tiramisu.config import Config
|
||||
from tiramisu.error import ConfigError, PropertiesOptionError
|
||||
from tiramisu.setting import groups
|
||||
from tiramisu import getapi, undefined
|
||||
from tiramisu.api import TIRAMISU_VERSION
|
||||
|
||||
|
||||
from time import sleep, time
|
||||
|
|
@ -45,97 +47,103 @@ def test_cache_config():
|
|||
def test_cache():
|
||||
od1 = make_description()
|
||||
c = Config(od1)
|
||||
api = getapi(c)
|
||||
values = c.cfgimpl_get_values()
|
||||
settings = c.cfgimpl_get_settings()
|
||||
c.u1
|
||||
api.option('u1').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
c.u2
|
||||
api.option('u2').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
assert 'u2' in values._p_.get_cached()
|
||||
assert 'u2' in settings._p_.get_cached()
|
||||
|
||||
|
||||
def test_get_cache():
|
||||
# force a value in cache, try if reget corrupted value
|
||||
od1 = make_description()
|
||||
c = Config(od1)
|
||||
values = c.cfgimpl_get_values()
|
||||
settings = c.cfgimpl_get_settings()
|
||||
ntime = time() + 1
|
||||
settings._p_.setcache('u1', set(['inject']), ntime, None)
|
||||
assert 'inject' in settings[od1.u1]
|
||||
values._p_.setcache('u1', 100, ntime, None)
|
||||
assert c.u1 == [100]
|
||||
#def test_get_cache():
|
||||
# # force a value in cache, try if reget corrupted value
|
||||
# od1 = make_description()
|
||||
# c = Config(od1)
|
||||
# api = getapi(c)
|
||||
# values = c.cfgimpl_get_values()
|
||||
# settings = c.cfgimpl_get_settings()
|
||||
# ntime = time() + 1
|
||||
# settings._p_.setcache('u1', set(['inject']), ntime, None)
|
||||
# assert 'inject' in settings[od1.u1]
|
||||
# values._p_.setcache('u1', 100, ntime, None)
|
||||
# assert api.option('u1').value.get() == [100]
|
||||
|
||||
|
||||
def test_get_cache_no_expire():
|
||||
# force a value in cache, try if reget corrupted value
|
||||
od1 = make_description()
|
||||
c = Config(od1)
|
||||
values = c.cfgimpl_get_values()
|
||||
settings = c.cfgimpl_get_settings()
|
||||
settings._p_.setcache('u1', set(['inject2']), None, None)
|
||||
assert 'inject2' in settings[od1.u1]
|
||||
values._p_.setcache('u1', 200, None, None)
|
||||
assert c.u1 == [200]
|
||||
#def test_get_cache_no_expire():
|
||||
# # force a value in cache, try if reget corrupted value
|
||||
# od1 = make_description()
|
||||
# c = Config(od1)
|
||||
# api = getapi(c)
|
||||
# values = c.cfgimpl_get_values()
|
||||
# settings = c.cfgimpl_get_settings()
|
||||
# settings._p_.setcache('u1', set(['inject2']), None, None)
|
||||
# assert 'inject2' in settings[od1.u1]
|
||||
# values._p_.setcache('u1', 200, None, None)
|
||||
# assert api.option('u1').value.get() == [200]
|
||||
|
||||
|
||||
def test_cache_reset():
|
||||
od1 = make_description()
|
||||
c = Config(od1)
|
||||
api = getapi(c)
|
||||
values = c.cfgimpl_get_values()
|
||||
settings = c.cfgimpl_get_settings()
|
||||
#when change a value
|
||||
c.u1
|
||||
c.u2
|
||||
api.option('u1').value.get()
|
||||
api.option('u2').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
assert 'u2' in values._p_.get_cached()
|
||||
assert 'u2' in settings._p_.get_cached()
|
||||
c.u2 = 1
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
api.option('u2').value.set(1)
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
assert 'u2' not in values._p_.get_cached()
|
||||
assert 'u2' not in settings._p_.get_cached()
|
||||
#when remove a value
|
||||
c.u1
|
||||
api.option('u1').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
del(c.u2)
|
||||
api.option('u2').value.reset()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
assert 'u2' not in values._p_.get_cached()
|
||||
assert 'u2' not in settings._p_.get_cached()
|
||||
#when add/del property
|
||||
c.u1
|
||||
api.option('u1').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
c.cfgimpl_get_settings()[od1.u2].append('test')
|
||||
api.option('u2').property.add('test')
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
assert 'u2' not in values._p_.get_cached()
|
||||
assert 'u2' not in settings._p_.get_cached()
|
||||
c.u1
|
||||
api.option('u1').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
c.cfgimpl_get_settings()[od1.u2].remove('test')
|
||||
api.option('u2').property.pop('test')
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
assert 'u2' not in values._p_.get_cached()
|
||||
assert 'u2' not in settings._p_.get_cached()
|
||||
#when enable/disabled property
|
||||
c.u1
|
||||
api.option('u1').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
c.cfgimpl_get_settings().append('test')
|
||||
api.property.add('test')
|
||||
assert 'u1' not in values._p_.get_cached()
|
||||
assert 'u1' not in settings._p_.get_cached()
|
||||
c.u1
|
||||
api.option('u1').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
c.cfgimpl_get_settings().remove('test')
|
||||
api.property.pop('test')
|
||||
assert 'u1' not in values._p_.get_cached()
|
||||
assert 'u1' not in settings._p_.get_cached()
|
||||
|
||||
|
|
@ -143,49 +151,50 @@ def test_cache_reset():
|
|||
def test_cache_reset_multi():
|
||||
od1 = make_description()
|
||||
c = Config(od1)
|
||||
api = getapi(c)
|
||||
values = c.cfgimpl_get_values()
|
||||
settings = c.cfgimpl_get_settings()
|
||||
c.u1
|
||||
c.u3
|
||||
api.option('u1').value.get()
|
||||
api.option('u3').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
assert 'u3' in values._p_.get_cached()
|
||||
assert 'u3' in settings._p_.get_cached()
|
||||
#when change a value
|
||||
c.u3 = [1]
|
||||
api.option('u3').value.set([1])
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
assert 'u3' not in values._p_.get_cached()
|
||||
assert 'u3' not in settings._p_.get_cached()
|
||||
#when append value
|
||||
c.u1
|
||||
c.u3
|
||||
api.option('u1').value.get()
|
||||
api.option('u3').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
assert 'u3' in values._p_.get_cached()
|
||||
assert 'u3' in settings._p_.get_cached()
|
||||
c.u3.append(1)
|
||||
api.option('u3').value.set([1, 1])
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
assert 'u3' not in values._p_.get_cached()
|
||||
assert 'u3' not in settings._p_.get_cached()
|
||||
#when pop value
|
||||
c.u1
|
||||
c.u3
|
||||
api.option('u1').value.get()
|
||||
api.option('u3').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
assert 'u3' in values._p_.get_cached()
|
||||
assert 'u3' in settings._p_.get_cached()
|
||||
c.u3.pop(1)
|
||||
api.option('u3').value.set([1])
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
assert 'u3' not in values._p_.get_cached()
|
||||
assert 'u3' not in settings._p_.get_cached()
|
||||
#when remove a value
|
||||
c.u1
|
||||
api.option('u1').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
del(c.u3)
|
||||
api.option('u3').value.reset()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
assert 'u3' not in values._p_.get_cached()
|
||||
|
|
@ -195,19 +204,20 @@ def test_cache_reset_multi():
|
|||
def test_reset_cache():
|
||||
od1 = make_description()
|
||||
c = Config(od1)
|
||||
api = getapi(c)
|
||||
values = c.cfgimpl_get_values()
|
||||
settings = c.cfgimpl_get_settings()
|
||||
c.u1
|
||||
api.option('u1').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
c.cfgimpl_reset_cache()
|
||||
assert 'u1' not in values._p_.get_cached()
|
||||
assert 'u1' not in settings._p_.get_cached()
|
||||
c.u1
|
||||
api.option('u1').value.get()
|
||||
sleep(1)
|
||||
c.u1
|
||||
api.option('u1').value.get()
|
||||
sleep(1)
|
||||
c.u2
|
||||
api.option('u2').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
assert 'u2' in values._p_.get_cached()
|
||||
|
|
@ -219,32 +229,35 @@ def test_reset_cache():
|
|||
assert 'u2' not in settings._p_.get_cached()
|
||||
|
||||
|
||||
def test_reset_cache_subconfig():
|
||||
od1 = make_description()
|
||||
od2 = OptionDescription('od2', '', [od1])
|
||||
c = Config(od2)
|
||||
values = c.cfgimpl_get_values()
|
||||
c.od1.u1
|
||||
assert 'od1.u1' in values._p_.get_cached()
|
||||
c.od1.cfgimpl_reset_cache()
|
||||
assert 'od1.u1' not in values._p_.get_cached()
|
||||
#def test_reset_cache_subconfig():
|
||||
# od1 = make_description()
|
||||
# od2 = OptionDescription('od2', '', [od1])
|
||||
# c = Config(od2)
|
||||
# api = getapi(c)
|
||||
# values = c.cfgimpl_get_values()
|
||||
# api.option('od1.u1').value.get()
|
||||
# assert 'od1.u1' in values._p_.get_cached()
|
||||
# c.od1.cfgimpl_reset_cache()
|
||||
# assert 'od1.u1' not in values._p_.get_cached()
|
||||
|
||||
|
||||
def test_reset_cache_only_expired():
|
||||
od1 = make_description()
|
||||
c = Config(od1)
|
||||
api = getapi(c)
|
||||
api.property.add('expire')
|
||||
values = c.cfgimpl_get_values()
|
||||
settings = c.cfgimpl_get_settings()
|
||||
c.u1
|
||||
api.option('u1').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
c.cfgimpl_reset_cache(True)
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
sleep(1)
|
||||
c.u1
|
||||
api.option('u1').value.get()
|
||||
sleep(1)
|
||||
c.u2
|
||||
api.option('u2').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
assert 'u2' in values._p_.get_cached()
|
||||
|
|
@ -259,17 +272,18 @@ def test_reset_cache_only_expired():
|
|||
def test_cache_not_expire():
|
||||
od1 = make_description()
|
||||
c = Config(od1)
|
||||
api = getapi(c)
|
||||
values = c.cfgimpl_get_values()
|
||||
settings = c.cfgimpl_get_settings()
|
||||
settings.remove('expire')
|
||||
c.u1
|
||||
#api.property.pop('expire')
|
||||
api.option('u1').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
c.cfgimpl_reset_cache(True)
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
sleep(1)
|
||||
c.u2
|
||||
api.option('u2').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
assert 'u2' in values._p_.get_cached()
|
||||
|
|
@ -284,66 +298,71 @@ def test_cache_not_expire():
|
|||
def test_cache_not_cache():
|
||||
od1 = make_description()
|
||||
c = Config(od1)
|
||||
api = getapi(c)
|
||||
values = c.cfgimpl_get_values()
|
||||
settings = c.cfgimpl_get_settings()
|
||||
settings.remove('cache')
|
||||
c.u1
|
||||
api.property.pop('cache')
|
||||
api.option('u1').value.get()
|
||||
assert 'u1' not in values._p_.get_cached()
|
||||
assert 'u1' not in settings._p_.get_cached()
|
||||
|
||||
|
||||
def test_reset_cache_only():
|
||||
od1 = make_description()
|
||||
c = Config(od1)
|
||||
values = c.cfgimpl_get_values()
|
||||
settings = c.cfgimpl_get_settings()
|
||||
c.u1
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
c.cfgimpl_reset_cache(only=('values',))
|
||||
assert 'u1' not in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
c.u1
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
c.cfgimpl_reset_cache(only=('settings',))
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' not in settings._p_.get_cached()
|
||||
#def test_reset_cache_only():
|
||||
# od1 = make_description()
|
||||
# c = Config(od1)
|
||||
# api = getapi(c)
|
||||
# values = c.cfgimpl_get_values()
|
||||
# settings = c.cfgimpl_get_settings()
|
||||
# api.option('u1').value.get()
|
||||
# assert 'u1' in values._p_.get_cached()
|
||||
# assert 'u1' in settings._p_.get_cached()
|
||||
# c.cfgimpl_reset_cache(only=('values',))
|
||||
# assert 'u1' not in values._p_.get_cached()
|
||||
# assert 'u1' in settings._p_.get_cached()
|
||||
# api.option('u1').value.get()
|
||||
# assert 'u1' in values._p_.get_cached()
|
||||
# assert 'u1' in settings._p_.get_cached()
|
||||
# c.cfgimpl_reset_cache(only=('settings',))
|
||||
# assert 'u1' in values._p_.get_cached()
|
||||
# assert 'u1' not in settings._p_.get_cached()
|
||||
|
||||
|
||||
def test_force_cache():
|
||||
u1 = IntOption('u1', '', multi=True)
|
||||
u2 = IntOption('u2', '')
|
||||
u3 = IntOption('u3', '', multi=True)
|
||||
u4 = IntOption('u4', '', properties=('disabled',))
|
||||
od = OptionDescription('od1', '', [u1, u2, u3, u4])
|
||||
c = Config(od)
|
||||
c.cfgimpl_get_settings().remove('expire')
|
||||
|
||||
c.cfgimpl_get_values().force_cache()
|
||||
assert c.cfgimpl_get_values()._p_.get_cached() == {'u1': {None: ([], None)},
|
||||
'u2': {None: (None, None)},
|
||||
'u3': {None: ([], None)},
|
||||
'u4': {None: (None, None)}}
|
||||
assert c.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'validator', 'warnings']), None)},
|
||||
'u1': {None: (set(['empty']), None)},
|
||||
'u2': {None: (set([]), None)},
|
||||
'u3': {None: (set(['empty']), None)},
|
||||
'u4': {None: (set(['disabled']), None)}}
|
||||
c.read_only()
|
||||
|
||||
c.cfgimpl_get_values().force_cache()
|
||||
assert c.cfgimpl_get_values()._p_.get_cached() == {'u1': {None: ([], None)},
|
||||
'u2': {None: (None, None)},
|
||||
'u3': {None: ([], None)}}
|
||||
assert c.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'empty', 'everything_frozen', 'frozen', 'mandatory', 'validator', 'warnings']), None)},
|
||||
'u1': {None: (set(['empty']), None)},
|
||||
'u2': {None: (set([]), None)},
|
||||
'u3': {None: (set(['empty']), None)},
|
||||
'u4': {None: (set(['disabled']), None)}}
|
||||
|
||||
c.cfgimpl_get_settings().remove('cache')
|
||||
raises(ConfigError, "c.cfgimpl_get_values().force_cache()")
|
||||
#def test_force_cache():
|
||||
# u1 = IntOption('u1', '', multi=True)
|
||||
# u2 = IntOption('u2', '')
|
||||
# u3 = IntOption('u3', '', multi=True)
|
||||
# u4 = IntOption('u4', '', properties=('disabled',))
|
||||
# od = OptionDescription('od1', '', [u1, u2, u3, u4])
|
||||
# c = Config(od)
|
||||
# api = getapi(c)
|
||||
# api.property.read_write()
|
||||
# api.property.pop('expire')
|
||||
# api.property.pop('disabled')
|
||||
#
|
||||
# c.cfgimpl_get_values().force_cache()
|
||||
# assert c.cfgimpl_get_values()._p_.get_cached() == {'u1': {None: ([], None)},
|
||||
# 'u2': {None: (None, None)},
|
||||
# 'u3': {None: ([], None)},
|
||||
# 'u4': {None: (None, None)}}
|
||||
# assert c.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
# 'u1': {None: (set(['empty']), None)},
|
||||
# 'u2': {None: (set([]), None)},
|
||||
# 'u3': {None: (set(['empty']), None)},
|
||||
# 'u4': {None: (set(['disabled']), None)}}
|
||||
# api.property.read_only()
|
||||
#
|
||||
# c.cfgimpl_get_values().force_cache()
|
||||
# assert c.cfgimpl_get_values()._p_.get_cached() == {'u1': {None: ([], None)},
|
||||
# 'u2': {None: (None, None)},
|
||||
# 'u3': {None: ([], None)}}
|
||||
# assert c.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'empty', 'everything_frozen', 'frozen', 'mandatory', 'validator', 'warnings']), None)},
|
||||
# 'u1': {None: (set(['empty']), None)},
|
||||
# 'u2': {None: (set([]), None)},
|
||||
# 'u3': {None: (set(['empty']), None)},
|
||||
# 'u4': {None: (set(['disabled']), None)}}
|
||||
#
|
||||
# c.cfgimpl_get_settings().remove('cache')
|
||||
# raises(ConfigError, "c.cfgimpl_get_values().force_cache()")
|
||||
|
||||
|
||||
def test_cache_master_slave():
|
||||
|
|
@ -353,42 +372,56 @@ def test_cache_master_slave():
|
|||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
cfg.read_write()
|
||||
api = getapi(cfg)
|
||||
api.property.read_write()
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {}
|
||||
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {}
|
||||
#assert cfg.cfgimpl_get_settings()._p_.get_cached() == {}
|
||||
#
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append('192.168.1.2')
|
||||
cfg.ip_admin_eth0.ip_admin_eth0
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.get()
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()
|
||||
cache = cfg.cfgimpl_get_values()._p_.get_cached()
|
||||
assert set(cache.keys()) == set(['ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
|
||||
if TIRAMISU_VERSION == 2:
|
||||
assert set(cache.keys()) == set(['ip_admin_eth0.ip_admin_eth0'])
|
||||
else:
|
||||
assert set(cache.keys()) == set(['ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
|
||||
assert set(cache['ip_admin_eth0.ip_admin_eth0'].keys()) == set([None])
|
||||
assert cache['ip_admin_eth0.ip_admin_eth0'][None][0] == ['192.168.1.2']
|
||||
assert set(cache['ip_admin_eth0.netmask_admin_eth0'].keys()) == set([None])
|
||||
assert cache['ip_admin_eth0.netmask_admin_eth0'][None][0] == [None]
|
||||
#assert set(cache['ip_admin_eth0.netmask_admin_eth0'].keys()) == set([None])
|
||||
#assert cache['ip_admin_eth0.netmask_admin_eth0'][None][0] == [None]
|
||||
#assert cache['ip_admin_eth0.netmask_admin_eth0'][0][0] is None
|
||||
cache = cfg.cfgimpl_get_settings()._p_.get_cached()
|
||||
assert set(cache.keys()) == set([None, 'ip_admin_eth0', 'ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
|
||||
assert set(cache['ip_admin_eth0'].keys()) == set([None])
|
||||
assert set(cache['ip_admin_eth0.ip_admin_eth0'].keys()) == set([None])
|
||||
assert set(cache['ip_admin_eth0.netmask_admin_eth0'].keys()) == set([None, 0])
|
||||
if TIRAMISU_VERSION == 2:
|
||||
assert set(cache['ip_admin_eth0.netmask_admin_eth0'].keys()) == set([None, 0])
|
||||
else:
|
||||
assert set(cache['ip_admin_eth0.netmask_admin_eth0'].keys()) == set([0])
|
||||
#
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append('192.168.1.1')
|
||||
cfg.ip_admin_eth0.ip_admin_eth0
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1'])
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.get()
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()
|
||||
cache = cfg.cfgimpl_get_values()._p_.get_cached()
|
||||
assert set(cache.keys()) == set(['ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
|
||||
if TIRAMISU_VERSION == 2:
|
||||
assert set(cache.keys()) == set(['ip_admin_eth0.ip_admin_eth0'])
|
||||
else:
|
||||
assert set(cache.keys()) == set(['ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
|
||||
assert set(cache['ip_admin_eth0.ip_admin_eth0'].keys()) == set([None])
|
||||
assert cache['ip_admin_eth0.ip_admin_eth0'][None][0] == ['192.168.1.2', '192.168.1.1']
|
||||
assert set(cache['ip_admin_eth0.netmask_admin_eth0'].keys()) == set([None])
|
||||
assert cache['ip_admin_eth0.netmask_admin_eth0'][None][0] == [None, None]
|
||||
#assert set(cache['ip_admin_eth0.netmask_admin_eth0'].keys()) == set([None])
|
||||
#assert cache['ip_admin_eth0.netmask_admin_eth0'][None][0] == [None, None]
|
||||
#assert cache['ip_admin_eth0.netmask_admin_eth0'][0][0] is None
|
||||
#assert cache['ip_admin_eth0.netmask_admin_eth0'][1][0] is None
|
||||
cache = cfg.cfgimpl_get_settings()._p_.get_cached()
|
||||
assert set(cache.keys()) == set([None, 'ip_admin_eth0', 'ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
|
||||
assert set(cache['ip_admin_eth0'].keys()) == set([None])
|
||||
assert set(cache['ip_admin_eth0.ip_admin_eth0'].keys()) == set([None])
|
||||
assert set(cache['ip_admin_eth0.netmask_admin_eth0'].keys()) == set([None, 0, 1])
|
||||
if TIRAMISU_VERSION == 2:
|
||||
assert set(cache['ip_admin_eth0.netmask_admin_eth0'].keys()) == set([None, 0, 1])
|
||||
else:
|
||||
assert set(cache['ip_admin_eth0.netmask_admin_eth0'].keys()) == set([0, 1])
|
||||
#DEL, insert, ...
|
||||
|
||||
|
||||
|
|
@ -404,9 +437,11 @@ def test_cache_callback():
|
|||
val5 = StrOption('val5', "", callback=return_value, callback_params={'value': ('yes',)}, multi=True)
|
||||
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4, val5])
|
||||
cfg = Config(maconfig)
|
||||
cfg.cfgimpl_get_settings().remove('expire')
|
||||
cfg.read_write()
|
||||
cfg.cfgimpl_get_values().force_cache()
|
||||
api = getapi(cfg)
|
||||
api.property.read_write()
|
||||
if TIRAMISU_VERSION == 2:
|
||||
api.property.pop('expire')
|
||||
api.option.make_dict()
|
||||
#assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
# 'val1': {None: (set([]), None)}}
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1': {None: ('val', None)},
|
||||
|
|
@ -414,12 +449,12 @@ def test_cache_callback():
|
|||
'val3': {None: ('yes', None)},
|
||||
'val4': {None: ('val', None)},
|
||||
'val5': {None: (['yes'], None)}}
|
||||
cfg.val1 = 'new'
|
||||
api.option('val1').value.set('new')
|
||||
#assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
# 'val1': {None: (set([]), None)}}
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val3': {None: ('yes', None)},
|
||||
'val5': {None: (['yes'], None)}}
|
||||
cfg.cfgimpl_get_values().force_cache()
|
||||
api.option.make_dict()
|
||||
#assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
# 'val1': {None: (set([]), None)}}
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1': {None: ('new', None)},
|
||||
|
|
@ -427,7 +462,7 @@ def test_cache_callback():
|
|||
'val3': {None: ('yes', None)},
|
||||
'val4': {None: ('new', None)},
|
||||
'val5': {None: (['yes'], None)}}
|
||||
cfg.val3 = 'new2'
|
||||
api.option('val3').value.set('new2')
|
||||
#assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
# 'val1': {None: (set([]), None)},
|
||||
# 'val3': {None: (set([]), None)}}
|
||||
|
|
@ -435,7 +470,7 @@ def test_cache_callback():
|
|||
'val2': {None: ('new', None)},
|
||||
'val4': {None: ('new', None)},
|
||||
'val5': {None: (['yes'], None)}}
|
||||
cfg.cfgimpl_get_values().force_cache()
|
||||
api.option.make_dict()
|
||||
#assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
# 'val1': {None: (set([]), None)},
|
||||
# 'val3': {None: (set([]), None)}}
|
||||
|
|
@ -444,7 +479,7 @@ def test_cache_callback():
|
|||
'val3': {None: ('new2', None)},
|
||||
'val4': {None: ('new', None)},
|
||||
'val5': {None: (['yes'], None)}}
|
||||
cfg.val4 = 'new3'
|
||||
api.option('val4').value.set('new3')
|
||||
#assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
# 'val1': {None: (set([]), None)},
|
||||
# 'val3': {None: (set([]), None)},
|
||||
|
|
@ -453,7 +488,7 @@ def test_cache_callback():
|
|||
'val2': {None: ('new', None)},
|
||||
'val3': {None: ('new2', None)},
|
||||
'val5': {None: (['yes'], None)}}
|
||||
cfg.cfgimpl_get_values().force_cache()
|
||||
api.option.make_dict()
|
||||
#assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
# 'val1': {None: (set([]), None)},
|
||||
# 'val3': {None: (set([]), None)},
|
||||
|
|
@ -463,7 +498,7 @@ def test_cache_callback():
|
|||
'val3': {None: ('new2', None)},
|
||||
'val4': {None: ('new3', None)},
|
||||
'val5': {None: (['yes'], None)}}
|
||||
cfg.val5.append('new4')
|
||||
api.option('val5').value.set([undefined, 'new4'])
|
||||
#assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
# 'val1': {None: (set([]), None)},
|
||||
# 'val3': {None: (set([]), None)},
|
||||
|
|
@ -473,7 +508,7 @@ def test_cache_callback():
|
|||
'val2': {None: ('new', None)},
|
||||
'val3': {None: ('new2', None)},
|
||||
'val4': {None: ('new3', None)}}
|
||||
cfg.cfgimpl_get_values().force_cache()
|
||||
api.option.make_dict()
|
||||
#assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
# 'val1': {None: (set([]), None)},
|
||||
# 'val3': {None: (set([]), None)},
|
||||
|
|
@ -493,39 +528,76 @@ def test_cache_master_and_slaves_master():
|
|||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('rootconfig', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
cfg.cfgimpl_get_settings().remove('expire')
|
||||
cfg.read_write()
|
||||
cfg.cfgimpl_get_values().force_cache()
|
||||
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
'val1': {None: (set([]), None)},
|
||||
'val1.val1': {None: (set(['empty']), None)},
|
||||
'val1.val2': {None: (set([]), None)}}
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([], None)}, 'val1.val2': {None: ([], None)}}
|
||||
cfg.val1.val1.append()
|
||||
api = getapi(cfg)
|
||||
api.property.read_write()
|
||||
api.option.make_dict()
|
||||
global_props = ['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']
|
||||
val1_props = []
|
||||
val1_val1_props = ['empty']
|
||||
val1_val2_props = []
|
||||
if TIRAMISU_VERSION == 2:
|
||||
api.property.pop('expire')
|
||||
global_props = set(global_props)
|
||||
val1_props = set(val1_props)
|
||||
val1_val1_props = set(val1_val1_props)
|
||||
val1_val2_props = set(val1_val2_props)
|
||||
else:
|
||||
global_props = frozenset(global_props)
|
||||
val1_props = frozenset(val1_props)
|
||||
val1_val1_props = frozenset(val1_val1_props)
|
||||
val1_val2_props = frozenset(val1_val2_props)
|
||||
#None because no value
|
||||
idx_val2 = None
|
||||
if TIRAMISU_VERSION == 2:
|
||||
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {}
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {}
|
||||
else:
|
||||
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (global_props, None)},
|
||||
'val1': {None: (val1_props, None)},
|
||||
'val1.val1': {None: (val1_val1_props, None)},
|
||||
'val1.val2': {idx_val2: (val1_val2_props, None)}}
|
||||
# len is 0 so don't get any value
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([], None)}}
|
||||
#
|
||||
api.option('val1.val1').value.set([undefined])
|
||||
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
'val1': {None: (set([]), None)}}
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {}
|
||||
cfg.cfgimpl_get_values().force_cache()
|
||||
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
'val1': {None: (set([]), None)},
|
||||
'val1.val1': {None: (set(['empty']), None)},
|
||||
'val1.val2': {None: (set([]), None), 0: (set([]), None)}}
|
||||
api.option.make_dict()
|
||||
if TIRAMISU_VERSION == 2:
|
||||
val_val2 = [None]
|
||||
val_val2_props = {None: (set(), None), 0: (set(), None)}
|
||||
else:
|
||||
#has value
|
||||
idx_val2 = 0
|
||||
val_val2 = None
|
||||
val_val2_props = {idx_val2: (val1_val2_props, None)}
|
||||
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (global_props, None)},
|
||||
'val1': {None: (val1_props, None)},
|
||||
'val1.val1': {None: (val1_val1_props, None)},
|
||||
'val1.val2': val_val2_props}
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([None], None)},
|
||||
'val1.val2': {None: ([None], None)}}
|
||||
cfg.val1.val1.append()
|
||||
cfg.cfgimpl_get_values().force_cache()
|
||||
cfg.val1.val2[1] = 'oui'
|
||||
'val1.val2': {idx_val2: (val_val2, None)}}
|
||||
api.option('val1.val1').value.set([undefined, undefined])
|
||||
api.option.make_dict()
|
||||
api.option('val1.val2', 1).value.set('oui')
|
||||
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
'val1': {None: (set([]), None)}}
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {}
|
||||
cfg.cfgimpl_get_values().force_cache()
|
||||
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
'val1': {None: (set([]), None)},
|
||||
'val1.val1': {None: (set(['empty']), None)},
|
||||
#FIXME voir pourquoi ce None ... soit c'est index soit ca ne l'ai pas ...
|
||||
'val1.val2': {None: (set([]), None), 0: (set([]), None), 1: (set([]), None)}}
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([None, None], None)},
|
||||
'val1.val2': {None: ([None, 'oui'], None)}}
|
||||
if TIRAMISU_VERSION == 2:
|
||||
val1_val2_props = {None: (set([]), None), 0: (set([]), None), 1: (set([]), None)}
|
||||
else:
|
||||
val1_val2_props = {0: (frozenset([]), None), 1: (frozenset([]), None)}
|
||||
#assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (global_props, None)},
|
||||
# 'val1': {None: (val1_props, None)},
|
||||
# 'val1.val1': {None: (val1_val1_props, None)},
|
||||
# 'val1.val2': val1_val2_props}
|
||||
#if TIRAMISU_VERSION == 2:
|
||||
# assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([None, None], None)},
|
||||
# 'val1.val2': {None: ([None, 'oui'], None)}}
|
||||
#else:
|
||||
# assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([None, None], None)},
|
||||
# 'val1.val2': {0: (None, None), 1: ('oui', None)}}
|
||||
|
||||
|
||||
def test_cache_master_callback():
|
||||
|
|
@ -535,20 +607,39 @@ def test_cache_master_callback():
|
|||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('rootconfig', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
cfg.cfgimpl_get_settings().remove('expire')
|
||||
cfg.read_write()
|
||||
cfg.cfgimpl_get_values().force_cache()
|
||||
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
'val1': {None: (set([]), None)},
|
||||
'val1.val1': {None: (set(['empty']), None)},
|
||||
'val1.val2': {None: (set([]), None)}}
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([], None)}, 'val1.val2': {None: ([], None)}}
|
||||
cfg.val1.val1.append()
|
||||
api = getapi(cfg)
|
||||
api.property.read_write()
|
||||
api.option.make_dict()
|
||||
global_props = ['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']
|
||||
val1_props = []
|
||||
val1_val1_props = ['empty']
|
||||
val1_val2_props = []
|
||||
if TIRAMISU_VERSION == 2:
|
||||
api.property.pop('expire')
|
||||
global_props = set(global_props)
|
||||
val1_props = set(val1_props)
|
||||
val1_val1_props = set(val1_val1_props)
|
||||
val1_val2_props = set(val1_val2_props)
|
||||
else:
|
||||
global_props = frozenset(global_props)
|
||||
val1_props = frozenset(val1_props)
|
||||
val1_val1_props = frozenset(val1_val1_props)
|
||||
val1_val2_props = frozenset(val1_val2_props)
|
||||
if TIRAMISU_VERSION == 2:
|
||||
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {}
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {}
|
||||
else:
|
||||
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (global_props, None)},
|
||||
'val1': {None: (val1_props, None)},
|
||||
'val1.val1': {None: (val1_val1_props, None)},
|
||||
'val1.val2': {None: (val1_val2_props, None)}}
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([], None)}}
|
||||
api.option('val1.val1').value.set([undefined])
|
||||
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
'val1': {None: (set([]), None)}}
|
||||
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {}
|
||||
cfg.cfgimpl_get_values().force_cache()
|
||||
api.option.make_dict()
|
||||
#FIXMEassert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
# 'val1': {None: (set([]), None)}}
|
||||
#FIXMEassert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([None], None)},
|
||||
|
|
@ -556,56 +647,57 @@ def test_cache_master_callback():
|
|||
# }
|
||||
|
||||
|
||||
def test_cache_master_slave_different():
|
||||
b = IntOption('int', 'Test int option', default=[0], multi=True)
|
||||
c = StrOption('str', 'Test string option', multi=True)
|
||||
d = StrOption('str1', 'Test string option', requires=[{'option': c, 'expected': None, 'action': 'hidden', 'inverse': True}], multi=True)
|
||||
descr = MasterSlaves("int", "", [b, c, d])
|
||||
#descr.impl_set_group_type(groups.master)
|
||||
cfg = Config(descr)
|
||||
cfg.cfgimpl_get_settings().remove('expire')
|
||||
cfg.read_write()
|
||||
cfg.cfgimpl_get_values().force_cache()
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'int': {None: ([0], None)},
|
||||
'str': {None: ([None], None)},
|
||||
'str1': {None: ([None], None)}}
|
||||
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
'int': {None: (set(['empty']), None)},
|
||||
'str': {None: (set([]), None), 0: (set([]), None)},
|
||||
'str1': {None: (set([]), None), 0: (set([]), None)}}
|
||||
cfg.int = [0, 1]
|
||||
cfg.cfgimpl_get_values().force_cache()
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'int': {None: ([0, 1], None)},
|
||||
'str': {None: ([None, None], None)},
|
||||
'str1': {None: ([None, None], None)}}
|
||||
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
'int': {None: (set(['empty']), None)},
|
||||
'str': {None: (set([]), None), 0: (set([]), None), 1: (set([]), None)},
|
||||
'str1': {None: (set([]), None), 0: (set([]), None), 1: (set([]), None)}}
|
||||
|
||||
cfg.str = [None, '1']
|
||||
cfg.cfgimpl_get_values().force_cache()
|
||||
assert set(cfg.cfgimpl_get_values()._p_.get_cached().keys()) == set(['int', 'str', 'str1'])
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached()['int'] == {None: ([0, 1], None)}
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached()['str'] == {None: ([None, '1'], None)}
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached()['str1'][None][0][0] == None
|
||||
raises(PropertiesOptionError, "cfg.cfgimpl_get_values()._p_.get_cached()['str1'][None][0][1]")
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached()['str1'][None][1] == None
|
||||
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
'int': {None: (set(['empty']), None)},
|
||||
'str': {None: (set([]), None), 0: (set([]), None), 1: (set([]), None)},
|
||||
'str1': {None: (set([]), None), 0: (set([]), None), 1: (set(['hidden']), None)}}
|
||||
cfg.read_only()
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {}
|
||||
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {}
|
||||
cfg.cfgimpl_get_values().force_cache()
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'int': {None: ([0, 1], None)},
|
||||
'str': {None: ([None, '1'], None)},
|
||||
'str1': {None: ([None, None], None)}}
|
||||
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'everything_frozen', 'validator', 'warnings', 'empty', 'mandatory', ]), None)},
|
||||
'int': {None: (set(['empty']), None)},
|
||||
'str': {None: (set([]), None), 0: (set([]), None), 1: (set([]), None)},
|
||||
'str1': {None: (set([]), None), 0: (set([]), None), 1: (set(['hidden']), None)}}
|
||||
#def test_cache_master_slave_different():
|
||||
# b = IntOption('int', 'Test int option', default=[0], multi=True)
|
||||
# c = StrOption('str', 'Test string option', multi=True)
|
||||
# d = StrOption('str1', 'Test string option', requires=[{'option': c, 'expected': None, 'action': 'hidden', 'inverse': True}], multi=True)
|
||||
# descr = MasterSlaves("int", "", [b, c, d])
|
||||
# #descr.impl_set_group_type(groups.master)
|
||||
# cfg = Config(descr)
|
||||
# api = getapi(cfg)
|
||||
# api.property.read_write()
|
||||
# api.property.pop('expire')
|
||||
# api.option.make_dict()
|
||||
# assert cfg.cfgimpl_get_values()._p_.get_cached() == {'int': {None: ([0], None)},
|
||||
# 'str': {None: ([None], None)},
|
||||
# 'str1': {None: ([None], None)}}
|
||||
# assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
# 'int': {None: (set(['empty']), None)},
|
||||
# 'str': {None: (set([]), None), 0: (set([]), None)},
|
||||
# 'str1': {None: (set([]), None), 0: (set([]), None)}}
|
||||
# api.option('int').value.set([0, 1])
|
||||
# api.option.make_dict()
|
||||
# assert cfg.cfgimpl_get_values()._p_.get_cached() == {'int': {None: ([0, 1], None)},
|
||||
# 'str': {None: ([None, None], None)},
|
||||
# 'str1': {None: ([None, None], None)}}
|
||||
# assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
# 'int': {None: (set(['empty']), None)},
|
||||
# 'str': {None: (set([]), None), 0: (set([]), None), 1: (set([]), None)},
|
||||
# 'str1': {None: (set([]), None), 0: (set([]), None), 1: (set([]), None)}}
|
||||
#
|
||||
# api.option('str', 1).value.set('1')
|
||||
# api.option.make_dict()
|
||||
# assert set(cfg.cfgimpl_get_values()._p_.get_cached().keys()) == set(['int', 'str', 'str1'])
|
||||
# assert cfg.cfgimpl_get_values()._p_.get_cached()['int'] == {None: ([0, 1], None)}
|
||||
# assert cfg.cfgimpl_get_values()._p_.get_cached()['str'] == {None: ([None, '1'], None)}
|
||||
# assert cfg.cfgimpl_get_values()._p_.get_cached()['str1'][None][0][0] == None
|
||||
# raises(PropertiesOptionError, "cfg.cfgimpl_get_values()._p_.get_cached()['str1'][None][0][1]")
|
||||
# assert cfg.cfgimpl_get_values()._p_.get_cached()['str1'][None][1] == None
|
||||
# assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
# 'int': {None: (set(['empty']), None)},
|
||||
# 'str': {None: (set([]), None), 0: (set([]), None), 1: (set([]), None)},
|
||||
# 'str1': {None: (set([]), None), 0: (set([]), None), 1: (set(['hidden']), None)}}
|
||||
# api.property.read_only()
|
||||
# assert cfg.cfgimpl_get_values()._p_.get_cached() == {}
|
||||
# assert cfg.cfgimpl_get_settings()._p_.get_cached() == {}
|
||||
# api.option.make_dict()
|
||||
# assert cfg.cfgimpl_get_values()._p_.get_cached() == {'int': {None: ([0, 1], None)},
|
||||
# 'str': {None: ([None, '1'], None)},
|
||||
# 'str1': {None: ([None, None], None)}}
|
||||
# assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'everything_frozen', 'validator', 'warnings', 'empty', 'mandatory', ]), None)},
|
||||
# 'int': {None: (set(['empty']), None)},
|
||||
# 'str': {None: (set([]), None), 0: (set([]), None), 1: (set([]), None)},
|
||||
# 'str1': {None: (set([]), None), 0: (set([]), None), 1: (set(['hidden']), None)}}
|
||||
|
||||
|
||||
|
||||
|
|
@ -615,40 +707,46 @@ def test_cache_requires():
|
|||
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
||||
od = OptionDescription('service', '', [a, b])
|
||||
c = Config(od)
|
||||
c.cfgimpl_get_settings().remove('expire')
|
||||
c.read_write()
|
||||
assert c.cfgimpl_get_settings()._p_.get_cached() == {}
|
||||
api = getapi(c)
|
||||
api.property.read_write()
|
||||
if TIRAMISU_VERSION == 2:
|
||||
api.property.pop('expire')
|
||||
#assert c.cfgimpl_get_settings()._p_.get_cached() == {}
|
||||
assert c.cfgimpl_get_values()._p_.get_cached() == {}
|
||||
assert c.ip_address_service == None
|
||||
assert api.option('ip_address_service').value.get() == None
|
||||
assert c.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
'activate_service': {None: (set([]), None)},
|
||||
'ip_address_service': {None: (set([]), None)}}
|
||||
|
||||
assert c.cfgimpl_get_values()._p_.get_cached() == {'ip_address_service': {None: (None, None)}}
|
||||
c.cfgimpl_get_values().force_cache()
|
||||
if TIRAMISU_VERSION == 2:
|
||||
assert c.cfgimpl_get_values()._p_.get_cached() == {'ip_address_service': {None: (None, None)}}
|
||||
else:
|
||||
assert c.cfgimpl_get_values()._p_.get_cached() == {'ip_address_service': {None: (None, None)},
|
||||
'activate_service': {None: (True, None)}}
|
||||
api.option.make_dict()
|
||||
assert c.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
'activate_service': {None: (set([]), None)},
|
||||
'ip_address_service': {None: (set([]), None)}}
|
||||
|
||||
assert c.cfgimpl_get_values()._p_.get_cached() == {'ip_address_service': {None: (None, None)},
|
||||
'activate_service': {None: (True, None)}}
|
||||
c.ip_address_service = '1.1.1.1'
|
||||
api.option('ip_address_service').value.set('1.1.1.1')
|
||||
assert c.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
'activate_service': {None: (set([]), None)}}
|
||||
|
||||
assert c.cfgimpl_get_values()._p_.get_cached() == {'activate_service': {None: (True, None)}}
|
||||
c.cfgimpl_get_values().force_cache()
|
||||
api.option.make_dict()
|
||||
assert c.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
'activate_service': {None: (set([]), None)},
|
||||
'ip_address_service': {None: (set([]), None)}}
|
||||
|
||||
assert c.cfgimpl_get_values()._p_.get_cached() == {'ip_address_service': {None: ('1.1.1.1', None)},
|
||||
'activate_service': {None: (True, None)}}
|
||||
c.activate_service = False
|
||||
api.option('activate_service').value.set(False)
|
||||
assert c.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}}
|
||||
|
||||
assert c.cfgimpl_get_values()._p_.get_cached() == {}
|
||||
c.cfgimpl_get_values().force_cache()
|
||||
api.option.make_dict()
|
||||
assert c.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
'activate_service': {None: (set([]), None)},
|
||||
'ip_address_service': {None: (set(['disabled']), None)}}
|
||||
|
|
@ -662,23 +760,29 @@ def test_cache_global_properties():
|
|||
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
||||
od = OptionDescription('service', '', [a, b])
|
||||
c = Config(od)
|
||||
c.cfgimpl_get_settings().remove('expire')
|
||||
c.read_write()
|
||||
assert c.cfgimpl_get_settings()._p_.get_cached() == {}
|
||||
api = getapi(c)
|
||||
api.property.read_write()
|
||||
if TIRAMISU_VERSION == 2:
|
||||
api.property.pop('expire')
|
||||
#assert c.cfgimpl_get_settings()._p_.get_cached() == {}
|
||||
assert c.cfgimpl_get_values()._p_.get_cached() == {}
|
||||
assert c.ip_address_service == None
|
||||
assert api.option('ip_address_service').value.get() == None
|
||||
assert c.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
'activate_service': {None: (set([]), None)},
|
||||
'ip_address_service': {None: (set([]), None)}}
|
||||
|
||||
assert c.cfgimpl_get_values()._p_.get_cached() == {'ip_address_service': {None: (None, None)}}
|
||||
c.cfgimpl_get_settings().remove('disabled')
|
||||
assert c.ip_address_service == None
|
||||
if TIRAMISU_VERSION == 2:
|
||||
assert c.cfgimpl_get_values()._p_.get_cached() == {'ip_address_service': {None: (None, None)}}
|
||||
else:
|
||||
assert c.cfgimpl_get_values()._p_.get_cached() == {'ip_address_service': {None: (None, None)},
|
||||
'activate_service': {None: (True, None)}}
|
||||
api.property.pop('disabled')
|
||||
assert api.option('ip_address_service').value.get() == None
|
||||
assert c.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
'activate_service': {None: (set([]), None)},
|
||||
'ip_address_service': {None: (set([]), None)}}
|
||||
c.cfgimpl_get_settings().append('test')
|
||||
assert c.ip_address_service == None
|
||||
api.property.add('test')
|
||||
assert api.option('ip_address_service').value.get() == None
|
||||
assert c.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'frozen', 'hidden', 'validator', 'warnings', 'test']), None)},
|
||||
'activate_service': {None: (set([]), None)},
|
||||
'ip_address_service': {None: (set([]), None)}}
|
||||
|
|
@ -689,10 +793,13 @@ def test_callback_value_incr():
|
|||
val2 = IntOption('val2', "", callback=return_value, callback_params={'value': ((val1, False),)})
|
||||
maconfig = OptionDescription('rootconfig', '', [val1, val2])
|
||||
cfg = Config(maconfig)
|
||||
cfg.read_write()
|
||||
assert cfg.val1 == 1
|
||||
api = getapi(cfg)
|
||||
api.property.read_write()
|
||||
if TIRAMISU_VERSION != 2:
|
||||
api.property.add('expire')
|
||||
assert api.option('val1').value.get() == 1
|
||||
sleep(1)
|
||||
assert cfg.val2 == 1
|
||||
assert api.option('val2').value.get() == 1
|
||||
sleep(1)
|
||||
assert cfg.val1 == 2
|
||||
assert cfg.val2 == 2
|
||||
assert api.option('val1').value.get() == 2
|
||||
assert api.option('val2').value.get() == 2
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
# coding: utf-8
|
||||
from py.test import raises
|
||||
|
||||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
|
||||
|
|
@ -6,8 +8,8 @@ from tiramisu.setting import owners
|
|||
from tiramisu.option import ChoiceOption, StrOption, OptionDescription
|
||||
from tiramisu.config import Config
|
||||
from tiramisu.error import ConfigError
|
||||
|
||||
from py.test import raises
|
||||
from tiramisu import getapi, undefined
|
||||
from tiramisu.api import TIRAMISU_VERSION
|
||||
|
||||
|
||||
def return_val(val):
|
||||
|
|
@ -27,117 +29,175 @@ def return_error():
|
|||
|
||||
|
||||
def test_choiceoption():
|
||||
ch = ChoiceOption('ch', '', values=('val1', 'val2'))
|
||||
od = OptionDescription('od', '', [ch])
|
||||
cfg = Config(od)
|
||||
cfg.read_write()
|
||||
owner = cfg.cfgimpl_get_settings().getowner()
|
||||
assert cfg.getowner(ch) == owners.default
|
||||
cfg.ch = 'val1'
|
||||
assert cfg.getowner(ch) == owner
|
||||
del(cfg.ch)
|
||||
assert cfg.getowner(ch) == owners.default
|
||||
raises(ValueError, "cfg.ch='no'")
|
||||
assert cfg.getowner(ch) == owners.default
|
||||
assert ch.impl_get_values(cfg) == ('val1', 'val2')
|
||||
choice = ChoiceOption('choice', '', values=('val1', 'val2'))
|
||||
odesc = OptionDescription('od', '', [choice])
|
||||
cfg = Config(odesc)
|
||||
api = getapi(cfg)
|
||||
api.property.read_write()
|
||||
owner = api.owner.get()
|
||||
assert api.option('choice').owner.get() == owners.default
|
||||
assert api.option('choice').owner.isdefault()
|
||||
#
|
||||
api.option('choice').value.set('val1')
|
||||
assert api.option('choice').owner.get() == owner
|
||||
assert not api.option('choice').owner.isdefault()
|
||||
#
|
||||
api.option('choice').value.reset()
|
||||
assert api.option('choice').owner.get() == owners.default
|
||||
assert api.option('choice').owner.isdefault()
|
||||
#
|
||||
raises(ValueError, "api.option('choice').value.set('no')")
|
||||
assert api.option('choice').owner.get() == owners.default
|
||||
assert api.option('choice').owner.isdefault()
|
||||
#
|
||||
assert api.option('choice').value.list() == ('val1', 'val2')
|
||||
|
||||
|
||||
def test_choiceoption_function():
|
||||
ch = ChoiceOption('ch', '', values=return_list)
|
||||
od = OptionDescription('od', '', [ch])
|
||||
cfg = Config(od)
|
||||
cfg.read_write()
|
||||
owner = cfg.cfgimpl_get_settings().getowner()
|
||||
assert cfg.getowner(ch) == owners.default
|
||||
cfg.ch = 'val1'
|
||||
assert cfg.getowner(ch) == owner
|
||||
del(cfg.ch)
|
||||
assert cfg.getowner(ch) == owners.default
|
||||
raises(ValueError, "cfg.ch='no'")
|
||||
assert cfg.getowner(ch) == owners.default
|
||||
assert ch.impl_get_values(None) == []
|
||||
assert ch.impl_get_values(cfg) == ['val1', 'val2']
|
||||
choice = ChoiceOption('choice', '', values=return_list)
|
||||
odesc = OptionDescription('od', '', [choice])
|
||||
cfg = Config(odesc)
|
||||
api = getapi(cfg)
|
||||
api.property.read_write()
|
||||
owner = api.owner.get()
|
||||
assert api.option('choice').owner.isdefault()
|
||||
#
|
||||
api.option('choice').value.set('val1')
|
||||
assert api.option('choice').owner.get() == owner
|
||||
#
|
||||
api.option('choice').value.reset()
|
||||
assert api.option('choice').owner.isdefault()
|
||||
#
|
||||
raises(ValueError, "api.option('choice').value.set('no')")
|
||||
assert api.option('choice').owner.isdefault()
|
||||
#
|
||||
assert api.option('choice').value.list() == ['val1', 'val2']
|
||||
|
||||
|
||||
def test_choiceoption_function_error():
|
||||
ch = ChoiceOption('ch', '', values=return_error)
|
||||
od = OptionDescription('od', '', [ch])
|
||||
cfg = Config(od)
|
||||
cfg.read_write()
|
||||
raises(Exception, "cfg.ch = 'no'")
|
||||
choice = ChoiceOption('choice', '', values=return_error)
|
||||
odesc = OptionDescription('od', '', [choice])
|
||||
cfg = Config(odesc)
|
||||
api = getapi(cfg)
|
||||
api.property.read_write()
|
||||
raises(ConfigError, "api.option('choice').value.set('val1')")
|
||||
|
||||
|
||||
def test_choiceoption_calc_function():
|
||||
ch = ChoiceOption('ch', "", values=return_calc_list, values_params={'': ('val1',)})
|
||||
od = OptionDescription('od', '', [ch])
|
||||
cfg = Config(od)
|
||||
cfg.read_write()
|
||||
owner = cfg.cfgimpl_get_settings().getowner()
|
||||
assert cfg.getowner(ch) == owners.default
|
||||
cfg.ch = 'val1'
|
||||
assert cfg.getowner(ch) == owner
|
||||
del(cfg.ch)
|
||||
assert cfg.getowner(ch) == owners.default
|
||||
raises(ValueError, "cfg.ch='no'")
|
||||
assert cfg.getowner(ch) == owners.default
|
||||
choice = ChoiceOption('choice', "", values=return_calc_list, values_params={'': ('val1',)})
|
||||
odesc = OptionDescription('od', '', [choice])
|
||||
cfg = Config(odesc)
|
||||
api = getapi(cfg)
|
||||
api.property.read_write()
|
||||
owner = api.owner.get()
|
||||
assert api.option('choice').owner.isdefault()
|
||||
#
|
||||
api.option('choice').value.set('val1')
|
||||
assert api.option('choice').owner.get() == owner
|
||||
#
|
||||
api.option('choice').value.reset()
|
||||
assert api.option('choice').owner.isdefault()
|
||||
#
|
||||
raises(ValueError, "api.option('choice').value.set('no')")
|
||||
assert api.option('choice').owner.isdefault()
|
||||
|
||||
|
||||
def test_choiceoption_calc_opt_function():
|
||||
st = StrOption('st', '', 'val1')
|
||||
ch = ChoiceOption('ch', "", values=return_calc_list, values_params={'': ((st, False),)})
|
||||
od = OptionDescription('od', '', [st, ch])
|
||||
cfg = Config(od)
|
||||
cfg.read_write()
|
||||
owner = cfg.cfgimpl_get_settings().getowner()
|
||||
assert cfg.getowner(ch) == owners.default
|
||||
cfg.ch = 'val1'
|
||||
assert cfg.getowner(ch) == owner
|
||||
del(cfg.ch)
|
||||
assert cfg.getowner(ch) == owners.default
|
||||
raises(ValueError, "cfg.ch='no'")
|
||||
assert cfg.getowner(ch) == owners.default
|
||||
str_ = StrOption('str', '', 'val1')
|
||||
choice = ChoiceOption('choice',
|
||||
"",
|
||||
values=return_calc_list,
|
||||
values_params={'': ((str_, False),)})
|
||||
odesc = OptionDescription('od', '', [str_, choice])
|
||||
cfg = Config(odesc)
|
||||
api = getapi(cfg)
|
||||
api.property.read_write()
|
||||
owner = api.owner.get()
|
||||
assert api.option('choice').owner.isdefault()
|
||||
#
|
||||
api.option('choice').value.set('val1')
|
||||
assert api.option('choice').owner.get() == owner
|
||||
#
|
||||
api.option('choice').value.reset()
|
||||
assert api.option('choice').owner.isdefault()
|
||||
#
|
||||
raises(ValueError, "api.option('choice').value.set('no')")
|
||||
assert api.option('choice').owner.isdefault()
|
||||
|
||||
|
||||
def test_choiceoption_calc_opt_function_propertyerror():
|
||||
st = StrOption('st', '', 'val1', properties=('disabled',))
|
||||
ch = ChoiceOption('ch', "", values=return_calc_list, values_params={'': ((st, False),)})
|
||||
od = OptionDescription('od', '', [st, ch])
|
||||
cfg = Config(od)
|
||||
cfg.read_write()
|
||||
raises(ValueError, "cfg.ch='no'")
|
||||
str_ = StrOption('str', '', 'val1', properties=('disabled',))
|
||||
choice = ChoiceOption('choice',
|
||||
"",
|
||||
values=return_calc_list,
|
||||
values_params={'': ((str_, False),)})
|
||||
odesc = OptionDescription('od', '', [str_, choice])
|
||||
cfg = Config(odesc)
|
||||
api = getapi(cfg)
|
||||
api.property.read_write()
|
||||
if TIRAMISU_VERSION == 2:
|
||||
raises(ValueError, "api.option('choice').value.set('no')")
|
||||
else:
|
||||
raises(ConfigError, "api.option('choice').value.set('no')")
|
||||
|
||||
|
||||
def test_choiceoption_calc_opt_multi_function():
|
||||
st = StrOption('st', '', ['val1'], multi=True)
|
||||
ch = ChoiceOption('ch', "", default_multi='val2', values=return_val, values_params={'': ((st, False),)}, multi=True)
|
||||
ch2 = ChoiceOption('ch2', "", default=['val2'], values=return_val, values_params={'': ((st, False),)}, multi=True)
|
||||
od = OptionDescription('od', '', [st, ch, ch2])
|
||||
cfg = Config(od)
|
||||
cfg.read_write()
|
||||
assert cfg.ch == []
|
||||
owner = cfg.cfgimpl_get_settings().getowner()
|
||||
assert cfg.getowner(ch) == owners.default
|
||||
raises(ValueError, "cfg.ch.append()")
|
||||
cfg.ch = ['val1']
|
||||
assert cfg.getowner(ch) == owner
|
||||
del(cfg.ch)
|
||||
assert cfg.getowner(ch) == owners.default
|
||||
raises(ValueError, "cfg.ch='no'")
|
||||
assert cfg.getowner(ch) == owners.default
|
||||
str_ = StrOption('str', '', ['val1'], multi=True)
|
||||
choice = ChoiceOption('choice',
|
||||
"",
|
||||
default_multi='val2',
|
||||
values=return_val,
|
||||
values_params={'': ((str_, False),)},
|
||||
multi=True)
|
||||
ch2 = ChoiceOption('ch2',
|
||||
"",
|
||||
default=['val2'],
|
||||
values=return_val,
|
||||
values_params={'': ((str_, False),)},
|
||||
multi=True)
|
||||
odesc = OptionDescription('od', '', [str_, choice, ch2])
|
||||
cfg = Config(odesc)
|
||||
api = getapi(cfg)
|
||||
api.property.read_write()
|
||||
owner = api.owner.get()
|
||||
assert api.option('choice').owner.isdefault()
|
||||
assert api.option('choice').value.get() == []
|
||||
#
|
||||
raises(ValueError, "cfg.ch2")
|
||||
api.option('choice').value.set(['val1'])
|
||||
assert api.option('choice').owner.get() == owner
|
||||
#
|
||||
raises(ValueError, "api.option('choice').value.set([undefined])")
|
||||
#
|
||||
api.option('choice').value.set(['val1'])
|
||||
assert api.option('choice').owner.get() == owner
|
||||
#
|
||||
api.option('choice').value.reset()
|
||||
assert api.option('choice').owner.isdefault()
|
||||
#
|
||||
raises(ValueError, "api.option('choice').value.set('no')")
|
||||
assert api.option('choice').owner.isdefault()
|
||||
#
|
||||
raises(ValueError, "api.option('ch2').value.get()")
|
||||
|
||||
|
||||
def test_choiceoption_calc_invalid():
|
||||
st = StrOption('st', '', ['val1'], multi=True)
|
||||
st
|
||||
raises(ValueError, "ch = ChoiceOption('ch', '', default_multi='val2', values=[1, 2, 3], values_params={'': ((st, False),)}, multi=True)")
|
||||
str_ = StrOption('str', '', ['val1'], multi=True)
|
||||
str_
|
||||
raises(ValueError,
|
||||
"choice = ChoiceOption('choice', '', default_multi='val2', values=[1, 2, 3], \
|
||||
values_params={'': ((str_, False),)}, multi=True)")
|
||||
|
||||
|
||||
def test_choiceoption_calc_not_list():
|
||||
st = StrOption('st', '', 'val1')
|
||||
ch = ChoiceOption('ch', "", default_multi='val2', values=return_val, values_params={'': ((st, False),)}, multi=True)
|
||||
od = OptionDescription('od', '', [st, ch])
|
||||
cfg = Config(od)
|
||||
cfg.read_write()
|
||||
raises(ConfigError, "cfg.ch = ['val1']")
|
||||
str_ = StrOption('str', '', 'val1')
|
||||
choice = ChoiceOption('choice',
|
||||
"",
|
||||
default_multi='val2',
|
||||
values=return_val,
|
||||
values_params={'': ((str_, False),)},
|
||||
multi=True)
|
||||
odesc = OptionDescription('od', '', [str_, choice])
|
||||
cfg = Config(odesc)
|
||||
api = getapi(cfg)
|
||||
api.property.read_write()
|
||||
raises(ConfigError, "api.option('choice').value.set(['val1'])")
|
||||
|
|
|
|||
|
|
@ -2,17 +2,17 @@
|
|||
|
||||
"""theses tests are much more to test that config, option description, vs...
|
||||
**it's there** and answers via attribute access"""
|
||||
from py.test import raises
|
||||
import weakref
|
||||
|
||||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
|
||||
from py.test import raises
|
||||
|
||||
from tiramisu.config import Config, SubConfig
|
||||
from tiramisu.option import IntOption, FloatOption, StrOption, ChoiceOption, \
|
||||
BoolOption, UnicodeOption, OptionDescription
|
||||
from tiramisu.i18n import _
|
||||
from tiramisu.error import ConflictError, ConfigError, PropertiesOptionError
|
||||
import weakref
|
||||
from tiramisu import Config, IntOption, FloatOption, StrOption, ChoiceOption, \
|
||||
BoolOption, UnicodeOption, OptionDescription, getapi, undefined
|
||||
from tiramisu.error import ConflictError, ConfigError, PropertiesOptionError, APIError
|
||||
|
||||
|
||||
def make_description():
|
||||
|
|
@ -37,16 +37,17 @@ def make_description():
|
|||
return descr
|
||||
|
||||
|
||||
#def test_base_config():
|
||||
# """making a :class:`tiramisu.config.Config()` object
|
||||
# and a :class:`tiramisu.option.OptionDescription()` object
|
||||
# """
|
||||
# gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
# descr = OptionDescription('tiramisu', '', [gcdummy])
|
||||
# cfg = Config(descr)
|
||||
# assert cfg.dummy is False
|
||||
# dm = cfg.unwrap_from_path('dummy')
|
||||
# assert dm.impl_getname() == 'dummy'
|
||||
def test_base_config():
|
||||
"""making a :class:`tiramisu.config.Config()` object
|
||||
and a :class:`tiramisu.option.OptionDescription()` object
|
||||
"""
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
descr = OptionDescription('tiramisu', '', [gcdummy])
|
||||
cfg = Config(descr)
|
||||
api = getapi(cfg)
|
||||
assert api.option('dummy').value.get() is False
|
||||
#dmo = cfg.unwrap_from_path('dummy')
|
||||
#assert dmo.impl_getname() == 'dummy'
|
||||
|
||||
|
||||
def test_base_config_name():
|
||||
|
|
@ -61,96 +62,81 @@ def test_not_config():
|
|||
assert raises(TypeError, "Config('str')")
|
||||
|
||||
|
||||
def test_base_path():
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
descr = OptionDescription('tiramisu', '', [gcdummy])
|
||||
cfg = Config(descr)
|
||||
assert cfg._impl_path is None
|
||||
base = OptionDescription('config', '', [descr])
|
||||
cfg = Config(base)
|
||||
assert cfg._impl_path is None
|
||||
assert cfg.tiramisu._impl_path == 'tiramisu'
|
||||
nbase = OptionDescription('baseconfig', '', [base])
|
||||
cfg = Config(nbase)
|
||||
assert cfg._impl_path is None
|
||||
assert cfg.config._impl_path == 'config'
|
||||
assert cfg.config.tiramisu._impl_path == 'config.tiramisu'
|
||||
#
|
||||
#
|
||||
#def test_reset_value():
|
||||
# descr = make_description()
|
||||
#def test_base_path():
|
||||
# gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
# descr = OptionDescription('tiramisu', '', [gcdummy])
|
||||
# cfg = Config(descr)
|
||||
# assert cfg.gc.dummy is False
|
||||
# cfg.gc.dummy = True
|
||||
# assert cfg.gc.dummy is True
|
||||
#
|
||||
#
|
||||
#def test_base_config_and_groups():
|
||||
# descr = make_description()
|
||||
# # overrides the booloption default value
|
||||
# config = Config(descr)
|
||||
# config.bool = False
|
||||
# assert config.gc.name == 'ref'
|
||||
# assert config.bool is False
|
||||
# nm = config.unwrap_from_path('gc.name')
|
||||
# assert nm.impl_getname() == 'name'
|
||||
# gc = config.unwrap_from_path('gc')
|
||||
# assert gc.impl_getname() == 'gc'
|
||||
# #nm = config.unwrap_from_name('name')
|
||||
# #assert nm.impl_getname() == 'name'
|
||||
# assert cfg._impl_path is None
|
||||
# base = OptionDescription('config', '', [descr])
|
||||
# cfg = Config(base)
|
||||
# assert cfg._impl_path is None
|
||||
# assert cfg.getattr('tiramisu', None, validate_properties=False)._impl_path == 'tiramisu'
|
||||
# nbase = OptionDescription('baseconfig', '', [base])
|
||||
# cfg = Config(nbase)
|
||||
# assert cfg._impl_path is None
|
||||
# assert cfg.getattr('config', None, validate_properties=False)._impl_path == 'config'
|
||||
# assert cfg.getattr('config.tiramisu', None, validate_properties=False)._impl_path == 'config.tiramisu'
|
||||
|
||||
|
||||
def test_base_config_force_permissive():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
config.read_write()
|
||||
config.cfgimpl_get_settings().setpermissive(('hidden',))
|
||||
raises(PropertiesOptionError, "config.getattr('boolop')")
|
||||
assert config.getattr('boolop', force_permissive=True) is True
|
||||
api = getapi(config)
|
||||
api.property.read_write()
|
||||
api.permissive.set(frozenset(['hidden']))
|
||||
raises(PropertiesOptionError, "api.option('boolop').value.get()")
|
||||
assert api.forcepermissive.option('boolop').value.get() is True
|
||||
|
||||
|
||||
def test_base_config_in_a_tree():
|
||||
"how options are organized into a tree, see :ref:`tree`"
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
config.bool = False
|
||||
assert config.gc.name == 'ref'
|
||||
config.gc.name = 'framework'
|
||||
assert config.gc.name == 'framework'
|
||||
assert getattr(config, "gc.name") == 'framework'
|
||||
|
||||
assert config.objspace == 'std'
|
||||
config.objspace = 'thunk'
|
||||
assert config.objspace == 'thunk'
|
||||
|
||||
assert config.gc.float == 2.3
|
||||
assert config.int == 0
|
||||
config.gc.float = 3.4
|
||||
config.int = 123
|
||||
assert config.gc.float == 3.4
|
||||
assert config.int == 123
|
||||
|
||||
assert not config.wantref
|
||||
|
||||
assert config.str == "abc"
|
||||
config.str = "def"
|
||||
assert config.str == "def"
|
||||
|
||||
raises(AttributeError, 'config.gc.foo = "bar"')
|
||||
|
||||
api = getapi(config)
|
||||
#
|
||||
api.option('bool').value.set(False)
|
||||
#
|
||||
assert api.option('gc.name').value.get() == 'ref'
|
||||
api.option('gc.name').value.set('framework')
|
||||
assert api.option('gc.name').value.get() == 'framework'
|
||||
#
|
||||
assert api.option('objspace').value.get() == 'std'
|
||||
api.option('objspace').value.set('thunk')
|
||||
assert api.option('objspace').value.get() == 'thunk'
|
||||
#
|
||||
assert api.option('gc.float').value.get() == 2.3
|
||||
api.option('gc.float').value.set(3.4)
|
||||
assert api.option('gc.float').value.get() == 3.4
|
||||
#
|
||||
assert api.option('int').value.get() == 0
|
||||
api.option('int').value.set(123)
|
||||
assert api.option('int').value.get() == 123
|
||||
#
|
||||
assert api.option('wantref').value.get() is False
|
||||
api.option('wantref').value.set(True)
|
||||
assert api.option('wantref').value.get() is True
|
||||
#
|
||||
assert api.option('str').value.get() == 'abc'
|
||||
api.option('str').value.set('def')
|
||||
assert api.option('str').value.get() == 'def'
|
||||
#
|
||||
raises(AttributeError, "api.option('gc.foo').value.get()")
|
||||
##
|
||||
config = Config(descr)
|
||||
config.bool = False
|
||||
assert config.gc.name == 'ref'
|
||||
config.wantframework = True
|
||||
api = getapi(config)
|
||||
assert api.option('bool').value.get() is True
|
||||
assert api.option('gc.name').value.get() == 'ref'
|
||||
assert api.option('wantframework').value.get() is False
|
||||
|
||||
|
||||
def test_cfgimpl_get_home_by_path():
|
||||
" :meth:`tiramisu.config.SubConfig.cfgimpl_get_home_by_path()` to retrieve a path"
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
config.bool = False
|
||||
assert config.cfgimpl_get_home_by_path('gc.dummy')[1] == 'dummy'
|
||||
assert config.cfgimpl_get_home_by_path('dummy')[1] == 'dummy'
|
||||
#def test_cfgimpl_get_home_by_path():
|
||||
# " :meth:`tiramisu.config.SubConfig.cfgimpl_get_home_by_path()` to retrieve a path"
|
||||
# descr = make_description()
|
||||
# config = Config(descr)
|
||||
# api = getapi(config)
|
||||
# api.option('bool').value.set(False)
|
||||
# assert config.cfgimpl_get_home_by_path('gc.dummy', None)[1] == 'dummy'
|
||||
# assert config.cfgimpl_get_home_by_path('dummy', None)[1] == 'dummy'
|
||||
|
||||
|
||||
def test_not_valid_properties():
|
||||
|
|
@ -160,21 +146,25 @@ def test_not_valid_properties():
|
|||
def test_information_config():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
api = getapi(config)
|
||||
string = 'some informations'
|
||||
config.impl_set_information('info', string)
|
||||
assert config.impl_get_information('info') == string
|
||||
raises(ValueError, "config.impl_get_information('noinfo')")
|
||||
assert config.impl_get_information('noinfo', 'default') == 'default'
|
||||
config.impl_del_information('info')
|
||||
raises(ValueError, "config.impl_get_information('info')")
|
||||
raises(ValueError, "config.impl_del_information('noinfo')")
|
||||
#
|
||||
api.information.set('info', string)
|
||||
assert api.information.get('info') == string
|
||||
#
|
||||
raises(ValueError, "api.information.get('noinfo')")
|
||||
assert api.information.get('noinfo', 'default') == 'default'
|
||||
api.information.reset('info')
|
||||
raises(ValueError, "api.information.get('info')")
|
||||
raises(ValueError, "api.information.reset('noinfo')")
|
||||
|
||||
|
||||
def test_config_impl_get_path_by_opt():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
dummy = config.unwrap_from_path('gc.dummy')
|
||||
boo = config.unwrap_from_path('bool')
|
||||
api = getapi(config)
|
||||
dummy = api.option.get('gc.dummy')
|
||||
boo = api.option.get('bool')
|
||||
unknown = IntOption('test', '')
|
||||
unknown
|
||||
assert config.cfgimpl_get_description().impl_get_path_by_opt(boo) == 'bool'
|
||||
|
|
@ -182,44 +172,42 @@ def test_config_impl_get_path_by_opt():
|
|||
raises(AttributeError, "config.cfgimpl_get_description().impl_get_path_by_opt(unknown)")
|
||||
|
||||
|
||||
def test_config_impl_get_path_by_opt_od():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
dummy = config.unwrap_from_path('gc.dummy')
|
||||
dummy
|
||||
raises(ConfigError, "config.cfgimpl_get_description().gc.impl_get_path_by_opt(dummy)")
|
||||
#def test_config_impl_get_path_by_opt_od():
|
||||
# descr = make_description()
|
||||
# config = Config(descr)
|
||||
# api = getapi(config)
|
||||
# dummy = api.option.get('gc.dummy')
|
||||
# dummy
|
||||
# raises(ConfigError, "config.getattr('gc', None).cfgimpl_get_description().impl_get_path_by_opt(dummy)")
|
||||
#
|
||||
#
|
||||
#def test_config_impl_get_opt_by_path():
|
||||
# descr = make_description()
|
||||
# config = Config(descr)
|
||||
# api = getapi(config)
|
||||
# dummy = api.option.get('gc.dummy')
|
||||
# boo = api.option.get('bool')
|
||||
# assert config.cfgimpl_get_description().impl_get_opt_by_path('bool') == boo
|
||||
# assert config.cfgimpl_get_description().impl_get_opt_by_path('gc.dummy') == dummy
|
||||
# raises(AttributeError, "config.cfgimpl_get_description().impl_get_opt_by_path('gc.unknown')")
|
||||
# raises(ConfigError, "config.getattr('gc', None).cfgimpl_get_description().impl_get_opt_by_path('gc.unknown')")
|
||||
|
||||
|
||||
def test_config_impl_get_opt_by_path():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
dummy = config.unwrap_from_path('gc.dummy')
|
||||
boo = config.unwrap_from_path('bool')
|
||||
if 'id' in dir(boo):
|
||||
assert config.cfgimpl_get_description().impl_get_opt_by_path('bool').id == boo.id
|
||||
assert config.cfgimpl_get_description().impl_get_opt_by_path('gc.dummy').id == dummy.id
|
||||
else:
|
||||
assert config.cfgimpl_get_description().impl_get_opt_by_path('bool') == boo
|
||||
assert config.cfgimpl_get_description().impl_get_opt_by_path('gc.dummy') == dummy
|
||||
raises(AttributeError, "config.cfgimpl_get_description().impl_get_opt_by_path('gc.unknown')")
|
||||
raises(ConfigError, "config.gc.cfgimpl_get_description().impl_get_opt_by_path('gc.unknown')")
|
||||
|
||||
|
||||
def test_information_display():
|
||||
g1 = IntOption('g1', '', 1)
|
||||
g2 = StrOption('g2', '', 'héhé')
|
||||
g3 = UnicodeOption('g3', '', u'héhé')
|
||||
g4 = BoolOption('g4', '', True)
|
||||
g5 = StrOption('g5', '')
|
||||
d1 = OptionDescription('od', '', [g1, g2, g3, g4, g5])
|
||||
root = OptionDescription('root', '', [d1])
|
||||
config = Config(root)
|
||||
config.od == """g1 = 1
|
||||
g2 = héhé
|
||||
g3 = héhé
|
||||
g4 = True
|
||||
g5 = None"""
|
||||
config == '[od]'
|
||||
#def test_information_display():
|
||||
# g1 = IntOption('g1', '', 1)
|
||||
# g2 = StrOption('g2', '', 'héhé')
|
||||
# g3 = UnicodeOption('g3', '', u'héhé')
|
||||
# g4 = BoolOption('g4', '', True)
|
||||
# g5 = StrOption('g5', '')
|
||||
# d1 = OptionDescription('od', '', [g1, g2, g3, g4, g5])
|
||||
# root = OptionDescription('root', '', [d1])
|
||||
# config = Config(root)
|
||||
# assert str(config.od) == """g1 = 1
|
||||
#g2 = héhé
|
||||
#g3 = héhé
|
||||
#g4 = True
|
||||
#g5 = None"""
|
||||
# assert str(config) == '[od]'
|
||||
|
||||
|
||||
def test_get_modified_values():
|
||||
|
|
@ -232,48 +220,50 @@ def test_get_modified_values():
|
|||
d1 = OptionDescription('od', '', [g1, g2, g3, g4, g5, g6])
|
||||
root = OptionDescription('root', '', [d1])
|
||||
config = Config(root)
|
||||
api = getapi(config)
|
||||
assert config.cfgimpl_get_values().get_modified_values() == {}
|
||||
config.od.g5 = 'yes'
|
||||
api.option('od.g5').value.set('yes')
|
||||
assert config.cfgimpl_get_values().get_modified_values() == {'od.g5': ('user', 'yes')}
|
||||
config.od.g4 = True
|
||||
api.option('od.g4').value.set(True)
|
||||
assert config.cfgimpl_get_values().get_modified_values() == {'od.g5': ('user', 'yes'), 'od.g4': ('user', True)}
|
||||
del config.od.g4
|
||||
api.option('od.g4').value.reset()
|
||||
assert config.cfgimpl_get_values().get_modified_values() == {'od.g5': ('user', 'yes')}
|
||||
config.od.g6.append()
|
||||
api.option('od.g6').value.set([undefined])
|
||||
assert config.cfgimpl_get_values().get_modified_values() == {'od.g5': ('user', 'yes'), 'od.g6': ('user', (None,))}
|
||||
config.od.g6.pop(0)
|
||||
api.option('od.g6').value.set([])
|
||||
assert config.cfgimpl_get_values().get_modified_values() == {'od.g5': ('user', 'yes'), 'od.g6': ('user', tuple())}
|
||||
config.od.g6.append('3')
|
||||
api.option('od.g6').value.set(['3'])
|
||||
assert config.cfgimpl_get_values().get_modified_values() == {'od.g5': ('user', 'yes'), 'od.g6': ('user', ('3',))}
|
||||
del config.od.g6[0]
|
||||
api.option('od.g6').value.set([])
|
||||
assert config.cfgimpl_get_values().get_modified_values() == {'od.g5': ('user', 'yes'), 'od.g6': ('user', tuple())}
|
||||
|
||||
|
||||
def test_has_value():
|
||||
g1 = IntOption('g1', '', 1)
|
||||
g2 = StrOption('g2', '', 'héhé')
|
||||
g3 = UnicodeOption('g3', '', u'héhé')
|
||||
g4 = BoolOption('g4', '', True)
|
||||
g5 = StrOption('g5', '')
|
||||
d1 = OptionDescription('od', '', [g1, g2, g3, g4, g5])
|
||||
root = OptionDescription('root', '', [d1])
|
||||
config = Config(root)
|
||||
assert not g5 in config.cfgimpl_get_values()
|
||||
config.od.g5 = 'yes'
|
||||
assert g5 in config.cfgimpl_get_values()
|
||||
#def test_has_value():
|
||||
# g1 = IntOption('g1', '', 1)
|
||||
# g2 = StrOption('g2', '', 'héhé')
|
||||
# g3 = UnicodeOption('g3', '', u'héhé')
|
||||
# g4 = BoolOption('g4', '', True)
|
||||
# g5 = StrOption('g5', '')
|
||||
# d1 = OptionDescription('od', '', [g1, g2, g3, g4, g5])
|
||||
# root = OptionDescription('root', '', [d1])
|
||||
# config = Config(root)
|
||||
# api = getapi(config)
|
||||
# assert not g5 in config.cfgimpl_get_values()
|
||||
# api.option('od.g5').value.set('yes')
|
||||
# assert g5 in config.cfgimpl_get_values()
|
||||
|
||||
|
||||
def test_values_not_setitem():
|
||||
g1 = IntOption('g1', '', 1)
|
||||
g2 = StrOption('g2', '', 'héhé')
|
||||
g3 = UnicodeOption('g3', '', u'héhé')
|
||||
g4 = BoolOption('g4', '', True)
|
||||
g5 = StrOption('g5', '')
|
||||
d1 = OptionDescription('od', '', [g1, g2, g3, g4, g5])
|
||||
root = OptionDescription('root', '', [d1])
|
||||
config = Config(root)
|
||||
config
|
||||
raises(ConfigError, "config.cfgimpl_get_values()[g1] = 2")
|
||||
#def test_values_not_setitem():
|
||||
# g1 = IntOption('g1', '', 1)
|
||||
# g2 = StrOption('g2', '', 'héhé')
|
||||
# g3 = UnicodeOption('g3', '', u'héhé')
|
||||
# g4 = BoolOption('g4', '', True)
|
||||
# g5 = StrOption('g5', '')
|
||||
# d1 = OptionDescription('od', '', [g1, g2, g3, g4, g5])
|
||||
# root = OptionDescription('root', '', [d1])
|
||||
# config = Config(root)
|
||||
# config
|
||||
# raises(ConfigError, "config.cfgimpl_get_values()[g1] = 2")
|
||||
|
||||
|
||||
def test_duplicated_option():
|
||||
|
|
@ -295,8 +285,9 @@ def test_duplicated_option_diff_od():
|
|||
def test_cannot_assign_value_to_option_description():
|
||||
descr = make_description()
|
||||
cfg = Config(descr)
|
||||
cfg
|
||||
raises(TypeError, "cfg.gc = 3")
|
||||
api = getapi(cfg)
|
||||
api
|
||||
raises(APIError, "api.option('gc').value.set(3)")
|
||||
|
||||
|
||||
def test_config_multi():
|
||||
|
|
@ -305,50 +296,53 @@ def test_config_multi():
|
|||
i3 = IntOption('test3', '', default=[2], multi=True, default_multi=1)
|
||||
od = OptionDescription('test', '', [i1, i2, i3])
|
||||
config = Config(od)
|
||||
assert config.test1 == []
|
||||
assert config.test2 == []
|
||||
config.test2.append()
|
||||
assert config.test2 == [1]
|
||||
assert config.test3 == [2]
|
||||
config.test3.append()
|
||||
assert config.test3 == [2, 1]
|
||||
api = getapi(config)
|
||||
assert api.option('test1').value.get() == []
|
||||
assert api.option('test2').value.get() == []
|
||||
api.option('test2').value.set([undefined])
|
||||
assert api.option('test2').value.get() == [1]
|
||||
assert api.option('test3').value.get() == [2]
|
||||
api.option('test3').value.set([undefined, undefined])
|
||||
assert api.option('test3').value.get() == [2, 1]
|
||||
|
||||
|
||||
def test_no_validation():
|
||||
i1 = IntOption('test1', '')
|
||||
od = OptionDescription('test', '', [i1])
|
||||
c = Config(od)
|
||||
setting = c.cfgimpl_get_settings()
|
||||
c.test1 = 1
|
||||
raises(ValueError, 'c.test1 = "yes"')
|
||||
assert c.test1 == 1
|
||||
setting.remove('validator')
|
||||
c.test1 = "yes"
|
||||
assert c.test1 == "yes"
|
||||
setting.append('validator')
|
||||
raises(ValueError, 'c.test1')
|
||||
del(c.test1)
|
||||
assert c.test1 is None
|
||||
cfg = Config(od)
|
||||
api = getapi(cfg)
|
||||
api.property.read_write()
|
||||
api.option('test1').value.set(1)
|
||||
raises(ValueError, "api.option('test1').value.set('yes')")
|
||||
assert api.option('test1').value.get() == 1
|
||||
api.property.pop('validator')
|
||||
api.option('test1').value.set('yes')
|
||||
assert api.option('test1').value.get() == 'yes'
|
||||
api.property.add('validator')
|
||||
raises(ValueError, "api.option('test1').value.get()")
|
||||
api.option('test1').value.reset()
|
||||
assert api.option('test1').value.get() is None
|
||||
|
||||
|
||||
def test_delete_config_with_subconfig():
|
||||
test = IntOption('test', '')
|
||||
multi = IntOption('multi', '', multi=True)
|
||||
od = OptionDescription('od', '', [test, multi])
|
||||
odroot = OptionDescription('odroot', '', [od])
|
||||
c = Config(odroot)
|
||||
sub = c.od
|
||||
val = c.cfgimpl_get_values()
|
||||
setting = c.cfgimpl_get_settings()
|
||||
val[test]
|
||||
val[multi]
|
||||
setting[test]
|
||||
sub.make_dict()
|
||||
del(c)
|
||||
raises(ConfigError, 'val[test]')
|
||||
raises(ConfigError, 'val[multi]')
|
||||
raises(ConfigError, 'setting[test]')
|
||||
raises(ConfigError, 'sub.make_dict()')
|
||||
#def test_delete_config_with_subconfig():
|
||||
# test = IntOption('test', '')
|
||||
# multi = IntOption('multi', '', multi=True)
|
||||
# od = OptionDescription('od', '', [test, multi])
|
||||
# odroot = OptionDescription('odroot', '', [od])
|
||||
# cfg = Config(odroot)
|
||||
# api = getapi(cfg)
|
||||
# sub = cfg.od
|
||||
# val = cfg.cfgimpl_get_values()
|
||||
# setting = cfg.cfgimpl_get_settings()
|
||||
# assert api.option('od.test').value.get() is None
|
||||
# assert api.option('od.multi').value.get() == []
|
||||
# api.config.make_dict()
|
||||
# del(api)
|
||||
# del(cfg)
|
||||
# raises(ConfigError, 'val[test]')
|
||||
# raises(ConfigError, 'val[multi]')
|
||||
# raises(ConfigError, 'setting[test]')
|
||||
# raises(ConfigError, 'sub.make_dict()')
|
||||
|
||||
|
||||
def test_subconfig():
|
||||
|
|
@ -358,43 +352,43 @@ def test_subconfig():
|
|||
c = Config(o2)
|
||||
c
|
||||
raises(TypeError, "SubConfig(i, weakref.ref(c))")
|
||||
pass
|
||||
|
||||
|
||||
def test_config_weakref():
|
||||
o = OptionDescription('val', '', [])
|
||||
o2 = OptionDescription('val', '', [o])
|
||||
c = Config(o2)
|
||||
SubConfig(o, weakref.ref(c))
|
||||
raises(ValueError, "SubConfig(o, c)")
|
||||
s = SubConfig(o, weakref.ref(c))
|
||||
assert s._cfgimpl_get_context() == c
|
||||
del(c)
|
||||
raises(ConfigError, "s._cfgimpl_get_context()")
|
||||
#def test_config_weakref():
|
||||
# o = OptionDescription('val', '', [])
|
||||
# o2 = OptionDescription('val', '', [o])
|
||||
# c = Config(o2)
|
||||
# SubConfig(o, weakref.ref(c))
|
||||
# raises(ValueError, "SubConfig(o, c)")
|
||||
# s = SubConfig(o, weakref.ref(c))
|
||||
# assert s._cfgimpl_get_context() == c
|
||||
# del(c)
|
||||
# raises(ConfigError, "s._cfgimpl_get_context()")
|
||||
|
||||
|
||||
def test_config_str():
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
gcdummy1 = BoolOption('dummy1', 'dummy', default=False, properties=('disabled',))
|
||||
o = OptionDescription('o', '', [gcdummy, gcdummy1])
|
||||
descr = OptionDescription('tiramisu', '', [o])
|
||||
cfg = Config(descr)
|
||||
cfg.read_only()
|
||||
str(cfg)
|
||||
str(cfg.o)
|
||||
#def test_config_str():
|
||||
# gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
# gcdummy1 = BoolOption('dummy1', 'dummy', default=False, properties=('disabled',))
|
||||
# o = OptionDescription('o', '', [gcdummy, gcdummy1])
|
||||
# descr = OptionDescription('tiramisu', '', [o])
|
||||
# cfg = Config(descr)
|
||||
# api = getapi(cfg)
|
||||
# api.property.read_only()
|
||||
# str(cfg)
|
||||
# str(cfg.o)
|
||||
|
||||
|
||||
def test_config_od_function():
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
gcdummy1 = BoolOption('dummy1', 'dummy', default=False, properties=('disabled',))
|
||||
o = OptionDescription('o', '', [gcdummy, gcdummy1])
|
||||
descr = OptionDescription('tiramisu', '', [o])
|
||||
cfg = Config(descr)
|
||||
try:
|
||||
print(cfg.impl_get_opt_by_path())
|
||||
except AttributeError as err:
|
||||
assert str(err) == _('unknown Option {0} in OptionDescription {1}'
|
||||
'').format('impl_get_opt_by_path', descr.impl_getname())
|
||||
#def test_config_od_function():
|
||||
# gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
# gcdummy1 = BoolOption('dummy1', 'dummy', default=False, properties=('disabled',))
|
||||
# o = OptionDescription('o', '', [gcdummy, gcdummy1])
|
||||
# descr = OptionDescription('tiramisu', '', [o])
|
||||
# cfg = Config(descr)
|
||||
# try:
|
||||
# print(cfg.impl_get_opt_by_path())
|
||||
# except AttributeError as err:
|
||||
# assert str(err) == _('unknown Option {0} in OptionDescription {1}'
|
||||
# '').format('impl_get_opt_by_path', descr.impl_getname())
|
||||
|
||||
|
||||
def test_config_subconfig():
|
||||
|
|
@ -405,5 +399,5 @@ def test_config_subconfig():
|
|||
od1 = OptionDescription('od1', '', [i1, i2, i3, i4])
|
||||
od2 = OptionDescription('od2', '', [od1])
|
||||
conf1 = Config(od2, session_id='conf1')
|
||||
conf1
|
||||
api = getapi(conf1)
|
||||
raises(ConfigError, "conf2 = Config(od1, session_id='conf2')")
|
||||
|
|
|
|||
|
|
@ -1,14 +1,13 @@
|
|||
"configuration objects global API"
|
||||
from py.test import raises
|
||||
|
||||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
|
||||
from py.test import raises
|
||||
|
||||
from tiramisu.config import Config
|
||||
from tiramisu.option import IntOption, FloatOption, StrOption, ChoiceOption, \
|
||||
from tiramisu import Config, IntOption, FloatOption, StrOption, ChoiceOption, \
|
||||
BoolOption, FilenameOption, UnicodeOption, SymLinkOption, IPOption, \
|
||||
PortOption, NetworkOption, NetmaskOption, BroadcastOption, \
|
||||
DomainnameOption, OptionDescription
|
||||
DomainnameOption, OptionDescription, getapi
|
||||
from tiramisu.error import PropertiesOptionError
|
||||
|
||||
|
||||
|
|
@ -44,35 +43,35 @@ def _is_same_opt(opt1, opt2):
|
|||
assert opt1 == opt2
|
||||
|
||||
|
||||
def test_iter_config():
|
||||
"iteration on config object"
|
||||
s = StrOption("string", "", default="string")
|
||||
s2 = StrOption("string2", "", default="string2")
|
||||
descr = OptionDescription("options", "", [s, s2])
|
||||
config = Config(descr)
|
||||
assert [(name, value) for name, value in config] == \
|
||||
[('string', 'string'), ('string2', 'string2')]
|
||||
|
||||
|
||||
def test_iter_config_property():
|
||||
"iteration on config object"
|
||||
s = StrOption("string", "", default="string", properties=('disabled',))
|
||||
s2 = StrOption("string2", "", default="string2")
|
||||
descr = OptionDescription("options", "", [s, s2])
|
||||
config = Config(descr)
|
||||
config.read_only()
|
||||
assert [(name, value) for name, value in config] == \
|
||||
[('string2', 'string2')]
|
||||
|
||||
|
||||
def test_iter_subconfig():
|
||||
"iteration on config sub object"
|
||||
descr = make_description()
|
||||
conf = Config(descr)
|
||||
for (name, value), (gname, gvalue) in \
|
||||
zip(conf.gc, [("name", "ref"), ("dummy", False)]):
|
||||
assert name == gname
|
||||
assert value == gvalue
|
||||
#def test_iter_config():
|
||||
# "iteration on config object"
|
||||
# s = StrOption("string", "", default="string")
|
||||
# s2 = StrOption("string2", "", default="string2")
|
||||
# descr = OptionDescription("options", "", [s, s2])
|
||||
# config = Config(descr)
|
||||
# assert [(name, value) for name, value in config] == \
|
||||
# [('string', 'string'), ('string2', 'string2')]
|
||||
#
|
||||
#
|
||||
#def test_iter_config_property():
|
||||
# "iteration on config object"
|
||||
# s = StrOption("string", "", default="string", properties=('disabled',))
|
||||
# s2 = StrOption("string2", "", default="string2")
|
||||
# descr = OptionDescription("options", "", [s, s2])
|
||||
# config = Config(descr)
|
||||
# config.read_only()
|
||||
# assert [(name, value) for name, value in config] == \
|
||||
# [('string2', 'string2')]
|
||||
#
|
||||
#
|
||||
#def test_iter_subconfig():
|
||||
# "iteration on config sub object"
|
||||
# descr = make_description()
|
||||
# conf = Config(descr)
|
||||
# for (name, value), (gname, gvalue) in \
|
||||
# zip(conf.gc, [("name", "ref"), ("dummy", False)]):
|
||||
# assert name == gname
|
||||
# assert value == gvalue
|
||||
|
||||
|
||||
def test_str():
|
||||
|
|
@ -89,18 +88,19 @@ def test_make_dict():
|
|||
BoolOption("b", "", default=False, properties=('hidden',))]),
|
||||
IntOption("int", "", default=42)])
|
||||
config = Config(descr)
|
||||
config.read_write()
|
||||
config.cfgimpl_get_settings().setpermissive(('hidden',))
|
||||
d = config.make_dict()
|
||||
api = getapi(config)
|
||||
api.property.read_write()
|
||||
api.permissive.set(frozenset(['hidden']))
|
||||
d = api.option.make_dict()
|
||||
assert d == {"s1.a": False, "int": 42}
|
||||
config.int = 43
|
||||
config.s1.a = True
|
||||
d = config.make_dict()
|
||||
api.option('int').value.set(43)
|
||||
api.option('s1.a').value.set(True)
|
||||
d = api.option.make_dict()
|
||||
assert d == {"s1.a": True, "int": 43}
|
||||
d2 = config.make_dict(flatten=True)
|
||||
d2 = api.option.make_dict(flatten=True)
|
||||
assert d2 == {'a': True, 'int': 43}
|
||||
raises(ValueError, 'd2 = config.make_dict(withvalue="3")')
|
||||
d = config.make_dict(force_permissive=True)
|
||||
raises(ValueError, 'd2 = api.option.make_dict(withvalue="3")')
|
||||
d = api.forcepermissive.option.make_dict()
|
||||
assert d == {"s1.a": True, "s1.b": False, "int": 43}
|
||||
|
||||
|
||||
|
|
@ -114,8 +114,9 @@ def test_make_dict_with_disabled():
|
|||
BoolOption("b", "", default=False)], properties=('disabled',)),
|
||||
IntOption("int", "", default=42)])
|
||||
config = Config(descr)
|
||||
config.read_only()
|
||||
d = config.make_dict()
|
||||
api = getapi(config)
|
||||
api.property.read_only()
|
||||
d = api.option.make_dict()
|
||||
assert d == {"s1.a": False, "int": 42}
|
||||
|
||||
|
||||
|
|
@ -129,8 +130,9 @@ def test_make_dict_with_disabled_in_callback():
|
|||
BoolOption("b", "", default=False)], properties=('disabled',)),
|
||||
IntOption("int", "", default=42)])
|
||||
config = Config(descr)
|
||||
config.read_only()
|
||||
d = config.make_dict()
|
||||
api = getapi(config)
|
||||
api.property.read_only()
|
||||
d = api.option.make_dict()
|
||||
assert d == {"s1.a": False, "int": 42}
|
||||
|
||||
|
||||
|
|
@ -146,182 +148,189 @@ def test_make_dict_fullpath():
|
|||
IntOption("int", "", default=42)]),
|
||||
IntOption("introot", "", default=42)])
|
||||
config = Config(descr)
|
||||
config.read_only()
|
||||
assert config.make_dict() == {"opt.s1.a": False, "opt.int": 42, "introot": 42}
|
||||
assert config.opt.make_dict() == {"s1.a": False, "int": 42}
|
||||
assert config.make_dict(fullpath=True) == {"opt.s1.a": False, "opt.int": 42, "introot": 42}
|
||||
assert config.opt.make_dict(fullpath=True) == {"opt.s1.a": False, "opt.int": 42}
|
||||
api = getapi(config)
|
||||
api.property.read_only()
|
||||
assert api.option.make_dict() == {"opt.s1.a": False, "opt.int": 42, "introot": 42}
|
||||
assert api.option('opt').make_dict() == {"s1.a": False, "int": 42}
|
||||
assert api.option.make_dict(fullpath=True) == {"opt.s1.a": False, "opt.int": 42, "introot": 42}
|
||||
assert api.option('opt').make_dict(fullpath=True) == {"opt.s1.a": False, "opt.int": 42}
|
||||
|
||||
|
||||
def test_find_in_config():
|
||||
"finds option in config"
|
||||
descr = make_description()
|
||||
conf = Config(descr)
|
||||
conf.read_only()
|
||||
conf.cfgimpl_get_settings().setpermissive(('hidden',))
|
||||
ret = conf.find(byname='dummy')
|
||||
api = getapi(conf)
|
||||
api.property.read_only()
|
||||
api.permissive.set(frozenset(['hidden']))
|
||||
ret = api.option.find('dummy')
|
||||
assert len(ret) == 1
|
||||
_is_same_opt(ret[0], conf.unwrap_from_path('gc.dummy'))
|
||||
_is_same_opt(ret[0], api.option.get('gc.dummy'))
|
||||
#
|
||||
ret = conf.find_first(byname='dummy')
|
||||
_is_same_opt(ret, conf.unwrap_from_path('gc.dummy'))
|
||||
ret = api.option.find_first('dummy')
|
||||
_is_same_opt(ret, api.option.get('gc.dummy'))
|
||||
#
|
||||
ret = conf.find(byname='float')
|
||||
ret = api.option.find('float')
|
||||
assert len(ret) == 2
|
||||
_is_same_opt(ret[0], conf.unwrap_from_path('gc.float'))
|
||||
_is_same_opt(ret[1], conf.unwrap_from_path('float'))
|
||||
_is_same_opt(conf.find_first(byname='bool'), conf.unwrap_from_path('gc.gc2.bool'))
|
||||
_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'))
|
||||
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 = 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')")
|
||||
_is_same_opt(ret[0], api.option.get('gc.float'))
|
||||
_is_same_opt(ret[1], api.option.get('float'))
|
||||
#
|
||||
_is_same_opt(api.option.find_first('bool'), api.option.get('gc.gc2.bool'))
|
||||
#_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'))
|
||||
#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 = 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')")
|
||||
|
||||
|
||||
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)
|
||||
# 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_does_not_find_in_config():
|
||||
descr = make_description()
|
||||
conf = Config(descr)
|
||||
conf
|
||||
raises(AttributeError, "conf.find(byname='IDontExist')")
|
||||
api = getapi(conf)
|
||||
api
|
||||
raises(AttributeError, "api.option.find('IDontExist')")
|
||||
|
||||
|
||||
def test_filename():
|
||||
a = FilenameOption('a', '')
|
||||
o = OptionDescription('o', '', [a])
|
||||
c = Config(o)
|
||||
c.a = u'/'
|
||||
c.a = u'/tmp'
|
||||
c.a = u'/tmp/'
|
||||
c.a = u'/tmp/text.txt'
|
||||
c.a = u'tmp'
|
||||
c.a = u'tmp/'
|
||||
c.a = u'tmp/text.txt'
|
||||
raises(ValueError, "c.a = u'/tmp/with space.txt'")
|
||||
raises(ValueError, "c.a = u'/tmp/with$.txt'")
|
||||
cfg = Config(o)
|
||||
api = getapi(cfg)
|
||||
api.option('a').value.set('/')
|
||||
api.option('a').value.set('/tmp')
|
||||
api.option('a').value.set('/tmp/')
|
||||
api.option('a').value.set('/tmp/text.txt')
|
||||
api.option('a').value.set('tmp')
|
||||
api.option('a').value.set('tmp/')
|
||||
api.option('a').value.set('tmp/text.txt')
|
||||
raises(ValueError, "api.option('a').value.set('/tmp/with space.txt')")
|
||||
raises(ValueError, "api.option('a').value.set('/tmp/with$.txt')")
|
||||
|
||||
|
||||
def test_iter_all():
|
||||
s = StrOption("string", "", default="string")
|
||||
s2 = StrOption("string2", "", default="string2")
|
||||
descr = OptionDescription("options", "", [s, s2])
|
||||
config = Config(descr)
|
||||
assert list(config.iter_all()) == [('string', 'string'), ('string2', 'string2')]
|
||||
for i in config.iter_all():
|
||||
#test StopIteration
|
||||
break
|
||||
#def test_iter_all():
|
||||
# s = StrOption("string", "", default="string")
|
||||
# s2 = StrOption("string2", "", default="string2")
|
||||
# descr = OptionDescription("options", "", [s, s2])
|
||||
# config = Config(descr)
|
||||
# assert list(config.iter_all()) == [('string', 'string'), ('string2', 'string2')]
|
||||
# for i in config.iter_all():
|
||||
# #test StopIteration
|
||||
# break
|
||||
#
|
||||
#
|
||||
#def test_iter_all_force_permissive():
|
||||
# s = StrOption("string", "", default="string")
|
||||
# s2 = StrOption("string2", "", default="string2")
|
||||
# s3 = StrOption("string3", "", default="string3", properties=('hidden',))
|
||||
# descr = OptionDescription("options", "", [s, s2, s3])
|
||||
# config = Config(descr)
|
||||
# api = getapi(config)
|
||||
# api.property.read_write()
|
||||
# api.permissive.set(('hidden',))
|
||||
# assert list(config.iter_all()) == [('string', 'string'), ('string2', 'string2')]
|
||||
# assert list(config.iter_all(force_permissive=True)) == [('string', 'string'),
|
||||
# ('string2', 'string2'),
|
||||
# ('string3', 'string3')]
|
||||
#
|
||||
#
|
||||
#def test_iter_all_prop():
|
||||
# s = StrOption("string", "", default="string", properties=('disabled',))
|
||||
# s2 = StrOption("string2", "", default="string2")
|
||||
# descr = OptionDescription("options", "", [s, s2])
|
||||
# config = Config(descr)
|
||||
# api = getapi(config)
|
||||
# api.property.read_only()
|
||||
# assert list(config.iter_all()) == [('string2', 'string2')]
|
||||
|
||||
|
||||
def test_iter_all_force_permissive():
|
||||
s = StrOption("string", "", default="string")
|
||||
s2 = StrOption("string2", "", default="string2")
|
||||
s3 = StrOption("string3", "", default="string3", properties=('hidden',))
|
||||
descr = OptionDescription("options", "", [s, s2, s3])
|
||||
config = Config(descr)
|
||||
config.read_write()
|
||||
config.cfgimpl_get_settings().setpermissive(('hidden',))
|
||||
assert list(config.iter_all()) == [('string', 'string'), ('string2', 'string2')]
|
||||
assert list(config.iter_all(force_permissive=True)) == [('string', 'string'),
|
||||
('string2', 'string2'),
|
||||
('string3', 'string3')]
|
||||
|
||||
|
||||
def test_iter_all_prop():
|
||||
s = StrOption("string", "", default="string", properties=('disabled',))
|
||||
s2 = StrOption("string2", "", default="string2")
|
||||
descr = OptionDescription("options", "", [s, s2])
|
||||
config = Config(descr)
|
||||
config.read_only()
|
||||
assert list(config.iter_all()) == [('string2', 'string2')]
|
||||
|
||||
|
||||
def test_impl_getpaths():
|
||||
s = StrOption("string", "", default="string", properties=('disabled',))
|
||||
s2 = StrOption("string2", "", default="string2")
|
||||
s3 = StrOption("string3", "", default="string3")
|
||||
s4 = StrOption("string4", "", default="string4", properties=('hidden',))
|
||||
od = OptionDescription('od', '', [s3, s4])
|
||||
descr = OptionDescription("options", "", [s, s2, od])
|
||||
config = Config(descr)
|
||||
assert ['string', 'string2', 'od.string3', 'od.string4'] == config.cfgimpl_get_description().impl_getpaths()
|
||||
assert ['string', 'string2', 'od', 'od.string3', 'od.string4'] == config.cfgimpl_get_description().impl_getpaths(include_groups=True)
|
||||
config.read_write()
|
||||
raises(PropertiesOptionError, "config.od.string4")
|
||||
assert ['string', 'string2', 'od.string3', 'od.string4'] == config.cfgimpl_get_description().impl_getpaths()
|
||||
assert ['string', 'string2', 'od', 'od.string3', 'od.string4'] == config.cfgimpl_get_description().impl_getpaths(include_groups=True)
|
||||
#def test_impl_getpaths():
|
||||
# s = StrOption("string", "", default="string", properties=('disabled',))
|
||||
# s2 = StrOption("string2", "", default="string2")
|
||||
# s3 = StrOption("string3", "", default="string3")
|
||||
# s4 = StrOption("string4", "", default="string4", properties=('hidden',))
|
||||
# od = OptionDescription('od', '', [s3, s4])
|
||||
# descr = OptionDescription("options", "", [s, s2, od])
|
||||
# config = Config(descr)
|
||||
# assert ['string', 'string2', 'od.string3', 'od.string4'] == config.cfgimpl_get_description().impl_getpaths()
|
||||
# assert ['string', 'string2', 'od', 'od.string3', 'od.string4'] == config.cfgimpl_get_description().impl_getpaths(include_groups=True)
|
||||
# config.read_write()
|
||||
# raises(PropertiesOptionError, "config.od.string4")
|
||||
# assert ['string', 'string2', 'od.string3', 'od.string4'] == config.cfgimpl_get_description().impl_getpaths()
|
||||
# assert ['string', 'string2', 'od', 'od.string3', 'od.string4'] == config.cfgimpl_get_description().impl_getpaths(include_groups=True)
|
||||
|
||||
|
||||
def test_invalid_option():
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ from tiramisu.config import Config
|
|||
from tiramisu.option import DomainnameOption, EmailOption, URLOption, OptionDescription
|
||||
from tiramisu.error import ValueWarning
|
||||
from tiramisu.i18n import _
|
||||
from tiramisu import getapi
|
||||
|
||||
|
||||
def test_domainname():
|
||||
|
|
@ -16,55 +17,51 @@ def test_domainname():
|
|||
g = DomainnameOption('g', '', allow_ip=True)
|
||||
od = OptionDescription('a', '', [d, f, g])
|
||||
c = Config(od)
|
||||
c.read_write()
|
||||
c.d = 'toto.com'
|
||||
raises(ValueError, "c.d = 'toto'")
|
||||
c.d = 'toto3.com'
|
||||
raises(ValueError, "c.d = 'toto_super.com'")
|
||||
c.d = 'toto-.com'
|
||||
raises(ValueError, "c.d = 'toto..com'")
|
||||
api = getapi(c)
|
||||
api.property.read_write()
|
||||
api.option('d').value.set('toto.com')
|
||||
raises(ValueError, "api.option('d').value.set('toto')")
|
||||
api.option('d').value.set('toto3.com')
|
||||
raises(ValueError, "api.option('d').value.set('toto_super.com')")
|
||||
api.option('d').value.set('toto-.com')
|
||||
raises(ValueError, "api.option('d').value.set('toto..com')")
|
||||
#
|
||||
c.f = 'toto.com'
|
||||
c.f = 'toto'
|
||||
c.f = 'domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea'
|
||||
raises(ValueError, "c.f = 'domainnametoolongthathavemorethanmaximumsizeforatruedomainnamean'")
|
||||
c.f = 'domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nd'
|
||||
c.f = 'domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnameto.olongthathavemorethanmaximumsizeforatruedomainnameanditsnoteas.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowie'
|
||||
raises(ValueError, "c.f = 'domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnameto.olongthathavemorethanmaximumsizeforatruedomainnameanditsnoteas.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowien'")
|
||||
c.f = 'd'
|
||||
c.f = 'd.t'
|
||||
api.option('f').value.set('toto.com')
|
||||
api.option('f').value.set('toto')
|
||||
api.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea')
|
||||
raises(ValueError, "api.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamean')")
|
||||
api.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nd')
|
||||
api.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnameto.olongthathavemorethanmaximumsizeforatruedomainnameanditsnoteas.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowie')
|
||||
raises(ValueError, "api.option('d').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnameto.olongthathavemorethanmaximumsizeforatruedomainnameanditsnoteas.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowien')")
|
||||
api.option('f').value.set('d')
|
||||
api.option('f').value.set('d.t')
|
||||
#
|
||||
raises(ValueError, "c.f = '192.168.1.1'")
|
||||
c.g = 'toto.com'
|
||||
c.g = '192.168.1.0'
|
||||
c.g = '192.168.1.29'
|
||||
raises(ValueError, "api.option('f').value.set('192.168.1.1')")
|
||||
api.option('g').value.set('toto.com')
|
||||
api.option('g').value.set('192.168.1.0')
|
||||
api.option('g').value.set('192.168.1.29')
|
||||
|
||||
|
||||
def test_domainname_upper():
|
||||
d = DomainnameOption('d', '')
|
||||
od = OptionDescription('a', '', [d])
|
||||
c = Config(od)
|
||||
c.read_write()
|
||||
c.d = 'toto.com'
|
||||
api = getapi(c)
|
||||
api.property.read_write()
|
||||
api.option('d').value.set('toto.com')
|
||||
msg = _('some characters are uppercase')
|
||||
has_error = False
|
||||
try:
|
||||
c.d = 'TOTO.COM'
|
||||
api.option('d').value.set('TOTO.COM')
|
||||
except ValueError as err:
|
||||
if sys.version_info[0] >= 3: # pragma: optional cover
|
||||
assert msg in str(err)
|
||||
else:
|
||||
assert msg in str(err)
|
||||
assert msg in str(err)
|
||||
has_error = True
|
||||
assert has_error is True
|
||||
has_error = False
|
||||
try:
|
||||
c.d = 'toTo.com'
|
||||
api.option('d').value.set('toTo.com')
|
||||
except ValueError as err:
|
||||
if sys.version_info[0] >= 3: # pragma: optional cover
|
||||
assert msg in str(err)
|
||||
else:
|
||||
assert msg in str(err)
|
||||
assert msg in str(err)
|
||||
has_error = True
|
||||
assert has_error is True
|
||||
|
||||
|
|
@ -76,30 +73,33 @@ def test_domainname_warning():
|
|||
od = OptionDescription('a', '', [d, f, g])
|
||||
warnings.simplefilter("always", ValueWarning)
|
||||
c = Config(od)
|
||||
c.read_write()
|
||||
c.d = 'toto.com'
|
||||
raises(ValueError, "c.d = 'toto'")
|
||||
c.d = 'toto3.com'
|
||||
api = getapi(c)
|
||||
api.property.read_write()
|
||||
api.option('d').value.set('toto.com')
|
||||
raises(ValueError, "api.option('d').value.set('toto')")
|
||||
api.option('d').value.set('toto3.com')
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
c.d = 'toto_super.com'
|
||||
api.option('d').value.set('toto_super.com')
|
||||
assert len(w) == 1
|
||||
c.d = 'toto-.com'
|
||||
raises(ValueError, "c.d = 'toto..com'")
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('d').value.set('toto-.com')
|
||||
assert len(w) == 0
|
||||
raises(ValueError, "api.option('d').value.set('toto..com')")
|
||||
#
|
||||
c.f = 'toto.com'
|
||||
c.f = 'toto'
|
||||
c.f = 'domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea'
|
||||
raises(ValueError, "c.f = 'domainnametoolongthathavemorethanmaximumsizeforatruedomainnamean'")
|
||||
c.f = 'domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nd'
|
||||
c.f = 'domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnameto.olongthathavemorethanmaximumsizeforatruedomainnameanditsnoteas.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowie'
|
||||
raises(ValueError, "c.f = 'domainnametoolongthathavemorethanmaximumsizeforatruedomainname.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnamet.olongthathavemorethanmaximumsizeforatruedomainnameanditsnotea.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowie.xxxx'")
|
||||
c.f = 'd'
|
||||
c.f = 'd.t'
|
||||
api.option('f').value.set('toto.com')
|
||||
api.option('f').value.set('toto')
|
||||
api.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea')
|
||||
raises(ValueError, "api.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamean')")
|
||||
api.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nd')
|
||||
api.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnameto.olongthathavemorethanmaximumsizeforatruedomainnameanditsnoteas.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowie')
|
||||
raises(ValueError, "api.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainname.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnamet.olongthathavemorethanmaximumsizeforatruedomainnameanditsnotea.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowie.xxxx')")
|
||||
api.option('f').value.set('d')
|
||||
api.option('f').value.set('d.t')
|
||||
#
|
||||
raises(ValueError, "c.f = '192.168.1.1'")
|
||||
c.g = 'toto.com'
|
||||
c.g = '192.168.1.0'
|
||||
c.g = '192.168.1.29'
|
||||
raises(ValueError, "api.option('f').value.set('192.168.1.1')")
|
||||
api.option('g').value.set('toto.com')
|
||||
api.option('g').value.set('192.168.1.0')
|
||||
api.option('g').value.set('192.168.1.29')
|
||||
|
||||
|
||||
def test_special_domain_name():
|
||||
|
|
@ -109,11 +109,12 @@ def test_special_domain_name():
|
|||
e = DomainnameOption('e', '', type_='netbios')
|
||||
od = OptionDescription('a', '', [d, e])
|
||||
c = Config(od)
|
||||
c.read_write()
|
||||
c.d = '1toto.com'
|
||||
c.d = '123toto.com'
|
||||
c.e = 'toto'
|
||||
c.e = '1toto'
|
||||
api = getapi(c)
|
||||
api.property.read_write()
|
||||
api.option('d').value.set('1toto.com')
|
||||
api.option('d').value.set('123toto.com')
|
||||
api.option('e').value.set('toto')
|
||||
api.option('e').value.set('1toto')
|
||||
|
||||
|
||||
def test_domainname_netbios():
|
||||
|
|
@ -121,10 +122,11 @@ def test_domainname_netbios():
|
|||
e = DomainnameOption('e', '', "toto", type_='netbios')
|
||||
od = OptionDescription('a', '', [d, e])
|
||||
c = Config(od)
|
||||
c.read_write()
|
||||
raises(ValueError, "c.d = 'toto.com'")
|
||||
c.d = 'toto'
|
||||
raises(ValueError, "c.d = 'domainnametoolong'")
|
||||
api = getapi(c)
|
||||
api.property.read_write()
|
||||
raises(ValueError, "api.option('d').value.set('toto.com')")
|
||||
api.option('d').value.set('toto')
|
||||
raises(ValueError, "api.option('d').value.set('domainnametoolong')")
|
||||
|
||||
|
||||
def test_domainname_hostname():
|
||||
|
|
@ -132,44 +134,47 @@ def test_domainname_hostname():
|
|||
e = DomainnameOption('e', '', "toto", type_='hostname')
|
||||
od = OptionDescription('a', '', [d, e])
|
||||
c = Config(od)
|
||||
c.read_write()
|
||||
raises(ValueError, "c.d = 'toto.com'")
|
||||
c.d = 'toto'
|
||||
c.d = 'domainnametoolong'
|
||||
api = getapi(c)
|
||||
api.property.read_write()
|
||||
raises(ValueError, "api.option('d').value.set('toto.com')")
|
||||
api.option('d').value.set('toto')
|
||||
api.option('d').value.set('domainnametoolong')
|
||||
|
||||
|
||||
def test_email():
|
||||
e = EmailOption('e', '')
|
||||
od = OptionDescription('a', '', [e])
|
||||
c = Config(od)
|
||||
c.read_write()
|
||||
c.e = u'foo-bar.baz@example.com'
|
||||
c.e = u'root@foo.com'
|
||||
c.e = u'root@domain'
|
||||
raises(ValueError, "c.e = 1")
|
||||
raises(ValueError, "c.e = u'root'")
|
||||
raises(ValueError, "c.e = u'root[]@domain'")
|
||||
api = getapi(c)
|
||||
api.property.read_write()
|
||||
api.option('e').value.set('foo-bar.baz@example.com')
|
||||
api.option('e').value.set('root@foo.com')
|
||||
api.option('e').value.set('root@domain')
|
||||
raises(ValueError, "api.option('e').value.set(1)")
|
||||
raises(ValueError, "api.option('e').value.set('root')")
|
||||
raises(ValueError, "api.option('e').value.set('root[]@domain')")
|
||||
|
||||
|
||||
def test_url():
|
||||
u = URLOption('u', '')
|
||||
od = OptionDescription('a', '', [u])
|
||||
c = Config(od)
|
||||
c.read_write()
|
||||
c.u = 'http://foo.com'
|
||||
c.u = 'https://foo.com'
|
||||
c.u = 'https://foo.com/'
|
||||
raises(ValueError, "c.u = 1")
|
||||
raises(ValueError, "c.u = 'ftp://foo.com'")
|
||||
raises(ValueError, "c.u = 'foo.com'")
|
||||
raises(ValueError, "c.u = ':/foo.com'")
|
||||
raises(ValueError, "c.u = 'foo.com/http://'")
|
||||
c.u = 'https://foo.com/index.html'
|
||||
c.u = 'https://foo.com/index.html?var=value&var2=val2'
|
||||
raises(ValueError, "c.u = 'https://foo.com/index\\n.html'")
|
||||
c.u = 'https://foo.com:8443'
|
||||
c.u = 'https://foo.com:8443/'
|
||||
c.u = 'https://foo.com:8443/index.html'
|
||||
raises(ValueError, "c.u = 'https://foo.com:84438989'")
|
||||
c.u = 'https://foo.com:8443/INDEX'
|
||||
raises(ValueError, "c.u = 'https://FOO.COM:8443'")
|
||||
api = getapi(c)
|
||||
api.property.read_write()
|
||||
api.option('u').value.set('http://foo.com')
|
||||
api.option('u').value.set('https://foo.com')
|
||||
api.option('u').value.set('https://foo.com/')
|
||||
raises(ValueError, "api.option('u').value.set(1)")
|
||||
raises(ValueError, "api.option('u').value.set('ftp://foo.com')")
|
||||
raises(ValueError, "api.option('u').value.set('foo.com')")
|
||||
raises(ValueError, "api.option('u').value.set(':/foo.com')")
|
||||
raises(ValueError, "api.option('u').value.set('foo.com/http://')")
|
||||
api.option('u').value.set('https://foo.com/index.html')
|
||||
api.option('u').value.set('https://foo.com/index.html?var=value&var2=val2')
|
||||
raises(ValueError, "api.option('u').value.set('https://foo.com/index\\n.html')")
|
||||
api.option('u').value.set('https://foo.com:8443')
|
||||
api.option('u').value.set('https://foo.com:8443/')
|
||||
api.option('u').value.set('https://foo.com:8443/index.html')
|
||||
raises(ValueError, "api.option('u').value.set('https://foo.com:84438989')")
|
||||
api.option('u').value.set('https://foo.com:8443/INDEX')
|
||||
raises(ValueError, "api.option('u').value.set('https://FOO.COM:8443')")
|
||||
|
|
|
|||
|
|
@ -3,9 +3,8 @@ do_autopath()
|
|||
|
||||
import warnings
|
||||
from py.test import raises
|
||||
from tiramisu.config import Config
|
||||
from tiramisu.option import IPOption, NetworkOption, NetmaskOption, \
|
||||
PortOption, BroadcastOption, OptionDescription
|
||||
from tiramisu import Config ,IPOption, NetworkOption, NetmaskOption, \
|
||||
PortOption, BroadcastOption, OptionDescription, getapi
|
||||
from tiramisu.error import ValueWarning
|
||||
|
||||
|
||||
|
|
@ -16,21 +15,22 @@ def test_ip():
|
|||
warnings.simplefilter("always", ValueWarning)
|
||||
od = OptionDescription('od', '', [a, b, d])
|
||||
c = Config(od)
|
||||
c.a = '192.168.1.1'
|
||||
c.a = '192.168.1.0'
|
||||
c.a = '88.88.88.88'
|
||||
c.a = '0.0.0.0'
|
||||
raises(ValueError, "c.a = '255.255.255.0'")
|
||||
c.b = '192.168.1.1'
|
||||
c.b = '192.168.1.0'
|
||||
raises(ValueError, "c.b = '88.88.88.88'")
|
||||
c.b = '0.0.0.0'
|
||||
raises(ValueError, "c.b = '255.255.255.0'")
|
||||
raises(ValueError, "c.a = '333.0.1.20'")
|
||||
api = getapi(c)
|
||||
api.option('a').value.set('192.168.1.1')
|
||||
api.option('a').value.set('192.168.1.0')
|
||||
api.option('a').value.set('88.88.88.88')
|
||||
api.option('a').value.set('0.0.0.0')
|
||||
raises(ValueError, "api.option('a').value.set('255.255.255.0')")
|
||||
api.option('b').value.set('192.168.1.1')
|
||||
api.option('b').value.set('192.168.1.0')
|
||||
raises(ValueError, "api.option('b').value.set('88.88.88.88')")
|
||||
api.option('b').value.set('0.0.0.0')
|
||||
raises(ValueError, "api.option('b').value.set('255.255.255.0')")
|
||||
raises(ValueError, "api.option('a').value.set('333.0.1.20')")
|
||||
|
||||
raises(ValueError, "IPOption('a', 'ip', default='192.000.023.01')")
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
c.d = '88.88.88.88'
|
||||
api.option('d').value.set('88.88.88.88')
|
||||
assert len(w) == 1
|
||||
|
||||
|
||||
|
|
@ -38,7 +38,8 @@ def test_ip_default():
|
|||
a = IPOption('a', '', '88.88.88.88')
|
||||
od = OptionDescription('od', '', [a])
|
||||
c = Config(od)
|
||||
c.a == '88.88.88.88'
|
||||
api = getapi(c)
|
||||
api.option('a').value.get() == '88.88.88.88'
|
||||
|
||||
|
||||
def test_ip_reserved():
|
||||
|
|
@ -48,10 +49,11 @@ def test_ip_reserved():
|
|||
od = OptionDescription('od', '', [a, b, c])
|
||||
warnings.simplefilter("always", ValueWarning)
|
||||
cfg = Config(od)
|
||||
raises(ValueError, "cfg.a = '226.94.1.1'")
|
||||
cfg.b = '226.94.1.1'
|
||||
api = getapi(cfg)
|
||||
raises(ValueError, "api.option('a').value.set('226.94.1.1')")
|
||||
api.option('b').value.set('226.94.1.1')
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
cfg.c = '226.94.1.1'
|
||||
api.option('c').value.set('226.94.1.1')
|
||||
assert len(w) == 1
|
||||
|
||||
|
||||
|
|
@ -61,17 +63,18 @@ def test_network():
|
|||
od = OptionDescription('od', '', [a, b])
|
||||
warnings.simplefilter("always", ValueWarning)
|
||||
c = Config(od)
|
||||
c.a = '192.168.1.1'
|
||||
c.a = '192.168.1.0'
|
||||
c.a = '88.88.88.88'
|
||||
c.a = '0.0.0.0'
|
||||
raises(ValueError, "c.a = 1")
|
||||
raises(ValueError, "c.a = '1.1.1.1.1'")
|
||||
raises(ValueError, "c.a = '255.255.255.0'")
|
||||
raises(ValueError, "c.a = '192.168.001.0'")
|
||||
raises(ValueError, "c.a = '333.168.1.1'")
|
||||
api = getapi(c)
|
||||
api.option('a').value.set('192.168.1.1')
|
||||
api.option('a').value.set('192.168.1.0')
|
||||
api.option('a').value.set('88.88.88.88')
|
||||
api.option('a').value.set('0.0.0.0')
|
||||
raises(ValueError, "api.option('a').value.set(1)")
|
||||
raises(ValueError, "api.option('a').value.set('1.1.1.1.1')")
|
||||
raises(ValueError, "api.option('a').value.set('255.255.255.0')")
|
||||
raises(ValueError, "api.option('a').value.set('192.168.001.0')")
|
||||
raises(ValueError, "api.option('a').value.set('333.168.1.1')")
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
c.b = '255.255.255.0'
|
||||
api.option('b').value.set('255.255.255.0')
|
||||
assert len(w) == 1
|
||||
|
||||
|
||||
|
|
@ -83,27 +86,29 @@ def test_netmask():
|
|||
a = NetmaskOption('a', '')
|
||||
od = OptionDescription('od', '', [a])
|
||||
c = Config(od)
|
||||
raises(ValueError, "c.a = '192.168.1.1.1'")
|
||||
raises(ValueError, "c.a = '192.168.1.1'")
|
||||
raises(ValueError, "c.a = '192.168.1.0'")
|
||||
raises(ValueError, "c.a = '88.88.88.88'")
|
||||
raises(ValueError, "c.a = '255.255.255.000'")
|
||||
raises(ValueError, "c.a = 2")
|
||||
c.a = '0.0.0.0'
|
||||
c.a = '255.255.255.0'
|
||||
api = getapi(c)
|
||||
raises(ValueError, "api.option('a').value.set('192.168.1.1.1')")
|
||||
raises(ValueError, "api.option('a').value.set('192.168.1.1')")
|
||||
raises(ValueError, "api.option('a').value.set('192.168.1.0')")
|
||||
raises(ValueError, "api.option('a').value.set('88.88.88.88')")
|
||||
raises(ValueError, "api.option('a').value.set('255.255.255.000')")
|
||||
raises(ValueError, "api.option('a').value.set(2)")
|
||||
api.option('a').value.set('0.0.0.0')
|
||||
api.option('a').value.set('255.255.255.0')
|
||||
|
||||
|
||||
def test_broadcast():
|
||||
a = BroadcastOption('a', '')
|
||||
od = OptionDescription('od', '', [a])
|
||||
c = Config(od)
|
||||
raises(ValueError, "c.a = '192.168.1.255.1'")
|
||||
raises(ValueError, "c.a = '192.168.001.255'")
|
||||
raises(ValueError, "c.a = '192.168.0.300'")
|
||||
raises(ValueError, "c.a = 1")
|
||||
raises(ValueError, "c.a = 2")
|
||||
c.a = '0.0.0.0'
|
||||
c.a = '255.255.255.0'
|
||||
api = getapi(c)
|
||||
raises(ValueError, "api.option('a').value.set('192.168.1.255.1')")
|
||||
raises(ValueError, "api.option('a').value.set('192.168.001.255')")
|
||||
raises(ValueError, "api.option('a').value.set('192.168.0.300')")
|
||||
raises(ValueError, "api.option('a').value.set(1)")
|
||||
raises(ValueError, "api.option('a').value.set(2)")
|
||||
api.option('a').value.set('0.0.0.0')
|
||||
api.option('a').value.set('255.255.255.0')
|
||||
|
||||
|
||||
def test_port():
|
||||
|
|
@ -115,58 +120,59 @@ def test_port():
|
|||
f = PortOption('f', '', allow_private=True)
|
||||
od = OptionDescription('od', '', [a, b, c, d, e, f])
|
||||
c = Config(od)
|
||||
raises(ValueError, "c.a = 0")
|
||||
c.a = 1
|
||||
c.a = 1023
|
||||
c.a = 1024
|
||||
c.a = 49151
|
||||
raises(ValueError, "c.a = 49152")
|
||||
raises(ValueError, "c.a = 65535")
|
||||
raises(ValueError, "c.a = 65536")
|
||||
api = getapi(c)
|
||||
raises(ValueError, "api.option('a').value.set(0)")
|
||||
api.option('a').value.set(1)
|
||||
api.option('a').value.set(1023)
|
||||
api.option('a').value.set(1024)
|
||||
api.option('a').value.set(49151)
|
||||
raises(ValueError, "api.option('a').value.set(49152)")
|
||||
raises(ValueError, "api.option('a').value.set(65535)")
|
||||
raises(ValueError, "api.option('a').value.set(65536)")
|
||||
|
||||
c.b = 0
|
||||
c.b = 1
|
||||
c.b = 1023
|
||||
c.b = 1024
|
||||
c.b = 49151
|
||||
raises(ValueError, "c.b = 49152")
|
||||
raises(ValueError, "c.b = 65535")
|
||||
raises(ValueError, "c.b = 65536")
|
||||
api.option('b').value.set(0)
|
||||
api.option('b').value.set(1)
|
||||
api.option('b').value.set(1023)
|
||||
api.option('b').value.set(1024)
|
||||
api.option('b').value.set(49151)
|
||||
raises(ValueError, "api.option('b').value.set(49152)")
|
||||
raises(ValueError, "api.option('b').value.set(65535)")
|
||||
raises(ValueError, "api.option('b').value.set(65536)")
|
||||
|
||||
c.c = 0
|
||||
c.c = 1
|
||||
c.c = 1023
|
||||
raises(ValueError, "c.c = 1024")
|
||||
raises(ValueError, "c.c = 49151")
|
||||
raises(ValueError, "c.c = 49152")
|
||||
raises(ValueError, "c.c = 65535")
|
||||
raises(ValueError, "c.c = 65536")
|
||||
api.option('c').value.set(0)
|
||||
api.option('c').value.set(1)
|
||||
api.option('c').value.set(1023)
|
||||
raises(ValueError, "api.option('c').value.set(1024)")
|
||||
raises(ValueError, "api.option('c').value.set(49151)")
|
||||
raises(ValueError, "api.option('c').value.set(49152)")
|
||||
raises(ValueError, "api.option('c').value.set(65535)")
|
||||
raises(ValueError, "api.option('c').value.set(65536)")
|
||||
|
||||
c.d = 0
|
||||
raises(ValueError, "c.d = 1")
|
||||
raises(ValueError, "c.d = 1023")
|
||||
raises(ValueError, "c.d = 1024")
|
||||
raises(ValueError, "c.d = 49151")
|
||||
raises(ValueError, "c.d = 49152")
|
||||
raises(ValueError, "c.d = 65535")
|
||||
raises(ValueError, "c.d = 65536")
|
||||
api.option('d').value.set(0)
|
||||
raises(ValueError, "api.option('d').value.set(1)")
|
||||
raises(ValueError, "api.option('d').value.set(1023)")
|
||||
raises(ValueError, "api.option('d').value.set(1024)")
|
||||
raises(ValueError, "api.option('d').value.set(49151)")
|
||||
raises(ValueError, "api.option('d').value.set(49152)")
|
||||
raises(ValueError, "api.option('d').value.set(65535)")
|
||||
raises(ValueError, "api.option('d').value.set(65536)")
|
||||
|
||||
c.e = 0
|
||||
c.e = 1
|
||||
c.e = 1023
|
||||
c.e = 1024
|
||||
c.e = 49151
|
||||
c.e = 49152
|
||||
c.e = 65535
|
||||
api.option('e').value.set(0)
|
||||
api.option('e').value.set(1)
|
||||
api.option('e').value.set(1023)
|
||||
api.option('e').value.set(1024)
|
||||
api.option('e').value.set(49151)
|
||||
api.option('e').value.set(49152)
|
||||
api.option('e').value.set(65535)
|
||||
|
||||
raises(ValueError, "c.f = 0")
|
||||
c.f = 1
|
||||
c.f = 1023
|
||||
c.f = 1024
|
||||
c.f = 49151
|
||||
c.f = 49152
|
||||
c.f = 65535
|
||||
raises(ValueError, "c.f = 65536")
|
||||
raises(ValueError, "api.option('f').value.set(0)")
|
||||
api.option('f').value.set(1)
|
||||
api.option('f').value.set(1023)
|
||||
api.option('f').value.set(1024)
|
||||
api.option('f').value.set(49151)
|
||||
api.option('f').value.set(49152)
|
||||
api.option('f').value.set(65535)
|
||||
raises(ValueError, "api.option('f').value.set(65536)")
|
||||
|
||||
|
||||
def test_port_range():
|
||||
|
|
@ -178,70 +184,71 @@ def test_port_range():
|
|||
f = PortOption('f', '', allow_range=True, allow_private=True)
|
||||
od = OptionDescription('od', '', [a, b, c, d, e, f])
|
||||
c = Config(od)
|
||||
raises(ValueError, "c.a = 0")
|
||||
c.a = 1
|
||||
c.a = 1023
|
||||
c.a = 1024
|
||||
c.a = 49151
|
||||
raises(ValueError, "c.a = 49152")
|
||||
raises(ValueError, "c.a = 65535")
|
||||
raises(ValueError, "c.a = 65536")
|
||||
c.a = '1:49151'
|
||||
raises(ValueError, "c.a = '0:49151'")
|
||||
raises(ValueError, "c.a = '1:49152'")
|
||||
api = getapi(c)
|
||||
raises(ValueError, "api.option('a').value.set(0)")
|
||||
api.option('a').value.set(1)
|
||||
api.option('a').value.set(1023)
|
||||
api.option('a').value.set(1024)
|
||||
api.option('a').value.set(49151)
|
||||
raises(ValueError, "api.option('a').value.set(49152)")
|
||||
raises(ValueError, "api.option('a').value.set(65535)")
|
||||
raises(ValueError, "api.option('a').value.set(65536)")
|
||||
api.option('a').value.set('1:49151')
|
||||
raises(ValueError, "api.option('a').value.set('0:49151')")
|
||||
raises(ValueError, "api.option('a').value.set('1:49152')")
|
||||
|
||||
c.b = 0
|
||||
c.b = 1
|
||||
c.b = 1023
|
||||
c.b = 1024
|
||||
c.b = 49151
|
||||
raises(ValueError, "c.b = 49152")
|
||||
raises(ValueError, "c.b = 65535")
|
||||
raises(ValueError, "c.b = 65536")
|
||||
c.b = '0:49151'
|
||||
raises(ValueError, "c.b = '0:49152'")
|
||||
api.option('b').value.set(0)
|
||||
api.option('b').value.set(1)
|
||||
api.option('b').value.set(1023)
|
||||
api.option('b').value.set(1024)
|
||||
api.option('b').value.set(49151)
|
||||
raises(ValueError, "api.option('b').value.set(49152)")
|
||||
raises(ValueError, "api.option('b').value.set(65535)")
|
||||
raises(ValueError, "api.option('b').value.set(65536)")
|
||||
api.option('b').value.set('0:49151')
|
||||
raises(ValueError, "api.option('b').value.set('0:49152')")
|
||||
|
||||
c.c = 0
|
||||
c.c = 1
|
||||
c.c = 1023
|
||||
raises(ValueError, "c.c = 1024")
|
||||
raises(ValueError, "c.c = 49151")
|
||||
raises(ValueError, "c.c = 49152")
|
||||
raises(ValueError, "c.c = 65535")
|
||||
raises(ValueError, "c.c = 65536")
|
||||
c.c = '0:1023'
|
||||
raises(ValueError, "c.c = '0:1024'")
|
||||
api.option('c').value.set(0)
|
||||
api.option('c').value.set(1)
|
||||
api.option('c').value.set(1023)
|
||||
raises(ValueError, "api.option('c').value.set(1024)")
|
||||
raises(ValueError, "api.option('c').value.set(49151)")
|
||||
raises(ValueError, "api.option('c').value.set(49152)")
|
||||
raises(ValueError, "api.option('c').value.set(65535)")
|
||||
raises(ValueError, "api.option('c').value.set(65536)")
|
||||
api.option('c').value.set('0:1023')
|
||||
raises(ValueError, "api.option('c').value.set('0:1024')")
|
||||
|
||||
c.d = 0
|
||||
raises(ValueError, "c.d = 1")
|
||||
raises(ValueError, "c.d = 1023")
|
||||
raises(ValueError, "c.d = 1024")
|
||||
raises(ValueError, "c.d = 49151")
|
||||
raises(ValueError, "c.d = 49152")
|
||||
raises(ValueError, "c.d = 65535")
|
||||
raises(ValueError, "c.d = 65536")
|
||||
raises(ValueError, "c.d = '0:0'")
|
||||
raises(ValueError, "c.d = '0:1'")
|
||||
api.option('d').value.set(0)
|
||||
raises(ValueError, "api.option('d').value.set(1)")
|
||||
raises(ValueError, "api.option('d').value.set(1023)")
|
||||
raises(ValueError, "api.option('d').value.set(1024)")
|
||||
raises(ValueError, "api.option('d').value.set(49151)")
|
||||
raises(ValueError, "api.option('d').value.set(49152)")
|
||||
raises(ValueError, "api.option('d').value.set(65535)")
|
||||
raises(ValueError, "api.option('d').value.set(65536)")
|
||||
raises(ValueError, "api.option('d').value.set('0:0')")
|
||||
raises(ValueError, "api.option('d').value.set('0:1')")
|
||||
|
||||
c.e = 0
|
||||
c.e = 1
|
||||
c.e = 1023
|
||||
c.e = 1024
|
||||
c.e = 49151
|
||||
c.e = 49152
|
||||
c.e = 65535
|
||||
c.e = '0:65535'
|
||||
raises(ValueError, "c.e = '0:65536'")
|
||||
api.option('e').value.set(0)
|
||||
api.option('e').value.set(1)
|
||||
api.option('e').value.set(1023)
|
||||
api.option('e').value.set(1024)
|
||||
api.option('e').value.set(49151)
|
||||
api.option('e').value.set(49152)
|
||||
api.option('e').value.set(65535)
|
||||
api.option('e').value.set('0:65535')
|
||||
raises(ValueError, "api.option('e').value.set('0:65536')")
|
||||
|
||||
raises(ValueError, "c.f = 0")
|
||||
c.f = 1
|
||||
c.f = 1023
|
||||
c.f = 1024
|
||||
c.f = 49151
|
||||
c.f = 49152
|
||||
c.f = 65535
|
||||
raises(ValueError, "c.f = 65536")
|
||||
c.f = '1:65535'
|
||||
c.f = '3:4'
|
||||
raises(ValueError, "c.f = '0:65535'")
|
||||
raises(ValueError, "c.f = '4:3'")
|
||||
raises(ValueError, "api.option('f').value.set(0)")
|
||||
api.option('f').value.set(1)
|
||||
api.option('f').value.set(1023)
|
||||
api.option('f').value.set(1024)
|
||||
api.option('f').value.set(49151)
|
||||
api.option('f').value.set(49152)
|
||||
api.option('f').value.set(65535)
|
||||
raises(ValueError, "api.option('f').value.set(65536)")
|
||||
api.option('f').value.set('1:65535')
|
||||
api.option('f').value.set('3:4')
|
||||
raises(ValueError, "api.option('f').value.set('0:65535')")
|
||||
raises(ValueError, "api.option('f').value.set('4:3')")
|
||||
|
|
|
|||
|
|
@ -2,16 +2,16 @@
|
|||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
|
||||
from tiramisu.config import Config, GroupConfig, MetaConfig
|
||||
from tiramisu.option import BoolOption, IntOption, StrOption, IPOption, NetmaskOption, \
|
||||
SymLinkOption, OptionDescription, DynOptionDescription, submulti
|
||||
from tiramisu import BoolOption, IntOption, StrOption, IPOption, NetmaskOption, \
|
||||
SymLinkOption, OptionDescription, DynOptionDescription, submulti, \
|
||||
Config, GroupConfig, MetaConfig, getapi
|
||||
import weakref
|
||||
|
||||
|
||||
IS_DEREFABLE = True
|
||||
|
||||
|
||||
def funcname(value):
|
||||
def funcname(*args, **kwargs):
|
||||
return value
|
||||
|
||||
|
||||
|
|
@ -166,26 +166,6 @@ def test_deref_metaconfig():
|
|||
assert w() is None
|
||||
|
||||
|
||||
def test_deref_submulti():
|
||||
if not IS_DEREFABLE:
|
||||
return
|
||||
multi = StrOption('multi', '', multi=submulti)
|
||||
od = OptionDescription('od', '', [multi])
|
||||
cfg = Config(od)
|
||||
cfg.cfgimpl_get_settings().remove('cache')
|
||||
w = weakref.ref(cfg.multi)
|
||||
assert w() is None
|
||||
cfg.multi.append([])
|
||||
w = weakref.ref(cfg.multi)
|
||||
assert w() is None
|
||||
m = cfg.multi
|
||||
w = weakref.ref(m)
|
||||
z = weakref.ref(w()[0])
|
||||
del(m)
|
||||
assert w() is None
|
||||
assert z() is None
|
||||
|
||||
|
||||
def test_deref_consistency():
|
||||
if not IS_DEREFABLE:
|
||||
return
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@ do_autopath()
|
|||
|
||||
from tiramisu.setting import groups
|
||||
from tiramisu.config import Config
|
||||
from tiramisu.option import ChoiceOption, BoolOption, IntOption, \
|
||||
StrOption, OptionDescription
|
||||
from tiramisu import ChoiceOption, BoolOption, IntOption, \
|
||||
StrOption, OptionDescription, getapi
|
||||
from .test_state import _diff_opts, _diff_conf
|
||||
from py.test import raises
|
||||
|
||||
|
|
@ -49,20 +49,27 @@ def make_description():
|
|||
def test_duplicate():
|
||||
cfg = Config(make_description())
|
||||
ncfg = cfg.duplicate()
|
||||
_diff_opts(cfg.cfgimpl_get_description(), ncfg.cfgimpl_get_description())
|
||||
_diff_conf(cfg, ncfg)
|
||||
cfg.creole.general.numero_etab = 'oui'
|
||||
raises(AssertionError, "_diff_conf(cfg, ncfg)")
|
||||
ncfg.creole.general.numero_etab = 'oui'
|
||||
_diff_conf(cfg, ncfg)
|
||||
api = getapi(cfg)
|
||||
api2 = getapi(ncfg)
|
||||
assert api.option('creole.general.numero_etab').value.get() == None
|
||||
api.option('creole.general.numero_etab').value.set('oui')
|
||||
assert api.option('creole.general.numero_etab').value.get() == 'oui'
|
||||
assert api2.option('creole.general.numero_etab').value.get() == None
|
||||
# _diff_opts(cfg.cfgimpl_get_description(), ncfg.cfgimpl_get_description())
|
||||
# _diff_conf(cfg, ncfg)
|
||||
# cfg.creole.general.numero_etab = 'oui'
|
||||
# raises(AssertionError, "_diff_conf(cfg, ncfg)")
|
||||
# ncfg.creole.general.numero_etab = 'oui'
|
||||
# _diff_conf(cfg, ncfg)
|
||||
|
||||
|
||||
def test_duplicate_force_store_value():
|
||||
descr = make_description()
|
||||
conf = Config(descr)
|
||||
conf2 = Config(descr)
|
||||
api = getapi(conf)
|
||||
assert conf.cfgimpl_get_values().get_modified_values() == {'creole.general.wantref': ('forced', False)}
|
||||
assert conf2.cfgimpl_get_values().get_modified_values() == {'creole.general.wantref': ('forced', False)}
|
||||
conf.creole.general.wantref = True
|
||||
api.option('creole.general.wantref').value.set(True)
|
||||
assert conf.cfgimpl_get_values().get_modified_values() == {'creole.general.wantref': ('user', True)}
|
||||
assert conf2.cfgimpl_get_values().get_modified_values() == {'creole.general.wantref': ('forced', False)}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -6,9 +6,9 @@ do_autopath()
|
|||
from py.test import raises
|
||||
|
||||
from tiramisu.setting import owners, groups
|
||||
from tiramisu.option import ChoiceOption, BoolOption, IntOption, FloatOption, \
|
||||
StrOption, OptionDescription, SymLinkOption, MasterSlaves
|
||||
from tiramisu.config import Config
|
||||
from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \
|
||||
StrOption, OptionDescription, SymLinkOption, MasterSlaves, Config, \
|
||||
getapi
|
||||
from tiramisu.error import PropertiesOptionError, ConfigError
|
||||
|
||||
|
||||
|
|
@ -55,27 +55,27 @@ def return_val3(context, value):
|
|||
|
||||
def test_freeze_whole_config():
|
||||
descr = make_description_freeze()
|
||||
conf = Config(descr)
|
||||
setting = conf.cfgimpl_get_settings()
|
||||
conf.read_write()
|
||||
setting.append('everything_frozen')
|
||||
assert conf.gc.dummy is False
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
api.property.add('everything_frozen')
|
||||
assert api.option('gc.dummy').value.get() is False
|
||||
prop = []
|
||||
try:
|
||||
conf.gc.dummy = True
|
||||
api.option('gc.dummy').value.set(True)
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'frozen' in prop
|
||||
assert conf.gc.dummy is False
|
||||
assert api.option('gc.dummy').value.get() is False
|
||||
#
|
||||
setting.remove('everything_frozen')
|
||||
conf.gc.dummy = True
|
||||
assert conf.gc.dummy is True
|
||||
setting.append('everything_frozen')
|
||||
owners.addowner("everythingfrozen")
|
||||
api.property.pop('everything_frozen')
|
||||
api.option('gc.dummy').value.set(True)
|
||||
assert api.option('gc.dummy').value.get() is True
|
||||
#
|
||||
api.property.add('everything_frozen')
|
||||
owners.addowner("everythingfrozen2")
|
||||
prop = []
|
||||
try:
|
||||
conf.cfgimpl_get_values().setowner(descr.gc.dummy, owners.everythingfrozen)
|
||||
api.option('gc.dummy').owner.set('everythingfrozen2')
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'frozen' in prop
|
||||
|
|
@ -84,16 +84,14 @@ def test_freeze_whole_config():
|
|||
def test_freeze_one_option():
|
||||
"freeze an option "
|
||||
descr = make_description_freeze()
|
||||
conf = Config(descr)
|
||||
setting = conf.cfgimpl_get_settings()
|
||||
conf.read_write()
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
#freeze only one option
|
||||
dummy = conf.unwrap_from_path('gc.dummy')
|
||||
setting[dummy].append('frozen')
|
||||
assert conf.gc.dummy is False
|
||||
api.option('gc.dummy').property.add('frozen')
|
||||
assert api.option('gc.dummy').value.get() is False
|
||||
prop = []
|
||||
try:
|
||||
conf.gc.dummy = True
|
||||
api.option('gc.dummy').value.set(True)
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'frozen' in prop
|
||||
|
|
@ -103,14 +101,13 @@ def test_frozen_value():
|
|||
"setattr a frozen value at the config level"
|
||||
s = StrOption("string", "", default="string")
|
||||
descr = OptionDescription("options", "", [s])
|
||||
config = Config(descr)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
config.read_write()
|
||||
setting.append('frozen')
|
||||
setting[s].append('frozen')
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
api.property.add('frozen')
|
||||
api.option('string').property.add('frozen')
|
||||
prop = []
|
||||
try:
|
||||
config.string = "egg"
|
||||
api.option('string').value.set('egg')
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'frozen' in prop
|
||||
|
|
@ -119,15 +116,13 @@ def test_frozen_value():
|
|||
def test_freeze():
|
||||
"freeze a whole configuration object"
|
||||
descr = make_description_freeze()
|
||||
conf = Config(descr)
|
||||
setting = conf.cfgimpl_get_settings()
|
||||
conf.read_write()
|
||||
setting.append('frozen')
|
||||
name = conf.unwrap_from_path("gc.name")
|
||||
setting[name].append('frozen')
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
api.property.add('frozen')
|
||||
api.option('gc.name').property.add('frozen')
|
||||
prop = []
|
||||
try:
|
||||
conf.gc.name = 'framework'
|
||||
api.option('gc.name').value.set('framework')
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'frozen' in prop
|
||||
|
|
@ -135,33 +130,13 @@ def test_freeze():
|
|||
|
||||
def test_freeze_multi():
|
||||
descr = make_description_freeze()
|
||||
conf = Config(descr)
|
||||
setting = conf.cfgimpl_get_settings()
|
||||
conf.read_write()
|
||||
setting.append('frozen')
|
||||
obj = conf.unwrap_from_path('boolop')
|
||||
setting[obj].append('frozen')
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
api.property.add('frozen')
|
||||
api.option('boolop').property.add('frozen')
|
||||
prop = []
|
||||
try:
|
||||
conf.boolop = [True]
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'frozen' in prop
|
||||
|
||||
|
||||
def test_freeze_get_multi():
|
||||
descr = make_description_freeze()
|
||||
conf = Config(descr)
|
||||
setting = conf.cfgimpl_get_settings()
|
||||
conf.read_write()
|
||||
setting.append('frozen')
|
||||
valmulti = conf.boolop
|
||||
valmulti.append(False)
|
||||
obj = conf.unwrap_from_path('boolop')
|
||||
setting[obj].append('frozen')
|
||||
prop = []
|
||||
try:
|
||||
valmulti.append(False)
|
||||
api.option('boolop').value.set([True])
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'frozen' in prop
|
||||
|
|
@ -170,17 +145,18 @@ def test_freeze_get_multi():
|
|||
def test_force_store_value():
|
||||
descr = make_description_freeze()
|
||||
conf = Config(descr)
|
||||
assert conf.cfgimpl_get_values().get_modified_values() == {'wantref': ('forced', False),
|
||||
'wantref2': ('forced', False),
|
||||
'wantref3': ('forced', (False,))}
|
||||
conf.wantref = True
|
||||
assert conf.cfgimpl_get_values().get_modified_values() == {'wantref': ('user', True),
|
||||
'wantref2': ('forced', False),
|
||||
'wantref3': ('forced', (False,))}
|
||||
del(conf.wantref)
|
||||
assert conf.cfgimpl_get_values().get_modified_values() == {'wantref': ('forced', False),
|
||||
'wantref2': ('forced', False),
|
||||
'wantref3': ('forced', (False,))}
|
||||
api = getapi(conf)
|
||||
assert api.value.get_modified() == {'wantref': ('forced', False),
|
||||
'wantref2': ('forced', False),
|
||||
'wantref3': ('forced', (False,))}
|
||||
api.option('wantref').value.set(True)
|
||||
assert api.value.get_modified() == {'wantref': ('user', True),
|
||||
'wantref2': ('forced', False),
|
||||
'wantref3': ('forced', (False,))}
|
||||
api.option('wantref').value.reset()
|
||||
assert api.value.get_modified() == {'wantref': ('forced', False),
|
||||
'wantref2': ('forced', False),
|
||||
'wantref3': ('forced', (False,))}
|
||||
|
||||
|
||||
def test_force_store_value_no_requirement():
|
||||
|
|
@ -196,43 +172,50 @@ def test_force_store_value_masterslaves_slave():
|
|||
b = IntOption('int', 'Test int option', multi=True)
|
||||
c = StrOption('str', 'Test string option', multi=True, properties=('force_store_value',))
|
||||
descr = MasterSlaves("int", "", [b, c])
|
||||
#descr.impl_set_group_type(groups.master)
|
||||
raises(ConfigError, "conf = Config(descr)")
|
||||
|
||||
|
||||
def test_force_store_value_masterslaves():
|
||||
#def test_force_store_value_masterslaves():
|
||||
# b = IntOption('int', 'Test int option', multi=True, properties=('force_store_value',))
|
||||
# c = StrOption('str', 'Test string option', multi=True)
|
||||
# descr = MasterSlaves("int", "", [b, c])
|
||||
# api = getapi(Config(descr))
|
||||
# assert api.value.get() == {'int': ('forced', ())}
|
||||
|
||||
|
||||
def test_force_store_value_masterslaves_sub():
|
||||
b = IntOption('int', 'Test int option', multi=True, properties=('force_store_value',))
|
||||
c = StrOption('str', 'Test string option', multi=True)
|
||||
descr = MasterSlaves("int", "", [b, c])
|
||||
#descr.impl_set_group_type(groups.master)
|
||||
conf = Config(descr)
|
||||
assert conf.cfgimpl_get_values().get_modified_values() == {'int': ('forced', ())}
|
||||
odr = OptionDescription('odr', '', [descr])
|
||||
api = getapi(Config(odr))
|
||||
assert api.value.get_modified() == {'int.int': ('forced', ())}
|
||||
|
||||
|
||||
def test_force_store_value_callback():
|
||||
b = IntOption('int', 'Test int option', properties=('force_store_value',), callback=return_val)
|
||||
descr = OptionDescription("int", "", [b])
|
||||
conf = Config(descr)
|
||||
assert conf.cfgimpl_get_values().get_modified_values() == {'int': ('forced', 1)}
|
||||
api = getapi(Config(descr))
|
||||
assert api.value.get_modified() == {'int': ('forced', 1)}
|
||||
|
||||
|
||||
def test_force_store_value_callback_params():
|
||||
b = IntOption('int', 'Test int option', properties=('force_store_value',), callback=return_val2, callback_params={'value': (2,)})
|
||||
descr = OptionDescription("int", "", [b])
|
||||
conf = Config(descr)
|
||||
assert conf.cfgimpl_get_values().get_modified_values() == {'int': ('forced', 2)}
|
||||
api = getapi(Config(descr))
|
||||
assert api.value.get_modified() == {'int': ('forced', 2)}
|
||||
|
||||
|
||||
def test_force_store_value_callback_params_2():
|
||||
b = IntOption('int', 'Test int option', properties=('force_store_value',), callback=return_val3, callback_params={'': ((None,),), 'value': (2,)})
|
||||
descr = OptionDescription("int", "", [b])
|
||||
conf = Config(descr)
|
||||
assert conf.cfgimpl_get_values().get_modified_values() == {'int': ('forced', 2)}
|
||||
api = getapi(Config(descr))
|
||||
assert api.value.get_modified() == {'int': ('forced', 2)}
|
||||
|
||||
|
||||
def test_force_store_value_callback_params_with_opt():
|
||||
a = IntOption('val1', "", 2)
|
||||
b = IntOption('int', 'Test int option', properties=('force_store_value',), callback=return_val2, callback_params={'value': ((a, False),)})
|
||||
descr = OptionDescription("int", "", [a, b])
|
||||
conf = Config(descr)
|
||||
assert conf.cfgimpl_get_values().get_modified_values() == {'int': ('forced', 2)}
|
||||
api = getapi(Config(descr))
|
||||
assert api.value.get_modified() == {'int': ('forced', 2)}
|
||||
|
|
|
|||
|
|
@ -3,12 +3,12 @@ from .autopath import do_autopath
|
|||
do_autopath()
|
||||
|
||||
from py.test import raises
|
||||
from tiramisu.api import TIRAMISU_VERSION
|
||||
from tiramisu.config import Config
|
||||
from tiramisu.option import IntOption, StrOption, UnicodeOption, OptionDescription, \
|
||||
SymLinkOption, MasterSlaves
|
||||
from tiramisu import IntOption, StrOption, UnicodeOption, OptionDescription, \
|
||||
SymLinkOption, MasterSlaves, getapi, undefined
|
||||
from tiramisu.error import PropertiesOptionError, ConfigError
|
||||
from tiramisu.setting import groups
|
||||
from tiramisu.storage import delete_session
|
||||
|
||||
|
||||
def make_description():
|
||||
|
|
@ -83,398 +83,308 @@ def make_description4():
|
|||
|
||||
def test_mandatory_ro():
|
||||
descr = make_description()
|
||||
config = Config(descr, session_id='man001')
|
||||
config.read_only()
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_only()
|
||||
prop = []
|
||||
try:
|
||||
config.str1
|
||||
api.option('str1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
config.read_write()
|
||||
config.str1 = 'yes'
|
||||
config.read_only()
|
||||
assert config.str1 == 'yes'
|
||||
try:
|
||||
delete_session('config', config.impl_getsessionid())
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
api.property.read_write()
|
||||
api.option('str1').value.set('yes')
|
||||
api.property.read_only()
|
||||
assert api.option('str1').value.get() == 'yes'
|
||||
|
||||
|
||||
def test_mandatory_rw():
|
||||
descr = make_description()
|
||||
config = Config(descr, session_id='man002')
|
||||
config.read_write()
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
#not mandatory in rw
|
||||
config.str1
|
||||
config.str1 = 'yes'
|
||||
assert config.str1 == 'yes'
|
||||
try:
|
||||
delete_session('config', config.impl_getsessionid())
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
api.option('str1').value.get()
|
||||
api.option('str1').value.set('yes')
|
||||
assert api.option('str1').value.get() == 'yes'
|
||||
|
||||
|
||||
def test_mandatory_default():
|
||||
descr = make_description()
|
||||
config = Config(descr, session_id='man003')
|
||||
config.read_only()
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_only()
|
||||
#not mandatory in rw
|
||||
config.str
|
||||
config.read_write()
|
||||
config.str = 'yes'
|
||||
config.read_only()
|
||||
config.str
|
||||
config.read_write()
|
||||
config.str = None
|
||||
config.read_only()
|
||||
api.option('str').value.get()
|
||||
api.property.read_write()
|
||||
api.option('str').value.set('yes')
|
||||
api.property.read_only()
|
||||
api.option('str').value.get()
|
||||
api.property.read_write()
|
||||
api.option('str').value.set(None)
|
||||
api.property.read_only()
|
||||
prop = []
|
||||
try:
|
||||
config.str
|
||||
api.option('str').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
try:
|
||||
delete_session('config', config.impl_getsessionid())
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
|
||||
|
||||
def test_mandatory_delete():
|
||||
descr = make_description()
|
||||
config = Config(descr, session_id='man004')
|
||||
config.read_only()
|
||||
config.str
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_only()
|
||||
api.option('str').value.get()
|
||||
try:
|
||||
config.str1
|
||||
api.option('str1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
config.read_write()
|
||||
config.str1 = 'yes'
|
||||
config.read_only()
|
||||
assert config.str1 == 'yes'
|
||||
config.cfgimpl_get_settings().remove('frozen')
|
||||
api.property.read_write()
|
||||
api.option('str1').value.set('yes')
|
||||
api.property.read_only()
|
||||
assert api.option('str1').value.get() == 'yes'
|
||||
api.property.pop('everything_frozen')
|
||||
prop = []
|
||||
try:
|
||||
del(config.str1)
|
||||
api.option('str1').value.reset()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
del(config.str)
|
||||
assert config.str1 == 'yes'
|
||||
try:
|
||||
delete_session('config', config.impl_getsessionid())
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
api.option('str').value.reset()
|
||||
|
||||
assert api.option('str1').value.get() == 'yes'
|
||||
|
||||
|
||||
#valeur vide : None, '', u'', ...
|
||||
def test_mandatory_none():
|
||||
descr = make_description()
|
||||
config = Config(descr, session_id='man005')
|
||||
config.str1 = None
|
||||
assert config.getowner(config.unwrap_from_path('str1')) == 'user'
|
||||
config.read_only()
|
||||
api = getapi(Config(descr))
|
||||
api.option('str1').value.set(None)
|
||||
assert api.option('str1').owner.get() == 'user'
|
||||
api.property.read_only()
|
||||
prop = []
|
||||
try:
|
||||
config.str1
|
||||
api.option('str1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
try:
|
||||
delete_session('config', config.impl_getsessionid())
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
|
||||
|
||||
def test_mandatory_empty():
|
||||
descr = make_description()
|
||||
config = Config(descr, session_id='man006')
|
||||
config.str1 = ''
|
||||
assert config.getowner(config.unwrap_from_path('str1')) == 'user'
|
||||
config.read_only()
|
||||
api = getapi(Config(descr))
|
||||
api.option('str1').value.set('')
|
||||
assert api.option('str1').owner.get() == 'user'
|
||||
api.property.read_only()
|
||||
prop = []
|
||||
try:
|
||||
config.str1
|
||||
api.option('str1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
try:
|
||||
delete_session('config', config.impl_getsessionid())
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
|
||||
|
||||
def test_mandatory_multi_none():
|
||||
descr = make_description()
|
||||
config = Config(descr, session_id='man007')
|
||||
config.str3 = [None]
|
||||
assert config.getowner(config.unwrap_from_path('str3')) == 'user'
|
||||
config.read_only()
|
||||
api = getapi(Config(descr))
|
||||
api.option('str3').value.set([None])
|
||||
assert api.option('str3').owner.get() == 'user'
|
||||
api.property.read_only()
|
||||
prop = []
|
||||
try:
|
||||
config.str3
|
||||
api.option('str3').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
config.read_write()
|
||||
config.str3 = ['yes', None]
|
||||
assert config.getowner(config.unwrap_from_path('str3')) == 'user'
|
||||
config.read_only()
|
||||
api.property.read_write()
|
||||
api.option('str3').value.set(['yes', None])
|
||||
assert api.option('str3').owner.get() == 'user'
|
||||
api.property.read_only()
|
||||
prop = []
|
||||
try:
|
||||
config.str3
|
||||
api.option('str3').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
try:
|
||||
delete_session('config', config.impl_getsessionid())
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
|
||||
|
||||
def test_mandatory_multi_empty():
|
||||
descr = make_description()
|
||||
config = Config(descr, session_id='man008')
|
||||
config.str3 = []
|
||||
assert config.getowner(config.unwrap_from_path('str3')) == 'user'
|
||||
config.read_only()
|
||||
api = getapi(Config(descr))
|
||||
api.option('str3').value.set([])
|
||||
assert api.option('str3').owner.get() == 'user'
|
||||
api.property.read_only()
|
||||
prop = []
|
||||
try:
|
||||
config.str3
|
||||
api.option('str3').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
#
|
||||
config.read_write()
|
||||
config.str3 = ['']
|
||||
assert config.getowner(config.unwrap_from_path('str3')) == 'user'
|
||||
config.read_only()
|
||||
api.property.read_write()
|
||||
api.option('str3').value.set([''])
|
||||
assert api.option('str3').owner.get() == 'user'
|
||||
api.property.read_only()
|
||||
prop = []
|
||||
try:
|
||||
config.str3
|
||||
api.option('str3').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
#
|
||||
config.read_write()
|
||||
config.str3 = ['yes', '']
|
||||
assert config.getowner(config.unwrap_from_path('str3')) == 'user'
|
||||
config.read_only()
|
||||
api.property.read_write()
|
||||
api.option('str3').value.set(['yes', ''])
|
||||
assert api.option('str3').owner.get() == 'user'
|
||||
api.property.read_only()
|
||||
prop = []
|
||||
try:
|
||||
config.str3
|
||||
api.option('str3').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
try:
|
||||
delete_session('config', config.impl_getsessionid())
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
|
||||
|
||||
def test_mandatory_multi_empty_allow_empty_list():
|
||||
descr = make_description()
|
||||
config = Config(descr, session_id='man009')
|
||||
config.str4 = []
|
||||
assert config.getowner(config.unwrap_from_path('str4')) == 'user'
|
||||
config.read_only()
|
||||
api = getapi(Config(descr))
|
||||
api.option('str4').value.set([])
|
||||
assert api.option('str4').owner.get() == 'user'
|
||||
api.property.read_only()
|
||||
prop = []
|
||||
config.str4
|
||||
api.option('str4').value.get()
|
||||
#
|
||||
config.read_write()
|
||||
config.str4 = ['']
|
||||
assert config.getowner(config.unwrap_from_path('str4')) == 'user'
|
||||
config.read_only()
|
||||
api.property.read_write()
|
||||
api.option('str4').value.set([''])
|
||||
assert api.option('str4').owner.get() == 'user'
|
||||
api.property.read_only()
|
||||
prop = []
|
||||
try:
|
||||
config.str4
|
||||
api.option('str4').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
#
|
||||
config.read_write()
|
||||
config.str4 = ['yes', '']
|
||||
assert config.getowner(config.unwrap_from_path('str4')) == 'user'
|
||||
config.read_only()
|
||||
api.property.read_write()
|
||||
api.option('str4').value.set(['yes', ''])
|
||||
assert api.option('str4').owner.get() == 'user'
|
||||
api.property.read_only()
|
||||
prop = []
|
||||
try:
|
||||
config.str4
|
||||
api.option('str4').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
try:
|
||||
delete_session('config', config.impl_getsessionid())
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
|
||||
|
||||
def test_mandatory_multi_append():
|
||||
descr = make_description()
|
||||
config = Config(descr, session_id='man010')
|
||||
config.str3 = ['yes']
|
||||
config.read_write()
|
||||
config.str3.append(None)
|
||||
try:
|
||||
delete_session('config', config.impl_getsessionid())
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
api = getapi(Config(descr))
|
||||
api.option('str3').value.set(['yes'])
|
||||
api.property.read_write()
|
||||
api.option('str3').value.get().append(None)
|
||||
|
||||
|
||||
def test_mandatory_disabled():
|
||||
descr = make_description()
|
||||
config = Config(descr, session_id='man011')
|
||||
setting = config.cfgimpl_get_settings()
|
||||
config.str1
|
||||
config.read_only()
|
||||
prop = []
|
||||
api = getapi(Config(descr))
|
||||
api.option('str1').value.get()
|
||||
api.option('str1').property.add('disabled')
|
||||
api.property.read_only()
|
||||
pop = []
|
||||
try:
|
||||
config.str1
|
||||
api.option('str1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert prop == ['mandatory']
|
||||
setting[descr.str1].append('disabled')
|
||||
prop = []
|
||||
try:
|
||||
config.str1
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert set(prop) == set(['disabled', 'mandatory'])
|
||||
try:
|
||||
delete_session('config', config.impl_getsessionid())
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
if TIRAMISU_VERSION == 2:
|
||||
search_prop = {'disabled', 'mandatory'}
|
||||
else:
|
||||
search_prop = {'disabled'}
|
||||
assert set(prop) == search_prop
|
||||
|
||||
|
||||
def test_mandatory_unicode():
|
||||
descr = make_description()
|
||||
config = Config(descr, session_id='man012')
|
||||
config.unicode2
|
||||
config.read_only()
|
||||
api = getapi(Config(descr))
|
||||
api.option('unicode2').value.get()
|
||||
api.property.read_only()
|
||||
prop = []
|
||||
try:
|
||||
config.unicode2
|
||||
api.option('unicode2').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert prop == ['mandatory']
|
||||
config.read_write()
|
||||
config.unicode2 = u''
|
||||
config.read_only()
|
||||
assert 'mandatory' in prop
|
||||
api.property.read_write()
|
||||
api.option('unicode2').value.set(u'')
|
||||
api.property.read_only()
|
||||
prop = []
|
||||
try:
|
||||
config.unicode2
|
||||
api.option('unicode2').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert prop == ['mandatory']
|
||||
try:
|
||||
delete_session('config', config.impl_getsessionid())
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
assert 'mandatory' in prop
|
||||
|
||||
|
||||
def test_mandatory_warnings_ro():
|
||||
descr = make_description()
|
||||
config = Config(descr, session_id='man013')
|
||||
config.str = ''
|
||||
config.read_only()
|
||||
api = getapi(Config(descr))
|
||||
api.option('str').value.set('')
|
||||
api.property.read_only()
|
||||
proc = []
|
||||
try:
|
||||
config.str
|
||||
api.option('str').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
proc = err.proptype
|
||||
assert proc == ['mandatory']
|
||||
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str', 'str1', 'unicode2', 'str3']
|
||||
config.read_write()
|
||||
config.str = 'a'
|
||||
config.read_only()
|
||||
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str1', 'unicode2', 'str3']
|
||||
try:
|
||||
delete_session('config', config.impl_getsessionid())
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
assert list(api.value.mandatory_warnings()) == ['str', 'str1', 'unicode2', 'str3']
|
||||
api.property.read_write()
|
||||
api.option('str').value.set('a')
|
||||
api.property.read_only()
|
||||
assert list(api.value.mandatory_warnings()) == ['str1', 'unicode2', 'str3']
|
||||
|
||||
|
||||
def test_mandatory_warnings_rw():
|
||||
descr = make_description()
|
||||
config = Config(descr, session_id='man100')
|
||||
config.str = ''
|
||||
config.read_write()
|
||||
config.str
|
||||
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str', 'str1', 'unicode2', 'str3']
|
||||
config.str = 'a'
|
||||
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str1', 'unicode2', 'str3']
|
||||
try:
|
||||
delete_session('config', 'man100')
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
api = getapi(Config(descr))
|
||||
api.option('str').value.set('')
|
||||
api.property.read_write()
|
||||
api.option('str').value.get()
|
||||
assert list(api.value.mandatory_warnings()) == ['str', 'str1', 'unicode2', 'str3']
|
||||
api.option('str').value.set('a')
|
||||
assert list(api.value.mandatory_warnings()) == ['str1', 'unicode2', 'str3']
|
||||
|
||||
|
||||
def test_mandatory_warnings_disabled():
|
||||
descr = make_description()
|
||||
config = Config(descr, session_id='man101')
|
||||
config.str = ''
|
||||
setting = config.cfgimpl_get_settings()
|
||||
config.read_write()
|
||||
config.str
|
||||
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str', 'str1', 'unicode2', 'str3']
|
||||
setting[descr.str].append('disabled')
|
||||
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str1', 'unicode2', 'str3']
|
||||
try:
|
||||
delete_session('config', 'man101')
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
api = getapi(Config(descr))
|
||||
api.option('str').value.set('')
|
||||
api.property.read_write()
|
||||
api.option('str').value.get()
|
||||
assert set(api.value.mandatory_warnings()) == {'str', 'str1', 'unicode2', 'str3'}
|
||||
api.option('str').property.add('disabled')
|
||||
assert set(api.value.mandatory_warnings()) == {'str1', 'unicode2', 'str3'}
|
||||
|
||||
|
||||
def test_mandatory_warnings_hidden():
|
||||
descr = make_description()
|
||||
config = Config(descr, session_id='man102')
|
||||
config.str = ''
|
||||
setting = config.cfgimpl_get_settings()
|
||||
config.read_write()
|
||||
config.cfgimpl_get_settings().setpermissive(('hidden',))
|
||||
config.str
|
||||
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str', 'str1', 'unicode2', 'str3']
|
||||
setting[descr.str].append('hidden')
|
||||
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str', 'str1', 'unicode2', 'str3']
|
||||
try:
|
||||
delete_session('config', 'man102')
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
api = getapi(Config(descr))
|
||||
api.option('str').value.set('')
|
||||
api.property.read_write()
|
||||
api.permissive.set(frozenset(['hidden']))
|
||||
api.option('str').value.get()
|
||||
assert set(api.value.mandatory_warnings()) == {'str', 'str1', 'unicode2', 'str3'}
|
||||
api.option('str').property.add('hidden')
|
||||
assert set(api.value.mandatory_warnings()) == {'str', 'str1', 'unicode2', 'str3'}
|
||||
|
||||
|
||||
def test_mandatory_warnings_frozen():
|
||||
descr = make_description()
|
||||
config = Config(descr, session_id='man103')
|
||||
config.str = ''
|
||||
setting = config.cfgimpl_get_settings()
|
||||
config.read_write()
|
||||
config.str
|
||||
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str', 'str1', 'unicode2', 'str3']
|
||||
setting[descr.str].append('frozen')
|
||||
config.read_only()
|
||||
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str', 'str1', 'unicode2', 'str3']
|
||||
try:
|
||||
delete_session('config', 'man103')
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
api = getapi(Config(descr))
|
||||
api.option('str').value.set('')
|
||||
api.property.read_write()
|
||||
api.option('str').value.get()
|
||||
assert set(api.value.mandatory_warnings()) == {'str', 'str1', 'unicode2', 'str3'}
|
||||
api.option('str').property.add('frozen')
|
||||
api.property.read_only()
|
||||
assert set(api.value.mandatory_warnings()) == {'str', 'str1', 'unicode2', 'str3'}
|
||||
|
||||
|
||||
def test_mandatory_master():
|
||||
|
|
@ -484,16 +394,10 @@ def test_mandatory_master():
|
|||
multi=True)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
o = OptionDescription('o', '', [interface1])
|
||||
config = Config(o, session_id='man104')
|
||||
config.read_only()
|
||||
raises(PropertiesOptionError, 'config.ip_admin_eth0.ip_admin_eth0')
|
||||
raises(PropertiesOptionError, 'config.ip_admin_eth0.netmask_admin_eth0')
|
||||
try:
|
||||
delete_session('config', 'man104')
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
descr = OptionDescription('o', '', [interface1])
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_only()
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()")
|
||||
|
||||
|
||||
def test_mandatory_warnings_master():
|
||||
|
|
@ -503,14 +407,9 @@ def test_mandatory_warnings_master():
|
|||
multi=True)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
o = OptionDescription('o', '', [interface1])
|
||||
config = Config(o, session_id='man105')
|
||||
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['ip_admin_eth0.ip_admin_eth0']
|
||||
try:
|
||||
delete_session('config', 'man105')
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
descr = OptionDescription('o', '', [interface1])
|
||||
api = getapi(Config(descr))
|
||||
assert list(api.value.mandatory_warnings()) == ['ip_admin_eth0.ip_admin_eth0']
|
||||
|
||||
|
||||
def test_mandatory_master_empty():
|
||||
|
|
@ -519,51 +418,41 @@ def test_mandatory_master_empty():
|
|||
multi=True)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
o = OptionDescription('o', '', [interface1])
|
||||
config = Config(o, session_id='man106')
|
||||
config.read_write()
|
||||
assert config.ip_admin_eth0.ip_admin_eth0 == []
|
||||
assert config.ip_admin_eth0.netmask_admin_eth0 == []
|
||||
descr = OptionDescription('o', '', [interface1])
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
#
|
||||
config.ip_admin_eth0.ip_admin_eth0.append()
|
||||
assert config.ip_admin_eth0.ip_admin_eth0 == [None]
|
||||
assert config.ip_admin_eth0.netmask_admin_eth0 == [None]
|
||||
config.read_only()
|
||||
raises(PropertiesOptionError, "config.ip_admin_eth0.ip_admin_eth0")
|
||||
raises(PropertiesOptionError, "config.ip_admin_eth0.netmask_admin_eth0")
|
||||
config.read_write()
|
||||
del(config.ip_admin_eth0.ip_admin_eth0)
|
||||
del(config.ip_admin_eth0.netmask_admin_eth0)
|
||||
assert config.ip_admin_eth0.ip_admin_eth0 == []
|
||||
assert config.ip_admin_eth0.netmask_admin_eth0 == []
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set([undefined])
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [None]
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
|
||||
api.property.read_only()
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()")
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
|
||||
api.property.read_write()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
#
|
||||
config.ip_admin_eth0.ip_admin_eth0.append('')
|
||||
assert config.ip_admin_eth0.ip_admin_eth0 == ['']
|
||||
assert config.ip_admin_eth0.netmask_admin_eth0 == [None]
|
||||
config.read_only()
|
||||
raises(PropertiesOptionError, "config.ip_admin_eth0.ip_admin_eth0")
|
||||
raises(PropertiesOptionError, "config.ip_admin_eth0.netmask_admin_eth0")
|
||||
config.read_write()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set([''])
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['']
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
|
||||
api.property.read_only()
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()")
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
|
||||
api.property.read_write()
|
||||
#
|
||||
config.read_write()
|
||||
config.ip_admin_eth0.ip_admin_eth0 = ['ip']
|
||||
config.read_only()
|
||||
assert config.ip_admin_eth0.ip_admin_eth0 == ['ip']
|
||||
assert config.ip_admin_eth0.netmask_admin_eth0 == [None]
|
||||
api.property.read_write()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
|
||||
api.property.read_only()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
|
||||
#
|
||||
config.read_write()
|
||||
config.ip_admin_eth0.netmask_admin_eth0 = ['ip2']
|
||||
config.read_only()
|
||||
raises(PropertiesOptionError, "del(config.ip_admin_eth0.netmask_admin_eth0)")
|
||||
raises(PropertiesOptionError, "del(config.ip_admin_eth0.ip_admin_eth0)")
|
||||
config.read_write()
|
||||
del(config.ip_admin_eth0.netmask_admin_eth0)
|
||||
del(config.ip_admin_eth0.ip_admin_eth0)
|
||||
try:
|
||||
delete_session('config', 'man106')
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
api.property.read_write()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip2'])
|
||||
api.property.read_only()
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.reset()")
|
||||
api.property.read_write()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
|
||||
|
||||
|
||||
def test_mandatory_warnings_master_empty():
|
||||
|
|
@ -572,29 +461,23 @@ def test_mandatory_warnings_master_empty():
|
|||
multi=True)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
o = OptionDescription('o', '', [interface1])
|
||||
config = Config(o, session_id='man107')
|
||||
config.read_write()
|
||||
config.ip_admin_eth0.ip_admin_eth0.append()
|
||||
assert config.ip_admin_eth0.ip_admin_eth0 == [None]
|
||||
assert config.ip_admin_eth0.netmask_admin_eth0 == [None]
|
||||
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['ip_admin_eth0.ip_admin_eth0']
|
||||
del(config.ip_admin_eth0.ip_admin_eth0)
|
||||
del(config.ip_admin_eth0.netmask_admin_eth0)
|
||||
descr = OptionDescription('o', '', [interface1])
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set([undefined])
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [None]
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
|
||||
assert list(api.value.mandatory_warnings()) == ['ip_admin_eth0.ip_admin_eth0']
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
|
||||
#
|
||||
config.ip_admin_eth0.ip_admin_eth0.append('')
|
||||
assert config.ip_admin_eth0.ip_admin_eth0 == ['']
|
||||
assert config.ip_admin_eth0.netmask_admin_eth0 == [None]
|
||||
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['ip_admin_eth0.ip_admin_eth0']
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set([''])
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['']
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
|
||||
assert list(api.value.mandatory_warnings()) == ['ip_admin_eth0.ip_admin_eth0']
|
||||
#
|
||||
config.read_write()
|
||||
config.ip_admin_eth0.ip_admin_eth0 = ['ip']
|
||||
assert list(config.cfgimpl_get_values().mandatory_warnings()) == []
|
||||
try:
|
||||
delete_session('config', 'man107')
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
api.property.read_write()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
|
||||
assert list(api.value.mandatory_warnings()) == []
|
||||
|
||||
|
||||
def test_mandatory_slave():
|
||||
|
|
@ -603,36 +486,28 @@ def test_mandatory_slave():
|
|||
multi=True, properties=('mandatory', ))
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
o = OptionDescription('o', '', [interface1])
|
||||
config = Config(o, session_id='man108')
|
||||
config.read_only()
|
||||
assert config.ip_admin_eth0.ip_admin_eth0 == []
|
||||
assert config.ip_admin_eth0.netmask_admin_eth0 == []
|
||||
descr = OptionDescription('o', '', [interface1])
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_only()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
#
|
||||
config.read_write()
|
||||
config.ip_admin_eth0.ip_admin_eth0.append('ip')
|
||||
config.read_only()
|
||||
assert config.ip_admin_eth0.ip_admin_eth0 == ['ip']
|
||||
assert len(config.ip_admin_eth0.netmask_admin_eth0) == 1
|
||||
raises(PropertiesOptionError, 'config.ip_admin_eth0.netmask_admin_eth0[0]')
|
||||
api.property.read_write()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
|
||||
api.property.read_only()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
|
||||
#
|
||||
config.read_write()
|
||||
config.ip_admin_eth0.netmask_admin_eth0 = ['']
|
||||
config.read_only()
|
||||
assert config.ip_admin_eth0.ip_admin_eth0 == ['ip']
|
||||
assert len(config.ip_admin_eth0.netmask_admin_eth0) == 1
|
||||
raises(PropertiesOptionError, 'config.ip_admin_eth0.netmask_admin_eth0[0]')
|
||||
api.property.read_write()
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('')
|
||||
api.property.read_only()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
|
||||
#
|
||||
config.read_write()
|
||||
config.ip_admin_eth0.netmask_admin_eth0 = ['ip']
|
||||
config.read_only()
|
||||
assert config.ip_admin_eth0.ip_admin_eth0 == ['ip']
|
||||
assert config.ip_admin_eth0.netmask_admin_eth0 == ['ip']
|
||||
try:
|
||||
delete_session('config', 'man108')
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
api.property.read_write()
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('ip')
|
||||
api.property.read_only()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == 'ip'
|
||||
|
||||
|
||||
def test_mandatory_warnings_slave():
|
||||
|
|
@ -641,97 +516,65 @@ def test_mandatory_warnings_slave():
|
|||
multi=True, properties=('mandatory', ))
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
o = OptionDescription('o', '', [interface1])
|
||||
config = Config(o, session_id='man109')
|
||||
config.read_only()
|
||||
assert config.ip_admin_eth0.ip_admin_eth0 == []
|
||||
assert config.ip_admin_eth0.netmask_admin_eth0 == []
|
||||
descr = OptionDescription('o', '', [interface1])
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_only()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
#
|
||||
config.read_write()
|
||||
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['ip_admin_eth0.netmask_admin_eth0']
|
||||
config.ip_admin_eth0.ip_admin_eth0.append('ip')
|
||||
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['ip_admin_eth0.netmask_admin_eth0']
|
||||
try:
|
||||
delete_session('config', 'man109')
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
api.property.read_write()
|
||||
assert list(api.value.mandatory_warnings()) == []
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
|
||||
assert list(api.value.mandatory_warnings()) == ['ip_admin_eth0.netmask_admin_eth0']
|
||||
|
||||
|
||||
def test_mandatory_warnings_symlink():
|
||||
descr = make_description_sym()
|
||||
config = Config(descr, session_id='man110')
|
||||
config.str = ''
|
||||
setting = config.cfgimpl_get_settings()
|
||||
config.read_write()
|
||||
config.str
|
||||
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str', 'str1', 'str3']
|
||||
setting[descr.str].append('frozen')
|
||||
config.read_only()
|
||||
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str', 'str1', 'str3']
|
||||
try:
|
||||
delete_session('config', 'man110')
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
api = getapi(Config(descr))
|
||||
api.option('str').value.set('')
|
||||
api.property.read_write()
|
||||
api.option('str').value.get()
|
||||
assert list(api.value.mandatory_warnings()) == ['str', 'str1', 'str3']
|
||||
api.option('str').property.add('frozen')
|
||||
api.property.read_only()
|
||||
assert list(api.value.mandatory_warnings()) == ['str', 'str1', 'str3']
|
||||
|
||||
|
||||
def test_mandatory_warnings_validate():
|
||||
descr = make_description3()
|
||||
config = Config(descr, session_id='man111')
|
||||
config.str = ''
|
||||
raises(ValueError, "list(config.cfgimpl_get_values().mandatory_warnings())")
|
||||
config.str = 'test'
|
||||
raises(ValueError, "list(config.cfgimpl_get_values().mandatory_warnings())")
|
||||
try:
|
||||
delete_session('config', 'man111')
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
#def test_mandatory_warnings_validate():
|
||||
# descr = make_description3()
|
||||
# api = getapi(Config(descr))
|
||||
# api.option('str').value.set('')
|
||||
# raises(ValueError, "list(api.value.mandatory_warnings())")
|
||||
# api.option('str').value.set('test')
|
||||
# raises(ValueError, "list(api.value.mandatory_warnings())")
|
||||
|
||||
|
||||
def test_mandatory_warnings_validate_empty():
|
||||
descr = make_description2()
|
||||
config = Config(descr, session_id='man112')
|
||||
config.str = ''
|
||||
config.read_only()
|
||||
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str', 'str1', 'str3', 'unicode1']
|
||||
try:
|
||||
delete_session('config', 'man112')
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
api = getapi(Config(descr))
|
||||
api.option('str').value.set('')
|
||||
api.property.read_only()
|
||||
assert list(api.value.mandatory_warnings()) == ['str', 'str1', 'str3', 'unicode1']
|
||||
|
||||
|
||||
def test_mandatory_warnings_requires():
|
||||
descr = make_description4()
|
||||
config = Config(descr, session_id='man113')
|
||||
config.str = ''
|
||||
config.read_write()
|
||||
config.str
|
||||
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str', 'str1', 'unicode2']
|
||||
config.read_only()
|
||||
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str', 'str1', 'unicode2']
|
||||
config.read_write()
|
||||
config.str = 'yes'
|
||||
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str1', 'unicode2', 'str3']
|
||||
try:
|
||||
delete_session('config', 'man113')
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
api = getapi(Config(descr))
|
||||
api.option('str').value.set('')
|
||||
api.property.read_write()
|
||||
api.option('str').value.get()
|
||||
assert list(api.value.mandatory_warnings()) == ['str', 'str1', 'unicode2']
|
||||
api.property.read_only()
|
||||
assert list(api.value.mandatory_warnings()) == ['str', 'str1', 'unicode2']
|
||||
api.property.read_write()
|
||||
api.option('str').value.set('yes')
|
||||
assert list(api.value.mandatory_warnings()) == ['str1', 'unicode2', 'str3']
|
||||
|
||||
|
||||
def test_mandatory_od_disabled():
|
||||
descr = make_description()
|
||||
od = OptionDescription('od', '', [descr])
|
||||
config = Config(od, session_id='man114')
|
||||
config.read_only()
|
||||
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['tiram.str1', 'tiram.unicode2', 'tiram.str3']
|
||||
config.cfgimpl_get_settings()[descr].append('disabled')
|
||||
assert list(config.cfgimpl_get_values().mandatory_warnings()) == []
|
||||
try:
|
||||
delete_session('config', 'man114')
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
descr = OptionDescription('od', '', [descr])
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_only()
|
||||
assert list(api.value.mandatory_warnings()) == ['tiram.str1', 'tiram.unicode2', 'tiram.str3']
|
||||
api.option('tiram').property.add('disabled')
|
||||
assert list(api.value.mandatory_warnings()) == []
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,21 +0,0 @@
|
|||
# coding: utf-8
|
||||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
|
||||
#from tiramisu.value import Multi
|
||||
from tiramisu.option import IntOption, StrOption, OptionDescription
|
||||
from tiramisu.config import Config
|
||||
from tiramisu.error import ConfigError, PropertiesOptionError
|
||||
from tiramisu.setting import groups
|
||||
|
||||
import weakref
|
||||
from py.test import raises
|
||||
|
||||
|
||||
def test_non_valid_multi():
|
||||
raises(ValueError, "IntOption('int', '', multi='string')")
|
||||
raises(ValueError, "IntOption('int', '', multi=True, unique='string')")
|
||||
|
||||
|
||||
def test_non_multi_unique():
|
||||
raises(ValueError, "IntOption('int', '', unique=True)")
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -4,10 +4,11 @@ do_autopath()
|
|||
from py.test import raises
|
||||
|
||||
from tiramisu.setting import owners, groups
|
||||
from tiramisu.config import Config
|
||||
from tiramisu.option import IPOption, NetworkOption, NetmaskOption, IntOption,\
|
||||
BroadcastOption, StrOption, SymLinkOption, OptionDescription, submulti, MasterSlaves
|
||||
from tiramisu import IPOption, NetworkOption, NetmaskOption, IntOption,\
|
||||
BroadcastOption, StrOption, SymLinkOption, OptionDescription, submulti, MasterSlaves,\
|
||||
Config, getapi, undefined
|
||||
from tiramisu.error import ConfigError, ValueWarning, PropertiesOptionError
|
||||
from tiramisu.api import TIRAMISU_VERSION
|
||||
import warnings
|
||||
|
||||
|
||||
|
|
@ -51,11 +52,11 @@ def test_consistency_warnings_only():
|
|||
b = IntOption('b', '')
|
||||
od = OptionDescription('od', '', [a, b])
|
||||
a.impl_add_consistency('not_equal', b, warnings_only=True)
|
||||
c = Config(od)
|
||||
c.a = 1
|
||||
api = getapi(Config(od))
|
||||
api.option('a').value.set(1)
|
||||
warnings.simplefilter("always", ValueWarning)
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
c.b = 1
|
||||
api.option('b').value.set(1)
|
||||
assert w != []
|
||||
|
||||
|
||||
|
|
@ -65,19 +66,19 @@ def test_consistency_warnings_only_more_option():
|
|||
d = IntOption('d', '')
|
||||
od = OptionDescription('od', '', [a, b, d])
|
||||
a.impl_add_consistency('not_equal', b, d, warnings_only=True)
|
||||
c = Config(od)
|
||||
c.a = 1
|
||||
api = getapi(Config(od))
|
||||
api.option('a').value.set(1)
|
||||
warnings.simplefilter("always", ValueWarning)
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
c.b = 1
|
||||
api.option('b').value.set(1)
|
||||
assert w != []
|
||||
assert len(w) == 1
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
c.d
|
||||
api.option('d').value.get()
|
||||
assert w != []
|
||||
assert len(w) == 1
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
c.d = 1
|
||||
api.option('d').value.set(1)
|
||||
assert w != []
|
||||
assert len(w) == 1
|
||||
|
||||
|
|
@ -87,14 +88,14 @@ def test_consistency_not_equal():
|
|||
b = IntOption('b', '')
|
||||
od = OptionDescription('od', '', [a, b])
|
||||
a.impl_add_consistency('not_equal', b)
|
||||
c = Config(od)
|
||||
assert c.a is None
|
||||
assert c.b is None
|
||||
c.a = 1
|
||||
del(c.a)
|
||||
c.a = 1
|
||||
raises(ValueError, "c.b = 1")
|
||||
c.b = 2
|
||||
api = getapi(Config(od))
|
||||
assert api.option('a').value.get() is None
|
||||
assert api.option('b').value.get() is None
|
||||
api.option('a').value.set(1)
|
||||
api.option('a').value.reset()
|
||||
api.option('a').value.set(1)
|
||||
raises(ValueError, "api.option('b').value.set(1)")
|
||||
api.option('b').value.set(2)
|
||||
|
||||
|
||||
def test_consistency_not_equal_many_opts():
|
||||
|
|
@ -106,25 +107,26 @@ def test_consistency_not_equal_many_opts():
|
|||
f = IntOption('f', '')
|
||||
od = OptionDescription('od', '', [a, b, c, d, e, f])
|
||||
a.impl_add_consistency('not_equal', b, c, d, e, f)
|
||||
c = Config(od)
|
||||
assert c.a is None
|
||||
assert c.b is None
|
||||
api = getapi(Config(od))
|
||||
assert api.option('a').value.get() is None
|
||||
assert api.option('b').value.get() is None
|
||||
#
|
||||
c.a = 1
|
||||
del(c.a)
|
||||
api.option('a').value.set(1)
|
||||
api.option('a').value.reset()
|
||||
#
|
||||
c.a = 1
|
||||
raises(ValueError, "c.b = 1")
|
||||
api.option('a').value.set(1)
|
||||
raises(ValueError, "api.option('b').value.set(1)")
|
||||
#
|
||||
c.b = 2
|
||||
raises(ValueError, "c.f = 2")
|
||||
raises(ValueError, "c.f = 1")
|
||||
api.option('b').value.set(2)
|
||||
raises(ValueError, "api.option('f').value.set(2)")
|
||||
raises(ValueError, "api.option('f').value.set(1)")
|
||||
#
|
||||
c.d = 3
|
||||
raises(ValueError, "c.f = 3")
|
||||
raises(ValueError, "c.a = 3")
|
||||
raises(ValueError, "c.c = 3")
|
||||
raises(ValueError, "c.e = 3")
|
||||
api.option('d').value.set(3)
|
||||
raises(ValueError, "api.option('f').value.set(3)")
|
||||
raises(ValueError, "api.option('a').value.set(3)")
|
||||
api.option('d').value.set(3)
|
||||
raises(ValueError, "api.option('c').value.set(3)")
|
||||
raises(ValueError, "api.option('e').value.set(3)")
|
||||
|
||||
|
||||
def test_consistency_not_equal_many_opts_one_disabled():
|
||||
|
|
@ -137,26 +139,26 @@ def test_consistency_not_equal_many_opts_one_disabled():
|
|||
g = IntOption('g', '', properties=('disabled',))
|
||||
od = OptionDescription('od', '', [a, b, c, d, e, f, g])
|
||||
a.impl_add_consistency('not_equal', b, c, d, e, f, g, transitive=False)
|
||||
c = Config(od)
|
||||
c.read_write()
|
||||
assert c.a is None
|
||||
assert c.b is None
|
||||
api = getapi(Config(od))
|
||||
api.property.read_write()
|
||||
assert api.option('a').value.get() is None
|
||||
assert api.option('b').value.get() is None
|
||||
#
|
||||
c.a = 1
|
||||
del(c.a)
|
||||
api.option('a').value.set(1)
|
||||
api.option('a').value.reset()
|
||||
#
|
||||
c.a = 1
|
||||
raises(ValueError, "c.b = 1")
|
||||
api.option('a').value.set(1)
|
||||
raises(ValueError, "api.option('b').value.set(1)")
|
||||
#
|
||||
c.b = 2
|
||||
raises(ValueError, "c.f = 2")
|
||||
raises(ValueError, "c.f = 1")
|
||||
api.option('b').value.set(2)
|
||||
raises(ValueError, "api.option('f').value.set(2)")
|
||||
raises(ValueError, "api.option('f').value.set(1)")
|
||||
#
|
||||
c.d = 3
|
||||
raises(ValueError, "c.f = 3")
|
||||
raises(ValueError, "c.a = 3")
|
||||
raises(ValueError, "c.c = 3")
|
||||
raises(ValueError, "c.e = 3")
|
||||
api.option('d').value.set(3)
|
||||
raises(ValueError, "api.option('f').value.set(3)")
|
||||
raises(ValueError, "api.option('a').value.set(3)")
|
||||
raises(ValueError, "api.option('c').value.set(3)")
|
||||
raises(ValueError, "api.option('e').value.set(3)")
|
||||
|
||||
|
||||
def test_consistency_not_in_config_1():
|
||||
|
|
@ -188,7 +190,7 @@ def test_consistency_not_in_config_3():
|
|||
od = OptionDescription('root', '', [od1, od2])
|
||||
od
|
||||
#with subconfig
|
||||
raises(ConfigError, "Config(od.od1)")
|
||||
raises(ConfigError, "Config(od1)")
|
||||
|
||||
|
||||
def test_consistency_after_config():
|
||||
|
|
@ -207,7 +209,7 @@ def test_consistency_not_equal_symlink():
|
|||
c = SymLinkOption('c', a)
|
||||
od = OptionDescription('od', '', [a, b, c])
|
||||
a.impl_add_consistency('not_equal', b)
|
||||
c = Config(od)
|
||||
api = getapi(Config(od))
|
||||
assert set(od._cache_consistencies.keys()) == set([a, b])
|
||||
|
||||
|
||||
|
|
@ -230,23 +232,19 @@ def test_consistency_not_equal_masterslave():
|
|||
a = IntOption('a', '', multi=True)
|
||||
b = IntOption('b', '', multi=True)
|
||||
od = MasterSlaves('a', '', [a, b])
|
||||
od2 = OptionDescription('b', '', [od])
|
||||
#od.impl_set_group_type(groups.master)
|
||||
a.impl_add_consistency('not_equal', b)
|
||||
c = Config(od)
|
||||
assert c.a == []
|
||||
assert c.b == []
|
||||
c.a = [1]
|
||||
del(c.a)
|
||||
c.a = [1]
|
||||
raises(ValueError, "c.b = [1]")
|
||||
c.b = [2]
|
||||
del(c.a)
|
||||
c.a.append(1)
|
||||
c.make_dict()
|
||||
c.b[0] = 3
|
||||
c.a.append(2)
|
||||
c.b[0] = 3
|
||||
raises(ValueError, "c.b[1] = 3")
|
||||
api = getapi(Config(od2))
|
||||
assert api.option('a.a').value.get() == []
|
||||
api.option('a.a').value.set([1])
|
||||
api.option('a.a').value.reset()
|
||||
api.option('a.a').value.set([1])
|
||||
raises(ValueError, "api.option('a.b', 0).value.set(1)")
|
||||
api.option('a.b', 0).value.set(2)
|
||||
api.option('a.a').value.reset()
|
||||
api.option('a.a').value.set([1])
|
||||
api.option.make_dict()
|
||||
|
||||
|
||||
def test_consistency_not_equal_masterslave_error_multi1():
|
||||
|
|
@ -289,14 +287,14 @@ def test_consistency_not_equal_masterslaves_default():
|
|||
a = IntOption('a', '', multi=True)
|
||||
b = IntOption('b', '', multi=True, default_multi=1)
|
||||
od = MasterSlaves('a', '', [a, b])
|
||||
od2 = OptionDescription('a', '', [od])
|
||||
#od.impl_set_group_type(groups.master)
|
||||
a.impl_add_consistency('not_equal', b)
|
||||
c = Config(od)
|
||||
assert c.a == []
|
||||
assert c.b == []
|
||||
raises(ValueError, 'c.a = [1]')
|
||||
c.a = [2]
|
||||
del(c.a)
|
||||
api = getapi(Config(od2))
|
||||
assert api.option('a.a').value.get() == []
|
||||
raises(ValueError, "api.option('a.a').value.set([1])")
|
||||
api.option('a.a').value.set([2])
|
||||
api.option('a.a').value.reset()
|
||||
|
||||
|
||||
def test_consistency_not_equal_multi():
|
||||
|
|
@ -304,20 +302,18 @@ def test_consistency_not_equal_multi():
|
|||
b = IntOption('b', '', multi=True)
|
||||
od = OptionDescription('a', '', [a, b])
|
||||
a.impl_add_consistency('not_equal', b)
|
||||
c = Config(od)
|
||||
assert c.a == []
|
||||
assert c.b == []
|
||||
c.a = [1]
|
||||
del(c.a)
|
||||
c.a = [1]
|
||||
raises(ValueError, "c.b = [1]")
|
||||
c.b = [2]
|
||||
raises(ValueError, "c.b = [2, 1]")
|
||||
raises(ValueError, "c.b.append(1)")
|
||||
c.b.append(3)
|
||||
raises(ValueError, "c.b.append(3)")
|
||||
raises(ValueError, "c.a.append(3)")
|
||||
raises(ValueError, "c.a.append(3)")
|
||||
api = getapi(Config(od))
|
||||
assert api.option('a').value.get() == []
|
||||
assert api.option('b').value.get() == []
|
||||
api.option('a').value.set([1])
|
||||
api.option('a').value.reset()
|
||||
api.option('a').value.set([1])
|
||||
raises(ValueError, "api.option('b').value.set([1])")
|
||||
api.option('a').value.set([2])
|
||||
raises(ValueError, "api.option('b').value.set([2, 1])")
|
||||
api.option('a').value.set([2, 3])
|
||||
raises(ValueError, "api.option('a').value.set([2, 3, 3])")
|
||||
raises(ValueError, "api.option('b').value.set([2, 3])")
|
||||
|
||||
|
||||
def test_consistency_not_equal_multi_default():
|
||||
|
|
@ -332,11 +328,11 @@ def test_consistency_not_equal_multi_default_modif():
|
|||
b = IntOption('b', '', multi=True, default=[1, 2])
|
||||
od = OptionDescription('a', '', [a, b])
|
||||
a.impl_add_consistency('not_equal', b)
|
||||
c = Config(od)
|
||||
assert c.a == []
|
||||
assert c.b == [1, 2]
|
||||
raises(ValueError, 'c.a.append(1)')
|
||||
raises(ValueError, 'c.b.append(1)')
|
||||
api = getapi(Config(od))
|
||||
assert api.option('a').value.get() == []
|
||||
assert api.option('b').value.get() == [1, 2]
|
||||
raises(ValueError, "api.option('a').value.set([1])")
|
||||
raises(ValueError, "api.option('b').value.set([1, 2, 1])")
|
||||
|
||||
|
||||
def test_consistency_default():
|
||||
|
|
@ -352,7 +348,8 @@ def test_consistency_default_multi():
|
|||
c = IntOption('c', '', [1, 2], multi=True)
|
||||
b
|
||||
raises(ValueError, "a.impl_add_consistency('not_equal', b)")
|
||||
a.impl_add_consistency('not_equal', c)
|
||||
if TIRAMISU_VERSION != 2:
|
||||
raises(ValueError, "a.impl_add_consistency('not_equal', c)")
|
||||
|
||||
|
||||
def test_consistency_default_diff():
|
||||
|
|
@ -360,13 +357,14 @@ def test_consistency_default_diff():
|
|||
b = IntOption('b', '', 1)
|
||||
od = OptionDescription('od', '', [a, b])
|
||||
a.impl_add_consistency('not_equal', b)
|
||||
c = Config(od)
|
||||
raises(ValueError, "c.a = 1")
|
||||
c.a = 2
|
||||
c.b = 3
|
||||
assert c.getowner(a) is owners.user
|
||||
raises(ValueError, "del(c.a)")
|
||||
assert c.getowner(a) is owners.user
|
||||
api = getapi(Config(od))
|
||||
raises(ValueError, "api.option('a').value.set(1)")
|
||||
api.option('a').value.set(2)
|
||||
api.option('b').value.set(3)
|
||||
owner = api.owner.get()
|
||||
assert api.option('a').owner.get() == owner
|
||||
raises(ValueError, "api.option('a').value.reset()")
|
||||
assert api.option('a').owner.get() == owner
|
||||
|
||||
|
||||
def test_consistency_ip_netmask():
|
||||
|
|
@ -374,14 +372,14 @@ def test_consistency_ip_netmask():
|
|||
b = NetmaskOption('b', '')
|
||||
od = OptionDescription('od', '', [a, b])
|
||||
b.impl_add_consistency('ip_netmask', a)
|
||||
c = Config(od)
|
||||
c.a = '192.168.1.1'
|
||||
c.b = '255.255.255.0'
|
||||
c.a = '192.168.1.2'
|
||||
c.b = '255.255.255.255'
|
||||
c.b = '255.255.255.0'
|
||||
raises(ValueError, "c.a = '192.168.1.0'")
|
||||
raises(ValueError, "c.a = '192.168.1.255'")
|
||||
api = getapi(Config(od))
|
||||
api.option('a').value.set('192.168.1.1')
|
||||
api.option('b').value.set('255.255.255.0')
|
||||
api.option('a').value.set('192.168.1.2')
|
||||
api.option('b').value.set('255.255.255.255')
|
||||
api.option('b').value.set('255.255.255.0')
|
||||
raises(ValueError, "api.option('a').value.set('192.168.1.0')")
|
||||
raises(ValueError, "api.option('a').value.set('192.168.1.255')")
|
||||
|
||||
|
||||
def test_consistency_network_netmask():
|
||||
|
|
@ -389,13 +387,13 @@ def test_consistency_network_netmask():
|
|||
b = NetmaskOption('b', '')
|
||||
od = OptionDescription('od', '', [a, b])
|
||||
b.impl_add_consistency('network_netmask', a)
|
||||
c = Config(od)
|
||||
c.a = '192.168.1.1'
|
||||
c.b = '255.255.255.255'
|
||||
del(c.b)
|
||||
c.a = '192.168.1.0'
|
||||
c.b = '255.255.255.0'
|
||||
raises(ValueError, "c.a = '192.168.1.1'")
|
||||
api = getapi(Config(od))
|
||||
api.option('a').value.set('192.168.1.1')
|
||||
api.option('b').value.set('255.255.255.255')
|
||||
api.option('b').value.reset()
|
||||
api.option('a').value.set('192.168.1.0')
|
||||
api.option('b').value.set('255.255.255.0')
|
||||
raises(ValueError, "api.option('a').value.set('192.168.1.1')")
|
||||
|
||||
|
||||
def test_consistency_ip_in_network():
|
||||
|
|
@ -407,15 +405,15 @@ def test_consistency_ip_in_network():
|
|||
c.impl_add_consistency('in_network', a, b)
|
||||
d.impl_add_consistency('in_network', a, b, warnings_only=True)
|
||||
warnings.simplefilter("always", ValueWarning)
|
||||
cfg = Config(od)
|
||||
cfg.a = '192.168.1.0'
|
||||
cfg.b = '255.255.255.0'
|
||||
cfg.c = '192.168.1.1'
|
||||
raises(ValueError, "cfg.c = '192.168.2.1'")
|
||||
raises(ValueError, "cfg.c = '192.168.1.0'")
|
||||
raises(ValueError, "cfg.c = '192.168.1.255'")
|
||||
api = getapi(Config(od))
|
||||
api.option('a').value.set('192.168.1.0')
|
||||
api.option('b').value.set('255.255.255.0')
|
||||
api.option('c').value.set('192.168.1.1')
|
||||
raises(ValueError, "api.option('c').value.set('192.168.2.1')")
|
||||
raises(ValueError, "api.option('c').value.set('192.168.1.0')")
|
||||
raises(ValueError, "api.option('c').value.set('192.168.1.255')")
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
cfg.d = '192.168.2.1'
|
||||
api.option('d').value.set('192.168.2.1')
|
||||
assert len(w) == 1
|
||||
|
||||
|
||||
|
|
@ -433,10 +431,10 @@ def test_consistency_ip_netmask_network_error():
|
|||
c = NetmaskOption('c', '')
|
||||
od = OptionDescription('od', '', [a, b, c])
|
||||
c.impl_add_consistency('ip_netmask', a, b)
|
||||
c = Config(od)
|
||||
c.a = '192.168.1.1'
|
||||
c.b = '192.168.1.0'
|
||||
raises(ConfigError, "c.c = '255.255.255.0'")
|
||||
api = getapi(Config(od))
|
||||
api.option('a').value.set('192.168.1.1')
|
||||
api.option('b').value.set('192.168.1.0')
|
||||
raises(ConfigError, "api.option('c').value.set('255.255.255.0')")
|
||||
|
||||
|
||||
def test_consistency_ip_netmask_error_multi():
|
||||
|
|
@ -451,40 +449,43 @@ def test_consistency_ip_netmask_multi():
|
|||
b = NetmaskOption('b', '', multi=True)
|
||||
od = MasterSlaves('a', '', [a, b])
|
||||
b.impl_add_consistency('ip_netmask', a)
|
||||
#od.impl_set_group_type(groups.master)
|
||||
c = Config(od)
|
||||
c.a = ['192.168.1.1']
|
||||
c.b = ['255.255.255.0']
|
||||
c.a = ['192.168.1.2']
|
||||
c.b = ['255.255.255.255']
|
||||
c.b = ['255.255.255.0']
|
||||
raises(ValueError, "c.a = ['192.168.1.0']")
|
||||
od2 = OptionDescription('od2', '', [od])
|
||||
api = getapi(Config(od2))
|
||||
api.option('a.a').value.set(['192.168.1.1'])
|
||||
api.option('a.b', 0).value.set('255.255.255.0')
|
||||
api.option('a.a').value.set(['192.168.1.2'])
|
||||
api.option('a.b', 0).value.set('255.255.255.255')
|
||||
api.option('a.b', 0).value.set('255.255.255.0')
|
||||
raises(ValueError, "api.option('a.a').value.set(['192.168.1.0'])")
|
||||
|
||||
|
||||
def test_consistency_network_netmask_multi():
|
||||
a = NetworkOption('a', '', multi=True)
|
||||
b = NetmaskOption('b', '', multi=True)
|
||||
od = MasterSlaves('a', '', [a, b])
|
||||
#od.impl_set_group_type(groups.master)
|
||||
b.impl_add_consistency('network_netmask', a)
|
||||
c = Config(od)
|
||||
c.a = ['192.168.1.1']
|
||||
c.b = ['255.255.255.255']
|
||||
del(c.b)
|
||||
c.a = ['192.168.1.0']
|
||||
c.b = ['255.255.255.0']
|
||||
raises(ValueError, "c.a = ['192.168.1.1']")
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
api = getapi(Config(od2))
|
||||
api.option('a.a').value.set(['192.168.1.1'])
|
||||
api.option('a.b', 0).value.set('255.255.255.255')
|
||||
api.option('a.b', 0).value.reset()
|
||||
api.option('a.a').value.set(['192.168.1.0'])
|
||||
api.option('a.b', 0).value.set('255.255.255.0')
|
||||
raises(ValueError, "api.option('a.a').value.set(['192.168.1.1'])")
|
||||
|
||||
|
||||
def test_consistency_network_netmask_multi_slave_default_multi():
|
||||
a = NetworkOption('a', '', default_multi=u'192.168.1.0', multi=True, properties=('mandatory',))
|
||||
b = NetmaskOption('b', '', default_multi=u'255.255.255.0', multi=True, properties=('mandatory',))
|
||||
od = MasterSlaves('a', '', [a, b])
|
||||
od2 = OptionDescription('od2', '', [od])
|
||||
#od.impl_set_group_type(groups.master)
|
||||
b.impl_add_consistency('network_netmask', a)
|
||||
c = Config(od)
|
||||
c.read_write()
|
||||
c.a.append()
|
||||
api = getapi(Config(od2))
|
||||
api.property.read_write()
|
||||
api.option('a.a').value.set([undefined])
|
||||
assert api.option('a.a').value.get() == ['192.168.1.0']
|
||||
assert api.option('a.b', 0).value.get() == '255.255.255.0'
|
||||
|
||||
|
||||
def test_consistency_network_netmask_multi_slave_default():
|
||||
|
|
@ -493,22 +494,21 @@ def test_consistency_network_netmask_multi_slave_default():
|
|||
od = MasterSlaves('a', '', [a, b])
|
||||
#od.impl_set_group_type(groups.master)
|
||||
b.impl_add_consistency('network_netmask', a)
|
||||
c = Config(od)
|
||||
c.read_write()
|
||||
c.cfgimpl_get_settings().remove('cache')
|
||||
assert c.a == []
|
||||
assert c.b == []
|
||||
c.a.append(u'192.168.1.0')
|
||||
c.read_only()
|
||||
assert c.a == [u'192.168.1.0']
|
||||
assert c.b == [u'255.255.255.0']
|
||||
c.read_write()
|
||||
raises(ValueError, "c.a[0] = u'192.168.1.2'")
|
||||
raises(ValueError, "c.a.append(u'192.168.1.1')")
|
||||
raises(ValueError, "c.a = [u'192.168.1.0', u'192.168.1.1']")
|
||||
c.a.append()
|
||||
c.b = [u'255.255.255.0', u'255.255.255.255']
|
||||
c.a = [u'192.168.1.0', u'192.168.1.1']
|
||||
od2 = OptionDescription('od2', '', [od])
|
||||
api = getapi(Config(od2))
|
||||
api.property.read_write()
|
||||
api.property.pop('cache')
|
||||
assert api.option('a.a').value.get() == []
|
||||
api.option('a.a').value.set(['192.168.1.0'])
|
||||
api.property.read_only()
|
||||
assert api.option('a.a').value.get() == [u'192.168.1.0']
|
||||
assert api.option('a.b', 0).value.get() == u'255.255.255.0'
|
||||
api.property.read_write()
|
||||
raises(ValueError, "api.option('a.a').value.set([u'192.168.1.0', u'192.168.1.1'])")
|
||||
api.option('a.a').value.set(['192.168.1.0', undefined])
|
||||
api.option('a.b', 0).value.set('255.255.255.0')
|
||||
api.option('a.b', 1).value.set('255.255.255.255')
|
||||
api.option('a.a').value.set([u'192.168.1.0', u'192.168.1.1'])
|
||||
|
||||
|
||||
def return_netmask(*args, **kwargs):
|
||||
|
|
@ -530,22 +530,21 @@ def test_consistency_network_netmask_multi_slave_callback():
|
|||
od = MasterSlaves('a', '', [a, b])
|
||||
#od.impl_set_group_type(groups.master)
|
||||
b.impl_add_consistency('network_netmask', a)
|
||||
c = Config(od)
|
||||
c.read_write()
|
||||
c.cfgimpl_get_settings().remove('cache')
|
||||
assert c.a == []
|
||||
assert c.b == []
|
||||
c.a.append(u'192.168.1.0')
|
||||
c.read_only()
|
||||
assert c.a == [u'192.168.1.0']
|
||||
assert c.b == [u'255.255.255.0']
|
||||
c.read_write()
|
||||
raises(ValueError, "c.a[0] = u'192.168.1.2'")
|
||||
raises(ValueError, "c.a.append(u'192.168.1.1')")
|
||||
raises(ValueError, "c.a = [u'192.168.1.0', u'192.168.1.1']")
|
||||
c.a.append()
|
||||
c.b = [u'255.255.255.0', u'255.255.255.255']
|
||||
c.a = [u'192.168.1.0', u'192.168.1.1']
|
||||
od2 = OptionDescription('od2', '', [od])
|
||||
api = getapi(Config(od2))
|
||||
api.property.read_write()
|
||||
api.property.pop('cache')
|
||||
assert api.option('a.a').value.get() == []
|
||||
api.option('a.a').value.set(['192.168.1.0'])
|
||||
api.property.read_only()
|
||||
assert api.option('a.a').value.get() == [u'192.168.1.0']
|
||||
assert api.option('a.b', 0).value.get() == '255.255.255.0'
|
||||
api.property.read_write()
|
||||
raises(ValueError, "assert api.option('a.a').value.set([u'192.168.1.0', u'192.168.1.1'])")
|
||||
api.option('a.a').value.set(['192.168.1.0', undefined])
|
||||
api.option('a.b', 0).value.set('255.255.255.0')
|
||||
api.option('a.b', 1).value.set('255.255.255.255')
|
||||
api.option('a.a').value.set(['192.168.1.0', '192.168.1.1'])
|
||||
|
||||
|
||||
def test_consistency_network_netmask_multi_slave_callback_value():
|
||||
|
|
@ -554,23 +553,23 @@ def test_consistency_network_netmask_multi_slave_callback_value():
|
|||
od = MasterSlaves('a', '', [a, b])
|
||||
#od.impl_set_group_type(groups.master)
|
||||
b.impl_add_consistency('network_netmask', a)
|
||||
c = Config(od)
|
||||
c.read_write()
|
||||
c.cfgimpl_get_settings().remove('cache')
|
||||
assert c.a == []
|
||||
assert c.b == []
|
||||
c.a.append(u'192.168.1.0')
|
||||
assert c.a == [u'192.168.1.0']
|
||||
assert c.b == [u'255.255.255.0']
|
||||
raises(ValueError, "c.a[0] = u'192.168.2.1'")
|
||||
assert c.a == [u'192.168.1.0']
|
||||
assert c.b == [u'255.255.255.0']
|
||||
raises(ValueError, "c.a = [u'192.168.2.1']")
|
||||
assert c.a == [u'192.168.1.0']
|
||||
assert c.b == [u'255.255.255.0']
|
||||
c.a.append(u'192.168.1.1')
|
||||
c.a = [u'192.168.1.0', u'192.168.1.1']
|
||||
c.b = [u'255.255.255.0', u'255.255.255.255']
|
||||
od2 = OptionDescription('od2', '', [od])
|
||||
api = getapi(Config(od2))
|
||||
api.property.read_write()
|
||||
api.property.pop('cache')
|
||||
assert api.option('a.a').value.get() == []
|
||||
api.option('a.a').value.set(['192.168.1.0'])
|
||||
assert api.option('a.a').value.get() == ['192.168.1.0']
|
||||
assert api.option('a.b', 0).value.get() == '255.255.255.0'
|
||||
raises(ValueError, "api.option('a.a').value.set(['192.168.1.0', '192.168.2.1'])")
|
||||
assert api.option('a.a').value.get() == [u'192.168.1.0']
|
||||
assert api.option('a.b', 0).value.get() == '255.255.255.0'
|
||||
raises(ValueError, "api.option('a.a').value.set(['192.168.2.1'])")
|
||||
assert api.option('a.a').value.get() == [u'192.168.1.0']
|
||||
assert api.option('a.b', 0).value.get() == '255.255.255.0'
|
||||
api.option('a.a').value.set(['192.168.1.0', '192.168.1.1'])
|
||||
api.option('a.b', 0).value.set('255.255.255.0')
|
||||
api.option('a.b', 1).value.set('255.255.255.255')
|
||||
|
||||
|
||||
def test_consistency_ip_netmask_multi_master():
|
||||
|
|
@ -579,16 +578,17 @@ def test_consistency_ip_netmask_multi_master():
|
|||
od = MasterSlaves('a', '', [a, b])
|
||||
#od.impl_set_group_type(groups.master)
|
||||
b.impl_add_consistency('ip_netmask', a)
|
||||
c = Config(od)
|
||||
c.a = ['192.168.1.1']
|
||||
c.b = ['255.255.255.0']
|
||||
c.a = ['192.168.1.2']
|
||||
c.b = ['255.255.255.255']
|
||||
c.b = ['255.255.255.0']
|
||||
raises(ValueError, "c.a = ['192.168.1.0']")
|
||||
c.a = ['192.168.1.128']
|
||||
raises(ValueError, "c.b = ['255.255.255.128']")
|
||||
c.a = ['192.168.1.2', '192.168.1.3']
|
||||
od2 = OptionDescription('od2', '', [od])
|
||||
api = getapi(Config(od2))
|
||||
api.option('a.a').value.set(['192.168.1.1'])
|
||||
api.option('a.b', 0).value.set('255.255.255.0')
|
||||
api.option('a.a').value.set(['192.168.1.2'])
|
||||
api.option('a.b', 0).value.set('255.255.255.255')
|
||||
api.option('a.b', 0).value.set('255.255.255.0')
|
||||
raises(ValueError, "api.option('a.a').value.set(['192.168.1.0'])")
|
||||
api.option('a.a').value.set(['192.168.1.128'])
|
||||
raises(ValueError, "api.option('a.b', 0).value.set('255.255.255.128')")
|
||||
api.option('a.a').value.set(['192.168.1.2', '192.168.1.3'])
|
||||
|
||||
|
||||
def test_consistency_network_netmask_multi_master():
|
||||
|
|
@ -597,13 +597,14 @@ def test_consistency_network_netmask_multi_master():
|
|||
od = MasterSlaves('a', '', [a, b])
|
||||
#od.impl_set_group_type(groups.master)
|
||||
b.impl_add_consistency('network_netmask', a)
|
||||
c = Config(od)
|
||||
c.a = ['192.168.1.1']
|
||||
c.b = ['255.255.255.255']
|
||||
del(c.b)
|
||||
c.a = ['192.168.1.0']
|
||||
c.b = ['255.255.255.0']
|
||||
raises(ValueError, "c.a = ['192.168.1.1']")
|
||||
od2 = OptionDescription('od2', '', [od])
|
||||
api = getapi(Config(od2))
|
||||
api.option('a.a').value.set(['192.168.1.1'])
|
||||
api.option('a.b', 0).value.set('255.255.255.255')
|
||||
api.option('a.b', 0).value.reset()
|
||||
api.option('a.a').value.set(['192.168.1.0'])
|
||||
api.option('a.b', 0).value.set('255.255.255.0')
|
||||
raises(ValueError, "api.option('a.a').value.set(['192.168.1.1'])")
|
||||
|
||||
|
||||
def test_consistency_broadcast():
|
||||
|
|
@ -614,21 +615,24 @@ def test_consistency_broadcast():
|
|||
#od.impl_set_group_type(groups.master)
|
||||
b.impl_add_consistency('network_netmask', a)
|
||||
c.impl_add_consistency('broadcast', a, b)
|
||||
c = Config(od)
|
||||
od2 = OptionDescription('od2', '', [od])
|
||||
api = getapi(Config(od2))
|
||||
#first, test network_netmask
|
||||
c.a = ['192.168.1.128']
|
||||
raises(ValueError, "c.b = ['255.255.255.0']")
|
||||
api.option('a.a').value.set(['192.168.1.128'])
|
||||
raises(ValueError, "api.option('a.a').value.set(['255.255.255.0'])")
|
||||
#
|
||||
c.a = ['192.168.1.0']
|
||||
c.b = ['255.255.255.0']
|
||||
c.c = ['192.168.1.255']
|
||||
raises(ValueError, "c.a = ['192.168.1.1']")
|
||||
api.option('a.a').value.set(['192.168.1.0'])
|
||||
api.option('a.b', 0).value.set('255.255.255.0')
|
||||
api.option('a.c', 0).value.set('192.168.1.255')
|
||||
raises(ValueError, "api.option('a.a').value.set(['192.168.1.1'])")
|
||||
#
|
||||
c.a = ['192.168.1.0', '192.168.2.128']
|
||||
c.b = ['255.255.255.0', '255.255.255.128']
|
||||
c.c = ['192.168.1.255', '192.168.2.255']
|
||||
raises(ValueError, "c.c[1] = '192.168.2.128'")
|
||||
c.c[1] = '192.168.2.255'
|
||||
api.option('a.a').value.set(['192.168.1.0', '192.168.2.128'])
|
||||
api.option('a.b', 0).value.set('255.255.255.0')
|
||||
api.option('a.b', 1).value.set('255.255.255.128')
|
||||
api.option('a.c', 0).value.set('192.168.1.255')
|
||||
api.option('a.c', 1).value.set('192.168.2.255')
|
||||
raises(ValueError, "api.option('a.c', 1).value.set('192.168.2.128')")
|
||||
api.option('a.c', 1).value.set('192.168.2.255')
|
||||
|
||||
|
||||
def test_consistency_broadcast_error():
|
||||
|
|
@ -636,11 +640,11 @@ def test_consistency_broadcast_error():
|
|||
b = NetmaskOption('b', '', multi=True)
|
||||
c = BroadcastOption('c', '', multi=True)
|
||||
od = MasterSlaves('a', '', [a, b, c])
|
||||
#od.impl_set_group_type(groups.master)
|
||||
od2 = OptionDescription('od2', '', [od])
|
||||
b.impl_add_consistency('network_netmask', a)
|
||||
c.impl_add_consistency('broadcast', a)
|
||||
c = Config(od)
|
||||
raises(ConfigError, "c.a = ['192.168.1.0']")
|
||||
api = getapi(Config(od2))
|
||||
raises(ConfigError, "api.option('a.a').value.set(['192.168.1.0'])")
|
||||
|
||||
|
||||
def test_consistency_broadcast_warnings():
|
||||
|
|
@ -650,14 +654,14 @@ def test_consistency_broadcast_warnings():
|
|||
c = NetmaskOption('c', '', properties=('mandatory', 'disabled'))
|
||||
od = OptionDescription('a', '', [a, b, c])
|
||||
b.impl_add_consistency('network_netmask', a, warnings_only=True)
|
||||
c = Config(od)
|
||||
api = getapi(Config(od))
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
c.a = '192.168.1.4'
|
||||
c.b = '255.255.255.0'
|
||||
api.option('a').value.set('192.168.1.4')
|
||||
api.option('b').value.set('255.255.255.0')
|
||||
assert len(w) == 1
|
||||
c.read_write()
|
||||
api.property.read_write()
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
list(c.cfgimpl_get_values().mandatory_warnings())
|
||||
list(api.value.mandatory_warnings())
|
||||
assert len(w) == 0
|
||||
|
||||
|
||||
|
|
@ -687,10 +691,11 @@ def test_consistency_not_all():
|
|||
od = MasterSlaves('a', '', [a, b, c])
|
||||
#od.impl_set_group_type(groups.master)
|
||||
b.impl_add_consistency('network_netmask', a)
|
||||
c = Config(od)
|
||||
c.a = ['192.168.1.0']
|
||||
c.b = ['255.255.255.0']
|
||||
c.c = ['192.168.1.255']
|
||||
od2 = OptionDescription('od2', '', [od])
|
||||
api = getapi(Config(od2))
|
||||
api.option('a.a').value.set(['192.168.1.0'])
|
||||
api.option('a.b', 0).value.set('255.255.255.0')
|
||||
api.option('a.c', 0).value.set('192.168.1.255')
|
||||
|
||||
|
||||
def test_consistency_permissive():
|
||||
|
|
@ -698,10 +703,10 @@ def test_consistency_permissive():
|
|||
b = IntOption('b', '', 2, properties=('hidden',))
|
||||
od = OptionDescription('od', '', [a, b])
|
||||
a.impl_add_consistency('not_equal', b)
|
||||
c = Config(od)
|
||||
c.cfgimpl_get_settings().setpermissive(('hidden',))
|
||||
c.read_write()
|
||||
c.a = 1
|
||||
api = getapi(Config(od))
|
||||
api.property.read_write()
|
||||
api.permissive.set(frozenset(['hidden']))
|
||||
api.option('a').value.set(1)
|
||||
|
||||
|
||||
def test_consistency_disabled():
|
||||
|
|
@ -709,9 +714,9 @@ def test_consistency_disabled():
|
|||
b = IntOption('b', '', properties=('disabled',))
|
||||
od = OptionDescription('od', '', [a, b])
|
||||
a.impl_add_consistency('not_equal', b)
|
||||
c = Config(od)
|
||||
c.read_write()
|
||||
raises(PropertiesOptionError, "c.a = 1")
|
||||
api = getapi(Config(od))
|
||||
api.property.read_write()
|
||||
raises(PropertiesOptionError, "api.option('a').value.set(1)")
|
||||
|
||||
|
||||
def test_consistency_disabled_transitive():
|
||||
|
|
@ -719,9 +724,9 @@ def test_consistency_disabled_transitive():
|
|||
b = IntOption('b', '', properties=('disabled',))
|
||||
od = OptionDescription('od', '', [a, b])
|
||||
a.impl_add_consistency('not_equal', b, transitive=False)
|
||||
c = Config(od)
|
||||
c.read_write()
|
||||
c.a = 1
|
||||
api = getapi(Config(od))
|
||||
api.property.read_write()
|
||||
api.option('a').value.set(1)
|
||||
|
||||
|
||||
def test_consistency_disabled_transitive_2():
|
||||
|
|
@ -732,15 +737,15 @@ def test_consistency_disabled_transitive_2():
|
|||
od = OptionDescription('od', '', [a, b, c, d])
|
||||
a.impl_add_consistency('not_equal', b)
|
||||
a.impl_add_consistency('in_network', c, d, transitive=False)
|
||||
c = Config(od)
|
||||
c.read_write()
|
||||
c.a = '192.168.1.1'
|
||||
raises(ValueError, "c.b = '192.168.1.1'")
|
||||
c.a = '192.168.2.1'
|
||||
api = getapi(Config(od))
|
||||
api.property.read_write()
|
||||
api.option('a').value.set('192.168.1.1')
|
||||
raises(ValueError, "api.option('b').value.set('192.168.1.1')")
|
||||
api.option('a').value.set('192.168.2.1')
|
||||
#
|
||||
c.a = '192.168.1.1'
|
||||
c.cfgimpl_get_settings().remove('disabled')
|
||||
raises(ValueError, "c.a = '192.168.2.1'")
|
||||
api.option('a').value.set('192.168.1.1')
|
||||
api.property.pop('disabled')
|
||||
raises(ValueError, "api.option('a').value.set('192.168.2.1')")
|
||||
|
||||
|
||||
def return_val(*args, **kwargs):
|
||||
|
|
@ -753,8 +758,8 @@ def test_consistency_with_callback():
|
|||
c = IPOption('c', '', callback=return_val, callback_params={'': ((a, False),)})
|
||||
od = OptionDescription('od', '', [a, b, c])
|
||||
c.impl_add_consistency('in_network', a, b)
|
||||
cfg = Config(od)
|
||||
cfg.c
|
||||
api = getapi(Config(od))
|
||||
api.option('c').value.get()
|
||||
|
||||
|
||||
def test_consistency_double_warnings():
|
||||
|
|
@ -765,21 +770,25 @@ def test_consistency_double_warnings():
|
|||
warnings.simplefilter("always", ValueWarning)
|
||||
a.impl_add_consistency('not_equal', b, warnings_only=True)
|
||||
a.impl_add_consistency('not_equal', c, warnings_only=True)
|
||||
cfg = Config(od)
|
||||
od2 = OptionDescription('od2', '', [od])
|
||||
api = getapi(Config(od2))
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
cfg.a = 1
|
||||
api.option('od.a').value.set(1)
|
||||
assert w != []
|
||||
assert len(w) == 2
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
cfg.c = 2
|
||||
assert w == []
|
||||
api.option('od.c').value.set(2)
|
||||
if TIRAMISU_VERSION == 2:
|
||||
assert len(w) == 0
|
||||
else:
|
||||
assert len(w) == 1
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
cfg.a = 2
|
||||
api.option('od.a').value.set(2)
|
||||
assert w != []
|
||||
assert len(w) == 1
|
||||
cfg.cfgimpl_get_settings().remove('warnings')
|
||||
api.property.pop('warnings')
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
cfg.a = 1
|
||||
api.option('od.a').value.set(1)
|
||||
assert w == []
|
||||
|
||||
|
||||
|
|
@ -791,9 +800,9 @@ def test_consistency_warnings_error():
|
|||
warnings.simplefilter("always", ValueWarning)
|
||||
a.impl_add_consistency('not_equal', b, warnings_only=True)
|
||||
a.impl_add_consistency('not_equal', c)
|
||||
cfg = Config(od)
|
||||
api = getapi(Config(od))
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
raises(ValueError, "cfg.a = 1")
|
||||
raises(ValueError, "api.option('a').value.set(1)")
|
||||
assert w == []
|
||||
|
||||
|
||||
|
|
@ -801,12 +810,12 @@ def test_consistency_network_netmask_mandatory():
|
|||
a = NetworkOption('a', '', multi=True, properties=('mandatory',), default=[u'0.0.0.0'])
|
||||
b = NetmaskOption('b', '', multi=True, properties=('mandatory',), default_multi=u'0.0.0.0')
|
||||
od = MasterSlaves('a', '', [a, b])
|
||||
#od.impl_set_group_type(groups.master)
|
||||
b.impl_add_consistency('network_netmask', a)
|
||||
c = Config(od)
|
||||
c.read_only()
|
||||
c.cfgimpl_get_settings().remove('mandatory')
|
||||
c.make_dict()
|
||||
od2 = OptionDescription('od2', '', [od])
|
||||
api = getapi(Config(od2))
|
||||
api.property.read_only()
|
||||
api.property.pop('mandatory')
|
||||
api.option.make_dict()
|
||||
|
||||
|
||||
def test_consistency_has_dependency():
|
||||
|
|
@ -814,11 +823,11 @@ def test_consistency_has_dependency():
|
|||
b = NetmaskOption('b', '')
|
||||
od = OptionDescription('od', '', [a, b])
|
||||
b.impl_add_consistency('ip_netmask', a)
|
||||
c = Config(od)
|
||||
assert c.cfgimpl_get_description().a.impl_has_dependency() is True
|
||||
assert c.cfgimpl_get_description().b.impl_has_dependency() is True
|
||||
assert c.cfgimpl_get_description().a.impl_has_dependency(False) is True
|
||||
assert c.cfgimpl_get_description().b.impl_has_dependency(False) is True
|
||||
api = getapi(Config(od))
|
||||
assert api.option('a').option.has_dependency() is True
|
||||
assert api.option('b').option.has_dependency() is True
|
||||
assert api.option('a').option.has_dependency(False) is True
|
||||
assert api.option('b').option.has_dependency(False) is True
|
||||
|
||||
|
||||
def test_consistency_not_equal_has_dependency():
|
||||
|
|
@ -826,8 +835,8 @@ def test_consistency_not_equal_has_dependency():
|
|||
b = IntOption('b', '')
|
||||
od = OptionDescription('od', '', [a, b])
|
||||
a.impl_add_consistency('not_equal', b)
|
||||
c = Config(od)
|
||||
assert c.cfgimpl_get_description().a.impl_has_dependency() is False
|
||||
assert c.cfgimpl_get_description().b.impl_has_dependency() is False
|
||||
assert c.cfgimpl_get_description().a.impl_has_dependency(False) is True
|
||||
assert c.cfgimpl_get_description().b.impl_has_dependency(False) is True
|
||||
api = getapi(Config(od))
|
||||
assert api.option('a').option.has_dependency() is False
|
||||
assert api.option('b').option.has_dependency() is False
|
||||
assert api.option('a').option.has_dependency(False) is True
|
||||
assert api.option('b').option.has_dependency(False) is True
|
||||
|
|
|
|||
|
|
@ -4,11 +4,10 @@ do_autopath()
|
|||
|
||||
from py.test import raises
|
||||
|
||||
from tiramisu.config import Config
|
||||
from tiramisu.setting import owners
|
||||
from tiramisu.error import PropertiesOptionError, ConfigError
|
||||
from tiramisu.option import IntOption, FloatOption, StrOption, ChoiceOption, \
|
||||
BoolOption, OptionDescription
|
||||
from tiramisu import IntOption, FloatOption, StrOption, ChoiceOption, \
|
||||
BoolOption, OptionDescription, MasterSlaves, Config, getapi, undefined
|
||||
|
||||
|
||||
def make_description():
|
||||
|
|
@ -46,10 +45,10 @@ def test_default_is_none():
|
|||
dummy1 = BoolOption('dummy1', 'doc dummy')
|
||||
dummy2 = BoolOption('dummy2', 'doc dummy')
|
||||
group = OptionDescription('group', '', [dummy1, dummy2])
|
||||
config = Config(group)
|
||||
api = getapi(Config(group))
|
||||
# so when the default value is not set, there is actually a default value
|
||||
assert config.dummy1 is None
|
||||
assert config.dummy2 is None
|
||||
assert api.option('dummy1').value.get() is None
|
||||
assert api.option('dummy2').value.get() is None
|
||||
|
||||
|
||||
def test_set_defaut_value_from_option_object():
|
||||
|
|
@ -63,74 +62,124 @@ def test_force_default_on_freeze():
|
|||
dummy1 = BoolOption('dummy1', 'doc dummy', default=False, properties=('force_default_on_freeze',))
|
||||
dummy2 = BoolOption('dummy2', 'doc dummy', default=True)
|
||||
group = OptionDescription('group', '', [dummy1, dummy2])
|
||||
config = Config(group)
|
||||
config.read_write()
|
||||
owners.addowner("frozen")
|
||||
config.dummy1 = True
|
||||
config.dummy2 = False
|
||||
assert config.getowner(dummy1) == owners.user
|
||||
assert config.getowner(dummy2) == owners.user
|
||||
setting = config.cfgimpl_get_settings()
|
||||
setting[dummy1].append('frozen')
|
||||
setting[dummy2].append('frozen')
|
||||
assert config.dummy1 is False
|
||||
assert config.dummy2 is False
|
||||
assert config.getowner(dummy1) == owners.default
|
||||
assert config.getowner(dummy2) == owners.user
|
||||
raises(PropertiesOptionError, "config.cfgimpl_get_values().setowner(dummy1, owners.frozen)")
|
||||
raises(PropertiesOptionError, "config.cfgimpl_get_values().setowner(dummy2, owners.frozen)")
|
||||
raises(PropertiesOptionError, "del(config.dummy1)")
|
||||
setting[dummy1].remove('frozen')
|
||||
del(config.dummy1)
|
||||
setting[dummy1].append('frozen')
|
||||
raises(PropertiesOptionError, "config.cfgimpl_get_values().setowner(dummy1, owners.frozen)")
|
||||
api = getapi(Config(group))
|
||||
api.property.read_write()
|
||||
owner = api.owner.get()
|
||||
api.option('dummy1').value.set(True)
|
||||
api.option('dummy2').value.set(False)
|
||||
assert api.option('dummy1').owner.get() == owner
|
||||
assert api.option('dummy2').owner.get() == owner
|
||||
api.option('dummy1').property.add('frozen')
|
||||
api.option('dummy2').property.add('frozen')
|
||||
assert api.option('dummy1').value.get() is False
|
||||
assert api.option('dummy2').value.get() is False
|
||||
assert api.option('dummy1').owner.isdefault()
|
||||
assert api.option('dummy2').owner.get() == owner
|
||||
raises(PropertiesOptionError, "api.option('dummy2').owner.set('frozen')")
|
||||
raises(PropertiesOptionError, "api.option('dummy1').value.reset()")
|
||||
api.option('dummy1').property.pop('frozen')
|
||||
api.option('dummy1').value.reset()
|
||||
api.option('dummy1').property.add('frozen')
|
||||
raises(PropertiesOptionError, "api.option('dummy2').owner.set('frozen')")
|
||||
|
||||
|
||||
def test_force_default_on_freeze_multi():
|
||||
dummy1 = BoolOption('dummy1', 'doc dummy', default=[False], properties=('force_default_on_freeze',), multi=True)
|
||||
dummy2 = BoolOption('dummy2', 'doc dummy', default=[True], multi=True)
|
||||
group = OptionDescription('group', '', [dummy1, dummy2])
|
||||
config = Config(group)
|
||||
config.read_write()
|
||||
owners.addowner("frozenmulti")
|
||||
config.dummy1.append(True)
|
||||
config.dummy2.append(False)
|
||||
assert config.getowner(dummy1) == owners.user
|
||||
assert config.getowner(dummy2) == owners.user
|
||||
setting = config.cfgimpl_get_settings()
|
||||
setting[dummy1].append('frozen')
|
||||
setting[dummy2].append('frozen')
|
||||
assert config.dummy1 == [False]
|
||||
assert config.dummy2 == [True, False]
|
||||
assert config.getowner(dummy1) == owners.default
|
||||
assert config.getowner(dummy2) == owners.user
|
||||
raises(PropertiesOptionError, "config.cfgimpl_get_values().setowner(dummy1, owners.frozenmulti)")
|
||||
raises(PropertiesOptionError, "config.cfgimpl_get_values().setowner(dummy2, owners.frozenmulti)")
|
||||
raises(PropertiesOptionError, "del(config.dummy1)")
|
||||
setting[dummy1].remove('frozen')
|
||||
del(config.dummy1)
|
||||
setting[dummy1].append('frozen')
|
||||
raises(PropertiesOptionError, "config.cfgimpl_get_values().setowner(dummy1, owners.frozenmulti)")
|
||||
api = getapi(Config(group))
|
||||
api.property.read_write()
|
||||
api.option('dummy1').value.set([undefined, True])
|
||||
api.option('dummy2').value.set([undefined, False])
|
||||
owner = api.owner.get()
|
||||
assert api.option('dummy1').owner.get() == owner
|
||||
assert api.option('dummy2').owner.get() == owner
|
||||
api.option('dummy1').property.add('frozen')
|
||||
api.option('dummy2').property.add('frozen')
|
||||
assert api.option('dummy1').value.get() == [False]
|
||||
assert api.option('dummy2').value.get() == [True, False]
|
||||
assert api.option('dummy1').owner.isdefault()
|
||||
assert api.option('dummy2').owner.get() == owner
|
||||
raises(PropertiesOptionError, "api.option('dummy2').owner.set('owner')")
|
||||
raises(PropertiesOptionError, "api.option('dummy2').value.reset()")
|
||||
api.option('dummy1').property.pop('frozen')
|
||||
api.option('dummy1').value.reset()
|
||||
api.option('dummy1').property.add('frozen')
|
||||
|
||||
|
||||
def test_force_default_on_freeze_master():
|
||||
dummy1 = BoolOption('dummy1', 'Test int option', multi=True, properties=('force_default_on_freeze',))
|
||||
dummy2 = BoolOption('dummy2', 'Test string option', multi=True)
|
||||
descr = MasterSlaves("dummy1", "", [dummy1, dummy2])
|
||||
descr = OptionDescription("root", "", [descr])
|
||||
raises(ConfigError, "Config(descr)")
|
||||
|
||||
|
||||
def test_force_default_on_freeze_slave():
|
||||
dummy1 = BoolOption('dummy1', 'Test int option', multi=True)
|
||||
dummy2 = BoolOption('dummy2', 'Test string option', multi=True, properties=('force_default_on_freeze',))
|
||||
descr = MasterSlaves("dummy1", "", [dummy1, dummy2])
|
||||
descr = OptionDescription("root", "", [descr])
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
owners.addowner("frozenmultislave2")
|
||||
api.option('dummy1.dummy1').value.set([True])
|
||||
api.option('dummy1.dummy2', 0).value.set(False)
|
||||
assert api.option('dummy1.dummy1').value.get() == [True]
|
||||
assert api.option('dummy1.dummy2', 0).value.get() == False
|
||||
assert api.option('dummy1.dummy1').owner.get() == 'user'
|
||||
assert api.option('dummy1.dummy2', 0).owner.get() == 'user'
|
||||
#
|
||||
api.option('dummy1.dummy2').property.add('frozen')
|
||||
assert api.option('dummy1.dummy1').value.get() == [True]
|
||||
assert api.option('dummy1.dummy2', 0).value.get() == None
|
||||
assert api.option('dummy1.dummy1').owner.get() == 'user'
|
||||
assert api.option('dummy1.dummy2', 0).owner.isdefault()
|
||||
raises(PropertiesOptionError, "api.option('dummy1.dummy2', 0).owner.set('frozenmultislave2')")
|
||||
#
|
||||
api.option('dummy1.dummy2').property.pop('frozen')
|
||||
api.option('dummy1.dummy1').value.set([True, True])
|
||||
api.option('dummy1.dummy2', 1).value.set(False)
|
||||
assert api.option('dummy1.dummy1').value.get() == [True, True]
|
||||
assert api.option('dummy1.dummy2', 0).value.get() == False
|
||||
assert api.option('dummy1.dummy2', 1).value.get() == False
|
||||
#
|
||||
api.option('dummy1.dummy2').property.add('frozen')
|
||||
assert api.option('dummy1.dummy1').value.get() == [True, True]
|
||||
assert api.option('dummy1.dummy2', 0).value.get() == None
|
||||
assert api.option('dummy1.dummy2', 1).value.get() == None
|
||||
#
|
||||
api.option('dummy1.dummy1').value.pop(1)
|
||||
assert api.option('dummy1.dummy1').value.get() == [True]
|
||||
assert api.option('dummy1.dummy2', 0).value.get() == None
|
||||
#
|
||||
api.option('dummy1.dummy2').property.pop('frozen')
|
||||
assert api.option('dummy1.dummy1').value.get() == [True]
|
||||
assert api.option('dummy1.dummy2', 0).value.get() == False
|
||||
#
|
||||
api.option('dummy1.dummy1').value.set([True, True])
|
||||
assert api.option('dummy1.dummy2', 0).value.get() == False
|
||||
assert api.option('dummy1.dummy2', 1).value.get() == None
|
||||
|
||||
|
||||
def test_overrides_changes_option_value():
|
||||
"with config.override(), the default is changed and the value is changed"
|
||||
descr = OptionDescription("test", "", [
|
||||
BoolOption("b", "", default=False)])
|
||||
config = Config(descr)
|
||||
config.b = True
|
||||
api = getapi(Config(descr))
|
||||
api.option('b').value.set(True)
|
||||
|
||||
|
||||
def test_choice_with_no_default():
|
||||
descr = OptionDescription("test", "", [
|
||||
ChoiceOption("backend", "", ("c", "cli"))])
|
||||
config = Config(descr)
|
||||
assert config.backend is None
|
||||
config.backend = "c"
|
||||
api = getapi(Config(descr))
|
||||
assert api.option('backend').value.get() is None
|
||||
api.option('backend').value.set('c')
|
||||
|
||||
|
||||
def test_choice_with_default():
|
||||
descr = OptionDescription("test", "", [
|
||||
ChoiceOption("backend", "", ("c", "cli"), default="cli")])
|
||||
config = Config(descr)
|
||||
assert config.backend == "cli"
|
||||
api = getapi(Config(descr))
|
||||
assert api.option('backend').value.get() == 'cli'
|
||||
|
|
|
|||
|
|
@ -4,10 +4,9 @@ do_autopath()
|
|||
from py.test import raises
|
||||
|
||||
from tiramisu.setting import owners, groups
|
||||
from tiramisu.config import Config
|
||||
from tiramisu.option import ChoiceOption, BoolOption, IntOption, FloatOption, \
|
||||
StrOption, OptionDescription, SymLinkOption, MasterSlaves
|
||||
from tiramisu.error import ConfigError, ConstError, PropertiesOptionError
|
||||
from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \
|
||||
StrOption, OptionDescription, SymLinkOption, MasterSlaves, Config, getapi
|
||||
from tiramisu.error import ConfigError, ConstError, PropertiesOptionError, APIError
|
||||
|
||||
|
||||
def make_description():
|
||||
|
|
@ -35,113 +34,107 @@ def make_description():
|
|||
def test_default_owner():
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
descr = OptionDescription('tiramisu', '', [gcdummy])
|
||||
cfg = Config(descr)
|
||||
assert cfg.dummy is False
|
||||
assert cfg.getowner(gcdummy) == 'default'
|
||||
raises(TypeError, "cfg.getowner('gcdummy')")
|
||||
cfg.dummy = True
|
||||
assert cfg.getowner(gcdummy) == owners.user
|
||||
api = getapi(Config(descr))
|
||||
assert api.option('dummy').value.get() is False
|
||||
assert api.option('dummy').owner.get() == 'default'
|
||||
api.option('dummy').value.set(True)
|
||||
owner = api.owner.get()
|
||||
assert api.option('dummy').owner.get() == owner
|
||||
|
||||
|
||||
def test_hidden_owner():
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False, properties=('hidden',))
|
||||
descr = OptionDescription('tiramisu', '', [gcdummy])
|
||||
cfg = Config(descr)
|
||||
cfg.read_write()
|
||||
raises(PropertiesOptionError, "cfg.getowner(gcdummy)")
|
||||
raises(PropertiesOptionError, "cfg.getowner(gcdummy, force_permissive=True)")
|
||||
raises(PropertiesOptionError, "cfg.cfgimpl_get_values().is_default_owner(gcdummy)")
|
||||
raises(PropertiesOptionError, "cfg.cfgimpl_get_values().is_default_owner(gcdummy, force_permissive=True)")
|
||||
cfg.cfgimpl_get_settings().setpermissive(('hidden',))
|
||||
cfg.getowner(gcdummy, force_permissive=True)
|
||||
cfg.cfgimpl_get_values().is_default_owner(gcdummy, force_permissive=True)
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
#raises(PropertiesOptionError, "api.forcepermissive.option('dummy').owner.get()")
|
||||
#raises(PropertiesOptionError, "api.option('dummy').owner.isdefault()")
|
||||
#raises(PropertiesOptionError, "api.forcepermissive.option('dummy').owner.isdefault()")
|
||||
api.permissive.set(frozenset(['hidden']))
|
||||
api.forcepermissive.option('dummy').value.get()
|
||||
api.forcepermissive.option('dummy').owner.isdefault()
|
||||
|
||||
|
||||
def test_addowner():
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
descr = OptionDescription('tiramisu', '', [gcdummy])
|
||||
cfg = Config(descr)
|
||||
assert cfg.dummy is False
|
||||
assert cfg.getowner(gcdummy) == 'default'
|
||||
assert cfg.cfgimpl_get_values().is_default_owner(gcdummy)
|
||||
owners.addowner("gen_config")
|
||||
cfg.cfgimpl_get_settings().setowner(owners.gen_config)
|
||||
cfg.dummy = True
|
||||
assert cfg.getowner(gcdummy) == owners.gen_config
|
||||
assert not cfg.cfgimpl_get_values().is_default_owner(gcdummy)
|
||||
api = getapi(Config(descr))
|
||||
assert api.option('dummy').value.get() is False
|
||||
assert api.option('dummy').owner.get() == 'default'
|
||||
assert api.option('dummy').owner.isdefault()
|
||||
api.owner.set('gen_config')
|
||||
api.option('dummy').value.set(True)
|
||||
assert api.option('dummy').owner.get() == owners.gen_config
|
||||
assert not api.option('dummy').owner.isdefault()
|
||||
|
||||
|
||||
def test_addowner_multiple_time():
|
||||
owners.addowner("testowner")
|
||||
raises(ConstError, 'owners.addowner("testowner")')
|
||||
owners.addowner("testowner2")
|
||||
raises(ConstError, 'owners.addowner("testowner2")')
|
||||
|
||||
|
||||
def test_delete_owner():
|
||||
owners.addowner('deleted')
|
||||
raises(ConstError, 'del(owners.deleted)')
|
||||
raises(ValueError, 'del(owners.deleted2)')
|
||||
owners.addowner('deleted2')
|
||||
raises(ConstError, 'del(owners.deleted2)')
|
||||
|
||||
|
||||
def test_owner_is_not_a_string():
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
descr = OptionDescription('tiramisu', '', [gcdummy])
|
||||
cfg = Config(descr)
|
||||
assert cfg.dummy is False
|
||||
assert cfg.getowner(gcdummy) == owners.default
|
||||
assert cfg.getowner(gcdummy) == 'default'
|
||||
assert isinstance(cfg.getowner(gcdummy), owners.Owner)
|
||||
cfg.dummy = True
|
||||
assert cfg.getowner(gcdummy) == 'user'
|
||||
api = getapi(Config(descr))
|
||||
assert api.option('dummy').value.get() is False
|
||||
assert api.option('dummy').owner.get() == owners.default
|
||||
assert api.option('dummy').owner.get() == 'default'
|
||||
assert isinstance(api.option('dummy').owner.get(), owners.Owner)
|
||||
api.option('dummy').value.set(True)
|
||||
assert api.option('dummy').owner.get() == 'user'
|
||||
|
||||
|
||||
def test_setowner_without_valid_owner():
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
descr = OptionDescription('tiramisu', '', [gcdummy])
|
||||
cfg = Config(descr)
|
||||
assert cfg.dummy is False
|
||||
assert cfg.getowner(gcdummy) == 'default'
|
||||
raises(TypeError, "cfg.cfgimpl_get_settings().setowner('gen_config')")
|
||||
api = getapi(Config(descr))
|
||||
assert api.option('dummy').value.get() is False
|
||||
assert api.option('dummy').owner.get() == 'default'
|
||||
|
||||
|
||||
def test_setowner_for_value():
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
descr = OptionDescription('tiramisu', '', [gcdummy])
|
||||
cfg = Config(descr)
|
||||
assert cfg.dummy is False
|
||||
assert cfg.getowner(gcdummy) == 'default'
|
||||
owners.addowner("new")
|
||||
raises(ConfigError, "cfg.cfgimpl_get_values().setowner(gcdummy, owners.new)")
|
||||
cfg.dummy = False
|
||||
assert cfg.getowner(gcdummy) == owners.user
|
||||
cfg.cfgimpl_get_values().setowner(gcdummy, owners.new)
|
||||
assert cfg.getowner(gcdummy) == owners.new
|
||||
raises(TypeError, "cfg.cfgimpl_get_values().setowner(gcdummy, 'new')")
|
||||
api = getapi(Config(descr))
|
||||
assert api.option('dummy').value.get() is False
|
||||
assert api.option('dummy').owner.get() == 'default'
|
||||
owners.addowner("new2")
|
||||
raises(ConfigError, "api.option('dummy').owner.set('new2')")
|
||||
api.option('dummy').value.set(False)
|
||||
assert api.option('dummy').owner.get() == owners.user
|
||||
api.option('dummy').owner.set('new2')
|
||||
assert api.option('dummy').owner.get() == owners.new2
|
||||
|
||||
|
||||
def test_setowner_read_only():
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
descr = OptionDescription('tiramisu', '', [gcdummy])
|
||||
cfg = Config(descr)
|
||||
cfg.read_write()
|
||||
assert cfg.dummy is False
|
||||
assert cfg.getowner(gcdummy) == 'default'
|
||||
owners.addowner("readonly")
|
||||
cfg.dummy = False
|
||||
assert cfg.getowner(gcdummy) == owners.user
|
||||
cfg.read_only()
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
assert api.option('dummy').value.get() is False
|
||||
assert api.option('dummy').owner.get() == 'default'
|
||||
owners.addowner("readonly2")
|
||||
api.option('dummy').value.set(False)
|
||||
assert api.option('dummy').owner.get() == owners.user
|
||||
api.property.read_only()
|
||||
raises(PropertiesOptionError,
|
||||
"cfg.cfgimpl_get_values().setowner(gcdummy, owners.readonly)")
|
||||
assert cfg.getowner(gcdummy) == owners.user
|
||||
"api.option('dummy').owner.set('readonly2')")
|
||||
assert api.option('dummy').owner.get() == owners.user
|
||||
|
||||
|
||||
def test_setowner_optiondescription():
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
descr1 = OptionDescription('tiramisu', '', [gcdummy])
|
||||
descr = OptionDescription('tiramisu', '', [descr1])
|
||||
cfg = Config(descr)
|
||||
cfg
|
||||
raises(ConfigError, 'cfg.cfgimpl_get_values().getowner(descr1)')
|
||||
raises(ConfigError, 'cfg.cfgimpl_get_values().setowner(descr1, owners.user)')
|
||||
api = getapi(Config(descr))
|
||||
raises(APIError, "api.option('tiramisu').owner.get()")
|
||||
raises(APIError, "api.option('tiramisu').owner.set('user')")
|
||||
|
||||
|
||||
def test_setowner_symlinkoption():
|
||||
|
|
@ -149,26 +142,27 @@ def test_setowner_symlinkoption():
|
|||
s = SymLinkOption('symdummy', gcdummy)
|
||||
descr1 = OptionDescription('tiramisu', '', [gcdummy, s])
|
||||
descr = OptionDescription('tiramisu', '', [descr1])
|
||||
cfg = Config(descr)
|
||||
assert cfg.cfgimpl_get_values().getowner(s) == owners.default
|
||||
cfg.tiramisu.dummy = True
|
||||
assert cfg.cfgimpl_get_values().getowner(s) == owners.user
|
||||
raises(ConfigError, 'cfg.cfgimpl_get_values().setowner(s, owners.user)')
|
||||
api = getapi(Config(descr))
|
||||
assert api.option('tiramisu.symdummy').owner.isdefault()
|
||||
api.option('tiramisu.dummy').value.set(True)
|
||||
assert not api.option('tiramisu.symdummy').owner.isdefault()
|
||||
raises(ConfigError, "api.option('tiramisu.symdummy').owner.set('user')")
|
||||
|
||||
|
||||
def test_owner_masterslaves():
|
||||
b = IntOption('int', 'Test int option', default=[0], multi=True)
|
||||
c = StrOption('str', 'Test string option', multi=True)
|
||||
descr = MasterSlaves("int", "", [b, c])
|
||||
#descr.impl_set_group_type(groups.master)
|
||||
cfg = Config(descr)
|
||||
raises(ConfigError, 'cfg.cfgimpl_get_values().setowner(c, owners.user)')
|
||||
od = OptionDescription('od', '', [descr])
|
||||
api = getapi(Config(od))
|
||||
raises(ConfigError, "api.option('int.str', 0).owner.set('user')")
|
||||
|
||||
cfg.int.append(1)
|
||||
cfg.str[0] = 'yes'
|
||||
assert cfg.cfgimpl_get_values().getowner(c, 0) == owners.user
|
||||
assert cfg.cfgimpl_get_values().getowner(c, 1) == owners.default
|
||||
cfg.cfgimpl_get_values().setowner(c, owners.user, 0)
|
||||
assert cfg.cfgimpl_get_values().getowner(c, 0) == owners.user
|
||||
assert cfg.cfgimpl_get_values().getowner(c, 1) == owners.default
|
||||
assert cfg.str == ['yes', None]
|
||||
api.option('int.int').value.set([0, 1])
|
||||
api.option('int.str', 0).value.set('yes')
|
||||
assert not api.option('int.str', 0).owner.isdefault()
|
||||
assert api.option('int.str', 1).owner.isdefault()
|
||||
api.option('int.str', 0).owner.set('user')
|
||||
assert api.option('int.str', 0).owner.get() == owners.user
|
||||
assert api.option('int.str', 1).owner.isdefault()
|
||||
assert api.option('int.str', 0).value.get() == 'yes'
|
||||
assert api.option('int.str', 1).value.get() == None
|
||||
|
|
|
|||
|
|
@ -7,10 +7,10 @@ from py.test import raises
|
|||
from tiramisu.i18n import _
|
||||
from tiramisu.error import display_list, ConfigError
|
||||
from tiramisu.setting import owners, groups
|
||||
from tiramisu.config import Config
|
||||
from tiramisu.option import ChoiceOption, BoolOption, IntOption, FloatOption, \
|
||||
StrOption, OptionDescription, MasterSlaves
|
||||
from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \
|
||||
StrOption, OptionDescription, MasterSlaves, Config, getapi, undefined
|
||||
from tiramisu.error import PropertiesOptionError
|
||||
from tiramisu.api import TIRAMISU_VERSION
|
||||
|
||||
|
||||
def make_description():
|
||||
|
|
@ -40,96 +40,96 @@ def test_attribute_access():
|
|||
"Once set, option values can't be changed again by attribute access"
|
||||
s = StrOption("string", "", default="string")
|
||||
descr = OptionDescription("options", "", [s])
|
||||
config = Config(descr)
|
||||
api = getapi(Config(descr))
|
||||
# let's try to change it again
|
||||
config.string = "foo"
|
||||
assert config.string == "foo"
|
||||
api.option('string').value.set('foo')
|
||||
assert api.option('string').value.get() == 'foo'
|
||||
|
||||
|
||||
def test_setitem():
|
||||
s = StrOption("string", "", default=["string", "sdfsdf"], default_multi="prout", multi=True)
|
||||
descr = OptionDescription("options", "", [s])
|
||||
config = Config(descr)
|
||||
config.string[1] = "titi"
|
||||
api = getapi(Config(descr))
|
||||
api.option('string').value.set([undefined, 'foo'])
|
||||
assert api.option('string').value.get() == ['string', 'foo']
|
||||
|
||||
|
||||
def test_reset():
|
||||
"if value is None, resets to default owner"
|
||||
s = StrOption("string", "", default="string")
|
||||
descr = OptionDescription("options", "", [s])
|
||||
config = Config(descr)
|
||||
config.string = "foo"
|
||||
assert config.string == "foo"
|
||||
assert config.getowner(s) == owners.user
|
||||
del(config.string)
|
||||
assert config.string == 'string'
|
||||
assert config.getowner(s) == owners.default
|
||||
api = getapi(Config(descr))
|
||||
api.option('string').value.set('foo')
|
||||
assert api.option('string').value.get() == "foo"
|
||||
assert api.option('string').owner.get() ==owners.user
|
||||
api.option('string').value.reset()
|
||||
assert api.option('string').value.get() == 'string'
|
||||
assert api.option('string').owner.get() ==owners.default
|
||||
|
||||
|
||||
def test_reset_with_multi():
|
||||
s = StrOption("string", "", default=["string"], default_multi="string", multi=True)
|
||||
descr = OptionDescription("options", "", [s])
|
||||
config = Config(descr)
|
||||
# config.string = []
|
||||
del(config.string)
|
||||
assert config.string == ["string"]
|
||||
assert config.getowner(s) == 'default'
|
||||
config.string = ["eggs", "spam", "foo"]
|
||||
assert config.getowner(s) == 'user'
|
||||
config.string = []
|
||||
del(config.string)
|
||||
# assert config.string == ["string"]
|
||||
assert config.getowner(s) == 'default'
|
||||
raises(ValueError, "config.string = None")
|
||||
api = getapi(Config(descr))
|
||||
# api.option('string').value.set([])
|
||||
api.option('string').value.reset()
|
||||
assert api.option('string').value.get() == ["string"]
|
||||
assert api.option('string').owner.get() =='default'
|
||||
api.option('string').value.set(["eggs", "spam", "foo"])
|
||||
assert api.option('string').owner.get() =='user'
|
||||
api.option('string').value.set([])
|
||||
api.option('string').value.reset()
|
||||
# assert api.option('string').value.get() == ["string"]
|
||||
assert api.option('string').owner.get() =='default'
|
||||
raises(ValueError, "api.option('string').value.set(None)")
|
||||
|
||||
|
||||
def test_default_with_multi():
|
||||
"default with multi is a list"
|
||||
s = StrOption("string", "", default=[], default_multi="string", multi=True)
|
||||
descr = OptionDescription("options", "", [s])
|
||||
config = Config(descr)
|
||||
assert config.string == []
|
||||
api = getapi(Config(descr))
|
||||
assert api.option('string').value.get() == []
|
||||
s = StrOption("string", "", default=None, default_multi="string", multi=True)
|
||||
descr = OptionDescription("options", "", [s])
|
||||
config = Config(descr)
|
||||
assert config.string == []
|
||||
api = getapi(Config(descr))
|
||||
assert api.option('string').value.get() == []
|
||||
|
||||
|
||||
def test_idontexist():
|
||||
descr = make_description()
|
||||
cfg = Config(descr)
|
||||
cfg
|
||||
raises(AttributeError, "cfg.idontexist")
|
||||
api = getapi(Config(descr))
|
||||
api.option.make_dict()
|
||||
raises(AttributeError, "api.option('idontexist').value.get()")
|
||||
|
||||
|
||||
# ____________________________________________________________
|
||||
def test_attribute_access_with_multi():
|
||||
s = StrOption("string", "", default=["string"], default_multi="string", multi=True)
|
||||
descr = OptionDescription("options", "", [s])
|
||||
config = Config(descr)
|
||||
config.string = ["foo", "bar"]
|
||||
assert config.string == ["foo", "bar"]
|
||||
api = getapi(Config(descr))
|
||||
api.option('string').value.set(["foo", "bar"])
|
||||
assert api.option('string').value.get() == ["foo", "bar"]
|
||||
|
||||
|
||||
def test_item_access_with_multi():
|
||||
s = StrOption("string", "", default=["string"], multi=True)
|
||||
descr = OptionDescription("options", "", [s])
|
||||
config = Config(descr)
|
||||
config.string = ["foo", "bar"]
|
||||
assert config.string == ["foo", "bar"]
|
||||
assert config.string[0] == "foo"
|
||||
config.string[0] = 'changetest'
|
||||
assert config.string[0] == 'changetest'
|
||||
api = getapi(Config(descr))
|
||||
api.option('string').value.set(["foo", "bar"])
|
||||
assert api.option('string').value.get() == ["foo", "bar"]
|
||||
api.option('string').value.set(["changetest", "bar"])
|
||||
assert api.option('string').value.get() == ["changetest", "bar"]
|
||||
|
||||
|
||||
def test_access_with_multi_default():
|
||||
s = StrOption("string", "", default=["string"], multi=True)
|
||||
descr = OptionDescription("options", "", [s])
|
||||
config = Config(descr)
|
||||
assert config.getowner(s) == 'default'
|
||||
config.string = ["foo", "bar"]
|
||||
assert config.string == ["foo", "bar"]
|
||||
assert config.getowner(s) == 'user'
|
||||
api = getapi(Config(descr))
|
||||
assert api.option('string').owner.get() =='default'
|
||||
api.option('string').value.set(["foo", "bar"])
|
||||
assert api.option('string').value.get() == ["foo", "bar"]
|
||||
assert api.option('string').owner.get() =='user'
|
||||
|
||||
|
||||
def test_multi_with_requires():
|
||||
|
|
@ -138,13 +138,12 @@ def test_multi_with_requires():
|
|||
stroption = StrOption('str', 'Test string option', default=["abc"], default_multi="abc",
|
||||
requires=[{'option': intoption, 'expected': 1, 'action': 'hidden'}], multi=True)
|
||||
descr = OptionDescription("options", "", [s, intoption, stroption])
|
||||
config = Config(descr)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
config.read_write()
|
||||
assert not 'hidden' in setting[stroption]
|
||||
config.int = 1
|
||||
raises(PropertiesOptionError, "config.str = ['a', 'b']")
|
||||
assert 'hidden' in setting[stroption]
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
assert not 'hidden' in api.option('str').property.get()
|
||||
api.option('int').value.set(1)
|
||||
raises(PropertiesOptionError, "api.option('str').value.set(['a', 'b'])")
|
||||
assert 'hidden' in api.option('str').property.get()
|
||||
|
||||
|
||||
def test__requires_with_inverted():
|
||||
|
|
@ -153,11 +152,10 @@ def test__requires_with_inverted():
|
|||
stroption = StrOption('str', 'Test string option', default=["abc"], default_multi="abc",
|
||||
requires=[{'option': intoption, 'expected': 1, 'action': 'hide', 'inverse': True}], multi=True)
|
||||
descr = OptionDescription("options", "", [s, intoption, stroption])
|
||||
config = Config(descr)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
assert not 'hidden' in setting[stroption]
|
||||
config.int = 1
|
||||
assert not 'hidden' in setting[stroption]
|
||||
api = getapi(Config(descr))
|
||||
assert not 'hidden' in api.option('str').property.get()
|
||||
api.option('int').value.set(1)
|
||||
assert not 'hidden' in api.option('str').property.get()
|
||||
|
||||
|
||||
def test_multi_with_requires_in_another_group():
|
||||
|
|
@ -167,13 +165,12 @@ def test_multi_with_requires_in_another_group():
|
|||
requires=[{'option': intoption, 'expected': 1, 'action': 'hidden'}], multi=True)
|
||||
descr = OptionDescription("opt", "", [stroption])
|
||||
descr2 = OptionDescription("opt2", "", [intoption, s, descr])
|
||||
config = Config(descr2)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
config.read_write()
|
||||
assert not 'hidden' in setting[stroption]
|
||||
config.int = 1
|
||||
raises(PropertiesOptionError, "config.opt.str = ['a', 'b']")
|
||||
assert 'hidden' in setting[stroption]
|
||||
api = getapi(Config(descr2))
|
||||
api.property.read_write()
|
||||
assert not 'hidden' in api.option('opt.str').property.get()
|
||||
api.option('int').value.set(1)
|
||||
raises(PropertiesOptionError, "api.option('opt.str').value.set(['a', 'b'])")
|
||||
assert 'hidden' in api.option('opt.str').property.get()
|
||||
|
||||
|
||||
def test_multi_with_requires_in_another_group_inverse():
|
||||
|
|
@ -183,13 +180,12 @@ def test_multi_with_requires_in_another_group_inverse():
|
|||
requires=[{'option': intoption, 'expected': 0, 'action': 'hidden', 'inverse': True}], multi=True)
|
||||
descr = OptionDescription("opt", "", [stroption])
|
||||
descr2 = OptionDescription("opt2", "", [intoption, s, descr])
|
||||
config = Config(descr2)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
config.read_write()
|
||||
assert not 'hidden' in setting[stroption]
|
||||
config.int = 1
|
||||
raises(PropertiesOptionError, "config.opt.str = ['a', 'b']")
|
||||
assert 'hidden' in setting[stroption]
|
||||
api = getapi(Config(descr2))
|
||||
api.property.read_write()
|
||||
assert not 'hidden' in api.option('opt.str').property.get()
|
||||
api.option('int').value.set(1)
|
||||
raises(PropertiesOptionError, "api.option('opt.str').value.set(['a', 'b'])")
|
||||
assert 'hidden' in api.option('opt.str').property.get()
|
||||
|
||||
|
||||
def test_apply_requires_from_config():
|
||||
|
|
@ -199,13 +195,12 @@ def test_apply_requires_from_config():
|
|||
requires=[{'option': intoption, 'expected': 1, 'action': 'hidden'}], multi=True)
|
||||
descr = OptionDescription("opt", "", [stroption])
|
||||
descr2 = OptionDescription("opt2", "", [intoption, s, descr])
|
||||
config = Config(descr2)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
config.read_write()
|
||||
assert not 'hidden' in setting[stroption]
|
||||
config.int = 1
|
||||
raises(PropertiesOptionError, 'config.opt.str')
|
||||
assert 'hidden' in setting[stroption]
|
||||
api = getapi(Config(descr2))
|
||||
api.property.read_write()
|
||||
assert not 'hidden' in api.option('opt.str').property.get()
|
||||
api.option('int').value.set(1)
|
||||
raises(PropertiesOptionError, "api.option('opt.str').value.get()")
|
||||
assert 'hidden' in api.option('opt.str').property.get()
|
||||
|
||||
|
||||
def test_apply_requires_with_disabled():
|
||||
|
|
@ -215,13 +210,12 @@ def test_apply_requires_with_disabled():
|
|||
requires=[{'option': intoption, 'expected': 1, 'action': 'disabled'}], multi=True)
|
||||
descr = OptionDescription("opt", "", [stroption])
|
||||
descr2 = OptionDescription("opt2", "", [intoption, s, descr])
|
||||
config = Config(descr2)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
config.read_write()
|
||||
assert not 'disabled' in setting[stroption]
|
||||
config.int = 1
|
||||
raises(PropertiesOptionError, 'config.opt.str')
|
||||
assert 'disabled' in setting[stroption]
|
||||
api = getapi(Config(descr2))
|
||||
api.property.read_write()
|
||||
assert not 'disabled' in api.option('opt.str').property.get()
|
||||
api.option('int').value.set(1)
|
||||
raises(PropertiesOptionError, "api.option('opt.str').value.get()")
|
||||
assert 'disabled' in api.option('opt.str').property.get()
|
||||
|
||||
|
||||
def test_multi_with_requires_with_disabled_in_another_group():
|
||||
|
|
@ -231,13 +225,12 @@ def test_multi_with_requires_with_disabled_in_another_group():
|
|||
requires=[{'option': intoption, 'expected': 1, 'action': 'disabled'}], multi=True)
|
||||
descr = OptionDescription("opt", "", [stroption])
|
||||
descr2 = OptionDescription("opt2", "", [intoption, s, descr])
|
||||
config = Config(descr2)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
config.read_write()
|
||||
assert not 'disabled' in setting[stroption]
|
||||
config.int = 1
|
||||
raises(PropertiesOptionError, "config.opt.str = ['a', 'b']")
|
||||
assert 'disabled' in setting[stroption]
|
||||
api = getapi(Config(descr2))
|
||||
api.property.read_write()
|
||||
assert not 'disabled' in api.option('opt.str').property.get()
|
||||
api.option('int').value.set(1)
|
||||
raises(PropertiesOptionError, "api.option('opt.str').value.set(['a', 'b'])")
|
||||
assert 'disabled' in api.option('opt.str').property.get()
|
||||
|
||||
|
||||
def test_multi_with_requires_that_is_multi():
|
||||
|
|
@ -260,16 +253,16 @@ def test_multi_with_requires_that_is_masterslave():
|
|||
b = IntOption('int', 'Test int option', default=[0], multi=True)
|
||||
c = StrOption('str', 'Test string option', requires=[{'option': b, 'expected': 1, 'action': 'hidden'}], multi=True)
|
||||
descr = MasterSlaves("int", "", [b, c])
|
||||
#descr.impl_set_group_type(groups.master)
|
||||
Config(descr)
|
||||
od = OptionDescription('root', '', [descr])
|
||||
Config(od)
|
||||
|
||||
|
||||
def test_multi_with_requires_that_is_masterslave_master():
|
||||
b = IntOption('int', 'Test int option', multi=True)
|
||||
c = StrOption('str', 'Test string option', requires=[{'option': b, 'expected': 1, 'action': 'hidden'}], multi=True)
|
||||
descr = MasterSlaves("str", "", [c, b])
|
||||
#descr.impl_set_group_type(groups.master)
|
||||
raises(ValueError, "Config(descr)")
|
||||
descr2 = OptionDescription('descr', '', [descr])
|
||||
raises(ValueError, "Config(descr2)")
|
||||
|
||||
|
||||
def test_multi_with_requires_that_is_masterslave_slave():
|
||||
|
|
@ -277,22 +270,25 @@ def test_multi_with_requires_that_is_masterslave_slave():
|
|||
c = StrOption('str', 'Test string option', multi=True)
|
||||
d = StrOption('str1', 'Test string option', requires=[{'option': c, 'expected': '1', 'action': 'hidden'}], multi=True)
|
||||
descr = MasterSlaves("int", "", [b, c, d])
|
||||
#descr.impl_set_group_type(groups.master)
|
||||
config = Config(descr)
|
||||
config.read_write()
|
||||
assert config.int == [0]
|
||||
assert config.str == [None]
|
||||
assert config.str1 == [None]
|
||||
config.int = [0, 1]
|
||||
assert config.int == [0, 1]
|
||||
assert config.str == [None, None]
|
||||
assert config.str1 == [None, None]
|
||||
config.str = [None, '1']
|
||||
config.read_only()
|
||||
assert config.str1 == [None, None]
|
||||
config.read_write()
|
||||
assert config.str1[0] is None
|
||||
raises(PropertiesOptionError, 'config.str1[1]')
|
||||
descr2 = OptionDescription('od', '', [descr])
|
||||
api = getapi(Config(descr2))
|
||||
api.property.read_write()
|
||||
assert api.option('int.int').value.get() == [0]
|
||||
assert api.option('int.str', 0).value.get() == None
|
||||
assert api.option('int.str1', 0).value.get() == None
|
||||
api.option('int.int').value.set([0, 1])
|
||||
assert api.option('int.int').value.get() == [0, 1]
|
||||
assert api.option('int.str', 0).value.get() == None
|
||||
assert api.option('int.str', 1).value.get() == None
|
||||
assert api.option('int.str1', 0).value.get() == None
|
||||
assert api.option('int.str1', 1).value.get() == None
|
||||
api.option('int.str', 1).value.set('1')
|
||||
api.property.read_only()
|
||||
assert api.option('int.str1', 0).value.get() == None
|
||||
assert api.option('int.str1', 1).value.get() == None
|
||||
api.property.read_write()
|
||||
assert api.option('int.str1', 0).value.get() == None
|
||||
raises(PropertiesOptionError, "api.option('int.str1', 1).value.get()")
|
||||
|
||||
|
||||
def test_multi_with_requires_that_is_masterslave_slave_inverse():
|
||||
|
|
@ -300,22 +296,25 @@ def test_multi_with_requires_that_is_masterslave_slave_inverse():
|
|||
c = StrOption('str', 'Test string option', multi=True)
|
||||
d = StrOption('str1', 'Test string option', requires=[{'option': c, 'expected': None, 'action': 'hidden', 'inverse': True}], multi=True)
|
||||
descr = MasterSlaves("int", "", [b, c, d])
|
||||
#descr.impl_set_group_type(groups.master)
|
||||
config = Config(descr)
|
||||
config.read_write()
|
||||
assert config.int == [0]
|
||||
assert config.str == [None]
|
||||
assert config.str1 == [None]
|
||||
config.int = [0, 1]
|
||||
assert config.int == [0, 1]
|
||||
assert config.str == [None, None]
|
||||
assert config.str1 == [None, None]
|
||||
config.str = [None, '1']
|
||||
config.read_only()
|
||||
assert config.str1 == [None, None]
|
||||
config.read_write()
|
||||
assert config.str1[0] is None
|
||||
raises(PropertiesOptionError, 'config.str1[1]')
|
||||
descr2 = OptionDescription('od', '', [descr])
|
||||
api = getapi(Config(descr2))
|
||||
api.property.read_write()
|
||||
assert api.option('int.int').value.get() == [0]
|
||||
assert api.option('int.str', 0).value.get() is None
|
||||
assert api.option('int.str1', 0).value.get() is None
|
||||
api.option('int.int').value.set([0, 1])
|
||||
assert api.option('int.int').value.get() == [0, 1]
|
||||
assert api.option('int.str', 0).value.get() is None
|
||||
assert api.option('int.str', 1).value.get() is None
|
||||
assert api.option('int.str1', 0).value.get() is None
|
||||
assert api.option('int.str1', 1).value.get() is None
|
||||
api.option('int.str', 1).value.set('1')
|
||||
api.property.read_only()
|
||||
assert api.option('int.str1', 0).value.get() is None
|
||||
assert api.option('int.str1', 1).value.get() is None
|
||||
api.property.read_write()
|
||||
assert api.option('int.str1', 0).value.get() is None
|
||||
raises(PropertiesOptionError, "api.option('int.str1', 1).value.get()")
|
||||
|
||||
|
||||
def test_multi_with_requires_that_is_not_same_masterslave():
|
||||
|
|
@ -335,43 +334,32 @@ def test_multi_with_requires_that_is_not_same_masterslave():
|
|||
def test_multi_with_bool():
|
||||
s = BoolOption("bool", "", default=[False], multi=True)
|
||||
descr = OptionDescription("options", "", [s])
|
||||
config = Config(descr)
|
||||
assert descr.bool.impl_is_multi() is True
|
||||
config.bool = [True, False]
|
||||
assert config.cfgimpl_get_values()[s] == [True, False]
|
||||
assert config.bool == [True, False]
|
||||
|
||||
|
||||
def test_multi_with_bool_two():
|
||||
s = BoolOption("bool", "", default=[False], multi=True)
|
||||
descr = OptionDescription("options", "", [s])
|
||||
config = Config(descr)
|
||||
config
|
||||
assert descr.bool.impl_is_multi() is True
|
||||
raises(ValueError, "config.bool = True")
|
||||
api = getapi(Config(descr))
|
||||
api.option('bool').value.set([True, False])
|
||||
assert api.option('bool').value.get() == [True, False]
|
||||
|
||||
|
||||
def test_choice_access_with_multi():
|
||||
ch = ChoiceOption("t1", "", ("a", "b"), default=["a"], multi=True)
|
||||
descr = OptionDescription("options", "", [ch])
|
||||
config = Config(descr)
|
||||
config.t1 = ["a", "b", "a", "b"]
|
||||
assert config.t1 == ["a", "b", "a", "b"]
|
||||
api = getapi(Config(descr))
|
||||
api.option('t1').value.set(["a", "b", "a", "b"])
|
||||
assert api.option('t1').value.get() == ["a", "b", "a", "b"]
|
||||
|
||||
|
||||
#____________________________________________________________
|
||||
def test_accepts_multiple_changes_from_option():
|
||||
s = StrOption("string", "", default="string")
|
||||
descr = OptionDescription("options", "", [s])
|
||||
config = Config(descr)
|
||||
config.string = "egg"
|
||||
assert s.impl_getdefault() == "string"
|
||||
assert config.string == "egg"
|
||||
config.string = 'blah'
|
||||
assert s.impl_getdefault() == "string"
|
||||
assert config.string == "blah"
|
||||
config.string = 'bol'
|
||||
assert config.string == 'bol'
|
||||
api = getapi(Config(descr))
|
||||
api.option('string').value.set("egg")
|
||||
assert api.option('string').option.default() == "string"
|
||||
assert api.option('string').value.get() == "egg"
|
||||
api.option('string').value.set('blah')
|
||||
assert api.option('string').option.default() == "string"
|
||||
assert api.option('string').value.get() == "blah"
|
||||
api.option('string').value.set('bol')
|
||||
assert api.option('string').value.get() == 'bol'
|
||||
|
||||
|
||||
def test_allow_multiple_changes_from_config():
|
||||
|
|
@ -383,22 +371,21 @@ def test_allow_multiple_changes_from_config():
|
|||
s2 = StrOption("string2", "", default="string")
|
||||
suboption = OptionDescription("bip", "", [s2])
|
||||
descr = OptionDescription("options", "", [s, suboption])
|
||||
config = Config(descr)
|
||||
config.string = "oh"
|
||||
assert config.string == "oh"
|
||||
config.string = "blah"
|
||||
assert config.string == "blah"
|
||||
api = getapi(Config(descr))
|
||||
api.option('string').value.set("oh")
|
||||
assert api.option('string').value.get() == "oh"
|
||||
api.option('string').value.set("blah")
|
||||
assert api.option('string').value.get() == "blah"
|
||||
|
||||
|
||||
# ____________________________________________________________
|
||||
# accessing a value by the get method
|
||||
def test_access_by_get():
|
||||
descr = make_description()
|
||||
cfg = Config(descr)
|
||||
raises(AttributeError, "cfg.find(byname='idontexist')")
|
||||
assert cfg.find_first(byname='wantref', type_='value') is False
|
||||
assert cfg.gc.dummy is False
|
||||
assert cfg.find_first(byname='dummy', type_='value') is False
|
||||
api = getapi(Config(descr))
|
||||
raises(AttributeError, "api.option.find('idontexist')")
|
||||
assert api.option.find_first('wantref', type='value') is False
|
||||
assert api.option.find_first('dummy', type='value') is False
|
||||
|
||||
|
||||
def test_access_by_get_whith_hide():
|
||||
|
|
@ -409,152 +396,116 @@ def test_access_by_get_whith_hide():
|
|||
BoolOption("d1", "")]),
|
||||
BoolOption("b2", ""),
|
||||
BoolOption("d1", "")])
|
||||
c = Config(descr)
|
||||
c.read_write()
|
||||
raises(AttributeError, "c.find(byname='b1')")
|
||||
|
||||
|
||||
def test_extend_config_properties():
|
||||
descr = make_description()
|
||||
cfg = Config(descr)
|
||||
setting = cfg.cfgimpl_get_settings()
|
||||
assert set(eval(str(setting))) == set(['cache', 'expire', 'validator', 'warnings'])
|
||||
setting.extend(['test', 'test2'])
|
||||
assert set(eval(str(setting))) == set(['test', 'cache', 'test2', 'expire', 'validator', 'warnings'])
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
raises(AttributeError, "api.option.find('b1', type='value')")
|
||||
|
||||
|
||||
def test_append_properties():
|
||||
descr = make_description()
|
||||
cfg = Config(descr)
|
||||
setting = cfg.cfgimpl_get_settings()
|
||||
option = cfg.cfgimpl_get_description().gc.dummy
|
||||
assert tuple(option._properties) == tuple()
|
||||
assert not 'test' in setting[option]
|
||||
setting[option].append('test')
|
||||
raises(ConfigError, "setting[option].append('force_store_value')")
|
||||
raises(ConfigError, "setting.append('force_store_value')")
|
||||
assert tuple(option._properties) == tuple()
|
||||
assert 'test' in setting[option]
|
||||
assert setting[option].get() == ('test',)
|
||||
api = getapi(Config(descr))
|
||||
assert api.option('gc.dummy').property.get() == set()
|
||||
api.option('gc.dummy').property.add('test')
|
||||
assert api.option('gc.dummy').property.get() == {'test'}
|
||||
raises(ConfigError, "api.option('gc.dummy').property.add('force_store_value')")
|
||||
assert api.option('gc.dummy').property.get() == {'test'}
|
||||
|
||||
|
||||
def test_reset_properties():
|
||||
descr = make_description()
|
||||
cfg = Config(descr)
|
||||
setting = cfg.cfgimpl_get_settings()
|
||||
option = cfg.cfgimpl_get_description().gc.dummy
|
||||
assert setting._p_.get_modified_properties() == {}
|
||||
setting.append('frozen')
|
||||
assert setting._p_.get_modified_properties() == {None: set(('frozen', 'expire', 'cache', 'validator', 'warnings'))}
|
||||
setting.reset()
|
||||
assert setting._p_.get_modified_properties() == {}
|
||||
setting[option].append('test')
|
||||
assert setting._p_.get_modified_properties() == {'gc.dummy': set(('test',))}
|
||||
setting.reset()
|
||||
assert setting._p_.get_modified_properties() == {'gc.dummy': set(('test',))}
|
||||
setting.append('frozen')
|
||||
assert setting._p_.get_modified_properties() == {None: set(('frozen', 'expire', 'validator', 'cache', 'warnings')), 'gc.dummy': set(('test',))}
|
||||
setting.reset(option)
|
||||
assert setting._p_.get_modified_properties() == {None: set(('frozen', 'expire', 'validator', 'cache', 'warnings'))}
|
||||
setting[option].append('test')
|
||||
assert setting._p_.get_modified_properties() == {None: set(('frozen', 'expire', 'validator', 'cache', 'warnings')), 'gc.dummy': set(('test',))}
|
||||
setting.reset(all_properties=True)
|
||||
assert setting._p_.get_modified_properties() == {}
|
||||
raises(ValueError, 'setting.reset(all_properties=True, opt=option)')
|
||||
a = descr.wantref
|
||||
setting[a].append('test')
|
||||
setting[a].reset()
|
||||
|
||||
|
||||
def test_reset_multiple():
|
||||
descr = make_description()
|
||||
cfg = Config(descr)
|
||||
setting = cfg.cfgimpl_get_settings()
|
||||
option = cfg.cfgimpl_get_description().gc.dummy
|
||||
setting.append('frozen')
|
||||
setting[option].append('test')
|
||||
setting.reset()
|
||||
setting.reset()
|
||||
setting.append('frozen')
|
||||
setting[option].append('test')
|
||||
setting.reset(option)
|
||||
setting.reset(option)
|
||||
setting.append('frozen')
|
||||
setting[option].append('test')
|
||||
setting.reset(all_properties=True)
|
||||
setting.reset(all_properties=True)
|
||||
api = getapi(Config(descr))
|
||||
assert api.option('gc.dummy').property.get() == set()
|
||||
api.option('gc.dummy').property.add('frozen')
|
||||
assert api.option('gc.dummy').property.get() == {'frozen'}
|
||||
api.option('gc.dummy').property.reset()
|
||||
assert api.option('gc.dummy').property.get() == set()
|
||||
|
||||
|
||||
def test_properties_cached():
|
||||
b1 = BoolOption("b1", "", properties=('test',))
|
||||
descr = OptionDescription("opt", "", [OptionDescription("sub", "", [b1])])
|
||||
c = Config(descr)
|
||||
c.read_write()
|
||||
setting = c.cfgimpl_get_settings()
|
||||
option = c.cfgimpl_get_description().sub.b1
|
||||
option
|
||||
c._setattr('sub.b1', True, force_permissive=True)
|
||||
assert str(setting[b1]) in ["['test']", "[u'test']"]
|
||||
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
assert api.option('sub.b1').property.get() == {'test'}
|
||||
|
||||
|
||||
def test_append_properties_force_store_value():
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False, properties=('force_store_value',))
|
||||
gcgroup = OptionDescription('gc', '', [gcdummy])
|
||||
descr = OptionDescription('tiramisu', '', [gcgroup])
|
||||
cfg = Config(descr)
|
||||
setting = cfg.cfgimpl_get_settings()
|
||||
option = cfg.cfgimpl_get_description().gc.dummy
|
||||
assert tuple(option._properties) == tuple(['force_store_value'])
|
||||
assert not 'test' in setting[option]
|
||||
setting[option].append('test')
|
||||
assert tuple(option._properties) == tuple(['force_store_value'])
|
||||
assert 'test' in setting[option]
|
||||
api = getapi(Config(descr))
|
||||
assert api.option('gc.dummy').property.get() == {'force_store_value'}
|
||||
api.option('gc.dummy').property.add('test')
|
||||
assert api.option('gc.dummy').property.get() == {'force_store_value', 'test'}
|
||||
|
||||
|
||||
def test_reset_properties_force_store_value():
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False, properties=('force_store_value',))
|
||||
gcgroup = OptionDescription('gc', '', [gcdummy])
|
||||
descr = OptionDescription('tiramisu', '', [gcgroup])
|
||||
cfg = Config(descr)
|
||||
setting = cfg.cfgimpl_get_settings()
|
||||
option = cfg.cfgimpl_get_description().gc.dummy
|
||||
assert setting._p_.get_modified_properties() == {}
|
||||
setting.append('frozen')
|
||||
assert setting._p_.get_modified_properties() == {None: set(('frozen', 'expire', 'cache', 'validator', 'warnings'))}
|
||||
setting.reset()
|
||||
assert setting._p_.get_modified_properties() == {}
|
||||
setting[option].append('test')
|
||||
assert setting._p_.get_modified_properties() == {'gc.dummy': set(('test', 'force_store_value'))}
|
||||
setting.reset()
|
||||
assert setting._p_.get_modified_properties() == {'gc.dummy': set(('test', 'force_store_value'))}
|
||||
setting.append('frozen')
|
||||
assert setting._p_.get_modified_properties() == {None: set(('frozen', 'expire', 'validator', 'cache', 'warnings')), 'gc.dummy': set(('test', 'force_store_value'))}
|
||||
setting.reset(option)
|
||||
assert setting._p_.get_modified_properties() == {None: set(('frozen', 'expire', 'validator', 'cache', 'warnings'))}
|
||||
setting[option].append('test')
|
||||
assert setting._p_.get_modified_properties() == {None: set(('frozen', 'expire', 'validator', 'cache', 'warnings')), 'gc.dummy': set(('test', 'force_store_value'))}
|
||||
setting.reset(all_properties=True)
|
||||
assert setting._p_.get_modified_properties() == {}
|
||||
raises(ValueError, 'setting.reset(all_properties=True, opt=option)')
|
||||
api = getapi(Config(descr))
|
||||
assert api.property.get_modified() == {}
|
||||
api.property.add('frozen')
|
||||
if TIRAMISU_VERSION == 2:
|
||||
assert api.property.get_modified() == \
|
||||
{None: set(('frozen', 'cache', 'validator', 'warnings', 'expire'))}
|
||||
else:
|
||||
assert api.property.get_modified() == \
|
||||
{None: set(('frozen', 'cache', 'validator', 'warnings'))}
|
||||
api.property.reset()
|
||||
assert api.property.get_modified() == {}
|
||||
api.option('gc.dummy').property.add('test')
|
||||
assert api.property.get_modified() == {'gc.dummy': set(('test', 'force_store_value'))}
|
||||
api.property.reset()
|
||||
assert api.property.get_modified() == {'gc.dummy': set(('test', 'force_store_value'))}
|
||||
api.property.add('frozen')
|
||||
if TIRAMISU_VERSION == 2:
|
||||
assert api.property.get_modified() == \
|
||||
{None: set(('frozen', 'validator', 'cache', 'warnings', 'expire')),
|
||||
'gc.dummy': set(('test', 'force_store_value'))}
|
||||
else:
|
||||
assert api.property.get_modified() == \
|
||||
{None: set(('frozen', 'validator', 'cache', 'warnings')),
|
||||
'gc.dummy': set(('test', 'force_store_value'))}
|
||||
api.property.add('frozen')
|
||||
if TIRAMISU_VERSION == 2:
|
||||
assert api.property.get_modified() == \
|
||||
{None: set(('frozen', 'validator', 'cache', 'warnings', 'expire')),
|
||||
'gc.dummy': set(('test', 'force_store_value'))}
|
||||
else:
|
||||
assert api.property.get_modified() == \
|
||||
{None: set(('frozen', 'validator', 'cache', 'warnings')),
|
||||
'gc.dummy': set(('test', 'force_store_value'))}
|
||||
api.option('gc.dummy').property.add('test')
|
||||
if TIRAMISU_VERSION == 2:
|
||||
assert api.property.get_modified() == \
|
||||
{None: set(('frozen', 'validator', 'cache', 'warnings', 'expire')),
|
||||
'gc.dummy': set(('test', 'force_store_value'))}
|
||||
else:
|
||||
assert api.property.get_modified() == \
|
||||
{None: set(('frozen', 'validator', 'cache', 'warnings')),
|
||||
'gc.dummy': set(('test', 'force_store_value'))}
|
||||
|
||||
|
||||
def test_set_modified_value():
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False, properties=('force_store_value',))
|
||||
gcgroup = OptionDescription('gc', '', [gcdummy])
|
||||
descr = OptionDescription('tiramisu', '', [gcgroup])
|
||||
cfg = Config(descr)
|
||||
setting = cfg.cfgimpl_get_settings()
|
||||
option = cfg.cfgimpl_get_description().gc.dummy
|
||||
assert setting._p_.get_modified_properties() == {}
|
||||
setting._p_.set_modified_properties({None: set(('frozen', 'expire', 'cache', 'validator', 'warnings'))})
|
||||
assert setting._p_.get_modified_properties() == {None: set(('frozen', 'expire', 'cache', 'validator', 'warnings'))}
|
||||
api = getapi(Config(descr))
|
||||
assert api.property.get_modified() == {}
|
||||
api.property.set_modified({None: set(('frozen', 'cache', 'validator', 'warnings'))})
|
||||
assert api.property.get_modified() == \
|
||||
{None: set(('frozen', 'cache', 'validator', 'warnings'))}
|
||||
|
||||
|
||||
def test_pprint():
|
||||
msg_error = _("cannot access to {0} \"{1}\" because has {2} {3}")
|
||||
if TIRAMISU_VERSION == 2:
|
||||
msg_error = _("cannot access to {0} \"{1}\" because has {2} {3}")
|
||||
msg_is_not = _('the value of "{0}" is not "{1}"')
|
||||
else:
|
||||
msg_error = _("cannot access to {0} \"{1}\" because has {2} {3}")
|
||||
msg_is_not = _('the value of "{0}" is not {1}')
|
||||
msg_is = _('the value of "{0}" is "{1}"')
|
||||
msg_is_not = _('the value of "{0}" is not "{1}"')
|
||||
properties = _('properties')
|
||||
prop = _('property')
|
||||
|
||||
|
|
@ -575,69 +526,69 @@ def test_pprint():
|
|||
val3 = StrOption('val3', "", requires=[{'option': stroption, 'expected': '2', 'action': 'hidden', 'inverse': True}])
|
||||
|
||||
descr = OptionDescription("options", "", [s, s2, s3, intoption, stroption, descr2, val3])
|
||||
config = Config(descr)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
config.read_write()
|
||||
config.int = 1
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
api.option('int').value.set(1)
|
||||
err = None
|
||||
try:
|
||||
config.str
|
||||
except Exception as error:
|
||||
api.option('str').value.get()
|
||||
except PropertiesOptionError as error:
|
||||
err = error
|
||||
|
||||
list_disabled_1 = 'disabled (' + display_list([msg_is.format('string2', 'string'), msg_is.format('Test int option', '1')]) + ')'
|
||||
list_disabled_2 = 'disabled (' + display_list([msg_is.format('Test int option', '1'), msg_is.format('string2', 'string')]) + ')'
|
||||
list_hidden = 'hidden (' + msg_is_not.format('Test int option', display_list([2, 3, 4], 'or')) + ')'
|
||||
comp1 = str(err) == _(msg_error.format('option', 'Test string option', properties, display_list([list_disabled_1, list_hidden])))
|
||||
comp2 = str(err) == _(msg_error.format('option', 'Test string option', properties, display_list([list_disabled_2, list_hidden])))
|
||||
comp3 = str(err) == _(msg_error.format('option', 'Test string option', properties, display_list([list_hidden, list_disabled_1])))
|
||||
comp4 = str(err) == _(msg_error.format('option', 'Test string option', properties, display_list([list_hidden, list_disabled_2])))
|
||||
assert comp1 or comp2 or comp3 or comp4
|
||||
if TIRAMISU_VERSION == 2:
|
||||
list_disabled = 'disabled (' + display_list([msg_is.format('Test int option', '1'), msg_is.format('string2', 'string')]) + ')'
|
||||
list_hidden = 'hidden (' + msg_is_not.format('Test int option', display_list([2, 3, 4], 'or')) + ')'
|
||||
else:
|
||||
list_disabled = '"disabled" (' + display_list([msg_is.format('Test int option', '1'), msg_is.format('string2', 'string')]) + ')'
|
||||
list_hidden = '"hidden" (' + msg_is_not.format('Test int option', display_list([2, 3, 4], 'or', add_quote=True)) + ')'
|
||||
assert str(err) == _(msg_error.format('option', 'Test string option', properties, display_list([list_disabled, list_hidden])))
|
||||
|
||||
err = None
|
||||
try:
|
||||
config.options.val2
|
||||
except Exception as error:
|
||||
api.option('options.val2').value.get()
|
||||
except PropertiesOptionError as error:
|
||||
err = error
|
||||
|
||||
assert str(err) == msg_error.format('optiondescription', 'options', prop, 'hidden (' + msg_is.format('Test int option', 1) + ')')
|
||||
if TIRAMISU_VERSION == 2:
|
||||
assert str(err) == msg_error.format('optiondescription', 'options', prop, 'hidden (' + msg_is.format('Test int option', 1) + ')')
|
||||
else:
|
||||
assert str(err) == msg_error.format('optiondescription', 'options', prop, '"hidden" (' + msg_is.format('Test int option', 1) + ')')
|
||||
|
||||
err = None
|
||||
try:
|
||||
config.val3
|
||||
except Exception as error:
|
||||
api.option('val3').value.get()
|
||||
except PropertiesOptionError as error:
|
||||
err = error
|
||||
|
||||
msg_1 = msg_is.format('string2', 'string')
|
||||
msg_2 = msg_is.format('Test int option', 1)
|
||||
msg_3 = msg_is_not.format('Test int option', display_list([2, 3, 4], 'or'))
|
||||
if TIRAMISU_VERSION == 2:
|
||||
msg_3 = msg_is_not.format('Test int option', display_list([2, 3, 4], 'or'))
|
||||
list_hidden = 'hidden (' + display_list([msg_2, msg_3, msg_1]) + ')'
|
||||
else:
|
||||
msg_3 = msg_is_not.format('Test int option', display_list([2, 3, 4], 'or', add_quote=True))
|
||||
list_hidden = '"hidden" (' + display_list([msg_2, msg_3, msg_1]) + ')'
|
||||
|
||||
list_hidden = 'hidden (' + display_list([msg_1, msg_2, msg_3]) + ')'
|
||||
comp1 = str(err) == msg_error.format('option', 'val3', prop, list_hidden)
|
||||
list_hidden = 'hidden (' + display_list([msg_1, msg_3, msg_2]) + ')'
|
||||
comp2 = str(err) == msg_error.format('option', 'val3', prop, list_hidden)
|
||||
list_hidden = 'hidden (' + display_list([msg_2, msg_1, msg_3]) + ')'
|
||||
comp3 = str(err) == msg_error.format('option', 'val3', prop, list_hidden)
|
||||
list_hidden = 'hidden (' + display_list([msg_2, msg_3, msg_1]) + ')'
|
||||
comp4 = str(err) == msg_error.format('option', 'val3', prop, list_hidden)
|
||||
list_hidden = 'hidden (' + display_list([msg_3, msg_1, msg_2]) + ')'
|
||||
comp5 = str(err) == msg_error.format('option', 'val3', prop, list_hidden)
|
||||
list_hidden = 'hidden (' + display_list([msg_3, msg_2, msg_1]) + ')'
|
||||
comp6 = str(err) == msg_error.format('option', 'val3', prop, list_hidden)
|
||||
assert comp1 or comp2 or comp3 or comp4 or comp5 or comp6
|
||||
assert str(err) == msg_error.format('option', 'val3', prop, list_hidden)
|
||||
|
||||
err = None
|
||||
try:
|
||||
config.string
|
||||
api.option('string').value.get()
|
||||
except Exception as error:
|
||||
err = error
|
||||
|
||||
assert str(err) == msg_error.format('option', 'string', properties, display_list(['disabled', 'hidden']))
|
||||
if TIRAMISU_VERSION == 2:
|
||||
assert str(err) == msg_error.format('option', 'string', properties, display_list(['disabled', 'hidden']))
|
||||
else:
|
||||
assert str(err) == msg_error.format('option', 'string', properties, display_list(['disabled', 'hidden'], add_quote=True))
|
||||
|
||||
err = None
|
||||
try:
|
||||
config.string3
|
||||
api.option('string3').value.get()
|
||||
except Exception as error:
|
||||
err = error
|
||||
|
||||
assert str(err) == msg_error.format('option', 'string3', prop, 'hidden')
|
||||
if TIRAMISU_VERSION == 2:
|
||||
assert str(err) == msg_error.format('option', 'string3', prop, 'hidden')
|
||||
else:
|
||||
assert str(err) == msg_error.format('option', 'string3', prop, '"hidden"')
|
||||
|
|
|
|||
|
|
@ -5,9 +5,8 @@ do_autopath()
|
|||
|
||||
from py.test import raises
|
||||
|
||||
from tiramisu.config import Config
|
||||
from tiramisu.option import ChoiceOption, BoolOption, IntOption, FloatOption, \
|
||||
PasswordOption, StrOption, DateOption, OptionDescription
|
||||
from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \
|
||||
PasswordOption, StrOption, DateOption, OptionDescription, Config, getapi
|
||||
from tiramisu.error import PropertiesOptionError
|
||||
|
||||
|
||||
|
|
@ -43,118 +42,93 @@ def make_description():
|
|||
# ____________________________________________________________
|
||||
def test_is_hidden():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
dummy = config.unwrap_from_path('gc.dummy')
|
||||
config.read_write()
|
||||
assert not 'frozen' in setting[dummy]
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
assert not 'frozen' in api.option('gc.dummy').property.get()
|
||||
# setattr
|
||||
raises(PropertiesOptionError, "config.gc.dummy == False")
|
||||
raises(PropertiesOptionError, "api.option('gc.dummy').value.get() == False")
|
||||
# getattr
|
||||
raises(PropertiesOptionError, "config.gc.dummy")
|
||||
raises(PropertiesOptionError, "api.option('gc.dummy').value.get()")
|
||||
|
||||
|
||||
def test_group_is_hidden():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
config.read_write()
|
||||
gc = config.unwrap_from_path('gc')
|
||||
#config.unwrap_from_path('gc.dummy')
|
||||
setting[gc].append('hidden')
|
||||
raises(PropertiesOptionError, "config.gc.dummy")
|
||||
assert 'hidden' in setting[gc]
|
||||
raises(PropertiesOptionError, "config.gc.float")
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
api.option('gc').property.add('hidden')
|
||||
raises(PropertiesOptionError, "api.option('gc.dummy').value.get()")
|
||||
assert 'hidden' in api.option('gc').property.get()
|
||||
raises(PropertiesOptionError, "api.option('gc.float').value.get()")
|
||||
# manually set the subconfigs to "show"
|
||||
setting[gc].remove('hidden')
|
||||
assert not 'hidden' in setting[gc]
|
||||
assert config.gc.float == 2.3
|
||||
api.option('gc').property.pop('hidden')
|
||||
assert not 'hidden' in api.option('gc').property.get()
|
||||
assert api.option('gc.float').value.get() == 2.3
|
||||
#dummy est en hide
|
||||
prop = []
|
||||
try:
|
||||
config.gc.dummy = False
|
||||
api.option('gc.dummy').value.set(False)
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'hidden' in prop
|
||||
|
||||
def test_extend_properties():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
config.read_write()
|
||||
gc = config.unwrap_from_path('gc')
|
||||
#config.unwrap_from_path('gc.dummy')
|
||||
setting[gc].extend(['hidden', 'user_defined_property'])
|
||||
assert 'hidden' in setting[gc]
|
||||
assert 'user_defined_property' in setting[gc]
|
||||
|
||||
def test_group_is_hidden_multi():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
config.read_write()
|
||||
obj = config.unwrap_from_path('objspace')
|
||||
objspace = config.objspace
|
||||
setting[obj].append('hidden')
|
||||
raises(PropertiesOptionError, "config.objspace")
|
||||
assert 'hidden' in setting[obj]
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
api.option('objspace').property.add('hidden')
|
||||
raises(PropertiesOptionError, "api.option('objspace').value.get()")
|
||||
assert 'hidden' in api.option('objspace').property.get()
|
||||
prop = []
|
||||
try:
|
||||
objspace.append('std')
|
||||
api.option('objspace').value.set(['std'])
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'hidden' in prop
|
||||
setting[obj].remove('hidden')
|
||||
assert not 'hidden' in setting[obj]
|
||||
config.objspace.append('std')
|
||||
api.option('objspace').property.pop('hidden')
|
||||
assert not 'hidden' in api.option('objspace').property.get()
|
||||
api.option('objspace').value.set(['std', 'std'])
|
||||
|
||||
|
||||
def test_global_show():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
dummy = config.unwrap_from_path('gc.dummy')
|
||||
config.read_write()
|
||||
setting[dummy].append('hidden')
|
||||
assert 'hidden' in setting[dummy]
|
||||
raises(PropertiesOptionError, "config.gc.dummy == False")
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
api.option('gc.dummy').property.add('hidden')
|
||||
assert 'hidden' in api.option('gc.dummy').property.get()
|
||||
raises(PropertiesOptionError, "api.option('gc.dummy').value.get() == False")
|
||||
|
||||
|
||||
def test_with_many_subgroups():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
booltwo = config.unwrap_from_path('gc.subgroup.booltwo')
|
||||
setting = config.cfgimpl_get_settings()
|
||||
assert not 'hidden' in setting[booltwo]
|
||||
assert config.gc.subgroup.booltwo is False
|
||||
setting[booltwo].append('hidden')
|
||||
path = 'gc.subgroup.booltwo'
|
||||
homeconfig, name = config.cfgimpl_get_home_by_path(path)
|
||||
assert name == "booltwo"
|
||||
getattr(homeconfig.cfgimpl_get_description(), name)
|
||||
assert 'hidden' in setting[booltwo]
|
||||
api = getapi(Config(descr))
|
||||
#booltwo = config.unwrap_from_path('gc.subgroup.booltwo')
|
||||
#setting = config.cfgimpl_get_settings()
|
||||
assert not 'hidden' in api.option('gc.subgroup.booltwo').property.get()
|
||||
assert api.option('gc.subgroup.booltwo').value.get() is False
|
||||
api.option('gc.subgroup.booltwo').property.add('hidden')
|
||||
|
||||
|
||||
def test_password_option():
|
||||
o = PasswordOption('o', '')
|
||||
d = OptionDescription('d', '', [o])
|
||||
c = Config(d)
|
||||
api = getapi(Config(d))
|
||||
|
||||
c.o = u'a_valid_password'
|
||||
raises(ValueError, "c.o = 1")
|
||||
api.option('o').value.set('a_valid_password')
|
||||
raises(ValueError, "api.option('o').value.set(1)")
|
||||
|
||||
|
||||
def test_date_option():
|
||||
o = DateOption('o', '')
|
||||
d = OptionDescription('d', '', [o])
|
||||
c = Config(d)
|
||||
api = getapi(Config(d))
|
||||
|
||||
c.o = u'2017-02-04'
|
||||
c.o = u'2017-2-4'
|
||||
raises(ValueError, "c.o = 1")
|
||||
raises(ValueError, "c.o = u'2017-13-20'")
|
||||
raises(ValueError, "c.o = u'2017-11-31'")
|
||||
raises(ValueError, "c.o = u'2017-12-32'")
|
||||
raises(ValueError, "c.o = u'2017-2-29'")
|
||||
raises(ValueError, "c.o = u'2-2-2017'")
|
||||
raises(ValueError, "c.o = u'2017/2/2'")
|
||||
api.option('o').value.set('2017-02-04')
|
||||
api.option('o').value.set('2017-2-4')
|
||||
raises(ValueError, "api.option('o').value.set(1)")
|
||||
raises(ValueError, "api.option('o').value.set('2017-13-20')")
|
||||
raises(ValueError, "api.option('o').value.set('2017-11-31')")
|
||||
raises(ValueError, "api.option('o').value.set('2017-12-32')")
|
||||
raises(ValueError, "api.option('o').value.set('2017-2-29')")
|
||||
raises(ValueError, "api.option('o').value.set('2-2-2017')")
|
||||
raises(ValueError, "api.option('o').value.set('2017/2/2')")
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ do_autopath()
|
|||
|
||||
from py.test import raises
|
||||
|
||||
from tiramisu.config import Config
|
||||
from tiramisu.option import UsernameOption
|
||||
|
||||
def test_username():
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@ do_autopath()
|
|||
import warnings
|
||||
from py.test import raises
|
||||
|
||||
from tiramisu.config import Config
|
||||
from tiramisu.option import BoolOption, StrOption, OptionDescription, MasterSlaves
|
||||
from tiramisu import BoolOption, StrOption, OptionDescription, MasterSlaves, Config, getapi
|
||||
from tiramisu.setting import groups
|
||||
from tiramisu.error import ValueWarning, ConfigError
|
||||
from tiramisu.i18n import _
|
||||
|
|
@ -22,7 +21,7 @@ def return_true(value, param=None):
|
|||
|
||||
def return_false(value, param=None):
|
||||
if value == 'val' and param in [None, 'yes']:
|
||||
raise ValueError('test error')
|
||||
raise ValueError('test error return_false')
|
||||
|
||||
|
||||
def return_val(value, param=None):
|
||||
|
|
@ -35,14 +34,18 @@ def return_if_val(value):
|
|||
|
||||
|
||||
def is_context(value, context):
|
||||
context.cfgimpl_get_settings().remove('validator')
|
||||
api = getapi(context)
|
||||
api.property.pop('validator')
|
||||
if not isinstance(context, Config):
|
||||
raise ValueError('not context')
|
||||
|
||||
|
||||
def value_values(value, values):
|
||||
if not (value == 'val' and values == ['val'] or
|
||||
value == 'val1' and values == ['val'] or
|
||||
value == 'val2' and values == ['val'] or
|
||||
value == 'val1' and values == ['val1'] or
|
||||
value == 'val1' and values == ['val1', 'val2'] or
|
||||
value == 'val2' and values == ['val1', 'val2'] or
|
||||
value == 'val1' and values == ['val1', None]):
|
||||
raise ValueError('error')
|
||||
|
|
@ -88,7 +91,8 @@ def value_empty(value, empty, values):
|
|||
|
||||
|
||||
def valid_from_config(value, config):
|
||||
if config.opt1 != u'yes':
|
||||
api = getapi(config)
|
||||
if api.option('opt1').value.get() != u'yes':
|
||||
raise ValueError("c'est une erreur")
|
||||
|
||||
|
||||
|
|
@ -97,13 +101,13 @@ def test_validator():
|
|||
raises(ValueError, "StrOption('opt2', '', validator=return_false, default='val')")
|
||||
opt2 = StrOption('opt2', '', validator=return_false)
|
||||
root = OptionDescription('root', '', [opt1, opt2])
|
||||
cfg = Config(root)
|
||||
assert cfg.opt1 == 'val'
|
||||
raises(ValueError, "cfg.opt2 = 'val'")
|
||||
api = getapi(Config(root))
|
||||
assert api.option('opt1').value.get() == 'val'
|
||||
raises(ValueError, "api.option('opt2').value.set('val')")
|
||||
try:
|
||||
cfg.opt2 = 'val'
|
||||
api.option('opt2').value.set('val')
|
||||
except ValueError as err:
|
||||
msg = _('"{0}" is an invalid {1} for "{2}", {3}').format('val', _('string'), 'opt2', 'test error')
|
||||
msg = _('"{0}" is an invalid {1} for "{2}", {3}').format('val', _('string'), 'opt2', 'test error return_false')
|
||||
assert str(err) == msg
|
||||
|
||||
|
||||
|
|
@ -112,27 +116,25 @@ def test_validator_params():
|
|||
raises(ValueError, "StrOption('opt2', '', validator=return_false, validator_params={'': ('yes',)}, default='val')")
|
||||
opt2 = StrOption('opt2', '', validator=return_false, validator_params={'': ('yes',)})
|
||||
root = OptionDescription('root', '', [opt1, opt2])
|
||||
cfg = Config(root)
|
||||
assert cfg.opt1 == 'val'
|
||||
raises(ValueError, "cfg.opt2 = 'val'")
|
||||
api = getapi(Config(root))
|
||||
assert api.option('opt1').value.get() == 'val'
|
||||
raises(ValueError, "api.option('opt2').value.set('val')")
|
||||
|
||||
|
||||
def test_validator_params_value_values():
|
||||
opt1 = StrOption('opt1', '', validator=value_values, default=['val'], multi=True)
|
||||
root = OptionDescription('root', '', [opt1])
|
||||
cfg = Config(root)
|
||||
assert cfg.opt1 == ['val']
|
||||
cfg.opt1[0] = 'val1'
|
||||
cfg.opt1.append('val2')
|
||||
api = getapi(Config(root))
|
||||
assert api.option('opt1').value.get() == ['val']
|
||||
api.option('opt1').value.set(['val1', 'val2'])
|
||||
|
||||
|
||||
def test_validator_params_value_values_index():
|
||||
opt1 = StrOption('opt1', '', validator=value_values_index, default=['val'], multi=True)
|
||||
root = OptionDescription('root', '', [opt1])
|
||||
cfg = Config(root)
|
||||
assert cfg.opt1 == ['val']
|
||||
cfg.opt1[0] = 'val1'
|
||||
cfg.opt1.append('val2')
|
||||
api = getapi(Config(root))
|
||||
assert api.option('opt1').value.get() == ['val']
|
||||
api.option('opt1').value.set(['val1', 'val2'])
|
||||
|
||||
|
||||
def test_validator_params_value_values_master():
|
||||
|
|
@ -141,10 +143,9 @@ def test_validator_params_value_values_master():
|
|||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
root = OptionDescription('root', '', [interface1])
|
||||
cfg = Config(root)
|
||||
assert cfg.ip_admin_eth0.ip_admin_eth0 == []
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append('val1')
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append('val2')
|
||||
api = getapi(Config(root))
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val2'])
|
||||
|
||||
|
||||
def test_validator_params_value_values_index_master():
|
||||
|
|
@ -153,10 +154,9 @@ def test_validator_params_value_values_index_master():
|
|||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
root = OptionDescription('root', '', [interface1])
|
||||
cfg = Config(root)
|
||||
assert cfg.ip_admin_eth0.ip_admin_eth0 == []
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append('val1')
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append('val2')
|
||||
api = getapi(Config(root))
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val2'])
|
||||
|
||||
|
||||
def test_validator_params_value_values_slave():
|
||||
|
|
@ -165,12 +165,12 @@ def test_validator_params_value_values_slave():
|
|||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
root = OptionDescription('root', '', [interface1])
|
||||
cfg = Config(root)
|
||||
assert cfg.ip_admin_eth0.ip_admin_eth0 == []
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append('val')
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0[0] = 'val1'
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append('val')
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0[1] = 'val2'
|
||||
api = getapi(Config(root))
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1')
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val2')
|
||||
|
||||
|
||||
def test_validator_params_value_values_index_slave():
|
||||
|
|
@ -179,12 +179,12 @@ def test_validator_params_value_values_index_slave():
|
|||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
root = OptionDescription('root', '', [interface1])
|
||||
cfg = Config(root)
|
||||
assert cfg.ip_admin_eth0.ip_admin_eth0 == []
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append('val')
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0[0] = 'val1'
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append('val')
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0[1] = 'val2'
|
||||
api = getapi(Config(root))
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1')
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val2')
|
||||
|
||||
|
||||
def test_validator_params_value_values_notmulti():
|
||||
|
|
@ -202,9 +202,9 @@ def test_validator_params_value_values_kwargs_empty():
|
|||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
root = OptionDescription('root', '', [v, interface1])
|
||||
cfg = Config(root)
|
||||
assert cfg.ip_admin_eth0.ip_admin_eth0 == ['ip']
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0[0] = 'val'
|
||||
api = getapi(Config(root))
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip', 'val'])
|
||||
#cfg.ip_admin_eth0.ip_admin_eth0.append('val')
|
||||
#cfg.ip_admin_eth0.netmask_admin_eth0[1] = 'val2'
|
||||
|
||||
|
|
@ -220,11 +220,11 @@ def test_validator_params_value_values_kwargs():
|
|||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
root = OptionDescription('root', '', [v, interface1])
|
||||
cfg = Config(root)
|
||||
assert cfg.ip_admin_eth0.ip_admin_eth0 == ['ip']
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0[0] = 'val1'
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append('val')
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0[1] = 'val2'
|
||||
api = getapi(Config(root))
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1')
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip', 'val'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val2')
|
||||
|
||||
|
||||
def test_validator_params_value_values_kwargs_values():
|
||||
|
|
@ -237,12 +237,12 @@ def test_validator_params_value_values_kwargs_values():
|
|||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
root = OptionDescription('root', '', [interface1])
|
||||
cfg = Config(root)
|
||||
assert cfg.ip_admin_eth0.ip_admin_eth0 == []
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append('val')
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0[0] = 'val1'
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append('val')
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0[1] = 'val2'
|
||||
api = getapi(Config(root))
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1')
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val2')
|
||||
|
||||
|
||||
def test_validator_params_value_values_kwargs2():
|
||||
|
|
@ -255,11 +255,11 @@ def test_validator_params_value_values_kwargs2():
|
|||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
root = OptionDescription('root', '', [interface1])
|
||||
cfg = Config(root)
|
||||
assert cfg.ip_admin_eth0.ip_admin_eth0 == []
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append('val')
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0[0] = 'val1'
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append('val')
|
||||
api = getapi(Config(root))
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1')
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val'])
|
||||
|
||||
|
||||
def test_validator_params_value_values_kwargs_index():
|
||||
|
|
@ -272,61 +272,60 @@ def test_validator_params_value_values_kwargs_index():
|
|||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
root = OptionDescription('root', '', [interface1])
|
||||
cfg = Config(root)
|
||||
assert cfg.ip_admin_eth0.ip_admin_eth0 == []
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append('val')
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0[0] = 'val1'
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append('val')
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0[1] = 'val2'
|
||||
api = getapi(Config(root))
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1')
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val2')
|
||||
|
||||
|
||||
def test_validator_params_context():
|
||||
opt1 = StrOption('opt1', '', validator=is_context, validator_params={'': ((None,),)}, default='val')
|
||||
root = OptionDescription('root', '', [opt1])
|
||||
cfg = Config(root)
|
||||
assert 'validator' in cfg.cfgimpl_get_settings()
|
||||
assert cfg.opt1 == 'val'
|
||||
assert 'validator' in cfg.cfgimpl_get_settings()
|
||||
api = getapi(Config(root))
|
||||
assert 'validator' in api.property.get()
|
||||
assert api.option('opt1').value.get() == 'val'
|
||||
assert 'validator' in api.property.get()
|
||||
|
||||
|
||||
def test_validator_params_context_value():
|
||||
opt1 = StrOption('opt1', '', 'yes')
|
||||
opt2 = StrOption('opt2', '', validator=valid_from_config, validator_params={'': ((None,),)}, default='val')
|
||||
root = OptionDescription('root', '', [opt1, opt2])
|
||||
cfg = Config(root)
|
||||
assert cfg.opt1 == 'yes'
|
||||
assert cfg.opt2 == 'val'
|
||||
cfg.opt1 = 'no'
|
||||
raises(ValueError, "cfg.opt2")
|
||||
api = getapi(Config(root))
|
||||
assert api.option('opt1').value.get() == 'yes'
|
||||
assert api.option('opt2').value.get() == 'val'
|
||||
api.option('opt1').value.set('no')
|
||||
raises(ValueError, "assert api.option('opt2').value.get()")
|
||||
|
||||
|
||||
def test_validator_params_key():
|
||||
opt1 = StrOption('opt1', '', validator=return_true, validator_params={'param': ('yes',)}, default='val')
|
||||
raises(ConfigError, "StrOption('opt2', '', validator=return_true, validator_params={'param_unknown': ('yes',)}, default='val')")
|
||||
root = OptionDescription('root', '', [opt1])
|
||||
cfg = Config(root)
|
||||
assert cfg.opt1 == 'val'
|
||||
api = getapi(Config(root))
|
||||
assert api.option('opt1').value.get() == 'val'
|
||||
|
||||
|
||||
def test_validator_params_option():
|
||||
opt0 = StrOption('opt0', '', default='yes')
|
||||
opt1 = StrOption('opt1', '', validator=return_true, validator_params={'': ((opt0, False),)}, default='val')
|
||||
r = OptionDescription('root', '', [opt0, opt1])
|
||||
cfg = Config(r)
|
||||
cfg.opt1
|
||||
cfg.opt0 = 'val'
|
||||
raises(ValueError, "cfg.opt1")
|
||||
api = getapi(Config(r))
|
||||
assert api.option('opt1').value.get() == 'val'
|
||||
api.option('opt0').value.set('val')
|
||||
raises(ValueError, "api.option('opt1').value.get()")
|
||||
|
||||
|
||||
def test_validator_multi():
|
||||
opt1 = StrOption('opt1', '', validator=return_if_val, multi=True)
|
||||
root = OptionDescription('root', '', [opt1])
|
||||
cfg = Config(root)
|
||||
assert cfg.opt1 == []
|
||||
cfg.opt1.append('val')
|
||||
assert cfg.opt1 == ['val']
|
||||
raises(ValueError, "cfg.opt1.append('val1')")
|
||||
raises(ValueError, "cfg.opt1 = ['val', 'val1']")
|
||||
api = getapi(Config(root))
|
||||
assert api.option('opt1').value.get() == []
|
||||
api.option('opt1').value.set(['val'])
|
||||
assert api.option('opt1').value.get() == ['val']
|
||||
raises(ValueError, "api.option('opt1').value.set(['val', 'val1'])")
|
||||
|
||||
|
||||
def test_validator_warning():
|
||||
|
|
@ -334,38 +333,41 @@ def test_validator_warning():
|
|||
opt2 = StrOption('opt2', '', validator=return_false, warnings_only=True)
|
||||
opt3 = StrOption('opt3', '', validator=return_if_val, multi=True, warnings_only=True)
|
||||
root = OptionDescription('root', '', [opt1, opt2, opt3])
|
||||
cfg = Config(root)
|
||||
assert cfg.opt1 == 'val'
|
||||
api = getapi(Config(root))
|
||||
assert api.option('opt1').value.get() == 'val'
|
||||
warnings.simplefilter("always", ValueWarning)
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
cfg.opt1 = 'val'
|
||||
api.option('opt1').value.set('val')
|
||||
assert w == []
|
||||
#
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
cfg.opt2 = 'val'
|
||||
api.option('opt2').value.set('val')
|
||||
assert len(w) == 1
|
||||
assert w[0].message.opt == opt2
|
||||
assert str(w[0].message) == msg_err.format('val', opt2._display_name, 'opt2', 'test error')
|
||||
assert str(w[0].message) == msg_err.format('val', opt2._display_name, 'opt2', 'test error return_false')
|
||||
#
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
cfg.opt3.append('val')
|
||||
api.option('opt3').value.set(['val'])
|
||||
assert w == []
|
||||
#
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
cfg.opt3.append('val1')
|
||||
api.option('opt3').value.set(['val', 'val1'])
|
||||
assert len(w) == 1
|
||||
assert w[0].message.opt == opt3
|
||||
assert str(w[0].message) == msg_err.format('val1', opt3._display_name, 'opt3', 'test error')
|
||||
raises(ValueError, "cfg.opt2 = 1")
|
||||
#
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
cfg.opt2 = 'val'
|
||||
cfg.opt3.append('val')
|
||||
raises(ValueError, "api.option('opt2').value.set(1)")
|
||||
assert len(w) == 0
|
||||
#
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('opt2').value.set('val')
|
||||
api.option('opt3').value.set(['val', 'val1', 'val'])
|
||||
assert len(w) == 2
|
||||
assert w[0].message.opt == opt2
|
||||
assert str(w[0].message) == msg_err.format('val', opt2._display_name, 'opt2', 'test error')
|
||||
assert str(w[0].message) == msg_err.format('val', opt2._display_name, 'opt2', 'test error return_false')
|
||||
assert w[1].message.opt == opt3
|
||||
assert str(w[0].message) == msg_err.format('val', opt2._display_name, 'opt2', 'test error')
|
||||
assert str(w[1].message) == msg_err.format('val1', opt3._display_name, 'opt3', 'test error')
|
||||
|
||||
|
||||
def test_validator_warning_disabled():
|
||||
|
|
@ -373,30 +375,30 @@ def test_validator_warning_disabled():
|
|||
opt2 = StrOption('opt2', '', validator=return_false, warnings_only=True)
|
||||
opt3 = StrOption('opt3', '', validator=return_if_val, multi=True, warnings_only=True)
|
||||
root = OptionDescription('root', '', [opt1, opt2, opt3])
|
||||
cfg = Config(root)
|
||||
cfg.cfgimpl_get_settings().remove('warnings')
|
||||
assert cfg.opt1 == 'val'
|
||||
api = getapi(Config(root))
|
||||
api.property.pop('warnings')
|
||||
assert api.option('opt1').value.get() == 'val'
|
||||
warnings.simplefilter("always", ValueWarning)
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
cfg.opt1 = 'val'
|
||||
api.option('opt1').value.set('val')
|
||||
assert w == []
|
||||
#
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
cfg.opt2 = 'val'
|
||||
api.option('opt2').value.set('val')
|
||||
assert w == []
|
||||
#
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
cfg.opt3.append('val')
|
||||
api.option('opt3').value.set(['val'])
|
||||
assert w == []
|
||||
#
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
cfg.opt3.append('val1')
|
||||
api.option('opt3').value.set(['val', 'val1'])
|
||||
assert w == []
|
||||
raises(ValueError, "cfg.opt2 = 1")
|
||||
raises(ValueError, "api.option('opt2').value.set(1)")
|
||||
#
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
cfg.opt2 = 'val'
|
||||
cfg.opt3.append('val')
|
||||
api.option('opt2').value.set('val')
|
||||
api.option('opt3').value.set(['val', 'val1', 'val'])
|
||||
assert w == []
|
||||
|
||||
|
||||
|
|
@ -409,42 +411,45 @@ def test_validator_warning_master_slave():
|
|||
#interface1.impl_set_group_type(groups.master)
|
||||
assert interface1.impl_get_group_type() == groups.master
|
||||
root = OptionDescription('root', '', [interface1])
|
||||
cfg = Config(root)
|
||||
api = getapi(Config(root))
|
||||
warnings.simplefilter("always", ValueWarning)
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append(None)
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set([None])
|
||||
assert w == []
|
||||
#
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0 = ['val1']
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1')
|
||||
assert len(w) == 1
|
||||
assert w[0].message.opt == netmask_admin_eth0
|
||||
assert str(w[0].message) == msg_err.format('val1', netmask_admin_eth0._display_name, display_name_netmask, 'test error')
|
||||
#
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
cfg.ip_admin_eth0.ip_admin_eth0 = ['val']
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val'])
|
||||
assert len(w) == 1
|
||||
assert w[0].message.opt == ip_admin_eth0
|
||||
assert str(w[0].message) == msg_err.format('val', ip_admin_eth0._display_name, display_name_ip, 'test error')
|
||||
assert str(w[0].message) == msg_err.format('val', ip_admin_eth0._display_name, display_name_ip, 'test error return_false')
|
||||
#
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
cfg.ip_admin_eth0.ip_admin_eth0 = ['val', 'val1', 'val1']
|
||||
assert len(w) == 1
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val1', 'val1'])
|
||||
#FIXME
|
||||
#assert len(w) == 1
|
||||
assert w[0].message.opt == ip_admin_eth0
|
||||
assert str(w[0].message) == msg_err.format('val', ip_admin_eth0._display_name, display_name_ip, 'test error')
|
||||
assert str(w[0].message) == msg_err.format('val', ip_admin_eth0._display_name, display_name_ip, 'test error return_false')
|
||||
#
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
cfg.ip_admin_eth0.ip_admin_eth0 = ['val1', 'val', 'val1']
|
||||
assert len(w) == 1
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val', 'val1'])
|
||||
#FIXME
|
||||
#assert len(w) == 1
|
||||
assert w[0].message.opt == ip_admin_eth0
|
||||
assert str(w[0].message) == msg_err.format('val', ip_admin_eth0._display_name, display_name_ip, 'test error')
|
||||
assert str(w[0].message) == msg_err.format('val', ip_admin_eth0._display_name, display_name_ip, 'test error return_false')
|
||||
#
|
||||
warnings.resetwarnings()
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
cfg.ip_admin_eth0.ip_admin_eth0 = ['val1', 'val1', 'val']
|
||||
assert len(w) == 1
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val1', 'val'])
|
||||
#FIXME
|
||||
#assert len(w) == 1
|
||||
assert w[0].message.opt == ip_admin_eth0
|
||||
assert str(w[0].message) == msg_err.format('val', ip_admin_eth0._display_name, display_name_ip, 'test error')
|
||||
assert str(w[0].message) == msg_err.format('val', ip_admin_eth0._display_name, display_name_ip, 'test error return_false')
|
||||
|
||||
|
||||
def test_validator_slave_param():
|
||||
|
|
@ -457,12 +462,12 @@ def test_validator_slave_param():
|
|||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
root = OptionDescription('root', '', [interface1])
|
||||
cfg = Config(root)
|
||||
assert cfg.ip_admin_eth0.ip_admin_eth0 == []
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append('yes')
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0 = ['val']
|
||||
cfg.ip_admin_eth0.ip_admin_eth0 = ['yes', 'yes']
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0[1] = 'val'
|
||||
api = getapi(Config(root))
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['yes'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val')
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['yes', 'yes'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val')
|
||||
|
||||
|
||||
def test_validator_dependencies():
|
||||
|
|
@ -473,11 +478,11 @@ def test_validator_dependencies():
|
|||
validator_params={'param': ((ip_admin_eth0, False),)})
|
||||
opt2 = StrOption('opt2', '', validator=return_false)
|
||||
root = OptionDescription('root', '', [ip_admin_eth0, netmask_admin_eth0, opt2])
|
||||
cfg = Config(root)
|
||||
assert cfg.cfgimpl_get_description().ip_admin_eth0.impl_has_dependency() is False
|
||||
assert cfg.cfgimpl_get_description().netmask_admin_eth0.impl_has_dependency() is True
|
||||
assert cfg.cfgimpl_get_description().opt2.impl_has_dependency() is False
|
||||
api = getapi(Config(root))
|
||||
assert api.option('ip_admin_eth0').option.has_dependency() is False
|
||||
assert api.option('netmask_admin_eth0').option.has_dependency() is True
|
||||
assert api.option('opt2').option.has_dependency() is False
|
||||
#
|
||||
assert cfg.cfgimpl_get_description().ip_admin_eth0.impl_has_dependency(False) is True
|
||||
assert cfg.cfgimpl_get_description().netmask_admin_eth0.impl_has_dependency(False) is False
|
||||
assert cfg.cfgimpl_get_description().opt2.impl_has_dependency(False) is False
|
||||
assert api.option('ip_admin_eth0').option.has_dependency(False) is True
|
||||
assert api.option('netmask_admin_eth0').option.has_dependency(False) is False
|
||||
assert api.option('opt2').option.has_dependency(False) is False
|
||||
|
|
|
|||
|
|
@ -4,9 +4,8 @@ do_autopath()
|
|||
|
||||
from py.test import raises
|
||||
|
||||
from tiramisu.config import Config
|
||||
from tiramisu.option import BoolOption, OptionDescription, ChoiceOption,\
|
||||
IntOption, FloatOption, StrOption
|
||||
from tiramisu import BoolOption, OptionDescription, ChoiceOption,\
|
||||
IntOption, FloatOption, StrOption, Config, getapi
|
||||
|
||||
|
||||
def make_description():
|
||||
|
|
@ -37,11 +36,12 @@ def test_root_config_answers_ok():
|
|||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
|
||||
descr = OptionDescription('tiramisu', '', [gcdummy, boolop])
|
||||
cfg = Config(descr)
|
||||
settings = cfg.cfgimpl_get_settings()
|
||||
settings.append('hidden')
|
||||
assert cfg.dummy is False
|
||||
assert cfg.boolop is True
|
||||
api = getapi(Config(descr))
|
||||
#settings = cfg.cfgimpl_get_settings()
|
||||
#settings.append('hidden')
|
||||
|
||||
assert api.option('dummy').value.get() is False
|
||||
assert api.option('boolop').value.get() is True
|
||||
|
||||
|
||||
def test_optname_shall_not_start_with_numbers():
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@ from .autopath import do_autopath
|
|||
do_autopath()
|
||||
|
||||
from tiramisu.setting import groups, owners
|
||||
from tiramisu.config import Config
|
||||
from tiramisu.option import ChoiceOption, BoolOption, IntOption, \
|
||||
StrOption, OptionDescription, MasterSlaves
|
||||
from tiramisu.error import SlaveError, PropertiesOptionError
|
||||
from tiramisu import ChoiceOption, BoolOption, IntOption, \
|
||||
StrOption, OptionDescription, MasterSlaves, Config, getapi
|
||||
from tiramisu.error import SlaveError, PropertiesOptionError, APIError, ConfigError
|
||||
from tiramisu.api import TIRAMISU_VERSION
|
||||
|
||||
from py.test import raises
|
||||
|
||||
|
|
@ -48,28 +48,28 @@ def make_description():
|
|||
|
||||
def test_base_config():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
config.read_write()
|
||||
assert config.creole.general.activer_proxy_client is False
|
||||
assert config.creole.general.nom_machine == "eoleng"
|
||||
assert config.find_first(byname='nom_machine', type_='value') == "eoleng"
|
||||
api = getapi(Config(descr))
|
||||
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_first('nom_machine', type='value') == "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',
|
||||
'interface1.ip_admin_eth0.netmask_admin_eth0': None, 'general.nom_machine':
|
||||
'eoleng', 'general.activer_proxy_client': False}
|
||||
assert config.creole.make_dict() == result
|
||||
assert api.option('creole').make_dict() == result
|
||||
result = {'serveur_ntp': [], 'mode_conteneur_actif': False,
|
||||
'ip_admin_eth0': None, 'time_zone': 'Paris', 'numero_etab': None,
|
||||
'netmask_admin_eth0': None, 'nom_machine': 'eoleng', 'activer_proxy_client':
|
||||
False, 'nombre_interfaces': 1}
|
||||
assert config.creole.make_dict(flatten=True) == result
|
||||
assert api.option('creole').make_dict(flatten=True) == result
|
||||
|
||||
|
||||
def test_make_dict_filter():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
config.read_write()
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
subresult = {'numero_etab': None, 'nombre_interfaces': 1,
|
||||
'serveur_ntp': [], 'mode_conteneur_actif': False,
|
||||
'time_zone': 'Paris', 'nom_machine': 'eoleng',
|
||||
|
|
@ -77,88 +77,82 @@ def test_make_dict_filter():
|
|||
result = {}
|
||||
for key, value in subresult.items():
|
||||
result['general.' + key] = value
|
||||
assert config.creole.make_dict(withoption='numero_etab') == result
|
||||
raises(AttributeError, "config.creole.make_dict(withoption='numero_etab', withvalue='toto')")
|
||||
assert config.creole.make_dict(withoption='numero_etab', withvalue=None) == result
|
||||
assert config.creole.general.make_dict(withoption='numero_etab') == subresult
|
||||
assert api.option('creole').make_dict(withoption='numero_etab') == result
|
||||
raises(AttributeError, "api.option('creole').make_dict(withoption='numero_etab', withvalue='toto')")
|
||||
assert api.option('creole').make_dict(withoption='numero_etab', withvalue=None) == result
|
||||
assert api.option('creole.general').make_dict(withoption='numero_etab') == subresult
|
||||
|
||||
|
||||
def test_get_group_type():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
config.read_write()
|
||||
grp = config.unwrap_from_path('creole.general')
|
||||
assert grp.impl_get_group_type() == groups.family
|
||||
assert grp.impl_get_group_type() == 'family'
|
||||
assert isinstance(grp.impl_get_group_type(), groups.GroupType)
|
||||
raises(TypeError, 'grp.impl_set_group_type(groups.default)')
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
grp = api.option('creole.general')
|
||||
assert grp.group_type() == groups.family
|
||||
assert grp.group_type() == 'family'
|
||||
assert isinstance(grp.group_type(), groups.GroupType)
|
||||
#raises(TypeError, 'grp.impl_set_group_type(groups.default)')
|
||||
|
||||
|
||||
def test_iter_on_groups():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
config.read_write()
|
||||
result = list(config.creole.iter_groups(group_type=groups.family))
|
||||
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]
|
||||
assert group_names == ['general', 'interface1']
|
||||
for i in config.creole.iter_groups(group_type=groups.family):
|
||||
for i in api.option('creole').list('optiondescription', group_type=groups.family):
|
||||
#test StopIteration
|
||||
break
|
||||
|
||||
|
||||
def test_iter_on_groups_force_permissive():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
config.read_write()
|
||||
config.cfgimpl_get_settings().setpermissive(('hidden',))
|
||||
result = list(config.creole.general.__iter__(force_permissive=True))
|
||||
group_names = [res[0] for res in result]
|
||||
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())
|
||||
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 = [res[0] for res in config.creole.general]
|
||||
group_names = list(api.option('creole.general').list())
|
||||
ass.remove('mode_conteneur_actif2')
|
||||
assert group_names == ass
|
||||
|
||||
|
||||
def test_iter_group_on_groups_force_permissive():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
config.read_write()
|
||||
config.cfgimpl_get_settings().setpermissive(('hidden',))
|
||||
result = list(config.creole.iter_groups(group_type=groups.family,
|
||||
force_permissive=True))
|
||||
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]
|
||||
assert group_names == ['general', 'interface1', 'new']
|
||||
|
||||
|
||||
def test_iter_on_groups_props():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
config.read_write()
|
||||
config.cfgimpl_get_settings()[descr.creole.interface1].append('disabled')
|
||||
result = list(config.creole.iter_groups(group_type=groups.family))
|
||||
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]
|
||||
assert group_names == ['general']
|
||||
|
||||
|
||||
def test_iter_on_empty_group():
|
||||
config = Config(OptionDescription("name", "descr", []))
|
||||
config.read_write()
|
||||
result = list(config.iter_groups())
|
||||
api = getapi(Config(OptionDescription("name", "descr", [])))
|
||||
api.property.read_write()
|
||||
result = list(api.option.list(type='optiondescription'))
|
||||
assert result == []
|
||||
for i in config.iter_groups():
|
||||
pass
|
||||
for i in config:
|
||||
pass
|
||||
assert [] == list(config)
|
||||
|
||||
|
||||
def test_iter_not_group():
|
||||
config = Config(OptionDescription("name", "descr", []))
|
||||
config.read_write()
|
||||
raises(TypeError, "list(config.iter_groups(group_type='family'))")
|
||||
api = getapi(Config(OptionDescription("name", "descr", [])))
|
||||
api.property.read_write()
|
||||
raises(TypeError, "list(api.option.list(type='optiondescription', group_type='family'))")
|
||||
|
||||
|
||||
def test_groups_with_master():
|
||||
|
|
@ -169,12 +163,20 @@ def test_groups_with_master():
|
|||
assert interface1.impl_get_group_type() == groups.master
|
||||
|
||||
|
||||
if TIRAMISU_VERSION != 2:
|
||||
def test_groups_with_master_in_root():
|
||||
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)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
raises(ConfigError, "Config(interface1)")
|
||||
|
||||
|
||||
def test_groups_with_master_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)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
Config(interface1)
|
||||
od = OptionDescription('root', '', [interface1])
|
||||
Config(od)
|
||||
assert interface1.impl_get_group_type() == groups.master
|
||||
|
||||
|
||||
|
|
@ -182,45 +184,42 @@ def test_groups_with_master_hidden_in_config():
|
|||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True, properties=('hidden',))
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, properties=('hidden',))
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
cfg = Config(interface1)
|
||||
cfg.read_write()
|
||||
cfg.cfgimpl_get_settings().setpermissive(('hidden',))
|
||||
cfg.getattr('ip_admin_eth0', force_permissive=True)
|
||||
cfg.getattr('netmask_admin_eth0', force_permissive=True)
|
||||
raises(PropertiesOptionError, "cfg.getattr('ip_admin_eth0')")
|
||||
raises(PropertiesOptionError, "cfg.getattr('netmask_admin_eth0')")
|
||||
od = OptionDescription('root', '', [interface1])
|
||||
api = getapi(Config(od))
|
||||
api.property.read_write()
|
||||
api.permissive.set(frozenset(['hidden']))
|
||||
assert api.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
api.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
|
||||
assert api.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()")
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
|
||||
|
||||
|
||||
def test_groups_with_master_hidden_in_config2():
|
||||
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 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
cfg = Config(interface1)
|
||||
cfg.read_write()
|
||||
cfg.cfgimpl_get_settings().setpermissive(('hidden',))
|
||||
cfg.getattr('ip_admin_eth0', force_permissive=True)
|
||||
cfg.getattr('netmask_admin_eth0', force_permissive=True)
|
||||
cfg.getattr('ip_admin_eth0')
|
||||
raises(PropertiesOptionError, "cfg.getattr('netmask_admin_eth0')")
|
||||
cfg.ip_admin_eth0.append('192.168.1.1')
|
||||
assert cfg.ip_admin_eth0 == ['192.168.1.1']
|
||||
raises(PropertiesOptionError, "cfg.netmask_admin_eth0[0]")
|
||||
del(cfg.ip_admin_eth0)
|
||||
assert cfg.ip_admin_eth0 == []
|
||||
od = OptionDescription('root', '', [interface1])
|
||||
api = getapi(Config(od))
|
||||
api.property.read_write()
|
||||
api.permissive.set(frozenset(['hidden']))
|
||||
assert api.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
api.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
|
||||
assert api.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
#del
|
||||
cfg.ip_admin_eth0.append('192.168.1.1')
|
||||
assert cfg.ip_admin_eth0 == ['192.168.1.1']
|
||||
cfg.cfgimpl_get_settings().remove('hidden')
|
||||
assert cfg.netmask_admin_eth0 == [None]
|
||||
cfg.netmask_admin_eth0 = ['255.255.255.0']
|
||||
assert cfg.netmask_admin_eth0 == ['255.255.255.0']
|
||||
cfg.cfgimpl_get_settings().append('hidden')
|
||||
del(cfg.ip_admin_eth0)
|
||||
cfg.ip_admin_eth0.append('192.168.1.1')
|
||||
cfg.cfgimpl_get_settings().remove('hidden')
|
||||
assert cfg.netmask_admin_eth0 == [None]
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
|
||||
api.property.pop('hidden')
|
||||
assert api.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
api.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
|
||||
assert api.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
|
||||
api.property.add('hidden')
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
|
||||
api.property.pop('hidden')
|
||||
assert api.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
|
||||
|
||||
def test_groups_with_master_hidden_in_config3():
|
||||
|
|
@ -228,14 +227,16 @@ def test_groups_with_master_hidden_in_config3():
|
|||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True, properties=('hidden',))
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
od = OptionDescription('root', '', [interface1])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
cfg = Config(interface1)
|
||||
cfg.read_write()
|
||||
cfg.cfgimpl_get_settings().setpermissive(('hidden',))
|
||||
cfg.getattr('ip_admin_eth0', force_permissive=True)
|
||||
cfg.getattr('netmask_admin_eth0', force_permissive=True)
|
||||
raises(PropertiesOptionError, "cfg.getattr('ip_admin_eth0')")
|
||||
raises(PropertiesOptionError, "cfg.getattr('netmask_admin_eth0')")
|
||||
api = getapi(Config(od))
|
||||
api.property.read_write()
|
||||
api.permissive.set(frozenset(['hidden']))
|
||||
assert api.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
api.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
|
||||
assert api.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()")
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
|
||||
|
||||
|
||||
def test_allowed_groups():
|
||||
|
|
@ -252,37 +253,15 @@ def test_values_with_master_disabled_master():
|
|||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
cfg.read_write()
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.pop(0)
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0 = ["192.168.230.145"]
|
||||
del(cfg.ip_admin_eth0.netmask_admin_eth0)
|
||||
cfg.cfgimpl_get_settings()[ip_admin_eth0].append('disabled')
|
||||
raises(PropertiesOptionError, "cfg.ip_admin_eth0.netmask_admin_eth0[0] = '192.168.230.145'")
|
||||
|
||||
|
||||
def test_values_with_master_remove():
|
||||
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)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
cfg.read_write()
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append('192.168.230.145')
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.remove('192.168.230.145')
|
||||
raises(ValueError, "cfg.ip_admin_eth0.ip_admin_eth0.remove('192.168.230.14')")
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append('192.168.230.15')
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0[-1] = '255.255.255.0'
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append('192.168.230.16')
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0[-1] = '255.255.255.128'
|
||||
assert cfg.ip_admin_eth0.ip_admin_eth0 == ['192.168.230.15', '192.168.230.16']
|
||||
assert cfg.ip_admin_eth0.netmask_admin_eth0 == ['255.255.255.0', '255.255.255.128']
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.remove('192.168.230.15')
|
||||
assert cfg.ip_admin_eth0.ip_admin_eth0 == ['192.168.230.16']
|
||||
assert cfg.ip_admin_eth0.netmask_admin_eth0 == ['255.255.255.128']
|
||||
api = getapi(Config(maconfig))
|
||||
api.property.read_write()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set("192.168.230.145")
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').property.add('disabled')
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('192.168.230.145')")
|
||||
|
||||
|
||||
def test_sub_group_in_master_group():
|
||||
|
|
@ -305,21 +284,20 @@ def test_values_with_master_and_slaves():
|
|||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
cfg.read_write()
|
||||
owner = cfg.cfgimpl_get_settings().getowner()
|
||||
api = getapi(Config(maconfig))
|
||||
api.property.read_write()
|
||||
owner = api.owner.get()
|
||||
assert interface1.impl_get_group_type() == groups.master
|
||||
assert cfg.getowner(ip_admin_eth0) == owners.default
|
||||
assert cfg.getowner(netmask_admin_eth0) == owners.default
|
||||
assert cfg.ip_admin_eth0.netmask_admin_eth0 == []
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
|
||||
assert cfg.ip_admin_eth0.ip_admin_eth0 == ["192.168.230.145"]
|
||||
assert cfg.ip_admin_eth0.netmask_admin_eth0 == [None]
|
||||
assert cfg.getowner(ip_admin_eth0) == owner
|
||||
assert cfg.getowner(netmask_admin_eth0) == owners.default
|
||||
cfg.ip_admin_eth0.ip_admin_eth0 = ["192.168.230.145", "192.168.230.147"]
|
||||
raises(SlaveError, 'cfg.ip_admin_eth0.netmask_admin_eth0.append(None)')
|
||||
raises(SlaveError, 'cfg.ip_admin_eth0.netmask_admin_eth0.pop(0)')
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
|
||||
#
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ["192.168.230.145"]
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", "192.168.230.147"])
|
||||
raises(APIError, "api.option('ip_admin_eth0.netmask_admin_eth0').value.set([None])")
|
||||
raises(APIError, "api.option('ip_admin_eth0.netmask_admin_eth0').value.pop(0)")
|
||||
|
||||
|
||||
def test_reset_values_with_master_and_slaves():
|
||||
|
|
@ -328,27 +306,22 @@ def test_reset_values_with_master_and_slaves():
|
|||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
cfg.read_write()
|
||||
owner = cfg.cfgimpl_get_settings().getowner()
|
||||
api = getapi(Config(maconfig))
|
||||
api.property.read_write()
|
||||
owner = api.owner.get()
|
||||
assert interface1.impl_get_group_type() == groups.master
|
||||
assert cfg.getowner(ip_admin_eth0) == owners.default
|
||||
assert cfg.getowner(netmask_admin_eth0) == owners.default
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
|
||||
assert cfg.getowner(ip_admin_eth0) == owner
|
||||
assert cfg.getowner(netmask_admin_eth0) == owners.default
|
||||
del(cfg.ip_admin_eth0.ip_admin_eth0)
|
||||
assert cfg.getowner(ip_admin_eth0) == owners.default
|
||||
assert cfg.getowner(netmask_admin_eth0) == owners.default
|
||||
assert cfg.ip_admin_eth0.ip_admin_eth0 == []
|
||||
assert cfg.ip_admin_eth0.netmask_admin_eth0 == []
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
#reset
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
|
||||
cfg.cfgimpl_get_values().reset(ip_admin_eth0)
|
||||
assert cfg.getowner(ip_admin_eth0) == owners.default
|
||||
assert cfg.getowner(netmask_admin_eth0) == owners.default
|
||||
assert cfg.ip_admin_eth0.ip_admin_eth0 == []
|
||||
assert cfg.ip_admin_eth0.netmask_admin_eth0 == []
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
|
||||
|
||||
def test_reset_values_with_master_and_slaves_default_value():
|
||||
|
|
@ -363,68 +336,39 @@ def test_reset_values_with_master_and_slaves_default():
|
|||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
cfg.read_write()
|
||||
owner = cfg.cfgimpl_get_settings().getowner()
|
||||
assert cfg.getowner(ip_admin_eth0) == owners.default
|
||||
assert cfg.getowner(netmask_admin_eth0) == owners.default
|
||||
api = getapi(Config(maconfig))
|
||||
api.property.read_write()
|
||||
owner = api.owner.get()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
|
||||
|
||||
cfg.ip_admin_eth0.ip_admin_eth0[0] = "192.168.230.146"
|
||||
assert cfg.getowner(ip_admin_eth0) == owner
|
||||
assert cfg.getowner(netmask_admin_eth0) == owners.default
|
||||
del(cfg.ip_admin_eth0.ip_admin_eth0)
|
||||
assert cfg.getowner(ip_admin_eth0) == owners.default
|
||||
assert cfg.getowner(netmask_admin_eth0) == owners.default
|
||||
assert cfg.ip_admin_eth0.ip_admin_eth0 == ['192.168.230.145']
|
||||
assert cfg.ip_admin_eth0.netmask_admin_eth0 == [None]
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.146'])
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.230.145']
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(None)
|
||||
|
||||
cfg.ip_admin_eth0.ip_admin_eth0[0] = "192.168.230.146"
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0[0] = "255.255.255.0"
|
||||
assert cfg.getowner(ip_admin_eth0) == owner
|
||||
assert cfg.getowner(netmask_admin_eth0, 0) == owner
|
||||
del(cfg.ip_admin_eth0.ip_admin_eth0)
|
||||
assert cfg.getowner(ip_admin_eth0) == owners.default
|
||||
assert cfg.getowner(netmask_admin_eth0, 0) == owners.default
|
||||
assert cfg.ip_admin_eth0.ip_admin_eth0 == ['192.168.230.145']
|
||||
assert cfg.ip_admin_eth0.netmask_admin_eth0 == [None]
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.146'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owner
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.default
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.230.145']
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(None)
|
||||
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0[0] = "255.255.255.0"
|
||||
assert cfg.getowner(ip_admin_eth0) == owners.default
|
||||
assert cfg.getowner(netmask_admin_eth0, 0) == owner
|
||||
del(cfg.ip_admin_eth0.ip_admin_eth0)
|
||||
assert cfg.getowner(ip_admin_eth0) == owners.default
|
||||
assert cfg.getowner(netmask_admin_eth0) == owners.default
|
||||
assert cfg.ip_admin_eth0.ip_admin_eth0 == ['192.168.230.145']
|
||||
assert cfg.ip_admin_eth0.netmask_admin_eth0 == [None]
|
||||
|
||||
|
||||
def test_reset_values_with_master_and_slaves_setitem():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True, default=['192.168.230.145'])
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
cfg.read_write()
|
||||
owner = cfg.cfgimpl_get_settings().getowner()
|
||||
assert cfg.getowner(ip_admin_eth0) == owners.default
|
||||
assert cfg.getowner(netmask_admin_eth0) == owners.default
|
||||
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.146")
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.146")
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.146")
|
||||
assert cfg.ip_admin_eth0.netmask_admin_eth0[-1] == None
|
||||
assert cfg.ip_admin_eth0.netmask_admin_eth0[3] == None
|
||||
assert cfg.getowner(netmask_admin_eth0, 3) == owners.default
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0[-1] = "255.255.255.0"
|
||||
assert cfg.ip_admin_eth0.netmask_admin_eth0[-1] == "255.255.255.0"
|
||||
assert cfg.ip_admin_eth0.netmask_admin_eth0[3] == "255.255.255.0"
|
||||
assert cfg.getowner(netmask_admin_eth0, 3) == owner
|
||||
#
|
||||
assert cfg.getowner(netmask_admin_eth0, 2) == owners.default
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0[2] = "255.255.0.0"
|
||||
assert cfg.ip_admin_eth0.netmask_admin_eth0[-2] == "255.255.0.0"
|
||||
assert cfg.getowner(netmask_admin_eth0, 2) == owner
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owner
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.230.145']
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(None)
|
||||
|
||||
|
||||
def test_values_with_master_and_slaves_slave():
|
||||
|
|
@ -433,26 +377,27 @@ def test_values_with_master_and_slaves_slave():
|
|||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
cfg.read_write()
|
||||
assert cfg.ip_admin_eth0.netmask_admin_eth0 == []
|
||||
raises(SlaveError, "cfg.ip_admin_eth0.netmask_admin_eth0 = ['255.255.255.0']")
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0 = ['255.255.255.0']
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0[0] = '255.255.255.0'
|
||||
raises(SlaveError, "cfg.ip_admin_eth0.netmask_admin_eth0 = ['255.255.255.0', '255.255.255.0']")
|
||||
raises(SlaveError, "cfg.ip_admin_eth0.netmask_admin_eth0 = []")
|
||||
del(cfg.ip_admin_eth0.netmask_admin_eth0)
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0 = ['255.255.255.0']
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
|
||||
assert cfg.ip_admin_eth0.netmask_admin_eth0 == ['255.255.255.0', None]
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0 = ['255.255.255.0', '255.255.255.0']
|
||||
raises(SlaveError, 'cfg.ip_admin_eth0.netmask_admin_eth0.pop(1)')
|
||||
api = getapi(Config(maconfig))
|
||||
api.property.read_write()
|
||||
raises(SlaveError,
|
||||
"api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')")
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset()
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
|
||||
#
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145', '192.168.230.145'])
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() is None
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.0')
|
||||
raises(APIError, "api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.pop(1)")
|
||||
#reset
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
|
||||
cfg.cfgimpl_get_values().reset(ip_admin_eth0)
|
||||
assert cfg.ip_admin_eth0.ip_admin_eth0 == []
|
||||
assert cfg.ip_admin_eth0.netmask_admin_eth0 == []
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145',
|
||||
'192.168.230.145',
|
||||
'192.168.230.145'])
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
|
||||
|
||||
def test_values_with_master_and_slaves_pop():
|
||||
|
|
@ -461,18 +406,18 @@ def test_values_with_master_and_slaves_pop():
|
|||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
cfg.read_write()
|
||||
assert cfg.ip_admin_eth0.netmask_admin_eth0 == []
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0 = ['255.255.255.0']
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.146")
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0[1] = '255.255.0.0'
|
||||
assert cfg.ip_admin_eth0.ip_admin_eth0 == ['192.168.230.145', '192.168.230.146']
|
||||
assert cfg.ip_admin_eth0.netmask_admin_eth0 == ['255.255.255.0', '255.255.0.0']
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.pop(0)
|
||||
assert cfg.ip_admin_eth0.ip_admin_eth0 == ['192.168.230.146']
|
||||
assert cfg.ip_admin_eth0.netmask_admin_eth0 == ['255.255.0.0']
|
||||
api = getapi(Config(maconfig))
|
||||
api.property.read_write()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145', '192.168.230.146'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.0.0')
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.230.145', '192.168.230.146']
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.0.0'
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.230.146']
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0'
|
||||
|
||||
|
||||
def test_values_with_master_and_slaves_master():
|
||||
|
|
@ -481,20 +426,21 @@ def test_values_with_master_and_slaves_master():
|
|||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
cfg.read_write()
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
|
||||
cfg.ip_admin_eth0.ip_admin_eth0 = ["192.168.230.145"]
|
||||
cfg.ip_admin_eth0.ip_admin_eth0 = ["192.168.230.145", "192.168.230.145"]
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0 = ['255.255.255.0', '255.255.255.0']
|
||||
raises(SlaveError, 'cfg.ip_admin_eth0.ip_admin_eth0 = ["192.168.230.145"]')
|
||||
assert cfg.ip_admin_eth0.netmask_admin_eth0 == ['255.255.255.0', '255.255.255.0']
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.pop(1)
|
||||
assert cfg.ip_admin_eth0.ip_admin_eth0 == ["192.168.230.145"]
|
||||
assert cfg.ip_admin_eth0.netmask_admin_eth0 == ['255.255.255.0']
|
||||
del(cfg.ip_admin_eth0.ip_admin_eth0)
|
||||
assert cfg.ip_admin_eth0.ip_admin_eth0 == []
|
||||
assert cfg.ip_admin_eth0.netmask_admin_eth0 == []
|
||||
api = getapi(Config(maconfig))
|
||||
api.property.read_write()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", "192.168.230.145"])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.0')
|
||||
raises(SlaveError, "api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])")
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.0'
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(1)
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ["192.168.230.145"]
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
|
||||
|
||||
def test_values_with_master_and_slaves_master_pop():
|
||||
|
|
@ -502,85 +448,64 @@ def test_values_with_master_and_slaves_master_pop():
|
|||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
cfg.read_write()
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.146")
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0[1] = '255.255.0.0'
|
||||
assert cfg.ip_admin_eth0.ip_admin_eth0 == ["192.168.230.145", "192.168.230.146"]
|
||||
assert cfg.ip_admin_eth0.netmask_admin_eth0 == [None, '255.255.0.0']
|
||||
assert cfg.cfgimpl_get_values().get_modified_values() == {'ip_admin_eth0.ip_admin_eth0': (
|
||||
api = getapi(Config(maconfig))
|
||||
api.property.read_write()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", "192.168.230.146"])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.0.0')
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ["192.168.230.145", "192.168.230.146"]
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.0.0'
|
||||
assert api.value.get_modified() == {'ip_admin_eth0.ip_admin_eth0': (
|
||||
'user',
|
||||
('192.168.230.145', '192.168.230.146')),
|
||||
'ip_admin_eth0.netmask_admin_eth0': (
|
||||
{'1': 'user'},
|
||||
{'1': '255.255.0.0'})}
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.pop(0)
|
||||
assert cfg.cfgimpl_get_values().get_modified_values() == {'ip_admin_eth0.ip_admin_eth0': (
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
|
||||
assert api.value.get_modified() == {'ip_admin_eth0.ip_admin_eth0': (
|
||||
'user',
|
||||
('192.168.230.146',)),
|
||||
'ip_admin_eth0.netmask_admin_eth0': (
|
||||
{'0': 'user'},
|
||||
{'0': '255.255.0.0'})}
|
||||
assert cfg.ip_admin_eth0.ip_admin_eth0 == ["192.168.230.146"]
|
||||
assert cfg.ip_admin_eth0.netmask_admin_eth0 == ['255.255.0.0']
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.146")
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.147")
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.148")
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.149")
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0[3] = '255.255.0.0'
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0[4] = '255.255.0.0'
|
||||
assert cfg.cfgimpl_get_values().get_modified_values() == {'ip_admin_eth0.ip_admin_eth0': (
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ["192.168.230.146"]
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0'
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.146', "192.168.230.145", "192.168.230.146", "192.168.230.147", "192.168.230.148", "192.168.230.149"])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 3).value.set('255.255.0.0')
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 4).value.set('255.255.0.0')
|
||||
assert api.value.get_modified() == {'ip_admin_eth0.ip_admin_eth0': (
|
||||
'user',
|
||||
('192.168.230.146', "192.168.230.145", "192.168.230.146", "192.168.230.147", "192.168.230.148", "192.168.230.149")),
|
||||
'ip_admin_eth0.netmask_admin_eth0': (
|
||||
{'0': 'user', '3': 'user', '4': 'user'},
|
||||
{'0': '255.255.0.0', '3': '255.255.0.0', '4': '255.255.0.0'})}
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.pop(5)
|
||||
assert cfg.cfgimpl_get_values().get_modified_values() == {'ip_admin_eth0.ip_admin_eth0': (
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(5)
|
||||
assert api.value.get_modified() == {'ip_admin_eth0.ip_admin_eth0': (
|
||||
'user',
|
||||
('192.168.230.146', "192.168.230.145", "192.168.230.146", "192.168.230.147", "192.168.230.148")),
|
||||
'ip_admin_eth0.netmask_admin_eth0': (
|
||||
{'0': 'user', '3': 'user', '4': 'user'},
|
||||
{'0': '255.255.0.0', '3': '255.255.0.0', '4': '255.255.0.0'})}
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.pop(2)
|
||||
assert cfg.cfgimpl_get_values().get_modified_values() == {'ip_admin_eth0.ip_admin_eth0': (
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(2)
|
||||
assert api.value.get_modified() == {'ip_admin_eth0.ip_admin_eth0': (
|
||||
'user',
|
||||
('192.168.230.146', "192.168.230.145", "192.168.230.147", "192.168.230.148")),
|
||||
'ip_admin_eth0.netmask_admin_eth0': (
|
||||
{'0': 'user', '2': 'user', '3': 'user'},
|
||||
{'0': '255.255.0.0', '2': '255.255.0.0', '3': '255.255.0.0'})}
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.pop(2)
|
||||
assert cfg.cfgimpl_get_values().get_modified_values() == {'ip_admin_eth0.ip_admin_eth0': (
|
||||
'user',
|
||||
('192.168.230.146', "192.168.230.145", "192.168.230.148")),
|
||||
'ip_admin_eth0.netmask_admin_eth0': (
|
||||
{'0': 'user', '2': 'user'},
|
||||
{'0': '255.255.0.0', '2': '255.255.0.0'})}
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.pop(2)
|
||||
assert cfg.cfgimpl_get_values().get_modified_values() == {'ip_admin_eth0.ip_admin_eth0': (
|
||||
'user',
|
||||
('192.168.230.146', "192.168.230.145")),
|
||||
'ip_admin_eth0.netmask_admin_eth0': (
|
||||
{'0': 'user'},
|
||||
{'0': '255.255.0.0'})}
|
||||
|
||||
|
||||
def test_values_with_master_and_slaves_master_error():
|
||||
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)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
cfg.read_write()
|
||||
cfg.ip_admin_eth0.ip_admin_eth0 = ["192.168.230.145", "192.168.230.145"]
|
||||
raises(SlaveError, "cfg.ip_admin_eth0.netmask_admin_eth0 = ['255.255.255.0']")
|
||||
raises(SlaveError, "cfg.ip_admin_eth0.netmask_admin_eth0 = ['255.255.255.0', '255.255.255.0', '255.255.255.0']")
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0 = ['255.255.255.0', '255.255.255.0']
|
||||
raises(SlaveError, "cfg.ip_admin_eth0.netmask_admin_eth0 = ['255.255.255.0']")
|
||||
raises(SlaveError, "cfg.ip_admin_eth0.netmask_admin_eth0 = ['255.255.255.0', '255.255.255.0', '255.255.255.0']")
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(2)
|
||||
assert api.value.get_modified() == {'ip_admin_eth0.ip_admin_eth0': ('user',
|
||||
('192.168.230.146',
|
||||
"192.168.230.145",
|
||||
"192.168.230.148")),
|
||||
'ip_admin_eth0.netmask_admin_eth0': ({'0': 'user', '2': 'user'},
|
||||
{'0': '255.255.0.0', '2': '255.255.0.0'})}
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(2)
|
||||
assert api.value.get_modified() == {'ip_admin_eth0.ip_admin_eth0': ('user',
|
||||
('192.168.230.146',
|
||||
"192.168.230.145")),
|
||||
'ip_admin_eth0.netmask_admin_eth0': ({'0': 'user'},
|
||||
{'0': '255.255.0.0'})}
|
||||
|
||||
|
||||
def test_values_with_master_owner():
|
||||
|
|
@ -589,17 +514,15 @@ def test_values_with_master_owner():
|
|||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
cfg.read_write()
|
||||
owner = cfg.cfgimpl_get_settings().getowner()
|
||||
assert cfg.getowner(ip_admin_eth0) == owners.default
|
||||
assert cfg.getowner(netmask_admin_eth0) == owners.default
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
|
||||
assert cfg.getowner(ip_admin_eth0) == owner
|
||||
assert cfg.getowner(netmask_admin_eth0) == owners.default
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.pop(0)
|
||||
assert cfg.getowner(ip_admin_eth0) == owner
|
||||
assert cfg.getowner(netmask_admin_eth0) == owners.default
|
||||
api = getapi(Config(maconfig))
|
||||
api.property.read_write()
|
||||
owner = api.owner.get()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
|
||||
|
||||
|
||||
def test_values_with_master_disabled():
|
||||
|
|
@ -608,138 +531,39 @@ def test_values_with_master_disabled():
|
|||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
cfg.read_write()
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.pop(0)
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0 = ["192.168.230.145"]
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.pop(0)
|
||||
del(cfg.ip_admin_eth0.netmask_admin_eth0)
|
||||
cfg.cfgimpl_get_settings()[netmask_admin_eth0].append('disabled')
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.pop(0)
|
||||
api = getapi(Config(maconfig))
|
||||
api.property.read_write()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set("192.168.230.145")
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0').property.add('disabled')
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
|
||||
|
||||
#delete with value in disabled var
|
||||
cfg.cfgimpl_get_settings()[netmask_admin_eth0].remove('disabled')
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0 = ["192.168.230.145"]
|
||||
cfg.cfgimpl_get_settings()[netmask_admin_eth0].append('disabled')
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.pop(0)
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0').property.pop('disabled')
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set("192.168.230.145")
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0').property.add('disabled')
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
|
||||
|
||||
#append with value in disabled var
|
||||
cfg.cfgimpl_get_settings()[netmask_admin_eth0].remove('disabled')
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0 = ["192.168.230.145"]
|
||||
cfg.cfgimpl_get_settings()[netmask_admin_eth0].append('disabled')
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append('192.168.230.43')
|
||||
|
||||
|
||||
def test_multi_insert():
|
||||
var = StrOption('var', '', ['ok'], multi=True)
|
||||
od = OptionDescription('od', '', [var])
|
||||
c = Config(od)
|
||||
c.read_write()
|
||||
assert c.var == ['ok']
|
||||
assert c.getowner(var) == owners.default
|
||||
c.var.insert(0, 'nok')
|
||||
assert c.var == ['nok', 'ok']
|
||||
assert c.getowner(var) != owners.default
|
||||
raises(ValueError, 'c.var.insert(0, 1)')
|
||||
|
||||
|
||||
def test_multi_insert_master():
|
||||
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)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
cfg.read_write()
|
||||
raises(SlaveError, "cfg.ip_admin_eth0.ip_admin_eth0.insert(0, 'nok')")
|
||||
raises(SlaveError, "cfg.ip_admin_eth0.netmask_admin_eth0.insert(0, 'nok')")
|
||||
|
||||
|
||||
def test_multi_sort():
|
||||
var = StrOption('var', '', ['ok', 'nok'], multi=True)
|
||||
od = OptionDescription('od', '', [var])
|
||||
c = Config(od)
|
||||
c.read_write()
|
||||
assert c.var == ['ok', 'nok']
|
||||
assert c.getowner(var) == owners.default
|
||||
c.var.sort()
|
||||
assert c.var == ['nok', 'ok']
|
||||
assert c.getowner(var) != owners.default
|
||||
|
||||
|
||||
def test_multi_sort_master():
|
||||
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)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
cfg.read_write()
|
||||
raises(SlaveError, "cfg.ip_admin_eth0.ip_admin_eth0.sort()")
|
||||
raises(SlaveError, "cfg.ip_admin_eth0.netmask_admin_eth0.sort()")
|
||||
|
||||
|
||||
def test_multi_reverse():
|
||||
var = StrOption('var', '', ['ok', 'nok'], multi=True)
|
||||
od = OptionDescription('od', '', [var])
|
||||
c = Config(od)
|
||||
c.read_write()
|
||||
assert c.var == ['ok', 'nok']
|
||||
assert c.getowner(var) == owners.default
|
||||
c.var.reverse()
|
||||
assert c.var == ['nok', 'ok']
|
||||
assert c.getowner(var) != owners.default
|
||||
|
||||
|
||||
def test_multi_reverse_master():
|
||||
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)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
cfg.read_write()
|
||||
raises(SlaveError, "cfg.ip_admin_eth0.ip_admin_eth0.reverse()")
|
||||
raises(SlaveError, "cfg.ip_admin_eth0.netmask_admin_eth0.reverse()")
|
||||
|
||||
|
||||
def test_multi_extend():
|
||||
var = StrOption('var', '', ['ok', 'nok'], multi=True)
|
||||
od = OptionDescription('od', '', [var])
|
||||
c = Config(od)
|
||||
c.read_write()
|
||||
assert c.var == ['ok', 'nok']
|
||||
assert c.getowner(var) == owners.default
|
||||
c.var.extend(['pok'])
|
||||
assert c.var == ['ok', 'nok', 'pok']
|
||||
assert c.getowner(var) != owners.default
|
||||
raises(ValueError, 'c.var.extend([1])')
|
||||
|
||||
|
||||
def test_multi_extend_master():
|
||||
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)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
cfg.read_write()
|
||||
raises(SlaveError, "cfg.ip_admin_eth0.ip_admin_eth0.extend(['ok'])")
|
||||
raises(SlaveError, "cfg.ip_admin_eth0.netmask_admin_eth0.extend(['ok'])")
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0').property.pop('disabled')
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set("192.168.230.145")
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0').property.add('disabled')
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", '192.168.230.43'])
|
||||
|
||||
|
||||
def test_multi_non_valid_value():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
|
||||
maconfig = OptionDescription('toto', '', [ip_admin_eth0])
|
||||
cfg = Config(maconfig)
|
||||
cfg.read_write()
|
||||
cfg.ip_admin_eth0 = ['a']
|
||||
raises(ValueError, 'cfg.ip_admin_eth0[0] = 1')
|
||||
api = getapi(Config(maconfig))
|
||||
api.property.read_write()
|
||||
api.option('ip_admin_eth0').value.set(['a'])
|
||||
raises(ValueError, "api.option('ip_admin_eth0').value.set([1])")
|
||||
|
||||
|
||||
def test_multi_master_default_slave():
|
||||
|
|
@ -748,11 +572,10 @@ def test_multi_master_default_slave():
|
|||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
cfg.read_write()
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append('192.168.1.1')
|
||||
cfg.cfgimpl_reset_cache()
|
||||
assert cfg.ip_admin_eth0.ip_admin_eth0 == ['192.168.1.1']
|
||||
api = getapi(Config(maconfig))
|
||||
api.property.read_write()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
|
||||
|
||||
|
||||
def test_groups_with_master_get_modified_value():
|
||||
|
|
@ -761,14 +584,13 @@ def test_groups_with_master_get_modified_value():
|
|||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
cfg.read_write()
|
||||
assert cfg.cfgimpl_get_values().get_modified_values() == {}
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append('192.168.1.1')
|
||||
cfg.cfgimpl_reset_cache()
|
||||
assert cfg.cfgimpl_get_values().get_modified_values() == {'ip_admin_eth0.ip_admin_eth0': ('user', ('192.168.1.1',))}
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0 = ['255.255.255.255']
|
||||
assert cfg.cfgimpl_get_values().get_modified_values() == {'ip_admin_eth0.ip_admin_eth0': ('user', ('192.168.1.1',)), 'ip_admin_eth0.netmask_admin_eth0': ({'0': 'user'}, {'0': '255.255.255.255'})}
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append('192.168.1.1')
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0[-1] = '255.255.255.255'
|
||||
assert cfg.cfgimpl_get_values().get_modified_values() == {'ip_admin_eth0.ip_admin_eth0': ('user', ('192.168.1.1', '192.168.1.1')), 'ip_admin_eth0.netmask_admin_eth0': ({'0': 'user', '1': 'user'}, {'0': '255.255.255.255', '1': '255.255.255.255'})}
|
||||
api = getapi(Config(maconfig))
|
||||
api.property.read_write()
|
||||
assert api.value.get_modified() == {}
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
|
||||
assert api.value.get_modified() == {'ip_admin_eth0.ip_admin_eth0': ('user', ('192.168.1.1',))}
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.255')
|
||||
assert api.value.get_modified() == {'ip_admin_eth0.ip_admin_eth0': ('user', ('192.168.1.1',)), 'ip_admin_eth0.netmask_admin_eth0': ({'0': 'user'}, {'0': '255.255.255.255'})}
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1', '192.168.1.1'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.255')
|
||||
assert api.value.get_modified() == {'ip_admin_eth0.ip_admin_eth0': ('user', ('192.168.1.1', '192.168.1.1')), 'ip_admin_eth0.netmask_admin_eth0': ({'0': 'user', '1': 'user'}, {'0': '255.255.255.255', '1': '255.255.255.255'})}
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@ do_autopath()
|
|||
|
||||
from py.test import raises
|
||||
|
||||
from tiramisu.option import IntOption, UnicodeOption, OptionDescription
|
||||
from tiramisu.config import Config
|
||||
from tiramisu import IntOption, UnicodeOption, OptionDescription, Config, getapi
|
||||
from tiramisu.error import PropertiesOptionError
|
||||
from tiramisu.api import TIRAMISU_VERSION
|
||||
|
||||
|
||||
def make_description():
|
||||
|
|
@ -17,257 +17,263 @@ def make_description():
|
|||
|
||||
def test_permissive():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
config.read_write()
|
||||
props = []
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
api.property.read_write()
|
||||
props = frozenset()
|
||||
try:
|
||||
config.u1
|
||||
api.option('u1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == ['disabled']
|
||||
setting.setpermissive(('disabled',))
|
||||
props = []
|
||||
assert set(props) == {'disabled'}
|
||||
api.permissive.set(frozenset(['disabled']))
|
||||
props = frozenset()
|
||||
try:
|
||||
config.u1
|
||||
api.option('u1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == ['disabled']
|
||||
setting.append('permissive')
|
||||
config.u1
|
||||
setting.remove('permissive')
|
||||
props = []
|
||||
assert set(props) == {'disabled'}
|
||||
api.property.add('permissive')
|
||||
api.option('u1').value.get()
|
||||
api.property.pop('permissive')
|
||||
props = frozenset()
|
||||
try:
|
||||
config.u1
|
||||
api.option('u1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == ['disabled']
|
||||
assert set(props) == {'disabled'}
|
||||
|
||||
|
||||
def test_permissive_mandatory():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
config.read_only()
|
||||
props = []
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_only()
|
||||
props = frozenset()
|
||||
try:
|
||||
config.u1
|
||||
api.option('u1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert set(props) == set(['disabled', 'mandatory'])
|
||||
setting.setpermissive(('mandatory', 'disabled',))
|
||||
setting.append('permissive')
|
||||
config.u1
|
||||
setting.remove('permissive')
|
||||
if TIRAMISU_VERSION == 2:
|
||||
assert frozenset(props) == frozenset(['disabled', 'mandatory'])
|
||||
else:
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
api.permissive.set(frozenset(['mandatory', 'disabled']))
|
||||
api.property.add('permissive')
|
||||
api.option('u1').value.get()
|
||||
api.property.pop('permissive')
|
||||
try:
|
||||
config.u1
|
||||
api.option('u1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert set(props) == set(['disabled', 'mandatory'])
|
||||
if TIRAMISU_VERSION == 2:
|
||||
assert frozenset(props) == frozenset(['disabled', 'mandatory'])
|
||||
else:
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_permissive_frozen():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
config.read_write()
|
||||
setting.setpermissive(('frozen', 'disabled',))
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
api.permissive.set(frozenset(['frozen', 'disabled']))
|
||||
try:
|
||||
config.u1 = 1
|
||||
api.option('u1').value.set(1)
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert set(props) == set(['frozen', 'disabled'])
|
||||
setting.append('permissive')
|
||||
config.u1 = 1
|
||||
assert config.u1 == 1
|
||||
setting.remove('permissive')
|
||||
if TIRAMISU_VERSION == 2:
|
||||
assert frozenset(props) == frozenset(['disabled', 'frozen'])
|
||||
else:
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
api.property.add('permissive')
|
||||
api.option('u1').value.set(1)
|
||||
assert api.option('u1').value.get() == 1
|
||||
api.property.pop('permissive')
|
||||
try:
|
||||
config.u1 = 1
|
||||
api.option('u1').value.set(1)
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert set(props) == set(['frozen', 'disabled'])
|
||||
if TIRAMISU_VERSION == 2:
|
||||
assert frozenset(props) == frozenset(['disabled', 'frozen'])
|
||||
else:
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_invalid_permissive():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
config.read_write()
|
||||
raises(TypeError, "setting.setpermissive(['frozen', 'disabled',])")
|
||||
if TIRAMISU_VERSION == 3:
|
||||
def test_invalid_permissive():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
raises(TypeError, "api.permissive.set(['frozen', 'disabled'])")
|
||||
|
||||
|
||||
def test_permissive_option():
|
||||
descr = make_description()
|
||||
u1 = descr.u1
|
||||
config = Config(descr)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
config.read_write()
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
|
||||
props = []
|
||||
props = frozenset()
|
||||
try:
|
||||
config.u1
|
||||
api.option('u1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == ['disabled']
|
||||
props = []
|
||||
assert set(props) == {'disabled'}
|
||||
props = frozenset()
|
||||
try:
|
||||
config.u2
|
||||
api.option('u2').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == ['disabled']
|
||||
assert set(props) == {'disabled'}
|
||||
|
||||
setting.setpermissive(('disabled',), u1)
|
||||
props = []
|
||||
api.option('u1').permissive.set(frozenset(['disabled']))
|
||||
props = frozenset()
|
||||
try:
|
||||
config.u1
|
||||
api.option('u1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == []
|
||||
props = []
|
||||
assert frozenset(props) == frozenset()
|
||||
props = frozenset()
|
||||
try:
|
||||
config.u2
|
||||
api.option('u2').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == ['disabled']
|
||||
assert set(props) == {'disabled'}
|
||||
|
||||
setting.append('permissive')
|
||||
config.u1
|
||||
props = []
|
||||
api.property.add('permissive')
|
||||
api.option('u1').value.get()
|
||||
props = frozenset()
|
||||
try:
|
||||
config.u2
|
||||
api.option('u2').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == ['disabled']
|
||||
assert set(props) == {'disabled'}
|
||||
|
||||
setting.remove('permissive')
|
||||
props = []
|
||||
api.property.pop('permissive')
|
||||
props = frozenset()
|
||||
try:
|
||||
config.u1
|
||||
api.option('u1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == []
|
||||
props = []
|
||||
assert frozenset(props) == frozenset()
|
||||
props = frozenset()
|
||||
try:
|
||||
config.u2
|
||||
api.option('u2').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == ['disabled']
|
||||
assert set(props) == {'disabled'}
|
||||
|
||||
|
||||
def test_permissive_option_cache():
|
||||
descr = make_description()
|
||||
u1 = descr.u1
|
||||
config = Config(descr)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
config.read_write()
|
||||
setting.remove('expire')
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
|
||||
props = []
|
||||
props = frozenset()
|
||||
try:
|
||||
config.u1
|
||||
api.option('u1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == ['disabled']
|
||||
props = []
|
||||
assert set(props) == {'disabled'}
|
||||
props = frozenset()
|
||||
try:
|
||||
config.u2
|
||||
api.option('u2').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == ['disabled']
|
||||
assert set(props) == {'disabled'}
|
||||
|
||||
setting.setpermissive(('disabled',), u1)
|
||||
props = []
|
||||
api.option('u1').permissive.set(frozenset(['disabled']))
|
||||
props = frozenset()
|
||||
try:
|
||||
config.u1
|
||||
api.option('u1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == []
|
||||
props = []
|
||||
assert frozenset(props) == frozenset()
|
||||
props = frozenset()
|
||||
try:
|
||||
config.u2
|
||||
api.option('u2').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == ['disabled']
|
||||
assert set(props) == {'disabled'}
|
||||
|
||||
setting.append('permissive')
|
||||
config.u1
|
||||
props = []
|
||||
api.property.add('permissive')
|
||||
api.option('u1').value.get()
|
||||
props = frozenset()
|
||||
try:
|
||||
config.u2
|
||||
api.option('u2').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == ['disabled']
|
||||
assert set(props) == {'disabled'}
|
||||
|
||||
setting.remove('permissive')
|
||||
props = []
|
||||
api.property.pop('permissive')
|
||||
props = frozenset()
|
||||
try:
|
||||
config.u1
|
||||
api.option('u1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == []
|
||||
props = []
|
||||
assert frozenset(props) == frozenset()
|
||||
props = frozenset()
|
||||
try:
|
||||
config.u2
|
||||
api.option('u2').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == ['disabled']
|
||||
assert set(props) == {'disabled'}
|
||||
|
||||
|
||||
def test_permissive_option_mandatory():
|
||||
descr = make_description()
|
||||
u1 = descr.u1
|
||||
config = Config(descr)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
config.read_only()
|
||||
props = []
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_only()
|
||||
props = frozenset()
|
||||
try:
|
||||
config.u1
|
||||
api.option('u1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert set(props) == set(['disabled', 'mandatory'])
|
||||
setting.setpermissive(('mandatory', 'disabled',), u1)
|
||||
setting.append('permissive')
|
||||
config.u1
|
||||
setting.remove('permissive')
|
||||
if TIRAMISU_VERSION == 2:
|
||||
assert frozenset(props) == frozenset(['disabled', 'mandatory'])
|
||||
else:
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
api.option('u1').permissive.set(frozenset(['mandatory', 'disabled']))
|
||||
api.property.add('permissive')
|
||||
api.option('u1').value.get()
|
||||
api.property.pop('permissive')
|
||||
try:
|
||||
config.u1
|
||||
api.option('u1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert set(props) == set(['disabled', 'mandatory'])
|
||||
if TIRAMISU_VERSION == 2:
|
||||
assert frozenset(props) == frozenset(['disabled', 'mandatory'])
|
||||
else:
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_permissive_option_frozen():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
u1 = descr.u1
|
||||
setting = config.cfgimpl_get_settings()
|
||||
config.read_write()
|
||||
setting.setpermissive(('frozen', 'disabled'), u1)
|
||||
config.u1 = 1
|
||||
assert config.u1 == 1
|
||||
setting.append('permissive')
|
||||
assert config.u1 == 1
|
||||
setting.remove('permissive')
|
||||
assert config.u1 == 1
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
api.option('u1').permissive.set(frozenset(['frozen', 'disabled']))
|
||||
api.option('u1').value.set(1)
|
||||
assert api.option('u1').value.get() == 1
|
||||
api.property.add('permissive')
|
||||
assert api.option('u1').value.get() == 1
|
||||
api.property.pop('permissive')
|
||||
assert api.option('u1').value.get() == 1
|
||||
|
||||
|
||||
def test_invalid_option_permissive():
|
||||
descr = make_description()
|
||||
u1 = descr.u1
|
||||
config = Config(descr)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
config.read_write()
|
||||
raises(TypeError, "setting.setpermissive(['frozen', 'disabled',], u1)")
|
||||
if TIRAMISU_VERSION == 3:
|
||||
def test_invalid_option_permissive():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
raises(TypeError, "api.option('u1').permissive.set(['frozen', 'disabled'])")
|
||||
|
||||
|
||||
def test_remove_option_permissive():
|
||||
var1 = UnicodeOption('var1', '', u'value', properties=('hidden',))
|
||||
od1 = OptionDescription('od1', '', [var1])
|
||||
rootod = OptionDescription('rootod', '', [od1])
|
||||
config = Config(rootod)
|
||||
config.read_write()
|
||||
raises(PropertiesOptionError, "config.od1.var1")
|
||||
config.cfgimpl_get_settings().setpermissive(('hidden',), var1)
|
||||
assert config.od1.var1 == u'value'
|
||||
config.cfgimpl_get_settings().setpermissive(tuple(), var1)
|
||||
raises(PropertiesOptionError, "config.od1.var1")
|
||||
api = getapi(Config(rootod))
|
||||
api.property.read_write()
|
||||
raises(PropertiesOptionError, "api.option('od1.var1').value.get()")
|
||||
api.option('od1.var1').permissive.set(frozenset(['hidden']))
|
||||
assert api.option('od1.var1').value.get() == 'value'
|
||||
api.option('od1.var1').permissive.set(frozenset())
|
||||
raises(PropertiesOptionError, "api.option('od1.var1').value.get()")
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -4,6 +4,11 @@ do_autopath()
|
|||
|
||||
from py.test import raises
|
||||
|
||||
try:
|
||||
from tiramisu.setting import ConfigBag
|
||||
tiramisu_version = 3
|
||||
except:
|
||||
tiramisu_version = 2
|
||||
from tiramisu.config import Config, SubConfig
|
||||
from tiramisu.option import ChoiceOption, BoolOption, IntOption, FloatOption,\
|
||||
StrOption, SymLinkOption, UnicodeOption, IPOption, OptionDescription, \
|
||||
|
|
@ -11,9 +16,6 @@ from tiramisu.option import ChoiceOption, BoolOption, IntOption, FloatOption,\
|
|||
URLOption, FilenameOption
|
||||
|
||||
|
||||
#FIXME slot pour un masterslaves !!
|
||||
|
||||
|
||||
def test_slots_option():
|
||||
c = ChoiceOption('a', '', ('a',))
|
||||
raises(AttributeError, "c.x = 1")
|
||||
|
|
@ -149,7 +151,10 @@ def test_slots_config():
|
|||
c = Config(od2)
|
||||
raises(AttributeError, "c.x = 1")
|
||||
raises(AttributeError, "c.cfgimpl_x = 1")
|
||||
sc = c.a
|
||||
if tiramisu_version == 2:
|
||||
sc = c.getattr('a')
|
||||
else:
|
||||
sc = c.getattr('a', None, ConfigBag(c))
|
||||
assert isinstance(sc, SubConfig)
|
||||
raises(AttributeError, "sc.x = 1")
|
||||
raises(AttributeError, "sc.cfgimpl_x = 1")
|
||||
|
|
|
|||
|
|
@ -149,8 +149,8 @@ def _diff_opt(opt1, opt2):
|
|||
def _diff_opts(opt1, opt2):
|
||||
_diff_opt(opt1, opt2)
|
||||
if isinstance(opt1, OptionDescription) or isinstance(opt1, DynOptionDescription):
|
||||
children1 = set([opt.impl_getname() for opt in opt1._impl_getchildren(dyn=False)])
|
||||
children2 = set([opt.impl_getname() for opt in opt2._impl_getchildren(dyn=False)])
|
||||
children1 = set([opt.impl_getname() for opt in opt1.impl_getchildren(dyn=False)])
|
||||
children2 = set([opt.impl_getname() for opt in opt2.impl_getchildren(dyn=False)])
|
||||
diff1 = children1 - children2
|
||||
diff2 = children2 - children1
|
||||
if diff1 != set():
|
||||
|
|
|
|||
|
|
@ -17,286 +17,286 @@ def test_non_persistent():
|
|||
Config(o, session_id='test_non_persistent')
|
||||
|
||||
|
||||
def test_list():
|
||||
b = BoolOption('b', '')
|
||||
o = OptionDescription('od', '', [b])
|
||||
c = Config(o, session_id='test_non_persistent')
|
||||
c.cfgimpl_get_settings().remove('cache')
|
||||
c.b = True
|
||||
assert 'test_non_persistent' in list_sessions('config')
|
||||
del(c)
|
||||
assert 'test_non_persistent' not in list_sessions('config')
|
||||
|
||||
|
||||
def test_create_persistent():
|
||||
b = BoolOption('b', '')
|
||||
o = OptionDescription('od', '', [b])
|
||||
try:
|
||||
Config(o, session_id='test_persistent', persistent=True)
|
||||
except ValueError:
|
||||
# storage is not persistent
|
||||
pass
|
||||
|
||||
|
||||
def test_create_delete_not_persistent():
|
||||
b = BoolOption('b', '')
|
||||
o = OptionDescription('od', '', [b])
|
||||
try:
|
||||
Config(o, session_id='test_persistent', persistent=True)
|
||||
except ValueError:
|
||||
raises(ValueError, "delete_session('option', 'test_persistent')")
|
||||
|
||||
|
||||
def test_list_sessions_persistent():
|
||||
b = BoolOption('b', '')
|
||||
o = OptionDescription('od', '', [b])
|
||||
try:
|
||||
c = Config(o, session_id='test_persistent', persistent=True)
|
||||
c.b = True
|
||||
except ValueError:
|
||||
# storage is not persistent
|
||||
pass
|
||||
else:
|
||||
assert 'test_persistent' in list_sessions('config')
|
||||
|
||||
|
||||
def test_delete_session_persistent():
|
||||
b = BoolOption('b', '')
|
||||
o = OptionDescription('od', '', [b])
|
||||
try:
|
||||
Config(o, session_id='test_persistent', persistent=True)
|
||||
except ValueError:
|
||||
# storage is not persistent
|
||||
pass
|
||||
else:
|
||||
assert 'test_persistent' in list_sessions('config')
|
||||
delete_session('config', 'test_persistent')
|
||||
assert 'test_persistent' not in list_sessions('config')
|
||||
|
||||
|
||||
def test_create_persistent_retrieve():
|
||||
b = BoolOption('b', '')
|
||||
o = OptionDescription('od', '', [b])
|
||||
try:
|
||||
c = Config(o, session_id='test_persistent', persistent=True)
|
||||
except ValueError:
|
||||
# storage is not persistent
|
||||
pass
|
||||
else:
|
||||
assert c.b is None
|
||||
c.b = True
|
||||
assert c.b is True
|
||||
del(c)
|
||||
c = Config(o, session_id='test_persistent', persistent=True)
|
||||
assert c.b is True
|
||||
assert 'test_persistent' in list_sessions('config')
|
||||
delete_session('config', c.impl_getsessionid())
|
||||
del(c)
|
||||
c = Config(o, session_id='test_persistent', persistent=True)
|
||||
assert c.b is None
|
||||
delete_session('config', c.impl_getsessionid())
|
||||
del(c)
|
||||
|
||||
|
||||
def test_two_persistent():
|
||||
b = BoolOption('b', '')
|
||||
o = OptionDescription('od', '', [b])
|
||||
try:
|
||||
c = Config(o, session_id='test_persistent', persistent=True)
|
||||
except ValueError:
|
||||
# storage is not persistent
|
||||
pass
|
||||
else:
|
||||
c.cfgimpl_get_settings().remove('cache')
|
||||
c2 = Config(o, session_id='test_persistent', persistent=True)
|
||||
c2.cfgimpl_get_settings().remove('cache')
|
||||
assert c.b is None
|
||||
assert c2.b is None
|
||||
c.b = False
|
||||
assert c.b is False
|
||||
assert c2.b is False
|
||||
c2.b = True
|
||||
assert c.b is True
|
||||
assert c2.b is True
|
||||
delete_session('config', 'test_persistent')
|
||||
|
||||
|
||||
def test_create_persistent_retrieve_owner():
|
||||
b = BoolOption('b', '')
|
||||
o = OptionDescription('od', '', [b])
|
||||
try:
|
||||
c = Config(o, session_id='test_persistent', persistent=True)
|
||||
except ValueError:
|
||||
# storage is not persistent
|
||||
pass
|
||||
else:
|
||||
assert c.getowner(b) == owners.default
|
||||
c.b = True
|
||||
assert c.b is True
|
||||
assert c.getowner(b) == owners.user
|
||||
owners.addowner('persistentowner')
|
||||
c.cfgimpl_get_values().setowner(b, owners.persistentowner)
|
||||
assert c.getowner(b) == owners.persistentowner
|
||||
del(c)
|
||||
#
|
||||
c = Config(o, session_id='test_persistent', persistent=True)
|
||||
c.cfgimpl_get_values().setowner(b, owners.persistentowner)
|
||||
delete_session('config', c.impl_getsessionid())
|
||||
del(c)
|
||||
#
|
||||
c = Config(o, session_id='test_persistent', persistent=True)
|
||||
assert c.b is None
|
||||
assert c.getowner(b) == owners.default
|
||||
delete_session('config', c.impl_getsessionid())
|
||||
del(c)
|
||||
|
||||
|
||||
def test_create_persistent_retrieve_owner_masterslaves():
|
||||
a = BoolOption('a', '', multi=True)
|
||||
b = BoolOption('b', '', multi=True)
|
||||
o = MasterSlaves('a', '', [a, b])
|
||||
#o.impl_set_group_type(groups.master)
|
||||
o1 = OptionDescription('a', '', [o])
|
||||
try:
|
||||
c = Config(o1, session_id='test_persistent', persistent=True)
|
||||
except ValueError:
|
||||
# storage is not persistent
|
||||
pass
|
||||
else:
|
||||
assert c.getowner(a) == owners.default
|
||||
assert c.getowner(b) == owners.default
|
||||
c.a.a = [True]
|
||||
c.a.a.append(False)
|
||||
c.a.b[1] = True
|
||||
assert c.getowner(a) == owners.user
|
||||
assert c.getowner(b, 0) == owners.default
|
||||
assert c.getowner(b, 1) == owners.user
|
||||
owners.addowner('persistentowner2')
|
||||
c.cfgimpl_get_values().setowner(b, owners.persistentowner2, 1)
|
||||
c.a.b[0] = True
|
||||
assert c.getowner(b, 0) == owners.user
|
||||
assert c.getowner(b, 1) == owners.persistentowner2
|
||||
del(c)
|
||||
#
|
||||
c = Config(o1, session_id='test_persistent', persistent=True)
|
||||
assert c.getowner(b, 0) == owners.user
|
||||
assert c.getowner(b, 1) == owners.persistentowner2
|
||||
delete_session('config', c.impl_getsessionid())
|
||||
del(c)
|
||||
#
|
||||
c = Config(o1, session_id='test_persistent', persistent=True)
|
||||
assert c.a.b == []
|
||||
assert c.getowner(b) == owners.default
|
||||
delete_session('config', c.impl_getsessionid())
|
||||
del(c)
|
||||
|
||||
|
||||
def test_two_persistent_owner():
|
||||
b = BoolOption('b', '')
|
||||
o = OptionDescription('od', '', [b])
|
||||
try:
|
||||
c = Config(o, session_id='test_persistent', persistent=True)
|
||||
c.cfgimpl_get_settings().remove('cache')
|
||||
except ValueError:
|
||||
# storage is not persistent
|
||||
pass
|
||||
else:
|
||||
c2 = Config(o, session_id='test_persistent', persistent=True)
|
||||
c2.cfgimpl_get_settings().remove('cache')
|
||||
assert c.getowner(b) == owners.default
|
||||
assert c2.getowner(b) == owners.default
|
||||
c.b = False
|
||||
assert c.getowner(b) == owners.user
|
||||
assert c2.getowner(b) == owners.user
|
||||
owners.addowner('persistent')
|
||||
c.cfgimpl_get_values().setowner(b, owners.persistent)
|
||||
assert c.getowner(b) == owners.persistent
|
||||
assert c2.getowner(b) == owners.persistent
|
||||
delete_session('config', 'test_persistent')
|
||||
|
||||
|
||||
def test_create_persistent_retrieve_information():
|
||||
b = BoolOption('b', '')
|
||||
o = OptionDescription('od', '', [b])
|
||||
try:
|
||||
c = Config(o, session_id='test_persistent', persistent=True)
|
||||
except ValueError:
|
||||
# storage is not persistent
|
||||
pass
|
||||
else:
|
||||
c.impl_set_information('info', 'string')
|
||||
assert c.impl_get_information('info') == 'string'
|
||||
del(c)
|
||||
#
|
||||
c = Config(o, session_id='test_persistent', persistent=True)
|
||||
assert c.impl_get_information('info') == 'string'
|
||||
delete_session('config', c.impl_getsessionid())
|
||||
del(c)
|
||||
#
|
||||
c = Config(o, session_id='test_persistent', persistent=True)
|
||||
assert c.impl_get_information('info', None) == None
|
||||
delete_session('config', c.impl_getsessionid())
|
||||
del(c)
|
||||
|
||||
|
||||
def test_two_persistent_information():
|
||||
b = BoolOption('b', '')
|
||||
o = OptionDescription('od', '', [b])
|
||||
try:
|
||||
c = Config(o, session_id='test_persistent', persistent=True)
|
||||
c.cfgimpl_get_settings().remove('cache')
|
||||
except ValueError:
|
||||
# storage is not persistent
|
||||
pass
|
||||
else:
|
||||
c.impl_set_information('info', 'string')
|
||||
assert c.impl_get_information('info') == 'string'
|
||||
c2 = Config(o, session_id='test_persistent', persistent=True)
|
||||
c2.cfgimpl_get_settings().remove('cache')
|
||||
c2.cfgimpl_get_settings().remove('cache')
|
||||
assert c2.impl_get_information('info') == 'string'
|
||||
delete_session('config', 'test_persistent')
|
||||
|
||||
|
||||
def test_two_different_persistents():
|
||||
b = BoolOption('b', '')
|
||||
o = OptionDescription('od', '', [b])
|
||||
try:
|
||||
c = Config(o, session_id='test_persistent', persistent=True)
|
||||
c.cfgimpl_get_settings().remove('cache')
|
||||
d = Config(o, session_id='test_persistent2', persistent=True)
|
||||
d.cfgimpl_get_settings().remove('cache')
|
||||
except ValueError:
|
||||
# storage is not persistent
|
||||
pass
|
||||
else:
|
||||
c.cfgimpl_get_settings()[b].append('test')
|
||||
assert str(c.cfgimpl_get_settings()[b]) in ["['test']", "[u'test']"]
|
||||
assert str(d.cfgimpl_get_settings()[b]) == "[]"
|
||||
assert c.b is None
|
||||
assert d.b is None
|
||||
c.b = True
|
||||
assert c.b == True
|
||||
assert d.b is None
|
||||
|
||||
delete_session('config', 'test_persistent')
|
||||
delete_session('config', 'test_persistent2')
|
||||
|
||||
|
||||
def test_two_different_information():
|
||||
b = BoolOption('b', '')
|
||||
o = OptionDescription('od', '', [b])
|
||||
try:
|
||||
c = Config(o, session_id='test_persistent', persistent=True)
|
||||
c.impl_set_information('a', 'a')
|
||||
d = Config(o, session_id='test_persistent2', persistent=True)
|
||||
d.impl_set_information('a', 'b')
|
||||
except ValueError:
|
||||
# storage is not persistent
|
||||
pass
|
||||
else:
|
||||
assert c.impl_get_information('a') == 'a'
|
||||
assert d.impl_get_information('a') == 'b'
|
||||
|
||||
delete_session('config', 'test_persistent')
|
||||
delete_session('config', 'test_persistent2')
|
||||
#def test_list():
|
||||
# b = BoolOption('b', '')
|
||||
# o = OptionDescription('od', '', [b])
|
||||
# c = Config(o, session_id='test_non_persistent')
|
||||
# c.cfgimpl_get_settings().remove('cache')
|
||||
# c.b = True
|
||||
# assert 'test_non_persistent' in list_sessions('config')
|
||||
# del(c)
|
||||
# assert 'test_non_persistent' not in list_sessions('config')
|
||||
#
|
||||
#
|
||||
#def test_create_persistent():
|
||||
# b = BoolOption('b', '')
|
||||
# o = OptionDescription('od', '', [b])
|
||||
# try:
|
||||
# Config(o, session_id='test_persistent', persistent=True)
|
||||
# except ValueError:
|
||||
# # storage is not persistent
|
||||
# pass
|
||||
#
|
||||
#
|
||||
#def test_create_delete_not_persistent():
|
||||
# b = BoolOption('b', '')
|
||||
# o = OptionDescription('od', '', [b])
|
||||
# try:
|
||||
# Config(o, session_id='test_persistent', persistent=True)
|
||||
# except ValueError:
|
||||
# raises(ValueError, "delete_session('option', 'test_persistent')")
|
||||
#
|
||||
#
|
||||
#def test_list_sessions_persistent():
|
||||
# b = BoolOption('b', '')
|
||||
# o = OptionDescription('od', '', [b])
|
||||
# try:
|
||||
# c = Config(o, session_id='test_persistent', persistent=True)
|
||||
# c.b = True
|
||||
# except ValueError:
|
||||
# # storage is not persistent
|
||||
# pass
|
||||
# else:
|
||||
# assert 'test_persistent' in list_sessions('config')
|
||||
#
|
||||
#
|
||||
#def test_delete_session_persistent():
|
||||
# b = BoolOption('b', '')
|
||||
# o = OptionDescription('od', '', [b])
|
||||
# try:
|
||||
# Config(o, session_id='test_persistent', persistent=True)
|
||||
# except ValueError:
|
||||
# # storage is not persistent
|
||||
# pass
|
||||
# else:
|
||||
# assert 'test_persistent' in list_sessions('config')
|
||||
# delete_session('config', 'test_persistent')
|
||||
# assert 'test_persistent' not in list_sessions('config')
|
||||
#
|
||||
#
|
||||
#def test_create_persistent_retrieve():
|
||||
# b = BoolOption('b', '')
|
||||
# o = OptionDescription('od', '', [b])
|
||||
# try:
|
||||
# c = Config(o, session_id='test_persistent', persistent=True)
|
||||
# except ValueError:
|
||||
# # storage is not persistent
|
||||
# pass
|
||||
# else:
|
||||
# assert c.b is None
|
||||
# c.b = True
|
||||
# assert c.b is True
|
||||
# del(c)
|
||||
# c = Config(o, session_id='test_persistent', persistent=True)
|
||||
# assert c.b is True
|
||||
# assert 'test_persistent' in list_sessions('config')
|
||||
# delete_session('config', c.impl_getsessionid())
|
||||
# del(c)
|
||||
# c = Config(o, session_id='test_persistent', persistent=True)
|
||||
# assert c.b is None
|
||||
# delete_session('config', c.impl_getsessionid())
|
||||
# del(c)
|
||||
#
|
||||
#
|
||||
#def test_two_persistent():
|
||||
# b = BoolOption('b', '')
|
||||
# o = OptionDescription('od', '', [b])
|
||||
# try:
|
||||
# c = Config(o, session_id='test_persistent', persistent=True)
|
||||
# except ValueError:
|
||||
# # storage is not persistent
|
||||
# pass
|
||||
# else:
|
||||
# c.cfgimpl_get_settings().remove('cache')
|
||||
# c2 = Config(o, session_id='test_persistent', persistent=True)
|
||||
# c2.cfgimpl_get_settings().remove('cache')
|
||||
# assert c.b is None
|
||||
# assert c2.b is None
|
||||
# c.b = False
|
||||
# assert c.b is False
|
||||
# assert c2.b is False
|
||||
# c2.b = True
|
||||
# assert c.b is True
|
||||
# assert c2.b is True
|
||||
# delete_session('config', 'test_persistent')
|
||||
#
|
||||
#
|
||||
#def test_create_persistent_retrieve_owner():
|
||||
# b = BoolOption('b', '')
|
||||
# o = OptionDescription('od', '', [b])
|
||||
# try:
|
||||
# c = Config(o, session_id='test_persistent', persistent=True)
|
||||
# except ValueError:
|
||||
# # storage is not persistent
|
||||
# pass
|
||||
# else:
|
||||
# assert c.getowner(b) == owners.default
|
||||
# c.b = True
|
||||
# assert c.b is True
|
||||
# assert c.getowner(b) == owners.user
|
||||
# owners.addowner('persistentowner')
|
||||
# c.cfgimpl_get_values().setowner(b, owners.persistentowner)
|
||||
# assert c.getowner(b) == owners.persistentowner
|
||||
# del(c)
|
||||
# #
|
||||
# c = Config(o, session_id='test_persistent', persistent=True)
|
||||
# c.cfgimpl_get_values().setowner(b, owners.persistentowner)
|
||||
# delete_session('config', c.impl_getsessionid())
|
||||
# del(c)
|
||||
# #
|
||||
# c = Config(o, session_id='test_persistent', persistent=True)
|
||||
# assert c.b is None
|
||||
# assert c.getowner(b) == owners.default
|
||||
# delete_session('config', c.impl_getsessionid())
|
||||
# del(c)
|
||||
#
|
||||
#
|
||||
#def test_create_persistent_retrieve_owner_masterslaves():
|
||||
# a = BoolOption('a', '', multi=True)
|
||||
# b = BoolOption('b', '', multi=True)
|
||||
# o = MasterSlaves('a', '', [a, b])
|
||||
# #o.impl_set_group_type(groups.master)
|
||||
# o1 = OptionDescription('a', '', [o])
|
||||
# try:
|
||||
# c = Config(o1, session_id='test_persistent', persistent=True)
|
||||
# except ValueError:
|
||||
# # storage is not persistent
|
||||
# pass
|
||||
# else:
|
||||
# assert c.getowner(a) == owners.default
|
||||
# assert c.getowner(b) == owners.default
|
||||
# c.a.a = [True]
|
||||
# c.a.a.append(False)
|
||||
# c.a.b[1] = True
|
||||
# assert c.getowner(a) == owners.user
|
||||
# assert c.getowner(b, 0) == owners.default
|
||||
# assert c.getowner(b, 1) == owners.user
|
||||
# owners.addowner('persistentowner2')
|
||||
# c.cfgimpl_get_values().setowner(b, owners.persistentowner2, 1)
|
||||
# c.a.b[0] = True
|
||||
# assert c.getowner(b, 0) == owners.user
|
||||
# assert c.getowner(b, 1) == owners.persistentowner2
|
||||
# del(c)
|
||||
# #
|
||||
# c = Config(o1, session_id='test_persistent', persistent=True)
|
||||
# assert c.getowner(b, 0) == owners.user
|
||||
# assert c.getowner(b, 1) == owners.persistentowner2
|
||||
# delete_session('config', c.impl_getsessionid())
|
||||
# del(c)
|
||||
# #
|
||||
# c = Config(o1, session_id='test_persistent', persistent=True)
|
||||
# assert c.a.b == []
|
||||
# assert c.getowner(b) == owners.default
|
||||
# delete_session('config', c.impl_getsessionid())
|
||||
# del(c)
|
||||
#
|
||||
#
|
||||
#def test_two_persistent_owner():
|
||||
# b = BoolOption('b', '')
|
||||
# o = OptionDescription('od', '', [b])
|
||||
# try:
|
||||
# c = Config(o, session_id='test_persistent', persistent=True)
|
||||
# c.cfgimpl_get_settings().remove('cache')
|
||||
# except ValueError:
|
||||
# # storage is not persistent
|
||||
# pass
|
||||
# else:
|
||||
# c2 = Config(o, session_id='test_persistent', persistent=True)
|
||||
# c2.cfgimpl_get_settings().remove('cache')
|
||||
# assert c.getowner(b) == owners.default
|
||||
# assert c2.getowner(b) == owners.default
|
||||
# c.b = False
|
||||
# assert c.getowner(b) == owners.user
|
||||
# assert c2.getowner(b) == owners.user
|
||||
# owners.addowner('persistent')
|
||||
# c.cfgimpl_get_values().setowner(b, owners.persistent)
|
||||
# assert c.getowner(b) == owners.persistent
|
||||
# assert c2.getowner(b) == owners.persistent
|
||||
# delete_session('config', 'test_persistent')
|
||||
#
|
||||
#
|
||||
#def test_create_persistent_retrieve_information():
|
||||
# b = BoolOption('b', '')
|
||||
# o = OptionDescription('od', '', [b])
|
||||
# try:
|
||||
# c = Config(o, session_id='test_persistent', persistent=True)
|
||||
# except ValueError:
|
||||
# # storage is not persistent
|
||||
# pass
|
||||
# else:
|
||||
# c.impl_set_information('info', 'string')
|
||||
# assert c.impl_get_information('info') == 'string'
|
||||
# del(c)
|
||||
# #
|
||||
# c = Config(o, session_id='test_persistent', persistent=True)
|
||||
# assert c.impl_get_information('info') == 'string'
|
||||
# delete_session('config', c.impl_getsessionid())
|
||||
# del(c)
|
||||
# #
|
||||
# c = Config(o, session_id='test_persistent', persistent=True)
|
||||
# assert c.impl_get_information('info', None) == None
|
||||
# delete_session('config', c.impl_getsessionid())
|
||||
# del(c)
|
||||
#
|
||||
#
|
||||
#def test_two_persistent_information():
|
||||
# b = BoolOption('b', '')
|
||||
# o = OptionDescription('od', '', [b])
|
||||
# try:
|
||||
# c = Config(o, session_id='test_persistent', persistent=True)
|
||||
# c.cfgimpl_get_settings().remove('cache')
|
||||
# except ValueError:
|
||||
# # storage is not persistent
|
||||
# pass
|
||||
# else:
|
||||
# c.impl_set_information('info', 'string')
|
||||
# assert c.impl_get_information('info') == 'string'
|
||||
# c2 = Config(o, session_id='test_persistent', persistent=True)
|
||||
# c2.cfgimpl_get_settings().remove('cache')
|
||||
# c2.cfgimpl_get_settings().remove('cache')
|
||||
# assert c2.impl_get_information('info') == 'string'
|
||||
# delete_session('config', 'test_persistent')
|
||||
#
|
||||
#
|
||||
#def test_two_different_persistents():
|
||||
# b = BoolOption('b', '')
|
||||
# o = OptionDescription('od', '', [b])
|
||||
# try:
|
||||
# c = Config(o, session_id='test_persistent', persistent=True)
|
||||
# c.cfgimpl_get_settings().remove('cache')
|
||||
# d = Config(o, session_id='test_persistent2', persistent=True)
|
||||
# d.cfgimpl_get_settings().remove('cache')
|
||||
# except ValueError:
|
||||
# # storage is not persistent
|
||||
# pass
|
||||
# else:
|
||||
# c.cfgimpl_get_settings()[b].append('test')
|
||||
# assert str(c.cfgimpl_get_settings()[b]) in ["['test']", "[u'test']"]
|
||||
# assert str(d.cfgimpl_get_settings()[b]) == "[]"
|
||||
# assert c.b is None
|
||||
# assert d.b is None
|
||||
# c.b = True
|
||||
# assert c.b == True
|
||||
# assert d.b is None
|
||||
#
|
||||
# delete_session('config', 'test_persistent')
|
||||
# delete_session('config', 'test_persistent2')
|
||||
#
|
||||
#
|
||||
#def test_two_different_information():
|
||||
# b = BoolOption('b', '')
|
||||
# o = OptionDescription('od', '', [b])
|
||||
# try:
|
||||
# c = Config(o, session_id='test_persistent', persistent=True)
|
||||
# c.impl_set_information('a', 'a')
|
||||
# d = Config(o, session_id='test_persistent2', persistent=True)
|
||||
# d.impl_set_information('a', 'b')
|
||||
# except ValueError:
|
||||
# # storage is not persistent
|
||||
# pass
|
||||
# else:
|
||||
# assert c.impl_get_information('a') == 'a'
|
||||
# assert d.impl_get_information('a') == 'b'
|
||||
#
|
||||
# delete_session('config', 'test_persistent')
|
||||
# delete_session('config', 'test_persistent2')
|
||||
|
|
|
|||
|
|
@ -1,14 +1,15 @@
|
|||
# coding: utf-8
|
||||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
from py.test import raises
|
||||
|
||||
|
||||
from tiramisu.api import TIRAMISU_VERSION
|
||||
from tiramisu.setting import groups, owners
|
||||
from tiramisu.config import Config, MetaConfig
|
||||
from tiramisu.option import StrOption, IntOption, OptionDescription, submulti, MasterSlaves
|
||||
#from tiramisu.value import SubMulti, Multi
|
||||
from tiramisu import StrOption, IntOption, OptionDescription, submulti, MasterSlaves, Config, \
|
||||
MetaConfig, getapi, undefined
|
||||
from tiramisu.error import SlaveError
|
||||
|
||||
from py.test import raises
|
||||
|
||||
|
||||
def return_val(val=None):
|
||||
|
|
@ -28,22 +29,160 @@ def return_list2(value=None):
|
|||
|
||||
def test_submulti():
|
||||
multi = StrOption('multi', '', multi=submulti)
|
||||
multi2 = StrOption('multi2', '', default_multi=['yes'], multi=submulti)
|
||||
if TIRAMISU_VERSION == 2:
|
||||
default_multi = 'yes'
|
||||
else:
|
||||
default_multi = ['yes']
|
||||
multi2 = StrOption('multi2', '', default_multi=default_multi, multi=submulti)
|
||||
multi3 = StrOption('multi3', '', default=[['yes']], multi=submulti)
|
||||
od = OptionDescription('od', '', [multi, multi2, multi3])
|
||||
cfg = Config(od)
|
||||
assert cfg.getowner(multi) == owners.default
|
||||
assert cfg.multi == []
|
||||
assert cfg.getowner(multi) == owners.default
|
||||
assert cfg.getowner(multi) == owners.default
|
||||
assert cfg.multi3 == [['yes']]
|
||||
assert cfg.multi3[0] == ['yes']
|
||||
assert cfg.multi3[0][0] == 'yes'
|
||||
cfg.multi3[0]
|
||||
assert cfg.getowner(multi) == owners.default
|
||||
api = getapi(Config(od))
|
||||
assert api.option('multi').owner.get() == owners.default
|
||||
assert api.option('multi').value.get() == []
|
||||
assert api.option('multi').owner.get() == owners.default
|
||||
assert api.option('multi').owner.get() == owners.default
|
||||
assert api.option('multi3').value.get() == [['yes']]
|
||||
assert api.option('multi').owner.get() == owners.default
|
||||
|
||||
|
||||
#FIXME multi sur une master
|
||||
def test_append_submulti():
|
||||
multi = StrOption('multi', '', multi=submulti)
|
||||
if TIRAMISU_VERSION == 2:
|
||||
default_multi = 'yes'
|
||||
else:
|
||||
default_multi = ['yes']
|
||||
multi2 = StrOption('multi2', '', default_multi=default_multi, multi=submulti)
|
||||
multi3 = StrOption('multi3', '', default=[['yes']], multi=submulti)
|
||||
od = OptionDescription('od', '', [multi, multi2, multi3])
|
||||
api = getapi(Config(od))
|
||||
owner = api.owner.get()
|
||||
assert api.option('multi').value.get() == []
|
||||
assert api.option('multi').owner.get() == owners.default
|
||||
api.option('multi').value.set([undefined])
|
||||
assert api.option('multi').owner.get() == owner
|
||||
assert api.option('multi').value.get() == [[]]
|
||||
api.option('multi').value.set([undefined, ['no']])
|
||||
assert api.option('multi').value.get() == [[], ['no']]
|
||||
#
|
||||
assert api.option('multi2').value.get() == []
|
||||
assert api.option('multi2').owner.get() == owners.default
|
||||
api.option('multi2').value.set([undefined])
|
||||
assert api.option('multi2').owner.get() == owner
|
||||
assert api.option('multi2').value.get() == [['yes']]
|
||||
api.option('multi2').value.set([undefined, ['no']])
|
||||
assert api.option('multi2').value.get() == [['yes'], ['no']]
|
||||
#
|
||||
assert api.option('multi3').value.get() == [['yes']]
|
||||
assert api.option('multi3').owner.get() == owners.default
|
||||
api.option('multi3').value.set([undefined, undefined])
|
||||
assert api.option('multi3').owner.get() == owner
|
||||
assert api.option('multi3').value.get() == [['yes'], []]
|
||||
api.option('multi3').value.set([undefined, undefined, ['no']])
|
||||
assert api.option('multi3').value.get() == [['yes'], [], ['no']]
|
||||
|
||||
|
||||
def test_append_unvalide_submulti():
|
||||
multi = StrOption('multi', '', multi=submulti)
|
||||
if TIRAMISU_VERSION == 2:
|
||||
default_multi = 'yes'
|
||||
else:
|
||||
default_multi = ['yes']
|
||||
multi2 = StrOption('multi2', '', default_multi=default_multi, multi=submulti)
|
||||
multi3 = StrOption('multi3', '', default=[['yes']], multi=submulti)
|
||||
od = OptionDescription('od', '', [multi, multi2, multi3])
|
||||
api = getapi(Config(od))
|
||||
assert api.option('multi').value.get() == []
|
||||
assert api.option('multi').owner.get() == owners.default
|
||||
raises(ValueError, "api.option('multi').value.set([[1]])")
|
||||
assert api.option('multi').value.get() == []
|
||||
assert api.option('multi').owner.get() == owners.default
|
||||
#
|
||||
assert api.option('multi2').value.get() == []
|
||||
raises(ValueError, "api.option('multi2').value.set(['no'])")
|
||||
assert api.option('multi').owner.get() == owners.default
|
||||
assert api.option('multi2').value.get() == []
|
||||
#
|
||||
assert api.option('multi3').value.get() == [['yes']]
|
||||
assert api.option('multi3').owner.get() == owners.default
|
||||
raises(ValueError, "api.option('multi3').value.set([[1]])")
|
||||
assert api.option('multi3').value.get() == [['yes']]
|
||||
assert api.option('multi3').owner.get() == owners.default
|
||||
|
||||
|
||||
def test_pop_submulti():
|
||||
multi = StrOption('multi', '', multi=submulti)
|
||||
if TIRAMISU_VERSION == 2:
|
||||
default_multi = 'yes'
|
||||
else:
|
||||
default_multi = ['yes']
|
||||
multi2 = StrOption('multi2', '', default_multi=default_multi, multi=submulti)
|
||||
multi3 = StrOption('multi3', '', default=[['yes']], multi=submulti)
|
||||
od = OptionDescription('od', '', [multi, multi2, multi3])
|
||||
api = getapi(Config(od))
|
||||
owner = api.owner.get()
|
||||
assert api.option('multi').value.get() == []
|
||||
assert api.option('multi3').owner.get() == owners.default
|
||||
api.option('multi').value.set([['no', 'yes'], ['peharps']])
|
||||
assert api.option('multi').owner.get() == owner
|
||||
assert api.option('multi').value.get() == [['no', 'yes'], ['peharps']]
|
||||
#
|
||||
assert api.option('multi3').value.get() == [['yes']]
|
||||
assert api.option('multi3').owner.get() == owners.default
|
||||
api.option('multi3').value.set([])
|
||||
assert api.option('multi').owner.get() == owner
|
||||
assert api.option('multi3').value.get() == []
|
||||
api.option('multi3').value.reset()
|
||||
assert api.option('multi3').owner.get() == owners.default
|
||||
api.option('multi3').value.set([[]])
|
||||
assert api.option('multi3').owner.get() == owner
|
||||
assert api.option('multi3').value.get() == [[]]
|
||||
|
||||
|
||||
def test_callback_submulti_str():
|
||||
multi = StrOption('multi', '', multi=submulti, callback=return_val)
|
||||
od = OptionDescription('od', '', [multi])
|
||||
api = getapi(Config(od))
|
||||
api.property.read_write()
|
||||
owner = api.owner.get()
|
||||
assert api.option('multi').owner.get() == owners.default
|
||||
assert api.option('multi').value.get() == [['val']]
|
||||
api.option('multi').value.set([['val'], undefined])
|
||||
assert api.option('multi').owner.get() == owner
|
||||
assert api.option('multi').value.get() == [['val'], ['val']]
|
||||
api.option('multi').value.reset()
|
||||
assert api.option('multi').owner.get() == owners.default
|
||||
|
||||
|
||||
def test_callback_submulti_list():
|
||||
multi = StrOption('multi', '', multi=submulti, callback=return_list)
|
||||
od = OptionDescription('od', '', [multi])
|
||||
api = getapi(Config(od))
|
||||
api.property.read_write()
|
||||
owner = api.owner.get()
|
||||
assert api.option('multi').value.get() == [['val', 'val']]
|
||||
assert api.option('multi').owner.get() == owners.default
|
||||
api.option('multi').value.set([['val', 'val'], undefined])
|
||||
assert api.option('multi').owner.get() == owner
|
||||
assert api.option('multi').value.get() == [['val', 'val'], ['val', 'val']]
|
||||
api.option('multi').value.set([['val', 'val'], undefined, undefined])
|
||||
assert api.option('multi').value.get() == [['val', 'val'], ['val', 'val'], ['val', 'val']]
|
||||
api.option('multi').value.reset()
|
||||
assert api.option('multi').owner.get() == owners.default
|
||||
|
||||
|
||||
def test_callback_submulti_list_list():
|
||||
multi = StrOption('multi', '', multi=submulti, callback=return_list2)
|
||||
od = OptionDescription('od', '', [multi])
|
||||
api = getapi(Config(od))
|
||||
api.property.read_write()
|
||||
owner = api.owner.get()
|
||||
assert api.option('multi').value.get() == [['val', 'val']]
|
||||
assert api.option('multi').owner.get() == owners.default
|
||||
api.option('multi').value.set([['val', 'val'], undefined])
|
||||
assert api.option('multi').owner.get() == owner
|
||||
assert api.option('multi').value.get() == [['val', 'val'], []]
|
||||
api.option('multi').value.reset()
|
||||
assert api.option('multi').owner.get() == owners.default
|
||||
|
||||
|
||||
def test_groups_with_master_submulti():
|
||||
|
|
@ -58,41 +197,62 @@ def test_groups_with_master_in_config_submulti():
|
|||
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=submulti)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
Config(interface1)
|
||||
od = OptionDescription('root', '', [interface1])
|
||||
Config(od)
|
||||
assert interface1.impl_get_group_type() == groups.master
|
||||
|
||||
|
||||
def test_values_with_master_and_slaves_submulti():
|
||||
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=submulti)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
api = getapi(Config(maconfig))
|
||||
api.property.read_write()
|
||||
owner = api.owner.get()
|
||||
assert interface1.impl_get_group_type() == groups.master
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.default
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ["192.168.230.145"]
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == []
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.default
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", "192.168.230.147"])
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == []
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == []
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(['255.255.255.0'])
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == ['255.255.255.0']
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == []
|
||||
raises(ValueError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')")
|
||||
raises(ValueError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set([['255.255.255.0']])")
|
||||
|
||||
|
||||
def test_reset_values_with_master_and_slaves_submulti():
|
||||
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=submulti)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
cfg.read_write()
|
||||
owner = cfg.cfgimpl_get_settings().getowner()
|
||||
api = getapi(Config(maconfig))
|
||||
api.property.read_write()
|
||||
owner = api.owner.get()
|
||||
assert interface1.impl_get_group_type() == groups.master
|
||||
assert cfg.getowner(ip_admin_eth0) == owners.default
|
||||
assert cfg.getowner(netmask_admin_eth0) == owners.default
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
|
||||
assert cfg.getowner(ip_admin_eth0) == owner
|
||||
assert cfg.getowner(netmask_admin_eth0) == owners.default
|
||||
del(cfg.ip_admin_eth0.ip_admin_eth0)
|
||||
assert cfg.getowner(ip_admin_eth0) == owners.default
|
||||
assert cfg.getowner(netmask_admin_eth0) == owners.default
|
||||
assert cfg.ip_admin_eth0.ip_admin_eth0 == []
|
||||
assert cfg.ip_admin_eth0.netmask_admin_eth0 == []
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.default
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.default
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.default
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
#
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0[0].append('255.255.255.0')
|
||||
assert cfg.getowner(ip_admin_eth0) == owner
|
||||
assert cfg.getowner(netmask_admin_eth0, 0) == owner
|
||||
del(cfg.ip_admin_eth0.ip_admin_eth0)
|
||||
assert cfg.getowner(ip_admin_eth0) == owners.default
|
||||
# assert cfg.getowner(netmask_admin_eth0) == owners.default
|
||||
assert cfg.ip_admin_eth0.ip_admin_eth0 == []
|
||||
assert cfg.ip_admin_eth0.netmask_admin_eth0 == []
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(['255.255.255.0'])
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owner
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.default
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
|
||||
|
||||
def test_values_with_master_and_slaves_slave_submulti():
|
||||
|
|
@ -101,22 +261,18 @@ def test_values_with_master_and_slaves_slave_submulti():
|
|||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
cfg.read_write()
|
||||
assert cfg.ip_admin_eth0.netmask_admin_eth0 == []
|
||||
raises(SlaveError, "cfg.ip_admin_eth0.netmask_admin_eth0 = [['255.255.255.0']]")
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0 = [['255.255.255.0']]
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0[0] = ['255.255.255.0']
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0[0][0] = '255.255.255.0'
|
||||
raises(SlaveError, "cfg.ip_admin_eth0.netmask_admin_eth0 = [['255.255.255.0'], ['255.255.255.0']]")
|
||||
raises(SlaveError, "cfg.ip_admin_eth0.netmask_admin_eth0 = []")
|
||||
del(cfg.ip_admin_eth0.netmask_admin_eth0)
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0 = [['255.255.255.0']]
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
|
||||
assert cfg.ip_admin_eth0.netmask_admin_eth0 == [['255.255.255.0'], []]
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0 = [['255.255.255.0'], ['255.255.255.0']]
|
||||
raises(SlaveError, 'cfg.ip_admin_eth0.netmask_admin_eth0.pop(1)')
|
||||
api = getapi(Config(maconfig))
|
||||
api.property.read_write()
|
||||
raises(SlaveError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(['255.255.255.0'])")
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(['255.255.255.0'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(['255.255.255.0', '255.255.255.0'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset()
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(['255.255.255.0'])
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145', '192.168.230.145'])
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == ['255.255.255.0']
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == []
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(['255.255.255.0'])
|
||||
|
||||
|
||||
def test_values_with_master_and_slaves_master_submulti():
|
||||
|
|
@ -125,36 +281,19 @@ def test_values_with_master_and_slaves_master_submulti():
|
|||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
cfg.read_write()
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
|
||||
cfg.ip_admin_eth0.ip_admin_eth0 = ["192.168.230.145"]
|
||||
cfg.ip_admin_eth0.ip_admin_eth0 = ["192.168.230.145", "192.168.230.145"]
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0 = [['255.255.255.0'], ['255.255.255.0']]
|
||||
raises(SlaveError, 'cfg.ip_admin_eth0.ip_admin_eth0 = ["192.168.230.145"]')
|
||||
assert cfg.ip_admin_eth0.netmask_admin_eth0 == [['255.255.255.0'], ['255.255.255.0']]
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.pop(1)
|
||||
assert cfg.ip_admin_eth0.ip_admin_eth0 == ["192.168.230.145"]
|
||||
assert cfg.ip_admin_eth0.netmask_admin_eth0 == [['255.255.255.0']]
|
||||
del(cfg.ip_admin_eth0.ip_admin_eth0)
|
||||
assert cfg.ip_admin_eth0.ip_admin_eth0 == []
|
||||
assert cfg.ip_admin_eth0.netmask_admin_eth0 == []
|
||||
|
||||
|
||||
def test_values_with_master_and_slaves_master_error_submulti():
|
||||
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=submulti)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
cfg.read_write()
|
||||
cfg.ip_admin_eth0.ip_admin_eth0 = ["192.168.230.145", "192.168.230.145"]
|
||||
raises(SlaveError, "cfg.ip_admin_eth0.netmask_admin_eth0 = [['255.255.255.0']]")
|
||||
raises(SlaveError, "cfg.ip_admin_eth0.netmask_admin_eth0 = [['255.255.255.0'], ['255.255.255.0'], ['255.255.255.0']]")
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0 = [['255.255.255.0'], ['255.255.255.0']]
|
||||
raises(SlaveError, "cfg.ip_admin_eth0.netmask_admin_eth0 = [['255.255.255.0']]")
|
||||
raises(SlaveError, "cfg.ip_admin_eth0.netmask_admin_eth0 = [['255.255.255.0'], ['255.255.255.0'], ['255.255.255.0']]")
|
||||
api = getapi(Config(maconfig))
|
||||
api.property.read_write()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", "192.168.230.145"])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(['255.255.255.0'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set(['255.255.255.0'])
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == ['255.255.255.0']
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == ['255.255.255.0']
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(1)
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ["192.168.230.145"]
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == ['255.255.255.0']
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
|
||||
|
||||
def test_values_with_master_owner_submulti():
|
||||
|
|
@ -163,123 +302,40 @@ def test_values_with_master_owner_submulti():
|
|||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
cfg.read_write()
|
||||
owner = cfg.cfgimpl_get_settings().getowner()
|
||||
assert cfg.getowner(ip_admin_eth0) == owners.default
|
||||
assert cfg.getowner(netmask_admin_eth0) == owners.default
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
|
||||
assert cfg.getowner(ip_admin_eth0) == owner
|
||||
assert cfg.getowner(netmask_admin_eth0) == owners.default
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.pop(0)
|
||||
assert cfg.getowner(ip_admin_eth0) == owner
|
||||
assert cfg.getowner(netmask_admin_eth0) == owners.default
|
||||
api = getapi(Config(maconfig))
|
||||
api.property.read_write()
|
||||
owner = api.owner.get()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.default
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.default
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.default
|
||||
|
||||
|
||||
def test_values_with_master_disabled_submulti():
|
||||
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=submulti)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
cfg.read_write()
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.pop(0)
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0 = [["192.168.230.145"]]
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.pop(0)
|
||||
del(cfg.ip_admin_eth0.netmask_admin_eth0)
|
||||
cfg.cfgimpl_get_settings()[netmask_admin_eth0].append('disabled')
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.pop(0)
|
||||
api = getapi(Config(maconfig))
|
||||
api.property.read_write()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(['192.168.230.145'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset()
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0').property.add('disabled')
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145', '192.168.230.145'])
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(1)
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
|
||||
|
||||
#delete with value in disabled var
|
||||
cfg.cfgimpl_get_settings()[netmask_admin_eth0].remove('disabled')
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0 = [["192.168.230.145"]]
|
||||
cfg.cfgimpl_get_settings()[netmask_admin_eth0].append('disabled')
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.pop(0)
|
||||
|
||||
#append with value in disabled var
|
||||
cfg.cfgimpl_get_settings()[netmask_admin_eth0].remove('disabled')
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
|
||||
cfg.ip_admin_eth0.netmask_admin_eth0 = [["192.168.230.145"]]
|
||||
cfg.cfgimpl_get_settings()[netmask_admin_eth0].append('disabled')
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append('192.168.230.43')
|
||||
|
||||
|
||||
def test_multi_insert_master_submulti():
|
||||
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=submulti)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
cfg.read_write()
|
||||
raises(SlaveError, "cfg.ip_admin_eth0.ip_admin_eth0.insert(0, 'nok')")
|
||||
raises(SlaveError, "cfg.ip_admin_eth0.netmask_admin_eth0.insert(0, 'nok')")
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append('192.168.1.1')
|
||||
raises(SlaveError, "cfg.ip_admin_eth0.netmask_admin_eth0[0].insert(0, 'nok')")
|
||||
|
||||
|
||||
def test_multi_sort_master_submulti():
|
||||
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=submulti)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
cfg.read_write()
|
||||
raises(SlaveError, "cfg.ip_admin_eth0.ip_admin_eth0.sort()")
|
||||
raises(SlaveError, "cfg.ip_admin_eth0.netmask_admin_eth0.sort()")
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append('192.168.1.1')
|
||||
raises(SlaveError, "cfg.ip_admin_eth0.netmask_admin_eth0[0].sort()")
|
||||
|
||||
|
||||
def test_multi_reverse_master_submulti():
|
||||
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=submulti)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
cfg.read_write()
|
||||
raises(SlaveError, "cfg.ip_admin_eth0.ip_admin_eth0.reverse()")
|
||||
raises(SlaveError, "cfg.ip_admin_eth0.netmask_admin_eth0.reverse()")
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append('192.168.1.1')
|
||||
raises(SlaveError, "cfg.ip_admin_eth0.netmask_admin_eth0[0].reverse()")
|
||||
|
||||
|
||||
def test_multi_extend_master_submulti():
|
||||
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=submulti)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
cfg.read_write()
|
||||
raises(SlaveError, "cfg.ip_admin_eth0.ip_admin_eth0.extend(['ok'])")
|
||||
raises(SlaveError, "cfg.ip_admin_eth0.netmask_admin_eth0.extend(['ok'])")
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append('192.168.1.1')
|
||||
raises(SlaveError, "cfg.ip_admin_eth0.netmask_admin_eth0[0].extend(['ok'])")
|
||||
|
||||
|
||||
def test_slave_submulti():
|
||||
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=submulti)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
cfg.read_write()
|
||||
assert cfg.ip_admin_eth0.ip_admin_eth0.__class__.__name__ == 'Multi'
|
||||
assert cfg.ip_admin_eth0.netmask_admin_eth0.__class__.__name__ == 'Multi'
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append('192.168.1.1')
|
||||
assert cfg.ip_admin_eth0.ip_admin_eth0.__class__.__name__ == 'Multi'
|
||||
assert cfg.ip_admin_eth0.netmask_admin_eth0.__class__.__name__ == 'Multi'
|
||||
assert cfg.ip_admin_eth0.ip_admin_eth0[0].__class__.__name__ == 'str'
|
||||
assert cfg.ip_admin_eth0.netmask_admin_eth0[0].__class__.__name__ == 'SubMulti'
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0').property.pop('disabled')
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(['192.168.230.145'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0').property.add('disabled')
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
|
||||
|
||||
|
||||
def test__master_is_submulti():
|
||||
|
|
@ -288,41 +344,90 @@ def test__master_is_submulti():
|
|||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
cfg.read_write()
|
||||
owner = cfg.cfgimpl_get_settings().getowner()
|
||||
api = getapi(Config(maconfig))
|
||||
api.property.read_write()
|
||||
owner = api.owner.get()
|
||||
assert interface1.impl_get_group_type() == groups.master
|
||||
assert cfg.getowner(ip_admin_eth0) == owners.default
|
||||
assert cfg.getowner(netmask_admin_eth0) == owners.default
|
||||
assert cfg.ip_admin_eth0.netmask_admin_eth0 == []
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append(["192.168.230.145"])
|
||||
assert cfg.ip_admin_eth0.ip_admin_eth0 == [["192.168.230.145"]]
|
||||
assert cfg.ip_admin_eth0.netmask_admin_eth0 == [None]
|
||||
assert cfg.getowner(ip_admin_eth0) == owner
|
||||
assert cfg.getowner(netmask_admin_eth0) == owners.default
|
||||
cfg.ip_admin_eth0.ip_admin_eth0 = [["192.168.230.145"], ["192.168.230.147"]]
|
||||
assert cfg.ip_admin_eth0.netmask_admin_eth0 == [None, None]
|
||||
raises(SlaveError, 'cfg.ip_admin_eth0.netmask_admin_eth0.append(None)')
|
||||
raises(SlaveError, 'cfg.ip_admin_eth0.netmask_admin_eth0.pop(0)')
|
||||
cfg.ip_admin_eth0.ip_admin_eth0[0].append('192.168.1.1')
|
||||
assert cfg.ip_admin_eth0.ip_admin_eth0 == [["192.168.230.145", '192.168.1.1'], ["192.168.230.147"]]
|
||||
cfg.ip_admin_eth0.ip_admin_eth0[0].pop(0)
|
||||
assert cfg.ip_admin_eth0.ip_admin_eth0 == [["192.168.1.1"], ["192.168.230.147"]]
|
||||
raises(ValueError, 'cfg.ip_admin_eth0.ip_admin_eth0 = ["192.168.1.1", "192.168.1.1"]')
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set([["192.168.230.145"]])
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [["192.168.230.145"]]
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set([["192.168.230.145"], ["192.168.230.147"]])
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == None
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set([["192.168.230.145", '192.168.1.1'], ["192.168.230.147"]])
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [["192.168.230.145", '192.168.1.1'], ["192.168.230.147"]]
|
||||
raises(ValueError, "api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1', '192.168.1.1'])")
|
||||
|
||||
|
||||
def test_callback_submulti():
|
||||
multi = StrOption('multi', '', multi=submulti)
|
||||
multi2 = StrOption('multi2', '', multi=submulti, callback=return_val, callback_params={'': ((multi, False),)})
|
||||
od = OptionDescription('multi', '', [multi, multi2])
|
||||
cfg = Config(od)
|
||||
cfg.read_write()
|
||||
owner = cfg.cfgimpl_get_settings().getowner()
|
||||
assert cfg.getowner(multi) == owners.default
|
||||
assert cfg.multi == []
|
||||
assert cfg.multi2 == []
|
||||
cfg.multi.append(['val'])
|
||||
assert cfg.getowner(multi) == owner
|
||||
assert cfg.getowner(multi2) == owners.default
|
||||
assert cfg.multi == [['val']]
|
||||
assert cfg.multi2 == [['val']]
|
||||
api = getapi(Config(od))
|
||||
api.property.read_write()
|
||||
owner = api.owner.get()
|
||||
assert api.option('multi').owner.get() == owners.default
|
||||
assert api.option('multi').value.get() == []
|
||||
assert api.option('multi2').value.get() == []
|
||||
api.option('multi').value.set([['val']])
|
||||
assert api.option('multi').owner.get() == owner
|
||||
assert api.option('multi2').owner.get() == owners.default
|
||||
assert api.option('multi').value.get() == [['val']]
|
||||
assert api.option('multi2').value.get() == [['val']]
|
||||
|
||||
|
||||
def test_submulti_unique():
|
||||
i = IntOption('int', '', multi=submulti, unique=True)
|
||||
o = OptionDescription('od', '', [i])
|
||||
api = getapi(Config(o))
|
||||
assert api.option('int').value.get() == []
|
||||
api.option('int').value.set([[0]])
|
||||
assert api.option('int').value.get() == [[0]]
|
||||
raises(ValueError, "api.option('int').value.set([[0, 0]])")
|
||||
api.option('int').value.set([[0], [0]])
|
||||
raises(ValueError, "api.option('int').value.set([[1, 0, 2, 3, 4, 5, 6, 0, 7], [0]])")
|
||||
api.option('int').value.set([[0, 4, 5, 6], [0]])
|
||||
#
|
||||
#
|
||||
#def test_multi_submulti_meta():
|
||||
# multi = StrOption('multi', '', multi=submulti)
|
||||
# od = OptionDescription('od', '', [multi])
|
||||
# conf1 = Config(od, session_id='conf1')
|
||||
# api1 = getapi(conf1)
|
||||
# api1.property.read_write()
|
||||
# conf2 = Config(od, session_id='conf2')
|
||||
# api2 = getapi(conf2)
|
||||
# api2.property.read_write()
|
||||
# meta = MetaConfig([conf1, conf2])
|
||||
# api3 = getapi(meta)
|
||||
# api3.property.read_write()
|
||||
# api3.option('multi').value.set([['val']])
|
||||
# assert api3.option('multi').value.get() == [['val']]
|
||||
# api3.config('conf1').option('multi').value.set([['val', None]])
|
||||
# assert api1.option('multi').value.get() == [['val', None]]
|
||||
# assert api3.config('conf1').option('multi').value.get() == [['val', None]]
|
||||
# assert api3.option('multi').value.get() == [['val']]
|
||||
#
|
||||
#
|
||||
#def test_multi_submulti_meta_no_cache():
|
||||
# multi = StrOption('multi', '', multi=submulti)
|
||||
# od = OptionDescription('od', '', [multi])
|
||||
# conf1 = Config(od, session_id='conf1_1')
|
||||
# api1 = getapi(conf1)
|
||||
# api1.property.read_write()
|
||||
# conf2 = Config(od, session_id='conf2_1')
|
||||
# api2 = getapi(conf2)
|
||||
# api2.property.read_write()
|
||||
# meta = MetaConfig([conf1, conf2])
|
||||
# api3 = getapi(api2)
|
||||
# api3.property.read_write()
|
||||
# api3.property.pop('cache')
|
||||
# api3.option('multi').value.set([['val']])
|
||||
# assert api3.option('multi').value.get() == [['val']]
|
||||
# api3.config('conf1').option('multi').value.set([['val', None]])
|
||||
# assert api1.option('multi').value.get() == [['val', None]]
|
||||
# assert api3.config('conf1').option('multi').value.get() == [['val', None]]
|
||||
# assert api3.option('multi').value.get() == [['val']]
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@
|
|||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
|
||||
from tiramisu.option import BoolOption, StrOption, SymLinkOption, \
|
||||
OptionDescription, MasterSlaves
|
||||
from tiramisu.config import Config
|
||||
from tiramisu.error import PropertiesOptionError
|
||||
from tiramisu import BoolOption, StrOption, SymLinkOption, \
|
||||
OptionDescription, MasterSlaves, Config, getapi
|
||||
from tiramisu.error import PropertiesOptionError, ConfigError
|
||||
from tiramisu.setting import groups, owners
|
||||
from tiramisu.api import TIRAMISU_VERSION
|
||||
|
||||
from py.test import raises
|
||||
|
||||
|
|
@ -21,27 +21,30 @@ def test_symlink_option():
|
|||
linkopt = SymLinkOption("c", boolopt)
|
||||
descr = OptionDescription("opt", "",
|
||||
[linkopt, OptionDescription("s1", "", [boolopt])])
|
||||
config = Config(descr)
|
||||
assert config.s1.b is False
|
||||
setattr(config, "s1.b", True)
|
||||
setattr(config, "s1.b", False)
|
||||
assert config.s1.b is False
|
||||
assert config.c is False
|
||||
config.c = True
|
||||
assert config.s1.b is True
|
||||
assert config.c is True
|
||||
config.c = False
|
||||
assert config.s1.b is False
|
||||
assert config.c is False
|
||||
api = getapi(Config(descr))
|
||||
assert api.option('s1.b').value.get() is False
|
||||
api.option("s1.b").value.set(True)
|
||||
api.option("s1.b").value.set(False)
|
||||
assert api.option('s1.b').value.get() is False
|
||||
assert api.option('c').value.get() is False
|
||||
api.option('s1.b').value.set(True)
|
||||
assert api.option('s1.b').value.get() is True
|
||||
assert api.option('c').value.get() is True
|
||||
api.option('s1.b').value.set(False)
|
||||
assert api.option('s1.b').value.get() is False
|
||||
assert api.option('c').value.get() is False
|
||||
|
||||
|
||||
def test_symlink_getproperties():
|
||||
boolopt = BoolOption('b', '', default=True, properties=('test',))
|
||||
linkopt = SymLinkOption("c", boolopt)
|
||||
descr = OptionDescription('opt', '', [boolopt, linkopt])
|
||||
config = Config(descr)
|
||||
config.read_write()
|
||||
assert boolopt.impl_getproperties() == linkopt.impl_getproperties() == ('test',)
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
if TIRAMISU_VERSION == 2:
|
||||
assert boolopt.impl_getproperties() == linkopt.impl_getproperties() == ('test',)
|
||||
else:
|
||||
assert boolopt.impl_getproperties() == linkopt.impl_getproperties() == {'test'}
|
||||
assert boolopt.impl_has_callback() == linkopt.impl_has_callback() == False
|
||||
|
||||
|
||||
|
|
@ -49,8 +52,8 @@ def test_symlink_getcallback():
|
|||
boolopt = BoolOption('b', '', callback=return_value)
|
||||
linkopt = SymLinkOption("c", boolopt)
|
||||
descr = OptionDescription('opt', '', [boolopt, linkopt])
|
||||
config = Config(descr)
|
||||
config.read_write()
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
assert boolopt.impl_has_callback() == linkopt.impl_has_callback() == True
|
||||
assert boolopt.impl_get_callback() == linkopt.impl_get_callback() == (return_value, {})
|
||||
|
||||
|
|
@ -62,26 +65,32 @@ def test_symlink_requires():
|
|||
'action': 'disabled'}])
|
||||
linkopt = SymLinkOption("c", stropt)
|
||||
descr = OptionDescription('opt', '', [boolopt, stropt, linkopt])
|
||||
config = Config(descr)
|
||||
config.read_write()
|
||||
assert config.b is True
|
||||
assert config.s is None
|
||||
assert config.c is None
|
||||
config.b = False
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
assert api.option('b').value.get() is True
|
||||
assert api.option('s').value.get() is None
|
||||
assert api.option('c').value.get() is None
|
||||
api.option('b').value.set(False)
|
||||
#
|
||||
props = []
|
||||
try:
|
||||
config.s
|
||||
api.option('s').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == ['disabled']
|
||||
if TIRAMISU_VERSION == 2:
|
||||
assert props == ['disabled']
|
||||
else:
|
||||
assert props == {'disabled'}
|
||||
#
|
||||
props = []
|
||||
try:
|
||||
config.c
|
||||
api.option('c').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == ['disabled']
|
||||
if TIRAMISU_VERSION == 2:
|
||||
assert props == ['disabled']
|
||||
else:
|
||||
assert props == {'disabled'}
|
||||
|
||||
|
||||
def test_symlink_multi():
|
||||
|
|
@ -89,33 +98,43 @@ def test_symlink_multi():
|
|||
linkopt = SymLinkOption("c", boolopt)
|
||||
descr = OptionDescription("opt", "",
|
||||
[linkopt, OptionDescription("s1", "", [boolopt])])
|
||||
config = Config(descr)
|
||||
assert config.s1.b == [False]
|
||||
assert config.c == [False]
|
||||
config.c = [True]
|
||||
assert config.s1.b == [True]
|
||||
assert config.c == [True]
|
||||
config.c = [False]
|
||||
assert config.s1.b == [False]
|
||||
assert config.c == [False]
|
||||
config.c.append(True)
|
||||
assert config.s1.b == [False, True]
|
||||
assert config.c == [False, True]
|
||||
api = getapi(Config(descr))
|
||||
assert api.option('s1.b').value.get() == [False]
|
||||
assert api.option('c').value.get() == [False]
|
||||
api.option('s1.b').value.set([True])
|
||||
assert api.option('s1.b').value.get() == [True]
|
||||
assert api.option('c').value.get() == [True]
|
||||
api.option('s1.b').value.set([False])
|
||||
assert api.option('s1.b').value.get() == [False]
|
||||
assert api.option('c').value.get() == [False]
|
||||
api.option('s1.b').value.set([False, True])
|
||||
assert api.option('s1.b').value.get() == [False, True]
|
||||
assert api.option('c').value.get() == [False, True]
|
||||
assert boolopt.impl_is_multi() is True
|
||||
assert linkopt.impl_is_multi() is True
|
||||
|
||||
|
||||
def test_symlink_assign():
|
||||
if TIRAMISU_VERSION != 2:
|
||||
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_owner():
|
||||
boolopt = BoolOption("b", "", default=False)
|
||||
linkopt = SymLinkOption("c", boolopt)
|
||||
descr = OptionDescription("opt", "",
|
||||
[linkopt, OptionDescription("s1", "", [boolopt])])
|
||||
config = Config(descr)
|
||||
assert config.getowner(boolopt) == owners.default
|
||||
assert config.getowner(linkopt) == owners.default
|
||||
config.c = True
|
||||
assert config.getowner(boolopt) != owners.default
|
||||
assert config.getowner(linkopt) != owners.default
|
||||
api = getapi(Config(descr))
|
||||
assert api.option('s1.b').owner.isdefault()
|
||||
assert api.option('c').owner.isdefault()
|
||||
api.option('s1.b').value.set(True)
|
||||
assert not api.option('s1.b').owner.isdefault()
|
||||
assert not api.option('c').owner.isdefault()
|
||||
|
||||
|
||||
def test_symlink_get_information():
|
||||
|
|
@ -149,8 +168,8 @@ def test_symlink_dependency():
|
|||
linkopt = SymLinkOption("c", boolopt)
|
||||
descr = OptionDescription("opt", "",
|
||||
[linkopt, OptionDescription("s1", "", [boolopt])])
|
||||
config = Config(descr)
|
||||
assert config.cfgimpl_get_description().s1.b.impl_has_dependency() is False
|
||||
assert config.cfgimpl_get_description().c.impl_has_dependency() is True
|
||||
assert config.cfgimpl_get_description().s1.b.impl_has_dependency(False) is True
|
||||
assert config.cfgimpl_get_description().c.impl_has_dependency(False) is False
|
||||
api = getapi(Config(descr))
|
||||
assert api.option('s1.b').option.has_dependency() is False
|
||||
assert api.option('c').option.has_dependency() is True
|
||||
assert api.option('s1.b').option.has_dependency(False) is True
|
||||
assert api.option('c').option.has_dependency(False) is False
|
||||
|
|
|
|||
|
|
@ -188,11 +188,6 @@ class TiramisuOptionOption(CommonTiramisuOption):
|
|||
option = self._get_option()
|
||||
return option.impl_is_master_slaves('slave')
|
||||
|
||||
@count
|
||||
def name(self):
|
||||
option = self._get_option()
|
||||
return option.impl_getname()
|
||||
|
||||
@count
|
||||
def doc(self):
|
||||
option = self._get_option()
|
||||
|
|
@ -766,8 +761,12 @@ class TiramisuContextConfig(TiramisuContext):
|
|||
|
||||
class TiramisuDispatcherConfig(TiramisuContextConfig):
|
||||
def __call__(self, path):
|
||||
spaths = path.split('.')
|
||||
config = self.config_bag.config
|
||||
if path is None:
|
||||
return TiramisuAPI(config,
|
||||
force_permissive=self.config_bag.force_permissive,
|
||||
force_unrestraint=self.config_bag.force_unrestraint)
|
||||
spaths = path.split('.')
|
||||
for spath in spaths:
|
||||
config = config.getconfig(spath)
|
||||
return TiramisuAPI(config,
|
||||
|
|
|
|||
|
|
@ -97,11 +97,11 @@ class Option(OnlyOption):
|
|||
_setattr(self, '_multi', _multi)
|
||||
if multi is not False and default is None:
|
||||
default = []
|
||||
super(Option, self).__init__(name,
|
||||
doc,
|
||||
requires=requires,
|
||||
properties=properties,
|
||||
is_multi=is_multi)
|
||||
super().__init__(name,
|
||||
doc,
|
||||
requires=requires,
|
||||
properties=properties,
|
||||
is_multi=is_multi)
|
||||
if validator is not None:
|
||||
validate_calculator(validator,
|
||||
validator_params,
|
||||
|
|
@ -343,6 +343,7 @@ class Option(OnlyOption):
|
|||
warnings.warn_explicit(ValueWarning(msg, self),
|
||||
ValueWarning,
|
||||
self.__class__.__name__, 0)
|
||||
|
||||
|
||||
def impl_is_dynsymlinkoption(self):
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -567,6 +567,7 @@ class Settings(object):
|
|||
if self._getcontext().cfgimpl_get_meta() is not None:
|
||||
raise ConfigError(_('cannot change property with metaconfig'))
|
||||
if path is not None and config_bag.option.impl_getrequires() is not None:
|
||||
print(properties, getattr(config_bag.option, '_calc_properties', static_set))
|
||||
not_allowed_props = properties & getattr(config_bag.option, '_calc_properties', static_set)
|
||||
if not_allowed_props:
|
||||
if len(not_allowed_props) == 1:
|
||||
|
|
@ -575,9 +576,9 @@ class Settings(object):
|
|||
else:
|
||||
prop_msg = _('properties')
|
||||
calc_msg = _('those properties are calculated')
|
||||
raise ValueError(_('cannot set {} {} for option {} {}'
|
||||
raise ValueError(_('cannot set {} {} for option "{}" {}'
|
||||
'').format(prop_msg, display_list(list(not_allowed_props), add_quote=True),
|
||||
config_bag.option.impl_getname(),
|
||||
config_bag.option.impl_get_display_name(),
|
||||
calc_msg))
|
||||
if config_bag is None:
|
||||
opt = None
|
||||
|
|
@ -607,9 +608,17 @@ class Settings(object):
|
|||
raise ConfigError(_('cannot add this property: "{0}"').format(
|
||||
' '.join(property_)))
|
||||
|
||||
props = config_bag.option.impl_getproperties()
|
||||
print('add', property_)
|
||||
self_properties = config_bag.properties
|
||||
if self_properties is None:
|
||||
index = None
|
||||
self_properties = self.getproperties(path,
|
||||
index,
|
||||
config_bag,
|
||||
apply_requires=False)
|
||||
config_bag.properties = self_properties
|
||||
self.setproperties(path,
|
||||
props | {property_},
|
||||
self_properties | {property_},
|
||||
config_bag,
|
||||
force=True)
|
||||
|
||||
|
|
@ -617,9 +626,16 @@ class Settings(object):
|
|||
path,
|
||||
property_,
|
||||
config_bag):
|
||||
props = config_bag.option.impl_getproperties()
|
||||
self_properties = config_bag.properties
|
||||
if self_properties is None:
|
||||
index = None
|
||||
self_properties = self.getproperties(path,
|
||||
index,
|
||||
config_bag,
|
||||
apply_requires=False)
|
||||
config_bag.properties = self_properties
|
||||
self.setproperties(path,
|
||||
props - {property_},
|
||||
self_properties - {property_},
|
||||
config_bag,
|
||||
force=True)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue