api: permissive => forcepermissive

api: add permissive object
test api: permissive
config: unwrap_from_path check properties for option, not only optiondescription
option: _RegexpOption => RegexpOption
This commit is contained in:
Emmanuel Garette 2017-11-03 21:52:13 +01:00
parent 39348a14aa
commit 2e412b64fd
16 changed files with 1073 additions and 986 deletions

View File

@ -47,7 +47,7 @@ def autocheck_owner_without_value(api, path, **kwargs):
"""check different value of owner when any value is set to this option
"""
try:
isslave = api.permissive.option.isslave(path)
isslave = api.forcepermissive.option.isslave(path)
except:
isslave = False
# check if owner is a string "default"
@ -61,14 +61,14 @@ def autocheck_owner_without_value(api, path, **kwargs):
raises(APIError, "api.unrestraint.owner.get(path)")
if not kwargs.get('propertyerror', False):
if not isslave:
assert api.permissive.owner.get(path) == 'default'
assert api.forcepermissive.owner.get(path) == 'default'
else:
assert api.permissive.owner.get(path, 0) == 'default'
assert api.forcepermissive.owner.get(path, 0) == 'default'
else:
if not isslave:
raises(PropertiesOptionError, "api.permissive.owner.get(path)")
raises(PropertiesOptionError, "api.forcepermissive.owner.get(path)")
else:
raises(PropertiesOptionError, "api.permissive.owner.get(path, 0)")
raises(PropertiesOptionError, "api.forcepermissive.owner.get(path, 0)")
# check if default owner
raises(APIError, "api.unrestraint.owner.isdefault(path)")
@ -77,9 +77,9 @@ def autocheck_owner_without_value(api, path, **kwargs):
else:
raises(PropertiesOptionError, "api.owner.isdefault(path)")
if not kwargs.get('propertyerror', False):
assert api.permissive.owner.isdefault(path)
assert api.forcepermissive.owner.isdefault(path)
else:
raises(PropertiesOptionError, "api.permissive.owner.isdefault(path)")
raises(PropertiesOptionError, "api.forcepermissive.owner.isdefault(path)")
@autocheck
@ -88,11 +88,11 @@ def autocheck_value(api, path, **kwargs):
"""
# check if is a multi, a master or a slave
if not kwargs.get('propertyerror', False):
multi = api.permissive.option.ismulti(path)
ismaster = api.permissive.option.ismaster(path)
isslave = api.permissive.option.isslave(path)
multi = api.forcepermissive.option.ismulti(path)
ismaster = api.forcepermissive.option.ismaster(path)
isslave = api.forcepermissive.option.isslave(path)
else:
raises(PropertiesOptionError, "api.permissive.option.ismulti(path)")
raises(PropertiesOptionError, "api.forcepermissive.option.ismulti(path)")
multi = api.unrestraint.option.ismulti(path)
ismaster = api.unrestraint.option.ismaster(path)
isslave = api.unrestraint.option.isslave(path)
@ -122,9 +122,9 @@ def autocheck_value(api, path, **kwargs):
raises(APIError, "api.unrestraint.value.get(path)")
if not isslave:
if not kwargs.get('propertyerror', False):
assert api.permissive.value.get(path) == empty_value
assert api.forcepermissive.value.get(path) == empty_value
else:
raises(PropertiesOptionError, "api.permissive.value.get(path)")
raises(PropertiesOptionError, "api.forcepermissive.value.get(path)")
# set a value without permissive
# for master/slave should have an index and good length
@ -158,17 +158,17 @@ def autocheck_value(api, path, **kwargs):
elif kwargs.get('permissive', False):
if isslave:
raises(PropertiesOptionError, "api.value.get(path, 0)")
assert api.permissive.value.get(path, 0) == empty_value
assert api.forcepermissive.value.get(path, 0) == empty_value
else:
raises(PropertiesOptionError, "api.value.get(path)")
assert api.permissive.value.get(path) == empty_value
assert api.forcepermissive.value.get(path) == empty_value
else:
if isslave:
raises(PropertiesOptionError, "api.value.get(path, 0)")
raises(PropertiesOptionError, "api.permissive.value.get(path, 0)")
raises(PropertiesOptionError, "api.forcepermissive.value.get(path, 0)")
else:
raises(PropertiesOptionError, "api.value.get(path)")
raises(PropertiesOptionError, "api.permissive.value.get(path)")
raises(PropertiesOptionError, "api.forcepermissive.value.get(path)")
# set a value with permissive
if ismaster:
@ -179,30 +179,30 @@ def autocheck_value(api, path, **kwargs):
raises(APIError, "api.unrestraint.value.set(path, second_value)")
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if ismaster:
raises(IndexError, "api.permissive.value.set(path, 1, second_value[1])")
api.permissive.value.append(path, second_value[1])
raises(IndexError, "api.forcepermissive.value.set(path, 1, second_value[1])")
api.forcepermissive.value.append(path, second_value[1])
elif isslave:
#FIXME
raises(PropertiesOptionError, "api.permissive.value.append(path, second_value[1])")
raises(PropertiesOptionError, "api.forcepermissive.value.append(path, second_value[1])")
api.value.set(path, 1, second_value[1])
raise Exception('ca entre ici')
else:
api.value.set(path, second_value)
elif kwargs.get('permissive', False):
if ismaster:
api.permissive.value.append(path, second_value[0])
api.permissive.value.append(path, second_value[1])
api.forcepermissive.value.append(path, second_value[0])
api.forcepermissive.value.append(path, second_value[1])
elif isslave:
api.permissive.value.set(path, 1, second_value[1])
api.forcepermissive.value.set(path, 1, second_value[1])
else:
api.permissive.value.set(path, first_value)
api.forcepermissive.value.set(path, first_value)
else:
if ismaster:
raises(PropertiesOptionError, "api.permissive.value.append(path, first_value[0])")
raises(PropertiesOptionError, "api.forcepermissive.value.append(path, first_value[0])")
elif isslave:
raises(PropertiesOptionError, "api.permissive.value.set(path, 0, first_value[0])")
raises(PropertiesOptionError, "api.forcepermissive.value.set(path, 0, first_value[0])")
else:
raises(PropertiesOptionError, "api.permissive.value.set(path, first_value)")
raises(PropertiesOptionError, "api.forcepermissive.value.set(path, first_value)")
# get value after set value with permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
@ -214,32 +214,32 @@ def autocheck_value(api, path, **kwargs):
elif kwargs.get('permissive', False):
if ismaster:
raises(PropertiesOptionError, "api.value.get(path)")
assert api.permissive.value.get(path) == second_value
assert api.forcepermissive.value.get(path) == second_value
elif isslave:
raises(PropertiesOptionError, "api.value.get(path, 0)")
raises(PropertiesOptionError, "api.value.get(path, 1)")
assert api.permissive.value.get(path, 1) == second_value[1]
assert api.forcepermissive.value.get(path, 1) == second_value[1]
else:
raises(PropertiesOptionError, "api.value.get(path)")
assert api.permissive.value.get(path) == first_value
assert api.forcepermissive.value.get(path) == first_value
else:
if isslave:
raises(PropertiesOptionError, "api.value.get(path, 0)")
raises(PropertiesOptionError, "api.permissive.value.get(path, 0)")
raises(PropertiesOptionError, "api.forcepermissive.value.get(path, 0)")
else:
raises(PropertiesOptionError, "api.value.get(path)")
raises(PropertiesOptionError, "api.permissive.value.get(path)")
raises(PropertiesOptionError, "api.forcepermissive.value.get(path)")
@autocheck
def autocheck_reset_value(api, path, **kwargs):
# check if is a multi, a master or a slave
if not kwargs.get('propertyerror', False):
multi = api.permissive.option.ismulti(path)
ismaster = api.permissive.option.ismaster(path)
isslave = api.permissive.option.isslave(path)
multi = api.forcepermissive.option.ismulti(path)
ismaster = api.forcepermissive.option.ismaster(path)
isslave = api.forcepermissive.option.isslave(path)
else:
raises(PropertiesOptionError, "api.permissive.option.ismulti(path)")
raises(PropertiesOptionError, "api.forcepermissive.option.ismulti(path)")
multi = api.unrestraint.option.ismulti(path)
ismaster = api.unrestraint.option.ismaster(path)
isslave = api.unrestraint.option.isslave(path)
@ -278,28 +278,28 @@ def autocheck_reset_value(api, path, **kwargs):
elif kwargs.get('permissive', False):
if isslave:
raises(PropertiesOptionError, "api.value.get(path, 0)")
assert api.permissive.value.get(path, 0) == empty_value
assert api.permissive.value.get(path, 1) == second_value[1]
assert api.forcepermissive.value.get(path, 0) == empty_value
assert api.forcepermissive.value.get(path, 1) == second_value[1]
else:
raises(PropertiesOptionError, "api.value.get(path)")
assert api.permissive.value.get(path) == first_value
assert api.forcepermissive.value.get(path) == first_value
# reset value with permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if not isslave:
api.permissive.value.reset(path)
api.forcepermissive.value.reset(path)
else:
api.permissive.value.reset(path, 1)
api.forcepermissive.value.reset(path, 1)
elif kwargs.get('permissive', False):
if not isslave:
api.permissive.value.reset(path)
api.forcepermissive.value.reset(path)
else:
api.permissive.value.reset(path, 1)
api.forcepermissive.value.reset(path, 1)
else:
if not isslave:
raises(PropertiesOptionError, "api.permissive.value.reset(path)")
raises(PropertiesOptionError, "api.forcepermissive.value.reset(path)")
else:
raises(PropertiesOptionError, "api.permissive.value.reset(path, 1)")
raises(PropertiesOptionError, "api.forcepermissive.value.reset(path, 1)")
# get value after reset value with permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
@ -312,11 +312,11 @@ def autocheck_reset_value(api, path, **kwargs):
if isslave:
raises(PropertiesOptionError, "api.value.get(path, 0)")
raises(PropertiesOptionError, "api.value.get(path, 1)")
assert api.permissive.value.get(path, 0) == empty_value
assert api.permissive.value.get(path, 1) == empty_value
assert api.forcepermissive.value.get(path, 0) == empty_value
assert api.forcepermissive.value.get(path, 1) == empty_value
else:
raises(PropertiesOptionError, "api.value.get(path)")
assert api.permissive.value.get(path) == empty_value
assert api.forcepermissive.value.get(path) == empty_value
@autocheck
@ -332,11 +332,11 @@ def autocheck_property(api, path, **kwargs):
"""
# check if is a multi or a slave
if not kwargs.get('propertyerror', False):
multi = api.permissive.option.ismulti(path)
isslave = api.permissive.option.isslave(path)
multi = api.forcepermissive.option.ismulti(path)
isslave = api.forcepermissive.option.isslave(path)
else:
raises(PropertiesOptionError, "api.permissive.option.ismulti(path)")
raises(PropertiesOptionError, "api.permissive.option.isslave(path)")
raises(PropertiesOptionError, "api.forcepermissive.option.ismulti(path)")
raises(PropertiesOptionError, "api.forcepermissive.option.isslave(path)")
multi = api.unrestraint.option.ismulti(path)
isslave = api.unrestraint.option.isslave(path)
@ -370,15 +370,15 @@ def autocheck_property(api, path, **kwargs):
raises(APIError, "api.unrestraint.property.get(path, 0)")
if not kwargs.get('propertyerror', False):
if not isslave:
assert set(api.permissive.property.get(path)) == set(default_props)
assert set(api.forcepermissive.property.get(path)) == set(default_props)
else:
assert set(api.permissive.property.get(path, 0)) == set(default_props)
assert set(api.permissive.property.get(path, 1)) == set(default_props)
assert set(api.forcepermissive.property.get(path, 0)) == set(default_props)
assert set(api.forcepermissive.property.get(path, 1)) == set(default_props)
else:
if not isslave:
raises(PropertiesOptionError, "api.permissive.property.get(path)")
raises(PropertiesOptionError, "api.forcepermissive.property.get(path)")
else:
raises(PropertiesOptionError, "api.permissive.property.get(path, 0)")
raises(PropertiesOptionError, "api.forcepermissive.property.get(path, 0)")
# set properties without permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
@ -389,54 +389,54 @@ def autocheck_property(api, path, **kwargs):
# check properties after set without permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
assert set(api.property.get(path)) == set(properties)
assert set(api.permissive.property.get(path)) == set(properties)
assert set(api.forcepermissive.property.get(path)) == set(properties)
elif kwargs.get('permissive', False):
raises(PropertiesOptionError, "api.property.get(path)")
if not isslave:
assert set(api.permissive.property.get(path)) == set(default_props)
assert set(api.forcepermissive.property.get(path)) == set(default_props)
else:
assert set(api.permissive.property.get(path, 0)) == set(default_props)
assert set(api.permissive.property.get(path, 1)) == set(default_props)
assert set(api.forcepermissive.property.get(path, 0)) == set(default_props)
assert set(api.forcepermissive.property.get(path, 1)) == set(default_props)
else:
if not isslave:
raises(PropertiesOptionError, "api.property.get(path)")
raises(PropertiesOptionError, "api.permissive.property.get(path)")
raises(PropertiesOptionError, "api.forcepermissive.property.get(path)")
else:
raises(PropertiesOptionError, "api.property.get(path, 0)")
raises(PropertiesOptionError, "api.permissive.property.get(path, 0)")
raises(PropertiesOptionError, "api.forcepermissive.property.get(path, 0)")
# set properties with permissive
if not kwargs.get('propertyerror', False):
api.permissive.property.set(path, properties)
api.forcepermissive.property.set(path, properties)
else:
raises(PropertiesOptionError, "api.permissive.property.set(path, properties)")
raises(PropertiesOptionError, "api.forcepermissive.property.set(path, properties)")
# check properties after set with permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if not isslave:
assert set(api.property.get(path)) == set(properties)
assert set(api.permissive.property.get(path)) == set(properties)
assert set(api.forcepermissive.property.get(path)) == set(properties)
else:
assert set(api.property.get(path, 0)) == set(properties)
assert set(api.permissive.property.get(path, 0)) == set(properties)
assert set(api.forcepermissive.property.get(path, 0)) == set(properties)
assert set(api.property.get(path, 1)) == set(properties)
assert set(api.permissive.property.get(path, 1)) == set(properties)
assert set(api.forcepermissive.property.get(path, 1)) == set(properties)
elif kwargs.get('permissive', False):
if not isslave:
raises(PropertiesOptionError, "api.property.get(path)")
assert set(api.permissive.property.get(path)) == set(properties)
assert set(api.forcepermissive.property.get(path)) == set(properties)
else:
raises(PropertiesOptionError, "api.property.get(path, 0)")
assert set(api.permissive.property.get(path, 0)) == set(properties)
assert set(api.forcepermissive.property.get(path, 0)) == set(properties)
raises(PropertiesOptionError, "api.property.get(path, 1)")
assert set(api.permissive.property.get(path, 1)) == set(properties)
assert set(api.forcepermissive.property.get(path, 1)) == set(properties)
else:
if not isslave:
raises(PropertiesOptionError, "api.property.get(path)")
raises(PropertiesOptionError, "api.permissive.property.get(path)")
raises(PropertiesOptionError, "api.forcepermissive.property.get(path)")
else:
raises(PropertiesOptionError, "api.property.get(path, 0)")
raises(PropertiesOptionError, "api.permissive.property.get(path, 0)")
raises(PropertiesOptionError, "api.forcepermissive.property.get(path, 0)")
@autocheck
@ -446,11 +446,11 @@ def autocheck_reset_property(api, path, **kwargs):
# check if is a multi or a slave
if not kwargs.get('propertyerror', False):
multi = api.permissive.option.ismulti(path)
isslave = api.permissive.option.isslave(path)
multi = api.forcepermissive.option.ismulti(path)
isslave = api.forcepermissive.option.isslave(path)
else:
raises(PropertiesOptionError, "api.permissive.option.ismulti(path)")
raises(PropertiesOptionError, "api.permissive.option.isslave(path)")
raises(PropertiesOptionError, "api.forcepermissive.option.ismulti(path)")
raises(PropertiesOptionError, "api.forcepermissive.option.isslave(path)")
multi = api.unrestraint.option.ismulti(path)
isslave = api.unrestraint.option.isslave(path)
@ -470,13 +470,13 @@ def autocheck_reset_property(api, path, **kwargs):
# check properties
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
assert set(api.property.get(path)) == set(properties)
assert set(api.permissive.property.get(path)) == set(properties)
assert set(api.forcepermissive.property.get(path)) == set(properties)
elif kwargs.get('permissive', False):
if not isslave:
assert set(api.permissive.property.get(path)) == set(properties)
assert set(api.forcepermissive.property.get(path)) == set(properties)
else:
assert set(api.permissive.property.get(path, 0)) == set(properties)
assert set(api.permissive.property.get(path, 1)) == set(properties)
assert set(api.forcepermissive.property.get(path, 0)) == set(properties)
assert set(api.forcepermissive.property.get(path, 1)) == set(properties)
# reset properties without permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
@ -488,44 +488,44 @@ def autocheck_reset_property(api, path, **kwargs):
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if not isslave:
assert set(api.property.get(path)) == set(default_props)
assert set(api.permissive.property.get(path)) == set(default_props)
assert set(api.forcepermissive.property.get(path)) == set(default_props)
else:
assert set(api.property.get(path, 0)) == set(default_props)
assert set(api.permissive.property.get(path, 0)) == set(default_props)
assert set(api.forcepermissive.property.get(path, 0)) == set(default_props)
assert set(api.property.get(path, 1)) == set(default_props)
assert set(api.permissive.property.get(path, 1)) == set(default_props)
assert set(api.forcepermissive.property.get(path, 1)) == set(default_props)
elif kwargs.get('permissive', False):
if not isslave:
assert set(api.permissive.property.get(path)) == set(properties)
assert set(api.forcepermissive.property.get(path)) == set(properties)
else:
assert set(api.permissive.property.get(path, 0)) == set(properties)
assert set(api.permissive.property.get(path, 1)) == set(properties)
assert set(api.forcepermissive.property.get(path, 0)) == set(properties)
assert set(api.forcepermissive.property.get(path, 1)) == set(properties)
# reset properties with permissive
raises(APIError, "api.unrestraint.property.set(path, properties)")
raises(APIError, "api.unrestraint.property.reset(path)")
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
api.permissive.property.set(path, properties)
api.permissive.property.reset(path)
api.forcepermissive.property.set(path, properties)
api.forcepermissive.property.reset(path)
elif kwargs.get('permissive', False):
api.permissive.property.reset(path)
api.forcepermissive.property.reset(path)
# check properties
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if not isslave:
assert set(api.property.get(path)) == set(default_props)
assert set(api.permissive.property.get(path)) == set(default_props)
assert set(api.forcepermissive.property.get(path)) == set(default_props)
else:
assert set(api.property.get(path, 0)) == set(default_props)
assert set(api.permissive.property.get(path, 0)) == set(default_props)
assert set(api.forcepermissive.property.get(path, 0)) == set(default_props)
assert set(api.property.get(path, 1)) == set(default_props)
assert set(api.permissive.property.get(path, 1)) == set(default_props)
assert set(api.forcepermissive.property.get(path, 1)) == set(default_props)
elif kwargs.get('permissive', False):
if not isslave:
assert set(api.permissive.property.get(path)) == set(default_props)
assert set(api.forcepermissive.property.get(path)) == set(default_props)
else:
assert set(api.permissive.property.get(path, 0)) == set(default_props)
assert set(api.permissive.property.get(path, 1)) == set(default_props)
assert set(api.forcepermissive.property.get(path, 0)) == set(default_props)
assert set(api.forcepermissive.property.get(path, 1)) == set(default_props)
@autocheck
@ -539,9 +539,9 @@ def autocheck_owner_with_value(api, path, **kwargs):
"""
# check if is a isslave
if not kwargs.get('propertyerror', False):
isslave = api.permissive.option.isslave(path)
isslave = api.forcepermissive.option.isslave(path)
else:
raises(PropertiesOptionError, "api.permissive.option.isslave(path)")
raises(PropertiesOptionError, "api.forcepermissive.option.isslave(path)")
isslave = api.unrestraint.option.isslave(path)
# get owner without permissive
@ -561,15 +561,15 @@ def autocheck_owner_with_value(api, path, **kwargs):
# get owner with permissive
if not kwargs.get('propertyerror', False):
if not isslave:
assert api.permissive.owner.get(path) == 'user'
assert api.forcepermissive.owner.get(path) == 'user'
else:
assert api.permissive.owner.get(path, 0) == 'default'
assert api.permissive.owner.get(path, 1) == 'user'
assert api.forcepermissive.owner.get(path, 0) == 'default'
assert api.forcepermissive.owner.get(path, 1) == 'user'
else:
if not isslave:
raises(PropertiesOptionError, "api.permissive.owner.get(path)")
raises(PropertiesOptionError, "api.forcepermissive.owner.get(path)")
else:
raises(PropertiesOptionError, "api.permissive.owner.get(path, 0)")
raises(PropertiesOptionError, "api.forcepermissive.owner.get(path, 0)")
# test if is default owner without permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
@ -579,18 +579,18 @@ def autocheck_owner_with_value(api, path, **kwargs):
# test if is default owner with permissive
if not kwargs.get('propertyerror', False):
assert api.permissive.owner.isdefault(path) is False
assert api.forcepermissive.owner.isdefault(path) is False
else:
raises(PropertiesOptionError, "api.permissive.owner.isdefault(path)")
raises(PropertiesOptionError, "api.forcepermissive.owner.isdefault(path)")
@autocheck
def autocheck_set_owner(api, path, **kwargs):
# test set owner without permissive
if not kwargs.get('propertyerror', False):
isslave = api.permissive.option.isslave(path)
isslave = api.forcepermissive.option.isslave(path)
else:
raises(PropertiesOptionError, "api.permissive.option.isslave(path)")
raises(PropertiesOptionError, "api.forcepermissive.option.isslave(path)")
isslave = False
# set owner without permissive
@ -609,35 +609,35 @@ def autocheck_set_owner(api, path, **kwargs):
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if not isslave:
assert api.owner.get(path) == 'new_user'
assert api.permissive.owner.get(path) == 'new_user'
assert api.forcepermissive.owner.get(path) == 'new_user'
else:
assert api.owner.get(path, 1) == 'new_user'
assert api.permissive.owner.get(path, 1) == 'new_user'
assert api.forcepermissive.owner.get(path, 1) == 'new_user'
elif not kwargs.get('propertyerror', False):
if not isslave:
assert api.permissive.owner.get(path) == 'user'
assert api.forcepermissive.owner.get(path) == 'user'
else:
assert api.permissive.owner.get(path, 1) == 'user'
assert api.forcepermissive.owner.get(path, 1) == 'user'
# set owner with permissive
if not kwargs.get('propertyerror', False):
if not isslave:
api.permissive.owner.set(path, 'new_user1')
api.forcepermissive.owner.set(path, 'new_user1')
else:
api.permissive.owner.set(path, 1, 'new_user1')
api.forcepermissive.owner.set(path, 1, 'new_user1')
else:
if not isslave:
raises(PropertiesOptionError, "api.permissive.owner.set(path, 'new_user1')")
raises(PropertiesOptionError, "api.forcepermissive.owner.set(path, 'new_user1')")
else:
raises(PropertiesOptionError, "api.permissive.owner.set(path, 1, 'new_user1')")
raises(PropertiesOptionError, "api.forcepermissive.owner.set(path, 1, 'new_user1')")
# get owner set with permissive
if not kwargs.get('propertyerror', False):
if not isslave:
assert api.permissive.owner.get(path) == 'new_user1'
assert api.forcepermissive.owner.get(path) == 'new_user1'
else:
assert api.permissive.owner.get(path, 0) == 'default'
assert api.permissive.owner.get(path, 1) == 'new_user1'
assert api.forcepermissive.owner.get(path, 0) == 'default'
assert api.forcepermissive.owner.get(path, 1) == 'new_user1'
@autocheck
@ -645,24 +645,24 @@ def autocheck_option(api, path, **kwargs):
expected_name = path.split('.')[-1]
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
current_name = api.option.getname(path)
assert current_name == api.permissive.option.getname(path)
assert current_name == api.forcepermissive.option.getname(path)
assert current_name == api.unrestraint.option.getname(path)
doc = api.option.getdoc(path)
assert doc == api.permissive.option.getdoc(path)
assert doc == api.forcepermissive.option.getdoc(path)
assert doc == api.unrestraint.option.getdoc(path)
elif not kwargs.get('propertyerror', False):
raises(PropertiesOptionError, "api.option.getname(path)")
current_name = api.permissive.option.getname(path)
current_name = api.forcepermissive.option.getname(path)
assert current_name == api.unrestraint.option.getname(path)
raises(PropertiesOptionError, "api.option.getdoc(path)")
doc = api.permissive.option.getdoc(path)
doc = api.forcepermissive.option.getdoc(path)
assert doc == api.unrestraint.option.getdoc(path)
else:
raises(PropertiesOptionError, "api.option.getname(path)")
raises(PropertiesOptionError, "api.permissive.option.getname(path)")
raises(PropertiesOptionError, "api.forcepermissive.option.getname(path)")
current_name = api.unrestraint.option.getname(path)
raises(PropertiesOptionError, "api.option.getdoc(path)")
raises(PropertiesOptionError, "api.permissive.option.getdoc(path)")
raises(PropertiesOptionError, "api.forcepermissive.option.getdoc(path)")
doc = api.unrestraint.option.getdoc(path)
assert current_name == expected_name
if expected_name.endswith('val1') or expected_name.endswith('val2'):
@ -670,6 +670,85 @@ def autocheck_option(api, path, **kwargs):
assert doc == "{}'s option".format(expected_name)
@autocheck
def autocheck_permissive(api, path, **kwargs):
"""test permissive for hidden and disabled value
"""
# check if is a multi, a master or a slave
if not kwargs.get('propertyerror', False):
multi = api.forcepermissive.option.ismulti(path)
ismaster = api.forcepermissive.option.ismaster(path)
isslave = api.forcepermissive.option.isslave(path)
else:
raises(PropertiesOptionError, "api.forcepermissive.option.ismulti(path)")
multi = api.unrestraint.option.ismulti(path)
ismaster = api.unrestraint.option.ismaster(path)
isslave = api.unrestraint.option.isslave(path)
# set default value (different if value is multi or not)
if not multi:
first_value = 'myvalue'
second_value = 'myvalue1'
else:
first_value = ['myvalue']
second_value = ['myvalue', 'myvalue1']
if multi and not isslave:
empty_value = []
else:
empty_value = None
# cannot access to hidden value without forcepermissive
# and to disabled value (with forcepermissive too)
if kwargs.get('propertyerror', False):
if not isslave:
raises(PropertiesOptionError, "api.value.get(path)")
raises(PropertiesOptionError, "api.forcepermissive.value.get(path)")
else:
raises(PropertiesOptionError, "api.value.get(path, 0)")
raises(PropertiesOptionError, "api.forcepermissive.value.get(path, 0)")
elif kwargs.get('permissive', False):
if not isslave:
raises(PropertiesOptionError, "api.value.get(path)")
api.forcepermissive.value.get(path)
else:
raises(PropertiesOptionError, "api.value.get(path, 0)")
api.forcepermissive.value.get(path, 0)
else:
if not isslave:
api.value.get(path)
else:
api.value.get(path, 0)
assert api.permissive.get(path) == frozenset()
api.permissive.set(path, ('disabled',))
assert api.permissive.get(path) == frozenset(['disabled'])
# can access to disabled value
if kwargs.get('permissive', False):
if not isslave:
raises(PropertiesOptionError, "api.value.get(path)")
api.forcepermissive.value.get(path)
else:
raises(PropertiesOptionError, "api.value.get(path, 0)")
api.forcepermissive.value.get(path, 0)
else:
if not isslave:
api.value.get(path)
else:
api.value.get(path, 0)
api.permissive.set(path, ('disabled', 'hidden'))
# can access to value
if not isslave:
api.value.get(path)
else:
api.value.get(path, 0)
assert api.permissive.get(path) == frozenset(['disabled', 'hidden'])
print('FIXME del !!!')
def check_all(api, path, multi, **kwargs):
text = u' {} launch tests for {}'.format(ICON, path)
if multi:

View File

@ -98,7 +98,7 @@ def test_cache_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' in settings._p_.get_cached()
assert 'u2' not in settings._p_.get_cached()
#when remove a value
c.u1
assert 'u1' in values._p_.get_cached()
@ -107,7 +107,7 @@ def test_cache_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' in settings._p_.get_cached()
assert 'u2' not in settings._p_.get_cached()
#when add/del property
c.u1
assert 'u1' in values._p_.get_cached()
@ -156,7 +156,7 @@ def test_cache_reset_multi():
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
assert 'u3' not in values._p_.get_cached()
assert 'u3' in settings._p_.get_cached()
assert 'u3' not in settings._p_.get_cached()
#when append value
c.u1
c.u3
@ -168,7 +168,7 @@ def test_cache_reset_multi():
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
assert 'u3' not in values._p_.get_cached()
assert 'u3' in settings._p_.get_cached()
assert 'u3' not in settings._p_.get_cached()
#when pop value
c.u1
c.u3
@ -180,7 +180,7 @@ def test_cache_reset_multi():
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
assert 'u3' not in values._p_.get_cached()
assert 'u3' in settings._p_.get_cached()
assert 'u3' not in settings._p_.get_cached()
#when remove a value
c.u1
assert 'u1' in values._p_.get_cached()
@ -189,7 +189,7 @@ def test_cache_reset_multi():
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
assert 'u3' not in values._p_.get_cached()
assert 'u3' in settings._p_.get_cached()
assert 'u3' not in settings._p_.get_cached()
def test_reset_cache():
@ -407,100 +407,78 @@ def test_cache_callback():
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)},
'val2': {None: (set(['mandatory']), None)},
'val3': {None: (set([]), None)},
'val4': {None: (set([]), None)},
'val5': {None: (set(['empty']), None)}}
#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)}}
cfg.val1 = 'new'
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)},
'val5': {None: (set(['empty']), None)}}
#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()
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
'val1': {None: (set([]), None)},
'val2': {None: (set(['mandatory']), None)},
'val3': {None: (set([]), None)},
'val4': {None: (set([]), None)},
'val5': {None: (set(['empty']), None)}}
#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)}}
cfg.val3 = 'new2'
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
'val1': {None: (set([]), None)},
'val2': {None: (set(['mandatory']), None)},
'val3': {None: (set([]), None)},
'val4': {None: (set([]), None)},
'val5': {None: (set(['empty']), None)}}
#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)}}
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)},
'val2': {None: (set(['mandatory']), None)},
'val3': {None: (set([]), None)},
'val4': {None: (set([]), None)},
'val5': {None: (set(['empty']), None)}}
#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)}}
cfg.val4 = 'new3'
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
'val1': {None: (set([]), None)},
'val2': {None: (set(['mandatory']), None)},
'val3': {None: (set([]), None)},
'val4': {None: (set([]), None)},
'val5': {None: (set(['empty']), None)}}
#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)}}
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)},
'val2': {None: (set(['mandatory']), None)},
'val3': {None: (set([]), None)},
'val4': {None: (set([]), None)},
'val5': {None: (set(['empty']), None)}}
#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)}}
cfg.val5.append('new4')
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
'val1': {None: (set([]), None)},
'val2': {None: (set(['mandatory']), None)},
'val3': {None: (set([]), None)},
'val4': {None: (set([]), None)},
'val5': {None: (set(['empty']), None)}}
#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)}}
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)},
'val2': {None: (set(['mandatory']), None)},
'val3': {None: (set([]), None)},
'val4': {None: (set([]), None)},
'val5': {None: (set(['empty']), None)}}
#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)},
@ -544,6 +522,7 @@ def test_cache_master_and_slaves_master():
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)}}
@ -567,14 +546,15 @@ def test_cache_master_callback():
cfg.val1.val1.append()
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)}}
#assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([None], None)},
# 'val1.val2': {None: ([None], None), 0: (None, None)}}
#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)
@ -654,8 +634,7 @@ def test_cache_requires():
'activate_service': {None: (True, None)}}
c.ip_address_service = '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)},
'ip_address_service': {None: (set([]), 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()
@ -666,8 +645,7 @@ def test_cache_requires():
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
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_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()

View File

@ -190,12 +190,12 @@ def test_find_in_config():
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.unwrap_from_path('gc.gc2.prop'))
_is_same_opt(ret[1], conf.unwrap_from_path('gc.prop'))
_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'))
_is_same_opt(conf.find_first(byname='prop', force_permissive=True), conf.unwrap_from_path('gc.prop'))
_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')
@ -221,8 +221,8 @@ def test_find_in_config():
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.unwrap_from_path('gc.gc2.prop'))
_is_same_opt(ret[1], conf.unwrap_from_path('gc.prop'))
_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

View File

@ -153,7 +153,7 @@ def test_mod_dyndescription():
cfg.od.dodval2.stval2 = 'no'
assert cfg.od.dodval1.stval1 == 'yes'
assert cfg.od.dodval2.stval2 == 'no'
assert cfg.getowner(st) == owners.default
#assert cfg.getowner(st) == owners.default
assert cfg.getowner(stval1) == owner
assert cfg.getowner(stval2) == owner
@ -195,7 +195,7 @@ def test_multi_dyndescription():
cfg.od.dodval2.stval2 = ['no']
assert cfg.od.dodval1.stval1 == ['yes']
assert cfg.od.dodval2.stval2 == ['no']
assert cfg.getowner(st) == owners.default
#assert cfg.getowner(st) == owners.default
assert cfg.getowner(stval1) == owner
assert cfg.getowner(stval2) == owner
cfg.od.dodval1.stval1.append('yes')
@ -214,18 +214,18 @@ def test_prop_dyndescription():
stval2 = cfg.unwrap_from_path('od.dodval2.stval2')
dodval1 = cfg.unwrap_from_path('od.dodval1')
dodval2 = cfg.unwrap_from_path('od.dodval2')
assert str(cfg.cfgimpl_get_settings()[stval1]) in [str(['test']), str([u'test'])]
assert str(cfg.cfgimpl_get_settings()[stval2]) in [str(['test']), str([u'test'])]
assert set(cfg.cfgimpl_get_settings()[stval1].get()) == set(['test'])
assert set(cfg.cfgimpl_get_settings()[stval2].get()) == set(['test'])
cfg.cfgimpl_get_settings()[stval2].append('test2')
assert str(cfg.cfgimpl_get_settings()[stval1]) in [str(['test']), str([u'test'])]
assert str(cfg.cfgimpl_get_settings()[stval2]) in [str(['test', 'test2']), str([u'test', 'test2']), str(['test2', 'test'])]
assert set(cfg.cfgimpl_get_settings()[stval1].get()) == set(['test'])
assert set(cfg.cfgimpl_get_settings()[stval2].get()) == set(['test', 'test2'])
cfg.cfgimpl_get_settings()[stval1].remove('test')
assert str(cfg.cfgimpl_get_settings()[stval1]) == str([])
#
assert str(cfg.cfgimpl_get_settings()[dodval1]) == str([])
assert str(cfg.cfgimpl_get_settings()[dodval2]) == str([])
cfg.cfgimpl_get_settings()[dodval1].append('test1')
assert str(cfg.cfgimpl_get_settings()[dodval1]) in [str(['test1']), str([u'test1'])]
assert set(cfg.cfgimpl_get_settings()[dodval1].get()) == set(['test1'])
assert str(cfg.cfgimpl_get_settings()[dodval2]) == str([])
cfg.cfgimpl_get_settings()[dodval1].remove('test1')
assert str(cfg.cfgimpl_get_settings()[dodval1]) == str([])
@ -370,7 +370,7 @@ def test_mod_dyndescription_context():
cfg.od.dodval2.stval2 = 'no'
assert cfg.od.dodval1.stval1 == 'yes'
assert cfg.od.dodval2.stval2 == 'no'
assert cfg.getowner(st) == owners.default
#assert cfg.getowner(st) == owners.default
assert cfg.getowner(stval1) == owner
assert cfg.getowner(stval2) == owner
@ -414,7 +414,7 @@ def test_multi_dyndescription_context():
cfg.od.dodval2.stval2 = ['no']
assert cfg.od.dodval1.stval1 == ['yes']
assert cfg.od.dodval2.stval2 == ['no']
assert cfg.getowner(st) == owners.default
#assert cfg.getowner(st) == owners.default
assert cfg.getowner(stval1) == owner
assert cfg.getowner(stval2) == owner
cfg.od.dodval1.stval1.append('yes')
@ -533,99 +533,99 @@ def test_decrease_dyndescription_context():
#FIXME
# raises(AttributeError, "cfg.getowner(stval2)")
raises(AttributeError, "cfg.unwrap_from_path('od.dodval2.stval2')")
#
#
#def test_requires_dyndescription():
# boolean = BoolOption('boolean', '', True)
# st = StrOption('st', '', requires=[{'option': boolean, 'expected': False,
# 'action': 'disabled'}])
# dod = DynOptionDescription('dod', '', [st], callback=return_list)
# od = OptionDescription('od', '', [dod])
# od2 = OptionDescription('od', '', [od, boolean])
# cfg = Config(od2)
# cfg.read_write()
# assert cfg.od.dodval1.stval1 is None
# assert cfg.od.dodval2.stval2 is None
# #
# cfg.boolean = False
# props = []
# try:
# cfg.od.dodval1.stval1
# except PropertiesOptionError as err:
# props = err.proptype
# assert props == ['disabled']
# props = []
# try:
# cfg.od.dodval2.stval2
# except PropertiesOptionError as err:
# props = err.proptype
# assert props == ['disabled']
# #
# cfg.boolean = True
# assert cfg.od.dodval1.stval1 is None
# assert cfg.od.dodval2.stval2 is None
# #transitive
# cfg.cfgimpl_get_settings()[boolean].append('disabled')
# props = []
# try:
# cfg.od.dodval1.stval1
# except PropertiesOptionError as err:
# props = err.proptype
# assert props == ['disabled']
# props = []
# try:
# cfg.od.dodval2.stval2
# except PropertiesOptionError as err:
# props = err.proptype
# assert props == ['disabled']
def test_requires_dyndescription():
boolean = BoolOption('boolean', '', True)
st = StrOption('st', '', requires=[{'option': boolean, 'expected': False,
'action': 'disabled'}])
dod = DynOptionDescription('dod', '', [st], callback=return_list)
od = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od, boolean])
cfg = Config(od2)
cfg.read_write()
assert cfg.od.dodval1.stval1 is None
assert cfg.od.dodval2.stval2 is None
#
cfg.boolean = False
props = []
try:
cfg.od.dodval1.stval1
except PropertiesOptionError as err:
props = err.proptype
assert props == ['disabled']
props = []
try:
cfg.od.dodval2.stval2
except PropertiesOptionError as err:
props = err.proptype
assert props == ['disabled']
#
cfg.boolean = True
assert cfg.od.dodval1.stval1 is None
assert cfg.od.dodval2.stval2 is None
#transitive
cfg.cfgimpl_get_settings()[boolean].append('disabled')
props = []
try:
cfg.od.dodval1.stval1
except PropertiesOptionError as err:
props = err.proptype
assert props == ['disabled']
props = []
try:
cfg.od.dodval2.stval2
except PropertiesOptionError as err:
props = err.proptype
assert props == ['disabled']
def test_requires_dyndescription2():
boolean = BoolOption('boolean', '', True)
st = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st], callback=return_list,
requires=[{'option': boolean, 'expected': False,
'action': 'disabled'}])
od = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od, boolean])
cfg = Config(od2)
cfg.read_write()
assert cfg.od.dodval1.stval1 is None
assert cfg.od.dodval2.stval2 is None
#
cfg.boolean = False
props = []
try:
cfg.od.dodval1.stval1
except PropertiesOptionError as err:
props = err.proptype
assert props == ['disabled']
props = []
try:
cfg.od.dodval2.stval2
except PropertiesOptionError as err:
props = err.proptype
assert props == ['disabled']
#
cfg.boolean = True
assert cfg.od.dodval1.stval1 is None
assert cfg.od.dodval2.stval2 is None
#transitive
cfg.cfgimpl_get_settings()[boolean].append('disabled')
props = []
try:
cfg.od.dodval1.stval1
except PropertiesOptionError as err:
props = err.proptype
assert props == ['disabled']
props = []
try:
cfg.od.dodval2.stval2
except PropertiesOptionError as err:
props = err.proptype
assert props == ['disabled']
#def test_requires_dyndescription2():
# boolean = BoolOption('boolean', '', True)
# st = StrOption('st', '')
# dod = DynOptionDescription('dod', '', [st], callback=return_list,
# requires=[{'option': boolean, 'expected': False,
# 'action': 'disabled'}])
# od = OptionDescription('od', '', [dod])
# od2 = OptionDescription('od', '', [od, boolean])
# cfg = Config(od2)
# cfg.read_write()
# assert cfg.od.dodval1.stval1 is None
# assert cfg.od.dodval2.stval2 is None
# #
# cfg.boolean = False
# props = []
# try:
# cfg.od.dodval1.stval1
# except PropertiesOptionError as err:
# props = err.proptype
# assert props == ['disabled']
# props = []
# try:
# cfg.od.dodval2.stval2
# except PropertiesOptionError as err:
# props = err.proptype
# assert props == ['disabled']
# #
# cfg.boolean = True
# assert cfg.od.dodval1.stval1 is None
# assert cfg.od.dodval2.stval2 is None
# #transitive
# cfg.cfgimpl_get_settings()[boolean].append('disabled')
# props = []
# try:
# cfg.od.dodval1.stval1
# except PropertiesOptionError as err:
# props = err.proptype
# assert props == ['disabled']
# props = []
# try:
# cfg.od.dodval2.stval2
# except PropertiesOptionError as err:
# props = err.proptype
# assert props == ['disabled']
#
#
def test_validator_dyndescription():
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
st = StrOption('st', '', validator=return_true, validator_params={'': ('yes',)}, default='val')
@ -706,25 +706,25 @@ def test_information_dyndescription_context():
assert dod.impl_get_information('testod') == 'val1'
assert st.impl_get_information('testst') == 'val2'
assert cfg.impl_get_information('testcfgod') == 'val3'
def test_consistency_dyndescription():
st = StrOption('st', '')
st2 = StrOption('st2', '')
dod = DynOptionDescription('dod', '', [st, st2], callback=return_list)
od = OptionDescription('od', '', [dod])
st.impl_add_consistency('not_equal', st2)
od2 = OptionDescription('od', '', [od])
cfg = Config(od2)
cfg.od.dodval1.stval1 = 'yes'
raises(ValueError, "cfg.od.dodval1.st2val1 = 'yes'")
cfg.od.dodval2.stval2 = 'yes'
raises(ValueError, "cfg.od.dodval2.st2val2 = 'yes'")
raises(ValueError, "cfg.od.dodval1.st2val1 = 'yes'")
del(cfg.od.dodval2.stval2)
raises(ValueError, "cfg.od.dodval1.st2val1 = 'yes'")
cfg.od.dodval2.st2val2 = 'yes'
raises(ValueError, "cfg.od.dodval2.stval2 = 'yes'")
#
#
#def test_consistency_dyndescription():
# st = StrOption('st', '')
# st2 = StrOption('st2', '')
# dod = DynOptionDescription('dod', '', [st, st2], callback=return_list)
# od = OptionDescription('od', '', [dod])
# st.impl_add_consistency('not_equal', st2)
# od2 = OptionDescription('od', '', [od])
# cfg = Config(od2)
# cfg.od.dodval1.stval1 = 'yes'
# raises(ValueError, "cfg.od.dodval1.st2val1 = 'yes'")
# cfg.od.dodval2.stval2 = 'yes'
# raises(ValueError, "cfg.od.dodval2.st2val2 = 'yes'")
# raises(ValueError, "cfg.od.dodval1.st2val1 = 'yes'")
# del(cfg.od.dodval2.stval2)
# raises(ValueError, "cfg.od.dodval1.st2val1 = 'yes'")
# cfg.od.dodval2.st2val2 = 'yes'
# raises(ValueError, "cfg.od.dodval2.stval2 = 'yes'")
def test_consistency_dyndescription_default():
@ -893,197 +893,222 @@ def test_all_dyndescription():
assert cfg.dodval2.urlval2 is None
assert cfg.dodval2.usernameval2 is None
assert cfg.dodval2.filenameval2 is None
#
#
#def test_consistency_ip_netmask_dyndescription():
# a = IPOption('a', '')
# b = NetmaskOption('b', '')
# dod = DynOptionDescription('dod', '', [a, b], callback=return_list)
# b.impl_add_consistency('ip_netmask', a)
# od = OptionDescription('od', '', [dod])
# c = Config(od)
# c.dodval1.aval1 = '192.168.1.1'
# c.dodval1.bval1 = '255.255.255.0'
# c.dodval2.aval2 = '192.168.1.2'
# c.dodval2.bval2 = '255.255.255.255'
## c.dodval2.bval2 = '255.255.255.0'
#
#
#def test_consistency_ip_in_network_dyndescription():
# a = NetworkOption('a', '')
# b = NetmaskOption('b', '')
# c = IPOption('c', '')
# dod = DynOptionDescription('dod', '', [a, b, c], callback=return_list)
# c.impl_add_consistency('in_network', a, b)
# od = OptionDescription('od', '', [dod])
# cfg = Config(od)
# cfg.dodval1.aval1 = '192.168.1.0'
# cfg.dodval1.bval1 = '255.255.255.0'
# cfg.dodval1.cval1 = '192.168.1.1'
def test_consistency_ip_netmask_dyndescription():
a = IPOption('a', '')
b = NetmaskOption('b', '')
dod = DynOptionDescription('dod', '', [a, b], callback=return_list)
b.impl_add_consistency('ip_netmask', a)
od = OptionDescription('od', '', [dod])
c = Config(od)
c.dodval1.aval1 = '192.168.1.1'
c.dodval1.bval1 = '255.255.255.0'
c.dodval2.aval2 = '192.168.1.2'
c.dodval2.bval2 = '255.255.255.255'
c.dodval2.bval2 = '255.255.255.0'
def test_consistency_ip_in_network_dyndescription():
a = NetworkOption('a', '')
b = NetmaskOption('b', '')
c = IPOption('c', '')
dod = DynOptionDescription('dod', '', [a, b, c], callback=return_list)
c.impl_add_consistency('in_network', a, b)
od = OptionDescription('od', '', [dod])
cfg = Config(od)
cfg.dodval1.aval1 = '192.168.1.0'
cfg.dodval1.bval1 = '255.255.255.0'
cfg.dodval1.cval1 = '192.168.1.1'
def test_masterslaves_dyndescription():
st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True)
stm = MasterSlaves('st1', '', [st1, st2])
#stm.impl_set_group_type(groups.master)
st = DynOptionDescription('st', '', [stm], callback=return_list)
od = OptionDescription('od', '', [st])
od2 = OptionDescription('od', '', [od])
cfg = Config(od2)
owner = cfg.cfgimpl_get_settings().getowner()
st1val1 = cfg.unwrap_from_path('od.stval1.st1val1.st1val1')
st2val1 = cfg.unwrap_from_path('od.stval1.st1val1.st2val1')
st1val2 = cfg.unwrap_from_path('od.stval2.st1val2.st1val2')
st2val2 = cfg.unwrap_from_path('od.stval2.st1val2.st2val2')
assert cfg.make_dict() == {'od.stval1.st1val1.st2val1': [], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': []}
assert cfg.od.stval1.st1val1.st1val1 == []
assert cfg.od.stval1.st1val1.st2val1 == []
assert cfg.od.stval2.st1val2.st1val2 == []
assert cfg.od.stval2.st1val2.st2val2 == []
assert cfg.getowner(st1val1) == owners.default
assert cfg.getowner(st1val2) == owners.default
assert cfg.getowner(st2val1) == owners.default
assert cfg.getowner(st2val2) == owners.default
#
cfg.od.stval1.st1val1.st1val1.append('yes')
assert cfg.make_dict() == {'od.stval1.st1val1.st2val1': [None], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': ['yes']}
assert cfg.od.stval1.st1val1.st1val1 == ['yes']
assert cfg.od.stval1.st1val1.st2val1 == [None]
assert cfg.od.stval2.st1val2.st1val2 == []
assert cfg.od.stval2.st1val2.st2val2 == []
assert cfg.getowner(st1val1) == owner
assert cfg.getowner(st1val2) == owners.default
assert cfg.getowner(st2val1) == owners.default
assert cfg.getowner(st2val2) == owners.default
#
cfg.od.stval1.st1val1.st1val1 = ['yes']
assert cfg.od.stval1.st1val1.st1val1 == ['yes']
assert cfg.od.stval1.st1val1.st2val1 == [None]
assert cfg.od.stval2.st1val2.st1val2 == []
assert cfg.od.stval2.st1val2.st2val2 == []
assert cfg.getowner(st1val1) == owner
assert cfg.getowner(st1val2) == owners.default
assert cfg.getowner(st2val1) == owners.default
assert cfg.getowner(st2val2) == owners.default
#
cfg.od.stval1.st1val1.st2val1 = ['no']
assert cfg.od.stval1.st1val1.st1val1 == ['yes']
assert cfg.od.stval1.st1val1.st2val1 == ['no']
assert cfg.od.stval2.st1val2.st1val2 == []
assert cfg.od.stval2.st1val2.st2val2 == []
assert cfg.getowner(st1val1) == owner
assert cfg.getowner(st1val2) == owners.default
assert cfg.getowner(st2val1, 0) == owner
#def test_masterslaves_dyndescription():
# st1 = StrOption('st1', "", multi=True)
# st2 = StrOption('st2', "", multi=True)
# stm = MasterSlaves('st1', '', [st1, st2])
# #stm.impl_set_group_type(groups.master)
# st = DynOptionDescription('st', '', [stm], callback=return_list)
# od = OptionDescription('od', '', [st])
# od2 = OptionDescription('od', '', [od])
# cfg = Config(od2)
# print('--------------- 1')
# owner = cfg.cfgimpl_get_settings().getowner()
# print('--------------- 2')
# st1val1 = cfg.unwrap_from_path('od.stval1.st1val1.st1val1')
# print('--------------- 3')
# st2val1 = cfg.unwrap_from_path('od.stval1.st1val1.st2val1')
# print('--------------- 4')
# st1val2 = cfg.unwrap_from_path('od.stval2.st1val2.st1val2')
# print('--------------- 5')
# st2val2 = cfg.unwrap_from_path('od.stval2.st1val2.st2val2')
# print('--------------- 6')
# assert cfg.make_dict() == {'od.stval1.st1val1.st2val1': [], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': []}
# print('--------------- 7')
# assert cfg.od.stval1.st1val1.st1val1 == []
# print('--------------- 8')
# assert cfg.od.stval1.st1val1.st2val1 == []
# print('--------------- 9')
# assert cfg.od.stval2.st1val2.st1val2 == []
# print('--------------- 10')
# assert cfg.od.stval2.st1val2.st2val2 == []
# print('--------------- 11')
# assert cfg.getowner(st1val1) == owners.default
# print('--------------- 12')
# assert cfg.getowner(st1val2) == owners.default
# print('--------------- 13')
# assert cfg.getowner(st2val1) == owners.default
# print('--------------- 14')
# assert cfg.getowner(st2val2) == owners.default
#
cfg.od.stval1.st1val1.st1val1.pop(0)
assert cfg.od.stval1.st1val1.st1val1 == []
assert cfg.od.stval1.st1val1.st2val1 == []
assert cfg.od.stval2.st1val2.st1val2 == []
assert cfg.od.stval2.st1val2.st2val2 == []
assert cfg.getowner(st1val1) == owner
assert cfg.getowner(st1val2) == owners.default
# assert cfg.getowner(st2val1) == owner
# print('--------------- 15')
# #
# cfg.od.stval1.st1val1.st1val1.append('yes')
# print('--------------- 16')
# assert cfg.make_dict() == {'od.stval1.st1val1.st2val1': [None], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': ['yes']}
# print('--------------- 17')
# assert cfg.od.stval1.st1val1.st1val1 == ['yes']
# print('--------------- 18')
# assert cfg.od.stval1.st1val1.st2val1 == [None]
# print('--------------- 19')
# assert cfg.od.stval2.st1val2.st1val2 == []
# print('--------------- 20')
# assert cfg.od.stval2.st1val2.st2val2 == []
# print('--------------- 21')
# assert cfg.getowner(st1val1) == owner
# print('--------------- 22')
# assert cfg.getowner(st1val2) == owners.default
# print('--------------- 23')
# assert cfg.getowner(st2val1) == owners.default
# print('--------------- 24')
# assert cfg.getowner(st2val2) == owners.default
#
cfg.od.stval1.st1val1.st1val1 = ['yes']
cfg.od.stval1.st1val1.st2val1 = ['yes']
assert cfg.getowner(st1val1) == owner
assert cfg.getowner(st2val1, 0) == owner
del(cfg.od.stval1.st1val1.st2val1)
assert cfg.getowner(st1val1) == owner
assert cfg.getowner(st1val2) == owners.default
# print('--------------- 25')
# #
# cfg.od.stval1.st1val1.st1val1 = ['yes']
# assert cfg.od.stval1.st1val1.st1val1 == ['yes']
# assert cfg.od.stval1.st1val1.st2val1 == [None]
# assert cfg.od.stval2.st1val2.st1val2 == []
# assert cfg.od.stval2.st1val2.st2val2 == []
# assert cfg.getowner(st1val1) == owner
# assert cfg.getowner(st1val2) == owners.default
# assert cfg.getowner(st2val1) == owners.default
# assert cfg.getowner(st2val2) == owners.default
#
cfg.od.stval1.st1val1.st1val1 = ['yes']
cfg.od.stval1.st1val1.st2val1 = ['yes']
del(cfg.od.stval1.st1val1.st1val1)
assert cfg.od.stval1.st1val1.st1val1 == []
assert cfg.od.stval1.st1val1.st2val1 == []
assert cfg.od.stval2.st1val2.st1val2 == []
assert cfg.od.stval2.st1val2.st2val2 == []
assert cfg.getowner(st1val1) == owners.default
assert cfg.getowner(st1val2) == owners.default
assert cfg.getowner(st2val1) == owners.default
assert cfg.getowner(st2val2) == owners.default
def test_masterslaves_default_multi_dyndescription():
st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True, default_multi='no')
stm = MasterSlaves('st1', '', [st1, st2])
#stm.impl_set_group_type(groups.master)
st = DynOptionDescription('st', '', [stm], callback=return_list)
od = OptionDescription('od', '', [st])
od2 = OptionDescription('od', '', [od])
cfg = Config(od2)
owner = cfg.cfgimpl_get_settings().getowner()
st1val1 = cfg.unwrap_from_path('od.stval1.st1val1.st1val1')
st2val1 = cfg.unwrap_from_path('od.stval1.st1val1.st2val1')
st1val2 = cfg.unwrap_from_path('od.stval2.st1val2.st1val2')
st2val2 = cfg.unwrap_from_path('od.stval2.st1val2.st2val2')
assert cfg.od.stval1.st1val1.st1val1 == []
assert cfg.od.stval1.st1val1.st2val1 == []
assert cfg.od.stval2.st1val2.st1val2 == []
assert cfg.od.stval2.st1val2.st2val2 == []
assert cfg.getowner(st1val1) == owners.default
assert cfg.getowner(st1val2) == owners.default
assert cfg.getowner(st2val1) == owners.default
assert cfg.getowner(st2val2) == owners.default
cfg.od.stval1.st1val1.st1val1.append('yes')
assert cfg.od.stval1.st1val1.st1val1 == ['yes']
assert cfg.od.stval1.st1val1.st2val1 == ['no']
assert cfg.od.stval2.st1val2.st1val2 == []
assert cfg.od.stval2.st1val2.st2val2 == []
assert cfg.getowner(st1val1) == owner
assert cfg.getowner(st1val2) == owners.default
assert cfg.getowner(st2val1) == owners.default
assert cfg.getowner(st2val2) == owners.default
def test_masterslaves_submulti_dyndescription():
st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=submulti)
stm = MasterSlaves('st1', '', [st1, st2])
#stm.impl_set_group_type(groups.master)
st = DynOptionDescription('st', '', [stm], callback=return_list)
od = OptionDescription('od', '', [st])
od2 = OptionDescription('od', '', [od])
cfg = Config(od2)
owner = cfg.cfgimpl_get_settings().getowner()
st1val1 = cfg.unwrap_from_path('od.stval1.st1val1.st1val1')
st2val1 = cfg.unwrap_from_path('od.stval1.st1val1.st2val1')
st1val2 = cfg.unwrap_from_path('od.stval2.st1val2.st1val2')
st2val2 = cfg.unwrap_from_path('od.stval2.st1val2.st2val2')
assert cfg.od.stval1.st1val1.st1val1 == []
assert cfg.od.stval1.st1val1.st2val1 == []
assert cfg.od.stval2.st1val2.st1val2 == []
assert cfg.od.stval2.st1val2.st2val2 == []
assert cfg.getowner(st1val1) == owners.default
assert cfg.getowner(st1val2) == owners.default
assert cfg.getowner(st2val1) == owners.default
assert cfg.getowner(st2val2) == owners.default
cfg.od.stval1.st1val1.st1val1.append('yes')
assert cfg.od.stval1.st1val1.st1val1 == ['yes']
assert cfg.od.stval1.st1val1.st2val1 == [[]]
assert cfg.od.stval2.st1val2.st1val2 == []
assert cfg.od.stval2.st1val2.st2val2 == []
assert cfg.getowner(st1val1) == owner
assert cfg.getowner(st1val2) == owners.default
assert cfg.getowner(st2val1) == owners.default
assert cfg.getowner(st2val2) == owners.default
#
cfg.od.stval1.st1val1.st2val1[0].append('no')
assert cfg.od.stval1.st1val1.st1val1 == ['yes']
assert cfg.od.stval1.st1val1.st2val1 == [['no']]
assert cfg.od.stval2.st1val2.st1val2 == []
assert cfg.od.stval2.st1val2.st2val2 == []
assert cfg.getowner(st1val1) == owner
assert cfg.getowner(st1val2) == owners.default
assert cfg.getowner(st2val1, 0) == owner
assert cfg.getowner(st2val2) == owners.default
# #
# cfg.od.stval1.st1val1.st2val1 = ['no']
# assert cfg.od.stval1.st1val1.st1val1 == ['yes']
# assert cfg.od.stval1.st1val1.st2val1 == ['no']
# assert cfg.od.stval2.st1val2.st1val2 == []
# assert cfg.od.stval2.st1val2.st2val2 == []
# assert cfg.getowner(st1val1) == owner
# assert cfg.getowner(st1val2) == owners.default
# assert cfg.getowner(st2val1, 0) == owner
## assert cfg.getowner(st2val2) == owners.default
# #
# cfg.od.stval1.st1val1.st1val1.pop(0)
# assert cfg.od.stval1.st1val1.st1val1 == []
# assert cfg.od.stval1.st1val1.st2val1 == []
# assert cfg.od.stval2.st1val2.st1val2 == []
# assert cfg.od.stval2.st1val2.st2val2 == []
# assert cfg.getowner(st1val1) == owner
# assert cfg.getowner(st1val2) == owners.default
## assert cfg.getowner(st2val1) == owner
## assert cfg.getowner(st2val2) == owners.default
# #
# cfg.od.stval1.st1val1.st1val1 = ['yes']
# cfg.od.stval1.st1val1.st2val1 = ['yes']
# assert cfg.getowner(st1val1) == owner
# assert cfg.getowner(st2val1, 0) == owner
# del(cfg.od.stval1.st1val1.st2val1)
# assert cfg.getowner(st1val1) == owner
# assert cfg.getowner(st1val2) == owners.default
## assert cfg.getowner(st2val1) == owners.default
## assert cfg.getowner(st2val2) == owners.default
# #
# cfg.od.stval1.st1val1.st1val1 = ['yes']
# cfg.od.stval1.st1val1.st2val1 = ['yes']
# del(cfg.od.stval1.st1val1.st1val1)
# assert cfg.od.stval1.st1val1.st1val1 == []
# assert cfg.od.stval1.st1val1.st2val1 == []
# assert cfg.od.stval2.st1val2.st1val2 == []
# assert cfg.od.stval2.st1val2.st2val2 == []
# assert cfg.getowner(st1val1) == owners.default
# assert cfg.getowner(st1val2) == owners.default
# assert cfg.getowner(st2val1) == owners.default
# assert cfg.getowner(st2val2) == owners.default
#
#
#def test_masterslaves_default_multi_dyndescription():
# st1 = StrOption('st1', "", multi=True)
# st2 = StrOption('st2', "", multi=True, default_multi='no')
# stm = MasterSlaves('st1', '', [st1, st2])
# #stm.impl_set_group_type(groups.master)
# st = DynOptionDescription('st', '', [stm], callback=return_list)
# od = OptionDescription('od', '', [st])
# od2 = OptionDescription('od', '', [od])
# cfg = Config(od2)
# owner = cfg.cfgimpl_get_settings().getowner()
# st1val1 = cfg.unwrap_from_path('od.stval1.st1val1.st1val1')
# st2val1 = cfg.unwrap_from_path('od.stval1.st1val1.st2val1')
# st1val2 = cfg.unwrap_from_path('od.stval2.st1val2.st1val2')
# st2val2 = cfg.unwrap_from_path('od.stval2.st1val2.st2val2')
# assert cfg.od.stval1.st1val1.st1val1 == []
# assert cfg.od.stval1.st1val1.st2val1 == []
# assert cfg.od.stval2.st1val2.st1val2 == []
# assert cfg.od.stval2.st1val2.st2val2 == []
# assert cfg.getowner(st1val1) == owners.default
# assert cfg.getowner(st1val2) == owners.default
# assert cfg.getowner(st2val1) == owners.default
# assert cfg.getowner(st2val2) == owners.default
# cfg.od.stval1.st1val1.st1val1.append('yes')
# assert cfg.od.stval1.st1val1.st1val1 == ['yes']
# assert cfg.od.stval1.st1val1.st2val1 == ['no']
# assert cfg.od.stval2.st1val2.st1val2 == []
# assert cfg.od.stval2.st1val2.st2val2 == []
# assert cfg.getowner(st1val1) == owner
# assert cfg.getowner(st1val2) == owners.default
# assert cfg.getowner(st2val1) == owners.default
# assert cfg.getowner(st2val2) == owners.default
#
#
#def test_masterslaves_submulti_dyndescription():
# st1 = StrOption('st1', "", multi=True)
# st2 = StrOption('st2', "", multi=submulti)
# stm = MasterSlaves('st1', '', [st1, st2])
# #stm.impl_set_group_type(groups.master)
# st = DynOptionDescription('st', '', [stm], callback=return_list)
# od = OptionDescription('od', '', [st])
# od2 = OptionDescription('od', '', [od])
# cfg = Config(od2)
# owner = cfg.cfgimpl_get_settings().getowner()
# st1val1 = cfg.unwrap_from_path('od.stval1.st1val1.st1val1')
# st2val1 = cfg.unwrap_from_path('od.stval1.st1val1.st2val1')
# st1val2 = cfg.unwrap_from_path('od.stval2.st1val2.st1val2')
# st2val2 = cfg.unwrap_from_path('od.stval2.st1val2.st2val2')
# assert cfg.od.stval1.st1val1.st1val1 == []
# assert cfg.od.stval1.st1val1.st2val1 == []
# assert cfg.od.stval2.st1val2.st1val2 == []
# assert cfg.od.stval2.st1val2.st2val2 == []
# assert cfg.getowner(st1val1) == owners.default
# assert cfg.getowner(st1val2) == owners.default
# assert cfg.getowner(st2val1) == owners.default
# assert cfg.getowner(st2val2) == owners.default
# cfg.od.stval1.st1val1.st1val1.append('yes')
# assert cfg.od.stval1.st1val1.st1val1 == ['yes']
# assert cfg.od.stval1.st1val1.st2val1 == [[]]
# assert cfg.od.stval2.st1val2.st1val2 == []
# assert cfg.od.stval2.st1val2.st2val2 == []
# assert cfg.getowner(st1val1) == owner
# assert cfg.getowner(st1val2) == owners.default
# assert cfg.getowner(st2val1) == owners.default
# assert cfg.getowner(st2val2) == owners.default
# #
# cfg.od.stval1.st1val1.st2val1[0].append('no')
# assert cfg.od.stval1.st1val1.st1val1 == ['yes']
# assert cfg.od.stval1.st1val1.st2val1 == [['no']]
# assert cfg.od.stval2.st1val2.st1val2 == []
# assert cfg.od.stval2.st1val2.st2val2 == []
# assert cfg.getowner(st1val1) == owner
# assert cfg.getowner(st1val2) == owners.default
# assert cfg.getowner(st2val1, 0) == owner
# assert cfg.getowner(st2val2) == owners.default
#def test_masterslaves_consistency_ip_dyndescription():
@ -1127,187 +1152,187 @@ def test_masterslaves_submulti_dyndescription():
# cfg.netval1.netval1 = ['192.168.1.0']
# cfg.read_only()
# raises(PropertiesOptionError, "cfg.netval1.netval1")
def test_masterslaves_callback_dyndescription():
st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True, callback=return_dynval, callback_params={'value': ((st1, False),)})
stm = MasterSlaves('st1', '', [st1, st2])
#stm.impl_set_group_type(groups.master)
st = DynOptionDescription('st', '', [stm], callback=return_list)
od = OptionDescription('od', '', [st])
od2 = OptionDescription('od', '', [od])
cfg = Config(od2)
owner = cfg.cfgimpl_get_settings().getowner()
st1val1 = cfg.unwrap_from_path('od.stval1.st1val1.st1val1')
st2val1 = cfg.unwrap_from_path('od.stval1.st1val1.st2val1')
st1val2 = cfg.unwrap_from_path('od.stval2.st1val2.st1val2')
st2val2 = cfg.unwrap_from_path('od.stval2.st1val2.st2val2')
assert cfg.make_dict() == {'od.stval1.st1val1.st2val1': [], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': []}
assert cfg.od.stval1.st1val1.st1val1 == []
assert cfg.od.stval1.st1val1.st2val1 == []
assert cfg.od.stval2.st1val2.st1val2 == []
assert cfg.od.stval2.st1val2.st2val2 == []
assert cfg.getowner(st1val1) == owners.default
assert cfg.getowner(st1val2) == owners.default
assert cfg.getowner(st2val1) == owners.default
assert cfg.getowner(st2val2) == owners.default
#
cfg.od.stval1.st1val1.st1val1.append('yes')
assert cfg.make_dict() == {'od.stval1.st1val1.st2val1': ['yes'], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': ['yes']}
assert cfg.od.stval1.st1val1.st1val1 == ['yes']
assert cfg.od.stval1.st1val1.st2val1 == ['yes']
assert cfg.od.stval2.st1val2.st1val2 == []
assert cfg.od.stval2.st1val2.st2val2 == []
assert cfg.getowner(st1val1) == owner
assert cfg.getowner(st1val2) == owners.default
assert cfg.getowner(st2val1) == owners.default
assert cfg.getowner(st2val2) == owners.default
#
cfg.od.stval1.st1val1.st2val1 = ['no']
assert cfg.od.stval1.st1val1.st1val1 == ['yes']
assert cfg.od.stval1.st1val1.st2val1 == ['no']
assert cfg.od.stval2.st1val2.st1val2 == []
assert cfg.od.stval2.st1val2.st2val2 == []
assert cfg.getowner(st1val1) == owner
assert cfg.getowner(st1val2) == owners.default
assert cfg.getowner(st2val1, 0) == owner
#
#
#def test_masterslaves_callback_dyndescription():
# st1 = StrOption('st1', "", multi=True)
# st2 = StrOption('st2', "", multi=True, callback=return_dynval, callback_params={'value': ((st1, False),)})
# stm = MasterSlaves('st1', '', [st1, st2])
# #stm.impl_set_group_type(groups.master)
# st = DynOptionDescription('st', '', [stm], callback=return_list)
# od = OptionDescription('od', '', [st])
# od2 = OptionDescription('od', '', [od])
# cfg = Config(od2)
# owner = cfg.cfgimpl_get_settings().getowner()
# st1val1 = cfg.unwrap_from_path('od.stval1.st1val1.st1val1')
# st2val1 = cfg.unwrap_from_path('od.stval1.st1val1.st2val1')
# st1val2 = cfg.unwrap_from_path('od.stval2.st1val2.st1val2')
# st2val2 = cfg.unwrap_from_path('od.stval2.st1val2.st2val2')
# assert cfg.make_dict() == {'od.stval1.st1val1.st2val1': [], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': []}
# assert cfg.od.stval1.st1val1.st1val1 == []
# assert cfg.od.stval1.st1val1.st2val1 == []
# assert cfg.od.stval2.st1val2.st1val2 == []
# assert cfg.od.stval2.st1val2.st2val2 == []
# assert cfg.getowner(st1val1) == owners.default
# assert cfg.getowner(st1val2) == owners.default
# assert cfg.getowner(st2val1) == owners.default
# assert cfg.getowner(st2val2) == owners.default
#
cfg.od.stval1.st1val1.st1val1.pop(0)
assert cfg.od.stval1.st1val1.st1val1 == []
assert cfg.od.stval1.st1val1.st2val1 == []
assert cfg.od.stval2.st1val2.st1val2 == []
assert cfg.od.stval2.st1val2.st2val2 == []
assert cfg.getowner(st1val1) == owner
assert cfg.getowner(st1val2) == owners.default
# assert cfg.getowner(st2val1) == owner
# #
# cfg.od.stval1.st1val1.st1val1.append('yes')
# assert cfg.make_dict() == {'od.stval1.st1val1.st2val1': ['yes'], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': ['yes']}
# assert cfg.od.stval1.st1val1.st1val1 == ['yes']
# assert cfg.od.stval1.st1val1.st2val1 == ['yes']
# assert cfg.od.stval2.st1val2.st1val2 == []
# assert cfg.od.stval2.st1val2.st2val2 == []
# assert cfg.getowner(st1val1) == owner
# assert cfg.getowner(st1val2) == owners.default
# assert cfg.getowner(st2val1) == owners.default
# assert cfg.getowner(st2val2) == owners.default
#
cfg.od.stval1.st1val1.st1val1 = ['yes']
cfg.od.stval1.st1val1.st2val1 = ['yes']
assert cfg.getowner(st1val1) == owner
assert cfg.getowner(st2val1, 0) == owner
del(cfg.od.stval1.st1val1.st2val1)
assert cfg.getowner(st1val1) == owner
assert cfg.getowner(st1val2) == owners.default
assert cfg.getowner(st2val1) == owners.default
assert cfg.getowner(st2val2) == owners.default
#
cfg.od.stval1.st1val1.st1val1 = ['yes']
cfg.od.stval1.st1val1.st2val1 = ['yes']
del(cfg.od.stval1.st1val1.st1val1)
assert cfg.od.stval1.st1val1.st1val1 == []
assert cfg.od.stval1.st1val1.st2val1 == []
assert cfg.od.stval2.st1val2.st1val2 == []
assert cfg.od.stval2.st1val2.st2val2 == []
assert cfg.getowner(st1val1) == owners.default
assert cfg.getowner(st1val2) == owners.default
assert cfg.getowner(st2val1) == owners.default
assert cfg.getowner(st2val2) == owners.default
#
cfg.od.stval1.st1val1.st2val1 = []
cfg.od.stval1.st1val1.st1val1 = ['yes']
assert cfg.od.stval1.st1val1.st2val1 == ['yes']
def test_masterslaves_callback_value_dyndescription():
st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True, callback=return_dynval, callback_params={'value': ('val',)})
stm = MasterSlaves('st1', '', [st1, st2])
#stm.impl_set_group_type(groups.master)
st = DynOptionDescription('st', '', [stm], callback=return_list)
od = OptionDescription('od', '', [st])
od2 = OptionDescription('od', '', [od])
cfg = Config(od2)
assert cfg.od.stval1.st1val1.st1val1 == []
assert cfg.od.stval1.st1val1.st2val1 == []
cfg.od.stval1.st1val1.st1val1.append('yes')
assert cfg.od.stval1.st1val1.st1val1 == ['yes']
assert cfg.od.stval1.st1val1.st2val1[0] == 'val'
assert cfg.od.stval1.st1val1.st2val1 == ['val']
def test_masterslaves_callback_nomulti_dyndescription():
v1 = StrOption('v1', '', "val")
st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True, callback=return_dynval, callback_params={'': ((v1, False),)})
stm = MasterSlaves('st1', '', [st1, st2])
#stm.impl_set_group_type(groups.master)
st = DynOptionDescription('st', '', [stm], callback=return_list)
od = OptionDescription('od', '', [st])
od2 = OptionDescription('od', '', [od, v1])
cfg = Config(od2)
assert cfg.od.stval1.st1val1.st1val1 == []
assert cfg.od.stval1.st1val1.st2val1 == []
cfg.od.stval1.st1val1.st1val1.append('yes')
assert cfg.od.stval1.st1val1.st1val1 == ['yes']
assert cfg.od.stval1.st1val1.st2val1 == ['val']
def test_masterslaves_callback_samegroup_dyndescription():
st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True)
st3 = StrOption('st3', "", multi=True, callback=return_dynval, callback_params={'': ((st2, False),)})
stm = MasterSlaves('st1', '', [st1, st2, st3])
#stm.impl_set_group_type(groups.master)
st = DynOptionDescription('st', '', [stm], callback=return_list)
od = OptionDescription('od', '', [st])
od2 = OptionDescription('od', '', [od])
cfg = Config(od2)
owner = cfg.cfgimpl_get_settings().getowner()
st1val1 = cfg.unwrap_from_path('od.stval1.st1val1.st1val1')
st2val1 = cfg.unwrap_from_path('od.stval1.st1val1.st2val1')
st3val1 = cfg.unwrap_from_path('od.stval1.st1val1.st3val1')
st1val2 = cfg.unwrap_from_path('od.stval2.st1val2.st1val2')
st2val2 = cfg.unwrap_from_path('od.stval2.st1val2.st2val2')
st3val2 = cfg.unwrap_from_path('od.stval2.st1val2.st3val2')
assert cfg.make_dict() == {'od.stval1.st1val1.st1val1': [],
'od.stval1.st1val1.st2val1': [],
'od.stval1.st1val1.st3val1': [],
'od.stval2.st1val2.st1val2': [],
'od.stval2.st1val2.st2val2': [],
'od.stval2.st1val2.st3val2': []}
assert cfg.od.stval1.st1val1.st1val1 == []
assert cfg.od.stval1.st1val1.st2val1 == []
assert cfg.od.stval1.st1val1.st3val1 == []
assert cfg.od.stval2.st1val2.st1val2 == []
assert cfg.od.stval2.st1val2.st2val2 == []
assert cfg.od.stval2.st1val2.st3val2 == []
assert cfg.getowner(st1val1) == owners.default
assert cfg.getowner(st1val2) == owners.default
assert cfg.getowner(st2val1) == owners.default
assert cfg.getowner(st2val2) == owners.default
assert cfg.getowner(st3val1) == owners.default
assert cfg.getowner(st3val2) == owners.default
##
cfg.od.stval1.st1val1.st1val1.append('yes')
assert cfg.make_dict() == {'od.stval1.st1val1.st1val1': ['yes'],
'od.stval1.st1val1.st2val1': [None],
'od.stval1.st1val1.st3val1': [None],
'od.stval2.st1val2.st1val2': [],
'od.stval2.st1val2.st2val2': [],
'od.stval2.st1val2.st3val2': []}
assert cfg.getowner(st1val1) == owner
assert cfg.getowner(st1val2) == owners.default
assert cfg.getowner(st2val1) == owners.default
assert cfg.getowner(st2val2) == owners.default
assert cfg.getowner(st3val1) == owners.default
assert cfg.getowner(st3val2) == owners.default
#
cfg.od.stval1.st1val1.st2val1[0] = 'yes'
assert cfg.make_dict() == {'od.stval1.st1val1.st1val1': ['yes'],
'od.stval1.st1val1.st2val1': ['yes'],
'od.stval1.st1val1.st3val1': ['yes'],
'od.stval2.st1val2.st1val2': [],
'od.stval2.st1val2.st2val2': [],
'od.stval2.st1val2.st3val2': []}
assert cfg.getowner(st1val1) == owner
assert cfg.getowner(st2val1, 0) == owner
assert cfg.getowner(st3val1, 0) == owners.default
assert cfg.getowner(st1val2) == owners.default
#assert cfg.getowner(st2val2) == owners.default
#assert cfg.getowner(st3val2) == owners.default
# #
# cfg.od.stval1.st1val1.st2val1 = ['no']
# assert cfg.od.stval1.st1val1.st1val1 == ['yes']
# assert cfg.od.stval1.st1val1.st2val1 == ['no']
# assert cfg.od.stval2.st1val2.st1val2 == []
# assert cfg.od.stval2.st1val2.st2val2 == []
# assert cfg.getowner(st1val1) == owner
# assert cfg.getowner(st1val2) == owners.default
# assert cfg.getowner(st2val1, 0) == owner
## assert cfg.getowner(st2val2) == owners.default
# #
# cfg.od.stval1.st1val1.st1val1.pop(0)
# assert cfg.od.stval1.st1val1.st1val1 == []
# assert cfg.od.stval1.st1val1.st2val1 == []
# assert cfg.od.stval2.st1val2.st1val2 == []
# assert cfg.od.stval2.st1val2.st2val2 == []
# assert cfg.getowner(st1val1) == owner
# assert cfg.getowner(st1val2) == owners.default
## assert cfg.getowner(st2val1) == owner
## assert cfg.getowner(st2val2) == owners.default
# #
# cfg.od.stval1.st1val1.st1val1 = ['yes']
# cfg.od.stval1.st1val1.st2val1 = ['yes']
# assert cfg.getowner(st1val1) == owner
# assert cfg.getowner(st2val1, 0) == owner
# del(cfg.od.stval1.st1val1.st2val1)
# assert cfg.getowner(st1val1) == owner
# assert cfg.getowner(st1val2) == owners.default
# assert cfg.getowner(st2val1) == owners.default
# assert cfg.getowner(st2val2) == owners.default
# #
# cfg.od.stval1.st1val1.st1val1 = ['yes']
# cfg.od.stval1.st1val1.st2val1 = ['yes']
# del(cfg.od.stval1.st1val1.st1val1)
# assert cfg.od.stval1.st1val1.st1val1 == []
# assert cfg.od.stval1.st1val1.st2val1 == []
# assert cfg.od.stval2.st1val2.st1val2 == []
# assert cfg.od.stval2.st1val2.st2val2 == []
# assert cfg.getowner(st1val1) == owners.default
# assert cfg.getowner(st1val2) == owners.default
# assert cfg.getowner(st2val1) == owners.default
# assert cfg.getowner(st2val2) == owners.default
# #
# cfg.od.stval1.st1val1.st2val1 = []
# cfg.od.stval1.st1val1.st1val1 = ['yes']
# assert cfg.od.stval1.st1val1.st2val1 == ['yes']
#
#
#def test_masterslaves_callback_value_dyndescription():
# st1 = StrOption('st1', "", multi=True)
# st2 = StrOption('st2', "", multi=True, callback=return_dynval, callback_params={'value': ('val',)})
# stm = MasterSlaves('st1', '', [st1, st2])
# #stm.impl_set_group_type(groups.master)
# st = DynOptionDescription('st', '', [stm], callback=return_list)
# od = OptionDescription('od', '', [st])
# od2 = OptionDescription('od', '', [od])
# cfg = Config(od2)
# assert cfg.od.stval1.st1val1.st1val1 == []
# assert cfg.od.stval1.st1val1.st2val1 == []
# cfg.od.stval1.st1val1.st1val1.append('yes')
# assert cfg.od.stval1.st1val1.st1val1 == ['yes']
# assert cfg.od.stval1.st1val1.st2val1[0] == 'val'
# assert cfg.od.stval1.st1val1.st2val1 == ['val']
#
#
#def test_masterslaves_callback_nomulti_dyndescription():
# v1 = StrOption('v1', '', "val")
# st1 = StrOption('st1', "", multi=True)
# st2 = StrOption('st2', "", multi=True, callback=return_dynval, callback_params={'': ((v1, False),)})
# stm = MasterSlaves('st1', '', [st1, st2])
# #stm.impl_set_group_type(groups.master)
# st = DynOptionDescription('st', '', [stm], callback=return_list)
# od = OptionDescription('od', '', [st])
# od2 = OptionDescription('od', '', [od, v1])
# cfg = Config(od2)
# assert cfg.od.stval1.st1val1.st1val1 == []
# assert cfg.od.stval1.st1val1.st2val1 == []
# cfg.od.stval1.st1val1.st1val1.append('yes')
# assert cfg.od.stval1.st1val1.st1val1 == ['yes']
# assert cfg.od.stval1.st1val1.st2val1 == ['val']
#
#
#def test_masterslaves_callback_samegroup_dyndescription():
# st1 = StrOption('st1', "", multi=True)
# st2 = StrOption('st2', "", multi=True)
# st3 = StrOption('st3', "", multi=True, callback=return_dynval, callback_params={'': ((st2, False),)})
# stm = MasterSlaves('st1', '', [st1, st2, st3])
# #stm.impl_set_group_type(groups.master)
# st = DynOptionDescription('st', '', [stm], callback=return_list)
# od = OptionDescription('od', '', [st])
# od2 = OptionDescription('od', '', [od])
# cfg = Config(od2)
# owner = cfg.cfgimpl_get_settings().getowner()
# st1val1 = cfg.unwrap_from_path('od.stval1.st1val1.st1val1')
# st2val1 = cfg.unwrap_from_path('od.stval1.st1val1.st2val1')
# st3val1 = cfg.unwrap_from_path('od.stval1.st1val1.st3val1')
# st1val2 = cfg.unwrap_from_path('od.stval2.st1val2.st1val2')
# st2val2 = cfg.unwrap_from_path('od.stval2.st1val2.st2val2')
# st3val2 = cfg.unwrap_from_path('od.stval2.st1val2.st3val2')
# assert cfg.make_dict() == {'od.stval1.st1val1.st1val1': [],
# 'od.stval1.st1val1.st2val1': [],
# 'od.stval1.st1val1.st3val1': [],
# 'od.stval2.st1val2.st1val2': [],
# 'od.stval2.st1val2.st2val2': [],
# 'od.stval2.st1val2.st3val2': []}
# assert cfg.od.stval1.st1val1.st1val1 == []
# assert cfg.od.stval1.st1val1.st2val1 == []
# assert cfg.od.stval1.st1val1.st3val1 == []
# assert cfg.od.stval2.st1val2.st1val2 == []
# assert cfg.od.stval2.st1val2.st2val2 == []
# assert cfg.od.stval2.st1val2.st3val2 == []
# assert cfg.getowner(st1val1) == owners.default
# assert cfg.getowner(st1val2) == owners.default
# assert cfg.getowner(st2val1) == owners.default
# assert cfg.getowner(st2val2) == owners.default
# assert cfg.getowner(st3val1) == owners.default
# assert cfg.getowner(st3val2) == owners.default
# ##
# cfg.od.stval1.st1val1.st1val1.append('yes')
# assert cfg.make_dict() == {'od.stval1.st1val1.st1val1': ['yes'],
# 'od.stval1.st1val1.st2val1': [None],
# 'od.stval1.st1val1.st3val1': [None],
# 'od.stval2.st1val2.st1val2': [],
# 'od.stval2.st1val2.st2val2': [],
# 'od.stval2.st1val2.st3val2': []}
# assert cfg.getowner(st1val1) == owner
# assert cfg.getowner(st1val2) == owners.default
# assert cfg.getowner(st2val1) == owners.default
# assert cfg.getowner(st2val2) == owners.default
# assert cfg.getowner(st3val1) == owners.default
# assert cfg.getowner(st3val2) == owners.default
# #
# cfg.od.stval1.st1val1.st2val1[0] = 'yes'
# assert cfg.make_dict() == {'od.stval1.st1val1.st1val1': ['yes'],
# 'od.stval1.st1val1.st2val1': ['yes'],
# 'od.stval1.st1val1.st3val1': ['yes'],
# 'od.stval2.st1val2.st1val2': [],
# 'od.stval2.st1val2.st2val2': [],
# 'od.stval2.st1val2.st3val2': []}
# assert cfg.getowner(st1val1) == owner
# assert cfg.getowner(st2val1, 0) == owner
# assert cfg.getowner(st3val1, 0) == owners.default
# assert cfg.getowner(st1val2) == owners.default
# #assert cfg.getowner(st2val2) == owners.default
# #assert cfg.getowner(st3val2) == owners.default
def test_invalid_conflict_dyndescription():

View File

@ -32,11 +32,14 @@ def make_description():
return od2
idx = 0
def make_metaconfig():
global idx
idx += 1
od2 = make_description()
conf1 = Config(od2, session_id='conf3')
conf2 = Config(od2, session_id='conf4')
meta = MetaConfig([conf1, conf2], session_id='meta')
conf1 = Config(od2, session_id='conf3_{}'.format(idx))
conf2 = Config(od2, session_id='conf4_{}'.format(idx))
meta = MetaConfig([conf1, conf2], session_id='meta_{}'.format(idx))
meta.read_write()
meta.cfgimpl_get_settings().setowner(owners.meta)
return meta
@ -44,7 +47,6 @@ def make_metaconfig():
#FIXME ne pas mettre 2 meta dans une config
#FIXME ne pas mettre 2 OD differents dans un meta
#FIXME serialization
def test_none():
meta = make_metaconfig()
conf1, conf2 = meta.cfgimpl_get_children()
@ -72,6 +74,8 @@ def test_none():
del(conf1.od1.i3)
assert conf1.od1.i3 is conf2.od1.i3 is None
assert conf1.getowner(conf1.unwrap_from_path('od1.i3')) is conf2.getowner(conf2.unwrap_from_path('od1.i3')) is owners.default
del(conf1)
del(conf2)
def test_default():
@ -132,8 +136,8 @@ def test_group_error():
def test_meta_meta():
meta1 = make_metaconfig()
meta2 = MetaConfig([meta1])
assert str(meta1) == """(conf3)
(conf4)
assert str(meta1) == """(conf3_5)
(conf4_5)
[od1]"""
meta2.cfgimpl_get_settings().setowner(owners.meta)
conf1, conf2 = meta1.cfgimpl_get_children()
@ -184,7 +188,7 @@ def test_meta_new_config():
def test_meta_new_config_wrong_name():
meta = make_metaconfig()
assert len(meta.cfgimpl_get_children()) == 2
raises(ConflictError, "meta.new_config('conf4')")
raises(ConflictError, "meta.new_config('conf4_7')")
assert len(meta.cfgimpl_get_children()) == 2
@ -319,21 +323,21 @@ def test_meta_master_slaves_value2():
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
conf1 = Config(interface1, session_id='conf1')
conf2 = Config(interface1, session_id='conf2')
meta = MetaConfig([conf1, conf2], session_id="meta")
meta.conf1.ip_admin_eth0 = ['192.168.1.8']
assert meta.conf1.netmask_admin_eth0 == [None]
del(meta.conf1.ip_admin_eth0)
assert meta.conf1.netmask_admin_eth0 == []
conf1 = Config(interface1, session_id='mconf1')
conf2 = Config(interface1, session_id='mconf2')
meta = MetaConfig([conf1, conf2], session_id="mmeta")
meta.mconf1.ip_admin_eth0 = ['192.168.1.8']
assert meta.mconf1.netmask_admin_eth0 == [None]
del(meta.mconf1.ip_admin_eth0)
assert meta.mconf1.netmask_admin_eth0 == []
meta.ip_admin_eth0 = ['192.168.1.1']
assert meta.conf1.netmask_admin_eth0 == [None]
assert meta.mconf1.netmask_admin_eth0 == [None]
meta.netmask_admin_eth0 = ['255.255.255.0']
assert meta.conf1.netmask_admin_eth0 == ['255.255.255.0']
assert meta.mconf1.netmask_admin_eth0 == ['255.255.255.0']
meta.netmask_admin_eth0 = ['255.255.0.0']
assert meta.conf1.netmask_admin_eth0 == ['255.255.0.0']
meta.conf1.ip_admin_eth0 = ['192.168.1.1']
assert meta.conf1.netmask_admin_eth0 == [None]
assert meta.mconf1.netmask_admin_eth0 == ['255.255.0.0']
meta.mconf1.ip_admin_eth0 = ['192.168.1.1']
assert meta.mconf1.netmask_admin_eth0 == [None]
def test_meta_master_slaves_value_default():
@ -341,18 +345,18 @@ def test_meta_master_slaves_value_default():
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True)
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
conf1 = Config(interface1, session_id='conf1')
conf2 = Config(interface1, session_id='conf2')
conf1 = Config(interface1, session_id='nconf1')
conf2 = Config(interface1, session_id='nconf2')
meta = MetaConfig([conf1, conf2])
assert meta.conf1.netmask_admin_eth0 == [None]
assert meta.nconf1.netmask_admin_eth0 == [None]
meta.ip_admin_eth0 = ['192.168.1.1']
assert meta.conf1.netmask_admin_eth0 == [None]
assert meta.nconf1.netmask_admin_eth0 == [None]
meta.netmask_admin_eth0 = ['255.255.255.0']
assert meta.conf1.netmask_admin_eth0 == ['255.255.255.0']
assert meta.nconf1.netmask_admin_eth0 == ['255.255.255.0']
meta.netmask_admin_eth0 = ['255.255.0.0']
assert meta.conf1.netmask_admin_eth0 == ['255.255.0.0']
meta.conf1.ip_admin_eth0 = ['192.168.1.1']
assert meta.conf1.netmask_admin_eth0 == [None]
assert meta.nconf1.netmask_admin_eth0 == ['255.255.0.0']
meta.nconf1.ip_admin_eth0 = ['192.168.1.1']
assert meta.nconf1.netmask_admin_eth0 == [None]
del(conf1)
del(conf2)
@ -362,30 +366,30 @@ def test_meta_master_slaves_owners():
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
conf1 = Config(interface1, session_id='conf1')
conf2 = Config(interface1, session_id='conf2')
conf1 = Config(interface1, session_id='sconf1')
conf2 = Config(interface1, session_id='sconf2')
meta = MetaConfig([conf1, conf2])
meta.cfgimpl_get_settings().setowner(owners.meta)
assert meta.conf1.getowner(ip_admin_eth0) == owners.default
assert meta.conf1.getowner(netmask_admin_eth0) == owners.default
meta.conf1.ip_admin_eth0 = ['192.168.1.1']
assert meta.conf1.getowner(ip_admin_eth0) == owners.user
assert meta.conf1.getowner(netmask_admin_eth0) == owners.default
del(meta.conf1.ip_admin_eth0)
assert meta.conf1.getowner(ip_admin_eth0) == owners.default
assert meta.conf1.getowner(netmask_admin_eth0) == owners.default
assert meta.sconf1.getowner(ip_admin_eth0) == owners.default
assert meta.sconf1.getowner(netmask_admin_eth0) == owners.default
meta.sconf1.ip_admin_eth0 = ['192.168.1.1']
assert meta.sconf1.getowner(ip_admin_eth0) == owners.user
assert meta.sconf1.getowner(netmask_admin_eth0) == owners.default
del(meta.sconf1.ip_admin_eth0)
assert meta.sconf1.getowner(ip_admin_eth0) == owners.default
assert meta.sconf1.getowner(netmask_admin_eth0) == owners.default
meta.ip_admin_eth0 = ['192.168.1.1']
assert meta.conf1.getowner(ip_admin_eth0) == owners.meta
assert meta.conf1.getowner(netmask_admin_eth0) == owners.default
assert meta.sconf1.getowner(ip_admin_eth0) == owners.meta
assert meta.sconf1.getowner(netmask_admin_eth0) == owners.default
meta.netmask_admin_eth0 = ['255.255.255.0']
assert meta.conf1.getowner(ip_admin_eth0) == owners.meta
assert meta.conf1.getowner(netmask_admin_eth0, 0) == owners.meta
assert meta.sconf1.getowner(ip_admin_eth0) == owners.meta
assert meta.sconf1.getowner(netmask_admin_eth0, 0) == owners.meta
meta.netmask_admin_eth0 = ['255.255.0.0']
assert meta.conf1.getowner(ip_admin_eth0) == owners.meta
assert meta.conf1.getowner(netmask_admin_eth0, 0) == owners.meta
meta.conf1.ip_admin_eth0 = ['192.168.1.1']
assert meta.conf1.getowner(ip_admin_eth0) == owners.user
assert meta.conf1.getowner(netmask_admin_eth0, 0) == owners.default
assert meta.sconf1.getowner(ip_admin_eth0) == owners.meta
assert meta.sconf1.getowner(netmask_admin_eth0, 0) == owners.meta
meta.sconf1.ip_admin_eth0 = ['192.168.1.1']
assert meta.sconf1.getowner(ip_admin_eth0) == owners.user
assert meta.sconf1.getowner(netmask_admin_eth0, 0) == owners.default
def test_meta_force_default():
@ -393,35 +397,35 @@ def test_meta_force_default():
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
conf1 = Config(interface1, session_id='conf1')
conf1 = Config(interface1, session_id='oconf1')
conf1.read_write()
conf2 = Config(interface1, session_id='conf2')
conf2 = Config(interface1, session_id='oconf2')
conf2.read_write()
meta = MetaConfig([conf1, conf2])
meta.read_write()
meta.cfgimpl_get_settings().setowner(owners.meta)
assert meta.ip_admin_eth0 == []
assert meta.conf1.ip_admin_eth0 == []
assert meta.conf2.ip_admin_eth0 == []
assert meta.oconf1.ip_admin_eth0 == []
assert meta.oconf2.ip_admin_eth0 == []
errors = meta.set_value('ip_admin_eth0', ['192.168.1.1'])
assert len(errors) == 0
assert meta.ip_admin_eth0 == ['192.168.1.1']
assert meta.conf1.ip_admin_eth0 == ['192.168.1.1']
assert meta.conf2.ip_admin_eth0 == ['192.168.1.1']
errors = meta.conf1.ip_admin_eth0 = ['192.168.1.2']
assert meta.oconf1.ip_admin_eth0 == ['192.168.1.1']
assert meta.oconf2.ip_admin_eth0 == ['192.168.1.1']
errors = meta.oconf1.ip_admin_eth0 = ['192.168.1.2']
assert meta.ip_admin_eth0 == ['192.168.1.1']
assert meta.conf1.ip_admin_eth0 == ['192.168.1.2']
assert meta.conf2.ip_admin_eth0 == ['192.168.1.1']
assert meta.oconf1.ip_admin_eth0 == ['192.168.1.2']
assert meta.oconf2.ip_admin_eth0 == ['192.168.1.1']
errors = meta.set_value('ip_admin_eth0', ['192.168.1.3'])
assert len(errors) == 0
assert meta.ip_admin_eth0 == ['192.168.1.3']
assert meta.conf1.ip_admin_eth0 == ['192.168.1.2']
assert meta.conf2.ip_admin_eth0 == ['192.168.1.3']
assert meta.oconf1.ip_admin_eth0 == ['192.168.1.2']
assert meta.oconf2.ip_admin_eth0 == ['192.168.1.3']
errors = meta.set_value('ip_admin_eth0', ['192.168.1.4'], force_default=True)
assert len(errors) == 0
assert meta.ip_admin_eth0 == ['192.168.1.4']
assert meta.conf1.ip_admin_eth0 == ['192.168.1.4']
assert meta.conf2.ip_admin_eth0 == ['192.168.1.4']
assert meta.oconf1.ip_admin_eth0 == ['192.168.1.4']
assert meta.oconf2.ip_admin_eth0 == ['192.168.1.4']
def test_meta_force_dont_change_value():
@ -429,26 +433,26 @@ def test_meta_force_dont_change_value():
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
conf1 = Config(interface1, session_id='conf1')
conf1 = Config(interface1, session_id='pconf1')
conf1.read_write()
conf2 = Config(interface1, session_id='conf2')
conf2 = Config(interface1, session_id='pconf2')
conf2.read_write()
meta = MetaConfig([conf1, conf2])
meta.read_write()
meta.cfgimpl_get_settings().setowner(owners.meta)
assert meta.ip_admin_eth0 == []
assert meta.conf1.ip_admin_eth0 == []
assert meta.conf2.ip_admin_eth0 == []
meta.conf1.ip_admin_eth0 = ['192.168.1.4']
assert meta.conf1.ip_admin_eth0 == ['192.168.1.4']
assert meta.conf2.ip_admin_eth0 == []
assert meta.pconf1.ip_admin_eth0 == []
assert meta.pconf2.ip_admin_eth0 == []
meta.pconf1.ip_admin_eth0 = ['192.168.1.4']
assert meta.pconf1.ip_admin_eth0 == ['192.168.1.4']
assert meta.pconf2.ip_admin_eth0 == []
assert conf1.getowner(ip_admin_eth0) is owners.user
assert conf2.getowner(ip_admin_eth0) is owners.default
errors = meta.set_value('ip_admin_eth0', ['192.168.1.4'], force_dont_change_value=True)
assert len(errors) == 0
assert meta.ip_admin_eth0 == ['192.168.1.4']
assert meta.conf1.ip_admin_eth0 == ['192.168.1.4']
assert meta.conf2.ip_admin_eth0 == []
assert meta.pconf1.ip_admin_eth0 == ['192.168.1.4']
assert meta.pconf2.ip_admin_eth0 == []
assert conf1.getowner(ip_admin_eth0) is owners.user
assert conf2.getowner(ip_admin_eth0) is owners.user
@ -502,41 +506,41 @@ def test_meta_force_default_if_same_and_dont_change():
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
conf1 = Config(interface1, session_id='conf1')
conf1 = Config(interface1, session_id='qconf1')
conf1.read_write()
conf2 = Config(interface1, session_id='conf2')
conf2 = Config(interface1, session_id='qconf2')
conf2.read_write()
meta = MetaConfig([conf1, conf2])
meta.read_write()
meta.cfgimpl_get_settings().setowner(owners.meta)
#
assert meta.ip_admin_eth0 == []
assert meta.conf1.ip_admin_eth0 == []
assert meta.conf2.ip_admin_eth0 == []
assert meta.qconf1.ip_admin_eth0 == []
assert meta.qconf2.ip_admin_eth0 == []
#
meta.conf1.ip_admin_eth0 = ['192.168.1.4']
assert meta.conf1.ip_admin_eth0 == ['192.168.1.4']
assert meta.conf2.ip_admin_eth0 == []
meta.qconf1.ip_admin_eth0 = ['192.168.1.4']
assert meta.qconf1.ip_admin_eth0 == ['192.168.1.4']
assert meta.qconf2.ip_admin_eth0 == []
assert conf1.getowner(ip_admin_eth0) is owners.user
assert conf2.getowner(ip_admin_eth0) is owners.default
errors = meta.set_value('ip_admin_eth0', ['192.168.1.4'], force_default_if_same=True, force_dont_change_value=True)
assert len(errors) == 0
assert meta.ip_admin_eth0 == ['192.168.1.4']
assert meta.conf1.ip_admin_eth0 == ['192.168.1.4']
assert meta.conf2.ip_admin_eth0 == []
assert meta.qconf1.ip_admin_eth0 == ['192.168.1.4']
assert meta.qconf2.ip_admin_eth0 == []
assert conf1.getowner(ip_admin_eth0) is owners.meta
assert conf2.getowner(ip_admin_eth0) is owners.user
#
meta.conf1.ip_admin_eth0 = ['192.168.1.3']
assert meta.conf1.ip_admin_eth0 == ['192.168.1.3']
assert meta.conf2.ip_admin_eth0 == []
meta.qconf1.ip_admin_eth0 = ['192.168.1.3']
assert meta.qconf1.ip_admin_eth0 == ['192.168.1.3']
assert meta.qconf2.ip_admin_eth0 == []
assert conf1.getowner(ip_admin_eth0) is owners.user
assert conf2.getowner(ip_admin_eth0) is owners.user
errors = meta.set_value('ip_admin_eth0', ['192.168.1.5'], force_default_if_same=True, force_dont_change_value=True)
assert len(errors) == 0
assert meta.ip_admin_eth0 == ['192.168.1.5']
assert meta.conf1.ip_admin_eth0 == ['192.168.1.3']
assert meta.conf2.ip_admin_eth0 == []
assert meta.qconf1.ip_admin_eth0 == ['192.168.1.3']
assert meta.qconf2.ip_admin_eth0 == []
assert conf1.getowner(ip_admin_eth0) is owners.user
assert conf2.getowner(ip_admin_eth0) is owners.user
@ -546,9 +550,9 @@ def test_meta_force_default_and_dont_change():
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
conf1 = Config(interface1, session_id='conf1')
conf1 = Config(interface1, session_id='rconf1')
conf1.read_write()
conf2 = Config(interface1, session_id='conf2')
conf2 = Config(interface1, session_id='rconf2')
conf2.read_write()
meta = MetaConfig([conf1, conf2])
meta.read_write()
@ -562,9 +566,9 @@ def test_meta_properties_meta():
netmask_admin_eth0.impl_add_consistency('network_netmask', ip_admin_eth0)
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
conf1 = Config(interface1, session_id='conf1')
conf1 = Config(interface1, session_id='sconf1')
conf1.read_write()
conf2 = Config(interface1, session_id='conf2')
conf2 = Config(interface1, session_id='sconf2')
conf2.read_write()
meta = MetaConfig([conf1, conf2])
meta.read_write()
@ -619,38 +623,38 @@ def test_meta_callback_slave():
interface1 = MasterSlaves('val1', '', [val1, val3, val4])
#interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('rootconfig', '', [val, interface1])
cfg = Config(maconfig, session_id='cfg')
cfg = Config(maconfig, session_id='cfg1')
meta = MetaConfig([cfg])
meta.read_write()
assert meta.cfg.make_dict() == {'val1.val2': ['val'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
meta.cfg.val = 'val1'
assert meta.cfg.make_dict() == {'val1.val2': ['val1'], 'val1.val1': ['val1'], 'val1.val3': ['val1'], 'val': 'val1'}
del(meta.cfg.val)
assert meta.cfg1.make_dict() == {'val1.val2': ['val'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
meta.cfg1.val = 'val1'
assert meta.cfg1.make_dict() == {'val1.val2': ['val1'], 'val1.val1': ['val1'], 'val1.val3': ['val1'], 'val': 'val1'}
del(meta.cfg1.val)
meta.val = 'val1'
assert meta.cfg.make_dict() == {'val1.val2': ['val1'], 'val1.val1': ['val1'], 'val1.val3': ['val1'], 'val': 'val1'}
assert meta.cfg1.make_dict() == {'val1.val2': ['val1'], 'val1.val1': ['val1'], 'val1.val3': ['val1'], 'val': 'val1'}
del(meta.val)
meta.cfg.val1.val2 = ['val2']
assert meta.cfg.make_dict() == {'val1.val2': ['val2'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
del(meta.cfg.val1.val2)
assert meta.cfg.make_dict() == {'val1.val2': ['val'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
meta.cfg1.val1.val2 = ['val2']
assert meta.cfg1.make_dict() == {'val1.val2': ['val2'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
del(meta.cfg1.val1.val2)
assert meta.cfg1.make_dict() == {'val1.val2': ['val'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
meta.val1.val2 = ['val2']
assert meta.cfg.make_dict() == {'val1.val2': ['val2'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
meta.cfg.val1.val3 = ['val6']
assert meta.cfg.make_dict() == {'val1.val2': ['val2'], 'val1.val1': ['val'], 'val1.val3': ['val6'], 'val': 'val'}
assert meta.cfg1.make_dict() == {'val1.val2': ['val2'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
meta.cfg1.val1.val3 = ['val6']
assert meta.cfg1.make_dict() == {'val1.val2': ['val2'], 'val1.val1': ['val'], 'val1.val3': ['val6'], 'val': 'val'}
del(meta.val1.val2)
del(meta.cfg.val1.val3)
meta.cfg.val1.val1 = ['val3']
assert meta.cfg.make_dict() == {'val1.val2': ['val3'], 'val1.val1': ['val3'], 'val1.val3': ['val3'], 'val': 'val'}
del(meta.cfg.val1.val1)
assert meta.cfg.make_dict() == {'val1.val2': ['val'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
del(meta.cfg1.val1.val3)
meta.cfg1.val1.val1 = ['val3']
assert meta.cfg1.make_dict() == {'val1.val2': ['val3'], 'val1.val1': ['val3'], 'val1.val3': ['val3'], 'val': 'val'}
del(meta.cfg1.val1.val1)
assert meta.cfg1.make_dict() == {'val1.val2': ['val'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
meta.val1.val1 = ['val3']
assert meta.cfg.make_dict() == {'val1.val2': ['val3'], 'val1.val1': ['val3'], 'val1.val3': ['val3'], 'val': 'val'}
meta.cfg.val1.val2 = ['val2']
assert meta.cfg.make_dict() == {'val1.val2': ['val2'], 'val1.val1': ['val3'], 'val1.val3': ['val3'], 'val': 'val'}
meta.cfg.val1.val1.append('rah')
assert meta.cfg.make_dict() == {'val1.val2': ['val2', 'rah'], 'val1.val1': ['val3', 'rah'], 'val1.val3': ['val3', 'rah'], 'val': 'val'}
assert meta.cfg1.make_dict() == {'val1.val2': ['val3'], 'val1.val1': ['val3'], 'val1.val3': ['val3'], 'val': 'val'}
meta.cfg1.val1.val2 = ['val2']
assert meta.cfg1.make_dict() == {'val1.val2': ['val2'], 'val1.val1': ['val3'], 'val1.val3': ['val3'], 'val': 'val'}
meta.cfg1.val1.val1.append('rah')
assert meta.cfg1.make_dict() == {'val1.val2': ['val2', 'rah'], 'val1.val1': ['val3', 'rah'], 'val1.val3': ['val3', 'rah'], 'val': 'val'}
meta.val1.val1 = ['val4']
assert meta.cfg.make_dict() == {'val1.val2': ['val2', 'rah'], 'val1.val1': ['val3', 'rah'], 'val1.val3': ['val3', 'rah'], 'val': 'val'}
assert meta.cfg1.make_dict() == {'val1.val2': ['val2', 'rah'], 'val1.val1': ['val3', 'rah'], 'val1.val3': ['val3', 'rah'], 'val': 'val'}
def test_meta_properties_meta_set_value():

View File

@ -45,8 +45,8 @@ def test_is_hidden():
descr = make_description()
config = Config(descr)
setting = config.cfgimpl_get_settings()
config.read_write()
dummy = config.unwrap_from_path('gc.dummy')
config.read_write()
assert not 'frozen' in setting[dummy]
# setattr
raises(PropertiesOptionError, "config.gc.dummy == False")
@ -60,7 +60,7 @@ def test_group_is_hidden():
setting = config.cfgimpl_get_settings()
config.read_write()
gc = config.unwrap_from_path('gc')
config.unwrap_from_path('gc.dummy')
#config.unwrap_from_path('gc.dummy')
setting[gc].append('hidden')
raises(PropertiesOptionError, "config.gc.dummy")
assert 'hidden' in setting[gc]
@ -83,7 +83,7 @@ def test_extend_properties():
setting = config.cfgimpl_get_settings()
config.read_write()
gc = config.unwrap_from_path('gc')
config.unwrap_from_path('gc.dummy')
#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]
@ -113,8 +113,8 @@ def test_global_show():
descr = make_description()
config = Config(descr)
setting = config.cfgimpl_get_settings()
config.read_write()
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")

View File

@ -701,9 +701,9 @@ def test_multi_submulti_meta():
def test_multi_submulti_meta_no_cache():
multi = StrOption('multi', '', multi=submulti)
od = OptionDescription('od', '', [multi])
conf1 = Config(od, session_id='conf1')
conf1 = Config(od, session_id='conf1_1')
conf1.read_write()
conf2 = Config(od, session_id='conf2')
conf2 = Config(od, session_id='conf2_1')
conf2.read_write()
meta = MetaConfig([conf1, conf2])
meta.read_write()

View File

@ -254,6 +254,32 @@ class TiramisuAPIProperty(CommonTiramisu):
self.settings.reset(_path=path)
class TiramisuAPIPermissive(CommonTiramisu):
"""manager option's property"""
def __init__(self, config, force_permissive, force_unrestraint):
super(TiramisuAPIPermissive, self).__init__(config, force_permissive, force_unrestraint)
self.config = config
self.force_permissive = force_permissive
self.force_unrestraint = force_unrestraint
if config:
self.settings = config.cfgimpl_get_settings()
def get(self, path):
"""get permissive value for a specified path"""
setting_properties = self.settings.getproperties(None, None, obj=False)
return self.settings.getpermissive(setting_properties, path)
def set(self, path, permissive):
self.settings.setpermissive(permissive, opt=None, path=path)
#def reset(self, path):
# """reset all personalised properties
# """
# self._get_obj_by_path(path)
# self.settings.reset(_path=path)
class TiramisuAPIValue(CommonTiramisu):
"""manager option's value"""
@ -348,7 +374,7 @@ class TiramisuAPI(object):
return self.registers[subfunc](self.config,
self.force_permissive,
self.force_unrestraint)
elif subfunc == 'permissive':
elif subfunc == 'forcepermissive':
return TiramisuAPI(self.config, force_permissive=True, force_unrestraint=self.force_unrestraint)
elif subfunc == 'unrestraint':
return TiramisuAPI(self.config, force_permissive=self.force_permissive, force_unrestraint=True)
@ -358,7 +384,7 @@ class TiramisuAPI(object):
raise APIError(_('please specify a valid sub function'))
def _help(self):
txt = ['[permissive]']
txt = ['[forcepermissive]']
for module_name, module in self.registers.items():
module_doc = getdoc(module)
txt.append(self.tmpl_help.format(self.icon, module_name, module_doc))

View File

@ -22,7 +22,7 @@
import weakref
import sys
from time import time
from itertools import chain
from copy import copy
from .error import PropertiesOptionError, ConfigError, ConflictError
@ -76,69 +76,33 @@ class SubConfig(object):
only=('values', 'properties', 'permissives', 'settings'),
opt=None,
path=None,
orig_opts=None):
resetted_opts=None):
"""reset all settings in cache
:param only_expired: if True reset only expired cached values
:type only_expired: boolean
"""
def reset_one_option_cache(opt, path):
if opt.__class__.__name__ == 'DynOptionDescription':
# this option is a DynOptionDescription
descr = context.cfgimpl_get_description()
spath = path.split('.')
subpath = '.'.join(spath[:-1])
dynopt = getattr(descr, subpath)._getattr(spath[-1], context=context,
dyn=False)
for suffix in dynopt._impl_get_suffixes(context):
path = subpath + '.' + spath[-1] + suffix
def reset_one_option_cache(opt, resetted_opts):
if 'values' in only:
values._p_.delcache(path)
if 'settings' in only or 'properties' in only:
settings._p_.delcache(path)
if 'settings' in only or 'permissives' in only:
settings._pp_.delcache(path)
elif not isinstance(opt, DynSymLinkOption) and opt._is_subdyn():
# this option is an instance of DynOptionDescription
descr = context.cfgimpl_get_description()
spath = path.split('.')
try:
subpath = '.'.join(spath[:-2])
dynsubopt = getattr(descr, subpath)
spath1 = spath[-2]
spath2 = spath[-1]
spath3 = None
except AttributeError:
if len(spath) == 2:
subpath = '.'.join(spath)
spath1 = spath[-2]
spath2 = spath[-1]
spath3 = None
dynsubopt = descr
tresetted_opts = copy(resetted_opts)
opt.reset_cache(opt, values, 'values', tresetted_opts)
if 'settings' in only:
tresetted_opts = copy(resetted_opts)
opt.reset_cache(opt, settings, 'settings', tresetted_opts)
else:
subpath = '.'.join(spath[:-3])
spath1 = spath[-3]
spath2 = spath[-2]
spath3 = spath[-1]
dynsubopt = getattr(descr, subpath)
dynopt = dynsubopt._getattr(spath1, context=context, dyn=False)
for suffix in dynopt._impl_get_suffixes(context):
path = subpath + '.' + spath1 + suffix + '.' + spath2 + suffix
if spath3:
path += '.' + spath3 + suffix
if 'values' in only:
values._p_.delcache(path)
if 'settings' in only or 'properties' in only:
settings._p_.delcache(path)
if 'settings' in only or 'permissives' in only:
settings._pp_.delcache(path)
else:
if 'values' in only:
values._p_.delcache(path)
if 'settings' in only or 'permissives' in only:
settings._p_.delcache(path)
if 'settings' in only or 'permissives' in only:
settings._pp_.delcache(path)
if 'properties' in only:
tresetted_opts = copy(resetted_opts)
opt.reset_cache(opt, settings, 'properties', tresetted_opts)
if 'permissives' in only:
tresetted_opts = copy(resetted_opts)
opt.reset_cache(opt, settings, 'permissives', tresetted_opts)
resetted_opts |= tresetted_opts
for option in opt._get_dependencies(self):
if option in resetted_opts:
continue
reset_one_option_cache(option, resetted_opts)
def reset_expired_cache():
# reset cache for expired cache value ony
@ -156,9 +120,14 @@ class SubConfig(object):
if 'settings' in only:
settings._p_.reset_all_cache()
settings._pp_.reset_all_cache()
else:
if 'properties' in only:
settings._p_.reset_all_cache()
if 'permissives' in only:
settings._pp_.reset_all_cache()
if orig_opts is None:
orig_opts = set()
if resetted_opts is None:
resetted_opts = set()
context = self._cfgimpl_get_context()
if 'values' in only:
@ -167,26 +136,8 @@ class SubConfig(object):
settings = context.cfgimpl_get_settings()
if not None in (opt, path):
reset_one_option_cache(opt, path)
# remove cache for option which has dependencies with this option
#if not isinstance(opt, OptionDescription) and not isinstance(opt, SynDynOptionDescription) and \
# opt.impl_is_master_slaves('slave'):
# slaves = opt.impl_get_master_slaves().getslaves(opt)
#else:
slaves = []
for option in chain(opt._get_dependencies(self), slaves):
if option in orig_opts:
continue
if 'values' in only:
option.reset_cache(opt, values, 'values', orig_opts)
if 'settings' in only:
option.reset_cache(opt, settings, 'settings', orig_opts)
else:
if 'properties' in only:
option.reset_cache(opt, settings, 'properties', orig_opts)
if 'permissives' in only:
option.reset_cache(opt, settings, 'permissives', orig_opts)
if opt not in resetted_opts:
reset_one_option_cache(opt, resetted_opts)
elif only_expired:
reset_expired_cache()
@ -445,6 +396,8 @@ class SubConfig(object):
return props
else:
raise props
if returns_option is True:
return option
return SubConfig(option, self._impl_context, subpath)
else:
if validate:
@ -737,23 +690,28 @@ class _CommonConfig(SubConfig):
force_permissive=force_permissive)
def unwrap_from_path(self, path, force_permissive=False, index=None,
validate_properties=True, validate=True):
validate_properties=True, validate=True,
_setting_properties=undefined):
"""convenience method to extract and Option() object from the Config()
and it is **fast**: finds the option directly in the appropriate
namespace
:returns: Option()
"""
if _setting_properties is undefined:
context = self._cfgimpl_get_context()
_setting_properties = context.cfgimpl_get_settings()._getproperties(read_write=True)
if '.' in path:
self, path = self.cfgimpl_get_home_by_path(path,
validate_properties=validate_properties,
force_permissive=force_permissive)
force_permissive=force_permissive,
_setting_properties=_setting_properties)
return self.getattr(path,
validate_properties=validate_properties,
validate=validate,
force_permissive=force_permissive,
index=index,
_setting_properties=_setting_properties,
returns_option=True)
def cfgimpl_get_path(self, dyn=True):
@ -889,13 +847,19 @@ class GroupConfig(_CommonConfig):
only=('values', 'settings'),
opt=None,
path=None,
orig_opts=set()):
resetted_opts=set()):
if isinstance(self, MetaConfig):
super(GroupConfig, self).cfgimpl_reset_cache(only_expired=only_expired, only=only,
opt=opt, path=path, orig_opts=orig_opts)
super(GroupConfig, self).cfgimpl_reset_cache(only_expired=only_expired,
only=only,
opt=opt,
path=path,
resetted_opts=copy(resetted_opts))
for child in self._impl_children:
child.cfgimpl_reset_cache(only_expired=only_expired, only=only, opt=opt, path=path,
orig_opts=orig_opts)
child.cfgimpl_reset_cache(only_expired=only_expired,
only=only,
opt=opt,
path=path,
resetted_opts=copy(resetted_opts))
def set_value(self, path, value, _commit=True):
"""Setattr not in current GroupConfig, but in each children
@ -964,7 +928,8 @@ class GroupConfig(_CommonConfig):
def getattr(self, name, force_permissive=False, validate=True,
_setting_properties=undefined, _self_properties=undefined, index=None,
returns_raise=False):
returns_raise=False, returns_option=False,
validate_properties=True):
for child in self._impl_children:
if name == child._impl_name:
return child
@ -973,7 +938,9 @@ class GroupConfig(_CommonConfig):
_self_properties=_self_properties,
index=index,
_setting_properties=_setting_properties,
returns_raise=returns_raise)
returns_raise=returns_raise,
returns_option=False,
validate_properties=validate_properties)
class MetaConfig(GroupConfig):

View File

@ -404,15 +404,16 @@ class BaseOption(Base):
name = name.encode('utf8')
return name
def reset_cache(self, opt, obj, type_, orig_opts):
context = obj._getcontext()
path = self.impl_getpath(context)
def reset_cache(self, opt, obj, type_, resetted_opts):
if opt in resetted_opts:
return
if not type_ == 'values' or not opt.impl_is_optiondescription():
path = opt.impl_getpath(obj._getcontext())
if type_ != 'permissives':
obj._p_.delcache(path)
orig_opts.add(opt)
context.cfgimpl_reset_cache(only=(type_,),
opt=self,
path=path,
orig_opts=orig_opts)
if type_ in ['settings', 'permissives']:
obj._pp_.delcache(path)
resetted_opts.add(opt)
def _is_symlinkoption(self):
return False

View File

@ -21,10 +21,10 @@
import re
from ..i18n import _
from .option import _RegexpOption
from .option import RegexpOption
class EmailOption(_RegexpOption):
class EmailOption(RegexpOption):
__slots__ = tuple()
#https://www.w3.org/TR/html-markup/input.email.html#input.email.attrs.value.single.
_regexp = re.compile(r"^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$")

View File

@ -21,10 +21,10 @@
import re
from ..i18n import _
from .option import _RegexpOption
from .option import RegexpOption
class FilenameOption(_RegexpOption):
class FilenameOption(RegexpOption):
__slots__ = tuple()
_regexp = re.compile(r"^[a-zA-Z0-9\-\._~/+]+$")
_display_name = _('file name')

View File

@ -503,7 +503,7 @@ class Option(OnlyOption):
all_cons_opts = tuple([self] + list(other_opts))
unknown_params = set(params.keys()) - set(['warnings_only', 'transitive'])
if unknown_params != set():
raise ValueError(_('unknow parameter {0} in consistency').format(unknown_params))
raise ValueError(_('unknown parameter {0} in consistency').format(unknown_params))
self._add_consistency(func, all_cons_opts, params)
#validate default value when add consistency
err = self.impl_validate(self.impl_getdefault())
@ -660,7 +660,7 @@ class Option(OnlyOption):
return hasattr(self, '_consistencies')
class _RegexpOption(Option):
class RegexpOption(Option):
__slots__ = tuple()
def _validate(self, value, context=undefined, current_opt=undefined):
@ -670,3 +670,7 @@ class _RegexpOption(Option):
match = self._regexp.search(value)
if not match:
return ValueError()
#FIXME compatibility
_RegexpOption = RegexpOption

View File

@ -358,11 +358,10 @@ class OptionDescriptionWalk(CacheOptionDescription):
for child in self._impl_st_getchildren(context):
cname = child.impl_getname()
if dyn and child.impl_is_dynoptiondescription():
path = cname
for value in child._impl_get_suffixes(context):
yield SynDynOptionDescription(child,
cname + value,
path + value, value)
value)
else:
yield child
@ -383,17 +382,16 @@ class OptionDescriptionWalk(CacheOptionDescription):
for child in self._impl_st_getchildren(context, only_dyn=True):
cname = child.impl_getname()
if name.startswith(cname):
path = cname
for value in child._impl_get_suffixes(context):
if name == cname + value:
return SynDynOptionDescription(child, name, path + value, value)
return SynDynOptionDescription(child, name, value)
return ret
def _impl_get_dynchild(self, child, suffix):
name = child.impl_getname() + suffix
path = self.impl_getname() + suffix + '.' + name
if isinstance(child, OptionDescription):
return SynDynOptionDescription(child, name, path, suffix)
return SynDynOptionDescription(child, name, suffix)
else:
return child._impl_to_dyn(name, path)
@ -524,12 +522,11 @@ class DynOptionDescription(OptionDescription):
class SynDynOptionDescription(object):
__slots__ = ('_opt', '_name', '_path', '_suffix')
__slots__ = ('_opt', '_name', '_suffix')
def __init__(self, opt, name, path, suffix):
def __init__(self, opt, name, suffix):
self._opt = opt
self._name = name
self._path = path
self._suffix = suffix
def __getattr__(self, name, context=undefined):
@ -549,7 +546,10 @@ class SynDynOptionDescription(object):
return self._impl_getchildren()
def impl_getpath(self, context):
return self._path
path = self._impl_getopt().impl_getpath(context).split('.')
path[-1] += self._suffix
path.append(self._name)
return '.'.join(path)
def impl_getpaths(self, include_groups=False, _currpath=None):
return _impl_getpaths(self, include_groups, _currpath)
@ -825,12 +825,13 @@ class MasterSlaves(OptionDescription):
" which has {1} as master").format(
name, opt.impl_getname()))
def reset_cache(self, opt, values, type_, orig_opts):
path = self.getmaster(opt).impl_getpath(values._getcontext())
values._p_.delcache(path)
for slave in self.getslaves(opt):
slave_path = slave.impl_getpath(values._getcontext())
values._p_.delcache(slave_path)
def reset_cache(self, opt, obj, type_, resetted_opts):
context = obj._getcontext()
#FIXME pb avec dyn, devrait etre une option
mopt = self.getmaster(None)
mopt.reset_cache(mopt, obj, type_, resetted_opts)
for slave in self.getslaves(mopt):
slave.reset_cache(slave, obj, type_, resetted_opts)
def _getattr(self, name, suffix=undefined, context=undefined, dyn=True):
return super(MasterSlaves, self)._getattr(name, suffix, context, dyn)

View File

@ -375,7 +375,7 @@ class Settings(object):
if opt is not None and _path is None:
_path = opt.impl_getpath(self._getcontext())
self._p_.delproperties(_path)
self._getcontext().cfgimpl_reset_cache(opt=opt, path=_path, only=('settings',))
self._getcontext().cfgimpl_reset_cache(opt=opt, path=_path, only=('settings', 'values'))
def _getproperties(self, opt=None, path=None,
setting_properties=undefined, read_write=True,
@ -468,7 +468,8 @@ class Settings(object):
raise ConfigError(_('cannot add those properties: {0}').format(
' '.join(forbidden_properties)))
self._p_.setproperties(path, properties)
self._getcontext().cfgimpl_reset_cache(opt=opt, path=path)
#values too because of slave values could have a PropertiesOptionError has value
self._getcontext().cfgimpl_reset_cache(opt=opt, path=path, only=('values', 'properties',))
def getpermissive(self, setting_properties, path=None):
if 'cache' in setting_properties and 'expire' in setting_properties:
@ -595,7 +596,7 @@ class Settings(object):
raise TypeError(_('permissive must be a tuple'))
self._pp_.setpermissive(path, permissive)
setting_properties = self._getproperties(read_write=False)
self._getcontext().cfgimpl_reset_cache(opt=opt, path=path, only=('values',))
self._getcontext().cfgimpl_reset_cache(opt=opt, path=path, only=('properties', 'values'))
if 'cache' in setting_properties:
if 'expire' in setting_properties:
ntime = int(time()) + expires_time

View File

@ -87,7 +87,7 @@ class Values(object):
callback=callback,
callback_params=callback_params,
index=index, validate=validate)
_orig_context.cfgimpl_reset_cache(opt=opt, path=path, only=('values',))
_orig_context.cfgimpl_reset_cache(opt=opt, path=path, only=('values', 'properties'))
if isinstance(value, list) and index is not None:
#if return a list and index is set, return value only if
#it's a submulti without submulti_index and without list of list
@ -295,7 +295,8 @@ class Values(object):
if isinstance(val, Exception):
return val
# cache doesn't work with SubMulti yet
if index is None and not isinstance(val, SubMulti) and 'cache' in setting_properties and \
if not from_masterslave and index is None and not isinstance(val, SubMulti) and \
'cache' in setting_properties and \
validate and validate_properties and force_permissive is False \
and trusted_cached_properties is True and _orig_context is undefined:
if 'expire' in setting_properties: