reorganise test

This commit is contained in:
Emmanuel Garette 2017-11-18 14:51:00 +01:00
parent 93fe29b651
commit 9cba5ad29f
1 changed files with 531 additions and 501 deletions

View File

@ -2,13 +2,14 @@
""" """
import weakref import weakref
import pytest import pytest
from copy import copy
from py.test import raises from py.test import raises
from .autopath import do_autopath from .autopath import do_autopath
do_autopath() do_autopath()
from tiramisu import Config, MetaConfig, \ from tiramisu import Config, MetaConfig, \
StrOption, OptionDescription, MasterSlaves, DynOptionDescription, \ StrOption, OptionDescription, MasterSlaves, DynOptionDescription, \
getapi, submulti, undefined getapi, submulti, undefined
from tiramisu.error import PropertiesOptionError, APIError from tiramisu.error import PropertiesOptionError, APIError, ConfigError
from collections import OrderedDict from collections import OrderedDict
ICON = u'\u2937' ICON = u'\u2937'
@ -16,6 +17,7 @@ OPTIONS_TYPE = {'str': {'type': str,
'option': StrOption} 'option': StrOption}
} }
PROPERTIES = ['hidden', 'disabled'] PROPERTIES = ['hidden', 'disabled']
PROPERTIES_LIST = ['prop1', 'prop2']
OWNER = 'user' OWNER = 'user'
@ -33,7 +35,7 @@ SUBLIST_SECOND_VALUE = [['myvalue'], ['myvalue1', 'myvalue2']]
SUBLIST_EMPTY_VALUE = [] SUBLIST_EMPTY_VALUE = []
DISPLAY = True DISPLAY = True
#DISPLAY = False DISPLAY = False
def return_list(val=None, suffix=None): def return_list(val=None, suffix=None):
@ -64,52 +66,103 @@ def autocheck(func):
@autocheck @autocheck
def autocheck_owner_without_value(api, path, **kwargs): def autocheck_option_multi(api, path, **kwargs):
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
api.option(path).option.ismulti()
api.option(path).option.issubmulti()
api.option(path).option.ismaster()
api.option(path).option.isslave()
#
api.forcepermissive.option(path).option.ismulti()
api.forcepermissive.option(path).option.issubmulti()
api.forcepermissive.option(path).option.ismaster()
api.forcepermissive.option(path).option.isslave()
#
api.unrestraint.option(path).option.ismulti()
api.unrestraint.option(path).option.issubmulti()
api.unrestraint.option(path).option.ismaster()
api.unrestraint.option(path).option.isslave()
elif not kwargs.get('propertyerror', False):
raises(PropertiesOptionError, "api.option(path).option.ismulti()")
raises(PropertiesOptionError, "api.option(path).option.issubmulti()")
raises(PropertiesOptionError, "api.option(path).option.ismaster()")
raises(PropertiesOptionError, "api.option(path).option.isslave()")
#
api.forcepermissive.option(path).option.ismulti()
api.forcepermissive.option(path).option.issubmulti()
api.forcepermissive.option(path).option.ismaster()
api.forcepermissive.option(path).option.isslave()
#
api.unrestraint.option(path).option.ismulti()
api.unrestraint.option(path).option.issubmulti()
api.unrestraint.option(path).option.ismaster()
api.unrestraint.option(path).option.isslave()
else:
raises(PropertiesOptionError, "api.option(path).option.ismulti()")
raises(PropertiesOptionError, "api.option(path).option.issubmulti()")
raises(PropertiesOptionError, "api.option(path).option.ismaster()")
raises(PropertiesOptionError, "api.option(path).option.isslave()")
#
raises(PropertiesOptionError, "api.forcepermissive.option(path).option.ismulti()")
raises(PropertiesOptionError, "api.forcepermissive.option(path).option.issubmulti()")
raises(PropertiesOptionError, "api.forcepermissive.option(path).option.ismaster()")
raises(PropertiesOptionError, "api.forcepermissive.option(path).option.isslave()")
#
api.unrestraint.option(path).option.ismulti()
api.unrestraint.option(path).option.issubmulti()
api.unrestraint.option(path).option.ismaster()
api.unrestraint.option(path).option.isslave()
@autocheck
def autocheck_default_owner(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: isslave = api.unrestraint.option(path).option.isslave()
isslave = api.forcepermissive.option(path).option.isslave() # check if owner is a string "default" and 'isdefault'
except: if not isslave:
isslave = False if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
# check if owner is a string "default"
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if not isslave:
assert api.option(path).owner.get() == 'default' assert api.option(path).owner.get() == 'default'
else:
assert api.option(path, 0).owner.get() == 'default'
else:
if not isslave:
raises(PropertiesOptionError, "api.option(path).owner.get()")
else:
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.option(path).owner.get() == 'default' assert api.forcepermissive.option(path).owner.get() == 'default'
else: #
assert api.forcepermissive.option(path, 0).owner.get() == 'default'
else:
if not isslave:
raises(PropertiesOptionError, "api.forcepermissive.option(path).owner.get()")
else:
raises(PropertiesOptionError, "api.forcepermissive.option(path, 0).owner.get()")
# check if default owner
raises(APIError, "api.unrestraint.option(path).owner.isdefault()")
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if not isslave:
assert api.option(path).owner.isdefault() assert api.option(path).owner.isdefault()
else: assert api.forcepermissive.option(path).owner.isdefault()
assert api.option(path, 0).owner.isdefault() elif not kwargs.get('propertyerror', False):
else: raises(PropertiesOptionError, "api.option(path).owner.get()")
raises(PropertiesOptionError, "api.option(path).owner.isdefault()") assert api.forcepermissive.option(path).owner.get() == 'default'
if not kwargs.get('propertyerror', False): #
if not isslave: raises(PropertiesOptionError, "api.option(path).owner.isdefault()")
assert api.forcepermissive.option(path).owner.isdefault() assert api.forcepermissive.option(path).owner.isdefault()
else: else:
assert api.forcepermissive.option(path, 0).owner.isdefault() raises(PropertiesOptionError, "api.option(path).owner.get()")
raises(PropertiesOptionError, "api.forcepermissive.option(path).owner.get()")
#
raises(PropertiesOptionError, "api.option(path).owner.isdefault()")
raises(PropertiesOptionError, "api.forcepermissive.option(path).owner.isdefault()")
else: else:
raises(PropertiesOptionError, "api.forcepermissive.option(path).owner.isdefault()") if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
assert api.option(path, 0).owner.get() == 'default'
assert api.forcepermissive.option(path, 0).owner.get() == 'default'
#
assert api.option(path, 0).owner.isdefault()
assert api.forcepermissive.option(path, 0).owner.isdefault()
elif not kwargs.get('propertyerror', False):
raises(PropertiesOptionError, "api.option(path, 0).owner.get()")
assert api.forcepermissive.option(path, 0).owner.get() == 'default'
#
assert api.option(path, 0).owner.isdefault()
raises(PropertiesOptionError, "api.forcepermissive.option(path, 0).owner.isdefault()")
else:
raises(PropertiesOptionError, "api.option(path, 0).owner.get()")
raises(PropertiesOptionError, "api.forcepermissive.option(path, 0).owner.get()")
#
raises(PropertiesOptionError, "api.option(path, 0).owner.isdefault()")
raises(PropertiesOptionError, "api.forcepermissive.option(path, 0).owner.isdefault()")
# unrestraint is not allowed
raises(APIError, "api.unrestraint.option(path).owner.get()")
raises(APIError, "api.unrestraint.option(path).owner.isdefault()")
def _getdefault(api, path, multi, isslave, submulti_): def _getdefault(api, path, multi, isslave, submulti_):
empty_value = api.unrestraint.option(path).option.getdefault() empty_value = api.unrestraint.option(path).option.getdefault()
@ -117,181 +170,239 @@ def _getdefault(api, path, multi, isslave, submulti_):
empty_value = api.unrestraint.option(path).option.getdefaultmulti() empty_value = api.unrestraint.option(path).option.getdefaultmulti()
return empty_value return empty_value
@autocheck
def autocheck_value(api, path, **kwargs): def _autocheck_default_value(api, path, **kwargs):
"""set and get values """set and get values
""" """
# 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): multi = api.unrestraint.option(path).option.ismulti()
multi = api.forcepermissive.option(path).option.ismulti() submulti_ = api.unrestraint.option(path).option.issubmulti()
submulti_ = api.forcepermissive.option(path).option.issubmulti() isslave = api.unrestraint.option(path).option.isslave()
ismaster = api.forcepermissive.option(path).option.ismaster()
isslave = api.forcepermissive.option(path).option.isslave()
else:
raises(PropertiesOptionError, "api.forcepermissive.option(path).option.ismulti()")
multi = api.unrestraint.option(path).option.ismulti()
submulti_ = api.unrestraint.option(path).option.issubmulti()
ismaster = api.unrestraint.option(path).option.ismaster()
isslave = api.unrestraint.option(path).option.isslave()
# set default value (different if value is multi or not) # set default value (different if value is multi or not)
if not multi:
first_value = FIRST_VALUE
second_value = SECOND_VALUE
elif submulti_ is False:
first_value = LIST_FIRST_VALUE
second_value = LIST_SECOND_VALUE
else:
first_value = SUBLIST_FIRST_VALUE
second_value = SUBLIST_SECOND_VALUE
empty_value = _getdefault(api, path, multi, isslave, submulti_) empty_value = _getdefault(api, path, multi, isslave, submulti_)
# test default value (should be empty) without permissive # test default value (should be empty)
# cannot test for slave (we cannot get all values for a slave) # cannot test for slave (we cannot get all values for a slave)
if not isslave: if not isslave:
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 api.option(path).value.get() == empty_value assert api.option(path).value.get() == empty_value
else: assert api.forcepermissive.option(path).value.get() == empty_value
elif not kwargs.get('propertyerror', False):
raises(PropertiesOptionError, "api.option(path).value.get()") 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.option(path).value.get()")
if not isslave:
if not kwargs.get('propertyerror', False):
assert api.forcepermissive.option(path).value.get() == empty_value assert api.forcepermissive.option(path).value.get() == empty_value
else: else:
raises(PropertiesOptionError, "api.option(path).value.get()")
raises(PropertiesOptionError, "api.forcepermissive.option(path).value.get()") raises(PropertiesOptionError, "api.forcepermissive.option(path).value.get()")
else:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
assert api.option(path, 0).value.get() == empty_value
assert api.option(path, 1).value.get() == empty_value
assert api.forcepermissive.option(path, 0).value.get() == empty_value
assert api.forcepermissive.option(path, 1).value.get() == empty_value
elif not kwargs.get('propertyerror', False):
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() == empty_value
else:
raises(PropertiesOptionError, "api.option(path, 0).value.get()")
raises(PropertiesOptionError, "api.forcepermissive.option(path, 0).value.get()")
@autocheck
def autocheck_default_value(api, path, **kwargs):
_autocheck_default_value(api, path, **kwargs)
def _autocheck_set_value(api, path, **kwargs):
set_permissive = kwargs.get('set_permissive', True)
multi = api.unrestraint.option(path).option.ismulti()
submulti_ = api.unrestraint.option(path).option.issubmulti()
ismaster = api.unrestraint.option(path).option.ismaster()
isslave = api.unrestraint.option(path).option.isslave()
# empty_value = _getdefault(api, path, multi, isslave, submulti_)
if not multi:
first_value = FIRST_VALUE
# second_value = SECOND_VALUE
elif submulti_ is False:
first_value = LIST_FIRST_VALUE
# second_value = LIST_SECOND_VALUE
else:
first_value = SUBLIST_FIRST_VALUE
# second_value = SUBLIST_SECOND_VALUE
# set a value without permissive
# for slave should have an index and good length # for slave should have an index and good length
# for master must append, not set # for master must append, not set
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if ismaster:
if ismaster: if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
raises(APIError, "api.option(path, 0).value.set(first_value[0])") raises(APIError, "api.option(path, 0).value.set(first_value[0])")
api.option(path).value.set([first_value[0]]) if not set_permissive:
elif isslave: api.option(path).value.set([first_value[0]])
api.option(path, 0).value.set(first_value[0]) else:
else: api.forcepermissive.option(path).value.set([first_value[0]])
api.option(path).value.set(first_value) elif not kwargs.get('propertyerror', False):
else:
if ismaster:
raises(PropertiesOptionError, "api.option(path).value.set([first_value[0]])") raises(PropertiesOptionError, "api.option(path).value.set([first_value[0]])")
elif isslave: if set_permissive:
api.forcepermissive.option(path).value.set([first_value[0]])
else:
raises(PropertiesOptionError, "api.option(path).value.set([first_value[0]])")
raises(PropertiesOptionError,
"api.forcepermissive.option(path).value.set([first_value[0]])")
raises(APIError, "api.unrestraint.option(path).value.set(first_value[1])")
elif isslave:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if not set_permissive:
api.option(path, 0).value.set(first_value[0])
else:
api.forcepermissive.option(path, 0).value.set(first_value[0])
elif not kwargs.get('propertyerror', False):
raises(PropertiesOptionError, "api.option(path, 0).value.set(first_value[0])") raises(PropertiesOptionError, "api.option(path, 0).value.set(first_value[0])")
if set_permissive:
api.forcepermissive.option(path, 0).value.set(first_value[0])
else:
raises(PropertiesOptionError, "api.option(path, 0).value.set(first_value[0])")
raises(PropertiesOptionError,
"api.forcepermissive.option(path, 0).value.set(first_value[0])")
raises(APIError,
"api.unrestraint.option(path).value.set([first_value[0], first_value[1]])")
else:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if not set_permissive:
api.option(path).value.set(first_value)
else:
api.forcepermissive.option(path).value.set(first_value)
elif not kwargs.get('propertyerror', False):
raises(PropertiesOptionError, "api.option(path).value.set(first_value)")
if set_permissive:
api.forcepermissive.option(path).value.set(first_value)
else: else:
raises(PropertiesOptionError, "api.option(path).value.set(first_value)") raises(PropertiesOptionError, "api.option(path).value.set(first_value)")
raises(PropertiesOptionError, "api.forcepermissive.option(path).value.set(first_value)")
raises(APIError, "api.unrestraint.option(path).value.set(first_value)")
@autocheck
def autocheck_set_value(api, path, **kwargs):
_autocheck_set_value(api, path, **kwargs)
@autocheck
def autocheck_get_value_permissive(api, path, **kwargs):
multi = api.unrestraint.option(path).option.ismulti()
submulti_ = api.unrestraint.option(path).option.issubmulti()
isslave = api.unrestraint.option(path).option.isslave()
_autocheck_set_value(api, path, **kwargs)
if not multi:
first_value = FIRST_VALUE
elif submulti_ is False:
first_value = LIST_FIRST_VALUE
else:
first_value = SUBLIST_FIRST_VALUE
# get value after set value without permissive # get value after set value without permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if isslave:
if isslave: if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
assert api.option(path, 0).value.get() == first_value[0] assert api.option(path, 0).value.get() == first_value[0]
assert api.forcepermissive.option(path, 0).value.get() == first_value[0]
elif kwargs.get('permissive', False):
raises(PropertiesOptionError, "api.option(path, 0).value.get()")
assert api.forcepermissive.option(path, 0).value.get() == first_value
else: else:
raises(PropertiesOptionError, "api.option(path, 0).value.get()")
raises(PropertiesOptionError, "api.forcepermissive.option(path, 0).value.get()")
else:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
assert api.option(path).value.get() == first_value assert api.option(path).value.get() == first_value
elif kwargs.get('permissive', False): assert api.forcepermissive.option(path).value.get() == first_value
if isslave: elif kwargs.get('permissive', False):
raises(PropertiesOptionError, "api.option(path).value.get()")
assert api.forcepermissive.option(path).value.get() == first_value
else:
raises(PropertiesOptionError, "api.option(path).value.get()")
raises(PropertiesOptionError, "api.forcepermissive.option(path).value.get()")
def _autocheck_get_value(api, path, **kwargs):
multi = api.unrestraint.option(path).option.ismulti()
submulti_ = api.unrestraint.option(path).option.issubmulti()
isslave = api.unrestraint.option(path).option.isslave()
empty_value = _getdefault(api, path, multi, isslave, submulti_)
if not multi:
first_value = FIRST_VALUE
elif submulti_ is False:
first_value = LIST_FIRST_VALUE
else:
first_value = SUBLIST_FIRST_VALUE
# get value after set value without permissive
if isslave:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
assert api.option(path, 0).value.get() == first_value[0]
assert api.forcepermissive.option(path, 0).value.get() == first_value[0]
elif kwargs.get('permissive', False):
raises(PropertiesOptionError, "api.option(path, 0).value.get()") raises(PropertiesOptionError, "api.option(path, 0).value.get()")
assert api.forcepermissive.option(path, 0).value.get() == empty_value assert api.forcepermissive.option(path, 0).value.get() == empty_value
else: else:
raises(PropertiesOptionError, "api.option(path, 0).value.get()")
raises(PropertiesOptionError, "api.forcepermissive.option(path, 0).value.get()")
else:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
assert api.option(path).value.get() == first_value
assert api.forcepermissive.option(path).value.get() == first_value
elif kwargs.get('permissive', False):
raises(PropertiesOptionError, "api.option(path).value.get()") raises(PropertiesOptionError, "api.option(path).value.get()")
assert api.forcepermissive.option(path).value.get() == empty_value assert api.forcepermissive.option(path).value.get() == empty_value
else:
if isslave:
raises(PropertiesOptionError, "api.option(path, 0).value.get()")
raises(PropertiesOptionError, "api.forcepermissive.option(path, 0).value.get()")
else:
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.option(path).value.set(second_value[1])")
elif isslave:
raises(APIError, "api.unrestraint.option(path).value.set([first_value[0], second_value[1]])")
else:
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(APIError, "api.forcepermissive.option(path, 1).value.set(second_value[1])")
api.forcepermissive.option(path).value.set([first_value[0], second_value[1]])
elif isslave:
#FIXME
raises(PropertiesOptionError, "api.forcepermissive.option(path).value.set([first_value[0], second_value[1]])")
api.option(path, 1).value.set(second_value[1])
raise Exception('ca entre ici')
else:
api.option(path).value.set(second_value)
elif kwargs.get('permissive', False):
if ismaster:
api.forcepermissive.option(path).value.set([first_value[0], second_value[1]])
elif isslave:
api.forcepermissive.option(path, 1).value.set(second_value[1])
else:
api.forcepermissive.option(path).value.set(first_value)
else:
if ismaster:
raises(PropertiesOptionError, "api.forcepermissive.option(path).value.set([first_value[0]])")
elif isslave:
raises(PropertiesOptionError, "api.forcepermissive.option(path, 0).value.set(first_value[0])")
else:
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.option(path, 0).value.get() == second_value[0]
assert api.option(path, 1).value.get() == second_value[1]
else:
assert api.option(path).value.get() == second_value
elif kwargs.get('permissive', False):
if ismaster:
raises(PropertiesOptionError, "api.option(path).value.get()")
assert api.forcepermissive.option(path).value.get() == second_value
elif isslave:
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.option(path).value.get()")
assert api.forcepermissive.option(path).value.get() == first_value
else:
if isslave:
raises(PropertiesOptionError, "api.option(path, 0).value.get()")
raises(PropertiesOptionError, "api.forcepermissive.option(path, 0).value.get()")
else: else:
raises(PropertiesOptionError, "api.option(path).value.get()") raises(PropertiesOptionError, "api.option(path).value.get()")
raises(PropertiesOptionError, "api.forcepermissive.option(path).value.get()") raises(PropertiesOptionError, "api.forcepermissive.option(path).value.get()")
@autocheck
def autocheck_get_value(api, path, **kwargs):
_autocheck_set_value(api, path, set_permissive=False, **kwargs)
_autocheck_get_value(api, path, **kwargs)
@autocheck @autocheck
def autocheck_value_slave(api, path, **kwargs): def autocheck_value_slave(api, path, **kwargs):
multi = api.unrestraint.option(path).option.ismulti()
isslave = api.unrestraint.option(path).option.isslave() isslave = api.unrestraint.option(path).option.isslave()
if not isslave: if not isslave:
#FIXME verifier pas de len ! #FIXME raises(APIError, "api.option(path).value.len()")
return return
if kwargs.get('propertyerror', False): if kwargs.get('propertyerror', False):
raises(PropertiesOptionError, "api.option(path).value.len()")
raises(PropertiesOptionError, "api.forcepermissive.option(path).value.len()")
return return
multi = api.unrestraint.option(path).option.ismulti()
submulti_ = api.forcepermissive.option(path).option.issubmulti() submulti_ = api.forcepermissive.option(path).option.issubmulti()
if not kwargs.get('permissive', False):
length = api.option(path).value.len()
else:
length = api.forcepermissive.option(path).value.len()
assert length == 2
value = []
for idx in range(length):
value.append(api.forcepermissive.option(path, idx).value.get())
if not submulti_: if not submulti_:
second_value = LIST_SECOND_VALUE second_value = LIST_SECOND_VALUE
else: else:
second_value = SUBLIST_SECOND_VALUE second_value = SUBLIST_SECOND_VALUE
empty_value = _getdefault(api, path, multi, isslave, submulti_) empty_value = _getdefault(api, path, multi, isslave, submulti_)
if not kwargs.get('permissive', False):
length = api.option(path).value.len()
assert api.forcepermissive.option(path).value.len() == length
else:
raises(PropertiesOptionError, "api.option(path).value.len()")
length = api.forcepermissive.option(path).value.len()
assert length == 2
value = []
for idx in range(length):
value.append(api.forcepermissive.option(path, idx).value.get())
assert value == [empty_value, second_value[1]] assert value == [empty_value, second_value[1]]
# cannot access to a slave with index too high # cannot access to a slave with index too high
if submulti_ is False: if submulti_ is False:
value = LIST_FIRST_VALUE[0] value = LIST_FIRST_VALUE[0]
else: else:
value = SUBLIST_FIRST_VALUE[0] value = SUBLIST_FIRST_VALUE[0]
raises(IndexError, "api.forcepermissive.option(path, length).value.get()") raises(IndexError, "api.forcepermissive.option(path, length).value.get()")
raises(IndexError, "api.forcepermissive.option(path, length).value.set(value)") raises(IndexError, "api.forcepermissive.option(path, length).value.set(value)")
raises(IndexError, "api.forcepermissive.option(path, length).value.reset()") raises(IndexError, "api.forcepermissive.option(path, length).value.reset()")
@ -320,35 +431,43 @@ def autocheck_reset_value(api, path, **kwargs):
first_value = SUBLIST_FIRST_VALUE first_value = SUBLIST_FIRST_VALUE
second_value = SUBLIST_SECOND_VALUE second_value = SUBLIST_SECOND_VALUE
empty_value = _getdefault(api, path, multi, isslave, submulti_) empty_value = _getdefault(api, path, multi, isslave, submulti_)
_autocheck_set_value(api, path, **kwargs)
# reset value without permissive # reset value without permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if not isslave:
if not isslave: if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
api.option(path).value.reset() api.option(path).value.reset()
else: else:
api.option(path, 0).value.reset()
else:
if not isslave:
raises(PropertiesOptionError, "api.option(path).value.reset()") raises(PropertiesOptionError, "api.option(path).value.reset()")
else:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
api.option(path, 0).value.reset()
else: else:
raises(PropertiesOptionError, "api.option(path, 0).value.reset()") raises(PropertiesOptionError, "api.option(path, 0).value.reset()")
# get value after reset value without permissive # get value after reset value without permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if isslave:
if isslave: if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
assert api.option(path, 0).value.get() == empty_value assert api.option(path, 0).value.get() == empty_value
assert api.option(path, 1).value.get() == second_value[1] assert api.option(path, 1).value.get() == second_value[1]
else: elif kwargs.get('permissive', False):
assert api.option(path).value.get() == empty_value
elif kwargs.get('permissive', False):
if isslave:
raises(PropertiesOptionError, "api.option(path, 0).value.get()") raises(PropertiesOptionError, "api.option(path, 0).value.get()")
assert api.forcepermissive.option(path, 0).value.get() == empty_value assert api.forcepermissive.option(path, 0).value.get() == empty_value
assert api.forcepermissive.option(path, 1).value.get() == second_value[1] assert api.forcepermissive.option(path, 1).value.get() == second_value[1]
else: else:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
assert api.option(path).value.get() == empty_value
elif kwargs.get('permissive', False):
raises(PropertiesOptionError, "api.option(path).value.get()") raises(PropertiesOptionError, "api.option(path).value.get()")
assert api.forcepermissive.option(path).value.get() == first_value assert api.forcepermissive.option(path).value.get() == first_value
@autocheck
def autocheck_reset_value_permissive(api, path, **kwargs):
# check if is a multi, a master or a slave
isslave = api.unrestraint.option(path).option.isslave()
_autocheck_set_value(api, path, **kwargs)
# 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:
@ -365,42 +484,56 @@ def autocheck_reset_value(api, path, **kwargs):
raises(PropertiesOptionError, "api.forcepermissive.option(path).value.reset()") raises(PropertiesOptionError, "api.forcepermissive.option(path).value.reset()")
else: else:
raises(PropertiesOptionError, "api.forcepermissive.option(path, 1).value.reset()") raises(PropertiesOptionError, "api.forcepermissive.option(path, 1).value.reset()")
_autocheck_default_value(api, path, **kwargs)
# get value after reset value with permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if isslave:
assert api.option(path, 0).value.get() == empty_value
assert api.option(path, 1).value.get() == empty_value
else:
assert api.option(path).value.get() == empty_value
elif kwargs.get('permissive', False):
if isslave:
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.option(path).value.get()")
assert api.forcepermissive.option(path).value.get() == empty_value
@autocheck
def autocheck_value2(*args, **kwargs):
"""re set value
"""
autocheck_value(*args, **kwargs)
@autocheck @autocheck
def autocheck_display(api, path, **kwargs): def autocheck_display(api, path, **kwargs):
"""re set value """re set value
""" """
#FIXME utile ? #FIXME make_dict?
assert api.config
_autocheck_set_value(api, path, **kwargs)
assert api.config assert api.config
@autocheck def _getproperties(multi, isslave, kwargs):
def autocheck_property(api, path, **kwargs): # define properties
properties = copy(PROPERTIES_LIST)
if multi and not isslave:
default_props = ['empty']
properties.append('empty')
else:
default_props = []
extra_properties = kwargs.get('extra_properties')
if extra_properties:
properties.extend(extra_properties)
default_props.extend(extra_properties)
return default_props, tuple(properties)
def _check_default_properties(api, path, kwargs, props_permissive, props):
if not api.unrestraint.option(path).option.isslave():
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
assert set(api.option(path).property.get()) == set(props_permissive)
assert set(api.forcepermissive.option(path).property.get()) == set(props_permissive)
elif not kwargs.get('propertyerror', False):
raises(PropertiesOptionError, "api.option(path).property.get()")
assert set(api.forcepermissive.option(path).property.get()) == set(props)
else:
raises(PropertiesOptionError, "api.option(path).property.get()")
raises(PropertiesOptionError, "api.forcepermissive.option(path).property.get()")
raises(APIError, "api.unrestraint.option(path).property.get()")
else:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
assert set(api.option(path, 0).property.get()) == set(props)
assert set(api.option(path, 1).property.get()) == set(props)
else:
raises(PropertiesOptionError, "api.option(path, 0).property.get()")
raises(APIError, "api.unrestraint.option(path, 0).property.get()")
def _autocheck_property(api, path, **kwargs):
"""get property from path """get property from path
""" """
# check if is a multi or a slave # check if is a multi or a slave
@ -408,7 +541,7 @@ def autocheck_property(api, path, **kwargs):
isslave = api.unrestraint.option(path).option.isslave() isslave = api.unrestraint.option(path).option.isslave()
# define properties # define properties
properties = ['prop1', 'prop2'] properties = copy(PROPERTIES_LIST)
if multi and not isslave: if multi and not isslave:
default_props = ['empty'] default_props = ['empty']
properties.append('empty') properties.append('empty')
@ -418,139 +551,73 @@ def autocheck_property(api, path, **kwargs):
if extra_properties: if extra_properties:
properties.extend(extra_properties) properties.extend(extra_properties)
default_props.extend(extra_properties) default_props.extend(extra_properties)
properties = tuple(properties) default_props, properties = _getproperties(multi, isslave, kwargs)
# get properties without permissive _check_default_properties(api, path, kwargs, default_props, default_props)
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if not isslave:
assert set(api.option(path).property.get()) == set(default_props)
else:
assert set(api.option(path, 0).property.get()) == set(default_props)
assert set(api.option(path, 1).property.get()) == set(default_props)
else:
if not isslave:
raises(PropertiesOptionError, "api.option(path).property.get()")
else:
raises(PropertiesOptionError, "api.option(path, 0).property.get()")
# get properties with permissive
if not isslave:
raises(APIError, "api.unrestraint.option(path).property.get()")
else:
raises(APIError, "api.unrestraint.option(path, 0).property.get()")
if not kwargs.get('propertyerror', False):
if not isslave:
assert set(api.forcepermissive.option(path).property.get()) == set(default_props)
else:
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.option(path).property.get()")
else:
raises(PropertiesOptionError, "api.forcepermissive.option(path, 0).property.get()")
# 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):
api.option(path).property.set(properties) api.option(path).property.set(properties)
else: else:
if not isslave: raises(PropertiesOptionError, "api.option(path).property.set(properties)")
raises(PropertiesOptionError, "api.option(path).property.set(properties)")
else:
raises(PropertiesOptionError, "api.option(path, 0).property.set(properties)")
# check properties after set without permissive _check_default_properties(api, path, kwargs, properties, default_props)
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
assert set(api.option(path).property.get()) == set(properties)
assert set(api.forcepermissive.option(path).property.get()) == set(properties) @autocheck
elif kwargs.get('permissive', False): def autocheck_property(api, path, **kwargs):
if not isslave: _autocheck_property(api, path, **kwargs)
raises(PropertiesOptionError, "api.option(path).property.get()")
assert set(api.forcepermissive.option(path).property.get()) == set(default_props)
else: def _property_permissive(api, path, **kwargs):
raises(PropertiesOptionError, "api.option(path, 0).property.get()") # check if is a multi or a slave
assert set(api.forcepermissive.option(path, 0).property.get()) == set(default_props) multi = api.unrestraint.option(path).option.ismulti()
assert set(api.forcepermissive.option(path, 1).property.get()) == set(default_props) isslave = api.unrestraint.option(path).option.isslave()
# define properties
properties = copy(PROPERTIES_LIST)
if multi and not isslave:
default_props = ['empty']
properties.append('empty')
else: else:
if not isslave: default_props = []
raises(PropertiesOptionError, "api.option(path).property.get()") extra_properties = kwargs.get('extra_properties')
raises(PropertiesOptionError, "api.forcepermissive.option(path).property.get()") if extra_properties:
else: properties.extend(extra_properties)
raises(PropertiesOptionError, "api.option(path, 0).property.get()") default_props.extend(extra_properties)
raises(PropertiesOptionError, "api.forcepermissive.option(path, 0).property.get()") default_props, properties = _getproperties(multi, isslave, kwargs)
_check_default_properties(api, path, kwargs, default_props, default_props)
# set properties with permissive # set properties with permissive
if not kwargs.get('propertyerror', False): if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
api.option(path).property.set(properties)
api.forcepermissive.option(path).property.set(properties)
elif not kwargs.get('propertyerror', False):
raises(PropertiesOptionError, "api.option(path).property.set(properties)")
api.forcepermissive.option(path).property.set(properties) api.forcepermissive.option(path).property.set(properties)
else: else:
raises(PropertiesOptionError, "api.option(path).property.set(properties)")
raises(PropertiesOptionError, "api.forcepermissive.option(path).property.set(properties)") raises(PropertiesOptionError, "api.forcepermissive.option(path).property.set(properties)")
# check properties after set with permissive _check_default_properties(api, path, kwargs, properties, properties)
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if not isslave:
assert set(api.option(path).property.get()) == set(properties) @autocheck
assert set(api.forcepermissive.option(path).property.get()) == set(properties) def autocheck_property_permissive(api, path, **kwargs):
else: _property_permissive(api, path, **kwargs)
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.option(path).property.get()")
assert set(api.forcepermissive.option(path).property.get()) == set(properties)
else:
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.option(path).property.get()")
raises(PropertiesOptionError, "api.forcepermissive.option(path).property.get()")
else:
raises(PropertiesOptionError, "api.option(path, 0).property.get()")
raises(PropertiesOptionError, "api.forcepermissive.option(path, 0).property.get()")
@autocheck @autocheck
def autocheck_reset_property(api, path, **kwargs): def autocheck_reset_property(api, path, **kwargs):
"""check properties after set with permissive """check properties after set with permissive
""" """
# check if is a multi or a slave # check if is a multi or a slave
if not kwargs.get('propertyerror', False): multi = api.unrestraint.option(path).option.ismulti()
multi = api.forcepermissive.option(path).option.ismulti() isslave = api.unrestraint.option(path).option.isslave()
isslave = api.forcepermissive.option(path).option.isslave() default_props, properties = _getproperties(multi, isslave, kwargs)
else:
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 _property_permissive(api, path, **kwargs)
properties = ['prop1', 'prop2']
if multi and not isslave:
default_props = ['empty']
properties.append('empty')
else:
default_props = []
extra_properties = kwargs.get('extra_properties')
if extra_properties:
properties.extend(extra_properties)
default_props.extend(extra_properties)
properties = tuple(properties)
# check properties
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
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.option(path).property.get()) == set(properties)
else:
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 # 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):
@ -558,22 +625,17 @@ def autocheck_reset_property(api, path, **kwargs):
else: else:
raises(PropertiesOptionError, "api.option(path).property.reset()") raises(PropertiesOptionError, "api.option(path).property.reset()")
# check properties _check_default_properties(api, path, kwargs, default_props, properties)
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if not isslave:
assert set(api.option(path).property.get()) == set(default_props) @autocheck
assert set(api.forcepermissive.option(path).property.get()) == set(default_props) def autocheck_reset_property_permissive(api, path, **kwargs):
else: # check if is a multi or a slave
assert set(api.option(path, 0).property.get()) == set(default_props) multi = api.unrestraint.option(path).option.ismulti()
assert set(api.forcepermissive.option(path, 0).property.get()) == set(default_props) isslave = api.unrestraint.option(path).option.isslave()
assert set(api.option(path, 1).property.get()) == set(default_props) default_props, properties = _getproperties(multi, isslave, kwargs)
assert set(api.forcepermissive.option(path, 1).property.get()) == set(default_props)
elif kwargs.get('permissive', False): _property_permissive(api, path, **kwargs)
if not isslave:
assert set(api.forcepermissive.option(path).property.get()) == set(properties)
else:
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 # reset properties with permissive
raises(APIError, "api.unrestraint.option(path).property.set(properties)") raises(APIError, "api.unrestraint.option(path).property.set(properties)")
@ -584,69 +646,56 @@ def autocheck_reset_property(api, path, **kwargs):
elif kwargs.get('permissive', False): elif kwargs.get('permissive', False):
api.forcepermissive.option(path).property.reset() api.forcepermissive.option(path).property.reset()
# check properties _check_default_properties(api, path, kwargs, default_props, default_props)
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if not isslave:
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.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.option(path).property.get()) == set(default_props)
else:
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 @autocheck
def autocheck_property2(*args, **kwargs): def autocheck_context_owner(api, path, **kwargs):
return autocheck_property(*args, display=False, **kwargs) owner = api.owner.get()
assert owner == OWNER
def _check_owner(api, path, kwargs, owner, permissive_owner):
isslave = api.unrestraint.option(path).option.isslave()
if not isslave:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
assert api.option(path).owner.get() == owner
assert api.forcepermissive.option(path).owner.get() == owner
elif not kwargs.get('propertyerror', False):
raises(PropertiesOptionError, "api.option(path).owner.get()")
assert api.forcepermissive.option(path).owner.get() == permissive_owner
else:
raises(PropertiesOptionError, "api.option(path).owner.get()")
raises(PropertiesOptionError, "api.forcepermissive.option(path).owner.get()")
else:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
assert api.option(path, 0).owner.get() == 'default'
assert api.option(path, 1).owner.get() == owner
assert api.forcepermissive.option(path, 0).owner.get() == 'default'
assert api.forcepermissive.option(path, 1).owner.get() == owner
elif not kwargs.get('propertyerror', False):
raises(PropertiesOptionError, "api.option(path, 0).owner.get()")
raises(PropertiesOptionError, "api.option(path, 1).owner.get()")
assert api.forcepermissive.option(path, 0).owner.get() == 'default'
assert api.forcepermissive.option(path, 1).owner.get() == permissive_owner
else:
raises(PropertiesOptionError, "api.option(path, 0).owner.get()")
raises(PropertiesOptionError, "api.forcepermissive.option(path, 0).owner.get()")
@autocheck @autocheck
def autocheck_owner_with_value(api, path, **kwargs): def autocheck_owner_with_value(api, path, **kwargs):
"""value is now changed, check owner in this case """value is now changed, check owner in this case
""" """
_autocheck_set_value(api, path, **kwargs)
_check_owner(api, path, kwargs, OWNER, OWNER)
@autocheck
def autocheck_default_owner_with_value(api, path, **kwargs):
_autocheck_set_value(api, path, **kwargs)
# check if is a isslave # check if is a isslave
if not kwargs.get('propertyerror', False): isslave = api.unrestraint.option(path).option.isslave()
isslave = api.forcepermissive.option(path).option.isslave()
else:
raises(PropertiesOptionError, "api.forcepermissive.option(path).option.isslave()")
isslave = api.unrestraint.option(path).option.isslave()
owner = api.owner.get()
assert owner == OWNER
# get owner without permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if not isslave:
assert api.option(path).owner.get() == owner
else:
assert api.option(path, 0).owner.get() == owner
assert api.option(path, 1).owner.get() == owner
else:
if not isslave:
raises(PropertiesOptionError, "api.option(path).owner.get()")
else:
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.option(path).owner.get() == owner
else:
assert api.forcepermissive.option(path, 0).owner.get() == 'default'
assert api.forcepermissive.option(path, 1).owner.get() == owner
else:
if not isslave:
raises(PropertiesOptionError, "api.forcepermissive.option(path).owner.get()")
else:
raises(PropertiesOptionError, "api.forcepermissive.option(path, 0).owner.get()")
# 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):
@ -654,6 +703,14 @@ def autocheck_owner_with_value(api, path, **kwargs):
else: else:
raises(PropertiesOptionError, "api.option(path).owner.isdefault()") raises(PropertiesOptionError, "api.option(path).owner.isdefault()")
@autocheck
def autocheck_default_owner_with_value_permissive(api, path, **kwargs):
# check if is a isslave
isslave = api.unrestraint.option(path).option.isslave()
_autocheck_set_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):
if not isslave: if not isslave:
@ -665,41 +722,43 @@ def autocheck_owner_with_value(api, path, **kwargs):
raises(PropertiesOptionError, "api.forcepermissive.option(path).owner.isdefault()") raises(PropertiesOptionError, "api.forcepermissive.option(path).owner.isdefault()")
@autocheck
def autocheck_set_owner_no_value(api, path, **kwargs):
isslave = api.unrestraint.option(path).option.isslave()
if not kwargs.get('propertyerror', False):
if not isslave:
raises(ConfigError, "api.forcepermissive.option(path).owner.set('new_user')")
else:
raises(ConfigError, "api.forcepermissive.option(path, 1).owner.set('new_user')")
@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): isslave = api.unrestraint.option(path).option.isslave()
isslave = api.forcepermissive.option(path).option.isslave()
else: _autocheck_set_value(api, path, **kwargs)
raises(PropertiesOptionError, "api.forcepermissive.option(path).option.isslave()")
isslave = False
# set owner without permissive # set owner without permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if not isslave:
if not isslave: if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
api.option(path).owner.set('new_user') api.option(path).owner.set('new_user')
else: else:
api.option(path, 1).owner.set('new_user')
else:
if not isslave:
raises(PropertiesOptionError, "api.option(path).owner.set('new_user')") raises(PropertiesOptionError, "api.option(path).owner.set('new_user')")
else:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
api.option(path, 1).owner.set('new_user')
else: else:
raises(PropertiesOptionError, "api.option(path, 1).owner.set('new_user')") raises(PropertiesOptionError, "api.option(path, 1).owner.set('new_user')")
# check owner set without permissive _check_owner(api, path, kwargs, 'new_user', OWNER)
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if not isslave:
assert api.option(path).owner.get() == 'new_user' @autocheck
assert api.forcepermissive.option(path).owner.get() == 'new_user' def autocheck_set_owner_permissive(api, path, **kwargs):
else: isslave = api.unrestraint.option(path).option.isslave()
assert api.option(path, 1).owner.get() == 'new_user'
assert api.forcepermissive.option(path, 1).owner.get() == 'new_user' _autocheck_set_value(api, path, **kwargs)
elif not kwargs.get('propertyerror', False):
owner = api.owner.get()
if not isslave:
assert api.forcepermissive.option(path).owner.get() == owner
else:
assert api.forcepermissive.option(path, 1).owner.get() == owner
# set owner with permissive # set owner with permissive
if not kwargs.get('propertyerror', False): if not kwargs.get('propertyerror', False):
@ -709,17 +768,13 @@ def autocheck_set_owner(api, path, **kwargs):
api.forcepermissive.option(path, 1).owner.set('new_user1') api.forcepermissive.option(path, 1).owner.set('new_user1')
else: else:
if not isslave: if not isslave:
raises(PropertiesOptionError, "api.forcepermissive.option(path).owner.set('new_user1')") raises(PropertiesOptionError,
"api.forcepermissive.option(path).owner.set('new_user1')")
else: else:
raises(PropertiesOptionError, "api.forcepermissive.option(path, 1).owner.set('new_user1')") raises(PropertiesOptionError,
"api.forcepermissive.option(path, 1).owner.set('new_user1')")
# get owner set with permissive _check_owner(api, path, kwargs, 'new_user1', 'new_user1')
if not kwargs.get('propertyerror', False):
if not isslave:
assert api.forcepermissive.option(path).owner.get() == 'new_user1'
else:
assert api.forcepermissive.option(path, 0).owner.get() == 'default'
assert api.forcepermissive.option(path, 1).owner.get() == 'new_user1'
@autocheck @autocheck
@ -756,93 +811,61 @@ def autocheck_option(api, path, **kwargs):
def autocheck_permissive(api, path, **kwargs): def autocheck_permissive(api, path, **kwargs):
"""test permissive for hidden and disabled value """test permissive for hidden and disabled value
""" """
# check if is a multi, a master or a slave # no permissive before
if not kwargs.get('propertyerror', False): assert api.unrestraint.option(path).permissive.get() == frozenset()
multi = api.forcepermissive.option(path).option.ismulti() if kwargs.get('permissive_od', False):
submulti_ = api.forcepermissive.option(path).option.issubmulti() assert api.unrestraint.option(path.rsplit('.', 1)[0]).permissive.get() == frozenset()
ismaster = api.forcepermissive.option(path).option.ismaster()
isslave = api.forcepermissive.option(path).option.isslave()
else:
raises(PropertiesOptionError, "api.forcepermissive.option(path).option.ismulti()")
multi = api.unrestraint.option(path).option.ismulti()
submulti_ = api.unrestraint.option(path).option.issubmulti()
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:
first_value = FIRST_VALUE
second_value = SECOND_VALUE
elif submulti_ is False:
first_value = LIST_FIRST_VALUE
second_value = LIST_SECOND_VALUE
else:
first_value = SUBLIST_FIRST_VALUE
second_value = SUBLIST_SECOND_VALUE
if multi and not isslave:
empty_value = LIST_EMPTY_VALUE
elif submulti_ and isslave:
empty_value = SUBLIST_EMPTY_VALUE
else:
empty_value = EMPTY_VALUE
# cannot access to hidden value without forcepermissive # cannot access to hidden value without forcepermissive
# and to disabled value (with forcepermissive too) # and to disabled value (with forcepermissive too)
if kwargs.get('propertyerror', False): _autocheck_default_value(api, path, **kwargs)
if not isslave:
raises(PropertiesOptionError, "api.option(path).value.get()") # set permissive
raises(PropertiesOptionError, "api.forcepermissive.option(path).value.get()") api.unrestraint.option(path).permissive.set(frozenset(['disabled']))
else:
raises(PropertiesOptionError, "api.option(path, 0).value.get()") # have permissive
raises(PropertiesOptionError, "api.forcepermissive.option(path, 0).value.get()")
elif kwargs.get('permissive', False):
if not isslave:
raises(PropertiesOptionError, "api.option(path).value.get()")
api.forcepermissive.option(path).value.get()
else:
raises(PropertiesOptionError, "api.option(path, 0).value.get()")
api.forcepermissive.option(path, 0).value.get()
else:
if not isslave:
api.option(path).value.get()
else:
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']) assert api.unrestraint.option(path).permissive.get() == frozenset(['disabled'])
# can access to disabled value # can access to disabled value
if kwargs.get('permissive', False): ckwargs = copy(kwargs)
if not isslave: ckwargs['propertyerror'] = False
raises(PropertiesOptionError, "api.option(path).value.get()") _autocheck_default_value(api, path, **ckwargs)
api.forcepermissive.option(path).value.get()
else:
raises(PropertiesOptionError, "api.option(path, 0).value.get()")
api.forcepermissive.option(path, 0).value.get()
else:
if not isslave:
api.option(path).value.get()
else:
api.option(path, 0).value.get()
#FIXME api.unrestraint.option(path).permissive.set(frozenset(['disabled', 'hidden']))
#api.option(path).permissive.set(('disabled', 'hidden'))
## can access to value # can access to all value except when optiondescript have hidden
#if not isslave: if not ckwargs.get('permissive_od', False):
# api.option(path).value.get() ckwargs['permissive'] = False
#else: _autocheck_default_value(api, path, **ckwargs)
# api.option(path, 0).value.get()
#assert api.option(path).permissive.get() == frozenset(['disabled', 'hidden']) if ckwargs.get('permissive_od', False):
# # set permissive to OptionDescription
#print('FIXME del !!!') api.unrestraint.option(path.rsplit('.', 1)[0]).permissive.set(frozenset(['disabled',
'hidden']))
ckwargs['permissive'] = False
_autocheck_default_value(api, path, **ckwargs)
# only hidden
api.unrestraint.option(path).permissive.set(frozenset(['hidden']))
if ckwargs.get('permissive_od', False):
_autocheck_default_value(api, path, **ckwargs)
api.unrestraint.option(path.rsplit('.', 1)[0]).permissive.set(frozenset(['hidden']))
ckwargs = copy(kwargs)
ckwargs['permissive'] = False
_autocheck_default_value(api, path, **ckwargs)
# no permissive
api.unrestraint.option(path).permissive.set(frozenset())
if ckwargs.get('permissive_od', False):
_autocheck_default_value(api, path, **ckwargs)
api.unrestraint.option(path.rsplit('.', 1)[0]).permissive.set(frozenset())
_autocheck_default_value(api, path, **kwargs)
def check_all(api, path, meta, multi, default, default_multi, **kwargs): def check_all(cfg, path, meta, multi, default, default_multi, **kwargs):
if DISPLAY: if DISPLAY:
text = u' {} launch tests for {}'.format(ICON, path, multi, default) text = u' {} launch tests for {}'.format(ICON, path)
if multi is True: if multi is True:
text += u' as a multi' text += u' as a multi'
elif multi is submulti: elif multi is submulti:
@ -855,7 +878,12 @@ def check_all(api, path, meta, multi, default, default_multi, **kwargs):
text += u' with default multi' text += u' with default multi'
text += u', kwargs: {}'.format(kwargs) text += u', kwargs: {}'.format(kwargs)
print(text) print(text)
api = getapi(cfg)
if api.unrestraint.option(path).option.isslave():
master_path = path.rsplit('.', 1)[0] + '.master'
api.option(master_path).value.set(LIST_SECOND_VALUE)
for func in autocheck_registers: for func in autocheck_registers:
api = getapi(cfg.duplicate())
if DISPLAY: if DISPLAY:
print(u' {} {}'.format(ICON, func.__name__)) print(u' {} {}'.format(ICON, func.__name__))
try: try:
@ -879,7 +907,7 @@ def check_deref(weakrefs):
assert wrf() is None assert wrf() is None
def make_api(options, meta, multi, default, default_multi): def make_conf(options, meta, multi, default, default_multi):
weakrefs = [] weakrefs = []
def make_option(path, option_infos): def make_option(path, option_infos):
#FIXME #FIXME
@ -970,9 +998,7 @@ def make_api(options, meta, multi, default, default_multi):
if meta: if meta:
cfg = MetaConfig([cfg], session_id='metatest') cfg = MetaConfig([cfg], session_id='metatest')
weakrefs.append(weakref.ref(cfg)) weakrefs.append(weakref.ref(cfg))
api = getapi(cfg) return cfg, weakrefs
weakrefs.append(weakref.ref(api))
return api, weakrefs
DICT_PATHS = [ DICT_PATHS = [
@ -994,7 +1020,7 @@ DICT_PATHS = [
('subod.second', {'second': {'disabled': True}}), ('subod.second', {'second': {'disabled': True}}),
('subod.subsubod.third', {'third': {'hidden': True}})]), ('subod.subsubod.third', {'third': {'hidden': True}})]),
#test a config with masterslaves #test a config with masterslaves
OrderedDict([('odmaster.first', {'odmaster': {'master': True}}), OrderedDict([('odmaster.first', {'master': {'master': True}}),
('odmaster.second', {'second': {'disabled': True, 'slave': True}}), ('odmaster.second', {'second': {'disabled': True, 'slave': True}}),
('odmaster.third', {'third': {'hidden': True, 'slave': True}})]), ('odmaster.third', {'third': {'hidden': True, 'slave': True}})]),
##test a config with dynoption ##test a config with dynoption
@ -1047,10 +1073,14 @@ def test_options(paths):
kwargs['permissive'] = True kwargs['permissive'] = True
if not od: if not od:
kwargs.setdefault('extra_properties', []).append('hidden') kwargs.setdefault('extra_properties', []).append('hidden')
else:
kwargs['permissive_od'] = True
if options.get('disabled', False) is True: if options.get('disabled', False) is True:
kwargs['propertyerror'] = True kwargs['propertyerror'] = True
if not od: if not od:
kwargs.setdefault('extra_properties', []).append('disabled') kwargs.setdefault('extra_properties', []).append('disabled')
else:
kwargs['propertyerror_od'] = True
def get_kwargs(path): def get_kwargs(path):
kwargs = {} kwargs = {}
@ -1067,18 +1097,18 @@ def test_options(paths):
for multi in (False, True, submulti): for multi in (False, True, submulti):
if multi is False and default_multi: if multi is False and default_multi:
continue continue
api, weakrefs = make_api(paths, meta, multi, default, default_multi) cfg, weakrefs = make_conf(paths, meta, multi, default, default_multi)
if api is None: if cfg is None:
continue continue
if len(lpaths) == 9: if len(lpaths) == 9:
check_all(api, lpaths[3], meta, multi, default, default_multi, **get_kwargs(lpaths[0])) check_all(cfg, lpaths[3], meta, multi, default, default_multi, **get_kwargs(lpaths[0]))
check_all(api, lpaths[4], meta, multi, default, default_multi, **get_kwargs(lpaths[1])) check_all(cfg, lpaths[4], meta, multi, default, default_multi, **get_kwargs(lpaths[1]))
check_all(api, lpaths[5], meta, multi, default, default_multi, **get_kwargs(lpaths[2])) check_all(cfg, lpaths[5], meta, multi, default, default_multi, **get_kwargs(lpaths[2]))
check_all(api, lpaths[6], meta, multi, default, default_multi, **get_kwargs(lpaths[0])) check_all(cfg, lpaths[6], meta, multi, default, default_multi, **get_kwargs(lpaths[0]))
check_all(api, lpaths[7], meta, multi, default, default_multi, **get_kwargs(lpaths[1])) check_all(cfg, lpaths[7], meta, multi, default, default_multi, **get_kwargs(lpaths[1]))
check_all(api, lpaths[8], meta, multi, default, default_multi, **get_kwargs(lpaths[2])) check_all(cfg, lpaths[8], meta, multi, default, default_multi, **get_kwargs(lpaths[2]))
else: else:
for lpath in lpaths: for lpath in lpaths:
check_all(api, lpath, meta, multi, default, default_multi, **get_kwargs(lpath)) check_all(cfg, lpath, meta, multi, default, default_multi, **get_kwargs(lpath))
del api del cfg
check_deref(weakrefs) check_deref(weakrefs)