tiramisu/test/auto/test_auto.py

1774 lines
84 KiB
Python
Raw Normal View History

"""test API
2017-10-22 09:48:08 +02: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()
from tiramisu import Config, MetaConfig, \
2017-12-04 20:05:36 +01:00
StrOption, SymLinkOption, OptionDescription, MasterSlaves, DynOptionDescription, \
getapi, submulti, undefined, owners, Params, ParamOption
2018-03-31 21:06:19 +02:00
from tiramisu.error import PropertiesOptionError, APIError, ConfigError, SlaveError
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}
}
2018-04-07 20:15:19 +02:00
PROPERTIES = ['hidden', 'disabled', 'mandatory']
2017-11-18 14:51:00 +01:00
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
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']
2017-11-28 22:42:30 +01:00
def return_str(val, suffix=None):
return val
2017-10-22 09:48:08 +02:00
def display_info(func):
def wrapper(*args, **kwargs):
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):
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-12-04 20:05:36 +01:00
def autocheck_option_multi(api, pathread, pathwrite, confread, confwrite, **kwargs):
2017-11-18 14:51:00 +01:00
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
2017-12-04 20:05:36 +01:00
api.option(pathread).option.ismulti()
api.option(pathread).option.issubmulti()
api.option(pathread).option.ismaster()
api.option(pathread).option.isslave()
2018-03-31 21:06:19 +02:00
else:
raises(PropertiesOptionError, "api.option(pathread).option.ismulti()")
raises(PropertiesOptionError, "api.option(pathread).option.issubmulti()")
raises(PropertiesOptionError, "api.option(pathread).option.ismaster()")
raises(PropertiesOptionError, "api.option(pathread).option.isslave()")
2018-04-05 21:13:24 +02:00
2018-03-31 21:06:19 +02:00
if not kwargs.get('propertyerror', False):
2017-12-04 20:05:36 +01:00
api.forcepermissive.option(pathread).option.ismulti()
api.forcepermissive.option(pathread).option.issubmulti()
api.forcepermissive.option(pathread).option.ismaster()
api.forcepermissive.option(pathread).option.isslave()
2018-03-31 21:06:19 +02:00
else:
raises(PropertiesOptionError, "api.forcepermissive.option(pathread).option.ismulti()")
raises(PropertiesOptionError, "api.forcepermissive.option(pathread).option.issubmulti()")
raises(PropertiesOptionError, "api.forcepermissive.option(pathread).option.ismaster()")
raises(PropertiesOptionError, "api.forcepermissive.option(pathread).option.isslave()")
2018-04-05 21:13:24 +02:00
2018-03-31 21:06:19 +02:00
api.unrestraint.option(pathread).option.ismulti()
api.unrestraint.option(pathread).option.issubmulti()
api.unrestraint.option(pathread).option.ismaster()
api.unrestraint.option(pathread).option.isslave()
2017-11-18 14:51:00 +01:00
@autocheck
2017-12-04 20:05:36 +01:00
def autocheck_default_owner(api, pathread, pathwrite, confread, confwrite, **kwargs):
2017-10-22 09:48:08 +02:00
"""check different value of owner when any value is set to this option
"""
2017-12-04 20:05:36 +01:00
isslave = api.unrestraint.option(pathread).option.isslave()
2017-11-18 14:51:00 +01:00
# check if owner is a string "default" and 'isdefault'
2017-11-23 16:56:14 +01:00
def do(conf):
if not isslave:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
2017-12-04 20:05:36 +01:00
assert api.config(conf).option(pathread).owner.get() == 'default'
assert api.forcepermissive.config(conf).option(pathread).owner.get() == 'default'
2017-11-23 16:56:14 +01:00
#
2017-12-04 20:05:36 +01:00
assert api.config(conf).option(pathread).owner.isdefault()
assert api.forcepermissive.config(conf).option(pathread).owner.isdefault()
2017-11-23 16:56:14 +01:00
elif not kwargs.get('propertyerror', False):
2018-03-31 21:06:19 +02:00
raises(PropertiesOptionError, "api.config(conf).option(pathread).owner.get()")
2017-12-04 20:05:36 +01:00
assert api.forcepermissive.config(conf).option(pathread).owner.get() == 'default'
2017-11-23 16:56:14 +01:00
#
2018-03-31 21:06:19 +02:00
raises(PropertiesOptionError, "api.config(conf).option(pathread).owner.isdefault()")
2017-12-04 20:05:36 +01:00
assert api.forcepermissive.config(conf).option(pathread).owner.isdefault()
2018-03-31 21:06:19 +02:00
else:
raises(PropertiesOptionError, "api.config(conf).option(pathread).owner.get()")
raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread).owner.get()")
#
raises(PropertiesOptionError, "api.config(conf).option(pathread).owner.isdefault()")
raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread).owner.isdefault()")
2018-04-05 21:13:24 +02:00
#
assert api.unrestraint.config(conf).option(pathread).owner.get() == 'default'
assert api.unrestraint.config(conf).option(pathread).owner.isdefault()
2017-10-22 09:48:08 +02:00
else:
2017-11-23 16:56:14 +01:00
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
2017-12-04 20:05:36 +01:00
assert api.config(conf).option(pathread, 0).owner.get() == 'default'
assert api.forcepermissive.config(conf).option(pathread, 0).owner.get() == 'default'
2017-11-23 16:56:14 +01:00
#
2017-12-04 20:05:36 +01:00
assert api.config(conf).option(pathread, 0).owner.isdefault()
assert api.forcepermissive.config(conf).option(pathread, 0).owner.isdefault()
2017-11-23 16:56:14 +01:00
elif not kwargs.get('propertyerror', False):
2017-12-04 20:05:36 +01:00
raises(PropertiesOptionError, "api.config(conf).option(pathread, 0).owner.get()")
assert api.forcepermissive.config(conf).option(pathread, 0).owner.get() == 'default'
2017-11-23 16:56:14 +01:00
#
2017-12-04 20:05:36 +01:00
raises(PropertiesOptionError, "api.config(conf).option(pathread, 0).owner.isdefault()")
assert api.forcepermissive.config(conf).option(pathread, 0).owner.isdefault()
2017-11-23 16:56:14 +01:00
else:
2017-12-04 20:05:36 +01:00
raises(PropertiesOptionError, "api.config(conf).option(pathread, 0).owner.get()")
raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread, 0).owner.get()")
2017-11-23 16:56:14 +01:00
#
2017-12-04 20:05:36 +01:00
raises(PropertiesOptionError, "api.config(conf).option(pathread, 0).owner.isdefault()")
raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread, 0).owner.isdefault()")
2018-04-05 21:13:24 +02:00
assert api.unrestraint.config(conf).option(pathread, 0).owner.get() == 'default'
assert api.unrestraint.config(conf).option(pathread, 0).owner.isdefault()
2017-11-23 16:56:14 +01:00
do(confread)
if confread != confwrite:
do(confwrite)
2017-11-18 14:51:00 +01:00
2017-10-22 09:48:08 +02:00
2017-11-23 16:56:14 +01:00
def _autocheck_default_value(api, path, conf, **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-28 22:42:30 +01:00
empty_value = kwargs['default']
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-23 16:56:14 +01:00
assert api.config(conf).option(path).value.get() == empty_value
assert api.forcepermissive.config(conf).option(path).value.get() == empty_value
2017-11-18 14:51:00 +01:00
elif not kwargs.get('propertyerror', False):
2017-11-23 16:56:14 +01:00
raises(PropertiesOptionError, "api.config(conf).option(path).value.get()")
assert api.forcepermissive.config(conf).option(path).value.get() == empty_value
2017-10-22 09:48:08 +02:00
else:
2017-11-23 16:56:14 +01:00
raises(PropertiesOptionError, "api.config(conf).option(path).value.get()")
raises(PropertiesOptionError, "api.forcepermissive.config(conf).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):
2017-11-23 16:56:14 +01:00
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
2017-11-18 14:51:00 +01:00
elif not kwargs.get('propertyerror', False):
2017-11-23 16:56:14 +01:00
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
2017-11-18 14:51:00 +01:00
else:
2017-11-23 16:56:14 +01:00
raises(PropertiesOptionError, "api.config(conf).option(path, 0).value.get()")
raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(path, 0).value.get()")
2017-11-18 14:51:00 +01:00
@autocheck
2017-12-04 20:05:36 +01:00
def autocheck_default_value(api, pathread, pathwrite, confread, confwrite, **kwargs):
_autocheck_default_value(api, pathread, confread, **kwargs)
2017-11-23 16:56:14 +01:00
if confread != confwrite:
2017-12-04 20:05:36 +01:00
_autocheck_default_value(api, pathread, confwrite, **kwargs)
2017-11-23 16:56:14 +01:00
2017-11-18 14:51:00 +01:00
2017-12-04 20:05:36 +01:00
def _set_value(api, pathwrite, conf, **kwargs):
2017-11-18 14:51:00 +01:00
set_permissive = kwargs.get('set_permissive', True)
2017-12-04 20:05:36 +01:00
multi = api.unrestraint.option(pathwrite).option.ismulti()
submulti_ = api.unrestraint.option(pathwrite).option.issubmulti()
ismaster = api.unrestraint.option(pathwrite).option.ismaster()
isslave = api.unrestraint.option(pathwrite).option.isslave()
2017-11-18 14:51:00 +01:00
if not multi:
first_value = FIRST_VALUE
elif submulti_ is False:
2017-11-28 22:42:30 +01:00
if not isslave:
first_value = LIST_FIRST_VALUE
else:
second_value = LIST_SECOND_VALUE[1]
2017-11-18 14:51:00 +01:00
else:
2017-11-28 22:42:30 +01:00
if not isslave:
first_value = SUBLIST_FIRST_VALUE
else:
second_value = SUBLIST_SECOND_VALUE[1]
2017-10-22 09:48:08 +02: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-12-04 20:05:36 +01:00
raises(APIError, "api.config(conf).option(pathwrite, 0).value.set(first_value[0])")
2017-11-18 14:51:00 +01:00
if not set_permissive:
2017-12-04 20:05:36 +01:00
api.config(conf).option(pathwrite).value.set([first_value[0]])
2017-11-18 14:51:00 +01:00
else:
2017-12-04 20:05:36 +01:00
api.forcepermissive.config(conf).option(pathwrite).value.set([first_value[0]])
2017-11-18 14:51:00 +01:00
elif not kwargs.get('propertyerror', False):
2017-12-04 20:05:36 +01:00
raises(PropertiesOptionError, "api.config(conf).option(pathwrite).value.set([first_value[0]])")
2017-11-18 14:51:00 +01:00
if set_permissive:
2017-12-04 20:05:36 +01:00
api.forcepermissive.config(conf).option(pathwrite).value.set([first_value[0]])
2017-10-22 09:48:08 +02:00
else:
2017-12-04 20:05:36 +01:00
raises(PropertiesOptionError, "api.config(conf).option(pathwrite).value.set([first_value[0]])")
2017-11-18 14:51:00 +01:00
raises(PropertiesOptionError,
2017-12-04 20:05:36 +01:00
"api.forcepermissive.config(conf).option(pathwrite).value.set([first_value[0]])")
2018-03-31 21:06:19 +02:00
if len(first_value) > 1:
raises(APIError, "api.unrestraint.config(conf).option(pathwrite).value.set(first_value[1])")
2017-11-18 14:51:00 +01:00
elif isslave:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if not set_permissive:
2017-12-04 20:05:36 +01:00
api.config(conf).option(pathwrite, 1).value.set(second_value)
2017-11-18 14:51:00 +01:00
else:
2017-12-04 20:05:36 +01:00
api.forcepermissive.config(conf).option(pathwrite, 1).value.set(second_value)
2017-11-18 14:51:00 +01:00
elif not kwargs.get('propertyerror', False):
2017-12-04 20:05:36 +01:00
raises(PropertiesOptionError, "api.config(conf).option(pathwrite, 1).value.set(second_value)")
2017-11-18 14:51:00 +01:00
if set_permissive:
2017-12-04 20:05:36 +01:00
api.forcepermissive.config(conf).option(pathwrite, 1).value.set(second_value)
2017-11-18 14:51:00 +01:00
else:
2017-12-04 20:05:36 +01:00
raises(PropertiesOptionError, "api.config(conf).option(pathwrite, 1).value.set(second_value)")
2017-11-18 14:51:00 +01:00
raises(PropertiesOptionError,
2017-12-04 20:05:36 +01:00
"api.forcepermissive.config(conf).option(pathwrite, 1).value.set(second_value)")
2017-11-18 14:51:00 +01:00
raises(APIError,
2017-12-04 20:05:36 +01:00
"api.unrestraint.config(conf).option(pathwrite).value.set([second_value, second_value])")
2017-11-18 14:51:00 +01:00
else:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if not set_permissive:
2017-12-04 20:05:36 +01:00
api.config(conf).option(pathwrite).value.set(first_value)
2017-11-18 14:51:00 +01:00
else:
2017-12-04 20:05:36 +01:00
api.forcepermissive.config(conf).option(pathwrite).value.set(first_value)
2017-11-18 14:51:00 +01:00
elif not kwargs.get('propertyerror', False):
2017-12-04 20:05:36 +01:00
raises(PropertiesOptionError, "api.config(conf).option(pathwrite).value.set(first_value)")
2017-11-18 14:51:00 +01:00
if set_permissive:
2017-12-04 20:05:36 +01:00
api.forcepermissive.config(conf).option(pathwrite).value.set(first_value)
2017-10-22 09:48:08 +02:00
else:
2017-12-04 20:05:36 +01:00
raises(PropertiesOptionError, "api.config(conf).option(pathwrite).value.set(first_value)")
raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathwrite).value.set(first_value)")
2018-03-31 21:06:19 +02:00
#FIXME raises(APIError, "api.unrestraint.config(conf).option(pathwrite).value.set(first_value)")
2017-11-18 14:51:00 +01:00
@autocheck
2017-12-04 20:05:36 +01:00
def autocheck_set_value(api, pathread, pathwrite, confread, confwrite, **kwargs):
_set_value(api, pathwrite, confwrite, **kwargs)
2017-11-18 14:51:00 +01:00
@autocheck
2017-12-04 20:05:36 +01:00
def autocheck_get_value_permissive(api, pathread, pathwrite, confread, confwrite, **kwargs):
multi = api.unrestraint.option(pathread).option.ismulti()
submulti_ = api.unrestraint.option(pathread).option.issubmulti()
isslave = api.unrestraint.option(pathread).option.isslave()
_set_value(api, pathwrite, confwrite, **kwargs)
2017-11-28 22:42:30 +01:00
empty_value = kwargs['default']
2017-11-18 14:51:00 +01:00
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
2017-11-23 16:56:14 +01:00
def do(conf):
# get value after set value without permissive
if isslave:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
2017-12-04 20:05:36 +01:00
assert api.config(conf).option(pathread, 0).value.get() == empty_value
assert api.forcepermissive.config(conf).option(pathread, 0).value.get() == empty_value
2017-11-28 22:42:30 +01:00
if submulti_:
2017-12-04 20:05:36 +01:00
assert api.config(conf).option(pathread, 1).value.get() == SUBLIST_SECOND_VALUE[1]
assert api.forcepermissive.config(conf).option(pathread, 1).value.get() == SUBLIST_SECOND_VALUE[1]
2017-11-28 22:42:30 +01:00
else:
2017-12-04 20:05:36 +01:00
assert api.config(conf).option(pathread, 1).value.get() == LIST_SECOND_VALUE[1]
assert api.forcepermissive.config(conf).option(pathread, 1).value.get() == LIST_SECOND_VALUE[1]
2017-11-23 16:56:14 +01:00
elif kwargs.get('permissive', False):
2017-12-04 20:05:36 +01:00
raises(PropertiesOptionError, "assert api.config(conf).option(pathread, 0).value.get()")
raises(PropertiesOptionError, "assert api.config(conf).option(pathread, 1).value.get()")
assert api.forcepermissive.config(conf).option(pathread, 0).value.get() == empty_value
2017-11-28 22:42:30 +01:00
if submulti_:
2017-12-04 20:05:36 +01:00
assert api.forcepermissive.config(conf).option(pathread, 1).value.get() == SUBLIST_SECOND_VALUE[1]
2017-11-28 22:42:30 +01:00
else:
2017-12-04 20:05:36 +01:00
assert api.forcepermissive.config(conf).option(pathread, 1).value.get() == LIST_SECOND_VALUE[1]
2017-11-23 16:56:14 +01:00
else:
2017-12-04 20:05:36 +01:00
raises(PropertiesOptionError, "assert api.config(conf).option(pathread, 0).value.get()")
raises(PropertiesOptionError, "assert api.config(conf).option(pathread, 1).value.get()")
raises(PropertiesOptionError, "assert api.forcepermissive.config(conf).option(pathread, 0).value.get()")
raises(PropertiesOptionError, "assert api.forcepermissive.config(conf).option(pathread, 1).value.get()")
2017-10-22 09:48:08 +02:00
else:
2017-11-23 16:56:14 +01:00
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
2017-12-04 20:05:36 +01:00
assert api.config(conf).option(pathread).value.get() == first_value
assert api.forcepermissive.config(conf).option(pathread).value.get() == first_value
2017-11-23 16:56:14 +01:00
elif kwargs.get('permissive', False):
2017-12-04 20:05:36 +01:00
raises(PropertiesOptionError, "api.config(conf).option(pathread).value.get()")
assert api.forcepermissive.config(conf).option(pathread).value.get() == first_value
2017-11-23 16:56:14 +01:00
else:
2017-12-04 20:05:36 +01:00
raises(PropertiesOptionError, "api.config(conf).option(pathread).value.get()")
raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread).value.get()")
2017-11-23 16:56:14 +01:00
do(confread)
if confread != confwrite:
do(confwrite)
2017-10-22 09:48:08 +02:00
2017-11-18 14:51:00 +01:00
2017-12-04 20:05:36 +01:00
def _autocheck_get_value(api, pathread, conf, **kwargs):
2017-11-28 22:42:30 +01:00
set_permissive = kwargs.get('set_permissive', True)
2017-12-04 20:05:36 +01:00
multi = api.unrestraint.option(pathread).option.ismulti()
submulti_ = api.unrestraint.option(pathread).option.issubmulti()
isslave = api.unrestraint.option(pathread).option.isslave()
2017-11-28 22:42:30 +01:00
empty_value = kwargs['default']
2017-11-18 14:51:00 +01:00
if not multi:
first_value = FIRST_VALUE
elif submulti_ is False:
2017-11-28 22:42:30 +01:00
if not isslave:
first_value = LIST_FIRST_VALUE
else:
second_value = LIST_SECOND_VALUE[1]
2017-10-22 09:48:08 +02:00
else:
2017-11-28 22:42:30 +01:00
if not isslave:
first_value = SUBLIST_FIRST_VALUE
else:
second_value = SUBLIST_SECOND_VALUE[1]
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):
2017-12-04 20:05:36 +01:00
assert api.config(conf).option(pathread, 0).value.get() == empty_value
assert api.config(conf).option(pathread, 1).value.get() == second_value
assert api.forcepermissive.config(conf).option(pathread, 0).value.get() == empty_value
assert api.forcepermissive.config(conf).option(pathread, 1).value.get() == second_value
2017-11-18 14:51:00 +01:00
elif kwargs.get('permissive', False):
2017-12-04 20:05:36 +01:00
raises(PropertiesOptionError, "api.config(conf).option(pathread, 0).value.get()")
assert api.forcepermissive.config(conf).option(pathread, 0).value.get() == empty_value
2017-11-28 22:42:30 +01:00
if set_permissive:
2017-12-04 20:05:36 +01:00
assert api.forcepermissive.config(conf).option(pathread, 1).value.get() == second_value
2017-11-28 22:42:30 +01:00
else:
2017-12-04 20:05:36 +01:00
assert api.forcepermissive.config(conf).option(pathread, 1).value.get() == empty_value
2017-10-22 09:48:08 +02:00
else:
2017-12-04 20:05:36 +01:00
raises(PropertiesOptionError, "api.config(conf).option(pathread, 0).value.get()")
raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread, 0).value.get()")
2017-11-18 14:51:00 +01:00
else:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
2017-12-04 20:05:36 +01:00
assert api.config(conf).option(pathread).value.get() == first_value
assert api.forcepermissive.config(conf).option(pathread).value.get() == first_value
2017-11-18 14:51:00 +01:00
elif kwargs.get('permissive', False):
2017-12-04 20:05:36 +01:00
raises(PropertiesOptionError, "api.config(conf).option(pathread).value.get()")
2017-11-28 22:42:30 +01:00
if set_permissive:
2017-12-04 20:05:36 +01:00
assert api.forcepermissive.config(conf).option(pathread).value.get() == first_value
2017-11-28 22:42:30 +01:00
else:
2017-12-04 20:05:36 +01:00
assert api.forcepermissive.config(conf).option(pathread).value.get() == empty_value
2017-10-22 09:48:08 +02:00
else:
2017-12-04 20:05:36 +01:00
raises(PropertiesOptionError, "api.config(conf).option(pathread).value.get()")
raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread).value.get()")
2017-10-22 09:48:08 +02:00
2017-11-18 14:51:00 +01:00
@autocheck
2017-12-04 20:05:36 +01:00
def autocheck_get_value(api, pathread, pathwrite, confread, confwrite, **kwargs):
_set_value(api, pathwrite, confwrite, set_permissive=False, **kwargs)
_autocheck_get_value(api, pathread, confread, set_permissive=False, **kwargs)
if pathread.endswith('val1'):
val2_path = pathread.replace('val1', 'val2')
2017-12-02 22:53:57 +01:00
_autocheck_default_value(api, val2_path, confread, **kwargs)
2017-11-23 16:56:14 +01:00
if confread != confwrite:
2017-12-04 20:05:36 +01:00
_autocheck_get_value(api, pathread, confwrite, set_permissive=False, **kwargs)
if pathread.endswith('val1'):
2017-12-02 22:53:57 +01:00
_autocheck_default_value(api, val2_path, confwrite, **kwargs)
2017-11-18 14:51:00 +01:00
@autocheck
2017-12-04 20:05:36 +01:00
def autocheck_value_slave(api, pathread, pathwrite, confread, confwrite, **kwargs):
isslave = api.unrestraint.option(pathread).option.isslave()
if not isslave:
2018-03-31 21:06:19 +02:00
if kwargs.get('propertyerror', False):
2018-04-05 21:13:24 +02:00
raises(APIError, "api.unrestraint.config(confread).option(pathread).value.len()")
return
if kwargs.get('propertyerror', False):
2017-12-04 20:05:36 +01:00
raises(PropertiesOptionError, "api.option(pathread).value.len()")
raises(PropertiesOptionError, "api.forcepermissive.option(pathread).value.len()")
return
2017-11-18 14:51:00 +01:00
2017-12-04 20:05:36 +01:00
multi = api.unrestraint.option(pathread).option.ismulti()
submulti_ = api.forcepermissive.option(pathread).option.issubmulti()
2017-11-28 22:42:30 +01:00
empty_value = kwargs['default']
2017-11-18 14:51:00 +01:00
2017-11-23 16:56:14 +01:00
def do(conf):
if not kwargs.get('permissive', False):
2017-12-04 20:05:36 +01:00
length = api.config(conf).option(pathread).value.len()
assert api.forcepermissive.config(conf).option(pathread).value.len() == length
2017-11-23 16:56:14 +01:00
else:
2017-12-04 20:05:36 +01:00
raises(PropertiesOptionError, "api.config(conf).option(pathread).value.len()")
length = api.forcepermissive.config(conf).option(pathread).value.len()
2017-11-23 16:56:14 +01:00
assert length == 2
do(confread)
if confread != confwrite:
do(confwrite)
length = 2
value = []
for idx in range(length):
2017-12-04 20:05:36 +01:00
value.append(api.forcepermissive.option(pathread, idx).value.get())
2017-11-18 14:51:00 +01:00
2017-11-28 22:42:30 +01:00
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]
2017-11-18 14:51:00 +01:00
2018-03-31 21:06:19 +02:00
raises(SlaveError, "api.forcepermissive.option(pathread, length).value.get()")
raises(SlaveError, "api.forcepermissive.option(pathread, length).value.set(value)")
raises(SlaveError, "api.forcepermissive.option(pathread, length).value.reset()")
raises(SlaveError, "api.forcepermissive.option(pathread, length).owner.get()")
raises(SlaveError, "api.forcepermissive.option(pathread, length).owner.isdefault()")
raises(SlaveError, "api.forcepermissive.option(pathread, length).property.get()")
raises(SlaveError, "api.forcepermissive.option(pathread, length).owner.set('new_user')")
raises(SlaveError, "api.forcepermissive.option(pathread, length).property.add('prop')")
2017-10-22 09:48:08 +02:00
@autocheck
2017-12-04 20:05:36 +01:00
def autocheck_reset_value(api, pathread, pathwrite, confread, confwrite, **kwargs):
2017-10-22 09:48:08 +02:00
# check if is a multi, a master or a slave
2017-12-04 20:05:36 +01:00
multi = api.unrestraint.option(pathread).option.ismulti()
submulti_ = api.unrestraint.option(pathread).option.issubmulti()
isslave = api.unrestraint.option(pathread).option.isslave()
2017-10-22 09:48:08 +02:00
# 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
2017-10-22 09:48:08 +02:00
else:
first_value = SUBLIST_FIRST_VALUE
second_value = SUBLIST_SECOND_VALUE
2017-11-28 22:42:30 +01:00
empty_value = kwargs['default']
2017-12-04 20:05:36 +01:00
_set_value(api, pathwrite, confwrite, **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-12-04 20:05:36 +01:00
api.config(confwrite).option(pathwrite).value.reset()
2018-03-19 08:33:53 +01:00
#else:
2018-03-31 21:06:19 +02:00
#FIXME raises(PropertiesOptionError, "api.config(confwrite).option(pathwrite).value.reset()")
2017-11-18 14:51:00 +01:00
else:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
2017-12-04 20:05:36 +01:00
api.config(confwrite).option(pathwrite, 0).value.reset()
2018-03-19 08:33:53 +01:00
#else:
2018-03-31 21:06:19 +02:00
#FIXME raises(PropertiesOptionError, "api.config(confwrite).option(pathwrite, 0).value.reset()")
2017-10-22 09:48:08 +02:00
# get value after reset value without permissive
2017-11-23 16:56:14 +01:00
def do(conf):
if isslave:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
2017-12-04 20:05:36 +01:00
assert api.config(conf).option(pathread, 0).value.get() == empty_value
assert api.config(conf).option(pathread, 1).value.get() == second_value[1]
2017-11-23 16:56:14 +01:00
elif kwargs.get('permissive', False):
2017-12-04 20:05:36 +01:00
raises(PropertiesOptionError, "api.config(conf).option(pathread, 0).value.get()")
assert api.forcepermissive.config(conf).option(pathread, 0).value.get() == empty_value
assert api.forcepermissive.config(conf).option(pathread, 1).value.get() == second_value[1]
2017-11-23 16:56:14 +01:00
else:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
2017-12-04 20:05:36 +01:00
assert api.config(conf).option(pathread).value.get() == empty_value
2017-11-23 16:56:14 +01:00
elif kwargs.get('permissive', False):
2017-12-04 20:05:36 +01:00
raises(PropertiesOptionError, "api.config(conf).option(pathread).value.get()")
assert api.forcepermissive.config(conf).option(pathread).value.get() == first_value
2017-11-23 16:56:14 +01:00
do(confread)
if confread != confwrite:
do(confwrite)
2017-10-22 09:48:08 +02:00
2017-11-18 14:51:00 +01:00
2017-11-28 22:42:30 +01:00
@autocheck
2017-12-04 20:05:36 +01:00
def autocheck_append_value(api, pathread, pathwrite, confread, confwrite, **kwargs):
ismaster = api.unrestraint.option(pathread).option.ismaster()
submulti_ = api.unrestraint.option(pathread).option.issubmulti()
2017-11-28 22:42:30 +01:00
if not ismaster:
return
if not kwargs.get('propertyerror', False):
2017-12-04 20:05:36 +01:00
master_value = api.forcepermissive.config(confread).option(pathread).value.get()
2017-11-28 22:42:30 +01:00
len_value = len(master_value)
master_value.append(undefined)
2017-12-04 20:05:36 +01:00
assert len(api.forcepermissive.config(confread).option(pathread).value.get()) == len_value
api.forcepermissive.config(confwrite).option(pathread).value.set(master_value)
new_master_value = api.forcepermissive.config(confread).option(pathread).value.get()
2017-11-28 22:42:30 +01:00
len_new = len(new_master_value)
assert len_value + 1 == len_new
assert new_master_value[-1] == kwargs['default_multi']
2017-12-04 20:05:36 +01:00
slave_path = pathread.rsplit('.', 1)[0]
2017-12-02 22:53:57 +01:00
if slave_path.endswith('val1') or slave_path.endswith('val2'):
slave_path += '.third' + slave_path[-4:]
else:
slave_path += '.third'
2017-11-28 22:42:30 +01:00
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)
2017-12-04 20:05:36 +01:00
assert len(api.forcepermissive.config(confread).option(pathread).value.get()) == len(new_master_value)
api.forcepermissive.config(confwrite).option(pathread).value.set(master_value)
assert api.forcepermissive.config(confread).option(pathread).value.get()[-1] == value
2017-11-28 22:42:30 +01:00
@autocheck
2017-12-04 20:05:36 +01:00
def autocheck_pop_value(api, pathread, pathwrite, confread, confwrite, **kwargs):
ismaster = api.unrestraint.option(pathread).option.ismaster()
submulti_ = api.unrestraint.option(pathread).option.issubmulti()
2017-11-28 22:42:30 +01:00
if not ismaster:
return
if not kwargs.get('propertyerror', False):
if not submulti_:
values = ['value1', 'value2', 'value3', 'value4']
2017-12-02 22:53:57 +01:00
slave_value = 'slave'
2017-11-28 22:42:30 +01:00
else:
values = [['value1'], ['value2'], ['value3'], ['value4']]
2017-12-02 22:53:57 +01:00
slave_value = ['slave']
slaves = [kwargs['default_multi'], slave_value, kwargs['default_multi'], kwargs['default_multi']]
2017-12-04 20:05:36 +01:00
a_slave = pathwrite.rsplit('.', 1)[0]
2017-12-02 22:53:57 +01:00
if a_slave.endswith('val1') or a_slave.endswith('val2'):
a_slave += '.third' + a_slave[-4:]
else:
a_slave += '.third'
2017-12-04 20:05:36 +01:00
api.forcepermissive.config(confwrite).option(pathread).value.set(values)
2017-12-02 22:53:57 +01:00
api.forcepermissive.config(confwrite).option(a_slave, 1).value.set(slave_value)
2017-11-28 22:42:30 +01:00
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
2017-12-02 22:53:57 +01:00
api.forcepermissive.config(confread).option(a_slave, 1).value.get() == slave_value
2017-11-28 22:42:30 +01:00
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
#
2017-12-04 20:05:36 +01:00
api.forcepermissive.config(confwrite).option(pathread).value.pop(3)
2017-11-28 22:42:30 +01:00
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
2017-12-02 22:53:57 +01:00
api.forcepermissive.config(confread).option(a_slave, 1).value.get() == slave_value
2017-11-28 22:42:30 +01:00
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
#
2017-12-04 20:05:36 +01:00
api.forcepermissive.config(confwrite).option(pathread).value.pop(0)
2017-12-02 22:53:57 +01:00
api.forcepermissive.config(confread).option(a_slave, 0).value.get() == slave_value
2017-11-28 22:42:30 +01:00
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
#
2017-12-04 20:05:36 +01:00
api.forcepermissive.config(confwrite).option(pathread).value.pop(0)
2017-11-28 22:42:30 +01:00
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
2017-11-18 14:51:00 +01:00
@autocheck
2017-12-04 20:05:36 +01:00
def autocheck_reset_value_permissive(api, pathread, pathwrite, confread, confwrite, **kwargs):
2017-11-18 14:51:00 +01:00
# check if is a multi, a master or a slave
2017-12-04 20:05:36 +01:00
isslave = api.unrestraint.option(pathread).option.isslave()
_set_value(api, pathwrite, confwrite, **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-12-04 20:05:36 +01:00
api.forcepermissive.config(confwrite).option(pathwrite).value.reset()
2017-10-22 09:48:08 +02:00
else:
2017-12-04 20:05:36 +01:00
api.forcepermissive.option(pathwrite, 1).value.reset()
2017-10-22 09:48:08 +02:00
elif kwargs.get('permissive', False):
if not isslave:
2017-12-04 20:05:36 +01:00
api.forcepermissive.config(confwrite).option(pathwrite).value.reset()
2017-10-22 09:48:08 +02:00
else:
2017-12-04 20:05:36 +01:00
api.forcepermissive.option(pathwrite, 1).value.reset()
2018-03-31 21:06:19 +02:00
#FIXME else:
2018-03-19 08:33:53 +01:00
# if not isslave:
# raises(PropertiesOptionError, "api.forcepermissive.config(confwrite).option(pathwrite).value.reset()")
# else:
# raises(PropertiesOptionError, "api.forcepermissive.option(pathwrite, 1).value.reset()")
2017-12-04 20:05:36 +01:00
_autocheck_default_value(api, pathread, confread, **kwargs)
2017-11-23 16:56:14 +01:00
if confread != confwrite:
2018-03-31 21:06:19 +02:00
_autocheck_default_value(api, pathwrite, confwrite, **kwargs)
2017-10-22 09:48:08 +02:00
@autocheck
2017-12-04 20:05:36 +01:00
def autocheck_display(api, pathread, pathwrite, confread, confwrite, **kwargs):
2017-10-25 08:46:22 +02:00
"""re set value
2017-10-22 09:48:08 +02:00
"""
2017-11-28 22:42:30 +01:00
if kwargs['callback']:
return
2017-11-23 16:56:14 +01:00
make_dict = kwargs['make_dict']
make_dict_value = kwargs['make_dict_value']
2018-03-19 08:33:53 +01:00
assert api.config(confread).option.make_dict() == make_dict
2017-11-23 16:56:14 +01:00
if confread != confwrite:
2018-03-19 08:33:53 +01:00
assert(api.config(confwrite).option.make_dict()) == make_dict
2017-12-04 20:05:36 +01:00
_set_value(api, pathwrite, confwrite, **kwargs)
2018-03-19 08:33:53 +01:00
assert api.config(confread).option.make_dict() == make_dict_value
2017-11-23 16:56:14 +01:00
if confread != confwrite:
2018-03-19 08:33:53 +01:00
assert(api.config(confwrite).option.make_dict()) == make_dict_value
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)
2017-11-20 17:01:36 +01:00
return default_props, frozenset(properties)
2017-11-18 14:51:00 +01:00
2018-03-31 21:06:19 +02:00
def _check_properties(api, pathread, conf, kwargs, props_permissive, props):
2017-12-04 20:05:36 +01:00
if not api.unrestraint.option(pathread).option.isslave():
2017-11-18 14:51:00 +01:00
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
2017-12-04 20:05:36 +01:00
assert set(api.config(conf).option(pathread).property.get()) == set(props_permissive)
2018-03-31 21:06:19 +02:00
assert set(api.config(conf).option(pathread).property.get()) == set(props)
else:
raises(PropertiesOptionError, "api.config(conf).option(pathread).property.get()")
raises(PropertiesOptionError, "api.config(conf).option(pathread).property.get()")
2018-04-05 21:13:24 +02:00
if not kwargs.get('propertyerror', False):
2018-03-31 21:06:19 +02:00
assert set(api.forcepermissive.config(conf).option(pathread).property.get()) == set(props_permissive)
2017-12-04 20:05:36 +01:00
assert set(api.forcepermissive.config(conf).option(pathread).property.get()) == set(props)
2018-03-31 21:06:19 +02:00
else:
2018-04-05 21:13:24 +02:00
assert PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread).property.get()"
assert PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread).property.get()"
2018-03-31 21:06:19 +02:00
assert set(api.unrestraint.config(conf).option(pathread).property.get()) == set(props_permissive)
assert set(api.unrestraint.config(conf).option(pathread).property.get()) == set(props)
2017-11-18 14:51:00 +01:00
else:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
2017-12-04 20:05:36 +01:00
assert set(api.config(conf).option(pathread, 0).property.get()) == set(props_permissive)
2018-03-31 21:06:19 +02:00
assert set(api.config(conf).option(pathread, 0).property.get()) == set(props)
#
2017-12-04 20:05:36 +01:00
assert set(api.config(conf).option(pathread, 1).property.get()) == set(props_permissive)
2018-03-31 21:06:19 +02:00
assert set(api.config(conf).option(pathread, 1).property.get()) == set(props)
else:
raises(PropertiesOptionError, "api.config(conf).option(pathread, 0).property.get()")
raises(PropertiesOptionError, "api.config(conf).option(pathread, 0).property.get()")
#
raises(PropertiesOptionError, "api.config(conf).option(pathread, 1).property.get()")
raises(PropertiesOptionError, "api.config(conf).option(pathread, 1).property.get()")
2018-04-05 21:13:24 +02:00
if not kwargs.get('propertyerror', False):
2018-03-31 21:06:19 +02:00
assert set(api.forcepermissive.config(conf).option(pathread, 0).property.get()) == set(props_permissive)
2017-12-04 20:05:36 +01:00
assert set(api.forcepermissive.config(conf).option(pathread, 0).property.get()) == set(props)
2018-03-31 21:06:19 +02:00
#
assert set(api.forcepermissive.config(conf).option(pathread, 1).property.get()) == set(props_permissive)
2017-12-04 20:05:36 +01:00
assert set(api.forcepermissive.config(conf).option(pathread, 1).property.get()) == set(props)
2017-11-18 14:51:00 +01:00
else:
2018-03-31 21:06:19 +02:00
raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread, 0).property.get()")
raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread, 0).property.get()")
#
raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread, 1).property.get()")
raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread, 1).property.get()")
assert set(api.unrestraint.config(conf).option(pathread, 0).property.get()) == set(props_permissive)
assert set(api.unrestraint.config(conf).option(pathread, 0).property.get()) == set(props)
#
assert set(api.unrestraint.config(conf).option(pathread, 1).property.get()) == set(props_permissive)
assert set(api.unrestraint.config(conf).option(pathread, 1).property.get()) == set(props)
2017-11-18 14:51:00 +01:00
2017-11-23 16:56:14 +01:00
@autocheck
2017-12-04 20:05:36 +01:00
def autocheck_property(api, pathread, pathwrite, confread, confwrite, **kwargs):
2017-11-18 14:51:00 +01:00
"""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
2017-12-04 20:05:36 +01:00
multi = api.unrestraint.option(pathread).option.ismulti()
isslave = api.unrestraint.option(pathread).option.isslave()
2017-11-18 14:51:00 +01:00
default_props, properties = _getproperties(multi, isslave, kwargs)
2018-03-31 21:06:19 +02:00
_check_properties(api, pathread, confread, kwargs, default_props, default_props)
if confread != confwrite:
_check_properties(api, pathread, confwrite, kwargs, default_props, default_props)
2017-11-18 14:51:00 +01:00
# set properties without permissive
2018-03-31 21:06:19 +02:00
for prop in properties:
2018-04-05 21:13:24 +02:00
api.unrestraint.config(confwrite).option(pathwrite).property.add(prop)
2018-03-31 21:06:19 +02:00
_check_properties(api, pathread, confread, kwargs, properties, properties)
2017-11-23 16:56:14 +01:00
if confread != confwrite:
2018-03-31 21:06:19 +02:00
_check_properties(api, pathread, confwrite, kwargs, properties, properties)
2017-11-13 22:45:53 +01:00
2017-12-04 20:05:36 +01:00
def _property_permissive(api, pathread, pathwrite, confread, confwrite, **kwargs):
2017-10-22 09:48:08 +02:00
# check if is a multi or a slave
2017-12-04 20:05:36 +01:00
multi = api.unrestraint.option(pathread).option.ismulti()
isslave = api.unrestraint.option(pathread).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
2018-03-31 21:06:19 +02:00
_check_properties(api, pathread, confwrite, kwargs, default_props, default_props)
2017-11-23 16:56:14 +01:00
if confwrite != confread:
2018-03-31 21:06:19 +02:00
_check_properties(api, pathread, confread, 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
2018-03-31 21:06:19 +02:00
for prop in properties:
2018-04-05 21:13:24 +02:00
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
api.config(confwrite).option(pathwrite).property.add(prop)
if not kwargs.get('propertyerror', False):
api.forcepermissive.config(confwrite).option(pathwrite).property.add(prop)
2018-03-31 21:06:19 +02:00
api.unrestraint.config(confwrite).option(pathwrite).property.add(prop)
_check_properties(api, pathread, confwrite, kwargs, properties, properties)
2017-11-23 16:56:14 +01:00
if confwrite != confread:
2018-03-31 21:06:19 +02:00
_check_properties(api, pathread, confread, kwargs, properties, properties)
2017-11-18 14:51:00 +01:00
@autocheck
2017-12-04 20:05:36 +01:00
def autocheck_property_permissive(api, pathread, pathwrite, confread, confwrite, **kwargs):
_property_permissive(api, pathread, pathwrite, confread, confwrite, **kwargs)
2017-10-22 09:48:08 +02:00
@autocheck
2017-12-04 20:05:36 +01:00
def autocheck_reset_property(api, pathread, pathwrite, confread, confwrite, **kwargs):
2017-10-22 09:48:08 +02:00
"""check properties after set with permissive
"""
# check if is a multi or a slave
2017-12-04 20:05:36 +01:00
multi = api.unrestraint.option(pathread).option.ismulti()
isslave = api.unrestraint.option(pathread).option.isslave()
2017-11-18 14:51:00 +01:00
default_props, properties = _getproperties(multi, isslave, kwargs)
2017-10-22 09:48:08 +02:00
2017-12-04 20:05:36 +01:00
_property_permissive(api, pathread, pathwrite, confread, confwrite, **kwargs)
2017-10-22 09:48:08 +02:00
# reset properties without permissive
2018-04-05 21:13:24 +02:00
api.unrestraint.config(confwrite).option(pathwrite).property.reset()
2017-10-22 09:48:08 +02:00
2018-03-31 21:06:19 +02:00
_check_properties(api, pathread, confread, kwargs, default_props, default_props)
2017-11-23 16:56:14 +01:00
if confread != confwrite:
2018-03-31 21:06:19 +02:00
_check_properties(api, pathread, confwrite, kwargs, default_props, default_props)
2017-11-18 14:51:00 +01:00
@autocheck
2017-12-04 20:05:36 +01:00
def autocheck_reset_property_permissive(api, pathread, pathwrite, confread, confwrite, **kwargs):
2017-11-18 14:51:00 +01:00
# check if is a multi or a slave
2017-12-04 20:05:36 +01:00
multi = api.unrestraint.option(pathread).option.ismulti()
isslave = api.unrestraint.option(pathread).option.isslave()
2017-11-18 14:51:00 +01:00
default_props, properties = _getproperties(multi, isslave, kwargs)
2017-12-04 20:05:36 +01:00
_property_permissive(api, pathread, pathwrite, confread, confwrite, **kwargs)
2017-10-22 09:48:08 +02:00
2018-03-31 21:06:19 +02:00
for prop in properties:
2018-04-05 21:13:24 +02:00
api.unrestraint.option(pathwrite).property.add(prop)
api.unrestraint.option(pathwrite).property.reset()
2017-10-22 09:48:08 +02:00
2018-03-31 21:06:19 +02:00
_check_properties(api, pathread, confwrite, kwargs, default_props, default_props)
2017-11-23 16:56:14 +01:00
if confread != confwrite:
2018-03-31 21:06:19 +02:00
_check_properties(api, pathread, confread, kwargs, default_props, default_props)
2017-10-22 09:48:08 +02:00
@autocheck
2017-12-04 20:05:36 +01:00
def autocheck_context_owner(api, pathread, pathwrite, confread, confwrite, **kwargs):
owner = api.owner.get()
2018-03-31 21:06:19 +02:00
assert owner == kwargs['owner']
2017-11-18 14:51:00 +01:00
2017-12-04 20:05:36 +01:00
def _check_owner(api, pathread, conf, kwargs, owner, permissive_owner):
isslave = api.unrestraint.option(pathread).option.isslave()
2017-11-18 14:51:00 +01:00
if not isslave:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
2017-12-04 20:05:36 +01:00
assert api.config(conf).option(pathread).owner.get() == owner
assert api.forcepermissive.config(conf).option(pathread).owner.get() == owner
2017-11-18 14:51:00 +01:00
elif not kwargs.get('propertyerror', False):
2018-03-31 21:06:19 +02:00
raises(PropertiesOptionError, "api.config(conf).option(pathread).owner.get()")
2017-12-04 20:05:36 +01:00
assert api.forcepermissive.config(conf).option(pathread).owner.get() == permissive_owner
2018-03-31 21:06:19 +02:00
else:
raises(PropertiesOptionError, "api.config(conf).option(pathread).owner.get()")
raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread).owner.get()")
2017-11-18 14:51:00 +01:00
else:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
2017-12-04 20:05:36 +01:00
assert api.config(conf).option(pathread, 0).owner.get() == 'default'
assert api.forcepermissive.config(conf).option(pathread, 0).owner.get() == 'default'
assert api.config(conf).option(pathread, 1).owner.get() == owner
assert api.forcepermissive.config(conf).option(pathread, 1).owner.get() == owner
2017-11-18 14:51:00 +01:00
elif not kwargs.get('propertyerror', False):
2017-12-04 20:05:36 +01:00
raises(PropertiesOptionError, "api.config(conf).option(pathread, 0).owner.get()")
raises(PropertiesOptionError, "api.config(conf).option(pathread, 1).owner.get()")
assert api.forcepermissive.config(conf).option(pathread, 0).owner.get() == 'default'
assert api.forcepermissive.config(conf).option(pathread, 1).owner.get() == permissive_owner
2017-10-22 09:48:08 +02:00
else:
2017-12-04 20:05:36 +01:00
raises(PropertiesOptionError, "api.config(conf).option(pathread, 0).owner.get()")
raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread, 0).owner.get()")
2017-10-22 09:48:08 +02:00
2017-11-18 14:51:00 +01:00
@autocheck
2017-12-04 20:05:36 +01:00
def autocheck_owner_with_value(api, pathread, pathwrite, confread, confwrite, **kwargs):
2017-11-18 14:51:00 +01:00
"""value is now changed, check owner in this case
"""
2017-12-04 20:05:36 +01:00
_set_value(api, pathwrite, confwrite, **kwargs)
2018-03-31 21:06:19 +02:00
_check_owner(api, pathread, confwrite, kwargs, kwargs['owner'], kwargs['owner'])
2017-11-23 16:56:14 +01:00
if confread != confwrite:
2018-03-31 21:06:19 +02:00
_check_owner(api, pathread, confread, kwargs, kwargs['owner'], kwargs['owner'])
2017-11-18 14:51:00 +01:00
@autocheck
2017-12-04 20:05:36 +01:00
def autocheck_default_owner_with_value(api, pathread, pathwrite, confread, confwrite, **kwargs):
isslave = api.unrestraint.option(pathread).option.isslave()
_set_value(api, pathwrite, confwrite, **kwargs)
2017-11-18 14:51:00 +01:00
2017-10-22 09:48:08 +02:00
# test if is default owner without permissive
2017-11-28 22:42:30 +01:00
if not isslave:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
2017-12-04 20:05:36 +01:00
assert api.config(confwrite).option(pathread).owner.isdefault() is False
2017-11-28 22:42:30 +01:00
if confwrite != confread:
2017-12-04 20:05:36 +01:00
assert api.config(confread).option(pathread).owner.isdefault() is False
2018-03-31 21:06:19 +02:00
#FIXME else:
2018-03-19 08:33:53 +01:00
# raises(PropertiesOptionError, "api.config(confwrite).option(pathread).owner.isdefault()")
# raises(PropertiesOptionError, "api.config(confread).option(pathread).owner.isdefault()")
2017-10-22 09:48:08 +02:00
else:
2017-11-28 22:42:30 +01:00
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
2017-12-04 20:05:36 +01:00
assert api.config(confwrite).option(pathread, 0).owner.isdefault() is True
assert api.config(confwrite).option(pathread, 1).owner.isdefault() is False
2017-11-28 22:42:30 +01:00
if confwrite != confread:
2017-12-04 20:05:36 +01:00
assert api.config(confread).option(pathread, 0).owner.isdefault() is True
assert api.config(confread).option(pathread, 1).owner.isdefault() is False
2018-03-31 21:06:19 +02:00
#FIXME else:
# raises(PropertiesOptionError, "api.config(confwrite).option(pathread, 0).owner.isdefault()")
# raises(PropertiesOptionError, "api.config(confread).option(pathread, 0).owner.isdefault()")
2017-10-22 09:48:08 +02:00
2017-11-18 14:51:00 +01:00
@autocheck
2017-12-04 20:05:36 +01:00
def autocheck_default_owner_with_value_permissive(api, pathread, pathwrite, confread, confwrite, **kwargs):
2017-11-18 14:51:00 +01:00
# check if is a isslave
2017-12-04 20:05:36 +01:00
isslave = api.unrestraint.option(pathread).option.isslave()
2017-11-18 14:51:00 +01:00
2017-12-04 20:05:36 +01:00
_set_value(api, pathwrite, confwrite, **kwargs)
2017-11-18 14:51:00 +01:00
2017-11-23 16:56:14 +01:00
def do(conf):
# test if is default owner with permissive
if not kwargs.get('propertyerror', False):
if not isslave:
2017-12-04 20:05:36 +01:00
assert api.forcepermissive.config(conf).option(pathread).owner.isdefault() is False
2017-11-23 16:56:14 +01:00
else:
2017-12-04 20:05:36 +01:00
assert api.forcepermissive.config(conf).option(pathread, 0).owner.isdefault() is True
assert api.forcepermissive.config(conf).option(pathread, 1).owner.isdefault() is False
2018-03-31 21:06:19 +02:00
#FIXME else:
2018-03-19 08:33:53 +01:00
# raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread).owner.isdefault()")
2017-11-23 16:56:14 +01:00
do(confwrite)
if confwrite != confread:
do(confread)
2017-10-22 09:48:08 +02:00
2017-11-18 14:51:00 +01:00
@autocheck
2017-12-04 20:05:36 +01:00
def autocheck_set_owner_no_value(api, pathread, pathwrite, confread, confwrite, **kwargs):
isslave = api.unrestraint.option(pathread).option.isslave()
2017-11-18 14:51:00 +01:00
if not kwargs.get('propertyerror', False):
if not isslave:
2017-12-04 20:05:36 +01:00
raises(ConfigError, "api.forcepermissive.config(confwrite).option(pathwrite).owner.set('new_user')")
2017-11-18 14:51:00 +01:00
else:
2017-12-04 20:05:36 +01:00
raises(ConfigError, "api.forcepermissive.option(pathwrite, 1).owner.set('new_user')")
2017-11-18 14:51:00 +01:00
2017-10-22 09:48:08 +02:00
@autocheck
2017-12-04 20:05:36 +01:00
def autocheck_set_owner(api, pathread, pathwrite, confread, confwrite, **kwargs):
2017-10-22 09:48:08 +02:00
# test set owner without permissive
2017-12-04 20:05:36 +01:00
isslave = api.unrestraint.option(pathread).option.isslave()
2017-11-18 14:51:00 +01:00
2017-12-04 20:05:36 +01:00
_set_value(api, pathwrite, confwrite, **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-12-04 20:05:36 +01:00
api.config(confwrite).option(pathwrite).owner.set('new_user')
raises(ConfigError, "api.config(confwrite).option(pathwrite).owner.set('default')")
raises(ConfigError, "api.config(confwrite).option(pathwrite).owner.set('forced')")
raises(ConfigError, "api.config(confwrite).option(pathwrite).owner.set('meta')")
2018-03-31 21:06:19 +02:00
#FIXME else:
2018-03-19 08:33:53 +01:00
# raises(PropertiesOptionError, "api.config(confwrite).option(pathwrite).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):
2017-12-04 20:05:36 +01:00
api.option(pathwrite, 1).owner.set('new_user')
2018-03-31 21:06:19 +02:00
#FIXME else:
# raises(PropertiesOptionError, "api.option(pathwrite, 1).owner.set('new_user')")
2017-10-22 09:48:08 +02:00
2018-03-31 21:06:19 +02:00
_check_owner(api, pathread, confwrite, kwargs, owners.new_user, kwargs['owner'])
2017-11-23 16:56:14 +01:00
if confwrite != confread:
2018-03-31 21:06:19 +02:00
_check_owner(api, pathread, confread, kwargs, owners.new_user, owners.meta)
2017-11-18 14:51:00 +01:00
@autocheck
2017-12-04 20:05:36 +01:00
def autocheck_set_owner_permissive(api, pathread, pathwrite, confread, confwrite, **kwargs):
isslave = api.unrestraint.option(pathread).option.isslave()
2017-11-18 14:51:00 +01:00
2017-12-04 20:05:36 +01:00
_set_value(api, pathwrite, confwrite, **kwargs)
2017-10-22 09:48:08 +02:00
# set owner with permissive
if not kwargs.get('propertyerror', False):
if not isslave:
2017-12-04 20:05:36 +01:00
api.forcepermissive.config(confwrite).option(pathwrite).owner.set('new_user1')
2017-10-22 09:48:08 +02:00
else:
2017-12-04 20:05:36 +01:00
api.forcepermissive.option(pathwrite, 1).owner.set('new_user1')
2018-03-31 21:06:19 +02:00
#FIXME else:
2018-03-19 08:33:53 +01:00
# if not isslave:
# raises(PropertiesOptionError,
# "api.forcepermissive.config(confwrite).option(pathwrite).owner.set('new_user1')")
# else:
# raises(PropertiesOptionError,
# "api.forcepermissive.option(pathwrite, 1).owner.set('new_user1')")
2017-10-22 09:48:08 +02:00
2017-12-04 20:05:36 +01:00
_check_owner(api, pathread, confwrite, kwargs, 'new_user1', 'new_user1')
2017-11-23 16:56:14 +01:00
if confwrite != confread:
2018-03-31 21:06:19 +02:00
_check_owner(api, pathread, confread, kwargs, 'new_user1', 'new_user1')
2018-04-05 21:20:39 +02:00
@autocheck
def autocheck_option(api, pathread, pathwrite, confread, confwrite, **kwargs):
expected_name = pathread.split('.')[-1]
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
current_name = api.option(pathread).option.name()
assert current_name == api.forcepermissive.option(pathread).option.name()
assert current_name == api.unrestraint.option(pathread).option.name()
doc = api.option(pathread).option.doc()
assert doc == api.forcepermissive.option(pathread).option.doc()
assert doc == api.unrestraint.option(pathread).option.doc()
elif not kwargs.get('propertyerror', False):
raises(PropertiesOptionError, "api.option(pathread).option.name()")
current_name = api.forcepermissive.option(pathread).option.name()
assert current_name == api.unrestraint.option(pathread).option.name()
raises(PropertiesOptionError, "api.option(pathread).option.doc()")
doc = api.forcepermissive.option(pathread).option.doc()
assert doc == api.unrestraint.option(pathread).option.doc()
else:
raises(PropertiesOptionError, "api.option(pathread).option.name()")
raises(PropertiesOptionError, "api.forcepermissive.option(pathread).option.name()")
current_name = api.unrestraint.option(pathread).option.name()
raises(PropertiesOptionError, "api.option(pathread).option.doc()")
raises(PropertiesOptionError, "api.forcepermissive.option(pathread).option.doc()")
doc = api.unrestraint.option(pathread).option.doc()
assert current_name == expected_name
if expected_name.endswith('val1') or expected_name.endswith('val2'):
expected_name = expected_name[:-4]
if kwargs['symlink']:
assert doc == "{}'s option link".format(expected_name)
else:
assert doc == "{}'s option".format(expected_name)
2017-10-25 08:46:22 +02:00
2017-11-29 07:14:29 +01:00
@autocheck
2017-12-04 20:05:36 +01:00
def autocheck_permissive(api, pathread, pathwrite, confread, confwrite, **kwargs):
"""test permissive for hidden and disabled value
"""
2017-11-18 14:51:00 +01:00
# no permissive before
2017-12-04 20:05:36 +01:00
assert api.unrestraint.config(confread).option(pathread).permissive.get() == frozenset()
2017-11-18 14:51:00 +01:00
if kwargs.get('permissive_od', False):
2017-12-04 20:05:36 +01:00
assert api.unrestraint.config(confread).option(pathread.rsplit('.', 1)[0]).permissive.get() == frozenset()
# cannot access to hidden value without forcepermissive
# and to disabled value (with forcepermissive too)
2017-11-23 16:56:14 +01:00
#
# with meta confread == confwrite
2017-12-04 20:05:36 +01:00
_autocheck_default_value(api, pathread, confread, **kwargs)
2017-11-18 14:51:00 +01:00
# set permissive
2017-12-04 20:05:36 +01:00
api.unrestraint.config(confwrite).option(pathwrite).permissive.set(frozenset(['disabled']))
2017-11-29 07:14:29 +01:00
callback = kwargs['callback']
if callback:
2017-12-04 20:05:36 +01:00
if pathread.endswith('val1') or pathread.endswith('val2'):
call_path = pathread[:-4] + 'call' + pathread[-4:]
2017-11-29 07:14:29 +01:00
else:
2017-12-04 20:05:36 +01:00
call_path = pathread + 'call'
2017-11-29 07:14:29 +01:00
api.unrestraint.config(confwrite).option(call_path).permissive.set(frozenset(['disabled']))
2017-11-18 14:51:00 +01:00
# have permissive
2017-12-04 20:05:36 +01:00
assert api.unrestraint.config(confwrite).option(pathread).permissive.get() == frozenset(['disabled'])
2017-11-23 16:56:14 +01:00
if confwrite != confread:
2017-12-04 20:05:36 +01:00
assert api.unrestraint.config(confread).option(pathread).permissive.get() == frozenset(['disabled'])
2017-11-18 14:51:00 +01:00
# can access to disabled value
ckwargs = copy(kwargs)
ckwargs['propertyerror'] = False
2017-12-04 20:05:36 +01:00
_autocheck_default_value(api, pathread, confread, **ckwargs)
2017-11-18 14:51:00 +01:00
2017-12-04 20:05:36 +01:00
api.unrestraint.config(confwrite).option(pathwrite).permissive.set(frozenset(['disabled', 'hidden']))
2017-11-29 07:14:29 +01:00
if kwargs['callback']:
api.unrestraint.config(confwrite).option(call_path).permissive.set(frozenset(['disabled', 'hidden']))
2017-11-18 14:51:00 +01:00
# can access to all value except when optiondescript have hidden
if not ckwargs.get('permissive_od', False):
ckwargs['permissive'] = False
2017-12-04 20:05:36 +01:00
_autocheck_default_value(api, pathread, confread, **ckwargs)
2017-11-23 16:56:14 +01:00
if confread != confwrite:
2017-12-04 20:05:36 +01:00
_autocheck_default_value(api, pathread, confwrite, **ckwargs)
2017-11-18 14:51:00 +01:00
if ckwargs.get('permissive_od', False):
# set permissive to OptionDescription
2017-12-04 20:05:36 +01:00
api.unrestraint.config(confwrite).option(pathwrite.rsplit('.', 1)[0]).permissive.set(frozenset(['disabled',
2017-11-23 16:56:14 +01:00
'hidden']))
2017-11-18 14:51:00 +01:00
ckwargs['permissive'] = False
2017-12-04 20:05:36 +01:00
_autocheck_default_value(api, pathread, confread, **ckwargs)
2017-11-23 16:56:14 +01:00
if confread != confwrite:
2017-12-04 20:05:36 +01:00
_autocheck_default_value(api, pathread, confwrite, **ckwargs)
2017-11-18 14:51:00 +01:00
# only hidden
2017-12-04 20:05:36 +01:00
api.unrestraint.config(confwrite).option(pathwrite).permissive.set(frozenset(['hidden']))
2017-11-29 07:14:29 +01:00
if callback:
api.unrestraint.config(confwrite).option(call_path).permissive.set(frozenset(['hidden']))
2017-11-18 14:51:00 +01:00
if ckwargs.get('permissive_od', False):
2017-12-04 20:05:36 +01:00
_autocheck_default_value(api, pathread, confread, **ckwargs)
2017-11-23 16:56:14 +01:00
if confread != confwrite:
2017-12-04 20:05:36 +01:00
_autocheck_default_value(api, pathread, confwrite, **ckwargs)
api.unrestraint.config(confwrite).option(pathwrite.rsplit('.', 1)[0]).permissive.set(frozenset(['hidden']))
2017-11-18 14:51:00 +01:00
ckwargs = copy(kwargs)
ckwargs['permissive'] = False
2017-12-04 20:05:36 +01:00
_autocheck_default_value(api, pathread, confread, **ckwargs)
2017-11-23 16:56:14 +01:00
if confread != confwrite:
2017-12-04 20:05:36 +01:00
_autocheck_default_value(api, pathread, confwrite, **ckwargs)
2017-11-18 14:51:00 +01:00
# no permissive
2017-12-04 20:05:36 +01:00
api.unrestraint.config(confwrite).option(pathwrite).permissive.set(frozenset())
2017-11-29 07:14:29 +01:00
if callback:
api.unrestraint.config(confwrite).option(call_path).permissive.set(frozenset())
2017-11-18 14:51:00 +01:00
if ckwargs.get('permissive_od', False):
2017-12-04 20:05:36 +01:00
_autocheck_default_value(api, pathread, confread, **ckwargs)
2017-11-23 16:56:14 +01:00
if confread != confwrite:
2017-12-04 20:05:36 +01:00
_autocheck_default_value(api, pathread, confwrite, **ckwargs)
api.unrestraint.config(confwrite).option(pathwrite.rsplit('.', 1)[0]).permissive.set(frozenset())
_autocheck_default_value(api, pathread, confread, **kwargs)
2017-11-23 16:56:14 +01:00
if confread != confwrite:
2017-12-04 20:05:36 +01:00
_autocheck_default_value(api, pathread, confwrite, **kwargs)
2017-11-18 14:51:00 +01:00
2017-11-23 16:56:14 +01:00
@autocheck
2017-12-04 20:05:36 +01:00
def autocheck_option_get(api, pathread, pathwrite, confread, confwrite, **kwargs):
if '.' in pathread:
name = pathread.rsplit('.', 1)[1]
2017-11-23 16:56:14 +01:00
else:
2017-12-04 20:05:36 +01:00
name = pathread
2018-04-07 20:15:19 +02:00
assert api.unrestraint.option(pathread).option.name() == name
2017-11-23 16:56:14 +01:00
2017-11-18 14:51:00 +01:00
2017-11-23 16:56:14 +01:00
@autocheck
2017-12-04 20:05:36 +01:00
def autocheck_find(api, pathread, pathwrite, confread, confwrite, **kwargs):
2017-11-23 16:56:14 +01:00
def _getoption(opt):
2018-04-10 12:33:51 +02:00
opt = opt.option.get()
2017-11-23 16:56:14 +01:00
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
2017-12-04 20:05:36 +01:00
if '.' in pathread:
name = pathread.rsplit('.', 1)[1]
2017-11-23 16:56:14 +01:00
else:
2017-12-04 20:05:36 +01:00
name = pathread
2018-04-10 12:33:51 +02:00
option = _getoption(api.unrestraint.option(pathread))
2017-11-23 16:56:14 +01:00
def do(conf):
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
2018-04-07 20:15:19 +02:00
assert option == _getoption(api.config(conf).option.find(name, first=True))
assert option == _getoption(api.forcepermissive.config(conf).option.find(name, first=True))
2017-11-23 16:56:14 +01:00
elif kwargs.get('permissive', False):
2018-04-07 20:15:19 +02:00
raises(AttributeError, "api.config(conf).option.find(name, first=True)")
assert option == _getoption(api.forcepermissive.config(conf).option.find(name, first=True))
2017-11-23 16:56:14 +01:00
else:
2018-04-07 20:15:19 +02:00
raises(AttributeError, "api.config(conf).option.find(name, first=True)")
raises(AttributeError, "api.forcepermissive.config(conf).option.find(name, first=True)")
assert option == _getoption(api.unrestraint.config(conf).option.find(name, first=True))
2017-11-23 16:56:14 +01:00
assert [option] == _getoptions(api.unrestraint.config(conf).option.find(name))
do(confread)
if confread != confwrite:
do(confwrite)
2018-04-07 20:15:19 +02:00
def check_all(cfg, paths_, path, meta, multi, default, default_multi, require, consistency, callback, symlink, weakrefs, **kwargs):
2017-11-23 16:56:14 +01:00
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
2017-11-28 22:42:30 +01:00
if not default or multi is submulti:
2017-11-23 16:56:14 +01:00
if not multi:
default_value = None
else:
default_value = []
else:
default_value = value
2017-11-28 22:42:30 +01:00
kwargs['default'] = default_value
2017-11-23 16:56:14 +01:00
is_dyn = False
2017-11-28 22:42:30 +01:00
is_master = False
2017-11-23 16:56:14 +01:00
dyns = []
has_value = False
2018-04-07 20:15:19 +02:00
for cpath, options in paths_.items():
2017-11-23 16:56:14 +01:00
if options is None:
break
if '.' in cpath:
dirname, name = cpath.split('.')[-2:]
2017-12-02 22:53:57 +01:00
for dname in cpath.split('.')[:-1]:
if options.get(dname, {}).get('dyn'):
is_dyn = True
if options.get(dname, {}).get('master'):
is_master = True
2017-11-23 16:56:14 +01:00
else:
dirname = ''
name = cpath
if options.get(dirname, {}).get('hidden'):
continue
allow_req = require and req
2017-12-02 22:53:57 +01:00
no_propertieserror = not options.get(name, {}).get('disabled') and not options.get(name, {}).get('hidden')
2017-11-23 16:56:14 +01:00
if is_dyn:
dyns.append(no_propertieserror or allow_req)
2017-12-02 22:53:57 +01:00
if not is_dyn and (no_propertieserror or allow_req):
2017-11-23 16:56:14 +01:00
dico[cpath] = default_value
2017-12-04 20:05:36 +01:00
if symlink:
dico[cpath + 'link'] = default_value
2017-11-23 16:56:14 +01:00
if path == cpath:
dico_value[cpath] = value
2017-12-04 20:05:36 +01:00
if symlink:
dico_value[cpath + 'link'] = value
2017-11-23 16:56:14 +01:00
else:
dico_value[cpath] = default_value
2017-12-04 20:05:36 +01:00
if symlink:
dico_value[cpath + 'link'] = default_value
2017-11-28 22:42:30 +01:00
2017-11-23 16:56:14 +01:00
has_value = True
2017-12-02 22:53:57 +01:00
isslave = False
if '.' in path and is_master and not path.rsplit('.', 1)[1].startswith('first'):
isslave = True
if not multi is submulti:
kwargs['default'] = None
if is_dyn and dyns:
2017-11-23 16:56:14 +01:00
idx = 0
2018-04-07 20:15:19 +02:00
for cpath in list(paths_.keys())[len(dyns):]:
2017-11-23 16:56:14 +01:00
if dyns[idx]:
dico[cpath] = default_value
2017-12-04 20:05:36 +01:00
if symlink:
dico[cpath + 'link'] = default_value
2017-11-23 16:56:14 +01:00
if path == cpath:
dico_value[cpath] = value
2017-12-04 20:05:36 +01:00
if symlink:
dico_value[cpath + 'link'] = value
2017-11-23 16:56:14 +01:00
else:
dico_value[cpath] = default_value
2017-12-04 20:05:36 +01:00
if symlink:
dico_value[cpath + 'link'] = default_value
2017-11-23 16:56:14 +01:00
idx += 1
if idx == len(dyns):
idx = 0
if require:
if not req:
dico['extraoptrequire'] = None
dico_value['extraoptrequire'] = None
2017-12-04 20:05:36 +01:00
if symlink:
dico['extraoptrequirelink'] = None
dico_value['extraoptrequirelink'] = None
2017-11-23 16:56:14 +01:00
else:
dico['extraoptrequire'] = 'value'
dico_value['extraoptrequire'] = 'value'
2017-12-04 20:05:36 +01:00
if symlink:
dico['extraoptrequirelink'] = 'value'
dico_value['extraoptrequirelink'] = 'value'
2017-11-23 16:56:14 +01:00
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_value[cpath + 'extraoptconsistencyval1'] = value
2017-12-02 22:53:57 +01:00
if is_master:
spath = cpath.split('.')
spath[-2] = spath[-2][:-1] + '2'
spath[-3] = spath[-3][:-1] + '2'
npath = '.'.join(spath) + 'extraoptconsistencyval2'
else:
npath = cpath[:-2] + '2.' + 'extraoptconsistencyval2'
dico[npath] = value
dico_value[npath] = value
2017-11-23 16:56:14 +01:00
else:
dico[cpath + 'extraoptconsistency'] = value
dico_value[cpath + 'extraoptconsistency'] = value
2017-11-28 22:42:30 +01:00
if is_master:
2018-04-07 20:15:19 +02:00
for cpath in list(paths_.keys())[len(dyns):]:
2017-12-02 22:53:57 +01:00
if cpath.endswith('.first') or cpath.endswith('.firstval1') or cpath.endswith('.firstval2'):
2017-11-28 22:42:30 +01:00
second_path = cpath.rsplit('.', 1)[0] + '.second'
third_path = cpath.rsplit('.', 1)[0] + '.third'
cons_path = cpath.rsplit('.', 1)[0] + '.extraoptconsistency'
2017-12-02 22:53:57 +01:00
if is_dyn:
suffix = cpath[-4:]
second_path += suffix
third_path += suffix
cons_path += suffix
2017-11-28 22:42:30 +01:00
#
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
2017-12-04 20:05:36 +01:00
if symlink:
dico[second_path + 'link'] = [dvalue] * len_master
2017-11-28 22:42:30 +01:00
if third_path in dico:
dico[third_path] = [dvalue] * len_master
2017-12-04 20:05:36 +01:00
if symlink:
dico[third_path + 'link'] = [dvalue] * len_master
2017-11-28 22:42:30 +01:00
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
2017-12-04 20:05:36 +01:00
if symlink:
dico_value[second_path + 'link'] = [dvalue] * len_master
2017-11-28 22:42:30 +01:00
if third_path in dico_value:
dico_value[third_path] = [dvalue] * len_master
2017-12-04 20:05:36 +01:00
if symlink:
dico_value[third_path + 'link'] = [dvalue] * len_master
2017-11-28 22:42:30 +01:00
if cons_path in dico_value:
dico_value[cons_path] = [dvalue] * len_master
2017-12-02 22:53:57 +01:00
return is_dyn, dico, dico_value
if DISPLAY:
2017-11-18 14:51:00 +01:00
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'
2017-11-23 16:56:14 +01:00
if require:
text += u' with requirement'
if consistency:
text += u' with consistency'
2017-11-13 22:45:53 +01:00
text += u', kwargs: {}'.format(kwargs)
print(text)
2017-11-20 17:01:36 +01:00
if not require:
requires = [False]
else:
requires = [False, True]
2017-11-23 16:56:14 +01:00
confwrite = confread = None
idx = 0
2017-11-20 17:01:36 +01:00
for req in requires:
2017-12-02 22:53:57 +01:00
is_dyn, kwargs['make_dict'], kwargs['make_dict_value'] = _build_make_dict()
2017-11-28 22:42:30 +01:00
kwargs['callback'] = callback
2017-12-04 20:05:36 +01:00
kwargs['symlink'] = symlink
2017-11-20 17:01:36 +01:00
for func in autocheck_registers:
2017-11-23 16:56:14 +01:00
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)
2017-11-28 22:42:30 +01:00
ckwargs = copy(kwargs)
2018-03-31 21:06:19 +02:00
if meta:
api.owner.set('meta')
ckwargs['owner'] = owners.meta
else:
ckwargs['owner'] = OWNER
2017-11-23 16:56:14 +01:00
if api.unrestraint.option(path).option.isslave():
2017-11-28 22:42:30 +01:00
dirname = path.rsplit('.', 1)[0]
master_path = dirname + '.first'
2017-12-02 22:53:57 +01:00
master_path_2 = None
if dirname.endswith('val1') or dirname.endswith('val2'):
master_path += 'val1'
master_path = master_path.replace('val2', 'val1')
master_path_2 = master_path.replace('val1', 'val2')
2017-11-28 22:42:30 +01:00
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
2017-12-04 20:05:36 +01:00
if symlink:
ckwargs['make_dict'][master_path + 'link'] = value
ckwargs['make_dict_value'][master_path + 'link'] = value
2017-12-02 22:53:57 +01:00
if master_path_2:
api.option(master_path_2).value.set(value)
ckwargs['make_dict'][master_path_2] = value
ckwargs['make_dict_value'][master_path_2] = value
2017-12-04 20:05:36 +01:00
if symlink:
ckwargs['make_dict'][master_path_2 + 'link'] = value
ckwargs['make_dict_value'][master_path_2 + 'link'] = value
2017-11-28 22:42:30 +01:00
if default_multi:
if multi is not submulti:
dvalue = SECOND_VALUE
else:
dvalue = LIST_SECOND_VALUE
elif multi is submulti:
dvalue = []
else:
dvalue = None
2017-12-02 22:53:57 +01:00
def do(suffix, oldsuffix=None):
if suffix:
ldirname = dirname.replace(oldsuffix, suffix)
else:
ldirname = dirname
npath = ldirname + '.second' + suffix
if npath in ckwargs['make_dict']:
ckwargs['make_dict'][npath] = [dvalue] * len(value)
ckwargs['make_dict_value'][npath] = [dvalue] * len(value)
2017-12-04 20:05:36 +01:00
if symlink:
ckwargs['make_dict'][npath + 'link'] = [dvalue] * len(value)
ckwargs['make_dict_value'][npath + 'link'] = [dvalue] * len(value)
2017-12-02 22:53:57 +01:00
if path == npath:
ckwargs['make_dict_value'][npath][-1] = ckwargs['make_dict_value'][master_path][-1]
2017-12-04 20:05:36 +01:00
if symlink:
ckwargs['make_dict_value'][npath + 'link'][-1] = ckwargs['make_dict_value'][master_path][-1]
2017-12-02 22:53:57 +01:00
npath = ldirname + '.third' + suffix
if npath in ckwargs['make_dict']:
ckwargs['make_dict'][npath] = [dvalue] * len(value)
ckwargs['make_dict_value'][npath] = [dvalue] * len(value)
2017-12-04 20:05:36 +01:00
if symlink:
ckwargs['make_dict'][npath + 'link'] = [dvalue] * len(value)
ckwargs['make_dict_value'][npath + 'link'] = [dvalue] * len(value)
2017-12-02 22:53:57 +01:00
if path == npath:
ckwargs['make_dict_value'][npath][-1] = ckwargs['make_dict_value'][master_path][-1]
2017-12-04 20:05:36 +01:00
if symlink:
ckwargs['make_dict_value'][npath + 'link'][-1] = ckwargs['make_dict_value'][master_path][-1]
2017-12-02 22:53:57 +01:00
npath = ldirname + '.extraoptconsistency' + suffix
if npath in ckwargs['make_dict']:
ckwargs['make_dict'][npath] = [dvalue] * len(value)
ckwargs['make_dict_value'][npath] = [dvalue] * len(value)
2017-12-04 20:05:36 +01:00
if symlink:
ckwargs['make_dict'][npath + 'link'] = [dvalue] * len(value)
ckwargs['make_dict_value'][npath + 'link'] = [dvalue] * len(value)
2017-12-02 22:53:57 +01:00
if not is_dyn:
do('')
else:
#do(dirname[-4:])
do('val1', 'val2')
do('val2', 'val1')
2017-11-28 22:42:30 +01:00
2017-11-20 17:01:36 +01:00
#FIXME devrait etre dans la config ca ...
2017-12-13 22:15:34 +01:00
api.property.read_write()
2017-11-20 17:01:36 +01:00
if req:
2017-12-04 20:05:36 +01:00
name = 'extraoptrequire'
if symlink:
name += 'link'
api.option(name).value.set('value')
2017-11-20 17:01:36 +01:00
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__))
2017-12-04 20:05:36 +01:00
pathread = path
if symlink:
pathwrite = path + 'link'
else:
pathwrite = path
2017-11-20 17:01:36 +01:00
try:
2017-12-04 20:05:36 +01:00
func(api, pathread, pathwrite, confread, confwrite, **ckwargs)
2017-11-20 17:01:36 +01:00
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'
2017-11-28 22:42:30 +01:00
if default is True:
2017-11-20 17:01:36 +01:00
msg += u' with default value'
2017-11-28 22:42:30 +01:00
if callback is True:
msg += u' (callback)'
2017-12-04 20:05:36 +01:00
if symlink is True:
msg += u' (symlink)'
2017-11-20 17:01:36 +01:00
print(u'{}: {}'.format(msg, ckwargs))
raise err
2017-11-23 16:56:14 +01:00
del api
del ncfg
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-12-04 20:05:36 +01:00
def make_conf(options, meta, multi, default, default_multi, require, consistency, callback, symlink):
2017-11-13 22:45:53 +01:00
weakrefs = []
2017-11-20 17:01:36 +01:00
dyn = []
goptions = []
2017-11-28 22:42:30 +01:00
def make_option(path, option_infos, in_master, master):
2017-10-22 09:48:08 +02:00
option_type = 'str'
option_properties = []
2017-11-20 17:01:36 +01:00
option_requires = []
isslave = False
2017-12-04 20:05:36 +01:00
if in_master and symlink:
return None, None, None
2017-11-12 20:11:56 +01:00
if option_infos is not None:
2018-03-31 21:06:19 +02:00
if require:
return None, None, None
2017-11-12 20:11:56 +01:00
for prop in PROPERTIES:
if option_infos.get(prop, False) is True:
2017-11-20 17:01:36 +01:00
if not require:
option_properties.append(prop)
else:
option_requires.append({'option': goptions[0], 'expected': None,
'action': prop})
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 = {}
2017-11-28 22:42:30 +01:00
call_kwargs = {}
2017-10-22 09:48:08 +02:00
if option_properties != []:
kwargs['properties'] = tuple(option_properties)
2017-11-28 22:42:30 +01:00
if callback:
call_kwargs['properties'] = tuple(option_properties)
2017-11-20 17:01:36 +01:00
if option_requires != []:
2017-11-28 22:42:30 +01:00
if callback:
call_kwargs['requires'] = option_requires
else:
kwargs['requires'] = option_requires
2017-11-20 17:01:36 +01:00
if multi and path is not 'extraoptrequire':
kwargs['multi'] = multi
2017-11-28 22:42:30 +01:00
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
2017-11-28 22:42:30 +01:00
if callback:
kwargs['callback'] = return_str
call_kwargs['default'] = value
else:
kwargs['default'] = value
elif callback:
2017-12-04 20:05:36 +01:00
return None, None, None
2017-11-20 17:01:36 +01:00
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
2017-10-22 09:48:08 +02:00
tiramisu_option = OPTIONS_TYPE[option_type]['option']
2017-11-28 22:42:30 +01:00
if callback:
largs = [path + 'call', "{}'s callback option".format(path)]
objcall = tiramisu_option(*largs, **call_kwargs)
kwargs['callback_params'] = Params(ParamOption(objcall))
2017-11-28 22:42:30 +01:00
else:
objcall = None
2017-12-04 20:05:36 +01:00
if symlink and not path.endswith('extraoptconsistency'):
sobj = tiramisu_option(args[0] + 'link', args[1] + ' link', **kwargs)
kwargs = {}
args[1] = sobj
tiramisu_option = SymLinkOption
else:
sobj = None
2017-11-13 22:45:53 +01:00
obj = tiramisu_option(*args, **kwargs)
2017-11-20 17:01:36 +01:00
if not 'extraopt' in path and consistency:
if require:
2017-12-04 20:05:36 +01:00
if symlink:
gopt = goptions[2]
else:
gopt = goptions[1]
2017-11-20 17:01:36 +01:00
else:
gopt = goptions[0]
2018-03-31 21:06:19 +02:00
obj.impl_add_consistency('not_equal', gopt, warnings_only=True, transitive=False)
2017-12-04 20:05:36 +01:00
return obj, objcall, sobj
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:
2017-12-04 20:05:36 +01:00
if symlink:
return
2017-11-12 20:11:56 +01:00
optiondescription = DynOptionDescription
kwargs['callback'] = return_list
2017-11-20 17:01:36 +01:00
dyn.append(path)
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-20 17:01:36 +01:00
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():
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]
2017-12-02 22:53:57 +01:00
in_master = False
2017-11-28 22:42:30 +01:00
if '.' in path:
name_od = path.rsplit('.', 1)[0]
2017-12-02 22:53:57 +01:00
if '.' in name_od:
subod, name_od = name_od.split('.')
oddescr = collect_options.get(subod, {})
else:
oddescr = collect_options
in_master = oddescr.get(name_od, {}).get('properties', {}).get('master')
2017-11-28 22:42:30 +01:00
master = in_master and path.endswith('first')
2017-12-04 20:05:36 +01:00
obj, objcall, sobj = make_option(option_name, option.get(option_name), in_master, master)
2017-11-28 22:42:30 +01:00
if obj is None:
return None, None, None
weakrefs.append(weakref.ref(obj))
if callback:
weakrefs.append(weakref.ref(objcall))
2017-12-04 20:05:36 +01:00
if sobj is not None:
weakrefs.append(weakref.ref(sobj))
2017-11-28 22:42:30 +01:00
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)
2017-11-20 17:01:36 +01:00
goptions.append(obj)
2017-11-28 22:42:30 +01:00
if callback:
local_collect_options.setdefault('options', []).append(objcall)
goptions.append(objcall)
2017-12-04 20:05:36 +01:00
if sobj is not None:
local_collect_options.setdefault('options', []).append(sobj)
goptions.append(sobj)
2017-10-22 09:48:08 +02:00
rootod = make_optiondescriptions('root', collect_options)
if rootod is None:
2017-11-28 22:42:30 +01:00
return None, None, None
2017-11-13 22:45:53 +01:00
cfg = Config(rootod, session_id='conftest')
weakrefs.append(weakref.ref(cfg))
2017-11-20 17:01:36 +01:00
del goptions
return cfg, weakrefs, dyn
2017-10-22 09:48:08 +02:00
DICT_PATHS = [
2018-04-05 21:13:24 +02:00
#test a config without optiondescription
OrderedDict([('first', {}),
('second', {'second': {'disabled': True}}),
('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 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
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}})]),
2018-04-05 21:13:24 +02:00
#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)]),
#test a config with dyn subsubod with masterslave
OrderedDict([('subod.subsubod.first', {'subod': {'dyn': True}, 'subsubod': {'master': True}}),
('subod.subsubod.second', {'subod': {'dyn': True}, 'subsubod' : {'master': True}, 'second': {'disabled': True, 'slave': True}}),
('subod.subsubod.third', {'subod': {'dyn': True}, 'subsubod': {'master': True}, 'third': {'hidden': True, 'slave': True}}),
('subodval1.subsubodval1.firstval1', None),
('subodval1.subsubodval1.secondval1', None),
('subodval1.subsubodval1.thirdval1', None),
('subodval2.subsubodval2.firstval2', None),
('subodval2.subsubodval2.secondval2', None),
('subodval2.subsubodval2.thirdval2', None)]),
]
2017-11-13 22:45:53 +01:00
@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
2017-11-13 22:45:53 +01:00
def test_options(paths):
def get_kwargs_option(options, kwargs, od=False):
2018-04-07 20:15:19 +02:00
if options.get('mandatory', False):
kwargs['mandatory'] = True
2017-11-13 22:45:53 +01:00
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())
2018-03-31 21:06:19 +02:00
2018-04-05 21:13:24 +02:00
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):
for symlink in (False, True):
2017-12-04 20:05:36 +01:00
if callback and default_multi:
continue
2018-04-05 21:13:24 +02:00
for default in (False, True):
for multi in (False, True, submulti):
# for meta in (False,):
# for callback in (False,):
# for consistency in (False,):
# for require in (False,):
# for default_multi in (False,):
# for symlink in (False,):
# if callback and default_multi:
# continue
# for default in (False,):
2018-04-09 21:37:49 +02:00
# for multi in (True,):
# print(meta, callback, consistency, require, default_multi, symlink, default, multi)
2017-12-04 20:05:36 +01:00
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, symlink)
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, symlink,
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, symlink,
weakrefs, **get_kwargs(lpath))
del cfg
check_deref(weakrefs)