tiramisu/test/api/test_owner.py

942 lines
40 KiB
Python
Raw Normal View History

"""test API
2017-10-22 09:48:08 +02:00
"""
import pytest
from py.test import raises
from .autopath import do_autopath
do_autopath()
from tiramisu import Config, StrOption, OptionDescription, MasterSlaves, DynOptionDescription, \
getapi
2017-10-25 08:46:22 +02:00
from tiramisu.error import PropertiesOptionError, APIError
from collections import OrderedDict
2017-10-22 09:48:08 +02:00
ICON = u'\u2937'
OPTIONS_TYPE = {'str': {'type': str,
'option': StrOption}
}
PROPERTIES = ['hidden', 'disabled']
DISPLAY = True
#DISPLAY = False
2017-10-22 09:48:08 +02:00
def return_list(val=None, suffix=None):
if val:
return val
else:
return ['val1', 'val2']
def display_info(func):
def wrapper(*args, **kwargs):
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
def autocheck_owner_without_value(api, path, **kwargs):
"""check different value of owner when any value is set to this option
"""
try:
isslave = api.forcepermissive.option(path).option.isslave()
2017-10-22 09:48:08 +02:00
except:
isslave = False
# check if owner is a string "default"
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
assert api.option(path).owner.get() == 'default'
2017-10-22 09:48:08 +02:00
else:
if not isslave:
raises(PropertiesOptionError, "api.option(path).owner.get()")
2017-10-22 09:48:08 +02:00
else:
raises(PropertiesOptionError, "api.option(path, 0).owner.get()")
raises(APIError, "api.unrestraint.option(path).owner.get()")
2017-10-22 09:48:08 +02:00
if not kwargs.get('propertyerror', False):
if not isslave:
assert api.forcepermissive.option(path).owner.get() == 'default'
2017-10-22 09:48:08 +02:00
else:
assert api.forcepermissive.option(path, 0).owner.get() == 'default'
2017-10-22 09:48:08 +02:00
else:
if not isslave:
raises(PropertiesOptionError, "api.forcepermissive.option(path).owner.get()")
2017-10-22 09:48:08 +02:00
else:
raises(PropertiesOptionError, "api.forcepermissive.option(path, 0).owner.get()")
2017-10-22 09:48:08 +02:00
# check if default owner
raises(APIError, "api.unrestraint.option(path).owner.isdefault()")
2017-10-22 09:48:08 +02:00
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
assert api.option(path).owner.isdefault()
2017-10-22 09:48:08 +02:00
else:
raises(PropertiesOptionError, "api.option(path).owner.isdefault()")
2017-10-22 09:48:08 +02:00
if not kwargs.get('propertyerror', False):
if not isslave:
assert api.forcepermissive.option(path).owner.isdefault()
else:
assert api.forcepermissive.option(path, 0).owner.isdefault()
2017-10-22 09:48:08 +02:00
else:
raises(PropertiesOptionError, "api.forcepermissive.option(path).owner.isdefault()")
2017-10-22 09:48:08 +02:00
@autocheck
def autocheck_value(api, path, **kwargs):
"""set and get values
"""
# check if is a multi, a master or a slave
if not kwargs.get('propertyerror', False):
multi = api.forcepermissive.option(path).option.ismulti()
ismaster = api.forcepermissive.option(path).option.ismaster()
isslave = api.forcepermissive.option(path).option.isslave()
2017-10-22 09:48:08 +02:00
else:
raises(PropertiesOptionError, "api.forcepermissive.option(path).option.ismulti()")
multi = api.unrestraint.option(path).option.ismulti()
ismaster = api.unrestraint.option(path).option.ismaster()
isslave = api.unrestraint.option(path).option.isslave()
2017-10-22 09:48:08 +02:00
# set default value (different if value is multi or not)
if not multi:
first_value = 'myvalue'
second_value = 'myvalue1'
else:
first_value = ['myvalue']
second_value = ['myvalue', 'myvalue1']
if multi and not isslave:
empty_value = []
else:
empty_value = None
# test default value (should be empty) without permissive
# 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.option(path).value.get() == empty_value
2017-10-22 09:48:08 +02:00
else:
raises(PropertiesOptionError, "api.option(path).value.get()")
2017-10-22 09:48:08 +02:00
# test default value (should be empty) with permissive
# cannot test for slave (we cannot get all values for a slave)
raises(APIError, "api.unrestraint.option(path).value.get()")
2017-10-22 09:48:08 +02:00
if not isslave:
if not kwargs.get('propertyerror', False):
assert api.forcepermissive.option(path).value.get() == empty_value
2017-10-22 09:48:08 +02:00
else:
raises(PropertiesOptionError, "api.forcepermissive.option(path).value.get()")
2017-10-22 09:48:08 +02:00
# set a value without permissive
# for slave should have an index and good length
2017-10-22 09:48:08 +02:00
# for master must append, not set
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if ismaster:
raises(APIError, "api.option(path, 0).value.set(first_value[0])")
2017-11-12 14:33:05 +01:00
api.option(path).value.set([first_value[0]])
2017-10-22 09:48:08 +02:00
elif isslave:
api.option(path, 0).value.set(first_value[0])
2017-10-22 09:48:08 +02:00
raise Exception('pouet')
else:
api.option(path).value.set(first_value)
2017-10-22 09:48:08 +02:00
else:
if ismaster:
2017-11-12 14:33:05 +01:00
raises(PropertiesOptionError, "api.option(path).value.set([first_value[0]])")
2017-10-22 09:48:08 +02:00
elif isslave:
raises(PropertiesOptionError, "api.option(path, 0).value.set(first_value[0])")
2017-10-22 09:48:08 +02:00
else:
raises(PropertiesOptionError, "api.option(path).value.set(first_value)")
2017-10-22 09:48:08 +02:00
# get value after set value without permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if isslave:
assert api.option(path, 0).value.get() == first_value[0]
2017-10-22 09:48:08 +02:00
else:
assert api.option(path).value.get() == first_value
2017-10-22 09:48:08 +02:00
elif kwargs.get('permissive', False):
if isslave:
raises(PropertiesOptionError, "api.option(path, 0).value.get()")
assert api.forcepermissive.option(path, 0).value.get() == empty_value
2017-10-22 09:48:08 +02:00
else:
raises(PropertiesOptionError, "api.option(path).value.get()")
assert api.forcepermissive.option(path).value.get() == empty_value
2017-10-22 09:48:08 +02:00
else:
if isslave:
raises(PropertiesOptionError, "api.option(path, 0).value.get()")
raises(PropertiesOptionError, "api.forcepermissive.option(path, 0).value.get()")
2017-10-22 09:48:08 +02:00
else:
raises(PropertiesOptionError, "api.option(path).value.get()")
raises(PropertiesOptionError, "api.forcepermissive.option(path).value.get()")
2017-10-22 09:48:08 +02:00
# set a value with permissive
2017-10-25 08:46:22 +02:00
if ismaster:
raises(APIError, "api.unrestraint.option(path).value.set(second_value[1])")
2017-10-25 08:46:22 +02:00
elif isslave:
2017-11-12 14:33:05 +01:00
raises(APIError, "api.unrestraint.option(path).value.set([first_value[0], second_value[1]])")
2017-10-25 08:46:22 +02:00
else:
raises(APIError, "api.unrestraint.option(path).value.set(second_value)")
2017-10-22 09:48:08 +02:00
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if ismaster:
raises(APIError, "api.forcepermissive.option(path, 1).value.set(second_value[1])")
2017-11-12 14:33:05 +01:00
api.forcepermissive.option(path).value.set([first_value[0], second_value[1]])
2017-10-22 09:48:08 +02:00
elif isslave:
#FIXME
2017-11-12 14:33:05 +01:00
raises(PropertiesOptionError, "api.forcepermissive.option(path).value.set([first_value[0], second_value[1]])")
api.option(path, 1).value.set(second_value[1])
2017-10-22 09:48:08 +02:00
raise Exception('ca entre ici')
else:
api.option(path).value.set(second_value)
2017-10-22 09:48:08 +02:00
elif kwargs.get('permissive', False):
if ismaster:
2017-11-12 14:33:05 +01:00
api.forcepermissive.option(path).value.set([first_value[0], second_value[1]])
2017-10-22 09:48:08 +02:00
elif isslave:
api.forcepermissive.option(path, 1).value.set(second_value[1])
2017-10-22 09:48:08 +02:00
else:
api.forcepermissive.option(path).value.set(first_value)
2017-10-22 09:48:08 +02:00
else:
if ismaster:
2017-11-12 14:33:05 +01:00
raises(PropertiesOptionError, "api.forcepermissive.option(path).value.set([first_value[0]])")
2017-10-22 09:48:08 +02:00
elif isslave:
raises(PropertiesOptionError, "api.forcepermissive.option(path, 0).value.set(first_value[0])")
2017-10-22 09:48:08 +02:00
else:
raises(PropertiesOptionError, "api.forcepermissive.option(path).value.set(first_value)")
2017-10-22 09:48:08 +02:00
# get value after set value with permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if isslave:
assert api.option(path, 0).value.get() == second_value[0]
assert api.option(path, 1).value.get() == second_value[1]
2017-10-22 09:48:08 +02:00
else:
assert api.option(path).value.get() == second_value
2017-10-22 09:48:08 +02:00
elif kwargs.get('permissive', False):
if ismaster:
raises(PropertiesOptionError, "api.option(path).value.get()")
assert api.forcepermissive.option(path).value.get() == second_value
2017-10-22 09:48:08 +02:00
elif isslave:
raises(PropertiesOptionError, "api.option(path, 0).value.get()")
raises(PropertiesOptionError, "api.option(path, 1).value.get()")
assert api.forcepermissive.option(path, 1).value.get() == second_value[1]
2017-10-22 09:48:08 +02:00
else:
raises(PropertiesOptionError, "api.option(path).value.get()")
assert api.forcepermissive.option(path).value.get() == first_value
2017-10-22 09:48:08 +02:00
else:
if isslave:
raises(PropertiesOptionError, "api.option(path, 0).value.get()")
raises(PropertiesOptionError, "api.forcepermissive.option(path, 0).value.get()")
2017-10-22 09:48:08 +02:00
else:
raises(PropertiesOptionError, "api.option(path).value.get()")
raises(PropertiesOptionError, "api.forcepermissive.option(path).value.get()")
2017-10-22 09:48:08 +02:00
@autocheck
def autocheck_reset_value(api, path, **kwargs):
# check if is a multi, a master or a slave
2017-11-12 14:33:05 +01:00
multi = api.unrestraint.option(path).option.ismulti()
isslave = api.unrestraint.option(path).option.isslave()
2017-10-22 09:48:08 +02:00
# set default value (different if value is multi or not)
if not multi:
first_value = 'myvalue'
second_value = 'myvalue1'
else:
first_value = ['myvalue']
second_value = ['myvalue', 'myvalue1']
if multi and not isslave:
empty_value = []
else:
empty_value = None
# reset value without permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if not isslave:
api.option(path).value.reset()
2017-10-22 09:48:08 +02:00
else:
api.option(path, 0).value.reset()
2017-10-22 09:48:08 +02:00
else:
if not isslave:
raises(PropertiesOptionError, "api.option(path).value.reset()")
2017-10-22 09:48:08 +02:00
else:
raises(PropertiesOptionError, "api.option(path, 0).value.reset()")
2017-10-22 09:48:08 +02:00
# get value after reset value without permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if isslave:
assert api.option(path, 0).value.get() == empty_value
assert api.option(path, 1).value.get() == second_value[1]
2017-10-22 09:48:08 +02:00
else:
assert api.option(path).value.get() == empty_value
2017-10-22 09:48:08 +02:00
elif kwargs.get('permissive', False):
if isslave:
raises(PropertiesOptionError, "api.option(path, 0).value.get()")
assert api.forcepermissive.option(path, 0).value.get() == empty_value
assert api.forcepermissive.option(path, 1).value.get() == second_value[1]
2017-10-22 09:48:08 +02:00
else:
raises(PropertiesOptionError, "api.option(path).value.get()")
assert api.forcepermissive.option(path).value.get() == first_value
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:
api.forcepermissive.option(path).value.reset()
2017-10-22 09:48:08 +02:00
else:
api.forcepermissive.option(path, 1).value.reset()
2017-10-22 09:48:08 +02:00
elif kwargs.get('permissive', False):
if not isslave:
api.forcepermissive.option(path).value.reset()
2017-10-22 09:48:08 +02:00
else:
api.forcepermissive.option(path, 1).value.reset()
2017-10-22 09:48:08 +02:00
else:
if not isslave:
raises(PropertiesOptionError, "api.forcepermissive.option(path).value.reset()")
2017-10-22 09:48:08 +02:00
else:
raises(PropertiesOptionError, "api.forcepermissive.option(path, 1).value.reset()")
2017-10-22 09:48:08 +02:00
# get value after reset value with permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if isslave:
assert api.option(path, 0).value.get() == empty_value
assert api.option(path, 1).value.get() == empty_value
2017-10-22 09:48:08 +02:00
else:
assert api.option(path).value.get() == empty_value
2017-10-22 09:48:08 +02:00
elif kwargs.get('permissive', False):
if isslave:
raises(PropertiesOptionError, "api.option(path, 0).value.get()")
raises(PropertiesOptionError, "api.option(path, 1).value.get()")
assert api.forcepermissive.option(path, 0).value.get() == empty_value
assert api.forcepermissive.option(path, 1).value.get() == empty_value
2017-10-22 09:48:08 +02:00
else:
raises(PropertiesOptionError, "api.option(path).value.get()")
assert api.forcepermissive.option(path).value.get() == empty_value
2017-10-22 09:48:08 +02:00
@autocheck
def autocheck_value2(*args, **kwargs):
2017-10-25 08:46:22 +02:00
"""re set value
2017-10-22 09:48:08 +02:00
"""
autocheck_value(*args, **kwargs)
@autocheck
def autocheck_property(api, path, **kwargs):
"""get property from path
"""
# check if is a multi or a slave
2017-11-12 14:33:05 +01:00
multi = api.unrestraint.option(path).option.ismulti()
isslave = api.unrestraint.option(path).option.isslave()
2017-10-22 09:48:08 +02:00
# define properties
properties = ['prop1', 'prop2']
if multi and not isslave:
default_props = ['empty']
properties.append('empty')
else:
default_props = []
extra_properties = kwargs.get('extra_properties')
if extra_properties:
properties.extend(extra_properties)
default_props.extend(extra_properties)
properties = tuple(properties)
# get properties without permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if not isslave:
assert set(api.option(path).property.get()) == set(default_props)
2017-10-22 09:48:08 +02:00
else:
assert set(api.option(path, 0).property.get()) == set(default_props)
assert set(api.option(path, 1).property.get()) == set(default_props)
2017-10-22 09:48:08 +02:00
else:
2017-11-12 14:33:05 +01:00
if not isslave:
raises(PropertiesOptionError, "api.option(path).property.get()")
else:
raises(PropertiesOptionError, "api.option(path, 0).property.get()")
2017-10-22 09:48:08 +02:00
# get properties with permissive
2017-10-25 08:46:22 +02:00
if not isslave:
raises(APIError, "api.unrestraint.option(path).property.get()")
2017-10-25 08:46:22 +02:00
else:
raises(APIError, "api.unrestraint.option(path, 0).property.get()")
2017-10-22 09:48:08 +02:00
if not kwargs.get('propertyerror', False):
if not isslave:
assert set(api.forcepermissive.option(path).property.get()) == set(default_props)
2017-10-22 09:48:08 +02:00
else:
assert set(api.forcepermissive.option(path, 0).property.get()) == set(default_props)
assert set(api.forcepermissive.option(path, 1).property.get()) == set(default_props)
2017-10-22 09:48:08 +02:00
else:
if not isslave:
raises(PropertiesOptionError, "api.forcepermissive.option(path).property.get()")
2017-10-22 09:48:08 +02:00
else:
raises(PropertiesOptionError, "api.forcepermissive.option(path, 0).property.get()")
2017-10-22 09:48:08 +02:00
# set properties without permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
api.option(path).property.set(properties)
2017-10-22 09:48:08 +02:00
else:
2017-11-12 14:33:05 +01:00
if not isslave:
raises(PropertiesOptionError, "api.option(path).property.set(properties)")
else:
raises(PropertiesOptionError, "api.option(path, 0).property.set(properties)")
2017-10-22 09:48:08 +02:00
# check properties after set without permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
assert set(api.option(path).property.get()) == set(properties)
assert set(api.forcepermissive.option(path).property.get()) == set(properties)
2017-10-22 09:48:08 +02:00
elif kwargs.get('permissive', False):
if not isslave:
2017-11-12 14:33:05 +01:00
raises(PropertiesOptionError, "api.option(path).property.get()")
assert set(api.forcepermissive.option(path).property.get()) == set(default_props)
2017-10-22 09:48:08 +02:00
else:
2017-11-12 14:33:05 +01:00
raises(PropertiesOptionError, "api.option(path, 0).property.get()")
assert set(api.forcepermissive.option(path, 0).property.get()) == set(default_props)
assert set(api.forcepermissive.option(path, 1).property.get()) == set(default_props)
2017-10-22 09:48:08 +02:00
else:
if not isslave:
raises(PropertiesOptionError, "api.option(path).property.get()")
raises(PropertiesOptionError, "api.forcepermissive.option(path).property.get()")
2017-10-22 09:48:08 +02:00
else:
raises(PropertiesOptionError, "api.option(path, 0).property.get()")
raises(PropertiesOptionError, "api.forcepermissive.option(path, 0).property.get()")
2017-10-22 09:48:08 +02:00
# set properties with permissive
if not kwargs.get('propertyerror', False):
api.forcepermissive.option(path).property.set(properties)
2017-10-22 09:48:08 +02:00
else:
raises(PropertiesOptionError, "api.forcepermissive.option(path).property.set(properties)")
2017-10-22 09:48:08 +02:00
# check properties after set with permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if not isslave:
assert set(api.option(path).property.get()) == set(properties)
assert set(api.forcepermissive.option(path).property.get()) == set(properties)
2017-10-22 09:48:08 +02:00
else:
assert set(api.option(path, 0).property.get()) == set(properties)
assert set(api.forcepermissive.option(path, 0).property.get()) == set(properties)
assert set(api.option(path, 1).property.get()) == set(properties)
assert set(api.forcepermissive.option(path, 1).property.get()) == set(properties)
2017-10-22 09:48:08 +02:00
elif kwargs.get('permissive', False):
if not isslave:
raises(PropertiesOptionError, "api.option(path).property.get()")
assert set(api.forcepermissive.option(path).property.get()) == set(properties)
2017-10-22 09:48:08 +02:00
else:
raises(PropertiesOptionError, "api.option(path, 0).property.get()")
assert set(api.forcepermissive.option(path, 0).property.get()) == set(properties)
raises(PropertiesOptionError, "api.option(path, 1).property.get()")
assert set(api.forcepermissive.option(path, 1).property.get()) == set(properties)
2017-10-22 09:48:08 +02:00
else:
if not isslave:
raises(PropertiesOptionError, "api.option(path).property.get()")
raises(PropertiesOptionError, "api.forcepermissive.option(path).property.get()")
2017-10-22 09:48:08 +02:00
else:
raises(PropertiesOptionError, "api.option(path, 0).property.get()")
raises(PropertiesOptionError, "api.forcepermissive.option(path, 0).property.get()")
2017-10-22 09:48:08 +02:00
@autocheck
def autocheck_reset_property(api, path, **kwargs):
"""check properties after set with permissive
"""
# check if is a multi or a slave
if not kwargs.get('propertyerror', False):
multi = api.forcepermissive.option(path).option.ismulti()
isslave = api.forcepermissive.option(path).option.isslave()
2017-10-22 09:48:08 +02:00
else:
raises(PropertiesOptionError, "api.forcepermissive.option(path).option.ismulti()")
raises(PropertiesOptionError, "api.forcepermissive.option(path).option.isslave()")
multi = api.unrestraint.option(path).option.ismulti()
isslave = api.unrestraint.option(path).option.isslave()
2017-10-22 09:48:08 +02:00
# define properties
properties = ['prop1', 'prop2']
if multi and not isslave:
default_props = ['empty']
properties.append('empty')
else:
default_props = []
extra_properties = kwargs.get('extra_properties')
if extra_properties:
properties.extend(extra_properties)
default_props.extend(extra_properties)
properties = tuple(properties)
# check properties
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
assert set(api.option(path).property.get()) == set(properties)
assert set(api.forcepermissive.option(path).property.get()) == set(properties)
2017-10-22 09:48:08 +02:00
elif kwargs.get('permissive', False):
if not isslave:
assert set(api.forcepermissive.option(path).property.get()) == set(properties)
2017-10-22 09:48:08 +02:00
else:
assert set(api.forcepermissive.option(path, 0).property.get()) == set(properties)
assert set(api.forcepermissive.option(path, 1).property.get()) == set(properties)
2017-10-22 09:48:08 +02:00
# reset properties without permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
api.option(path).property.reset()
2017-10-22 09:48:08 +02:00
else:
raises(PropertiesOptionError, "api.option(path).property.reset()")
2017-10-22 09:48:08 +02:00
# check properties
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if not isslave:
assert set(api.option(path).property.get()) == set(default_props)
assert set(api.forcepermissive.option(path).property.get()) == set(default_props)
2017-10-22 09:48:08 +02:00
else:
assert set(api.option(path, 0).property.get()) == set(default_props)
assert set(api.forcepermissive.option(path, 0).property.get()) == set(default_props)
assert set(api.option(path, 1).property.get()) == set(default_props)
assert set(api.forcepermissive.option(path, 1).property.get()) == set(default_props)
2017-10-22 09:48:08 +02:00
elif kwargs.get('permissive', False):
if not isslave:
assert set(api.forcepermissive.option(path).property.get()) == set(properties)
2017-10-22 09:48:08 +02:00
else:
assert set(api.forcepermissive.option(path, 0).property.get()) == set(properties)
assert set(api.forcepermissive.option(path, 1).property.get()) == set(properties)
2017-10-22 09:48:08 +02:00
# reset properties with permissive
raises(APIError, "api.unrestraint.option(path).property.set(properties)")
raises(APIError, "api.unrestraint.option(path).property.reset()")
2017-10-22 09:48:08 +02:00
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
api.forcepermissive.option(path).property.set(properties)
api.forcepermissive.option(path).property.reset()
2017-10-22 09:48:08 +02:00
elif kwargs.get('permissive', False):
api.forcepermissive.option(path).property.reset()
2017-10-22 09:48:08 +02:00
# check properties
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if not isslave:
assert set(api.option(path).property.get()) == set(default_props)
assert set(api.forcepermissive.option(path).property.get()) == set(default_props)
2017-10-22 09:48:08 +02:00
else:
assert set(api.option(path, 0).property.get()) == set(default_props)
assert set(api.forcepermissive.option(path, 0).property.get()) == set(default_props)
assert set(api.option(path, 1).property.get()) == set(default_props)
assert set(api.forcepermissive.option(path, 1).property.get()) == set(default_props)
2017-10-22 09:48:08 +02:00
elif kwargs.get('permissive', False):
if not isslave:
assert set(api.forcepermissive.option(path).property.get()) == set(default_props)
2017-10-22 09:48:08 +02:00
else:
assert set(api.forcepermissive.option(path, 0).property.get()) == set(default_props)
assert set(api.forcepermissive.option(path, 1).property.get()) == set(default_props)
2017-10-22 09:48:08 +02:00
@autocheck
def autocheck_property2(*args, **kwargs):
return autocheck_property(*args, display=False, **kwargs)
@autocheck
def autocheck_owner_with_value(api, path, **kwargs):
"""value is now changed, check owner in this case
"""
# check if is a isslave
if not kwargs.get('propertyerror', False):
isslave = api.forcepermissive.option(path).option.isslave()
2017-10-22 09:48:08 +02:00
else:
raises(PropertiesOptionError, "api.forcepermissive.option(path).option.isslave()")
isslave = api.unrestraint.option(path).option.isslave()
2017-10-22 09:48:08 +02:00
# get owner without permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if not isslave:
assert api.option(path).owner.get() == 'user'
2017-10-22 09:48:08 +02:00
else:
assert api.option(path, 0).owner.get() == 'user'
assert api.option(path, 1).owner.get() == 'user'
2017-10-22 09:48:08 +02:00
else:
if not isslave:
raises(PropertiesOptionError, "api.option(path).owner.get()")
2017-10-22 09:48:08 +02:00
else:
raises(PropertiesOptionError, "api.option(path, 0).owner.get()")
raises(PropertiesOptionError, "api.option(path, 1).owner.get()")
2017-10-22 09:48:08 +02:00
# get owner with permissive
if not kwargs.get('propertyerror', False):
if not isslave:
assert api.forcepermissive.option(path).owner.get() == 'user'
2017-10-22 09:48:08 +02:00
else:
assert api.forcepermissive.option(path, 0).owner.get() == 'default'
assert api.forcepermissive.option(path, 1).owner.get() == 'user'
2017-10-22 09:48:08 +02:00
else:
if not isslave:
raises(PropertiesOptionError, "api.forcepermissive.option(path).owner.get()")
2017-10-22 09:48:08 +02:00
else:
raises(PropertiesOptionError, "api.forcepermissive.option(path, 0).owner.get()")
2017-10-22 09:48:08 +02:00
# test if is default owner without permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
assert api.option(path).owner.isdefault() is False
2017-10-22 09:48:08 +02:00
else:
raises(PropertiesOptionError, "api.option(path).owner.isdefault()")
2017-10-22 09:48:08 +02:00
# test if is default owner with permissive
if not kwargs.get('propertyerror', False):
if not isslave:
assert api.forcepermissive.option(path).owner.isdefault() is False
else:
2017-11-12 14:33:05 +01:00
assert api.forcepermissive.option(path, 0).owner.isdefault() is True
assert api.forcepermissive.option(path, 1).owner.isdefault() is False
2017-10-22 09:48:08 +02:00
else:
raises(PropertiesOptionError, "api.forcepermissive.option(path).owner.isdefault()")
2017-10-22 09:48:08 +02:00
@autocheck
def autocheck_set_owner(api, path, **kwargs):
# test set owner without permissive
if not kwargs.get('propertyerror', False):
isslave = api.forcepermissive.option(path).option.isslave()
2017-10-22 09:48:08 +02:00
else:
raises(PropertiesOptionError, "api.forcepermissive.option(path).option.isslave()")
2017-10-22 09:48:08 +02:00
isslave = False
# set owner without permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if not isslave:
api.option(path).owner.set('new_user')
2017-10-22 09:48:08 +02:00
else:
api.option(path, 1).owner.set('new_user')
2017-10-22 09:48:08 +02:00
else:
if not isslave:
raises(PropertiesOptionError, "api.option(path).owner.set('new_user')")
2017-10-22 09:48:08 +02:00
else:
raises(PropertiesOptionError, "api.option(path, 1).owner.set('new_user')")
2017-10-22 09:48:08 +02:00
# check owner set without permissive
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if not isslave:
assert api.option(path).owner.get() == 'new_user'
assert api.forcepermissive.option(path).owner.get() == 'new_user'
2017-10-22 09:48:08 +02:00
else:
assert api.option(path, 1).owner.get() == 'new_user'
assert api.forcepermissive.option(path, 1).owner.get() == 'new_user'
2017-10-22 09:48:08 +02:00
elif not kwargs.get('propertyerror', False):
if not isslave:
assert api.forcepermissive.option(path).owner.get() == 'user'
2017-10-22 09:48:08 +02:00
else:
assert api.forcepermissive.option(path, 1).owner.get() == 'user'
2017-10-22 09:48:08 +02:00
# set owner with permissive
if not kwargs.get('propertyerror', False):
if not isslave:
api.forcepermissive.option(path).owner.set('new_user1')
2017-10-22 09:48:08 +02:00
else:
api.forcepermissive.option(path, 1).owner.set('new_user1')
2017-10-22 09:48:08 +02:00
else:
if not isslave:
raises(PropertiesOptionError, "api.forcepermissive.option(path).owner.set('new_user1')")
2017-10-22 09:48:08 +02:00
else:
raises(PropertiesOptionError, "api.forcepermissive.option(path, 1).owner.set('new_user1')")
2017-10-22 09:48:08 +02:00
# get owner set with permissive
if not kwargs.get('propertyerror', False):
if not isslave:
assert api.forcepermissive.option(path).owner.get() == 'new_user1'
2017-10-22 09:48:08 +02:00
else:
assert api.forcepermissive.option(path, 0).owner.get() == 'default'
assert api.forcepermissive.option(path, 1).owner.get() == 'new_user1'
2017-10-22 09:48:08 +02:00
2017-10-25 08:46:22 +02:00
@autocheck
def autocheck_option(api, path, **kwargs):
expected_name = path.split('.')[-1]
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
current_name = api.option(path).option.getname()
assert current_name == api.forcepermissive.option(path).option.getname()
assert current_name == api.unrestraint.option(path).option.getname()
doc = api.option(path).option.getdoc()
assert doc == api.forcepermissive.option(path).option.getdoc()
assert doc == api.unrestraint.option(path).option.getdoc()
2017-10-25 08:46:22 +02:00
elif not kwargs.get('propertyerror', False):
raises(PropertiesOptionError, "api.option(path).option.getname()")
current_name = api.forcepermissive.option(path).option.getname()
assert current_name == api.unrestraint.option(path).option.getname()
raises(PropertiesOptionError, "api.option(path).option.getdoc()")
doc = api.forcepermissive.option(path).option.getdoc()
assert doc == api.unrestraint.option(path).option.getdoc()
else:
raises(PropertiesOptionError, "api.option(path).option.getname()")
raises(PropertiesOptionError, "api.forcepermissive.option(path).option.getname()")
current_name = api.unrestraint.option(path).option.getname()
raises(PropertiesOptionError, "api.option(path).option.getdoc()")
raises(PropertiesOptionError, "api.forcepermissive.option(path).option.getdoc()")
doc = api.unrestraint.option(path).option.getdoc()
2017-10-25 08:46:22 +02:00
assert current_name == expected_name
if expected_name.endswith('val1') or expected_name.endswith('val2'):
expected_name = expected_name[:-4]
assert doc == "{}'s option".format(expected_name)
@autocheck
def autocheck_permissive(api, path, **kwargs):
"""test permissive for hidden and disabled value
"""
# check if is a multi, a master or a slave
if not kwargs.get('propertyerror', False):
multi = api.forcepermissive.option(path).option.ismulti()
ismaster = api.forcepermissive.option(path).option.ismaster()
isslave = api.forcepermissive.option(path).option.isslave()
else:
raises(PropertiesOptionError, "api.forcepermissive.option(path).option.ismulti()")
multi = api.unrestraint.option(path).option.ismulti()
ismaster = api.unrestraint.option(path).option.ismaster()
isslave = api.unrestraint.option(path).option.isslave()
# set default value (different if value is multi or not)
if not multi:
first_value = 'myvalue'
second_value = 'myvalue1'
else:
first_value = ['myvalue']
second_value = ['myvalue', 'myvalue1']
if multi and not isslave:
empty_value = []
else:
empty_value = None
# cannot access to hidden value without forcepermissive
# and to disabled value (with forcepermissive too)
if kwargs.get('propertyerror', False):
if not isslave:
raises(PropertiesOptionError, "api.option(path).value.get()")
raises(PropertiesOptionError, "api.forcepermissive.option(path).value.get()")
else:
raises(PropertiesOptionError, "api.option(path, 0).value.get()")
raises(PropertiesOptionError, "api.forcepermissive.option(path, 0).value.get()")
elif kwargs.get('permissive', False):
if not isslave:
raises(PropertiesOptionError, "api.option(path).value.get()")
api.forcepermissive.option(path).value.get()
else:
raises(PropertiesOptionError, "api.option(path, 0).value.get()")
api.forcepermissive.option(path, 0).value.get()
else:
if not isslave:
api.option(path).value.get()
else:
api.option(path, 0).value.get()
assert api.unrestraint.option(path).permissive.get() == frozenset()
api.unrestraint.option(path).permissive.set(('disabled',))
assert api.unrestraint.option(path).permissive.get() == frozenset(['disabled'])
# can access to disabled value
if kwargs.get('permissive', False):
if not isslave:
raises(PropertiesOptionError, "api.option(path).value.get()")
api.forcepermissive.option(path).value.get()
else:
raises(PropertiesOptionError, "api.option(path, 0).value.get()")
api.forcepermissive.option(path, 0).value.get()
else:
if not isslave:
api.option(path).value.get()
else:
api.option(path, 0).value.get()
#FIXME
#api.option(path).permissive.set(('disabled', 'hidden'))
## can access to value
#if not isslave:
# api.option(path).value.get()
#else:
# api.option(path, 0).value.get()
#assert api.option(path).permissive.get() == frozenset(['disabled', 'hidden'])
#
#print('FIXME del !!!')
2017-10-22 09:48:08 +02:00
def check_all(api, path, multi, **kwargs):
if DISPLAY:
text = u' {} launch tests for {}'.format(ICON, path)
if multi:
text += u' as a multi'
print(text)
2017-10-22 09:48:08 +02:00
for func in autocheck_registers:
if DISPLAY:
print(u' {} {}'.format(ICON, func.__name__))
2017-10-22 09:48:08 +02:00
func(api, path, **kwargs)
def make_api(options, multi):
2017-11-12 14:33:05 +01:00
def make_option(path, option_infos):
#FIXME
2017-10-22 09:48:08 +02:00
option_type = 'str'
option_properties = []
2017-11-12 14:33:05 +01:00
if option_infos is not None:
for prop in PROPERTIES:
if option_infos.get(prop, False) is True:
option_properties.append(prop)
args = [path, "{}'s option".format(path)]
2017-10-22 09:48:08 +02:00
kwargs = {}
if option_properties != []:
kwargs['properties'] = tuple(option_properties)
if multi:
kwargs['multi'] = True
tiramisu_option = OPTIONS_TYPE[option_type]['option']
return tiramisu_option(*args, **kwargs)
def make_optiondescriptions(path, collected):
2017-11-12 14:33:05 +01:00
infos = collected.get('properties', {})
2017-10-22 09:48:08 +02:00
properties = []
kwargs = {}
optiondescription = OptionDescription
2017-11-12 14:33:05 +01:00
for prop in PROPERTIES:
if infos.get(prop, False) is True:
properties.append(prop)
if infos.get('master', False) is True:
if not multi:
return
optiondescription = MasterSlaves
if infos.get('dyn', False) is True:
optiondescription = DynOptionDescription
kwargs['callback'] = return_list
2017-10-22 09:48:08 +02:00
options = []
if 'options' in collected:
options.extend(collected['options'])
for key, values in collected.items():
if key == 'options':
continue
option = make_optiondescriptions(key, values)
if option is None:
return
options.append(option)
if properties != []:
kwargs['properties'] = tuple(properties)
2017-11-12 14:33:05 +01:00
return optiondescription(path, "{}'s optiondescription".format(path), options, **kwargs)
2017-10-22 09:48:08 +02:00
collect_options = {}
2017-11-12 14:33:05 +01:00
for path, option in options.items():
2017-10-22 09:48:08 +02:00
if option is None:
continue
local_collect_options = collect_options
2017-11-12 14:33:05 +01:00
for optiondescription in path.split('.')[:-1]:
2017-10-22 09:48:08 +02:00
local_collect_options.setdefault(optiondescription, {})
local_collect_options = local_collect_options[optiondescription]
2017-11-12 14:33:05 +01:00
local_collect_options['properties'] = option.get(optiondescription, {})
option_name = path.split('.')[-1]
path = '.'.join(path.split('.')[:-1])
local_collect_options.setdefault('options', []).append(make_option(option_name, option.get(option_name)))
2017-10-22 09:48:08 +02:00
rootod = make_optiondescriptions('root', collect_options)
if rootod is None:
return
cfg = Config(rootod)
return getapi(cfg)
DICT_PATHS = [
#test a config without optiondescription
2017-11-12 14:33:05 +01:00
OrderedDict([('first', {}),
('second', {'second': {'disabled': True}}),
('third', {'third': {'hidden': True}})]),
2017-10-22 09:48:08 +02:00
#test a config with an optiondescription
2017-11-12 14:33:05 +01:00
OrderedDict([('subod.first', {}),
('subod.second', {'second': {'disabled': True}}),
('subod.third', {'third': {'hidden': True}})]),
2017-10-22 09:48:08 +02:00
#test a config with two optiondescription
2017-11-12 14:33:05 +01:00
OrderedDict([('subod.subsubod.first', {}),
('subod.subsubod.second', {'second': {'disabled': True}}),
('subod.subsubod.third', {'third': {'hidden': True}})]),
2017-10-22 09:48:08 +02:00
#test a config with mix of different optiondescription
2017-11-12 14:33:05 +01:00
OrderedDict([('first', {}),
('subod.second', {'second': {'disabled': True}}),
('subod.subsubod.third', {'third': {'hidden': True}})]),
2017-10-22 09:48:08 +02:00
#test a config with masterslaves
2017-11-12 14:33:05 +01:00
OrderedDict([('odmaster.first', {'odmaster': {'master': True}}),
('odmaster.second', {'second': {'disabled': True}}),
('odmaster.third', {'third': {'hidden': True}})]),
2017-10-22 09:48:08 +02:00
##test a config with dynoption
2017-11-12 14:33:05 +01:00
OrderedDict([('subod.firstv', {'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)]),
2017-10-22 09:48:08 +02:00
#test a config with dynoption subdir
2017-11-12 14:33:05 +01:00
OrderedDict([('subod.subsubod.first', {'subod': {'dyn': True}}),
('subod.subsubod.second', {'second': {'disabled': True}}),
('subod.subsubod.third', {'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)])
2017-10-22 09:48:08 +02:00
]
@pytest.fixture(scope="function", params=DICT_PATHS)
def paths(request):
if DISPLAY:
print(u'\n{} {}: {}'.format(ICON, request.function.__name__, request.param))
2017-10-22 09:48:08 +02:00
return request.param
def test_options(paths):
lpaths = list(paths.keys())
for multi in (False, True):
2017-11-12 14:33:05 +01:00
api = make_api(paths, multi)
2017-10-22 09:48:08 +02:00
if api is None:
continue
check_all(api, lpaths[0], multi)
check_all(api, lpaths[1], multi, propertyerror=True, extra_properties=['disabled'])
check_all(api, lpaths[2], multi, permissive=True, extra_properties=['hidden'])
if len(lpaths) == 6:
check_all(api, lpaths[3], multi)
check_all(api, lpaths[4], multi, propertyerror=True, extra_properties=['disabled'])
check_all(api, lpaths[5], multi, permissive=True, extra_properties=['hidden'])
##
#print('')
#print(api.help)
DICT_PATHS2 = [
2017-11-12 14:33:05 +01:00
OrderedDict([('subod.subsubod.first', {'subsubod': {'hidden': True}}),
('subod.subsubod.second', {}),
('subod.subsubod.third', {})]),
OrderedDict([('subod.subsubod.first', {'subsub': {'dyn': True, 'hidden': True}}),
('subod.subsubod.second', {}),
('subod.subsubod.third', {}),
('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_PATHS2)
def paths2(request):
if DISPLAY:
print(u'\n{} {}: {}'.format(ICON, request.function.__name__, request.param))
return request.param
2017-11-12 14:33:05 +01:00
#FIXME
#def test_tree_od_permissive(paths2):
# """permissive when optiondescription is hidden
# """
# lpaths = list(paths2.keys())
# for multi in (False, True):
# api = make_api(paths2, multi)
# if api is None:
# continue
# check_all(api, lpaths[0], multi, permissive=True)
# check_all(api, lpaths[1], multi, permissive=True)
# check_all(api, lpaths[2], multi, permissive=True, extra_properties=['hidden'])
# if len(lpaths) == 6:
# check_all(api, lpaths[3], multi, permissive=True)
# check_all(api, lpaths[4], multi, permissive=True)
# check_all(api, lpaths[5], multi, permissive=True, extra_properties=['hidden'])