2017-11-05 15:40:27 +01:00
|
|
|
"""test API
|
2017-10-22 09:48:08 +02:00
|
|
|
"""
|
2017-11-16 21:30:07 +01:00
|
|
|
import weakref
|
2017-10-22 09:48:08 +02:00
|
|
|
import pytest
|
2017-11-18 14:51:00 +01:00
|
|
|
from copy import copy
|
2017-10-22 09:48:08 +02:00
|
|
|
from py.test import raises
|
|
|
|
from .autopath import do_autopath
|
|
|
|
do_autopath()
|
2017-11-16 21:30:07 +01:00
|
|
|
from tiramisu import Config, MetaConfig, \
|
|
|
|
StrOption, OptionDescription, MasterSlaves, DynOptionDescription, \
|
|
|
|
getapi, submulti, undefined
|
2017-11-18 14:51:00 +01:00
|
|
|
from tiramisu.error import PropertiesOptionError, APIError, ConfigError
|
2017-10-25 08:46:22 +02:00
|
|
|
from collections import OrderedDict
|
2017-10-22 09:48:08 +02:00
|
|
|
ICON = u'\u2937'
|
|
|
|
|
|
|
|
OPTIONS_TYPE = {'str': {'type': str,
|
|
|
|
'option': StrOption}
|
2017-11-16 21:30:07 +01:00
|
|
|
}
|
2017-10-22 09:48:08 +02:00
|
|
|
PROPERTIES = ['hidden', 'disabled']
|
2017-11-18 14:51:00 +01:00
|
|
|
PROPERTIES_LIST = ['prop1', 'prop2']
|
2017-11-16 21:30:07 +01:00
|
|
|
|
|
|
|
OWNER = 'user'
|
|
|
|
|
|
|
|
# multi is False
|
|
|
|
FIRST_VALUE = 'myvalue'
|
|
|
|
SECOND_VALUE = 'myvalue1'
|
|
|
|
EMPTY_VALUE = None
|
|
|
|
# multi is True
|
|
|
|
LIST_FIRST_VALUE = ['myvalue']
|
|
|
|
LIST_SECOND_VALUE = ['myvalue', 'myvalue1']
|
|
|
|
LIST_EMPTY_VALUE = []
|
|
|
|
# multi is submulti
|
|
|
|
SUBLIST_FIRST_VALUE = [['myvalue']]
|
|
|
|
SUBLIST_SECOND_VALUE = [['myvalue'], ['myvalue1', 'myvalue2']]
|
|
|
|
SUBLIST_EMPTY_VALUE = []
|
|
|
|
|
2017-11-05 15:40:27 +01:00
|
|
|
DISPLAY = True
|
2017-11-18 14:51:00 +01:00
|
|
|
DISPLAY = False
|
2017-10-22 09:48:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
def return_list(val=None, suffix=None):
|
|
|
|
if val:
|
|
|
|
return val
|
|
|
|
else:
|
|
|
|
return ['val1', 'val2']
|
|
|
|
|
|
|
|
|
|
|
|
def display_info(func):
|
|
|
|
def wrapper(*args, **kwargs):
|
2017-11-05 15:40:27 +01:00
|
|
|
if DISPLAY:
|
|
|
|
print(u'\n{} {}'.format(ICON, func.__name__))
|
2017-10-22 09:48:08 +02:00
|
|
|
return func(*args, **kwargs)
|
|
|
|
return wrapper
|
|
|
|
|
|
|
|
|
|
|
|
autocheck_registers = []
|
|
|
|
|
|
|
|
|
|
|
|
def autocheck(func):
|
|
|
|
autocheck_registers.append(func)
|
|
|
|
def wrapper(*args, **kwargs):
|
2017-11-05 15:40:27 +01:00
|
|
|
if DISPLAY and kwargs.get('display', True):
|
2017-10-22 09:48:08 +02:00
|
|
|
print(u' {} {}'.format(ICON, func.__name__))
|
|
|
|
return func(*args, **kwargs)
|
|
|
|
return wrapper
|
|
|
|
|
|
|
|
|
|
|
|
@autocheck
|
2017-11-18 14:51:00 +01:00
|
|
|
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):
|
2017-10-22 09:48:08 +02:00
|
|
|
"""check different value of owner when any value is set to this option
|
|
|
|
"""
|
2017-11-18 14:51:00 +01:00
|
|
|
isslave = api.unrestraint.option(path).option.isslave()
|
|
|
|
# check if owner is a string "default" and 'isdefault'
|
|
|
|
if not isslave:
|
|
|
|
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
2017-11-13 22:45:53 +01:00
|
|
|
assert api.option(path).owner.get() == 'default'
|
2017-11-18 14:51:00 +01:00
|
|
|
assert api.forcepermissive.option(path).owner.get() == 'default'
|
|
|
|
#
|
|
|
|
assert api.option(path).owner.isdefault()
|
|
|
|
assert api.forcepermissive.option(path).owner.isdefault()
|
|
|
|
elif not kwargs.get('propertyerror', False):
|
2017-11-05 15:40:27 +01:00
|
|
|
raises(PropertiesOptionError, "api.option(path).owner.get()")
|
|
|
|
assert api.forcepermissive.option(path).owner.get() == 'default'
|
2017-11-18 14:51:00 +01:00
|
|
|
#
|
|
|
|
raises(PropertiesOptionError, "api.option(path).owner.isdefault()")
|
|
|
|
assert api.forcepermissive.option(path).owner.isdefault()
|
2017-10-22 09:48:08 +02:00
|
|
|
else:
|
2017-11-18 14:51:00 +01:00
|
|
|
raises(PropertiesOptionError, "api.option(path).owner.get()")
|
2017-11-05 15:40:27 +01:00
|
|
|
raises(PropertiesOptionError, "api.forcepermissive.option(path).owner.get()")
|
2017-11-18 14:51:00 +01:00
|
|
|
#
|
|
|
|
raises(PropertiesOptionError, "api.option(path).owner.isdefault()")
|
|
|
|
raises(PropertiesOptionError, "api.forcepermissive.option(path).owner.isdefault()")
|
|
|
|
else:
|
|
|
|
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()")
|
2017-10-22 09:48:08 +02:00
|
|
|
else:
|
2017-11-18 14:51:00 +01:00
|
|
|
raises(PropertiesOptionError, "api.option(path, 0).owner.get()")
|
2017-11-05 15:40:27 +01:00
|
|
|
raises(PropertiesOptionError, "api.forcepermissive.option(path, 0).owner.get()")
|
2017-11-18 14:51:00 +01:00
|
|
|
#
|
|
|
|
raises(PropertiesOptionError, "api.option(path, 0).owner.isdefault()")
|
|
|
|
raises(PropertiesOptionError, "api.forcepermissive.option(path, 0).owner.isdefault()")
|
2017-10-22 09:48:08 +02:00
|
|
|
|
2017-11-18 14:51:00 +01:00
|
|
|
# unrestraint is not allowed
|
|
|
|
raises(APIError, "api.unrestraint.option(path).owner.get()")
|
2017-11-05 15:40:27 +01:00
|
|
|
raises(APIError, "api.unrestraint.option(path).owner.isdefault()")
|
2017-11-18 14:51:00 +01:00
|
|
|
|
2017-10-22 09:48:08 +02:00
|
|
|
|
2017-11-16 21:30:07 +01:00
|
|
|
def _getdefault(api, path, multi, isslave, submulti_):
|
|
|
|
empty_value = api.unrestraint.option(path).option.getdefault()
|
|
|
|
if isslave and empty_value == []:
|
|
|
|
empty_value = api.unrestraint.option(path).option.getdefaultmulti()
|
|
|
|
return empty_value
|
2017-10-22 09:48:08 +02:00
|
|
|
|
2017-11-18 14:51:00 +01:00
|
|
|
|
|
|
|
def _autocheck_default_value(api, path, **kwargs):
|
2017-10-22 09:48:08 +02:00
|
|
|
"""set and get values
|
|
|
|
"""
|
|
|
|
# check if is a multi, a master or a slave
|
2017-11-18 14:51:00 +01:00
|
|
|
multi = api.unrestraint.option(path).option.ismulti()
|
|
|
|
submulti_ = api.unrestraint.option(path).option.issubmulti()
|
|
|
|
isslave = api.unrestraint.option(path).option.isslave()
|
2017-10-22 09:48:08 +02:00
|
|
|
|
|
|
|
# set default value (different if value is multi or not)
|
2017-11-16 21:30:07 +01:00
|
|
|
empty_value = _getdefault(api, path, multi, isslave, submulti_)
|
2017-10-22 09:48:08 +02:00
|
|
|
|
2017-11-18 14:51:00 +01:00
|
|
|
# test default value (should be empty)
|
2017-10-22 09:48:08 +02:00
|
|
|
# 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):
|
2017-11-05 15:40:27 +01:00
|
|
|
assert api.option(path).value.get() == empty_value
|
2017-11-18 14:51:00 +01:00
|
|
|
assert api.forcepermissive.option(path).value.get() == empty_value
|
|
|
|
elif not kwargs.get('propertyerror', False):
|
2017-11-05 15:40:27 +01:00
|
|
|
raises(PropertiesOptionError, "api.option(path).value.get()")
|
|
|
|
assert api.forcepermissive.option(path).value.get() == empty_value
|
2017-10-22 09:48:08 +02:00
|
|
|
else:
|
2017-11-18 14:51:00 +01:00
|
|
|
raises(PropertiesOptionError, "api.option(path).value.get()")
|
2017-11-05 15:40:27 +01:00
|
|
|
raises(PropertiesOptionError, "api.forcepermissive.option(path).value.get()")
|
2017-11-18 14:51:00 +01:00
|
|
|
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
|
2017-10-22 09:48:08 +02:00
|
|
|
|
2017-11-05 15:40:27 +01:00
|
|
|
# for slave should have an index and good length
|
2017-10-22 09:48:08 +02:00
|
|
|
# for master must append, not set
|
2017-11-18 14:51:00 +01:00
|
|
|
if ismaster:
|
|
|
|
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
2017-11-05 15:40:27 +01:00
|
|
|
raises(APIError, "api.option(path, 0).value.set(first_value[0])")
|
2017-11-18 14:51:00 +01:00
|
|
|
if not set_permissive:
|
|
|
|
api.option(path).value.set([first_value[0]])
|
|
|
|
else:
|
|
|
|
api.forcepermissive.option(path).value.set([first_value[0]])
|
|
|
|
elif not kwargs.get('propertyerror', False):
|
|
|
|
raises(PropertiesOptionError, "api.option(path).value.set([first_value[0]])")
|
|
|
|
if set_permissive:
|
|
|
|
api.forcepermissive.option(path).value.set([first_value[0]])
|
2017-10-22 09:48:08 +02:00
|
|
|
else:
|
2017-11-12 20:11:56 +01:00
|
|
|
raises(PropertiesOptionError, "api.option(path).value.set([first_value[0]])")
|
2017-11-18 14:51:00 +01:00
|
|
|
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])")
|
|
|
|
if set_permissive:
|
|
|
|
api.forcepermissive.option(path, 0).value.set(first_value[0])
|
|
|
|
else:
|
2017-11-05 15:40:27 +01:00
|
|
|
raises(PropertiesOptionError, "api.option(path, 0).value.set(first_value[0])")
|
2017-11-18 14:51:00 +01:00
|
|
|
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)
|
2017-10-22 09:48:08 +02:00
|
|
|
else:
|
2017-11-05 15:40:27 +01:00
|
|
|
raises(PropertiesOptionError, "api.option(path).value.set(first_value)")
|
2017-11-18 14:51:00 +01:00
|
|
|
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
|
2017-10-22 09:48:08 +02:00
|
|
|
|
|
|
|
# get value after set value without permissive
|
2017-11-18 14:51:00 +01:00
|
|
|
if isslave:
|
|
|
|
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
2017-11-05 15:40:27 +01:00
|
|
|
assert api.option(path, 0).value.get() == first_value[0]
|
2017-11-18 14:51:00 +01:00
|
|
|
assert api.forcepermissive.option(path, 0).value.get() == first_value[0]
|
|
|
|
elif kwargs.get('permissive', False):
|
2017-11-05 15:40:27 +01:00
|
|
|
raises(PropertiesOptionError, "api.option(path, 0).value.get()")
|
2017-11-18 14:51:00 +01:00
|
|
|
assert api.forcepermissive.option(path, 0).value.get() == first_value
|
2017-10-22 09:48:08 +02:00
|
|
|
else:
|
2017-11-05 15:40:27 +01:00
|
|
|
raises(PropertiesOptionError, "api.option(path, 0).value.get()")
|
|
|
|
raises(PropertiesOptionError, "api.forcepermissive.option(path, 0).value.get()")
|
2017-11-18 14:51:00 +01:00
|
|
|
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()")
|
|
|
|
assert api.forcepermissive.option(path).value.get() == first_value
|
2017-10-22 09:48:08 +02:00
|
|
|
else:
|
2017-11-05 15:40:27 +01:00
|
|
|
raises(PropertiesOptionError, "api.option(path).value.get()")
|
|
|
|
raises(PropertiesOptionError, "api.forcepermissive.option(path).value.get()")
|
2017-10-22 09:48:08 +02:00
|
|
|
|
2017-11-18 14:51:00 +01:00
|
|
|
|
|
|
|
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
|
2017-10-22 09:48:08 +02:00
|
|
|
else:
|
2017-11-18 14:51:00 +01:00
|
|
|
first_value = SUBLIST_FIRST_VALUE
|
2017-10-22 09:48:08 +02:00
|
|
|
|
2017-11-18 14:51:00 +01:00
|
|
|
# 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):
|
2017-11-05 15:40:27 +01:00
|
|
|
raises(PropertiesOptionError, "api.option(path, 0).value.get()")
|
2017-11-18 14:51:00 +01:00
|
|
|
assert api.forcepermissive.option(path, 0).value.get() == empty_value
|
2017-10-22 09:48:08 +02:00
|
|
|
else:
|
2017-11-05 15:40:27 +01:00
|
|
|
raises(PropertiesOptionError, "api.option(path, 0).value.get()")
|
|
|
|
raises(PropertiesOptionError, "api.forcepermissive.option(path, 0).value.get()")
|
2017-11-18 14:51:00 +01:00
|
|
|
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()")
|
|
|
|
assert api.forcepermissive.option(path).value.get() == empty_value
|
2017-10-22 09:48:08 +02:00
|
|
|
else:
|
2017-11-05 15:40:27 +01:00
|
|
|
raises(PropertiesOptionError, "api.option(path).value.get()")
|
|
|
|
raises(PropertiesOptionError, "api.forcepermissive.option(path).value.get()")
|
2017-10-22 09:48:08 +02:00
|
|
|
|
|
|
|
|
2017-11-18 14:51:00 +01:00
|
|
|
@autocheck
|
|
|
|
def autocheck_get_value(api, path, **kwargs):
|
|
|
|
_autocheck_set_value(api, path, set_permissive=False, **kwargs)
|
|
|
|
_autocheck_get_value(api, path, **kwargs)
|
|
|
|
|
|
|
|
|
2017-11-16 21:30:07 +01:00
|
|
|
@autocheck
|
|
|
|
def autocheck_value_slave(api, path, **kwargs):
|
|
|
|
isslave = api.unrestraint.option(path).option.isslave()
|
|
|
|
if not isslave:
|
2017-11-18 14:51:00 +01:00
|
|
|
#FIXME raises(APIError, "api.option(path).value.len()")
|
2017-11-16 21:30:07 +01:00
|
|
|
return
|
|
|
|
if kwargs.get('propertyerror', False):
|
2017-11-18 14:51:00 +01:00
|
|
|
raises(PropertiesOptionError, "api.option(path).value.len()")
|
|
|
|
raises(PropertiesOptionError, "api.forcepermissive.option(path).value.len()")
|
2017-11-16 21:30:07 +01:00
|
|
|
return
|
2017-11-18 14:51:00 +01:00
|
|
|
|
|
|
|
multi = api.unrestraint.option(path).option.ismulti()
|
2017-11-16 21:30:07 +01:00
|
|
|
submulti_ = api.forcepermissive.option(path).option.issubmulti()
|
2017-11-18 14:51:00 +01:00
|
|
|
if not submulti_:
|
|
|
|
second_value = LIST_SECOND_VALUE
|
|
|
|
else:
|
|
|
|
second_value = SUBLIST_SECOND_VALUE
|
|
|
|
empty_value = _getdefault(api, path, multi, isslave, submulti_)
|
|
|
|
|
2017-11-16 21:30:07 +01:00
|
|
|
if not kwargs.get('permissive', False):
|
|
|
|
length = api.option(path).value.len()
|
2017-11-18 14:51:00 +01:00
|
|
|
assert api.forcepermissive.option(path).value.len() == length
|
2017-11-16 21:30:07 +01:00
|
|
|
else:
|
2017-11-18 14:51:00 +01:00
|
|
|
raises(PropertiesOptionError, "api.option(path).value.len()")
|
2017-11-16 21:30:07 +01:00
|
|
|
length = api.forcepermissive.option(path).value.len()
|
2017-11-18 14:51:00 +01:00
|
|
|
|
2017-11-16 21:30:07 +01:00
|
|
|
assert length == 2
|
2017-11-18 14:51:00 +01:00
|
|
|
|
2017-11-16 21:30:07 +01:00
|
|
|
value = []
|
|
|
|
for idx in range(length):
|
|
|
|
value.append(api.forcepermissive.option(path, idx).value.get())
|
2017-11-18 14:51:00 +01:00
|
|
|
|
2017-11-16 21:30:07 +01:00
|
|
|
assert value == [empty_value, second_value[1]]
|
|
|
|
# cannot access to a slave with index too high
|
|
|
|
if submulti_ is False:
|
|
|
|
value = LIST_FIRST_VALUE[0]
|
|
|
|
else:
|
|
|
|
value = SUBLIST_FIRST_VALUE[0]
|
2017-11-18 14:51:00 +01:00
|
|
|
|
2017-11-16 21:30:07 +01:00
|
|
|
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.reset()")
|
|
|
|
raises(IndexError, "api.forcepermissive.option(path, length).owner.get()")
|
|
|
|
raises(IndexError, "api.forcepermissive.option(path, length).owner.isdefault()")
|
|
|
|
raises(IndexError, "api.forcepermissive.option(path, length).property.get()")
|
|
|
|
raises(IndexError, "api.forcepermissive.option(path, length).owner.set('new_user')")
|
|
|
|
raises(IndexError, "api.forcepermissive.option(path, length).property.set(('prop',))")
|
|
|
|
|
|
|
|
|
2017-10-22 09:48:08 +02:00
|
|
|
@autocheck
|
|
|
|
def autocheck_reset_value(api, path, **kwargs):
|
|
|
|
# check if is a multi, a master or a slave
|
2017-11-12 20:11:56 +01:00
|
|
|
multi = api.unrestraint.option(path).option.ismulti()
|
2017-11-16 21:30:07 +01:00
|
|
|
submulti_ = api.unrestraint.option(path).option.issubmulti()
|
2017-11-12 20:11:56 +01:00
|
|
|
isslave = api.unrestraint.option(path).option.isslave()
|
2017-10-22 09:48:08 +02:00
|
|
|
|
|
|
|
# set default value (different if value is multi or not)
|
|
|
|
if not multi:
|
2017-11-16 21:30:07 +01:00
|
|
|
first_value = FIRST_VALUE
|
|
|
|
second_value = SECOND_VALUE
|
|
|
|
elif submulti_ is False:
|
|
|
|
first_value = LIST_FIRST_VALUE
|
|
|
|
second_value = LIST_SECOND_VALUE
|
2017-10-22 09:48:08 +02:00
|
|
|
else:
|
2017-11-16 21:30:07 +01:00
|
|
|
first_value = SUBLIST_FIRST_VALUE
|
|
|
|
second_value = SUBLIST_SECOND_VALUE
|
|
|
|
empty_value = _getdefault(api, path, multi, isslave, submulti_)
|
2017-11-18 14:51:00 +01:00
|
|
|
_autocheck_set_value(api, path, **kwargs)
|
2017-10-22 09:48:08 +02:00
|
|
|
|
|
|
|
# reset value without permissive
|
2017-11-18 14:51:00 +01:00
|
|
|
if not isslave:
|
|
|
|
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
2017-11-05 15:40:27 +01:00
|
|
|
api.option(path).value.reset()
|
2017-10-22 09:48:08 +02:00
|
|
|
else:
|
2017-11-05 15:40:27 +01:00
|
|
|
raises(PropertiesOptionError, "api.option(path).value.reset()")
|
2017-11-18 14:51:00 +01:00
|
|
|
else:
|
|
|
|
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
|
|
|
api.option(path, 0).value.reset()
|
2017-10-22 09:48:08 +02:00
|
|
|
else:
|
2017-11-05 15:40:27 +01:00
|
|
|
raises(PropertiesOptionError, "api.option(path, 0).value.reset()")
|
2017-10-22 09:48:08 +02:00
|
|
|
|
|
|
|
# get value after reset value without permissive
|
2017-11-18 14:51:00 +01:00
|
|
|
if isslave:
|
|
|
|
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
2017-11-05 15:40:27 +01:00
|
|
|
assert api.option(path, 0).value.get() == empty_value
|
|
|
|
assert api.option(path, 1).value.get() == second_value[1]
|
2017-11-18 14:51:00 +01:00
|
|
|
elif kwargs.get('permissive', False):
|
2017-11-05 15:40:27 +01:00
|
|
|
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]
|
2017-11-18 14:51:00 +01:00
|
|
|
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):
|
2017-11-05 15:40:27 +01:00
|
|
|
raises(PropertiesOptionError, "api.option(path).value.get()")
|
|
|
|
assert api.forcepermissive.option(path).value.get() == first_value
|
2017-10-22 09:48:08 +02:00
|
|
|
|
2017-11-18 14:51:00 +01:00
|
|
|
|
|
|
|
@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)
|
|
|
|
|
2017-10-22 09:48:08 +02:00
|
|
|
# reset value with permissive
|
|
|
|
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
|
|
|
if not isslave:
|
2017-11-05 15:40:27 +01:00
|
|
|
api.forcepermissive.option(path).value.reset()
|
2017-10-22 09:48:08 +02:00
|
|
|
else:
|
2017-11-05 15:40:27 +01:00
|
|
|
api.forcepermissive.option(path, 1).value.reset()
|
2017-10-22 09:48:08 +02:00
|
|
|
elif kwargs.get('permissive', False):
|
|
|
|
if not isslave:
|
2017-11-05 15:40:27 +01:00
|
|
|
api.forcepermissive.option(path).value.reset()
|
2017-10-22 09:48:08 +02:00
|
|
|
else:
|
2017-11-05 15:40:27 +01:00
|
|
|
api.forcepermissive.option(path, 1).value.reset()
|
2017-10-22 09:48:08 +02:00
|
|
|
else:
|
|
|
|
if not isslave:
|
2017-11-05 15:40:27 +01:00
|
|
|
raises(PropertiesOptionError, "api.forcepermissive.option(path).value.reset()")
|
2017-10-22 09:48:08 +02:00
|
|
|
else:
|
2017-11-05 15:40:27 +01:00
|
|
|
raises(PropertiesOptionError, "api.forcepermissive.option(path, 1).value.reset()")
|
2017-11-18 14:51:00 +01:00
|
|
|
_autocheck_default_value(api, path, **kwargs)
|
2017-10-22 09:48:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
@autocheck
|
2017-11-18 14:51:00 +01:00
|
|
|
def autocheck_display(api, path, **kwargs):
|
2017-10-25 08:46:22 +02:00
|
|
|
"""re set value
|
2017-10-22 09:48:08 +02:00
|
|
|
"""
|
2017-11-18 14:51:00 +01:00
|
|
|
#FIXME make_dict?
|
|
|
|
assert api.config
|
|
|
|
_autocheck_set_value(api, path, **kwargs)
|
|
|
|
assert api.config
|
2017-10-22 09:48:08 +02:00
|
|
|
|
|
|
|
|
2017-11-18 14:51:00 +01:00
|
|
|
def _getproperties(multi, isslave, 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
|
2017-11-13 22:45:53 +01:00
|
|
|
"""
|
2017-11-18 14:51:00 +01:00
|
|
|
# check if is a multi or a slave
|
|
|
|
multi = api.unrestraint.option(path).option.ismulti()
|
|
|
|
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:
|
|
|
|
default_props = []
|
|
|
|
extra_properties = kwargs.get('extra_properties')
|
|
|
|
if extra_properties:
|
|
|
|
properties.extend(extra_properties)
|
|
|
|
default_props.extend(extra_properties)
|
|
|
|
default_props, properties = _getproperties(multi, isslave, kwargs)
|
|
|
|
|
|
|
|
_check_default_properties(api, path, kwargs, default_props, default_props)
|
|
|
|
|
|
|
|
# set properties without permissive
|
|
|
|
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
|
|
|
api.option(path).property.set(properties)
|
|
|
|
else:
|
|
|
|
raises(PropertiesOptionError, "api.option(path).property.set(properties)")
|
|
|
|
|
|
|
|
_check_default_properties(api, path, kwargs, properties, default_props)
|
2017-11-13 22:45:53 +01:00
|
|
|
|
|
|
|
|
2017-10-22 09:48:08 +02:00
|
|
|
@autocheck
|
|
|
|
def autocheck_property(api, path, **kwargs):
|
2017-11-18 14:51:00 +01:00
|
|
|
_autocheck_property(api, path, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
def _property_permissive(api, path, **kwargs):
|
2017-10-22 09:48:08 +02:00
|
|
|
# check if is a multi or a slave
|
2017-11-12 20:11:56 +01:00
|
|
|
multi = api.unrestraint.option(path).option.ismulti()
|
|
|
|
isslave = api.unrestraint.option(path).option.isslave()
|
2017-10-22 09:48:08 +02:00
|
|
|
|
|
|
|
# define properties
|
2017-11-18 14:51:00 +01:00
|
|
|
properties = copy(PROPERTIES_LIST)
|
2017-10-22 09:48:08 +02:00
|
|
|
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)
|
2017-11-18 14:51:00 +01:00
|
|
|
default_props, properties = _getproperties(multi, isslave, kwargs)
|
2017-10-22 09:48:08 +02:00
|
|
|
|
2017-11-18 14:51:00 +01:00
|
|
|
_check_default_properties(api, path, kwargs, default_props, default_props)
|
2017-10-22 09:48:08 +02:00
|
|
|
|
2017-11-18 14:51:00 +01:00
|
|
|
# set properties with permissive
|
2017-10-22 09:48:08 +02:00
|
|
|
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
2017-11-05 15:40:27 +01:00
|
|
|
api.option(path).property.set(properties)
|
2017-11-18 14:51:00 +01:00
|
|
|
api.forcepermissive.option(path).property.set(properties)
|
|
|
|
elif not kwargs.get('propertyerror', False):
|
|
|
|
raises(PropertiesOptionError, "api.option(path).property.set(properties)")
|
2017-11-05 15:40:27 +01:00
|
|
|
api.forcepermissive.option(path).property.set(properties)
|
2017-10-22 09:48:08 +02:00
|
|
|
else:
|
2017-11-18 14:51:00 +01:00
|
|
|
raises(PropertiesOptionError, "api.option(path).property.set(properties)")
|
2017-11-05 15:40:27 +01:00
|
|
|
raises(PropertiesOptionError, "api.forcepermissive.option(path).property.set(properties)")
|
2017-10-22 09:48:08 +02:00
|
|
|
|
2017-11-18 14:51:00 +01:00
|
|
|
_check_default_properties(api, path, kwargs, properties, properties)
|
|
|
|
|
|
|
|
|
|
|
|
@autocheck
|
|
|
|
def autocheck_property_permissive(api, path, **kwargs):
|
|
|
|
_property_permissive(api, path, **kwargs)
|
2017-10-22 09:48:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
@autocheck
|
|
|
|
def autocheck_reset_property(api, path, **kwargs):
|
|
|
|
"""check properties after set with permissive
|
|
|
|
"""
|
|
|
|
# check if is a multi or a slave
|
2017-11-18 14:51:00 +01:00
|
|
|
multi = api.unrestraint.option(path).option.ismulti()
|
|
|
|
isslave = api.unrestraint.option(path).option.isslave()
|
|
|
|
default_props, properties = _getproperties(multi, isslave, kwargs)
|
2017-10-22 09:48:08 +02:00
|
|
|
|
2017-11-18 14:51:00 +01:00
|
|
|
_property_permissive(api, path, **kwargs)
|
2017-10-22 09:48:08 +02:00
|
|
|
|
|
|
|
# reset properties without permissive
|
|
|
|
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
2017-11-05 15:40:27 +01:00
|
|
|
api.option(path).property.reset()
|
2017-10-22 09:48:08 +02:00
|
|
|
else:
|
2017-11-05 15:40:27 +01:00
|
|
|
raises(PropertiesOptionError, "api.option(path).property.reset()")
|
2017-10-22 09:48:08 +02:00
|
|
|
|
2017-11-18 14:51:00 +01:00
|
|
|
_check_default_properties(api, path, kwargs, default_props, properties)
|
|
|
|
|
|
|
|
|
|
|
|
@autocheck
|
|
|
|
def autocheck_reset_property_permissive(api, path, **kwargs):
|
|
|
|
# check if is a multi or a slave
|
|
|
|
multi = api.unrestraint.option(path).option.ismulti()
|
|
|
|
isslave = api.unrestraint.option(path).option.isslave()
|
|
|
|
default_props, properties = _getproperties(multi, isslave, kwargs)
|
|
|
|
|
|
|
|
_property_permissive(api, path, **kwargs)
|
2017-10-22 09:48:08 +02:00
|
|
|
|
|
|
|
# reset properties with permissive
|
2017-11-05 15:40:27 +01:00
|
|
|
raises(APIError, "api.unrestraint.option(path).property.set(properties)")
|
|
|
|
raises(APIError, "api.unrestraint.option(path).property.reset()")
|
2017-10-22 09:48:08 +02:00
|
|
|
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
2017-11-05 15:40:27 +01:00
|
|
|
api.forcepermissive.option(path).property.set(properties)
|
|
|
|
api.forcepermissive.option(path).property.reset()
|
2017-10-22 09:48:08 +02:00
|
|
|
elif kwargs.get('permissive', False):
|
2017-11-05 15:40:27 +01:00
|
|
|
api.forcepermissive.option(path).property.reset()
|
2017-10-22 09:48:08 +02:00
|
|
|
|
2017-11-18 14:51:00 +01:00
|
|
|
_check_default_properties(api, path, kwargs, default_props, default_props)
|
2017-10-22 09:48:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
@autocheck
|
2017-11-18 14:51:00 +01:00
|
|
|
def autocheck_context_owner(api, path, **kwargs):
|
2017-11-16 21:30:07 +01:00
|
|
|
owner = api.owner.get()
|
|
|
|
assert owner == OWNER
|
|
|
|
|
2017-11-18 14:51:00 +01:00
|
|
|
|
|
|
|
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):
|
2017-11-16 21:30:07 +01:00
|
|
|
assert api.option(path).owner.get() == owner
|
2017-11-18 14:51:00 +01:00
|
|
|
assert api.forcepermissive.option(path).owner.get() == owner
|
|
|
|
elif not kwargs.get('propertyerror', False):
|
2017-11-05 15:40:27 +01:00
|
|
|
raises(PropertiesOptionError, "api.option(path).owner.get()")
|
2017-11-18 14:51:00 +01:00
|
|
|
assert api.forcepermissive.option(path).owner.get() == permissive_owner
|
2017-10-22 09:48:08 +02:00
|
|
|
else:
|
2017-11-18 14:51:00 +01:00
|
|
|
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):
|
2017-11-05 15:40:27 +01:00
|
|
|
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'
|
2017-11-18 14:51:00 +01:00
|
|
|
assert api.forcepermissive.option(path, 1).owner.get() == permissive_owner
|
2017-10-22 09:48:08 +02:00
|
|
|
else:
|
2017-11-18 14:51:00 +01:00
|
|
|
raises(PropertiesOptionError, "api.option(path, 0).owner.get()")
|
2017-11-05 15:40:27 +01:00
|
|
|
raises(PropertiesOptionError, "api.forcepermissive.option(path, 0).owner.get()")
|
2017-10-22 09:48:08 +02:00
|
|
|
|
2017-11-18 14:51:00 +01:00
|
|
|
|
|
|
|
@autocheck
|
|
|
|
def autocheck_owner_with_value(api, path, **kwargs):
|
|
|
|
"""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
|
|
|
|
isslave = api.unrestraint.option(path).option.isslave()
|
|
|
|
|
2017-10-22 09:48:08 +02:00
|
|
|
# test if is default owner without permissive
|
|
|
|
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
2017-11-05 15:40:27 +01:00
|
|
|
assert api.option(path).owner.isdefault() is False
|
2017-10-22 09:48:08 +02:00
|
|
|
else:
|
2017-11-05 15:40:27 +01:00
|
|
|
raises(PropertiesOptionError, "api.option(path).owner.isdefault()")
|
2017-10-22 09:48:08 +02:00
|
|
|
|
2017-11-18 14:51:00 +01:00
|
|
|
|
|
|
|
@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)
|
|
|
|
|
2017-10-22 09:48:08 +02:00
|
|
|
# test if is default owner with permissive
|
|
|
|
if not kwargs.get('propertyerror', False):
|
2017-11-05 15:40:27 +01:00
|
|
|
if not isslave:
|
|
|
|
assert api.forcepermissive.option(path).owner.isdefault() is False
|
|
|
|
else:
|
2017-11-12 20:11:56 +01:00
|
|
|
assert api.forcepermissive.option(path, 0).owner.isdefault() is True
|
|
|
|
assert api.forcepermissive.option(path, 1).owner.isdefault() is False
|
2017-10-22 09:48:08 +02:00
|
|
|
else:
|
2017-11-05 15:40:27 +01:00
|
|
|
raises(PropertiesOptionError, "api.forcepermissive.option(path).owner.isdefault()")
|
2017-10-22 09:48:08 +02:00
|
|
|
|
|
|
|
|
2017-11-18 14:51:00 +01:00
|
|
|
@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')")
|
|
|
|
|
|
|
|
|
2017-10-22 09:48:08 +02:00
|
|
|
@autocheck
|
|
|
|
def autocheck_set_owner(api, path, **kwargs):
|
|
|
|
# test set owner without permissive
|
2017-11-18 14:51:00 +01:00
|
|
|
isslave = api.unrestraint.option(path).option.isslave()
|
|
|
|
|
|
|
|
_autocheck_set_value(api, path, **kwargs)
|
2017-10-22 09:48:08 +02:00
|
|
|
|
|
|
|
# set owner without permissive
|
2017-11-18 14:51:00 +01:00
|
|
|
if not isslave:
|
|
|
|
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
2017-11-05 15:40:27 +01:00
|
|
|
api.option(path).owner.set('new_user')
|
2017-10-22 09:48:08 +02:00
|
|
|
else:
|
2017-11-05 15:40:27 +01:00
|
|
|
raises(PropertiesOptionError, "api.option(path).owner.set('new_user')")
|
2017-11-18 14:51:00 +01:00
|
|
|
else:
|
|
|
|
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
|
|
|
api.option(path, 1).owner.set('new_user')
|
2017-10-22 09:48:08 +02:00
|
|
|
else:
|
2017-11-05 15:40:27 +01:00
|
|
|
raises(PropertiesOptionError, "api.option(path, 1).owner.set('new_user')")
|
2017-10-22 09:48:08 +02:00
|
|
|
|
2017-11-18 14:51:00 +01:00
|
|
|
_check_owner(api, path, kwargs, 'new_user', OWNER)
|
|
|
|
|
|
|
|
|
|
|
|
@autocheck
|
|
|
|
def autocheck_set_owner_permissive(api, path, **kwargs):
|
|
|
|
isslave = api.unrestraint.option(path).option.isslave()
|
|
|
|
|
|
|
|
_autocheck_set_value(api, path, **kwargs)
|
2017-10-22 09:48:08 +02:00
|
|
|
|
|
|
|
# set owner with permissive
|
|
|
|
if not kwargs.get('propertyerror', False):
|
|
|
|
if not isslave:
|
2017-11-05 15:40:27 +01:00
|
|
|
api.forcepermissive.option(path).owner.set('new_user1')
|
2017-10-22 09:48:08 +02:00
|
|
|
else:
|
2017-11-05 15:40:27 +01:00
|
|
|
api.forcepermissive.option(path, 1).owner.set('new_user1')
|
2017-10-22 09:48:08 +02:00
|
|
|
else:
|
|
|
|
if not isslave:
|
2017-11-18 14:51:00 +01:00
|
|
|
raises(PropertiesOptionError,
|
|
|
|
"api.forcepermissive.option(path).owner.set('new_user1')")
|
2017-10-22 09:48:08 +02:00
|
|
|
else:
|
2017-11-18 14:51:00 +01:00
|
|
|
raises(PropertiesOptionError,
|
|
|
|
"api.forcepermissive.option(path, 1).owner.set('new_user1')")
|
2017-10-22 09:48:08 +02:00
|
|
|
|
2017-11-18 14:51:00 +01:00
|
|
|
_check_owner(api, path, kwargs, 'new_user1', 'new_user1')
|
2017-10-22 09:48:08 +02:00
|
|
|
|
|
|
|
|
2017-10-25 08:46:22 +02:00
|
|
|
@autocheck
|
|
|
|
def autocheck_option(api, path, **kwargs):
|
|
|
|
expected_name = path.split('.')[-1]
|
|
|
|
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
2017-11-05 15:40:27 +01:00
|
|
|
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()
|
2017-10-25 08:46:22 +02:00
|
|
|
elif not kwargs.get('propertyerror', False):
|
2017-11-05 15:40:27 +01:00
|
|
|
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(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()
|
2017-10-25 08:46:22 +02:00
|
|
|
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)
|
|
|
|
|
|
|
|
|
2017-11-03 21:52:13 +01:00
|
|
|
@autocheck
|
|
|
|
def autocheck_permissive(api, path, **kwargs):
|
|
|
|
"""test permissive for hidden and disabled value
|
|
|
|
"""
|
2017-11-18 14:51:00 +01:00
|
|
|
# no permissive before
|
|
|
|
assert api.unrestraint.option(path).permissive.get() == frozenset()
|
|
|
|
if kwargs.get('permissive_od', False):
|
|
|
|
assert api.unrestraint.option(path.rsplit('.', 1)[0]).permissive.get() == frozenset()
|
2017-11-03 21:52:13 +01:00
|
|
|
|
|
|
|
# cannot access to hidden value without forcepermissive
|
|
|
|
# and to disabled value (with forcepermissive too)
|
2017-11-18 14:51:00 +01:00
|
|
|
_autocheck_default_value(api, path, **kwargs)
|
2017-11-03 21:52:13 +01:00
|
|
|
|
2017-11-18 14:51:00 +01:00
|
|
|
# set permissive
|
|
|
|
api.unrestraint.option(path).permissive.set(frozenset(['disabled']))
|
2017-11-03 21:52:13 +01:00
|
|
|
|
2017-11-18 14:51:00 +01:00
|
|
|
# have permissive
|
|
|
|
assert api.unrestraint.option(path).permissive.get() == frozenset(['disabled'])
|
2017-11-03 21:52:13 +01:00
|
|
|
|
2017-11-18 14:51:00 +01:00
|
|
|
# can access to disabled value
|
|
|
|
ckwargs = copy(kwargs)
|
|
|
|
ckwargs['propertyerror'] = False
|
|
|
|
_autocheck_default_value(api, path, **ckwargs)
|
|
|
|
|
|
|
|
api.unrestraint.option(path).permissive.set(frozenset(['disabled', 'hidden']))
|
|
|
|
|
|
|
|
# can access to all value except when optiondescript have hidden
|
|
|
|
if not ckwargs.get('permissive_od', False):
|
|
|
|
ckwargs['permissive'] = False
|
|
|
|
_autocheck_default_value(api, path, **ckwargs)
|
|
|
|
|
|
|
|
if ckwargs.get('permissive_od', False):
|
|
|
|
# set permissive to OptionDescription
|
|
|
|
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(cfg, path, meta, multi, default, default_multi, **kwargs):
|
2017-11-05 15:40:27 +01:00
|
|
|
if DISPLAY:
|
2017-11-18 14:51:00 +01:00
|
|
|
text = u' {} launch tests for {}'.format(ICON, path)
|
2017-11-16 21:30:07 +01:00
|
|
|
if multi is True:
|
2017-11-05 15:40:27 +01:00
|
|
|
text += u' as a multi'
|
2017-11-16 21:30:07 +01:00
|
|
|
elif multi is submulti:
|
|
|
|
text += u' as a submulti'
|
|
|
|
if default is True:
|
|
|
|
text += u' with default'
|
|
|
|
if multi is True:
|
|
|
|
text += u' with default value'
|
|
|
|
if default_multi is True:
|
|
|
|
text += u' with default multi'
|
2017-11-13 22:45:53 +01:00
|
|
|
text += u', kwargs: {}'.format(kwargs)
|
2017-11-05 15:40:27 +01:00
|
|
|
print(text)
|
2017-11-18 14:51:00 +01:00
|
|
|
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)
|
2017-10-22 09:48:08 +02:00
|
|
|
for func in autocheck_registers:
|
2017-11-18 14:51:00 +01:00
|
|
|
api = getapi(cfg.duplicate())
|
2017-11-05 15:40:27 +01:00
|
|
|
if DISPLAY:
|
|
|
|
print(u' {} {}'.format(ICON, func.__name__))
|
2017-11-16 21:30:07 +01:00
|
|
|
try:
|
|
|
|
func(api, path, **kwargs)
|
|
|
|
except Exception as err:
|
|
|
|
msg = u'error in function {} for {}'.format(func.__name__, path)
|
|
|
|
if multi is True:
|
|
|
|
msg += u' as a multi'
|
|
|
|
elif multi is submulti:
|
|
|
|
msg += u' as a submulti'
|
|
|
|
if multi is True:
|
|
|
|
msg += u' with default value'
|
|
|
|
print(u'{}: {}'.format(msg, kwargs))
|
|
|
|
raise err
|
|
|
|
|
|
|
|
|
|
|
|
def check_deref(weakrefs):
|
|
|
|
"""try if all elements are dereferenced
|
|
|
|
"""
|
|
|
|
for wrf in weakrefs:
|
|
|
|
assert wrf() is None
|
2017-10-22 09:48:08 +02:00
|
|
|
|
|
|
|
|
2017-11-18 14:51:00 +01:00
|
|
|
def make_conf(options, meta, multi, default, default_multi):
|
2017-11-13 22:45:53 +01:00
|
|
|
weakrefs = []
|
2017-11-12 20:11:56 +01:00
|
|
|
def make_option(path, option_infos):
|
|
|
|
#FIXME
|
2017-10-22 09:48:08 +02:00
|
|
|
option_type = 'str'
|
|
|
|
option_properties = []
|
2017-11-16 21:30:07 +01:00
|
|
|
isslave = False
|
2017-11-12 20:11:56 +01:00
|
|
|
if option_infos is not None:
|
|
|
|
for prop in PROPERTIES:
|
|
|
|
if option_infos.get(prop, False) is True:
|
|
|
|
option_properties.append(prop)
|
2017-11-16 21:30:07 +01:00
|
|
|
isslave = option_infos.get('slave', False)
|
2017-11-12 20:11:56 +01:00
|
|
|
args = [path, "{}'s option".format(path)]
|
2017-10-22 09:48:08 +02:00
|
|
|
kwargs = {}
|
|
|
|
if option_properties != []:
|
|
|
|
kwargs['properties'] = tuple(option_properties)
|
|
|
|
if multi:
|
2017-11-16 21:30:07 +01:00
|
|
|
kwargs['multi'] = multi
|
|
|
|
if default and not submulti:
|
|
|
|
if multi is False:
|
|
|
|
value = FIRST_VALUE
|
|
|
|
elif multi is True:
|
|
|
|
value = LIST_FIRST_VALUE
|
|
|
|
else:
|
|
|
|
value = SUBLIST_EMPTY_VALUE
|
|
|
|
kwargs['default'] = value
|
|
|
|
if default_multi:
|
|
|
|
if multi is not submulti:
|
|
|
|
value = SECOND_VALUE
|
|
|
|
else:
|
|
|
|
value = LIST_SECOND_VALUE
|
|
|
|
kwargs['default_multi'] = value
|
|
|
|
|
2017-10-22 09:48:08 +02:00
|
|
|
tiramisu_option = OPTIONS_TYPE[option_type]['option']
|
2017-11-13 22:45:53 +01:00
|
|
|
obj = tiramisu_option(*args, **kwargs)
|
|
|
|
weakrefs.append(weakref.ref(obj))
|
|
|
|
return obj
|
2017-10-22 09:48:08 +02:00
|
|
|
|
|
|
|
def make_optiondescriptions(path, collected):
|
2017-11-12 20:11:56 +01:00
|
|
|
infos = collected.get('properties', {})
|
2017-10-22 09:48:08 +02:00
|
|
|
properties = []
|
|
|
|
kwargs = {}
|
|
|
|
optiondescription = OptionDescription
|
2017-11-12 20:11:56 +01:00
|
|
|
|
|
|
|
for prop in PROPERTIES:
|
|
|
|
if infos.get(prop, False) is True:
|
|
|
|
properties.append(prop)
|
|
|
|
if infos.get('master', False) is True:
|
|
|
|
if not multi:
|
|
|
|
return
|
|
|
|
optiondescription = MasterSlaves
|
|
|
|
if infos.get('dyn', False) is True:
|
|
|
|
optiondescription = DynOptionDescription
|
|
|
|
kwargs['callback'] = return_list
|
2017-10-22 09:48:08 +02:00
|
|
|
options = []
|
|
|
|
if 'options' in collected:
|
|
|
|
options.extend(collected['options'])
|
|
|
|
for key, values in collected.items():
|
2017-11-12 20:11:56 +01:00
|
|
|
if key in ['options', 'properties']:
|
2017-10-22 09:48:08 +02:00
|
|
|
continue
|
|
|
|
option = make_optiondescriptions(key, values)
|
|
|
|
if option is None:
|
|
|
|
return
|
|
|
|
options.append(option)
|
|
|
|
if properties != []:
|
|
|
|
kwargs['properties'] = tuple(properties)
|
2017-11-13 22:45:53 +01:00
|
|
|
obj = optiondescription(path, "{}'s optiondescription".format(path), options, **kwargs)
|
|
|
|
weakrefs.append(weakref.ref(obj))
|
|
|
|
return obj
|
2017-10-22 09:48:08 +02:00
|
|
|
|
|
|
|
collect_options = {}
|
2017-11-12 20:11:56 +01:00
|
|
|
for path, option in options.items():
|
2017-10-22 09:48:08 +02:00
|
|
|
if option is None:
|
|
|
|
continue
|
|
|
|
local_collect_options = collect_options
|
2017-11-12 20:11:56 +01:00
|
|
|
for optiondescription in path.split('.')[:-1]:
|
|
|
|
local_collect_options.setdefault(optiondescription, {'properties': {}})
|
2017-10-22 09:48:08 +02:00
|
|
|
local_collect_options = local_collect_options[optiondescription]
|
2017-11-12 20:11:56 +01:00
|
|
|
local_collect_options['properties'].update(option.get(optiondescription, {}))
|
|
|
|
option_name = path.split('.')[-1]
|
|
|
|
path = '.'.join(path.split('.')[:-1])
|
|
|
|
local_collect_options.setdefault('options', []).append(make_option(option_name, option.get(option_name)))
|
2017-10-22 09:48:08 +02:00
|
|
|
|
|
|
|
rootod = make_optiondescriptions('root', collect_options)
|
|
|
|
if rootod is None:
|
2017-11-13 22:45:53 +01:00
|
|
|
return None, None
|
|
|
|
cfg = Config(rootod, session_id='conftest')
|
|
|
|
weakrefs.append(weakref.ref(cfg))
|
2017-11-16 21:30:07 +01:00
|
|
|
if meta:
|
|
|
|
cfg = MetaConfig([cfg], session_id='metatest')
|
|
|
|
weakrefs.append(weakref.ref(cfg))
|
2017-11-18 14:51:00 +01:00
|
|
|
return cfg, weakrefs
|
2017-10-22 09:48:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
DICT_PATHS = [
|
|
|
|
#test a config without optiondescription
|
2017-11-12 20:11:56 +01:00
|
|
|
OrderedDict([('first', {}),
|
|
|
|
('second', {'second': {'disabled': True}}),
|
2017-11-13 22:45:53 +01:00
|
|
|
('third', {'third': {'hidden': True}})
|
|
|
|
]),
|
2017-10-22 09:48:08 +02:00
|
|
|
#test a config with an optiondescription
|
2017-11-12 20:11:56 +01:00
|
|
|
OrderedDict([('subod.first', {}),
|
|
|
|
('subod.second', {'second': {'disabled': True}}),
|
|
|
|
('subod.third', {'third': {'hidden': True}})]),
|
2017-10-22 09:48:08 +02:00
|
|
|
#test a config with two optiondescription
|
2017-11-12 20:11:56 +01:00
|
|
|
OrderedDict([('subod.subsubod.first', {}),
|
|
|
|
('subod.subsubod.second', {'second': {'disabled': True}}),
|
|
|
|
('subod.subsubod.third', {'third': {'hidden': True}})]),
|
2017-10-22 09:48:08 +02:00
|
|
|
#test a config with mix of different optiondescription
|
2017-11-12 20:11:56 +01:00
|
|
|
OrderedDict([('first', {}),
|
|
|
|
('subod.second', {'second': {'disabled': True}}),
|
|
|
|
('subod.subsubod.third', {'third': {'hidden': True}})]),
|
2017-10-22 09:48:08 +02:00
|
|
|
#test a config with masterslaves
|
2017-11-18 14:51:00 +01:00
|
|
|
OrderedDict([('odmaster.first', {'master': {'master': True}}),
|
2017-11-16 21:30:07 +01:00
|
|
|
('odmaster.second', {'second': {'disabled': True, 'slave': True}}),
|
|
|
|
('odmaster.third', {'third': {'hidden': True, 'slave': True}})]),
|
2017-10-22 09:48:08 +02:00
|
|
|
##test a config with dynoption
|
2017-11-12 20:11:56 +01:00
|
|
|
OrderedDict([('subod.first', {'subod': {'dyn': True}}),
|
|
|
|
('subod.second', {'second': {'disabled': True}}),
|
|
|
|
('subod.third', {'third': {'hidden': True}}),
|
|
|
|
('subodval1.firstval1', None),
|
|
|
|
('subodval1.secondval1', None),
|
|
|
|
('subodval1.thirdval1', None),
|
2017-10-25 22:24:34 +02:00
|
|
|
('subodval2.firstval2', None),
|
|
|
|
('subodval2.secondval2', None),
|
|
|
|
('subodval2.thirdval2', None)]),
|
2017-10-22 09:48:08 +02:00
|
|
|
#test a config with dynoption subdir
|
2017-11-12 20:11:56 +01:00
|
|
|
OrderedDict([('subod.subsubod.first', {'subsubod': {'dyn': True}}),
|
2017-11-13 22:45:53 +01:00
|
|
|
('subod.subsubod.second', {'subsubod': {'dyn': True}, 'second': {'disabled': True}}),
|
|
|
|
('subod.subsubod.third', {'subsubod': {'dyn': True}, 'third': {'hidden': True}}),
|
2017-11-12 20:11:56 +01:00
|
|
|
('subod.subsubodval1.firstval1', None),
|
|
|
|
('subod.subsubodval1.secondval1', None),
|
|
|
|
('subod.subsubodval1.thirdval1', None),
|
|
|
|
('subod.subsubodval2.firstval2', None),
|
|
|
|
('subod.subsubodval2.secondval2', None),
|
2017-11-13 22:45:53 +01:00
|
|
|
('subod.subsubodval2.thirdval2', None)]),
|
|
|
|
#test a config with hidden subsubod
|
2017-11-12 20:11:56 +01:00
|
|
|
OrderedDict([('subod.subsubod.first', {'subsubod': {'hidden': True}}),
|
2017-11-13 22:45:53 +01:00
|
|
|
('subod.subsubod.second', {'subsubod': {'hidden': True}}),
|
|
|
|
('subod.subsubod.third', {'subsubod': {'hidden': True}})]),
|
|
|
|
#test a config with hidden dyn subsubod
|
2017-11-12 20:11:56 +01:00
|
|
|
OrderedDict([('subod.subsubod.first', {'subsubod': {'dyn': True, 'hidden': True}}),
|
2017-11-13 22:45:53 +01:00
|
|
|
('subod.subsubod.second', {'subsubod': {'dyn': True, 'hidden': True}}),
|
|
|
|
('subod.subsubod.third', {'subsubod': {'dyn': True, 'hidden': True}}),
|
2017-11-12 20:11:56 +01:00
|
|
|
('subod.subsubodval1.firstval1', None),
|
|
|
|
('subod.subsubodval1.secondval1', None),
|
|
|
|
('subod.subsubodval1.thirdval1', None),
|
|
|
|
('subod.subsubodval2.firstval2', None),
|
|
|
|
('subod.subsubodval2.secondval2', None),
|
|
|
|
('subod.subsubodval2.thirdval2', None)])
|
2017-10-25 22:24:34 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
|
2017-11-13 22:45:53 +01:00
|
|
|
@pytest.fixture(scope="function", params=DICT_PATHS)
|
|
|
|
def paths(request):
|
2017-11-05 15:40:27 +01:00
|
|
|
if DISPLAY:
|
|
|
|
print(u'\n{} {}: {}'.format(ICON, request.function.__name__, request.param))
|
2017-10-25 22:24:34 +02:00
|
|
|
return request.param
|
|
|
|
|
|
|
|
|
2017-11-13 22:45:53 +01:00
|
|
|
def test_options(paths):
|
|
|
|
def get_kwargs_option(options, kwargs, od=False):
|
|
|
|
if options.get('hidden', False) is True:
|
|
|
|
kwargs['permissive'] = True
|
|
|
|
if not od:
|
|
|
|
kwargs.setdefault('extra_properties', []).append('hidden')
|
2017-11-18 14:51:00 +01:00
|
|
|
else:
|
|
|
|
kwargs['permissive_od'] = True
|
2017-11-13 22:45:53 +01:00
|
|
|
if options.get('disabled', False) is True:
|
|
|
|
kwargs['propertyerror'] = True
|
|
|
|
if not od:
|
|
|
|
kwargs.setdefault('extra_properties', []).append('disabled')
|
2017-11-18 14:51:00 +01:00
|
|
|
else:
|
|
|
|
kwargs['propertyerror_od'] = True
|
2017-11-13 22:45:53 +01:00
|
|
|
|
|
|
|
def get_kwargs(path):
|
|
|
|
kwargs = {}
|
|
|
|
spath = path.split('.')
|
|
|
|
get_kwargs_option(paths[path].get(spath[-1], {}), kwargs)
|
|
|
|
if len(spath) > 1:
|
|
|
|
get_kwargs_option(paths[path].get(spath[-2], {}), kwargs, od=True)
|
|
|
|
return kwargs
|
|
|
|
|
|
|
|
lpaths = list(paths.keys())
|
2017-11-16 21:30:07 +01:00
|
|
|
for meta in (False, True):
|
|
|
|
for default_multi in (False, True):
|
|
|
|
for default in (False, True):
|
|
|
|
for multi in (False, True, submulti):
|
|
|
|
if multi is False and default_multi:
|
|
|
|
continue
|
2017-11-18 14:51:00 +01:00
|
|
|
cfg, weakrefs = make_conf(paths, meta, multi, default, default_multi)
|
|
|
|
if cfg is None:
|
2017-11-16 21:30:07 +01:00
|
|
|
continue
|
|
|
|
if len(lpaths) == 9:
|
2017-11-18 14:51:00 +01:00
|
|
|
check_all(cfg, lpaths[3], meta, multi, default, default_multi, **get_kwargs(lpaths[0]))
|
|
|
|
check_all(cfg, lpaths[4], meta, multi, default, default_multi, **get_kwargs(lpaths[1]))
|
|
|
|
check_all(cfg, lpaths[5], meta, multi, default, default_multi, **get_kwargs(lpaths[2]))
|
|
|
|
check_all(cfg, lpaths[6], meta, multi, default, default_multi, **get_kwargs(lpaths[0]))
|
|
|
|
check_all(cfg, lpaths[7], meta, multi, default, default_multi, **get_kwargs(lpaths[1]))
|
|
|
|
check_all(cfg, lpaths[8], meta, multi, default, default_multi, **get_kwargs(lpaths[2]))
|
2017-11-16 21:30:07 +01:00
|
|
|
else:
|
|
|
|
for lpath in lpaths:
|
2017-11-18 14:51:00 +01:00
|
|
|
check_all(cfg, lpath, meta, multi, default, default_multi, **get_kwargs(lpath))
|
|
|
|
del cfg
|
2017-11-16 21:30:07 +01:00
|
|
|
check_deref(weakrefs)
|