test api: add DISPLAY variable to display more informations about generated test

api: new format, api.owner.get('path') become api.option('path').owner.get()
value._getdefaultvalue: better submulti support
This commit is contained in:
Emmanuel Garette 2017-11-05 15:40:27 +01:00
parent 2e412b64fd
commit ee445aee85
4 changed files with 527 additions and 525 deletions

View File

@ -1,4 +1,4 @@
"""test API to get/set owner
"""test API
"""
import pytest
from py.test import raises
@ -14,6 +14,8 @@ OPTIONS_TYPE = {'str': {'type': str,
'option': StrOption}
}
PROPERTIES = ['hidden', 'disabled']
DISPLAY = True
#DISPLAY = False
def return_list(val=None, suffix=None):
@ -25,6 +27,7 @@ def return_list(val=None, suffix=None):
def display_info(func):
def wrapper(*args, **kwargs):
if DISPLAY:
print(u'\n{} {}'.format(ICON, func.__name__))
return func(*args, **kwargs)
return wrapper
@ -36,7 +39,7 @@ autocheck_registers = []
def autocheck(func):
autocheck_registers.append(func)
def wrapper(*args, **kwargs):
if kwargs.get('display', True):
if DISPLAY and kwargs.get('display', True):
print(u' {} {}'.format(ICON, func.__name__))
return func(*args, **kwargs)
return wrapper
@ -47,39 +50,42 @@ def autocheck_owner_without_value(api, path, **kwargs):
"""check different value of owner when any value is set to this option
"""
try:
isslave = api.forcepermissive.option.isslave(path)
isslave = api.forcepermissive.option(path).option.isslave()
except:
isslave = False
# check if owner is a string "default"
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
assert api.owner.get(path) == 'default'
assert api.option(path).owner.get() == 'default'
else:
if not isslave:
raises(PropertiesOptionError, "api.owner.get(path)")
raises(PropertiesOptionError, "api.option(path).owner.get()")
else:
raises(PropertiesOptionError, "api.owner.get(path, 0)")
raises(APIError, "api.unrestraint.owner.get(path)")
raises(PropertiesOptionError, "api.option(path, 0).owner.get()")
raises(APIError, "api.unrestraint.option(path).owner.get()")
if not kwargs.get('propertyerror', False):
if not isslave:
assert api.forcepermissive.owner.get(path) == 'default'
assert api.forcepermissive.option(path).owner.get() == 'default'
else:
assert api.forcepermissive.owner.get(path, 0) == 'default'
assert api.forcepermissive.option(path, 0).owner.get() == 'default'
else:
if not isslave:
raises(PropertiesOptionError, "api.forcepermissive.owner.get(path)")
raises(PropertiesOptionError, "api.forcepermissive.option(path).owner.get()")
else:
raises(PropertiesOptionError, "api.forcepermissive.owner.get(path, 0)")
raises(PropertiesOptionError, "api.forcepermissive.option(path, 0).owner.get()")
# check if default owner
raises(APIError, "api.unrestraint.owner.isdefault(path)")
raises(APIError, "api.unrestraint.option(path).owner.isdefault()")
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
assert api.owner.isdefault(path)
assert api.option(path).owner.isdefault()
else:
raises(PropertiesOptionError, "api.owner.isdefault(path)")
raises(PropertiesOptionError, "api.option(path).owner.isdefault()")
if not kwargs.get('propertyerror', False):
assert api.forcepermissive.owner.isdefault(path)
if not isslave:
assert api.forcepermissive.option(path).owner.isdefault()
else:
raises(PropertiesOptionError, "api.forcepermissive.owner.isdefault(path)")
assert api.forcepermissive.option(path, 0).owner.isdefault()
else:
raises(PropertiesOptionError, "api.forcepermissive.option(path).owner.isdefault()")
@autocheck
@ -88,14 +94,14 @@ def autocheck_value(api, path, **kwargs):
"""
# 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)
multi = api.forcepermissive.option(path).option.ismulti()
ismaster = api.forcepermissive.option(path).option.ismaster()
isslave = api.forcepermissive.option(path).option.isslave()
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)
raises(PropertiesOptionError, "api.forcepermissive.option(path).option.ismulti()")
multi = api.unrestraint.option(path).option.ismulti()
ismaster = api.unrestraint.option(path).option.ismaster()
isslave = api.unrestraint.option(path).option.isslave()
# set default value (different if value is multi or not)
if not multi:
@ -113,136 +119,136 @@ def autocheck_value(api, path, **kwargs):
# cannot test for slave (we cannot get all values for a slave)
if not isslave:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
assert api.value.get(path) == empty_value
assert api.option(path).value.get() == empty_value
else:
raises(PropertiesOptionError, "api.value.get(path)")
raises(PropertiesOptionError, "api.option(path).value.get()")
# test default value (should be empty) with permissive
# cannot test for slave (we cannot get all values for a slave)
raises(APIError, "api.unrestraint.value.get(path)")
raises(APIError, "api.unrestraint.option(path).value.get()")
if not isslave:
if not kwargs.get('propertyerror', False):
assert api.forcepermissive.value.get(path) == empty_value
assert api.forcepermissive.option(path).value.get() == empty_value
else:
raises(PropertiesOptionError, "api.forcepermissive.value.get(path)")
raises(PropertiesOptionError, "api.forcepermissive.option(path).value.get()")
# set a value without permissive
# for master/slave should have an index and good length
# for slave should have an index and good length
# for master must append, not set
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if ismaster:
raises(IndexError, "api.value.set(path, 0, first_value[0])")
api.value.append(path, first_value[0])
raises(APIError, "api.option(path, 0).value.set(first_value[0])")
api.option(path).value.append(first_value[0])
elif isslave:
#FIXME
print(api.value.append(path, first_value[0]))
raises(PropertiesOptionError, "api.value.append(path, first_value[0])")
api.value.set(path, 0, first_value[0])
print(api.option(path).value.append(first_value[0]))
raises(PropertiesOptionError, "api.option(path).value.append(first_value[0])")
api.option(path, 0).value.set(first_value[0])
raise Exception('pouet')
else:
api.value.set(path, first_value)
api.option(path).value.set(first_value)
else:
if ismaster:
raises(PropertiesOptionError, "api.value.append(path, first_value[0])")
raises(PropertiesOptionError, "api.option(path).value.append(first_value[0])")
elif isslave:
raises(PropertiesOptionError, "api.value.set(path, 0, first_value[0])")
raises(PropertiesOptionError, "api.option(path, 0).value.set(first_value[0])")
else:
raises(PropertiesOptionError, "api.value.set(path, first_value)")
raises(PropertiesOptionError, "api.option(path).value.set(first_value)")
# get value after set value without permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if isslave:
assert api.value.get(path, 0) == first_value[0]
assert api.option(path, 0).value.get() == first_value[0]
else:
assert api.value.get(path) == first_value
assert api.option(path).value.get() == first_value
elif kwargs.get('permissive', False):
if isslave:
raises(PropertiesOptionError, "api.value.get(path, 0)")
assert api.forcepermissive.value.get(path, 0) == empty_value
raises(PropertiesOptionError, "api.option(path, 0).value.get()")
assert api.forcepermissive.option(path, 0).value.get() == empty_value
else:
raises(PropertiesOptionError, "api.value.get(path)")
assert api.forcepermissive.value.get(path) == empty_value
raises(PropertiesOptionError, "api.option(path).value.get()")
assert api.forcepermissive.option(path).value.get() == empty_value
else:
if isslave:
raises(PropertiesOptionError, "api.value.get(path, 0)")
raises(PropertiesOptionError, "api.forcepermissive.value.get(path, 0)")
raises(PropertiesOptionError, "api.option(path, 0).value.get()")
raises(PropertiesOptionError, "api.forcepermissive.option(path, 0).value.get()")
else:
raises(PropertiesOptionError, "api.value.get(path)")
raises(PropertiesOptionError, "api.forcepermissive.value.get(path)")
raises(PropertiesOptionError, "api.option(path).value.get()")
raises(PropertiesOptionError, "api.forcepermissive.option(path).value.get()")
# set a value with permissive
if ismaster:
raises(APIError, "api.unrestraint.value.set(path, second_value[1])")
raises(APIError, "api.unrestraint.option(path).value.set(second_value[1])")
elif isslave:
raises(APIError, "api.unrestraint.value.append(path, second_value[1])")
raises(APIError, "api.unrestraint.option(path).value.append(second_value[1])")
else:
raises(APIError, "api.unrestraint.value.set(path, second_value)")
raises(APIError, "api.unrestraint.option(path).value.set(second_value)")
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if ismaster:
raises(IndexError, "api.forcepermissive.value.set(path, 1, second_value[1])")
api.forcepermissive.value.append(path, second_value[1])
raises(APIError, "api.forcepermissive.option(path, 1).value.set(second_value[1])")
api.forcepermissive.option(path).value.append(second_value[1])
elif isslave:
#FIXME
raises(PropertiesOptionError, "api.forcepermissive.value.append(path, second_value[1])")
api.value.set(path, 1, second_value[1])
raises(PropertiesOptionError, "api.forcepermissive.option(path).value.append(second_value[1])")
api.option(path, 1).value.set(second_value[1])
raise Exception('ca entre ici')
else:
api.value.set(path, second_value)
api.option(path).value.set(second_value)
elif kwargs.get('permissive', False):
if ismaster:
api.forcepermissive.value.append(path, second_value[0])
api.forcepermissive.value.append(path, second_value[1])
api.forcepermissive.option(path).value.append(second_value[0])
api.forcepermissive.option(path).value.append(second_value[1])
elif isslave:
api.forcepermissive.value.set(path, 1, second_value[1])
api.forcepermissive.option(path, 1).value.set(second_value[1])
else:
api.forcepermissive.value.set(path, first_value)
api.forcepermissive.option(path).value.set(first_value)
else:
if ismaster:
raises(PropertiesOptionError, "api.forcepermissive.value.append(path, first_value[0])")
raises(PropertiesOptionError, "api.forcepermissive.option(path).value.append(first_value[0])")
elif isslave:
raises(PropertiesOptionError, "api.forcepermissive.value.set(path, 0, first_value[0])")
raises(PropertiesOptionError, "api.forcepermissive.option(path, 0).value.set(first_value[0])")
else:
raises(PropertiesOptionError, "api.forcepermissive.value.set(path, first_value)")
raises(PropertiesOptionError, "api.forcepermissive.option(path).value.set(first_value)")
# get value after set value with permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if isslave:
assert api.value.get(path, 0) == second_value[0]
assert api.value.get(path, 1) == second_value[1]
assert api.option(path, 0).value.get() == second_value[0]
assert api.option(path, 1).value.get() == second_value[1]
else:
assert api.value.get(path) == second_value
assert api.option(path).value.get() == second_value
elif kwargs.get('permissive', False):
if ismaster:
raises(PropertiesOptionError, "api.value.get(path)")
assert api.forcepermissive.value.get(path) == second_value
raises(PropertiesOptionError, "api.option(path).value.get()")
assert api.forcepermissive.option(path).value.get() == second_value
elif isslave:
raises(PropertiesOptionError, "api.value.get(path, 0)")
raises(PropertiesOptionError, "api.value.get(path, 1)")
assert api.forcepermissive.value.get(path, 1) == second_value[1]
raises(PropertiesOptionError, "api.option(path, 0).value.get()")
raises(PropertiesOptionError, "api.option(path, 1).value.get()")
assert api.forcepermissive.option(path, 1).value.get() == second_value[1]
else:
raises(PropertiesOptionError, "api.value.get(path)")
assert api.forcepermissive.value.get(path) == first_value
raises(PropertiesOptionError, "api.option(path).value.get()")
assert api.forcepermissive.option(path).value.get() == first_value
else:
if isslave:
raises(PropertiesOptionError, "api.value.get(path, 0)")
raises(PropertiesOptionError, "api.forcepermissive.value.get(path, 0)")
raises(PropertiesOptionError, "api.option(path, 0).value.get()")
raises(PropertiesOptionError, "api.forcepermissive.option(path, 0).value.get()")
else:
raises(PropertiesOptionError, "api.value.get(path)")
raises(PropertiesOptionError, "api.forcepermissive.value.get(path)")
raises(PropertiesOptionError, "api.option(path).value.get()")
raises(PropertiesOptionError, "api.forcepermissive.option(path).value.get()")
@autocheck
def autocheck_reset_value(api, path, **kwargs):
# check if is a multi, a master or a slave
if not kwargs.get('propertyerror', False):
multi = api.forcepermissive.option.ismulti(path)
ismaster = api.forcepermissive.option.ismaster(path)
isslave = api.forcepermissive.option.isslave(path)
multi = api.forcepermissive.option(path).option.ismulti()
ismaster = api.forcepermissive.option(path).option.ismaster()
isslave = api.forcepermissive.option(path).option.isslave()
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)
raises(PropertiesOptionError, "api.forcepermissive.option(path).option.ismulti()")
multi = api.unrestraint.option(path).option.ismulti()
ismaster = api.unrestraint.option(path).option.ismaster()
isslave = api.unrestraint.option(path).option.isslave()
# set default value (different if value is multi or not)
if not multi:
@ -259,64 +265,64 @@ def autocheck_reset_value(api, path, **kwargs):
# reset value without permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if not isslave:
api.value.reset(path)
api.option(path).value.reset()
else:
api.value.reset(path, 0)
api.option(path, 0).value.reset()
else:
if not isslave:
raises(PropertiesOptionError, "api.value.reset(path)")
raises(PropertiesOptionError, "api.option(path).value.reset()")
else:
raises(PropertiesOptionError, "api.value.reset(path, 0)")
raises(PropertiesOptionError, "api.option(path, 0).value.reset()")
# get value after reset value without permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if isslave:
assert api.value.get(path, 0) == empty_value
assert api.value.get(path, 1) == second_value[1]
assert api.option(path, 0).value.get() == empty_value
assert api.option(path, 1).value.get() == second_value[1]
else:
assert api.value.get(path) == empty_value
assert api.option(path).value.get() == empty_value
elif kwargs.get('permissive', False):
if isslave:
raises(PropertiesOptionError, "api.value.get(path, 0)")
assert api.forcepermissive.value.get(path, 0) == empty_value
assert api.forcepermissive.value.get(path, 1) == second_value[1]
raises(PropertiesOptionError, "api.option(path, 0).value.get()")
assert api.forcepermissive.option(path, 0).value.get() == empty_value
assert api.forcepermissive.option(path, 1).value.get() == second_value[1]
else:
raises(PropertiesOptionError, "api.value.get(path)")
assert api.forcepermissive.value.get(path) == first_value
raises(PropertiesOptionError, "api.option(path).value.get()")
assert api.forcepermissive.option(path).value.get() == first_value
# reset value with permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if not isslave:
api.forcepermissive.value.reset(path)
api.forcepermissive.option(path).value.reset()
else:
api.forcepermissive.value.reset(path, 1)
api.forcepermissive.option(path, 1).value.reset()
elif kwargs.get('permissive', False):
if not isslave:
api.forcepermissive.value.reset(path)
api.forcepermissive.option(path).value.reset()
else:
api.forcepermissive.value.reset(path, 1)
api.forcepermissive.option(path, 1).value.reset()
else:
if not isslave:
raises(PropertiesOptionError, "api.forcepermissive.value.reset(path)")
raises(PropertiesOptionError, "api.forcepermissive.option(path).value.reset()")
else:
raises(PropertiesOptionError, "api.forcepermissive.value.reset(path, 1)")
raises(PropertiesOptionError, "api.forcepermissive.option(path, 1).value.reset()")
# get value after reset value with permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if isslave:
assert api.value.get(path, 0) == empty_value
assert api.value.get(path, 1) == empty_value
assert api.option(path, 0).value.get() == empty_value
assert api.option(path, 1).value.get() == empty_value
else:
assert api.value.get(path) == empty_value
assert api.option(path).value.get() == empty_value
elif kwargs.get('permissive', False):
if isslave:
raises(PropertiesOptionError, "api.value.get(path, 0)")
raises(PropertiesOptionError, "api.value.get(path, 1)")
assert api.forcepermissive.value.get(path, 0) == empty_value
assert api.forcepermissive.value.get(path, 1) == empty_value
raises(PropertiesOptionError, "api.option(path, 0).value.get()")
raises(PropertiesOptionError, "api.option(path, 1).value.get()")
assert api.forcepermissive.option(path, 0).value.get() == empty_value
assert api.forcepermissive.option(path, 1).value.get() == empty_value
else:
raises(PropertiesOptionError, "api.value.get(path)")
assert api.forcepermissive.value.get(path) == empty_value
raises(PropertiesOptionError, "api.option(path).value.get()")
assert api.forcepermissive.option(path).value.get() == empty_value
@autocheck
@ -332,13 +338,13 @@ def autocheck_property(api, path, **kwargs):
"""
# check if is a multi or a slave
if not kwargs.get('propertyerror', False):
multi = api.forcepermissive.option.ismulti(path)
isslave = api.forcepermissive.option.isslave(path)
multi = api.forcepermissive.option(path).option.ismulti()
isslave = api.forcepermissive.option(path).option.isslave()
else:
raises(PropertiesOptionError, "api.forcepermissive.option.ismulti(path)")
raises(PropertiesOptionError, "api.forcepermissive.option.isslave(path)")
multi = api.unrestraint.option.ismulti(path)
isslave = api.unrestraint.option.isslave(path)
raises(PropertiesOptionError, "api.forcepermissive.option(path).option.ismulti()")
raises(PropertiesOptionError, "api.forcepermissive.option(path).option.isslave()")
multi = api.unrestraint.option(path).option.ismulti()
isslave = api.unrestraint.option(path).option.isslave()
# define properties
properties = ['prop1', 'prop2']
@ -356,87 +362,87 @@ def autocheck_property(api, path, **kwargs):
# get properties without permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if not isslave:
assert set(api.property.get(path)) == set(default_props)
assert set(api.option(path).property.get()) == set(default_props)
else:
assert set(api.property.get(path, 0)) == set(default_props)
assert set(api.property.get(path, 1)) == set(default_props)
assert set(api.option(path, 0).property.get()) == set(default_props)
assert set(api.option(path, 1).property.get()) == set(default_props)
else:
raises(PropertiesOptionError, "api.property.get(path)")
raises(PropertiesOptionError, "api.option(path).property.get()")
# get properties with permissive
if not isslave:
raises(APIError, "api.unrestraint.property.get(path)")
raises(APIError, "api.unrestraint.option(path).property.get()")
else:
raises(APIError, "api.unrestraint.property.get(path, 0)")
raises(APIError, "api.unrestraint.option(path, 0).property.get()")
if not kwargs.get('propertyerror', False):
if not isslave:
assert set(api.forcepermissive.property.get(path)) == set(default_props)
assert set(api.forcepermissive.option(path).property.get()) == set(default_props)
else:
assert set(api.forcepermissive.property.get(path, 0)) == set(default_props)
assert set(api.forcepermissive.property.get(path, 1)) == set(default_props)
assert set(api.forcepermissive.option(path, 0).property.get()) == set(default_props)
assert set(api.forcepermissive.option(path, 1).property.get()) == set(default_props)
else:
if not isslave:
raises(PropertiesOptionError, "api.forcepermissive.property.get(path)")
raises(PropertiesOptionError, "api.forcepermissive.option(path).property.get()")
else:
raises(PropertiesOptionError, "api.forcepermissive.property.get(path, 0)")
raises(PropertiesOptionError, "api.forcepermissive.option(path, 0).property.get()")
# set properties without permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
api.property.set(path, properties)
api.option(path).property.set(properties)
else:
raises(PropertiesOptionError, "api.property.set(path, properties)")
raises(PropertiesOptionError, "api.option(path).property.set(properties)")
# check properties after set without permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
assert set(api.property.get(path)) == set(properties)
assert set(api.forcepermissive.property.get(path)) == set(properties)
assert set(api.option(path).property.get()) == set(properties)
assert set(api.forcepermissive.option(path).property.get()) == set(properties)
elif kwargs.get('permissive', False):
raises(PropertiesOptionError, "api.property.get(path)")
raises(PropertiesOptionError, "api.option(path).property.get()")
if not isslave:
assert set(api.forcepermissive.property.get(path)) == set(default_props)
assert set(api.forcepermissive.option(path).property.get()) == set(default_props)
else:
assert set(api.forcepermissive.property.get(path, 0)) == set(default_props)
assert set(api.forcepermissive.property.get(path, 1)) == set(default_props)
assert set(api.forcepermissive.option(path, 0).property.get()) == set(default_props)
assert set(api.forcepermissive.option(path, 1).property.get()) == set(default_props)
else:
if not isslave:
raises(PropertiesOptionError, "api.property.get(path)")
raises(PropertiesOptionError, "api.forcepermissive.property.get(path)")
raises(PropertiesOptionError, "api.option(path).property.get()")
raises(PropertiesOptionError, "api.forcepermissive.option(path).property.get()")
else:
raises(PropertiesOptionError, "api.property.get(path, 0)")
raises(PropertiesOptionError, "api.forcepermissive.property.get(path, 0)")
raises(PropertiesOptionError, "api.option(path, 0).property.get()")
raises(PropertiesOptionError, "api.forcepermissive.option(path, 0).property.get()")
# set properties with permissive
if not kwargs.get('propertyerror', False):
api.forcepermissive.property.set(path, properties)
api.forcepermissive.option(path).property.set(properties)
else:
raises(PropertiesOptionError, "api.forcepermissive.property.set(path, properties)")
raises(PropertiesOptionError, "api.forcepermissive.option(path).property.set(properties)")
# check properties after set with permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if not isslave:
assert set(api.property.get(path)) == set(properties)
assert set(api.forcepermissive.property.get(path)) == set(properties)
assert set(api.option(path).property.get()) == set(properties)
assert set(api.forcepermissive.option(path).property.get()) == set(properties)
else:
assert set(api.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.forcepermissive.property.get(path, 1)) == set(properties)
assert set(api.option(path, 0).property.get()) == set(properties)
assert set(api.forcepermissive.option(path, 0).property.get()) == set(properties)
assert set(api.option(path, 1).property.get()) == set(properties)
assert set(api.forcepermissive.option(path, 1).property.get()) == set(properties)
elif kwargs.get('permissive', False):
if not isslave:
raises(PropertiesOptionError, "api.property.get(path)")
assert set(api.forcepermissive.property.get(path)) == set(properties)
raises(PropertiesOptionError, "api.option(path).property.get()")
assert set(api.forcepermissive.option(path).property.get()) == set(properties)
else:
raises(PropertiesOptionError, "api.property.get(path, 0)")
assert set(api.forcepermissive.property.get(path, 0)) == set(properties)
raises(PropertiesOptionError, "api.property.get(path, 1)")
assert set(api.forcepermissive.property.get(path, 1)) == set(properties)
raises(PropertiesOptionError, "api.option(path, 0).property.get()")
assert set(api.forcepermissive.option(path, 0).property.get()) == set(properties)
raises(PropertiesOptionError, "api.option(path, 1).property.get()")
assert set(api.forcepermissive.option(path, 1).property.get()) == set(properties)
else:
if not isslave:
raises(PropertiesOptionError, "api.property.get(path)")
raises(PropertiesOptionError, "api.forcepermissive.property.get(path)")
raises(PropertiesOptionError, "api.option(path).property.get()")
raises(PropertiesOptionError, "api.forcepermissive.option(path).property.get()")
else:
raises(PropertiesOptionError, "api.property.get(path, 0)")
raises(PropertiesOptionError, "api.forcepermissive.property.get(path, 0)")
raises(PropertiesOptionError, "api.option(path, 0).property.get()")
raises(PropertiesOptionError, "api.forcepermissive.option(path, 0).property.get()")
@autocheck
@ -446,13 +452,13 @@ def autocheck_reset_property(api, path, **kwargs):
# check if is a multi or a slave
if not kwargs.get('propertyerror', False):
multi = api.forcepermissive.option.ismulti(path)
isslave = api.forcepermissive.option.isslave(path)
multi = api.forcepermissive.option(path).option.ismulti()
isslave = api.forcepermissive.option(path).option.isslave()
else:
raises(PropertiesOptionError, "api.forcepermissive.option.ismulti(path)")
raises(PropertiesOptionError, "api.forcepermissive.option.isslave(path)")
multi = api.unrestraint.option.ismulti(path)
isslave = api.unrestraint.option.isslave(path)
raises(PropertiesOptionError, "api.forcepermissive.option(path).option.ismulti()")
raises(PropertiesOptionError, "api.forcepermissive.option(path).option.isslave()")
multi = api.unrestraint.option(path).option.ismulti()
isslave = api.unrestraint.option(path).option.isslave()
# define properties
properties = ['prop1', 'prop2']
@ -469,63 +475,63 @@ def autocheck_reset_property(api, path, **kwargs):
# check properties
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
assert set(api.property.get(path)) == set(properties)
assert set(api.forcepermissive.property.get(path)) == set(properties)
assert set(api.option(path).property.get()) == set(properties)
assert set(api.forcepermissive.option(path).property.get()) == set(properties)
elif kwargs.get('permissive', False):
if not isslave:
assert set(api.forcepermissive.property.get(path)) == set(properties)
assert set(api.forcepermissive.option(path).property.get()) == set(properties)
else:
assert set(api.forcepermissive.property.get(path, 0)) == set(properties)
assert set(api.forcepermissive.property.get(path, 1)) == set(properties)
assert set(api.forcepermissive.option(path, 0).property.get()) == set(properties)
assert set(api.forcepermissive.option(path, 1).property.get()) == set(properties)
# reset properties without permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
api.property.reset(path)
api.option(path).property.reset()
else:
raises(PropertiesOptionError, "api.property.reset(path)")
raises(PropertiesOptionError, "api.option(path).property.reset()")
# check properties
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if not isslave:
assert set(api.property.get(path)) == set(default_props)
assert set(api.forcepermissive.property.get(path)) == set(default_props)
assert set(api.option(path).property.get()) == set(default_props)
assert set(api.forcepermissive.option(path).property.get()) == set(default_props)
else:
assert set(api.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.forcepermissive.property.get(path, 1)) == set(default_props)
assert set(api.option(path, 0).property.get()) == set(default_props)
assert set(api.forcepermissive.option(path, 0).property.get()) == set(default_props)
assert set(api.option(path, 1).property.get()) == set(default_props)
assert set(api.forcepermissive.option(path, 1).property.get()) == set(default_props)
elif kwargs.get('permissive', False):
if not isslave:
assert set(api.forcepermissive.property.get(path)) == set(properties)
assert set(api.forcepermissive.option(path).property.get()) == set(properties)
else:
assert set(api.forcepermissive.property.get(path, 0)) == set(properties)
assert set(api.forcepermissive.property.get(path, 1)) == set(properties)
assert set(api.forcepermissive.option(path, 0).property.get()) == set(properties)
assert set(api.forcepermissive.option(path, 1).property.get()) == set(properties)
# reset properties with permissive
raises(APIError, "api.unrestraint.property.set(path, properties)")
raises(APIError, "api.unrestraint.property.reset(path)")
raises(APIError, "api.unrestraint.option(path).property.set(properties)")
raises(APIError, "api.unrestraint.option(path).property.reset()")
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
api.forcepermissive.property.set(path, properties)
api.forcepermissive.property.reset(path)
api.forcepermissive.option(path).property.set(properties)
api.forcepermissive.option(path).property.reset()
elif kwargs.get('permissive', False):
api.forcepermissive.property.reset(path)
api.forcepermissive.option(path).property.reset()
# check properties
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if not isslave:
assert set(api.property.get(path)) == set(default_props)
assert set(api.forcepermissive.property.get(path)) == set(default_props)
assert set(api.option(path).property.get()) == set(default_props)
assert set(api.forcepermissive.option(path).property.get()) == set(default_props)
else:
assert set(api.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.forcepermissive.property.get(path, 1)) == set(default_props)
assert set(api.option(path, 0).property.get()) == set(default_props)
assert set(api.forcepermissive.option(path, 0).property.get()) == set(default_props)
assert set(api.option(path, 1).property.get()) == set(default_props)
assert set(api.forcepermissive.option(path, 1).property.get()) == set(default_props)
elif kwargs.get('permissive', False):
if not isslave:
assert set(api.forcepermissive.property.get(path)) == set(default_props)
assert set(api.forcepermissive.option(path).property.get()) == set(default_props)
else:
assert set(api.forcepermissive.property.get(path, 0)) == set(default_props)
assert set(api.forcepermissive.property.get(path, 1)) == set(default_props)
assert set(api.forcepermissive.option(path, 0).property.get()) == set(default_props)
assert set(api.forcepermissive.option(path, 1).property.get()) == set(default_props)
@autocheck
@ -539,131 +545,134 @@ def autocheck_owner_with_value(api, path, **kwargs):
"""
# check if is a isslave
if not kwargs.get('propertyerror', False):
isslave = api.forcepermissive.option.isslave(path)
isslave = api.forcepermissive.option(path).option.isslave()
else:
raises(PropertiesOptionError, "api.forcepermissive.option.isslave(path)")
isslave = api.unrestraint.option.isslave(path)
raises(PropertiesOptionError, "api.forcepermissive.option(path).option.isslave()")
isslave = api.unrestraint.option(path).option.isslave()
# get owner without permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if not isslave:
assert api.owner.get(path) == 'user'
assert api.option(path).owner.get() == 'user'
else:
assert api.owner.get(path, 0) == 'user'
assert api.owner.get(path, 1) == 'user'
assert api.option(path, 0).owner.get() == 'user'
assert api.option(path, 1).owner.get() == 'user'
else:
if not isslave:
raises(PropertiesOptionError, "api.owner.get(path)")
raises(PropertiesOptionError, "api.option(path).owner.get()")
else:
raises(PropertiesOptionError, "api.owner.get(path, 0)")
raises(PropertiesOptionError, "api.owner.get(path, 1)")
raises(PropertiesOptionError, "api.option(path, 0).owner.get()")
raises(PropertiesOptionError, "api.option(path, 1).owner.get()")
# get owner with permissive
if not kwargs.get('propertyerror', False):
if not isslave:
assert api.forcepermissive.owner.get(path) == 'user'
assert api.forcepermissive.option(path).owner.get() == 'user'
else:
assert api.forcepermissive.owner.get(path, 0) == 'default'
assert api.forcepermissive.owner.get(path, 1) == 'user'
assert api.forcepermissive.option(path, 0).owner.get() == 'default'
assert api.forcepermissive.option(path, 1).owner.get() == 'user'
else:
if not isslave:
raises(PropertiesOptionError, "api.forcepermissive.owner.get(path)")
raises(PropertiesOptionError, "api.forcepermissive.option(path).owner.get()")
else:
raises(PropertiesOptionError, "api.forcepermissive.owner.get(path, 0)")
raises(PropertiesOptionError, "api.forcepermissive.option(path, 0).owner.get()")
# test if is default owner without permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
assert api.owner.isdefault(path) is False
assert api.option(path).owner.isdefault() is False
else:
raises(PropertiesOptionError, "api.owner.isdefault(path)")
raises(PropertiesOptionError, "api.option(path).owner.isdefault()")
# test if is default owner with permissive
if not kwargs.get('propertyerror', False):
assert api.forcepermissive.owner.isdefault(path) is False
if not isslave:
assert api.forcepermissive.option(path).owner.isdefault() is False
else:
raises(PropertiesOptionError, "api.forcepermissive.owner.isdefault(path)")
assert api.forcepermissive.option(path, 0).owner.isdefault() is False
else:
raises(PropertiesOptionError, "api.forcepermissive.option(path).owner.isdefault()")
@autocheck
def autocheck_set_owner(api, path, **kwargs):
# test set owner without permissive
if not kwargs.get('propertyerror', False):
isslave = api.forcepermissive.option.isslave(path)
isslave = api.forcepermissive.option(path).option.isslave()
else:
raises(PropertiesOptionError, "api.forcepermissive.option.isslave(path)")
raises(PropertiesOptionError, "api.forcepermissive.option(path).option.isslave()")
isslave = False
# set owner without permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if not isslave:
api.owner.set(path, 'new_user')
api.option(path).owner.set('new_user')
else:
api.owner.set(path, 1, 'new_user')
api.option(path, 1).owner.set('new_user')
else:
if not isslave:
raises(PropertiesOptionError, "api.owner.set(path, 'new_user')")
raises(PropertiesOptionError, "api.option(path).owner.set('new_user')")
else:
raises(PropertiesOptionError, "api.owner.set(path, 1, 'new_user')")
raises(PropertiesOptionError, "api.option(path, 1).owner.set('new_user')")
# check owner set without permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if not isslave:
assert api.owner.get(path) == 'new_user'
assert api.forcepermissive.owner.get(path) == 'new_user'
assert api.option(path).owner.get() == 'new_user'
assert api.forcepermissive.option(path).owner.get() == 'new_user'
else:
assert api.owner.get(path, 1) == 'new_user'
assert api.forcepermissive.owner.get(path, 1) == 'new_user'
assert api.option(path, 1).owner.get() == 'new_user'
assert api.forcepermissive.option(path, 1).owner.get() == 'new_user'
elif not kwargs.get('propertyerror', False):
if not isslave:
assert api.forcepermissive.owner.get(path) == 'user'
assert api.forcepermissive.option(path).owner.get() == 'user'
else:
assert api.forcepermissive.owner.get(path, 1) == 'user'
assert api.forcepermissive.option(path, 1).owner.get() == 'user'
# set owner with permissive
if not kwargs.get('propertyerror', False):
if not isslave:
api.forcepermissive.owner.set(path, 'new_user1')
api.forcepermissive.option(path).owner.set('new_user1')
else:
api.forcepermissive.owner.set(path, 1, 'new_user1')
api.forcepermissive.option(path, 1).owner.set('new_user1')
else:
if not isslave:
raises(PropertiesOptionError, "api.forcepermissive.owner.set(path, 'new_user1')")
raises(PropertiesOptionError, "api.forcepermissive.option(path).owner.set('new_user1')")
else:
raises(PropertiesOptionError, "api.forcepermissive.owner.set(path, 1, 'new_user1')")
raises(PropertiesOptionError, "api.forcepermissive.option(path, 1).owner.set('new_user1')")
# get owner set with permissive
if not kwargs.get('propertyerror', False):
if not isslave:
assert api.forcepermissive.owner.get(path) == 'new_user1'
assert api.forcepermissive.option(path).owner.get() == 'new_user1'
else:
assert api.forcepermissive.owner.get(path, 0) == 'default'
assert api.forcepermissive.owner.get(path, 1) == 'new_user1'
assert api.forcepermissive.option(path, 0).owner.get() == 'default'
assert api.forcepermissive.option(path, 1).owner.get() == 'new_user1'
@autocheck
def autocheck_option(api, path, **kwargs):
expected_name = path.split('.')[-1]
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
current_name = api.option.getname(path)
assert current_name == api.forcepermissive.option.getname(path)
assert current_name == api.unrestraint.option.getname(path)
doc = api.option.getdoc(path)
assert doc == api.forcepermissive.option.getdoc(path)
assert doc == api.unrestraint.option.getdoc(path)
current_name = api.option(path).option.getname()
assert current_name == api.forcepermissive.option(path).option.getname()
assert current_name == api.unrestraint.option(path).option.getname()
doc = api.option(path).option.getdoc()
assert doc == api.forcepermissive.option(path).option.getdoc()
assert doc == api.unrestraint.option(path).option.getdoc()
elif not kwargs.get('propertyerror', False):
raises(PropertiesOptionError, "api.option.getname(path)")
current_name = api.forcepermissive.option.getname(path)
assert current_name == api.unrestraint.option.getname(path)
raises(PropertiesOptionError, "api.option.getdoc(path)")
doc = api.forcepermissive.option.getdoc(path)
assert doc == api.unrestraint.option.getdoc(path)
raises(PropertiesOptionError, "api.option(path).option.getname()")
current_name = api.forcepermissive.option(path).option.getname()
assert current_name == api.unrestraint.option(path).option.getname()
raises(PropertiesOptionError, "api.option(path).option.getdoc()")
doc = api.forcepermissive.option(path).option.getdoc()
assert doc == api.unrestraint.option(path).option.getdoc()
else:
raises(PropertiesOptionError, "api.option.getname(path)")
raises(PropertiesOptionError, "api.forcepermissive.option.getname(path)")
current_name = api.unrestraint.option.getname(path)
raises(PropertiesOptionError, "api.option.getdoc(path)")
raises(PropertiesOptionError, "api.forcepermissive.option.getdoc(path)")
doc = api.unrestraint.option.getdoc(path)
raises(PropertiesOptionError, "api.option(path).option.getname()")
raises(PropertiesOptionError, "api.forcepermissive.option(path).option.getname()")
current_name = api.unrestraint.option(path).option.getname()
raises(PropertiesOptionError, "api.option(path).option.getdoc()")
raises(PropertiesOptionError, "api.forcepermissive.option(path).option.getdoc()")
doc = api.unrestraint.option(path).option.getdoc()
assert current_name == expected_name
if expected_name.endswith('val1') or expected_name.endswith('val2'):
expected_name = expected_name[:-4]
@ -676,14 +685,14 @@ def autocheck_permissive(api, path, **kwargs):
"""
# 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)
multi = api.forcepermissive.option(path).option.ismulti()
ismaster = api.forcepermissive.option(path).option.ismaster()
isslave = api.forcepermissive.option(path).option.isslave()
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)
raises(PropertiesOptionError, "api.forcepermissive.option(path).option.ismulti()")
multi = api.unrestraint.option(path).option.ismulti()
ismaster = api.unrestraint.option(path).option.ismaster()
isslave = api.unrestraint.option(path).option.isslave()
# set default value (different if value is multi or not)
if not multi:
@ -701,60 +710,64 @@ def autocheck_permissive(api, path, **kwargs):
# 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)")
raises(PropertiesOptionError, "api.option(path).value.get()")
raises(PropertiesOptionError, "api.forcepermissive.option(path).value.get()")
else:
raises(PropertiesOptionError, "api.value.get(path, 0)")
raises(PropertiesOptionError, "api.forcepermissive.value.get(path, 0)")
raises(PropertiesOptionError, "api.option(path, 0).value.get()")
raises(PropertiesOptionError, "api.forcepermissive.option(path, 0).value.get()")
elif kwargs.get('permissive', False):
if not isslave:
raises(PropertiesOptionError, "api.value.get(path)")
api.forcepermissive.value.get(path)
raises(PropertiesOptionError, "api.option(path).value.get()")
api.forcepermissive.option(path).value.get()
else:
raises(PropertiesOptionError, "api.value.get(path, 0)")
api.forcepermissive.value.get(path, 0)
raises(PropertiesOptionError, "api.option(path, 0).value.get()")
api.forcepermissive.option(path, 0).value.get()
else:
if not isslave:
api.value.get(path)
api.option(path).value.get()
else:
api.value.get(path, 0)
assert api.permissive.get(path) == frozenset()
api.permissive.set(path, ('disabled',))
assert api.permissive.get(path) == frozenset(['disabled'])
api.option(path, 0).value.get()
assert api.unrestraint.option(path).permissive.get() == frozenset()
api.unrestraint.option(path).permissive.set(('disabled',))
assert api.unrestraint.option(path).permissive.get() == 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)
raises(PropertiesOptionError, "api.option(path).value.get()")
api.forcepermissive.option(path).value.get()
else:
raises(PropertiesOptionError, "api.value.get(path, 0)")
api.forcepermissive.value.get(path, 0)
raises(PropertiesOptionError, "api.option(path, 0).value.get()")
api.forcepermissive.option(path, 0).value.get()
else:
if not isslave:
api.value.get(path)
api.option(path).value.get()
else:
api.value.get(path, 0)
api.option(path, 0).value.get()
api.permissive.set(path, ('disabled', 'hidden'))
#FIXME
#api.option(path).permissive.set(('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 !!!')
## can access to value
#if not isslave:
# api.option(path).value.get()
#else:
# api.option(path, 0).value.get()
#assert api.option(path).permissive.get() == frozenset(['disabled', 'hidden'])
#
#print('FIXME del !!!')
def check_all(api, path, multi, **kwargs):
if DISPLAY:
text = u' {} launch tests for {}'.format(ICON, path)
if multi:
text += u' as a multi'
print(text)
for func in autocheck_registers:
if DISPLAY:
print(u' {} {}'.format(ICON, func.__name__))
func(api, path, **kwargs)
@ -871,6 +884,7 @@ DICT_PATHS = [
@pytest.fixture(scope="function", params=DICT_PATHS)
def paths(request):
if DISPLAY:
print(u'\n{} {}: {}'.format(ICON, request.function.__name__, request.param))
return request.param
@ -908,6 +922,7 @@ DICT_PATHS2 = [
@pytest.fixture(scope="function", params=DICT_PATHS2)
def paths2(request):
if DISPLAY:
print(u'\n{} {}: {}'.format(ICON, request.function.__name__, request.param))
return request.param

View File

@ -17,9 +17,10 @@ from .option import *
from .error import APIError
from .api import getapi
from .option import __all__ as all_options
from .setting import owners, undefined
allfuncs = ['Config', 'getapi', 'APIError']
allfuncs = ['Config', 'getapi', 'APIError', 'undefined']
allfuncs.extend(all_options)
del(all_options)
__all__ = tuple(allfuncs)

View File

@ -18,64 +18,45 @@ from inspect import ismethod, getdoc
from .error import APIError
from .i18n import _
from .setting import owners, undefined
def getter(func):
def wrapper(self, path, *args, **kwargs):
opt = self._get_obj_by_path(path)
if opt.impl_is_master_slaves('slave'):
get = self._slave_get
else:
get = self._simple_get
return get(path, *args, **kwargs)
return wrapper
def setter(func):
def wrapper(self, path, *args, **kwargs):
opt = self._get_obj_by_path(path)
if opt.impl_is_master_slaves('slave'):
return self._slave_set(path, *args, **kwargs)
elif opt.impl_is_master_slaves('master'):
return self._master_set(path, *args, **kwargs)
else:
return self._simple_set(path, *args, **kwargs)
return wrapper
def resetter(func):
def wrapper(self, path, *args, **kwargs):
opt = self._get_obj_by_path(path)
if opt.impl_is_master_slaves('slave'):
reset = self._slave_reset
else:
reset = self._simple_reset
return reset(path, *args, **kwargs)
return wrapper
try:
from .value import Multi
except:
Multi = list
class CommonTiramisu(object):
icon = '\u2937'
tmpl_help = u' {} {}: {}'
allow_unrestraint = False
slave_need_index = True
def __init__(self, config, force_permissive, force_unrestraint):
def __init__(self,
opt,
path,
index,
config,
force_permissive,
force_unrestraint):
self.opt = opt
self.path = path
self.index = index
if self.slave_need_index:
self._test_slave_index()
self.config = config
self.force_permissive = force_permissive
self.force_unrestraint = force_unrestraint
if not self.allow_unrestraint:
self._unrestraint_not_allowed(force_unrestraint)
def _test_slave_index(self):
if self.index is None and self.opt.impl_is_master_slaves('slave'):
raise APIError('index must be set with a slave option')
def _unrestraint_not_allowed(self, force_unrestraint):
if force_unrestraint:
name = self.__class__.__name__[11:].lower()
name = self.__class__.__name__[14:].lower()
raise APIError(_('{} cannot be unrestraint').format(name))
def _get_obj_by_path(self, path, index=None):
validate = not self.force_unrestraint
return self.config.unwrap_from_path(path,
validate=validate,
validate_properties=validate,
force_permissive=self.force_permissive,
index=index)
def __getattr__(self, name):
if name == 'help':
return self._help()
@ -95,183 +76,136 @@ class CommonTiramisu(object):
return '\n'.join(txt)
class TiramisuAPIOption(CommonTiramisu):
class TiramisuOptionOption(CommonTiramisu):
"""get information from an option"""
allow_unrestraint = True
slave_need_index = False
def __init__(self, config, force_permissive, force_unrestraint):
super(TiramisuAPIOption, self).__init__(config, force_permissive, force_unrestraint)
self.config = config
self.force_permissive = force_permissive
self.force_unrestraint = force_unrestraint
def __init__(self, opt, path, index, config, force_permissive, force_unrestraint):
super(TiramisuOptionOption, self).__init__(opt,
path,
index,
config,
force_permissive,
force_unrestraint)
if config:
self.values = self.config.cfgimpl_get_values()
def ismulti(self, path):
def ismulti(self):
"""test if option could have multi value"""
opt = self._get_obj_by_path(path)
return opt.impl_is_multi()
return self.opt.impl_is_multi()
def ismasterslaves(self, path):
def ismasterslaves(self):
"""test if option is a master or a slave"""
opt = self._get_obj_by_path(path)
return opt.impl_is_master_slaves()
return self.opt.impl_is_master_slaves()
def ismaster(self, path):
def ismaster(self):
"""test if option is a master"""
opt = self._get_obj_by_path(path)
return opt.impl_is_master_slaves('master')
return self.opt.impl_is_master_slaves('master')
def isslave(self, path):
def isslave(self):
"""test if option is a slave"""
opt = self._get_obj_by_path(path)
return opt.impl_is_master_slaves('slave')
return self.opt.impl_is_master_slaves('slave')
def getname(self, path):
opt = self._get_obj_by_path(path)
return opt.impl_getname()
def getname(self):
return self.opt.impl_getname()
def getdoc(self, path):
opt = self._get_obj_by_path(path)
return opt.impl_get_display_name()
def getdoc(self):
return self.opt.impl_get_display_name()
class TiramisuAPIOwner(CommonTiramisu):
class TiramisuOptionOwner(CommonTiramisu):
"""manager option's owner"""
def __init__(self, config, force_permissive, force_unrestraint):
super(TiramisuAPIOwner, self).__init__(config, force_permissive, force_unrestraint)
self.config = config
self.force_permissive = force_permissive
self.force_unrestraint = force_unrestraint
def __init__(self, opt, path, index, config, force_permissive, force_unrestraint):
super(TiramisuOptionOwner, self).__init__(opt,
path,
index,
config,
force_permissive,
force_unrestraint)
if config:
self.values = self.config.cfgimpl_get_values()
@getter
def get(self):
"""get owner for a specified option"""
pass
def _simple_get(self, path):
##FIXME should not be here, just for check property
#self.config.getattr(path,
# force_permissive=self.force_permissive)
# FIXME doublons aussi
opt = self._get_obj_by_path(path)
return self.values.getowner(opt,
return self.values.getowner(self.opt,
index=self.index,
force_permissive=self.force_permissive)
def _slave_get(self, path, index):
##FIXME should not be here, just for check property
#self.config.getattr(path,
# index=index,
# force_permissive=self.force_permissive)
# FIXME doublons aussi
opt = self._get_obj_by_path(path,
index=index)
return self.values.getowner(opt,
index=index,
force_permissive=self.force_permissive)
def isdefault(self, path):
def isdefault(self):
"""is option has defaut value"""
#FIXME isdefault for slave should have index!
opt = self._get_obj_by_path(path)
#FIXME should not be here, just for check property
self.config.getattr(path,
force_permissive=self.force_permissive)
return self.values.is_default_owner(opt,
return self.values.is_default_owner(self.opt,
force_permissive=self.force_permissive)
@setter
def set(self):
def set(self, owner):
"""get owner for a specified option"""
pass
def _simple_set(self, path, owner):
#FIXME doublons, opt est deja dans le setter
opt = self._get_obj_by_path(path)
try:
obj_owner = getattr(owners, owner)
except AttributeError:
owners.addowner(owner)
obj_owner = getattr(owners, owner)
self.values.setowner(opt,
self.values.setowner(self.opt,
obj_owner,
force_permissive=self.force_permissive)
def _master_set(self, path, owner):
return self._simple_set(path, owner)
def _slave_set(self, path, index, owner):
#FIXME doublons, opt est deja dans le setter
opt = self._get_obj_by_path(path, index)
try:
obj_owner = getattr(owners, owner)
except AttributeError:
owners.addowner(owner)
obj_owner = getattr(owners, owner)
self.values.setowner(opt,
obj_owner,
index,
self.index,
force_permissive=self.force_permissive)
class TiramisuAPIProperty(CommonTiramisu):
class TiramisuOptionProperty(CommonTiramisu):
"""manager option's property"""
#allow_unrestraint = True
slave_need_index = False
def __init__(self, config, force_permissive, force_unrestraint):
super(TiramisuAPIProperty, self).__init__(config, force_permissive, force_unrestraint)
self.config = config
self.force_permissive = force_permissive
self.force_unrestraint = force_unrestraint
def __init__(self, opt, path, index, config, force_permissive, force_unrestraint):
super(TiramisuOptionProperty, self).__init__(opt,
path,
index,
config,
force_permissive,
force_unrestraint)
if config:
self.settings = config.cfgimpl_get_settings()
@getter
def get(self, path):
"""get property for a specified option"""
def get(self):
self._test_slave_index()
return self.settings.getproperties(self.opt, self.path, index=self.index, obj=False)
def _simple_get(self, path):
opt = self._get_obj_by_path(path)
return self.settings.getproperties(opt, path, obj=False)
def _slave_get(self, path, index):
opt = self._get_obj_by_path(path)
return self.settings.getproperties(opt, path, index=index, obj=False)
def set(self, path, properties):
def set(self, properties):
"""set properties for a specified option"""
opt = self._get_obj_by_path(path)
self.settings.setproperties(set(properties),
opt,
path)
self.opt,
self.path)
def reset(self, path):
def reset(self):
"""reset all personalised properties
"""
self._get_obj_by_path(path)
self.settings.reset(_path=path)
self.settings.reset(_path=self.path)
class TiramisuAPIPermissive(CommonTiramisu):
class TiramisuOptionPermissive(CommonTiramisu):
"""manager option's property"""
allow_unrestraint = True
slave_need_index = False
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
def __init__(self, opt, path, index, config, force_permissive, force_unrestraint):
super(TiramisuOptionPermissive, self).__init__(opt,
path,
index,
config,
force_permissive,
force_unrestraint)
if config:
self.settings = config.cfgimpl_get_settings()
def get(self, path):
def get(self):
"""get permissive value for a specified path"""
setting_properties = self.settings.getproperties(None, None, obj=False)
return self.settings.getpermissive(setting_properties, path)
return self.settings.getpermissive(setting_properties, self.path)
def set(self, path, permissive):
self.settings.setpermissive(permissive, opt=None, path=path)
def set(self, permissive):
self.settings.setpermissive(permissive, opt=self.opt, path=self.path)
#def reset(self, path):
# """reset all personalised properties
@ -280,73 +214,108 @@ class TiramisuAPIPermissive(CommonTiramisu):
# self.settings.reset(_path=path)
class TiramisuAPIValue(CommonTiramisu):
class TiramisuOptionValue(CommonTiramisu):
"""manager option's value"""
def __init__(self, config, force_permissive, force_unrestraint):
super(TiramisuAPIValue, self).__init__(config, force_permissive, force_unrestraint)
def __init__(self, opt, path, index, config, force_permissive, force_unrestraint):
super(TiramisuOptionValue, self).__init__(opt,
path,
index,
config,
force_permissive,
force_unrestraint)
def append(self, value=undefined):
if not self.opt.impl_is_master_slaves('master'):
raise APIError('append is only allowed for a master')
multi = self.config.getattr(self.path,
force_permissive=self.force_permissive)
multi.append(value)
self.set(multi)
def get(self):
value = self.config.getattr(self.path,
index=self.index,
force_permissive=self.force_permissive)
if isinstance(value, Multi):
value = list(value)
return value
def set(self, value):
"""set a value for a specified option"""
values = self.config.cfgimpl_get_values()
if isinstance(value, list):
while undefined in value:
idx = value.index(undefined)
value[idx] = values._getdefaultvalue(self.opt,
self.path,
True,
idx,
undefined,
True)
else:
if value == undefined:
value = values._getdefaultvalue(self.opt,
self.path,
True,
self.index,
undefined,
True)
self.config.setattr(self.path,
value,
index=self.index,
force_permissive=self.force_permissive)
def reset(self):
"""reset value for a value"""
if self.index is None:
self.config.cfgimpl_get_values().reset(self.opt,
path=self.path,
force_permissive=self.force_permissive)
else:
#FIXME ... _p_ ...
self.config.cfgimpl_get_values()._p_.resetvalue_index(self.path, self.index)
class TiramisuOption(object):
icon = '\u2937'
tmpl_help = ' {} {}: {}'
def __init__(self, opt, path, index, config, force_permissive=False, force_unrestraint=False):
self.opt = opt
self.path = path
self.index = index
self.config = config
self.force_permissive = force_permissive
self.force_unrestraint = force_unrestraint
self.registers = {}
self.prefix = self.__class__.__name__
for module_name in globals().keys():
if module_name != self.prefix and module_name.startswith(self.prefix):
module = globals()[module_name]
func_name = module_name[len(self.prefix):].lower()
self.registers[func_name] = module
def append(self, path, value=undefined):
opt = self._get_obj_by_path(path)
if not opt.impl_is_master_slaves('master'):
raise APIError('append is only allowed for a master')
multi = self.config.getattr(path,
force_permissive=self.force_permissive)
multi.append(value, force_permissive=self.force_permissive)
def _help(self):
txt = []
for module_name, module in self.registers.items():
module_doc = getdoc(module)
txt.append(self.tmpl_help.format(self.icon, module_name, module_doc))
txt.append(module(None, None).help)
return '\n'.join(txt)
@getter
def get(self):
"""get value for a specified option"""
pass
def _simple_get(self, path):
return self.config.getattr(path,
force_permissive=self.force_permissive)
def _slave_get(self, path, index):
return self.config.getattr(path,
index=index,
force_permissive=self.force_permissive)
@setter
def set(self):
"""set a value for a specified option"""
pass
def _simple_set(self, path, value):
self.config.setattr(path,
value,
force_permissive=self.force_permissive)
def _master_set(self, path, index, value):
multi = self.config.getattr(path,
force_permissive=self.force_permissive)
multi[index] = value
def _slave_set(self, path, index, value):
self.config.setattr(path,
value,
index=index,
force_permissive=self.force_permissive)
@resetter
def reset(self, path):
"""reset value for a value"""
pass
def _simple_reset(self, path):
opt = self._get_obj_by_path(path)
self.config.cfgimpl_get_values().reset(opt,
path=path,
force_permissive=self.force_permissive)
def _slave_reset(self, path, index):
self._get_obj_by_path(path)
#FIXME ... _p_ ...
self.config.cfgimpl_get_values()._p_.resetvalue_index(path, index)
def __getattr__(self, subfunc):
if subfunc in self.registers:
return self.registers[subfunc](self.opt,
self.path,
self.index,
self.config,
self.force_permissive,
self.force_unrestraint)
elif subfunc == 'help':
return self._help()
else:
raise APIError(_('please specify a valid sub function'))
class TiramisuAPI(object):
@ -361,20 +330,25 @@ class TiramisuAPI(object):
self.config.read_write()
self.config.cfgimpl_get_settings().setpermissive(('hidden',))
#/FIXME ?
self.registers = {}
self.prefix = self.__class__.__name__
for module_name in globals().keys():
if module_name != self.prefix and module_name.startswith(self.prefix):
module = globals()[module_name]
func_name = module_name[11:].lower()
self.registers[func_name] = module
def option(self, path, index=None):
validate = not self.force_unrestraint
opt = self.config.unwrap_from_path(path,
validate=validate,
validate_properties=validate,
force_permissive=self.force_permissive,
index=index)
if index is not None and not opt.impl_is_master_slaves('slave'):
raise APIError('index must be set only with a slave option')
return TiramisuOption(opt,
path,
index,
self.config,
force_permissive=self.force_permissive,
force_unrestraint=self.force_unrestraint)
def __getattr__(self, subfunc):
if subfunc in self.registers:
return self.registers[subfunc](self.config,
self.force_permissive,
self.force_unrestraint)
elif subfunc == 'forcepermissive':
if subfunc == 'forcepermissive':
return TiramisuAPI(self.config, force_permissive=True, force_unrestraint=self.force_unrestraint)
elif subfunc == 'unrestraint':
return TiramisuAPI(self.config, force_permissive=self.force_permissive, force_unrestraint=True)

View File

@ -103,11 +103,23 @@ class Values(object):
if opt.impl_is_multi() and index is not None:
if value == []:
value = opt.impl_getdefault_multi()
if submulti_index is undefined and opt.impl_is_submulti():
if value is None:
value = []
elif not isinstance(value, list):
value = [value]
else:
if len(value) > index:
value = value[index]
else:
value = opt.impl_getdefault_multi()
if submulti_index is undefined and opt.impl_is_submulti():
if value is None:
value = []
elif not isinstance(value, list):
value = [value]
if opt.impl_is_submulti() and not isinstance(value, list) and submulti_index is undefined:
value = [value]
return value
def _getvalue(self, opt, path, self_properties, index, submulti_index,