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 """check different value of owner when any value is set to this option
""" """
try: try:
isslave = api.permissive.option.isslave(path) isslave = api.forcepermissive.option.isslave(path)
except: except:
isslave = False isslave = False
# check if owner is a string "default" # 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)") raises(APIError, "api.unrestraint.owner.get(path)")
if not kwargs.get('propertyerror', False): if not kwargs.get('propertyerror', False):
if not isslave: if not isslave:
assert api.permissive.owner.get(path) == 'default' assert api.forcepermissive.owner.get(path) == 'default'
else: else:
assert api.permissive.owner.get(path, 0) == 'default' assert api.forcepermissive.owner.get(path, 0) == 'default'
else: else:
if not isslave: if not isslave:
raises(PropertiesOptionError, "api.permissive.owner.get(path)") raises(PropertiesOptionError, "api.forcepermissive.owner.get(path)")
else: else:
raises(PropertiesOptionError, "api.permissive.owner.get(path, 0)") raises(PropertiesOptionError, "api.forcepermissive.owner.get(path, 0)")
# check if default owner # check if default owner
raises(APIError, "api.unrestraint.owner.isdefault(path)") raises(APIError, "api.unrestraint.owner.isdefault(path)")
@ -77,9 +77,9 @@ def autocheck_owner_without_value(api, path, **kwargs):
else: else:
raises(PropertiesOptionError, "api.owner.isdefault(path)") raises(PropertiesOptionError, "api.owner.isdefault(path)")
if not kwargs.get('propertyerror', False): if not kwargs.get('propertyerror', False):
assert api.permissive.owner.isdefault(path) assert api.forcepermissive.owner.isdefault(path)
else: else:
raises(PropertiesOptionError, "api.permissive.owner.isdefault(path)") raises(PropertiesOptionError, "api.forcepermissive.owner.isdefault(path)")
@autocheck @autocheck
@ -88,11 +88,11 @@ def autocheck_value(api, path, **kwargs):
""" """
# check if is a multi, a master or a slave # check if is a multi, a master or a slave
if not kwargs.get('propertyerror', False): if not kwargs.get('propertyerror', False):
multi = api.permissive.option.ismulti(path) multi = api.forcepermissive.option.ismulti(path)
ismaster = api.permissive.option.ismaster(path) ismaster = api.forcepermissive.option.ismaster(path)
isslave = api.permissive.option.isslave(path) isslave = api.forcepermissive.option.isslave(path)
else: else:
raises(PropertiesOptionError, "api.permissive.option.ismulti(path)") raises(PropertiesOptionError, "api.forcepermissive.option.ismulti(path)")
multi = api.unrestraint.option.ismulti(path) multi = api.unrestraint.option.ismulti(path)
ismaster = api.unrestraint.option.ismaster(path) ismaster = api.unrestraint.option.ismaster(path)
isslave = api.unrestraint.option.isslave(path) isslave = api.unrestraint.option.isslave(path)
@ -122,9 +122,9 @@ def autocheck_value(api, path, **kwargs):
raises(APIError, "api.unrestraint.value.get(path)") raises(APIError, "api.unrestraint.value.get(path)")
if not isslave: if not isslave:
if not kwargs.get('propertyerror', False): if not kwargs.get('propertyerror', False):
assert api.permissive.value.get(path) == empty_value assert api.forcepermissive.value.get(path) == empty_value
else: else:
raises(PropertiesOptionError, "api.permissive.value.get(path)") raises(PropertiesOptionError, "api.forcepermissive.value.get(path)")
# set a value without permissive # set a value without permissive
# for master/slave should have an index and good length # 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): elif kwargs.get('permissive', False):
if isslave: if isslave:
raises(PropertiesOptionError, "api.value.get(path, 0)") 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: else:
raises(PropertiesOptionError, "api.value.get(path)") raises(PropertiesOptionError, "api.value.get(path)")
assert api.permissive.value.get(path) == empty_value assert api.forcepermissive.value.get(path) == empty_value
else: else:
if isslave: if isslave:
raises(PropertiesOptionError, "api.value.get(path, 0)") raises(PropertiesOptionError, "api.value.get(path, 0)")
raises(PropertiesOptionError, "api.permissive.value.get(path, 0)") raises(PropertiesOptionError, "api.forcepermissive.value.get(path, 0)")
else: else:
raises(PropertiesOptionError, "api.value.get(path)") 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 # set a value with permissive
if ismaster: if ismaster:
@ -179,30 +179,30 @@ def autocheck_value(api, path, **kwargs):
raises(APIError, "api.unrestraint.value.set(path, second_value)") raises(APIError, "api.unrestraint.value.set(path, second_value)")
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if ismaster: if ismaster:
raises(IndexError, "api.permissive.value.set(path, 1, second_value[1])") raises(IndexError, "api.forcepermissive.value.set(path, 1, second_value[1])")
api.permissive.value.append(path, second_value[1]) api.forcepermissive.value.append(path, second_value[1])
elif isslave: elif isslave:
#FIXME #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]) api.value.set(path, 1, second_value[1])
raise Exception('ca entre ici') raise Exception('ca entre ici')
else: else:
api.value.set(path, second_value) api.value.set(path, second_value)
elif kwargs.get('permissive', False): elif kwargs.get('permissive', False):
if ismaster: if ismaster:
api.permissive.value.append(path, second_value[0]) api.forcepermissive.value.append(path, second_value[0])
api.permissive.value.append(path, second_value[1]) api.forcepermissive.value.append(path, second_value[1])
elif isslave: elif isslave:
api.permissive.value.set(path, 1, second_value[1]) api.forcepermissive.value.set(path, 1, second_value[1])
else: else:
api.permissive.value.set(path, first_value) api.forcepermissive.value.set(path, first_value)
else: else:
if ismaster: if ismaster:
raises(PropertiesOptionError, "api.permissive.value.append(path, first_value[0])") raises(PropertiesOptionError, "api.forcepermissive.value.append(path, first_value[0])")
elif isslave: 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: 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 # get value after set value with permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): 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): elif kwargs.get('permissive', False):
if ismaster: if ismaster:
raises(PropertiesOptionError, "api.value.get(path)") raises(PropertiesOptionError, "api.value.get(path)")
assert api.permissive.value.get(path) == second_value assert api.forcepermissive.value.get(path) == second_value
elif isslave: elif isslave:
raises(PropertiesOptionError, "api.value.get(path, 0)") raises(PropertiesOptionError, "api.value.get(path, 0)")
raises(PropertiesOptionError, "api.value.get(path, 1)") 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: else:
raises(PropertiesOptionError, "api.value.get(path)") raises(PropertiesOptionError, "api.value.get(path)")
assert api.permissive.value.get(path) == first_value assert api.forcepermissive.value.get(path) == first_value
else: else:
if isslave: if isslave:
raises(PropertiesOptionError, "api.value.get(path, 0)") raises(PropertiesOptionError, "api.value.get(path, 0)")
raises(PropertiesOptionError, "api.permissive.value.get(path, 0)") raises(PropertiesOptionError, "api.forcepermissive.value.get(path, 0)")
else: else:
raises(PropertiesOptionError, "api.value.get(path)") raises(PropertiesOptionError, "api.value.get(path)")
raises(PropertiesOptionError, "api.permissive.value.get(path)") raises(PropertiesOptionError, "api.forcepermissive.value.get(path)")
@autocheck @autocheck
def autocheck_reset_value(api, path, **kwargs): def autocheck_reset_value(api, path, **kwargs):
# check if is a multi, a master or a slave # check if is a multi, a master or a slave
if not kwargs.get('propertyerror', False): if not kwargs.get('propertyerror', False):
multi = api.permissive.option.ismulti(path) multi = api.forcepermissive.option.ismulti(path)
ismaster = api.permissive.option.ismaster(path) ismaster = api.forcepermissive.option.ismaster(path)
isslave = api.permissive.option.isslave(path) isslave = api.forcepermissive.option.isslave(path)
else: else:
raises(PropertiesOptionError, "api.permissive.option.ismulti(path)") raises(PropertiesOptionError, "api.forcepermissive.option.ismulti(path)")
multi = api.unrestraint.option.ismulti(path) multi = api.unrestraint.option.ismulti(path)
ismaster = api.unrestraint.option.ismaster(path) ismaster = api.unrestraint.option.ismaster(path)
isslave = api.unrestraint.option.isslave(path) isslave = api.unrestraint.option.isslave(path)
@ -278,28 +278,28 @@ def autocheck_reset_value(api, path, **kwargs):
elif kwargs.get('permissive', False): elif kwargs.get('permissive', False):
if isslave: if isslave:
raises(PropertiesOptionError, "api.value.get(path, 0)") 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
assert api.permissive.value.get(path, 1) == second_value[1] assert api.forcepermissive.value.get(path, 1) == second_value[1]
else: else:
raises(PropertiesOptionError, "api.value.get(path)") 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 # reset value with permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if not isslave: if not isslave:
api.permissive.value.reset(path) api.forcepermissive.value.reset(path)
else: else:
api.permissive.value.reset(path, 1) api.forcepermissive.value.reset(path, 1)
elif kwargs.get('permissive', False): elif kwargs.get('permissive', False):
if not isslave: if not isslave:
api.permissive.value.reset(path) api.forcepermissive.value.reset(path)
else: else:
api.permissive.value.reset(path, 1) api.forcepermissive.value.reset(path, 1)
else: else:
if not isslave: if not isslave:
raises(PropertiesOptionError, "api.permissive.value.reset(path)") raises(PropertiesOptionError, "api.forcepermissive.value.reset(path)")
else: else:
raises(PropertiesOptionError, "api.permissive.value.reset(path, 1)") raises(PropertiesOptionError, "api.forcepermissive.value.reset(path, 1)")
# get value after reset value with permissive # get value after reset value with permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): 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: if isslave:
raises(PropertiesOptionError, "api.value.get(path, 0)") raises(PropertiesOptionError, "api.value.get(path, 0)")
raises(PropertiesOptionError, "api.value.get(path, 1)") raises(PropertiesOptionError, "api.value.get(path, 1)")
assert api.permissive.value.get(path, 0) == empty_value assert api.forcepermissive.value.get(path, 0) == empty_value
assert api.permissive.value.get(path, 1) == empty_value assert api.forcepermissive.value.get(path, 1) == empty_value
else: else:
raises(PropertiesOptionError, "api.value.get(path)") raises(PropertiesOptionError, "api.value.get(path)")
assert api.permissive.value.get(path) == empty_value assert api.forcepermissive.value.get(path) == empty_value
@autocheck @autocheck
@ -332,11 +332,11 @@ def autocheck_property(api, path, **kwargs):
""" """
# check if is a multi or a slave # check if is a multi or a slave
if not kwargs.get('propertyerror', False): if not kwargs.get('propertyerror', False):
multi = api.permissive.option.ismulti(path) multi = api.forcepermissive.option.ismulti(path)
isslave = api.permissive.option.isslave(path) isslave = api.forcepermissive.option.isslave(path)
else: else:
raises(PropertiesOptionError, "api.permissive.option.ismulti(path)") raises(PropertiesOptionError, "api.forcepermissive.option.ismulti(path)")
raises(PropertiesOptionError, "api.permissive.option.isslave(path)") raises(PropertiesOptionError, "api.forcepermissive.option.isslave(path)")
multi = api.unrestraint.option.ismulti(path) multi = api.unrestraint.option.ismulti(path)
isslave = api.unrestraint.option.isslave(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)") raises(APIError, "api.unrestraint.property.get(path, 0)")
if not kwargs.get('propertyerror', False): if not kwargs.get('propertyerror', False):
if not isslave: if not isslave:
assert set(api.permissive.property.get(path)) == set(default_props) assert set(api.forcepermissive.property.get(path)) == set(default_props)
else: else:
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.permissive.property.get(path, 1)) == set(default_props) assert set(api.forcepermissive.property.get(path, 1)) == set(default_props)
else: else:
if not isslave: if not isslave:
raises(PropertiesOptionError, "api.permissive.property.get(path)") raises(PropertiesOptionError, "api.forcepermissive.property.get(path)")
else: else:
raises(PropertiesOptionError, "api.permissive.property.get(path, 0)") raises(PropertiesOptionError, "api.forcepermissive.property.get(path, 0)")
# set properties without permissive # set properties without permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): 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 # check properties after set without permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
assert set(api.property.get(path)) == set(properties) 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): elif kwargs.get('permissive', False):
raises(PropertiesOptionError, "api.property.get(path)") raises(PropertiesOptionError, "api.property.get(path)")
if not isslave: if not isslave:
assert set(api.permissive.property.get(path)) == set(default_props) assert set(api.forcepermissive.property.get(path)) == set(default_props)
else: else:
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.permissive.property.get(path, 1)) == set(default_props) assert set(api.forcepermissive.property.get(path, 1)) == set(default_props)
else: else:
if not isslave: if not isslave:
raises(PropertiesOptionError, "api.property.get(path)") raises(PropertiesOptionError, "api.property.get(path)")
raises(PropertiesOptionError, "api.permissive.property.get(path)") raises(PropertiesOptionError, "api.forcepermissive.property.get(path)")
else: else:
raises(PropertiesOptionError, "api.property.get(path, 0)") 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 # set properties with permissive
if not kwargs.get('propertyerror', False): if not kwargs.get('propertyerror', False):
api.permissive.property.set(path, properties) api.forcepermissive.property.set(path, properties)
else: else:
raises(PropertiesOptionError, "api.permissive.property.set(path, properties)") raises(PropertiesOptionError, "api.forcepermissive.property.set(path, properties)")
# check properties after set with permissive # check properties after set with permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if not isslave: if not isslave:
assert set(api.property.get(path)) == set(properties) 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: else:
assert set(api.property.get(path, 0)) == set(properties) 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.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): elif kwargs.get('permissive', False):
if not isslave: if not isslave:
raises(PropertiesOptionError, "api.property.get(path)") 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: else:
raises(PropertiesOptionError, "api.property.get(path, 0)") 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)") 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: else:
if not isslave: if not isslave:
raises(PropertiesOptionError, "api.property.get(path)") raises(PropertiesOptionError, "api.property.get(path)")
raises(PropertiesOptionError, "api.permissive.property.get(path)") raises(PropertiesOptionError, "api.forcepermissive.property.get(path)")
else: else:
raises(PropertiesOptionError, "api.property.get(path, 0)") raises(PropertiesOptionError, "api.property.get(path, 0)")
raises(PropertiesOptionError, "api.permissive.property.get(path, 0)") raises(PropertiesOptionError, "api.forcepermissive.property.get(path, 0)")
@autocheck @autocheck
@ -446,11 +446,11 @@ def autocheck_reset_property(api, path, **kwargs):
# check if is a multi or a slave # check if is a multi or a slave
if not kwargs.get('propertyerror', False): if not kwargs.get('propertyerror', False):
multi = api.permissive.option.ismulti(path) multi = api.forcepermissive.option.ismulti(path)
isslave = api.permissive.option.isslave(path) isslave = api.forcepermissive.option.isslave(path)
else: else:
raises(PropertiesOptionError, "api.permissive.option.ismulti(path)") raises(PropertiesOptionError, "api.forcepermissive.option.ismulti(path)")
raises(PropertiesOptionError, "api.permissive.option.isslave(path)") raises(PropertiesOptionError, "api.forcepermissive.option.isslave(path)")
multi = api.unrestraint.option.ismulti(path) multi = api.unrestraint.option.ismulti(path)
isslave = api.unrestraint.option.isslave(path) isslave = api.unrestraint.option.isslave(path)
@ -470,13 +470,13 @@ def autocheck_reset_property(api, path, **kwargs):
# check properties # check properties
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
assert set(api.property.get(path)) == set(properties) 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): elif kwargs.get('permissive', False):
if not isslave: if not isslave:
assert set(api.permissive.property.get(path)) == set(properties) assert set(api.forcepermissive.property.get(path)) == set(properties)
else: else:
assert set(api.permissive.property.get(path, 0)) == set(properties) assert set(api.forcepermissive.property.get(path, 0)) == set(properties)
assert set(api.permissive.property.get(path, 1)) == set(properties) assert set(api.forcepermissive.property.get(path, 1)) == set(properties)
# reset properties without permissive # reset properties without permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): 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 kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if not isslave: if not isslave:
assert set(api.property.get(path)) == set(default_props) 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: else:
assert set(api.property.get(path, 0)) == set(default_props) 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.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): elif kwargs.get('permissive', False):
if not isslave: if not isslave:
assert set(api.permissive.property.get(path)) == set(properties) assert set(api.forcepermissive.property.get(path)) == set(properties)
else: else:
assert set(api.permissive.property.get(path, 0)) == set(properties) assert set(api.forcepermissive.property.get(path, 0)) == set(properties)
assert set(api.permissive.property.get(path, 1)) == set(properties) assert set(api.forcepermissive.property.get(path, 1)) == set(properties)
# reset properties with permissive # reset properties with permissive
raises(APIError, "api.unrestraint.property.set(path, properties)") raises(APIError, "api.unrestraint.property.set(path, properties)")
raises(APIError, "api.unrestraint.property.reset(path)") raises(APIError, "api.unrestraint.property.reset(path)")
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
api.permissive.property.set(path, properties) api.forcepermissive.property.set(path, properties)
api.permissive.property.reset(path) api.forcepermissive.property.reset(path)
elif kwargs.get('permissive', False): elif kwargs.get('permissive', False):
api.permissive.property.reset(path) api.forcepermissive.property.reset(path)
# check properties # check properties
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if not isslave: if not isslave:
assert set(api.property.get(path)) == set(default_props) 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: else:
assert set(api.property.get(path, 0)) == set(default_props) 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.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): elif kwargs.get('permissive', False):
if not isslave: if not isslave:
assert set(api.permissive.property.get(path)) == set(default_props) assert set(api.forcepermissive.property.get(path)) == set(default_props)
else: else:
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.permissive.property.get(path, 1)) == set(default_props) assert set(api.forcepermissive.property.get(path, 1)) == set(default_props)
@autocheck @autocheck
@ -539,9 +539,9 @@ def autocheck_owner_with_value(api, path, **kwargs):
""" """
# check if is a isslave # check if is a isslave
if not kwargs.get('propertyerror', False): if not kwargs.get('propertyerror', False):
isslave = api.permissive.option.isslave(path) isslave = api.forcepermissive.option.isslave(path)
else: else:
raises(PropertiesOptionError, "api.permissive.option.isslave(path)") raises(PropertiesOptionError, "api.forcepermissive.option.isslave(path)")
isslave = api.unrestraint.option.isslave(path) isslave = api.unrestraint.option.isslave(path)
# get owner without permissive # get owner without permissive
@ -561,15 +561,15 @@ def autocheck_owner_with_value(api, path, **kwargs):
# get owner with permissive # get owner with permissive
if not kwargs.get('propertyerror', False): if not kwargs.get('propertyerror', False):
if not isslave: if not isslave:
assert api.permissive.owner.get(path) == 'user' assert api.forcepermissive.owner.get(path) == 'user'
else: else:
assert api.permissive.owner.get(path, 0) == 'default' assert api.forcepermissive.owner.get(path, 0) == 'default'
assert api.permissive.owner.get(path, 1) == 'user' assert api.forcepermissive.owner.get(path, 1) == 'user'
else: else:
if not isslave: if not isslave:
raises(PropertiesOptionError, "api.permissive.owner.get(path)") raises(PropertiesOptionError, "api.forcepermissive.owner.get(path)")
else: else:
raises(PropertiesOptionError, "api.permissive.owner.get(path, 0)") raises(PropertiesOptionError, "api.forcepermissive.owner.get(path, 0)")
# test if is default owner without permissive # test if is default owner without permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): 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 # test if is default owner with permissive
if not kwargs.get('propertyerror', False): if not kwargs.get('propertyerror', False):
assert api.permissive.owner.isdefault(path) is False assert api.forcepermissive.owner.isdefault(path) is False
else: else:
raises(PropertiesOptionError, "api.permissive.owner.isdefault(path)") raises(PropertiesOptionError, "api.forcepermissive.owner.isdefault(path)")
@autocheck @autocheck
def autocheck_set_owner(api, path, **kwargs): def autocheck_set_owner(api, path, **kwargs):
# test set owner without permissive # test set owner without permissive
if not kwargs.get('propertyerror', False): if not kwargs.get('propertyerror', False):
isslave = api.permissive.option.isslave(path) isslave = api.forcepermissive.option.isslave(path)
else: else:
raises(PropertiesOptionError, "api.permissive.option.isslave(path)") raises(PropertiesOptionError, "api.forcepermissive.option.isslave(path)")
isslave = False isslave = False
# set owner without permissive # 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 kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if not isslave: if not isslave:
assert api.owner.get(path) == 'new_user' assert api.owner.get(path) == 'new_user'
assert api.permissive.owner.get(path) == 'new_user' assert api.forcepermissive.owner.get(path) == 'new_user'
else: else:
assert api.owner.get(path, 1) == 'new_user' 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): elif not kwargs.get('propertyerror', False):
if not isslave: if not isslave:
assert api.permissive.owner.get(path) == 'user' assert api.forcepermissive.owner.get(path) == 'user'
else: else:
assert api.permissive.owner.get(path, 1) == 'user' assert api.forcepermissive.owner.get(path, 1) == 'user'
# set owner with permissive # set owner with permissive
if not kwargs.get('propertyerror', False): if not kwargs.get('propertyerror', False):
if not isslave: if not isslave:
api.permissive.owner.set(path, 'new_user1') api.forcepermissive.owner.set(path, 'new_user1')
else: else:
api.permissive.owner.set(path, 1, 'new_user1') api.forcepermissive.owner.set(path, 1, 'new_user1')
else: else:
if not isslave: if not isslave:
raises(PropertiesOptionError, "api.permissive.owner.set(path, 'new_user1')") raises(PropertiesOptionError, "api.forcepermissive.owner.set(path, 'new_user1')")
else: 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 # get owner set with permissive
if not kwargs.get('propertyerror', False): if not kwargs.get('propertyerror', False):
if not isslave: if not isslave:
assert api.permissive.owner.get(path) == 'new_user1' assert api.forcepermissive.owner.get(path) == 'new_user1'
else: else:
assert api.permissive.owner.get(path, 0) == 'default' assert api.forcepermissive.owner.get(path, 0) == 'default'
assert api.permissive.owner.get(path, 1) == 'new_user1' assert api.forcepermissive.owner.get(path, 1) == 'new_user1'
@autocheck @autocheck
@ -645,24 +645,24 @@ def autocheck_option(api, path, **kwargs):
expected_name = path.split('.')[-1] expected_name = path.split('.')[-1]
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
current_name = api.option.getname(path) 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) assert current_name == api.unrestraint.option.getname(path)
doc = api.option.getdoc(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) assert doc == api.unrestraint.option.getdoc(path)
elif not kwargs.get('propertyerror', False): elif not kwargs.get('propertyerror', False):
raises(PropertiesOptionError, "api.option.getname(path)") 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) assert current_name == api.unrestraint.option.getname(path)
raises(PropertiesOptionError, "api.option.getdoc(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) assert doc == api.unrestraint.option.getdoc(path)
else: else:
raises(PropertiesOptionError, "api.option.getname(path)") 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) current_name = api.unrestraint.option.getname(path)
raises(PropertiesOptionError, "api.option.getdoc(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) doc = api.unrestraint.option.getdoc(path)
assert current_name == expected_name assert current_name == expected_name
if expected_name.endswith('val1') or expected_name.endswith('val2'): 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) 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): def check_all(api, path, multi, **kwargs):
text = u' {} launch tests for {}'.format(ICON, path) text = u' {} launch tests for {}'.format(ICON, path)
if multi: if multi:

View File

@ -98,7 +98,7 @@ def test_cache_reset():
assert 'u1' in values._p_.get_cached() assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached() assert 'u1' in settings._p_.get_cached()
assert 'u2' not in values._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 #when remove a value
c.u1 c.u1
assert 'u1' in values._p_.get_cached() 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 values._p_.get_cached()
assert 'u1' in settings._p_.get_cached() assert 'u1' in settings._p_.get_cached()
assert 'u2' not in values._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 #when add/del property
c.u1 c.u1
assert 'u1' in values._p_.get_cached() 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 values._p_.get_cached()
assert 'u1' in settings._p_.get_cached() assert 'u1' in settings._p_.get_cached()
assert 'u3' not in values._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 #when append value
c.u1 c.u1
c.u3 c.u3
@ -168,7 +168,7 @@ def test_cache_reset_multi():
assert 'u1' in values._p_.get_cached() assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached() assert 'u1' in settings._p_.get_cached()
assert 'u3' not in values._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 #when pop value
c.u1 c.u1
c.u3 c.u3
@ -180,7 +180,7 @@ def test_cache_reset_multi():
assert 'u1' in values._p_.get_cached() assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached() assert 'u1' in settings._p_.get_cached()
assert 'u3' not in values._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 #when remove a value
c.u1 c.u1
assert 'u1' in values._p_.get_cached() 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 values._p_.get_cached()
assert 'u1' in settings._p_.get_cached() assert 'u1' in settings._p_.get_cached()
assert 'u3' not in values._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(): def test_reset_cache():
@ -407,105 +407,83 @@ def test_cache_callback():
cfg.cfgimpl_get_settings().remove('expire') cfg.cfgimpl_get_settings().remove('expire')
cfg.read_write() cfg.read_write()
cfg.cfgimpl_get_values().force_cache() cfg.cfgimpl_get_values().force_cache()
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, #assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
'val1': {None: (set([]), 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_values()._p_.get_cached() == {'val1': {None: ('val', None)}, assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1': {None: ('val', None)},
'val2': {None: ('val', None)}, 'val2': {None: ('val', None)},
'val3': {None: ('yes', None)}, 'val3': {None: ('yes', None)},
'val4': {None: ('val', None)}, 'val4': {None: ('val', None)},
'val5': {None: (['yes'], None)}} 'val5': {None: (['yes'], None)}}
cfg.val1 = 'new' cfg.val1 = 'new'
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, #assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
'val1': {None: (set([]), None)}, # 'val1': {None: (set([]), None)}}
'val3': {None: (set([]), None)},
'val5': {None: (set(['empty']), None)}}
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val3': {None: ('yes', None)}, assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val3': {None: ('yes', None)},
'val5': {None: (['yes'], None)}} 'val5': {None: (['yes'], None)}}
cfg.cfgimpl_get_values().force_cache() cfg.cfgimpl_get_values().force_cache()
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, #assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
'val1': {None: (set([]), 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_values()._p_.get_cached() == {'val1': {None: ('new', None)}, assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1': {None: ('new', None)},
'val2': {None: ('new', None)}, 'val2': {None: ('new', None)},
'val3': {None: ('yes', None)}, 'val3': {None: ('yes', None)},
'val4': {None: ('new', None)}, 'val4': {None: ('new', None)},
'val5': {None: (['yes'], None)}} 'val5': {None: (['yes'], None)}}
cfg.val3 = 'new2' cfg.val3 = 'new2'
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, #assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
'val1': {None: (set([]), None)}, # 'val1': {None: (set([]), None)},
'val2': {None: (set(['mandatory']), None)}, # 'val3': {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)}, assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1': {None: ('new', None)},
'val2': {None: ('new', None)}, 'val2': {None: ('new', None)},
'val4': {None: ('new', None)}, 'val4': {None: ('new', None)},
'val5': {None: (['yes'], None)}} 'val5': {None: (['yes'], None)}}
cfg.cfgimpl_get_values().force_cache() cfg.cfgimpl_get_values().force_cache()
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, #assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
'val1': {None: (set([]), None)}, # 'val1': {None: (set([]), None)},
'val2': {None: (set(['mandatory']), None)}, # 'val3': {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)}, assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1': {None: ('new', None)},
'val2': {None: ('new', None)}, 'val2': {None: ('new', None)},
'val3': {None: ('new2', None)}, 'val3': {None: ('new2', None)},
'val4': {None: ('new', None)}, 'val4': {None: ('new', None)},
'val5': {None: (['yes'], None)}} 'val5': {None: (['yes'], None)}}
cfg.val4 = 'new3' cfg.val4 = 'new3'
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, #assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
'val1': {None: (set([]), None)}, # 'val1': {None: (set([]), None)},
'val2': {None: (set(['mandatory']), None)}, # 'val3': {None: (set([]), None)},
'val3': {None: (set([]), None)}, # 'val4': {None: (set([]), None)}}
'val4': {None: (set([]), None)},
'val5': {None: (set(['empty']), None)}}
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1': {None: ('new', None)}, assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1': {None: ('new', None)},
'val2': {None: ('new', None)}, 'val2': {None: ('new', None)},
'val3': {None: ('new2', None)}, 'val3': {None: ('new2', None)},
'val5': {None: (['yes'], None)}} 'val5': {None: (['yes'], None)}}
cfg.cfgimpl_get_values().force_cache() cfg.cfgimpl_get_values().force_cache()
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, #assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
'val1': {None: (set([]), None)}, # 'val1': {None: (set([]), None)},
'val2': {None: (set(['mandatory']), None)}, # 'val3': {None: (set([]), None)},
'val3': {None: (set([]), None)}, # 'val4': {None: (set([]), None)}}
'val4': {None: (set([]), None)},
'val5': {None: (set(['empty']), None)}}
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1': {None: ('new', None)}, assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1': {None: ('new', None)},
'val2': {None: ('new', None)}, 'val2': {None: ('new', None)},
'val3': {None: ('new2', None)}, 'val3': {None: ('new2', None)},
'val4': {None: ('new3', None)}, 'val4': {None: ('new3', None)},
'val5': {None: (['yes'], None)}} 'val5': {None: (['yes'], None)}}
cfg.val5.append('new4') cfg.val5.append('new4')
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, #assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
'val1': {None: (set([]), None)}, # 'val1': {None: (set([]), None)},
'val2': {None: (set(['mandatory']), None)}, # 'val3': {None: (set([]), None)},
'val3': {None: (set([]), None)}, # 'val4': {None: (set([]), None)},
'val4': {None: (set([]), None)}, # 'val5': {None: (set(['empty']), None)}}
'val5': {None: (set(['empty']), None)}}
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1': {None: ('new', None)}, assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1': {None: ('new', None)},
'val2': {None: ('new', None)}, 'val2': {None: ('new', None)},
'val3': {None: ('new2', None)}, 'val3': {None: ('new2', None)},
'val4': {None: ('new3', None)}} 'val4': {None: ('new3', None)}}
cfg.cfgimpl_get_values().force_cache() cfg.cfgimpl_get_values().force_cache()
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, #assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
'val1': {None: (set([]), None)}, # 'val1': {None: (set([]), None)},
'val2': {None: (set(['mandatory']), None)}, # 'val3': {None: (set([]), None)},
'val3': {None: (set([]), None)}, # 'val4': {None: (set([]), None)},
'val4': {None: (set([]), None)}, # 'val5': {None: (set(['empty']), None)}}
'val5': {None: (set(['empty']), None)}}
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1': {None: ('new', None)}, assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1': {None: ('new', None)},
'val2': {None: ('new', None)}, 'val2': {None: ('new', None)},
'val3': {None: ('new2', None)}, 'val3': {None: ('new2', None)},
'val4': {None: ('new3', None)}, 'val4': {None: ('new3', None)},
'val5': {None: (['yes', 'new4'], None)}} 'val5': {None: (['yes', 'new4'], None)}}
def test_cache_master_and_slaves_master(): def test_cache_master_and_slaves_master():
@ -519,34 +497,35 @@ def test_cache_master_and_slaves_master():
cfg.read_write() cfg.read_write()
cfg.cfgimpl_get_values().force_cache() cfg.cfgimpl_get_values().force_cache()
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
'val1': {None: (set([]), None)}, 'val1': {None: (set([]), None)},
'val1.val1': {None: (set(['empty']), None)}, 'val1.val1': {None: (set(['empty']), None)},
'val1.val2': {None: (set([]), None)}} 'val1.val2': {None: (set([]), None)}}
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([], None)}, 'val1.val2': {None: ([], None)}} assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([], None)}, 'val1.val2': {None: ([], None)}}
cfg.val1.val1.append() cfg.val1.val1.append()
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
'val1': {None: (set([]), None)}} 'val1': {None: (set([]), None)}}
assert cfg.cfgimpl_get_values()._p_.get_cached() == {} assert cfg.cfgimpl_get_values()._p_.get_cached() == {}
cfg.cfgimpl_get_values().force_cache() cfg.cfgimpl_get_values().force_cache()
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
'val1': {None: (set([]), None)}, 'val1': {None: (set([]), None)},
'val1.val1': {None: (set(['empty']), None)}, 'val1.val1': {None: (set(['empty']), None)},
'val1.val2': {None: (set([]), None), 0: (set([]), None)}} 'val1.val2': {None: (set([]), None), 0: (set([]), None)}}
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([None], None)}, assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([None], None)},
'val1.val2': {None: ([None], None)}} 'val1.val2': {None: ([None], None)}}
cfg.val1.val1.append() cfg.val1.val1.append()
cfg.cfgimpl_get_values().force_cache() cfg.cfgimpl_get_values().force_cache()
cfg.val1.val2[1] = 'oui' cfg.val1.val2[1] = 'oui'
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
'val1': {None: (set([]), None)}} 'val1': {None: (set([]), None)}}
assert cfg.cfgimpl_get_values()._p_.get_cached() == {} assert cfg.cfgimpl_get_values()._p_.get_cached() == {}
cfg.cfgimpl_get_values().force_cache() cfg.cfgimpl_get_values().force_cache()
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
'val1': {None: (set([]), None)}, 'val1': {None: (set([]), None)},
'val1.val1': {None: (set(['empty']), None)}, 'val1.val1': {None: (set(['empty']), None)},
'val1.val2': {None: (set([]), None), 0: (set([]), None), 1: (set([]), 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)}, assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([None, None], None)},
'val1.val2': {None: ([None, 'oui'], None)}} 'val1.val2': {None: ([None, 'oui'], None)}}
def test_cache_master_callback(): def test_cache_master_callback():
@ -560,21 +539,22 @@ def test_cache_master_callback():
cfg.read_write() cfg.read_write()
cfg.cfgimpl_get_values().force_cache() cfg.cfgimpl_get_values().force_cache()
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
'val1': {None: (set([]), None)}, 'val1': {None: (set([]), None)},
'val1.val1': {None: (set(['empty']), None)}, 'val1.val1': {None: (set(['empty']), None)},
'val1.val2': {None: (set([]), None)}} 'val1.val2': {None: (set([]), None)}}
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([], None)}, 'val1.val2': {None: ([], None)}} assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([], None)}, 'val1.val2': {None: ([], None)}}
cfg.val1.val1.append() cfg.val1.val1.append()
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
'val1': {None: (set([]), None)}} 'val1': {None: (set([]), None)}}
assert cfg.cfgimpl_get_values()._p_.get_cached() == {} assert cfg.cfgimpl_get_values()._p_.get_cached() == {}
cfg.cfgimpl_get_values().force_cache() cfg.cfgimpl_get_values().force_cache()
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, #FIXMEassert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
'val1': {None: (set([]), None)}, # 'val1': {None: (set([]), None)}}
'val1.val1': {None: (set(['empty']), None)}, #FIXMEassert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([None], None)},
'val1.val2': {None: (set([]), None), 0: (set([]), None)}} # 'val1.val2': {None: ([None], None)}
#assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([None], None)}, # }
# 'val1.val2': {None: ([None], None), 0: (None, None)}}
def test_cache_master_slave_different(): def test_cache_master_slave_different():
b = IntOption('int', 'Test int option', default=[0], multi=True) b = IntOption('int', 'Test int option', default=[0], multi=True)
@ -641,39 +621,37 @@ def test_cache_requires():
assert c.cfgimpl_get_values()._p_.get_cached() == {} assert c.cfgimpl_get_values()._p_.get_cached() == {}
assert c.ip_address_service == None assert c.ip_address_service == None
assert c.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, assert c.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
'activate_service': {None: (set([]), None)}, 'activate_service': {None: (set([]), None)},
'ip_address_service': {None: (set([]), None)}} 'ip_address_service': {None: (set([]), None)}}
assert c.cfgimpl_get_values()._p_.get_cached() == {'ip_address_service': {None: (None, None)}} assert c.cfgimpl_get_values()._p_.get_cached() == {'ip_address_service': {None: (None, None)}}
c.cfgimpl_get_values().force_cache() c.cfgimpl_get_values().force_cache()
assert c.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, assert c.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
'activate_service': {None: (set([]), None)}, 'activate_service': {None: (set([]), None)},
'ip_address_service': {None: (set([]), None)}} 'ip_address_service': {None: (set([]), None)}}
assert c.cfgimpl_get_values()._p_.get_cached() == {'ip_address_service': {None: (None, None)}, assert c.cfgimpl_get_values()._p_.get_cached() == {'ip_address_service': {None: (None, None)},
'activate_service': {None: (True, None)}} 'activate_service': {None: (True, None)}}
c.ip_address_service = '1.1.1.1' 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)}, assert c.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
'activate_service': {None: (set([]), None)}, 'activate_service': {None: (set([]), None)}}
'ip_address_service': {None: (set([]), None)}}
assert c.cfgimpl_get_values()._p_.get_cached() == {'activate_service': {None: (True, None)}} assert c.cfgimpl_get_values()._p_.get_cached() == {'activate_service': {None: (True, None)}}
c.cfgimpl_get_values().force_cache() c.cfgimpl_get_values().force_cache()
assert c.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, assert c.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
'activate_service': {None: (set([]), None)}, 'activate_service': {None: (set([]), None)},
'ip_address_service': {None: (set([]), None)}} 'ip_address_service': {None: (set([]), None)}}
assert c.cfgimpl_get_values()._p_.get_cached() == {'ip_address_service': {None: ('1.1.1.1', None)}, assert c.cfgimpl_get_values()._p_.get_cached() == {'ip_address_service': {None: ('1.1.1.1', None)},
'activate_service': {None: (True, None)}} 'activate_service': {None: (True, None)}}
c.activate_service = False c.activate_service = False
assert c.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, assert c.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}}
'activate_service': {None: (set([]), None)}}
assert c.cfgimpl_get_values()._p_.get_cached() == {} assert c.cfgimpl_get_values()._p_.get_cached() == {}
c.cfgimpl_get_values().force_cache() c.cfgimpl_get_values().force_cache()
assert c.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, assert c.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
'activate_service': {None: (set([]), None)}, 'activate_service': {None: (set([]), None)},
'ip_address_service': {None: (set(['disabled']), None)}} 'ip_address_service': {None: (set(['disabled']), None)}}
assert c.cfgimpl_get_values()._p_.get_cached() == {'activate_service': {None: (False, None)}} assert c.cfgimpl_get_values()._p_.get_cached() == {'activate_service': {None: (False, None)}}

View File

@ -190,12 +190,12 @@ def test_find_in_config():
raises(AttributeError, "assert conf.find(byname='prop')") raises(AttributeError, "assert conf.find(byname='prop')")
ret = conf.find(byname='prop', check_properties=False) ret = conf.find(byname='prop', check_properties=False)
assert len(ret) == 2 assert len(ret) == 2
_is_same_opt(ret[0], conf.unwrap_from_path('gc.gc2.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')) _is_same_opt(ret[1], conf.unwrap_from_path('gc.prop', force_permissive=True))
ret = conf.find(byname='prop', force_permissive=True) ret = conf.find(byname='prop', force_permissive=True)
assert len(ret) == 1 assert len(ret) == 1
_is_same_opt(ret[0], 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')) _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') #assert conf.find_first(byname='prop') == conf.unwrap_from_path('gc.prop')
# combinaison of filters # combinaison of filters
ret = conf.find(bytype=BoolOption, byname='dummy') ret = conf.find(bytype=BoolOption, byname='dummy')
@ -221,8 +221,8 @@ def test_find_in_config():
raises(AttributeError, "conf.gc.find(byname='wantref').first()") raises(AttributeError, "conf.gc.find(byname='wantref').first()")
ret = conf.gc.find(byname='prop', check_properties=False) ret = conf.gc.find(byname='prop', check_properties=False)
assert len(ret) == 2 assert len(ret) == 2
_is_same_opt(ret[0], conf.unwrap_from_path('gc.gc2.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')) _is_same_opt(ret[1], conf.unwrap_from_path('gc.prop', force_permissive=True))
conf.read_only() conf.read_only()
ret = conf.gc.find(byname='prop') ret = conf.gc.find(byname='prop')
assert len(ret) == 1 assert len(ret) == 1

View File

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

View File

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

View File

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

View File

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

View File

@ -254,6 +254,32 @@ class TiramisuAPIProperty(CommonTiramisu):
self.settings.reset(_path=path) 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): class TiramisuAPIValue(CommonTiramisu):
"""manager option's value""" """manager option's value"""
@ -348,7 +374,7 @@ class TiramisuAPI(object):
return self.registers[subfunc](self.config, return self.registers[subfunc](self.config,
self.force_permissive, self.force_permissive,
self.force_unrestraint) self.force_unrestraint)
elif subfunc == 'permissive': elif subfunc == 'forcepermissive':
return TiramisuAPI(self.config, force_permissive=True, force_unrestraint=self.force_unrestraint) return TiramisuAPI(self.config, force_permissive=True, force_unrestraint=self.force_unrestraint)
elif subfunc == 'unrestraint': elif subfunc == 'unrestraint':
return TiramisuAPI(self.config, force_permissive=self.force_permissive, force_unrestraint=True) 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')) raise APIError(_('please specify a valid sub function'))
def _help(self): def _help(self):
txt = ['[permissive]'] txt = ['[forcepermissive]']
for module_name, module in self.registers.items(): for module_name, module in self.registers.items():
module_doc = getdoc(module) module_doc = getdoc(module)
txt.append(self.tmpl_help.format(self.icon, module_name, module_doc)) txt.append(self.tmpl_help.format(self.icon, module_name, module_doc))

View File

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

View File

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

View File

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

View File

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

View File

@ -503,7 +503,7 @@ class Option(OnlyOption):
all_cons_opts = tuple([self] + list(other_opts)) all_cons_opts = tuple([self] + list(other_opts))
unknown_params = set(params.keys()) - set(['warnings_only', 'transitive']) unknown_params = set(params.keys()) - set(['warnings_only', 'transitive'])
if unknown_params != set(): 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) self._add_consistency(func, all_cons_opts, params)
#validate default value when add consistency #validate default value when add consistency
err = self.impl_validate(self.impl_getdefault()) err = self.impl_validate(self.impl_getdefault())
@ -660,7 +660,7 @@ class Option(OnlyOption):
return hasattr(self, '_consistencies') return hasattr(self, '_consistencies')
class _RegexpOption(Option): class RegexpOption(Option):
__slots__ = tuple() __slots__ = tuple()
def _validate(self, value, context=undefined, current_opt=undefined): def _validate(self, value, context=undefined, current_opt=undefined):
@ -670,3 +670,7 @@ class _RegexpOption(Option):
match = self._regexp.search(value) match = self._regexp.search(value)
if not match: if not match:
return ValueError() return ValueError()
#FIXME compatibility
_RegexpOption = RegexpOption

View File

@ -358,11 +358,10 @@ class OptionDescriptionWalk(CacheOptionDescription):
for child in self._impl_st_getchildren(context): for child in self._impl_st_getchildren(context):
cname = child.impl_getname() cname = child.impl_getname()
if dyn and child.impl_is_dynoptiondescription(): if dyn and child.impl_is_dynoptiondescription():
path = cname
for value in child._impl_get_suffixes(context): for value in child._impl_get_suffixes(context):
yield SynDynOptionDescription(child, yield SynDynOptionDescription(child,
cname + value, cname + value,
path + value, value) value)
else: else:
yield child yield child
@ -383,17 +382,16 @@ class OptionDescriptionWalk(CacheOptionDescription):
for child in self._impl_st_getchildren(context, only_dyn=True): for child in self._impl_st_getchildren(context, only_dyn=True):
cname = child.impl_getname() cname = child.impl_getname()
if name.startswith(cname): if name.startswith(cname):
path = cname
for value in child._impl_get_suffixes(context): for value in child._impl_get_suffixes(context):
if name == cname + value: if name == cname + value:
return SynDynOptionDescription(child, name, path + value, value) return SynDynOptionDescription(child, name, value)
return ret return ret
def _impl_get_dynchild(self, child, suffix): def _impl_get_dynchild(self, child, suffix):
name = child.impl_getname() + suffix name = child.impl_getname() + suffix
path = self.impl_getname() + suffix + '.' + name path = self.impl_getname() + suffix + '.' + name
if isinstance(child, OptionDescription): if isinstance(child, OptionDescription):
return SynDynOptionDescription(child, name, path, suffix) return SynDynOptionDescription(child, name, suffix)
else: else:
return child._impl_to_dyn(name, path) return child._impl_to_dyn(name, path)
@ -524,12 +522,11 @@ class DynOptionDescription(OptionDescription):
class SynDynOptionDescription(object): 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._opt = opt
self._name = name self._name = name
self._path = path
self._suffix = suffix self._suffix = suffix
def __getattr__(self, name, context=undefined): def __getattr__(self, name, context=undefined):
@ -549,7 +546,10 @@ class SynDynOptionDescription(object):
return self._impl_getchildren() return self._impl_getchildren()
def impl_getpath(self, context): 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): def impl_getpaths(self, include_groups=False, _currpath=None):
return _impl_getpaths(self, include_groups, _currpath) return _impl_getpaths(self, include_groups, _currpath)
@ -825,12 +825,13 @@ class MasterSlaves(OptionDescription):
" which has {1} as master").format( " which has {1} as master").format(
name, opt.impl_getname())) name, opt.impl_getname()))
def reset_cache(self, opt, values, type_, orig_opts): def reset_cache(self, opt, obj, type_, resetted_opts):
path = self.getmaster(opt).impl_getpath(values._getcontext()) context = obj._getcontext()
values._p_.delcache(path) #FIXME pb avec dyn, devrait etre une option
for slave in self.getslaves(opt): mopt = self.getmaster(None)
slave_path = slave.impl_getpath(values._getcontext()) mopt.reset_cache(mopt, obj, type_, resetted_opts)
values._p_.delcache(slave_path) for slave in self.getslaves(mopt):
slave.reset_cache(slave, obj, type_, resetted_opts)
def _getattr(self, name, suffix=undefined, context=undefined, dyn=True): def _getattr(self, name, suffix=undefined, context=undefined, dyn=True):
return super(MasterSlaves, self)._getattr(name, suffix, context, dyn) 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: if opt is not None and _path is None:
_path = opt.impl_getpath(self._getcontext()) _path = opt.impl_getpath(self._getcontext())
self._p_.delproperties(_path) 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, def _getproperties(self, opt=None, path=None,
setting_properties=undefined, read_write=True, setting_properties=undefined, read_write=True,
@ -394,12 +394,12 @@ class Settings(object):
props = self._p_.getproperties(path, default_properties) props = self._p_.getproperties(path, default_properties)
else: else:
props = meta.cfgimpl_get_settings()._getproperties() props = meta.cfgimpl_get_settings()._getproperties()
if 'cache' in props: if 'cache' in props:
if 'expire' in props: if 'expire' in props:
ntime = ntime + expires_time ntime = ntime + expires_time
else: else:
ntime = None ntime = None
self._p_.setcache(path, props, ntime, None) self._p_.setcache(path, props, ntime, None)
else: else:
if path is None: # pragma: optional cover if path is None: # pragma: optional cover
raise ValueError(_('if opt is not None, path should not be' raise ValueError(_('if opt is not None, path should not be'
@ -468,7 +468,8 @@ class Settings(object):
raise ConfigError(_('cannot add those properties: {0}').format( raise ConfigError(_('cannot add those properties: {0}').format(
' '.join(forbidden_properties))) ' '.join(forbidden_properties)))
self._p_.setproperties(path, 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): def getpermissive(self, setting_properties, path=None):
if 'cache' in setting_properties and 'expire' in setting_properties: if 'cache' in setting_properties and 'expire' in setting_properties:
@ -595,7 +596,7 @@ class Settings(object):
raise TypeError(_('permissive must be a tuple')) raise TypeError(_('permissive must be a tuple'))
self._pp_.setpermissive(path, permissive) self._pp_.setpermissive(path, permissive)
setting_properties = self._getproperties(read_write=False) 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 'cache' in setting_properties:
if 'expire' in setting_properties: if 'expire' in setting_properties:
ntime = int(time()) + expires_time ntime = int(time()) + expires_time

View File

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