add unrestraint in option
This commit is contained in:
@ -6,7 +6,8 @@ from .autopath import do_autopath
|
||||
do_autopath()
|
||||
from tiramisu import Config, StrOption, OptionDescription, MasterSlaves, DynOptionDescription, \
|
||||
getapi
|
||||
from tiramisu.error import PropertiesOptionError
|
||||
from tiramisu.error import PropertiesOptionError, APIError
|
||||
from collections import OrderedDict
|
||||
ICON = u'\u2937'
|
||||
|
||||
OPTIONS_TYPE = {'str': {'type': str,
|
||||
@ -57,6 +58,7 @@ def autocheck_owner_without_value(api, path, **kwargs):
|
||||
raises(PropertiesOptionError, "api.owner.get(path)")
|
||||
else:
|
||||
raises(PropertiesOptionError, "api.owner.get(path, 0)")
|
||||
raises(APIError, "api.unrestraint.owner.get(path)")
|
||||
if not kwargs.get('propertyerror', False):
|
||||
if not isslave:
|
||||
assert api.permissive.owner.get(path) == 'default'
|
||||
@ -69,6 +71,7 @@ def autocheck_owner_without_value(api, path, **kwargs):
|
||||
raises(PropertiesOptionError, "api.permissive.owner.get(path, 0)")
|
||||
|
||||
# check if default owner
|
||||
raises(APIError, "api.unrestraint.owner.isdefault(path)")
|
||||
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
||||
assert api.owner.isdefault(path)
|
||||
else:
|
||||
@ -83,15 +86,6 @@ def autocheck_owner_without_value(api, path, **kwargs):
|
||||
def autocheck_value(api, path, **kwargs):
|
||||
"""set and get values
|
||||
"""
|
||||
print('=============')
|
||||
try:
|
||||
print(api.permissive.owner.get(path))
|
||||
except Exception as pouet:
|
||||
try:
|
||||
print(api.permissive.owner.get(path, 0))
|
||||
except Exception as pouet:
|
||||
print(pouet)
|
||||
pass
|
||||
# check if is a multi, a master or a slave
|
||||
if not kwargs.get('propertyerror', False):
|
||||
multi = api.permissive.option.ismulti(path)
|
||||
@ -99,9 +93,9 @@ def autocheck_value(api, path, **kwargs):
|
||||
isslave = api.permissive.option.isslave(path)
|
||||
else:
|
||||
raises(PropertiesOptionError, "api.permissive.option.ismulti(path)")
|
||||
multi = False
|
||||
ismaster = False
|
||||
isslave = False
|
||||
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:
|
||||
@ -125,6 +119,7 @@ def autocheck_value(api, path, **kwargs):
|
||||
|
||||
# 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)")
|
||||
if not isslave:
|
||||
if not kwargs.get('propertyerror', False):
|
||||
assert api.permissive.value.get(path) == empty_value
|
||||
@ -176,6 +171,12 @@ def autocheck_value(api, path, **kwargs):
|
||||
raises(PropertiesOptionError, "api.permissive.value.get(path)")
|
||||
|
||||
# set a value with permissive
|
||||
if ismaster:
|
||||
raises(APIError, "api.unrestraint.value.set(path, second_value[1])")
|
||||
elif isslave:
|
||||
raises(APIError, "api.unrestraint.value.append(path, second_value[1])")
|
||||
else:
|
||||
raises(APIError, "api.unrestraint.value.set(path, second_value)")
|
||||
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
||||
if ismaster:
|
||||
raises(IndexError, "api.permissive.value.set(path, 1, second_value[1])")
|
||||
@ -228,15 +229,6 @@ def autocheck_value(api, path, **kwargs):
|
||||
else:
|
||||
raises(PropertiesOptionError, "api.value.get(path)")
|
||||
raises(PropertiesOptionError, "api.permissive.value.get(path)")
|
||||
print('=============')
|
||||
try:
|
||||
print(api.permissive.owner.get(path))
|
||||
except Exception as pouet:
|
||||
try:
|
||||
print(api.permissive.owner.get(path, 0))
|
||||
except Exception as pouet:
|
||||
print(pouet)
|
||||
pass
|
||||
|
||||
|
||||
@autocheck
|
||||
@ -248,9 +240,9 @@ def autocheck_reset_value(api, path, **kwargs):
|
||||
isslave = api.permissive.option.isslave(path)
|
||||
else:
|
||||
raises(PropertiesOptionError, "api.permissive.option.ismulti(path)")
|
||||
multi = False
|
||||
ismaster = False
|
||||
isslave = False
|
||||
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:
|
||||
@ -329,7 +321,7 @@ def autocheck_reset_value(api, path, **kwargs):
|
||||
|
||||
@autocheck
|
||||
def autocheck_value2(*args, **kwargs):
|
||||
"""reset value
|
||||
"""re set value
|
||||
"""
|
||||
autocheck_value(*args, **kwargs)
|
||||
|
||||
@ -345,8 +337,8 @@ def autocheck_property(api, path, **kwargs):
|
||||
else:
|
||||
raises(PropertiesOptionError, "api.permissive.option.ismulti(path)")
|
||||
raises(PropertiesOptionError, "api.permissive.option.isslave(path)")
|
||||
multi = False
|
||||
isslave = False
|
||||
multi = api.unrestraint.option.ismulti(path)
|
||||
isslave = api.unrestraint.option.isslave(path)
|
||||
|
||||
# define properties
|
||||
properties = ['prop1', 'prop2']
|
||||
@ -372,6 +364,10 @@ def autocheck_property(api, path, **kwargs):
|
||||
raises(PropertiesOptionError, "api.property.get(path)")
|
||||
|
||||
# get properties with permissive
|
||||
if not isslave:
|
||||
raises(APIError, "api.unrestraint.property.get(path)")
|
||||
else:
|
||||
raises(APIError, "api.unrestraint.property.get(path, 0)")
|
||||
if not kwargs.get('propertyerror', False):
|
||||
if not isslave:
|
||||
assert set(api.permissive.property.get(path)) == set(default_props)
|
||||
@ -455,8 +451,8 @@ def autocheck_reset_property(api, path, **kwargs):
|
||||
else:
|
||||
raises(PropertiesOptionError, "api.permissive.option.ismulti(path)")
|
||||
raises(PropertiesOptionError, "api.permissive.option.isslave(path)")
|
||||
multi = False
|
||||
isslave = False
|
||||
multi = api.unrestraint.option.ismulti(path)
|
||||
isslave = api.unrestraint.option.isslave(path)
|
||||
|
||||
# define properties
|
||||
properties = ['prop1', 'prop2']
|
||||
@ -506,6 +502,8 @@ def autocheck_reset_property(api, path, **kwargs):
|
||||
assert set(api.permissive.property.get(path, 1)) == set(properties)
|
||||
|
||||
# reset properties with permissive
|
||||
raises(APIError, "api.unrestraint.property.set(path, properties)")
|
||||
raises(APIError, "api.unrestraint.property.reset(path)")
|
||||
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
||||
api.permissive.property.set(path, properties)
|
||||
api.permissive.property.reset(path)
|
||||
@ -544,7 +542,7 @@ def autocheck_owner_with_value(api, path, **kwargs):
|
||||
isslave = api.permissive.option.isslave(path)
|
||||
else:
|
||||
raises(PropertiesOptionError, "api.permissive.option.isslave(path)")
|
||||
isslave = False
|
||||
isslave = api.unrestraint.option.isslave(path)
|
||||
|
||||
# get owner without permissive
|
||||
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
||||
@ -565,9 +563,6 @@ def autocheck_owner_with_value(api, path, **kwargs):
|
||||
if not isslave:
|
||||
assert api.permissive.owner.get(path) == 'user'
|
||||
else:
|
||||
print('--------')
|
||||
print(api.permissive.owner.get(path, 0))
|
||||
print(api.permissive.value.get(path, 0))
|
||||
assert api.permissive.owner.get(path, 0) == 'default'
|
||||
assert api.permissive.owner.get(path, 1) == 'user'
|
||||
else:
|
||||
@ -645,6 +640,36 @@ def autocheck_set_owner(api, path, **kwargs):
|
||||
assert api.permissive.owner.get(path, 1) == '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.permissive.option.getname(path)
|
||||
assert current_name == api.unrestraint.option.getname(path)
|
||||
doc = api.option.getdoc(path)
|
||||
assert doc == api.permissive.option.getdoc(path)
|
||||
assert doc == api.unrestraint.option.getdoc(path)
|
||||
elif not kwargs.get('propertyerror', False):
|
||||
raises(PropertiesOptionError, "api.option.getname(path)")
|
||||
current_name = api.permissive.option.getname(path)
|
||||
assert current_name == api.unrestraint.option.getname(path)
|
||||
raises(PropertiesOptionError, "api.option.getdoc(path)")
|
||||
doc = api.permissive.option.getdoc(path)
|
||||
assert doc == api.unrestraint.option.getdoc(path)
|
||||
else:
|
||||
raises(PropertiesOptionError, "api.option.getname(path)")
|
||||
raises(PropertiesOptionError, "api.permissive.option.getname(path)")
|
||||
current_name = api.unrestraint.option.getname(path)
|
||||
raises(PropertiesOptionError, "api.option.getdoc(path)")
|
||||
raises(PropertiesOptionError, "api.permissive.option.getdoc(path)")
|
||||
doc = api.unrestraint.option.getdoc(path)
|
||||
assert current_name == expected_name
|
||||
if expected_name.endswith('val1') or expected_name.endswith('val2'):
|
||||
expected_name = expected_name[:-4]
|
||||
assert doc == "{}'s option".format(expected_name)
|
||||
|
||||
|
||||
def check_all(api, path, multi, **kwargs):
|
||||
text = u' {} launch tests for {}'.format(ICON, path)
|
||||
if multi:
|
||||
@ -729,39 +754,39 @@ def make_api(options, multi):
|
||||
|
||||
DICT_PATHS = [
|
||||
#test a config without optiondescription
|
||||
{'first': 'first',
|
||||
'second': 'second_disabled',
|
||||
'third': 'third_hidden'},
|
||||
OrderedDict({'first': 'first',
|
||||
'second': 'second_disabled',
|
||||
'third': 'third_hidden'}),
|
||||
#test a config with an optiondescription
|
||||
{'subod.first': 'subod.first',
|
||||
'subod.second': 'subod.second_disabled',
|
||||
'subod.third': 'subod.third_hidden'},
|
||||
OrderedDict({'subod.first': 'subod.first',
|
||||
'subod.second': 'subod.second_disabled',
|
||||
'subod.third': 'subod.third_hidden'}),
|
||||
#test a config with two optiondescription
|
||||
{'subod.subsubod.first': 'subod.subsubod.first',
|
||||
'subod.subsubod.second': 'subod.subsubod.second_disabled',
|
||||
'subod.subsubod.third': 'subod.subsubod.third_hidden'},
|
||||
OrderedDict({'subod.subsubod.first': 'subod.subsubod.first',
|
||||
'subod.subsubod.second': 'subod.subsubod.second_disabled',
|
||||
'subod.subsubod.third': 'subod.subsubod.third_hidden'}),
|
||||
#test a config with mix of different optiondescription
|
||||
{'first': 'first',
|
||||
'subod.second': 'subod.second_disabled',
|
||||
'subod.subsubod.third': 'subod.subsubod.third_hidden'},
|
||||
OrderedDict({'first': 'first',
|
||||
'subod.second': 'subod.second_disabled',
|
||||
'subod.subsubod.third': 'subod.subsubod.third_hidden'}),
|
||||
#test a config with masterslaves
|
||||
{'first.first': 'first_master.first',
|
||||
'first.second': 'first_master.second_disabled',
|
||||
'first.third': 'first_master.third_hidden'},
|
||||
OrderedDict({'first.first': 'first_master.first',
|
||||
'first.second': 'first_master.second_disabled',
|
||||
'first.third': 'first_master.third_hidden'}),
|
||||
##test a config with dynoption
|
||||
{'subodval1.firstval1': 'subod_dyn.first',
|
||||
'subodval1.secondval1': 'subod_dyn.second_disabled',
|
||||
'subodval1.thirdval1': 'subod_dyn.third_hidden',
|
||||
'subodval2.firstval2': None,
|
||||
'subodval2.secondval2': None,
|
||||
'subodval2.thirdval2': None},
|
||||
OrderedDict({'subodval1.firstval1': 'subod_dyn.first',
|
||||
'subodval1.secondval1': 'subod_dyn.second_disabled',
|
||||
'subodval1.thirdval1': 'subod_dyn.third_hidden',
|
||||
'subodval2.firstval2': None,
|
||||
'subodval2.secondval2': None,
|
||||
'subodval2.thirdval2': None}),
|
||||
#test a config with dynoption subdir
|
||||
{'subod.subodval1.firstval1': 'subod.subod_dyn.first',
|
||||
'subod.subodval1.secondval1': 'subod.subod_dyn.second_disabled',
|
||||
'subod.subodval1.thirdval1': 'subod.subod_dyn.third_hidden',
|
||||
'subod.subodval2.firstval2': None,
|
||||
'subod.subodval2.secondval2': None,
|
||||
'subod.subodval2.thirdval2': None}
|
||||
OrderedDict({'subod.subodval1.firstval1': 'subod.subod_dyn.first',
|
||||
'subod.subodval1.secondval1': 'subod.subod_dyn.second_disabled',
|
||||
'subod.subodval1.thirdval1': 'subod.subod_dyn.third_hidden',
|
||||
'subod.subodval2.firstval2': None,
|
||||
'subod.subodval2.secondval2': None,
|
||||
'subod.subodval2.thirdval2': None})
|
||||
]
|
||||
|
||||
|
||||
@ -794,16 +819,15 @@ def test_tree_od_permissive():
|
||||
"""permissive when optiondescription is hidden
|
||||
"""
|
||||
tpaths = [
|
||||
{'subod.subsubod.first': 'subod.subsubod_hidden.first',
|
||||
'subod.subsubod.second': 'subod.subsubod_hidden.second',
|
||||
'subod.subsubod.third': 'subod.subsubod_hidden.third_hidden'},
|
||||
{'subod.subodval1.firstval1': 'subod.subod_dyn_hidden.first',
|
||||
'subod.subodval1.secondval1': 'subod.subod_dyn_hidden.second',
|
||||
'subod.subodval1.thirdval1': 'subod.subod_dyn_hidden.third_hidden',
|
||||
'subod.subodval2.firstval2': None,
|
||||
'subod.subodval2.secondval2': None,
|
||||
'subod.subodval2.thirdval2': None
|
||||
}
|
||||
OrderedDict({'subod.subsubod.first': 'subod.subsubod_hidden.first',
|
||||
'subod.subsubod.second': 'subod.subsubod_hidden.second',
|
||||
'subod.subsubod.third': 'subod.subsubod_hidden.third_hidden'}),
|
||||
OrderedDict({'subod.subodval1.firstval1': 'subod.subod_dyn_hidden.first',
|
||||
'subod.subodval1.secondval1': 'subod.subod_dyn_hidden.second',
|
||||
'subod.subodval1.thirdval1': 'subod.subod_dyn_hidden.third_hidden',
|
||||
'subod.subodval2.firstval2': None,
|
||||
'subod.subodval2.secondval2': None,
|
||||
'subod.subodval2.thirdval2': None})
|
||||
]
|
||||
for paths in tpaths:
|
||||
lpaths = list(paths.keys())
|
||||
|
Reference in New Issue
Block a user