1641 lines
76 KiB
Python
1641 lines
76 KiB
Python
"""test API
|
|
"""
|
|
import weakref
|
|
import pytest
|
|
from copy import copy
|
|
from py.test import raises
|
|
from .autopath import do_autopath
|
|
do_autopath()
|
|
from tiramisu import Config, MetaConfig, \
|
|
StrOption, OptionDescription, MasterSlaves, DynOptionDescription, \
|
|
getapi, submulti, undefined, owners
|
|
from tiramisu.error import PropertiesOptionError, APIError, ConfigError
|
|
from tiramisu.api import display_count
|
|
from collections import OrderedDict
|
|
ICON = u'\u2937'
|
|
|
|
OPTIONS_TYPE = {'str': {'type': str,
|
|
'option': StrOption}
|
|
}
|
|
PROPERTIES = ['hidden', 'disabled']
|
|
PROPERTIES_LIST = ['prop1', 'prop2']
|
|
|
|
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 = []
|
|
|
|
DISPLAY = True
|
|
DISPLAY = False
|
|
|
|
|
|
def return_list(val=None, suffix=None):
|
|
if val:
|
|
return val
|
|
else:
|
|
return ['val1', 'val2']
|
|
|
|
|
|
def return_str(val, suffix=None):
|
|
return val
|
|
|
|
|
|
def display_info(func):
|
|
def wrapper(*args, **kwargs):
|
|
if DISPLAY:
|
|
print(u'\n{} {}'.format(ICON, func.__name__))
|
|
return func(*args, **kwargs)
|
|
return wrapper
|
|
|
|
|
|
autocheck_registers = []
|
|
|
|
|
|
def autocheck(func):
|
|
autocheck_registers.append(func)
|
|
def wrapper(*args, **kwargs):
|
|
if DISPLAY and kwargs.get('display', True):
|
|
print(u' {} {}'.format(ICON, func.__name__))
|
|
return func(*args, **kwargs)
|
|
return wrapper
|
|
|
|
|
|
@autocheck
|
|
def autocheck_option_multi(api, path, confread, confwrite, **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, confread, confwrite, **kwargs):
|
|
"""check different value of owner when any value is set to this option
|
|
"""
|
|
isslave = api.unrestraint.option(path).option.isslave()
|
|
# check if owner is a string "default" and 'isdefault'
|
|
def do(conf):
|
|
if not isslave:
|
|
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
|
assert api.config(conf).option(path).owner.get() == 'default'
|
|
assert api.forcepermissive.config(conf).option(path).owner.get() == 'default'
|
|
#
|
|
assert api.config(conf).option(path).owner.isdefault()
|
|
assert api.forcepermissive.config(conf).option(path).owner.isdefault()
|
|
elif not kwargs.get('propertyerror', False):
|
|
raises(PropertiesOptionError, "api.config(conf).option(path).owner.get()")
|
|
assert api.forcepermissive.config(conf).option(path).owner.get() == 'default'
|
|
#
|
|
raises(PropertiesOptionError, "api.config(conf).option(path).owner.isdefault()")
|
|
assert api.forcepermissive.config(conf).option(path).owner.isdefault()
|
|
else:
|
|
raises(PropertiesOptionError, "api.config(conf).option(path).owner.get()")
|
|
raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(path).owner.get()")
|
|
#
|
|
raises(PropertiesOptionError, "api.config(conf).option(path).owner.isdefault()")
|
|
raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(path).owner.isdefault()")
|
|
else:
|
|
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
|
assert api.config(conf).option(path, 0).owner.get() == 'default'
|
|
assert api.forcepermissive.config(conf).option(path, 0).owner.get() == 'default'
|
|
#
|
|
assert api.config(conf).option(path, 0).owner.isdefault()
|
|
assert api.forcepermissive.config(conf).option(path, 0).owner.isdefault()
|
|
elif not kwargs.get('propertyerror', False):
|
|
raises(PropertiesOptionError, "api.config(conf).option(path, 0).owner.get()")
|
|
assert api.forcepermissive.config(conf).option(path, 0).owner.get() == 'default'
|
|
#
|
|
raises(PropertiesOptionError, "api.config(conf).option(path, 0).owner.isdefault()")
|
|
assert api.forcepermissive.config(conf).option(path, 0).owner.isdefault()
|
|
else:
|
|
raises(PropertiesOptionError, "api.config(conf).option(path, 0).owner.get()")
|
|
raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(path, 0).owner.get()")
|
|
#
|
|
raises(PropertiesOptionError, "api.config(conf).option(path, 0).owner.isdefault()")
|
|
raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(path, 0).owner.isdefault()")
|
|
|
|
# unrestraint is not allowed
|
|
raises(APIError, "api.unrestraint.config(conf).option(path).owner.get()")
|
|
raises(APIError, "api.unrestraint.config(conf).option(path).owner.isdefault()")
|
|
do(confread)
|
|
if confread != confwrite:
|
|
do(confwrite)
|
|
|
|
|
|
def _autocheck_default_value(api, path, conf, **kwargs):
|
|
"""set and get values
|
|
"""
|
|
# check if is a multi, a master or a slave
|
|
multi = api.unrestraint.option(path).option.ismulti()
|
|
submulti_ = api.unrestraint.option(path).option.issubmulti()
|
|
isslave = api.unrestraint.option(path).option.isslave()
|
|
|
|
# set default value (different if value is multi or not)
|
|
empty_value = kwargs['default']
|
|
|
|
# test default value (should be empty)
|
|
# cannot test for slave (we cannot get all values for a slave)
|
|
if not isslave:
|
|
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
|
assert api.config(conf).option(path).value.get() == empty_value
|
|
assert api.forcepermissive.config(conf).option(path).value.get() == empty_value
|
|
elif not kwargs.get('propertyerror', False):
|
|
raises(PropertiesOptionError, "api.config(conf).option(path).value.get()")
|
|
assert api.forcepermissive.config(conf).option(path).value.get() == empty_value
|
|
else:
|
|
raises(PropertiesOptionError, "api.config(conf).option(path).value.get()")
|
|
raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(path).value.get()")
|
|
else:
|
|
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
|
assert api.config(conf).option(path, 0).value.get() == empty_value
|
|
assert api.config(conf).option(path, 1).value.get() == empty_value
|
|
assert api.forcepermissive.config(conf).option(path, 0).value.get() == empty_value
|
|
assert api.forcepermissive.config(conf).option(path, 1).value.get() == empty_value
|
|
elif not kwargs.get('propertyerror', False):
|
|
raises(PropertiesOptionError, "api.config(conf).option(path, 0).value.get()")
|
|
assert api.forcepermissive.config(conf).option(path, 0).value.get() == empty_value
|
|
assert api.forcepermissive.config(conf).option(path, 1).value.get() == empty_value
|
|
else:
|
|
raises(PropertiesOptionError, "api.config(conf).option(path, 0).value.get()")
|
|
raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(path, 0).value.get()")
|
|
|
|
|
|
@autocheck
|
|
def autocheck_default_value(api, path, confread, confwrite, **kwargs):
|
|
_autocheck_default_value(api, path, confread, **kwargs)
|
|
if confread != confwrite:
|
|
_autocheck_default_value(api, path, confwrite, **kwargs)
|
|
|
|
|
|
|
|
def _set_value(api, path, conf, **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()
|
|
if not multi:
|
|
first_value = FIRST_VALUE
|
|
elif submulti_ is False:
|
|
if not isslave:
|
|
first_value = LIST_FIRST_VALUE
|
|
else:
|
|
second_value = LIST_SECOND_VALUE[1]
|
|
|
|
else:
|
|
if not isslave:
|
|
first_value = SUBLIST_FIRST_VALUE
|
|
else:
|
|
second_value = SUBLIST_SECOND_VALUE[1]
|
|
|
|
# for slave should have an index and good length
|
|
# for master must append, not set
|
|
if ismaster:
|
|
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
|
raises(APIError, "api.config(conf).option(path, 0).value.set(first_value[0])")
|
|
if not set_permissive:
|
|
api.config(conf).option(path).value.set([first_value[0]])
|
|
else:
|
|
api.forcepermissive.config(conf).option(path).value.set([first_value[0]])
|
|
elif not kwargs.get('propertyerror', False):
|
|
raises(PropertiesOptionError, "api.config(conf).option(path).value.set([first_value[0]])")
|
|
if set_permissive:
|
|
api.forcepermissive.config(conf).option(path).value.set([first_value[0]])
|
|
else:
|
|
raises(PropertiesOptionError, "api.config(conf).option(path).value.set([first_value[0]])")
|
|
raises(PropertiesOptionError,
|
|
"api.forcepermissive.config(conf).option(path).value.set([first_value[0]])")
|
|
raises(APIError, "api.unrestraint.config(conf).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.config(conf).option(path, 1).value.set(second_value)
|
|
else:
|
|
api.forcepermissive.config(conf).option(path, 1).value.set(second_value)
|
|
elif not kwargs.get('propertyerror', False):
|
|
raises(PropertiesOptionError, "api.config(conf).option(path, 1).value.set(second_value)")
|
|
if set_permissive:
|
|
api.forcepermissive.config(conf).option(path, 1).value.set(second_value)
|
|
else:
|
|
raises(PropertiesOptionError, "api.config(conf).option(path, 1).value.set(second_value)")
|
|
raises(PropertiesOptionError,
|
|
"api.forcepermissive.config(conf).option(path, 1).value.set(second_value)")
|
|
raises(APIError,
|
|
"api.unrestraint.config(conf).option(path).value.set([second_value, second_value])")
|
|
|
|
else:
|
|
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
|
if not set_permissive:
|
|
api.config(conf).option(path).value.set(first_value)
|
|
else:
|
|
api.forcepermissive.config(conf).option(path).value.set(first_value)
|
|
elif not kwargs.get('propertyerror', False):
|
|
raises(PropertiesOptionError, "api.config(conf).option(path).value.set(first_value)")
|
|
if set_permissive:
|
|
api.forcepermissive.config(conf).option(path).value.set(first_value)
|
|
else:
|
|
raises(PropertiesOptionError, "api.config(conf).option(path).value.set(first_value)")
|
|
raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(path).value.set(first_value)")
|
|
raises(APIError, "api.unrestraint.config(conf).option(path).value.set(first_value)")
|
|
|
|
|
|
@autocheck
|
|
def autocheck_set_value(api, path, confread, confwrite, **kwargs):
|
|
_set_value(api, path, confwrite, **kwargs)
|
|
|
|
|
|
@autocheck
|
|
def autocheck_get_value_permissive(api, path, confread, confwrite, **kwargs):
|
|
multi = api.unrestraint.option(path).option.ismulti()
|
|
submulti_ = api.unrestraint.option(path).option.issubmulti()
|
|
isslave = api.unrestraint.option(path).option.isslave()
|
|
_set_value(api, path, confwrite, **kwargs)
|
|
empty_value = kwargs['default']
|
|
if not multi:
|
|
first_value = FIRST_VALUE
|
|
elif submulti_ is False:
|
|
first_value = LIST_FIRST_VALUE
|
|
else:
|
|
first_value = SUBLIST_FIRST_VALUE
|
|
|
|
def do(conf):
|
|
# get value after set value without permissive
|
|
if isslave:
|
|
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
|
assert api.config(conf).option(path, 0).value.get() == empty_value
|
|
assert api.forcepermissive.config(conf).option(path, 0).value.get() == empty_value
|
|
if submulti_:
|
|
assert api.config(conf).option(path, 1).value.get() == SUBLIST_SECOND_VALUE[1]
|
|
assert api.forcepermissive.config(conf).option(path, 1).value.get() == SUBLIST_SECOND_VALUE[1]
|
|
else:
|
|
assert api.config(conf).option(path, 1).value.get() == LIST_SECOND_VALUE[1]
|
|
assert api.forcepermissive.config(conf).option(path, 1).value.get() == LIST_SECOND_VALUE[1]
|
|
elif kwargs.get('permissive', False):
|
|
raises(PropertiesOptionError, "assert api.config(conf).option(path, 0).value.get()")
|
|
raises(PropertiesOptionError, "assert api.config(conf).option(path, 1).value.get()")
|
|
assert api.forcepermissive.config(conf).option(path, 0).value.get() == empty_value
|
|
if submulti_:
|
|
assert api.forcepermissive.config(conf).option(path, 1).value.get() == SUBLIST_SECOND_VALUE[1]
|
|
else:
|
|
assert api.forcepermissive.config(conf).option(path, 1).value.get() == LIST_SECOND_VALUE[1]
|
|
else:
|
|
raises(PropertiesOptionError, "assert api.config(conf).option(path, 0).value.get()")
|
|
raises(PropertiesOptionError, "assert api.config(conf).option(path, 1).value.get()")
|
|
raises(PropertiesOptionError, "assert api.forcepermissive.config(conf).option(path, 0).value.get()")
|
|
raises(PropertiesOptionError, "assert api.forcepermissive.config(conf).option(path, 1).value.get()")
|
|
else:
|
|
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
|
assert api.config(conf).option(path).value.get() == first_value
|
|
assert api.forcepermissive.config(conf).option(path).value.get() == first_value
|
|
elif kwargs.get('permissive', False):
|
|
raises(PropertiesOptionError, "api.config(conf).option(path).value.get()")
|
|
assert api.forcepermissive.config(conf).option(path).value.get() == first_value
|
|
else:
|
|
raises(PropertiesOptionError, "api.config(conf).option(path).value.get()")
|
|
raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(path).value.get()")
|
|
do(confread)
|
|
if confread != confwrite:
|
|
do(confwrite)
|
|
|
|
|
|
def _autocheck_get_value(api, path, conf, **kwargs):
|
|
set_permissive = kwargs.get('set_permissive', True)
|
|
multi = api.unrestraint.option(path).option.ismulti()
|
|
submulti_ = api.unrestraint.option(path).option.issubmulti()
|
|
isslave = api.unrestraint.option(path).option.isslave()
|
|
empty_value = kwargs['default']
|
|
if not multi:
|
|
first_value = FIRST_VALUE
|
|
elif submulti_ is False:
|
|
if not isslave:
|
|
first_value = LIST_FIRST_VALUE
|
|
else:
|
|
second_value = LIST_SECOND_VALUE[1]
|
|
|
|
else:
|
|
if not isslave:
|
|
first_value = SUBLIST_FIRST_VALUE
|
|
else:
|
|
second_value = SUBLIST_SECOND_VALUE[1]
|
|
|
|
# get value after set value without permissive
|
|
if isslave:
|
|
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
|
assert api.config(conf).option(path, 0).value.get() == empty_value
|
|
assert api.config(conf).option(path, 1).value.get() == second_value
|
|
assert api.forcepermissive.config(conf).option(path, 0).value.get() == empty_value
|
|
assert api.forcepermissive.config(conf).option(path, 1).value.get() == second_value
|
|
elif kwargs.get('permissive', False):
|
|
raises(PropertiesOptionError, "api.config(conf).option(path, 0).value.get()")
|
|
assert api.forcepermissive.config(conf).option(path, 0).value.get() == empty_value
|
|
if set_permissive:
|
|
assert api.forcepermissive.config(conf).option(path, 1).value.get() == second_value
|
|
else:
|
|
assert api.forcepermissive.config(conf).option(path, 1).value.get() == empty_value
|
|
else:
|
|
raises(PropertiesOptionError, "api.config(conf).option(path, 0).value.get()")
|
|
raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(path, 0).value.get()")
|
|
else:
|
|
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
|
assert api.config(conf).option(path).value.get() == first_value
|
|
assert api.forcepermissive.config(conf).option(path).value.get() == first_value
|
|
elif kwargs.get('permissive', False):
|
|
raises(PropertiesOptionError, "api.config(conf).option(path).value.get()")
|
|
if set_permissive:
|
|
assert api.forcepermissive.config(conf).option(path).value.get() == first_value
|
|
else:
|
|
assert api.forcepermissive.config(conf).option(path).value.get() == empty_value
|
|
else:
|
|
raises(PropertiesOptionError, "api.config(conf).option(path).value.get()")
|
|
raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(path).value.get()")
|
|
|
|
|
|
@autocheck
|
|
def autocheck_get_value(api, path, confread, confwrite, **kwargs):
|
|
_set_value(api, path, confwrite, set_permissive=False, **kwargs)
|
|
_autocheck_get_value(api, path, confread, set_permissive=False, **kwargs)
|
|
if confread != confwrite:
|
|
_autocheck_get_value(api, path, confwrite, set_permissive=False, **kwargs)
|
|
|
|
|
|
@autocheck
|
|
def autocheck_value_slave(api, path, confread, confwrite, **kwargs):
|
|
isslave = api.unrestraint.option(path).option.isslave()
|
|
if not isslave:
|
|
#FIXME raises(APIError, "api.config(confread).option(path).value.len()")
|
|
return
|
|
if kwargs.get('propertyerror', False):
|
|
raises(PropertiesOptionError, "api.option(path).value.len()")
|
|
raises(PropertiesOptionError, "api.forcepermissive.option(path).value.len()")
|
|
return
|
|
|
|
multi = api.unrestraint.option(path).option.ismulti()
|
|
submulti_ = api.forcepermissive.option(path).option.issubmulti()
|
|
empty_value = kwargs['default']
|
|
|
|
def do(conf):
|
|
if not kwargs.get('permissive', False):
|
|
length = api.config(conf).option(path).value.len()
|
|
assert api.forcepermissive.config(conf).option(path).value.len() == length
|
|
else:
|
|
raises(PropertiesOptionError, "api.config(conf).option(path).value.len()")
|
|
length = api.forcepermissive.config(conf).option(path).value.len()
|
|
assert length == 2
|
|
do(confread)
|
|
if confread != confwrite:
|
|
do(confwrite)
|
|
|
|
length = 2
|
|
value = []
|
|
for idx in range(length):
|
|
value.append(api.forcepermissive.option(path, idx).value.get())
|
|
|
|
assert value == [empty_value, empty_value]
|
|
# cannot access to a slave with index too high
|
|
if submulti_ is False:
|
|
value = LIST_FIRST_VALUE[0]
|
|
else:
|
|
value = SUBLIST_FIRST_VALUE[0]
|
|
|
|
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',))")
|
|
|
|
|
|
@autocheck
|
|
def autocheck_reset_value(api, path, confread, confwrite, **kwargs):
|
|
# check if is a multi, a master or a slave
|
|
multi = api.unrestraint.option(path).option.ismulti()
|
|
submulti_ = api.unrestraint.option(path).option.issubmulti()
|
|
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
|
|
empty_value = kwargs['default']
|
|
_set_value(api, path, confwrite, **kwargs)
|
|
|
|
# reset value without permissive
|
|
if not isslave:
|
|
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
|
api.config(confwrite).option(path).value.reset()
|
|
else:
|
|
raises(PropertiesOptionError, "api.config(confwrite).option(path).value.reset()")
|
|
else:
|
|
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
|
api.config(confwrite).option(path, 0).value.reset()
|
|
else:
|
|
raises(PropertiesOptionError, "api.config(confwrite).option(path, 0).value.reset()")
|
|
|
|
# get value after reset value without permissive
|
|
def do(conf):
|
|
if isslave:
|
|
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
|
assert api.config(conf).option(path, 0).value.get() == empty_value
|
|
assert api.config(conf).option(path, 1).value.get() == second_value[1]
|
|
elif kwargs.get('permissive', False):
|
|
raises(PropertiesOptionError, "api.config(conf).option(path, 0).value.get()")
|
|
assert api.forcepermissive.config(conf).option(path, 0).value.get() == empty_value
|
|
assert api.forcepermissive.config(conf).option(path, 1).value.get() == second_value[1]
|
|
else:
|
|
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
|
assert api.config(conf).option(path).value.get() == empty_value
|
|
elif kwargs.get('permissive', False):
|
|
raises(PropertiesOptionError, "api.config(conf).option(path).value.get()")
|
|
assert api.forcepermissive.config(conf).option(path).value.get() == first_value
|
|
do(confread)
|
|
if confread != confwrite:
|
|
do(confwrite)
|
|
|
|
|
|
@autocheck
|
|
def autocheck_append_value(api, path, confread, confwrite, **kwargs):
|
|
ismaster = api.unrestraint.option(path).option.ismaster()
|
|
submulti_ = api.unrestraint.option(path).option.issubmulti()
|
|
if not ismaster:
|
|
return
|
|
|
|
if not kwargs.get('propertyerror', False):
|
|
master_value = api.forcepermissive.config(confread).option(path).value.get()
|
|
len_value = len(master_value)
|
|
master_value.append(undefined)
|
|
assert len(api.forcepermissive.config(confread).option(path).value.get()) == len_value
|
|
api.forcepermissive.config(confwrite).option(path).value.set(master_value)
|
|
new_master_value = api.forcepermissive.config(confread).option(path).value.get()
|
|
len_new = len(new_master_value)
|
|
assert len_value + 1 == len_new
|
|
assert new_master_value[-1] == kwargs['default_multi']
|
|
slave_path = path.rsplit('.', 1)[0] + '.third'
|
|
for idx in range(len_new):
|
|
assert api.forcepermissive.config(confread).option(slave_path, idx).value.get() == kwargs['default_multi']
|
|
#
|
|
if not submulti_:
|
|
value = 'value'
|
|
else:
|
|
value = ['value']
|
|
master_value.append(value)
|
|
assert len(api.forcepermissive.config(confread).option(path).value.get()) == len(new_master_value)
|
|
api.forcepermissive.config(confwrite).option(path).value.set(master_value)
|
|
assert api.forcepermissive.config(confread).option(path).value.get()[-1] == value
|
|
|
|
|
|
@autocheck
|
|
def autocheck_pop_value(api, path, confread, confwrite, **kwargs):
|
|
ismaster = api.unrestraint.option(path).option.ismaster()
|
|
submulti_ = api.unrestraint.option(path).option.issubmulti()
|
|
if not ismaster:
|
|
return
|
|
|
|
if not kwargs.get('propertyerror', False):
|
|
if not submulti_:
|
|
values = ['value1', 'value2', 'value3', 'value4']
|
|
slave = 'slave'
|
|
else:
|
|
values = [['value1'], ['value2'], ['value3'], ['value4']]
|
|
slave = ['slave']
|
|
slaves = [kwargs['default_multi'], slave, kwargs['default_multi'], kwargs['default_multi']]
|
|
a_slave = path.rsplit('.', 1)[0] + '.third'
|
|
api.forcepermissive.config(confwrite).option(path).value.set(values)
|
|
api.forcepermissive.config(confwrite).option(a_slave, 1).value.set(slave)
|
|
api.forcepermissive.config(confread).option(a_slave, 0).value.get() == kwargs['default_multi']
|
|
assert api.forcepermissive.config(confread).option(a_slave, 0).owner.isdefault() is True
|
|
api.forcepermissive.config(confread).option(a_slave, 1).value.get() == slave
|
|
assert api.forcepermissive.config(confread).option(a_slave, 1).owner.isdefault() is False
|
|
api.forcepermissive.config(confread).option(a_slave, 2).value.get() == kwargs['default_multi']
|
|
assert api.forcepermissive.config(confread).option(a_slave, 2).owner.isdefault() is True
|
|
api.forcepermissive.config(confread).option(a_slave, 3).value.get() == kwargs['default_multi']
|
|
assert api.forcepermissive.config(confread).option(a_slave, 3).owner.isdefault() is True
|
|
#
|
|
api.forcepermissive.config(confwrite).option(path).value.pop(3)
|
|
api.forcepermissive.config(confread).option(a_slave, 0).value.get() == kwargs['default_multi']
|
|
assert api.forcepermissive.config(confread).option(a_slave, 0).owner.isdefault() is True
|
|
api.forcepermissive.config(confread).option(a_slave, 1).value.get() == slave
|
|
assert api.forcepermissive.config(confread).option(a_slave, 1).owner.isdefault() is False
|
|
api.forcepermissive.config(confread).option(a_slave, 2).value.get() == kwargs['default_multi']
|
|
assert api.forcepermissive.config(confread).option(a_slave, 2).owner.isdefault() is True
|
|
#
|
|
api.forcepermissive.config(confwrite).option(path).value.pop(0)
|
|
api.forcepermissive.config(confread).option(a_slave, 0).value.get() == slave
|
|
assert api.forcepermissive.config(confread).option(a_slave, 0).owner.isdefault() is False
|
|
api.forcepermissive.config(confread).option(a_slave, 1).value.get() == kwargs['default_multi']
|
|
assert api.forcepermissive.config(confread).option(a_slave, 1).owner.isdefault() is True
|
|
#
|
|
api.forcepermissive.config(confwrite).option(path).value.pop(0)
|
|
api.forcepermissive.config(confread).option(a_slave, 0).value.get() == kwargs['default_multi']
|
|
assert api.forcepermissive.config(confread).option(a_slave, 0).owner.isdefault() is True
|
|
|
|
|
|
@autocheck
|
|
def autocheck_reset_value_permissive(api, path, confread, confwrite, **kwargs):
|
|
# check if is a multi, a master or a slave
|
|
isslave = api.unrestraint.option(path).option.isslave()
|
|
_set_value(api, path, confwrite, **kwargs)
|
|
|
|
# reset value with permissive
|
|
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
|
if not isslave:
|
|
api.forcepermissive.config(confwrite).option(path).value.reset()
|
|
else:
|
|
api.forcepermissive.option(path, 1).value.reset()
|
|
elif kwargs.get('permissive', False):
|
|
if not isslave:
|
|
api.forcepermissive.config(confwrite).option(path).value.reset()
|
|
else:
|
|
api.forcepermissive.option(path, 1).value.reset()
|
|
else:
|
|
if not isslave:
|
|
raises(PropertiesOptionError, "api.forcepermissive.config(confwrite).option(path).value.reset()")
|
|
else:
|
|
raises(PropertiesOptionError, "api.forcepermissive.option(path, 1).value.reset()")
|
|
_autocheck_default_value(api, path, confread, **kwargs)
|
|
if confread != confwrite:
|
|
_autocheck_default_value(api, path, confwrite, **kwargs)
|
|
|
|
|
|
@autocheck
|
|
def autocheck_display(api, path, confread, confwrite, **kwargs):
|
|
"""re set value
|
|
"""
|
|
if kwargs['callback']:
|
|
return
|
|
make_dict = kwargs['make_dict']
|
|
make_dict_value = kwargs['make_dict_value']
|
|
#print(make_dict)
|
|
#print(make_dict_value)
|
|
#print(api.config(confread).config.make_dict())
|
|
assert api.config(confread).config.make_dict() == make_dict
|
|
if confread != confwrite:
|
|
assert(api.config(confwrite).config.make_dict()) == make_dict
|
|
_set_value(api, path, confwrite, **kwargs)
|
|
#print(api.config(confread).config.make_dict())
|
|
assert api.config(confread).config.make_dict() == make_dict_value
|
|
if confread != confwrite:
|
|
assert(api.config(confwrite).config.make_dict()) == make_dict_value
|
|
|
|
|
|
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, frozenset(properties)
|
|
|
|
|
|
def _check_default_properties(api, path, conf, 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.config(conf).option(path).property.get()) == set(props_permissive)
|
|
assert set(api.config(conf).forcepermissive.option(path).property.get()) == set(props_permissive)
|
|
elif not kwargs.get('propertyerror', False):
|
|
raises(PropertiesOptionError, "api.config(conf).option(path).property.get()")
|
|
assert set(api.forcepermissive.config(conf).option(path).property.get()) == set(props)
|
|
else:
|
|
raises(PropertiesOptionError, "api.config(conf).option(path).property.get()")
|
|
raises(PropertiesOptionError, "api.forcepermissive.config(conf).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.config(conf).option(path, 0).property.get()) == set(props_permissive)
|
|
assert set(api.config(conf).option(path, 1).property.get()) == set(props_permissive)
|
|
elif not kwargs.get('propertyerror', False):
|
|
raises(PropertiesOptionError, "api.config(conf).option(path).property.get()")
|
|
assert set(api.forcepermissive.config(conf).option(path, 0).property.get()) == set(props)
|
|
assert set(api.forcepermissive.config(conf).option(path, 1).property.get()) == set(props)
|
|
else:
|
|
raises(PropertiesOptionError, "api.config(conf).option(path, 0).property.get()")
|
|
raises(APIError, "api.unrestraint.option(path, 0).property.get()")
|
|
|
|
|
|
@autocheck
|
|
def autocheck_property(api, path, confread, confwrite, **kwargs):
|
|
"""get property from path
|
|
"""
|
|
# 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)
|
|
|
|
_check_default_properties(api, path, confread, kwargs, default_props, default_props)
|
|
_check_default_properties(api, path, confwrite, kwargs, default_props, default_props)
|
|
|
|
# set properties without permissive
|
|
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
|
api.config(confwrite).option(path).property.set(properties)
|
|
else:
|
|
raises(PropertiesOptionError, "api.config(confwrite).option(path).property.set(properties)")
|
|
|
|
_check_default_properties(api, path, confread, kwargs, properties, default_props)
|
|
if confread != confwrite:
|
|
_check_default_properties(api, path, confwrite, kwargs, properties, default_props)
|
|
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
|
raises(ConfigError, "api.config(confread).option(path).property.set(properties)")
|
|
|
|
|
|
|
|
|
|
def _property_permissive(api, path, confread, confwrite, **kwargs):
|
|
# 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, confwrite, kwargs, default_props, default_props)
|
|
if confwrite != confread:
|
|
_check_default_properties(api, path, confread, kwargs, default_props, default_props)
|
|
|
|
# set properties with permissive
|
|
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
|
api.config(confwrite).option(path).property.set(properties)
|
|
api.forcepermissive.config(confwrite).option(path).property.set(properties)
|
|
elif not kwargs.get('propertyerror', False):
|
|
raises(PropertiesOptionError, "api.config(confwrite).option(path).property.set(properties)")
|
|
api.forcepermissive.config(confwrite).option(path).property.set(properties)
|
|
else:
|
|
raises(PropertiesOptionError, "api.config(confwrite).option(path).property.set(properties)")
|
|
raises(PropertiesOptionError, "api.forcepermissive.config(confwrite).option(path).property.set(properties)")
|
|
|
|
_check_default_properties(api, path, confwrite, kwargs, properties, properties)
|
|
if confwrite != confread:
|
|
_check_default_properties(api, path, confread, kwargs, properties, properties)
|
|
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
|
raises(ConfigError, "api.config(confread).option(path).property.set(properties)")
|
|
|
|
|
|
@autocheck
|
|
def autocheck_property_permissive(api, path, confread, confwrite, **kwargs):
|
|
_property_permissive(api, path, confread, confwrite, **kwargs)
|
|
|
|
|
|
@autocheck
|
|
def autocheck_reset_property(api, path, confread, confwrite, **kwargs):
|
|
"""check properties after set with permissive
|
|
"""
|
|
# 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, confread, confwrite, **kwargs)
|
|
|
|
# reset properties without permissive
|
|
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
|
api.config(confwrite).option(path).property.reset()
|
|
else:
|
|
raises(PropertiesOptionError, "api.config(confwrite).option(path).property.reset()")
|
|
|
|
_check_default_properties(api, path, confread, kwargs, default_props, properties)
|
|
if confread != confwrite:
|
|
_check_default_properties(api, path, confwrite, kwargs, default_props, properties)
|
|
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
|
raises(ConfigError, "api.config(confread).option(path).property.reset()")
|
|
|
|
|
|
@autocheck
|
|
def autocheck_reset_property_permissive(api, path, confread, confwrite, **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, confread, confwrite, **kwargs)
|
|
|
|
# reset properties with permissive
|
|
raises(APIError, "api.unrestraint.option(path).property.set(properties)")
|
|
raises(APIError, "api.unrestraint.option(path).property.reset()")
|
|
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
|
api.forcepermissive.option(path).property.set(properties)
|
|
api.forcepermissive.option(path).property.reset()
|
|
elif kwargs.get('permissive', False):
|
|
api.forcepermissive.option(path).property.reset()
|
|
|
|
_check_default_properties(api, path, confwrite, kwargs, default_props, default_props)
|
|
if confread != confwrite:
|
|
_check_default_properties(api, path, confread, kwargs, default_props, default_props)
|
|
|
|
|
|
@autocheck
|
|
def autocheck_context_owner(api, path, confread, confwrite, **kwargs):
|
|
owner = api.owner.get()
|
|
assert owner == OWNER
|
|
|
|
|
|
def _check_owner(api, path, conf, 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.config(conf).option(path).owner.get() == owner
|
|
assert api.forcepermissive.config(conf).option(path).owner.get() == owner
|
|
elif not kwargs.get('propertyerror', False):
|
|
raises(PropertiesOptionError, "api.config(conf).option(path).owner.get()")
|
|
assert api.forcepermissive.config(conf).option(path).owner.get() == permissive_owner
|
|
else:
|
|
raises(PropertiesOptionError, "api.config(conf).option(path).owner.get()")
|
|
raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(path).owner.get()")
|
|
else:
|
|
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
|
assert api.config(conf).option(path, 0).owner.get() == 'default'
|
|
assert api.forcepermissive.config(conf).option(path, 0).owner.get() == 'default'
|
|
assert api.config(conf).option(path, 1).owner.get() == owner
|
|
assert api.forcepermissive.config(conf).option(path, 1).owner.get() == owner
|
|
elif not kwargs.get('propertyerror', False):
|
|
raises(PropertiesOptionError, "api.config(conf).option(path, 0).owner.get()")
|
|
raises(PropertiesOptionError, "api.config(conf).option(path, 1).owner.get()")
|
|
assert api.forcepermissive.config(conf).option(path, 0).owner.get() == 'default'
|
|
assert api.forcepermissive.config(conf).option(path, 1).owner.get() == permissive_owner
|
|
else:
|
|
raises(PropertiesOptionError, "api.config(conf).option(path, 0).owner.get()")
|
|
raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(path, 0).owner.get()")
|
|
|
|
|
|
@autocheck
|
|
def autocheck_owner_with_value(api, path, confread, confwrite, **kwargs):
|
|
"""value is now changed, check owner in this case
|
|
"""
|
|
_set_value(api, path, confwrite, **kwargs)
|
|
_check_owner(api, path, confwrite, kwargs, OWNER, OWNER)
|
|
if confread != confwrite:
|
|
_check_owner(api, path, confread, kwargs, owners.meta, owners.meta)
|
|
|
|
|
|
@autocheck
|
|
def autocheck_default_owner_with_value(api, path, confread, confwrite, **kwargs):
|
|
isslave = api.unrestraint.option(path).option.isslave()
|
|
_set_value(api, path, confwrite, **kwargs)
|
|
|
|
# test if is default owner without permissive
|
|
if not isslave:
|
|
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
|
assert api.config(confwrite).option(path).owner.isdefault() is False
|
|
if confwrite != confread:
|
|
assert api.config(confread).option(path).owner.isdefault() is False
|
|
else:
|
|
raises(PropertiesOptionError, "api.config(confwrite).option(path).owner.isdefault()")
|
|
raises(PropertiesOptionError, "api.config(confread).option(path).owner.isdefault()")
|
|
else:
|
|
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
|
assert api.config(confwrite).option(path, 0).owner.isdefault() is True
|
|
assert api.config(confwrite).option(path, 1).owner.isdefault() is False
|
|
if confwrite != confread:
|
|
assert api.config(confread).option(path, 0).owner.isdefault() is True
|
|
assert api.config(confread).option(path, 1).owner.isdefault() is False
|
|
else:
|
|
raises(PropertiesOptionError, "api.config(confwrite).option(path, 0).owner.isdefault()")
|
|
raises(PropertiesOptionError, "api.config(confread).option(path, 0).owner.isdefault()")
|
|
|
|
|
|
@autocheck
|
|
def autocheck_default_owner_with_value_permissive(api, path, confread, confwrite, **kwargs):
|
|
# check if is a isslave
|
|
isslave = api.unrestraint.option(path).option.isslave()
|
|
|
|
_set_value(api, path, confwrite, **kwargs)
|
|
|
|
def do(conf):
|
|
# test if is default owner with permissive
|
|
if not kwargs.get('propertyerror', False):
|
|
if not isslave:
|
|
assert api.forcepermissive.config(conf).option(path).owner.isdefault() is False
|
|
else:
|
|
assert api.forcepermissive.config(conf).option(path, 0).owner.isdefault() is True
|
|
assert api.forcepermissive.config(conf).option(path, 1).owner.isdefault() is False
|
|
else:
|
|
raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(path).owner.isdefault()")
|
|
do(confwrite)
|
|
if confwrite != confread:
|
|
do(confread)
|
|
|
|
|
|
@autocheck
|
|
def autocheck_set_owner_no_value(api, path, confread, confwrite, **kwargs):
|
|
isslave = api.unrestraint.option(path).option.isslave()
|
|
if not kwargs.get('propertyerror', False):
|
|
if not isslave:
|
|
raises(ConfigError, "api.forcepermissive.config(confwrite).option(path).owner.set('new_user')")
|
|
else:
|
|
raises(ConfigError, "api.forcepermissive.option(path, 1).owner.set('new_user')")
|
|
|
|
|
|
@autocheck
|
|
def autocheck_set_owner(api, path, confread, confwrite, **kwargs):
|
|
# test set owner without permissive
|
|
isslave = api.unrestraint.option(path).option.isslave()
|
|
|
|
_set_value(api, path, confwrite, **kwargs)
|
|
|
|
# set owner without permissive
|
|
if not isslave:
|
|
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
|
api.config(confwrite).option(path).owner.set('new_user')
|
|
raises(ConfigError, "api.config(confwrite).option(path).owner.set('default')")
|
|
raises(ConfigError, "api.config(confwrite).option(path).owner.set('forced')")
|
|
raises(ConfigError, "api.config(confwrite).option(path).owner.set('meta')")
|
|
else:
|
|
raises(PropertiesOptionError, "api.config(confwrite).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:
|
|
raises(PropertiesOptionError, "api.option(path, 1).owner.set('new_user')")
|
|
|
|
_check_owner(api, path, confwrite, kwargs, owners.new_user, OWNER)
|
|
if confwrite != confread:
|
|
_check_owner(api, path, confread, kwargs, owners.meta, owners.meta)
|
|
|
|
|
|
@autocheck
|
|
def autocheck_set_owner_permissive(api, path, confread, confwrite, **kwargs):
|
|
isslave = api.unrestraint.option(path).option.isslave()
|
|
|
|
_set_value(api, path, confwrite, **kwargs)
|
|
|
|
# set owner with permissive
|
|
if not kwargs.get('propertyerror', False):
|
|
if not isslave:
|
|
api.forcepermissive.config(confwrite).option(path).owner.set('new_user1')
|
|
else:
|
|
api.forcepermissive.option(path, 1).owner.set('new_user1')
|
|
else:
|
|
if not isslave:
|
|
raises(PropertiesOptionError,
|
|
"api.forcepermissive.config(confwrite).option(path).owner.set('new_user1')")
|
|
else:
|
|
raises(PropertiesOptionError,
|
|
"api.forcepermissive.option(path, 1).owner.set('new_user1')")
|
|
|
|
_check_owner(api, path, confwrite, kwargs, 'new_user1', 'new_user1')
|
|
if confwrite != confread:
|
|
_check_owner(api, path, confread, kwargs, owners.meta, owners.meta)
|
|
|
|
|
|
@autocheck
|
|
def autocheck_option(api, path, confread, confwrite, **kwargs):
|
|
expected_name = path.split('.')[-1]
|
|
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
|
current_name = api.option(path).option.getname()
|
|
assert current_name == api.forcepermissive.option(path).option.getname()
|
|
assert current_name == api.unrestraint.option(path).option.getname()
|
|
doc = api.option(path).option.getdoc()
|
|
assert doc == api.forcepermissive.option(path).option.getdoc()
|
|
assert doc == api.unrestraint.option(path).option.getdoc()
|
|
elif not kwargs.get('propertyerror', False):
|
|
raises(PropertiesOptionError, "api.option(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()
|
|
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)
|
|
|
|
|
|
@autocheck
|
|
def autocheck_permissive(api, path, confread, confwrite, **kwargs):
|
|
"""test permissive for hidden and disabled value
|
|
"""
|
|
# no permissive before
|
|
assert api.unrestraint.config(confread).option(path).permissive.get() == frozenset()
|
|
if kwargs.get('permissive_od', False):
|
|
assert api.unrestraint.config(confread).option(path.rsplit('.', 1)[0]).permissive.get() == frozenset()
|
|
|
|
# cannot access to hidden value without forcepermissive
|
|
# and to disabled value (with forcepermissive too)
|
|
#
|
|
# with meta confread == confwrite
|
|
_autocheck_default_value(api, path, confread, **kwargs)
|
|
|
|
# set permissive
|
|
api.unrestraint.config(confwrite).option(path).permissive.set(frozenset(['disabled']))
|
|
callback = kwargs['callback']
|
|
if callback:
|
|
if path.endswith('val1') or path.endswith('val2'):
|
|
call_path = path[:-4] + 'call' + path[-4:]
|
|
else:
|
|
call_path = path + 'call'
|
|
api.unrestraint.config(confwrite).option(call_path).permissive.set(frozenset(['disabled']))
|
|
|
|
# have permissive
|
|
assert api.unrestraint.config(confwrite).option(path).permissive.get() == frozenset(['disabled'])
|
|
if confwrite != confread:
|
|
assert api.unrestraint.config(confread).option(path).permissive.get() == frozenset(['disabled'])
|
|
|
|
# can access to disabled value
|
|
ckwargs = copy(kwargs)
|
|
ckwargs['propertyerror'] = False
|
|
_autocheck_default_value(api, path, confread, **ckwargs)
|
|
|
|
api.unrestraint.config(confwrite).option(path).permissive.set(frozenset(['disabled', 'hidden']))
|
|
if kwargs['callback']:
|
|
api.unrestraint.config(confwrite).option(call_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, confread, **ckwargs)
|
|
if confread != confwrite:
|
|
_autocheck_default_value(api, path, confwrite, **ckwargs)
|
|
|
|
if ckwargs.get('permissive_od', False):
|
|
# set permissive to OptionDescription
|
|
api.unrestraint.config(confwrite).option(path.rsplit('.', 1)[0]).permissive.set(frozenset(['disabled',
|
|
'hidden']))
|
|
ckwargs['permissive'] = False
|
|
_autocheck_default_value(api, path, confread, **ckwargs)
|
|
if confread != confwrite:
|
|
_autocheck_default_value(api, path, confwrite, **ckwargs)
|
|
|
|
# only hidden
|
|
api.unrestraint.config(confwrite).option(path).permissive.set(frozenset(['hidden']))
|
|
if callback:
|
|
api.unrestraint.config(confwrite).option(call_path).permissive.set(frozenset(['hidden']))
|
|
if ckwargs.get('permissive_od', False):
|
|
_autocheck_default_value(api, path, confread, **ckwargs)
|
|
if confread != confwrite:
|
|
_autocheck_default_value(api, path, confwrite, **ckwargs)
|
|
api.unrestraint.config(confwrite).option(path.rsplit('.', 1)[0]).permissive.set(frozenset(['hidden']))
|
|
ckwargs = copy(kwargs)
|
|
ckwargs['permissive'] = False
|
|
_autocheck_default_value(api, path, confread, **ckwargs)
|
|
if confread != confwrite:
|
|
_autocheck_default_value(api, path, confwrite, **ckwargs)
|
|
|
|
# no permissive
|
|
api.unrestraint.config(confwrite).option(path).permissive.set(frozenset())
|
|
if callback:
|
|
api.unrestraint.config(confwrite).option(call_path).permissive.set(frozenset())
|
|
if ckwargs.get('permissive_od', False):
|
|
_autocheck_default_value(api, path, confread, **ckwargs)
|
|
if confread != confwrite:
|
|
_autocheck_default_value(api, path, confwrite, **ckwargs)
|
|
api.unrestraint.config(confwrite).option(path.rsplit('.', 1)[0]).permissive.set(frozenset())
|
|
_autocheck_default_value(api, path, confread, **kwargs)
|
|
if confread != confwrite:
|
|
_autocheck_default_value(api, path, confwrite, **kwargs)
|
|
|
|
|
|
@autocheck
|
|
def autocheck_option_get(api, path, confread, confwrite, **kwargs):
|
|
if '.' in path:
|
|
name = path.rsplit('.', 1)[1]
|
|
else:
|
|
name = path
|
|
assert api.option.get(path).impl_getname() == name
|
|
|
|
|
|
@autocheck
|
|
def autocheck_find(api, path, confread, confwrite, **kwargs):
|
|
def _getoption(opt):
|
|
if opt.impl_is_dynsymlinkoption():
|
|
opt = opt.impl_getopt()
|
|
return opt
|
|
|
|
def _getoptions(opts):
|
|
nopts = []
|
|
for opt in opts:
|
|
nopts.append(_getoption(opt))
|
|
return nopts
|
|
|
|
if '.' in path:
|
|
name = path.rsplit('.', 1)[1]
|
|
else:
|
|
name = path
|
|
option = _getoption(api.option.get(path))
|
|
|
|
def do(conf):
|
|
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
|
|
assert option == _getoption(api.config(conf).option.find_first(name))
|
|
assert option == _getoption(api.forcepermissive.config(conf).option.find_first(name))
|
|
elif kwargs.get('permissive', False):
|
|
raises(AttributeError, "api.config(conf).option.find_first(name)")
|
|
assert option == _getoption(api.forcepermissive.config(conf).option.find_first(name))
|
|
else:
|
|
raises(AttributeError, "api.config(conf).option.find_first(name)")
|
|
raises(AttributeError, "api.forcepermissive.config(conf).option.find_first(name)")
|
|
assert option == _getoption(api.unrestraint.config(conf).option.find_first(name))
|
|
assert [option] == _getoptions(api.unrestraint.config(conf).option.find(name))
|
|
assert path == api.unrestraint.config(conf).option.find_first(name, 'path')
|
|
assert [path] == api.unrestraint.config(conf).option.find(name, 'path')
|
|
do(confread)
|
|
if confread != confwrite:
|
|
do(confwrite)
|
|
|
|
|
|
def check_all(cfg, paths, path, meta, multi, default, default_multi, require, consistency, callback, weakrefs, **kwargs):
|
|
def _build_make_dict():
|
|
dico = {}
|
|
dico_value = {}
|
|
if multi is False:
|
|
value = FIRST_VALUE
|
|
elif multi is True:
|
|
value = LIST_FIRST_VALUE
|
|
else:
|
|
value = SUBLIST_FIRST_VALUE
|
|
if not default or multi is submulti:
|
|
if not multi:
|
|
default_value = None
|
|
else:
|
|
default_value = []
|
|
else:
|
|
default_value = value
|
|
kwargs['default'] = default_value
|
|
if '.' in path:
|
|
if paths.get(path, {}) is None:
|
|
isslave = False
|
|
else:
|
|
isslave = paths.get(path, {}).get(path.rsplit('.', 1)[0], {}).get('master') is True and not path.endswith('.first')
|
|
if isslave and not multi is submulti:
|
|
kwargs['default'] = None
|
|
|
|
is_dyn = False
|
|
is_master = False
|
|
dyns = []
|
|
has_value = False
|
|
for cpath, options in paths.items():
|
|
if options is None:
|
|
break
|
|
if '.' in cpath:
|
|
dirname, name = cpath.split('.')[-2:]
|
|
else:
|
|
dirname = ''
|
|
name = cpath
|
|
if options.get(dirname, {}).get('hidden'):
|
|
continue
|
|
if options.get(dirname, {}).get('dyn'):
|
|
is_dyn = True
|
|
if options.get(dirname, {}).get('master'):
|
|
is_master = True
|
|
no_propertieserror = not options.get(name, {}).get('disabled') and not options.get(name, {}).get('hidden')
|
|
allow_req = require and req
|
|
if is_dyn:
|
|
dyns.append(no_propertieserror or allow_req)
|
|
elif no_propertieserror or allow_req:
|
|
dico[cpath] = default_value
|
|
if path == cpath:
|
|
dico_value[cpath] = value
|
|
else:
|
|
dico_value[cpath] = default_value
|
|
|
|
has_value = True
|
|
if is_dyn:
|
|
idx = 0
|
|
for cpath in list(paths.keys())[len(dyns):]:
|
|
if dyns[idx]:
|
|
dico[cpath] = default_value
|
|
if path == cpath:
|
|
dico_value[cpath] = value
|
|
else:
|
|
dico_value[cpath] = default_value
|
|
idx += 1
|
|
if idx == len(dyns):
|
|
idx = 0
|
|
if require:
|
|
if not req:
|
|
dico['extraoptrequire'] = None
|
|
dico_value['extraoptrequire'] = None
|
|
else:
|
|
dico['extraoptrequire'] = 'value'
|
|
dico_value['extraoptrequire'] = 'value'
|
|
if consistency and has_value:
|
|
cpath = list(dico.keys())[0]
|
|
if "." in cpath:
|
|
cpath = cpath.rsplit('.', 1)[0] + '.'
|
|
else:
|
|
cpath = ''
|
|
if multi:
|
|
value = []
|
|
else:
|
|
value = None
|
|
if is_dyn:
|
|
dico[cpath + 'extraoptconsistencyval1'] = value
|
|
dico[cpath[:-2] + '2.' + 'extraoptconsistencyval2'] = value
|
|
dico_value[cpath + 'extraoptconsistencyval1'] = value
|
|
dico_value[cpath[:-2] + '2.' + 'extraoptconsistencyval2'] = value
|
|
else:
|
|
dico[cpath + 'extraoptconsistency'] = value
|
|
dico_value[cpath + 'extraoptconsistency'] = value
|
|
if is_master:
|
|
for cpath in list(paths.keys())[len(dyns):]:
|
|
if cpath.endswith('.first'):
|
|
second_path = cpath.rsplit('.', 1)[0] + '.second'
|
|
third_path = cpath.rsplit('.', 1)[0] + '.third'
|
|
cons_path = cpath.rsplit('.', 1)[0] + '.extraoptconsistency'
|
|
#
|
|
if default_multi:
|
|
if multi is not submulti:
|
|
dvalue = SECOND_VALUE
|
|
else:
|
|
dvalue = LIST_SECOND_VALUE
|
|
else:
|
|
dvalue = []
|
|
if dvalue == [] and multi is not submulti:
|
|
dvalue = None
|
|
#
|
|
kwargs['default_multi'] = dvalue
|
|
if isslave:
|
|
kwargs['default'] = dvalue
|
|
len_master = len(dico[cpath])
|
|
if second_path in dico:
|
|
dico[second_path] = [dvalue] * len_master
|
|
if third_path in dico:
|
|
dico[third_path] = [dvalue] * len_master
|
|
if cons_path in dico:
|
|
dico[cons_path] = [dvalue] * len_master
|
|
#
|
|
len_master = len(dico_value[cpath])
|
|
if second_path in dico_value:
|
|
dico_value[second_path] = [dvalue] * len_master
|
|
if third_path in dico_value:
|
|
dico_value[third_path] = [dvalue] * len_master
|
|
cons_path = cpath.rsplit('.', 1)[0] + '.extraoptconsistency'
|
|
if cons_path in dico_value:
|
|
dico_value[cons_path] = [dvalue] * len_master
|
|
break
|
|
return dico, dico_value
|
|
if DISPLAY:
|
|
text = u' {} launch tests for {}'.format(ICON, path)
|
|
if multi is True:
|
|
text += u' as a multi'
|
|
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'
|
|
if require:
|
|
text += u' with requirement'
|
|
if consistency:
|
|
text += u' with consistency'
|
|
text += u', kwargs: {}'.format(kwargs)
|
|
print(text)
|
|
if not require:
|
|
requires = [False]
|
|
else:
|
|
requires = [False, True]
|
|
confwrite = confread = None
|
|
idx = 0
|
|
for req in requires:
|
|
kwargs['make_dict'], kwargs['make_dict_value'] = _build_make_dict()
|
|
kwargs['callback'] = callback
|
|
for func in autocheck_registers:
|
|
cfg_name = 'conftest' + str(idx)
|
|
idx += 1
|
|
ncfg = cfg.duplicate(session_id=cfg_name)
|
|
if meta:
|
|
confwrite = None
|
|
confread = cfg_name
|
|
ncfg = MetaConfig([ncfg], session_id='metatest')
|
|
weakrefs.append(weakref.ref(cfg))
|
|
api = getapi(ncfg)
|
|
ckwargs = copy(kwargs)
|
|
if api.unrestraint.option(path).option.isslave():
|
|
dirname = path.rsplit('.', 1)[0]
|
|
master_path = dirname + '.first'
|
|
if multi is submulti:
|
|
value = SUBLIST_SECOND_VALUE
|
|
else:
|
|
value = LIST_SECOND_VALUE
|
|
api.option(master_path).value.set(value)
|
|
ckwargs['make_dict'][master_path] = value
|
|
ckwargs['make_dict_value'][master_path] = value
|
|
if default_multi:
|
|
if multi is not submulti:
|
|
dvalue = SECOND_VALUE
|
|
else:
|
|
dvalue = LIST_SECOND_VALUE
|
|
elif multi is submulti:
|
|
dvalue = []
|
|
else:
|
|
dvalue = None
|
|
if dirname + '.second' in ckwargs['make_dict']:
|
|
ckwargs['make_dict'][dirname + '.second'] = [dvalue] * len(value)
|
|
ckwargs['make_dict_value'][dirname + '.second'] = [dvalue] * len(value)
|
|
if path == dirname + '.second':
|
|
ckwargs['make_dict_value'][dirname + '.second'][-1] = ckwargs['make_dict_value'][master_path][-1]
|
|
if dirname + '.third' in ckwargs['make_dict']:
|
|
ckwargs['make_dict'][dirname + '.third'] = [dvalue] * len(value)
|
|
ckwargs['make_dict_value'][dirname + '.third'] = [dvalue] * len(value)
|
|
if path == dirname + '.third':
|
|
ckwargs['make_dict_value'][dirname + '.third'][-1] = ckwargs['make_dict_value'][master_path][-1]
|
|
if dirname + '.extraoptconsistency' in ckwargs['make_dict']:
|
|
ckwargs['make_dict'][dirname + '.extraoptconsistency'] = [dvalue] * len(value)
|
|
ckwargs['make_dict_value'][dirname + '.extraoptconsistency'] = [dvalue] * len(value)
|
|
|
|
#FIXME devrait etre dans la config ca ...
|
|
api.read_write()
|
|
if req:
|
|
api.option('extraoptrequire').value.set('value')
|
|
if 'permissive' in ckwargs and not 'permissive_od' in ckwargs or \
|
|
'propertyerror' in ckwargs and not 'propertyerror_od' in ckwargs:
|
|
for to_del in ['permissive', 'propertyerror', 'extra_properties']:
|
|
if to_del in ckwargs:
|
|
del ckwargs[to_del]
|
|
if DISPLAY:
|
|
print(u' {} {}'.format(ICON, func.__name__))
|
|
try:
|
|
func(api, path, confread, confwrite, **ckwargs)
|
|
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 default is True:
|
|
msg += u' with default value'
|
|
if callback is True:
|
|
msg += u' (callback)'
|
|
print(u'{}: {}'.format(msg, ckwargs))
|
|
raise err
|
|
del api
|
|
del ncfg
|
|
|
|
|
|
def check_deref(weakrefs):
|
|
"""try if all elements are dereferenced
|
|
"""
|
|
for wrf in weakrefs:
|
|
assert wrf() is None
|
|
|
|
|
|
def make_conf(options, meta, multi, default, default_multi, require, consistency, callback):
|
|
weakrefs = []
|
|
dyn = []
|
|
goptions = []
|
|
def make_option(path, option_infos, in_master, master):
|
|
option_type = 'str'
|
|
option_properties = []
|
|
option_requires = []
|
|
isslave = False
|
|
if option_infos is not None:
|
|
for prop in PROPERTIES:
|
|
if option_infos.get(prop, False) is True:
|
|
if not require:
|
|
option_properties.append(prop)
|
|
else:
|
|
option_requires.append({'option': goptions[0], 'expected': None,
|
|
'action': prop})
|
|
isslave = option_infos.get('slave', False)
|
|
args = [path, "{}'s option".format(path)]
|
|
kwargs = {}
|
|
call_kwargs = {}
|
|
if option_properties != []:
|
|
kwargs['properties'] = tuple(option_properties)
|
|
if callback:
|
|
call_kwargs['properties'] = tuple(option_properties)
|
|
if option_requires != []:
|
|
if callback:
|
|
call_kwargs['requires'] = option_requires
|
|
else:
|
|
kwargs['requires'] = option_requires
|
|
if multi and path is not 'extraoptrequire':
|
|
kwargs['multi'] = multi
|
|
if callback:
|
|
call_kwargs['multi'] = multi
|
|
if ((not in_master or master) and default) and path is not 'extraoptrequire' and not path.endswith('extraoptconsistency'):
|
|
if multi is False:
|
|
value = FIRST_VALUE
|
|
elif multi is True:
|
|
value = LIST_FIRST_VALUE
|
|
else:
|
|
value = SUBLIST_EMPTY_VALUE
|
|
if callback:
|
|
kwargs['callback'] = return_str
|
|
call_kwargs['default'] = value
|
|
else:
|
|
kwargs['default'] = value
|
|
elif callback:
|
|
return None, None
|
|
if default_multi and path is not 'extraoptrequire':
|
|
if multi is not submulti:
|
|
value = SECOND_VALUE
|
|
else:
|
|
value = LIST_SECOND_VALUE
|
|
kwargs['default_multi'] = value
|
|
|
|
tiramisu_option = OPTIONS_TYPE[option_type]['option']
|
|
if callback:
|
|
largs = [path + 'call', "{}'s callback option".format(path)]
|
|
objcall = tiramisu_option(*largs, **call_kwargs)
|
|
kwargs['callback_params'] = {'': ((objcall, False),)}
|
|
else:
|
|
objcall = None
|
|
obj = tiramisu_option(*args, **kwargs)
|
|
if not 'extraopt' in path and consistency:
|
|
if require:
|
|
gopt = goptions[1]
|
|
else:
|
|
gopt = goptions[0]
|
|
obj.impl_add_consistency('not_equal', gopt, warnings_only=True)
|
|
return obj, objcall
|
|
|
|
def make_optiondescriptions(path, collected):
|
|
infos = collected.get('properties', {})
|
|
properties = []
|
|
kwargs = {}
|
|
optiondescription = OptionDescription
|
|
|
|
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
|
|
dyn.append(path)
|
|
options = []
|
|
if 'options' in collected:
|
|
options.extend(collected['options'])
|
|
for key, values in collected.items():
|
|
if key in ['options', 'properties']:
|
|
continue
|
|
option = make_optiondescriptions(key, values)
|
|
if option is None:
|
|
return
|
|
options.append(option)
|
|
if properties != []:
|
|
kwargs['properties'] = tuple(properties)
|
|
obj = optiondescription(path, "{}'s optiondescription".format(path), options, **kwargs)
|
|
weakrefs.append(weakref.ref(obj))
|
|
return obj
|
|
|
|
collect_options = {}
|
|
if require or consistency:
|
|
noptions = OrderedDict()
|
|
if require:
|
|
noptions['extraoptrequire'] = {}
|
|
if consistency:
|
|
subpath = list(options.keys())[0]
|
|
if '.' in subpath:
|
|
subpath = subpath.rsplit('.', 1)[0] + '.'
|
|
else:
|
|
subpath = ''
|
|
noptions[subpath + 'extraoptconsistency'] = {}
|
|
noptions.update(options)
|
|
else:
|
|
noptions = options
|
|
|
|
for path, option in noptions.items():
|
|
if option is None:
|
|
continue
|
|
local_collect_options = collect_options
|
|
for optiondescription in path.split('.')[:-1]:
|
|
local_collect_options.setdefault(optiondescription, {'properties': {}})
|
|
local_collect_options = local_collect_options[optiondescription]
|
|
local_collect_options['properties'].update(option.get(optiondescription, {}))
|
|
option_name = path.split('.')[-1]
|
|
if '.' in path:
|
|
name_od = path.rsplit('.', 1)[0]
|
|
else:
|
|
name_od = ''
|
|
in_master = collect_options.get(name_od, {}).get('properties', {}).get('master')
|
|
master = in_master and path.endswith('first')
|
|
obj, objcall = make_option(option_name, option.get(option_name), in_master, master)
|
|
if obj is None:
|
|
return None, None, None
|
|
weakrefs.append(weakref.ref(obj))
|
|
if callback:
|
|
weakrefs.append(weakref.ref(objcall))
|
|
if '.' in path:
|
|
if master:
|
|
local_collect_options.setdefault('options', []).insert(0, obj)
|
|
else:
|
|
local_collect_options.setdefault('options', []).append(obj)
|
|
else:
|
|
local_collect_options.setdefault('options', []).append(obj)
|
|
goptions.append(obj)
|
|
if callback:
|
|
local_collect_options.setdefault('options', []).append(objcall)
|
|
goptions.append(objcall)
|
|
|
|
rootod = make_optiondescriptions('root', collect_options)
|
|
if rootod is None:
|
|
return None, None, None
|
|
cfg = Config(rootod, session_id='conftest')
|
|
weakrefs.append(weakref.ref(cfg))
|
|
del goptions
|
|
return cfg, weakrefs, dyn
|
|
|
|
|
|
DICT_PATHS = [
|
|
#test a config without optiondescription
|
|
OrderedDict([('first', {}),
|
|
('second', {'second': {'disabled': True}}),
|
|
('third', {'third': {'hidden': True}})
|
|
]),
|
|
#test a config with an optiondescription
|
|
OrderedDict([('subod.first', {}),
|
|
('subod.second', {'second': {'disabled': True}}),
|
|
('subod.third', {'third': {'hidden': True}})]),
|
|
#test a config with two optiondescription
|
|
OrderedDict([('subod.subsubod.first', {}),
|
|
('subod.subsubod.second', {'second': {'disabled': True}}),
|
|
('subod.subsubod.third', {'third': {'hidden': True}})]),
|
|
#test a config with mix of different optiondescription
|
|
OrderedDict([('first', {}),
|
|
('subod.second', {'second': {'disabled': True}}),
|
|
('subod.subsubod.third', {'third': {'hidden': True}})]),
|
|
#test a config with masterslaves
|
|
OrderedDict([('odmaster.first', {'odmaster': {'master': True}}),
|
|
('odmaster.second', {'odmaster': {'master': True}, 'second': {'disabled': True, 'slave': True}}),
|
|
('odmaster.third', {'odmaster': {'master': True}, 'third': {'hidden': True, 'slave': True}})]),
|
|
#test a config with dynoption
|
|
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),
|
|
('subodval2.firstval2', None),
|
|
('subodval2.secondval2', None),
|
|
('subodval2.thirdval2', None)]),
|
|
#test a config with dynoption subdir
|
|
OrderedDict([('subod.subsubod.first', {'subsubod': {'dyn': True}}),
|
|
('subod.subsubod.second', {'subsubod': {'dyn': True}, 'second': {'disabled': True}}),
|
|
('subod.subsubod.third', {'subsubod': {'dyn': True}, 'third': {'hidden': True}}),
|
|
('subod.subsubodval1.firstval1', None),
|
|
('subod.subsubodval1.secondval1', None),
|
|
('subod.subsubodval1.thirdval1', None),
|
|
('subod.subsubodval2.firstval2', None),
|
|
('subod.subsubodval2.secondval2', None),
|
|
('subod.subsubodval2.thirdval2', None)]),
|
|
#test a config with hidden subsubod
|
|
OrderedDict([('subod.subsubod.first', {'subsubod': {'hidden': True}}),
|
|
('subod.subsubod.second', {'subsubod': {'hidden': True}}),
|
|
('subod.subsubod.third', {'subsubod': {'hidden': True}})]),
|
|
#test a config with hidden dyn subsubod
|
|
OrderedDict([('subod.subsubod.first', {'subsubod': {'dyn': True, 'hidden': True}}),
|
|
('subod.subsubod.second', {'subsubod': {'dyn': True, 'hidden': True}}),
|
|
('subod.subsubod.third', {'subsubod': {'dyn': True, 'hidden': True}}),
|
|
('subod.subsubodval1.firstval1', None),
|
|
('subod.subsubodval1.secondval1', None),
|
|
('subod.subsubodval1.thirdval1', None),
|
|
('subod.subsubodval2.firstval2', None),
|
|
('subod.subsubodval2.secondval2', None),
|
|
('subod.subsubodval2.thirdval2', None)])
|
|
]
|
|
|
|
|
|
@pytest.fixture(scope="function", params=DICT_PATHS)
|
|
def paths(request):
|
|
if DISPLAY:
|
|
print(u'\n{} {}: {}'.format(ICON, request.function.__name__, request.param))
|
|
return request.param
|
|
|
|
|
|
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')
|
|
else:
|
|
kwargs['permissive_od'] = True
|
|
if options.get('disabled', False) is True:
|
|
kwargs['propertyerror'] = True
|
|
if not od:
|
|
kwargs.setdefault('extra_properties', []).append('disabled')
|
|
else:
|
|
kwargs['propertyerror_od'] = True
|
|
|
|
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())
|
|
for meta in (False, True):
|
|
for callback in (False, True):
|
|
for consistency in (False, True):
|
|
for require in (False, True):
|
|
for default_multi in (False, True):
|
|
if callback and default_multi:
|
|
continue
|
|
for default in (False, True):
|
|
for multi in (False, True, submulti):
|
|
if multi is submulti and default:
|
|
continue
|
|
if multi is submulti and consistency:
|
|
continue
|
|
if multi is False and default_multi:
|
|
continue
|
|
cfg, weakrefs, dyn = make_conf(paths, meta, multi, default, default_multi, require, consistency, callback)
|
|
if cfg is None:
|
|
continue
|
|
if dyn:
|
|
cnt = 0
|
|
idx = 0
|
|
for index, lpath in enumerate(lpaths):
|
|
if paths[lpath]:
|
|
cnt += 1
|
|
else:
|
|
check_all(cfg, paths, lpaths[index], meta, multi, default,
|
|
default_multi, require, consistency, callback, weakrefs, **get_kwargs(lpaths[idx]))
|
|
idx += 1
|
|
if idx == cnt:
|
|
idx = 0
|
|
else:
|
|
for lpath in lpaths:
|
|
check_all(cfg, paths, lpath, meta, multi, default,
|
|
default_multi, require, consistency, callback, weakrefs, **get_kwargs(lpath))
|
|
del cfg
|
|
check_deref(weakrefs)
|
|
display_count()
|