"""test API to get/set owner """ import pytest from py.test import raises from .autopath import do_autopath do_autopath() from tiramisu import Config, StrOption, OptionDescription, MasterSlaves, DynOptionDescription, \ getapi from tiramisu.error import PropertiesOptionError, APIError from collections import OrderedDict ICON = u'\u2937' OPTIONS_TYPE = {'str': {'type': str, 'option': StrOption} } PROPERTIES = ['hidden', 'disabled'] def return_list(val=None, suffix=None): if val: return val else: return ['val1', 'val2'] def display_info(func): def wrapper(*args, **kwargs): print(u'\n{} {}'.format(ICON, func.__name__)) return func(*args, **kwargs) return wrapper autocheck_registers = [] def autocheck(func): autocheck_registers.append(func) def wrapper(*args, **kwargs): if kwargs.get('display', True): 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.permissive.option.isslave(path) except: isslave = False # check if owner is a string "default" if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): assert api.owner.get(path) == 'default' else: if not isslave: raises(PropertiesOptionError, "api.owner.get(path)") else: raises(PropertiesOptionError, "api.owner.get(path, 0)") raises(APIError, "api.unrestraint.owner.get(path)") if not kwargs.get('propertyerror', False): if not isslave: assert api.permissive.owner.get(path) == 'default' else: assert api.permissive.owner.get(path, 0) == 'default' else: if not isslave: raises(PropertiesOptionError, "api.permissive.owner.get(path)") else: raises(PropertiesOptionError, "api.permissive.owner.get(path, 0)") # check if default owner raises(APIError, "api.unrestraint.owner.isdefault(path)") if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): assert api.owner.isdefault(path) else: raises(PropertiesOptionError, "api.owner.isdefault(path)") if not kwargs.get('propertyerror', False): assert api.permissive.owner.isdefault(path) else: raises(PropertiesOptionError, "api.permissive.owner.isdefault(path)") @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.permissive.option.ismulti(path) ismaster = api.permissive.option.ismaster(path) isslave = api.permissive.option.isslave(path) else: raises(PropertiesOptionError, "api.permissive.option.ismulti(path)") multi = api.unrestraint.option.ismulti(path) ismaster = api.unrestraint.option.ismaster(path) isslave = api.unrestraint.option.isslave(path) # 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.value.get(path) == empty_value else: raises(PropertiesOptionError, "api.value.get(path)") # test default value (should be empty) with permissive # cannot test for slave (we cannot get all values for a slave) raises(APIError, "api.unrestraint.value.get(path)") if not isslave: if not kwargs.get('propertyerror', False): assert api.permissive.value.get(path) == empty_value else: raises(PropertiesOptionError, "api.permissive.value.get(path)") # set a value without permissive # for master/slave should have an index and good length # for master must append, not set if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if ismaster: raises(IndexError, "api.value.set(path, 0, first_value[0])") api.value.append(path, first_value[0]) elif isslave: #FIXME print(api.value.append(path, first_value[0])) raises(PropertiesOptionError, "api.value.append(path, first_value[0])") api.value.set(path, 0, first_value[0]) raise Exception('pouet') else: api.value.set(path, first_value) else: if ismaster: raises(PropertiesOptionError, "api.value.append(path, first_value[0])") elif isslave: raises(PropertiesOptionError, "api.value.set(path, 0, first_value[0])") else: raises(PropertiesOptionError, "api.value.set(path, first_value)") # get value after set value without permissive if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if isslave: assert api.value.get(path, 0) == first_value[0] else: assert api.value.get(path) == first_value elif kwargs.get('permissive', False): if isslave: raises(PropertiesOptionError, "api.value.get(path, 0)") assert api.permissive.value.get(path, 0) == empty_value else: raises(PropertiesOptionError, "api.value.get(path)") assert api.permissive.value.get(path) == empty_value else: if isslave: raises(PropertiesOptionError, "api.value.get(path, 0)") raises(PropertiesOptionError, "api.permissive.value.get(path, 0)") else: raises(PropertiesOptionError, "api.value.get(path)") raises(PropertiesOptionError, "api.permissive.value.get(path)") # set a value with permissive if ismaster: raises(APIError, "api.unrestraint.value.set(path, second_value[1])") elif isslave: raises(APIError, "api.unrestraint.value.append(path, second_value[1])") else: raises(APIError, "api.unrestraint.value.set(path, second_value)") if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if ismaster: raises(IndexError, "api.permissive.value.set(path, 1, second_value[1])") api.permissive.value.append(path, second_value[1]) elif isslave: #FIXME raises(PropertiesOptionError, "api.permissive.value.append(path, second_value[1])") api.value.set(path, 1, second_value[1]) raise Exception('ca entre ici') else: api.value.set(path, second_value) elif kwargs.get('permissive', False): if ismaster: api.permissive.value.append(path, second_value[0]) api.permissive.value.append(path, second_value[1]) elif isslave: api.permissive.value.set(path, 1, second_value[1]) else: api.permissive.value.set(path, first_value) else: if ismaster: raises(PropertiesOptionError, "api.permissive.value.append(path, first_value[0])") elif isslave: raises(PropertiesOptionError, "api.permissive.value.set(path, 0, first_value[0])") else: raises(PropertiesOptionError, "api.permissive.value.set(path, first_value)") # get value after set value with permissive if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if isslave: assert api.value.get(path, 0) == second_value[0] assert api.value.get(path, 1) == second_value[1] else: assert api.value.get(path) == second_value elif kwargs.get('permissive', False): if ismaster: raises(PropertiesOptionError, "api.value.get(path)") assert api.permissive.value.get(path) == second_value elif isslave: raises(PropertiesOptionError, "api.value.get(path, 0)") raises(PropertiesOptionError, "api.value.get(path, 1)") assert api.permissive.value.get(path, 1) == second_value[1] else: raises(PropertiesOptionError, "api.value.get(path)") assert api.permissive.value.get(path) == first_value else: if isslave: raises(PropertiesOptionError, "api.value.get(path, 0)") raises(PropertiesOptionError, "api.permissive.value.get(path, 0)") else: raises(PropertiesOptionError, "api.value.get(path)") raises(PropertiesOptionError, "api.permissive.value.get(path)") @autocheck def autocheck_reset_value(api, path, **kwargs): # check if is a multi, a master or a slave if not kwargs.get('propertyerror', False): multi = api.permissive.option.ismulti(path) ismaster = api.permissive.option.ismaster(path) isslave = api.permissive.option.isslave(path) else: raises(PropertiesOptionError, "api.permissive.option.ismulti(path)") multi = api.unrestraint.option.ismulti(path) ismaster = api.unrestraint.option.ismaster(path) isslave = api.unrestraint.option.isslave(path) # 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.value.reset(path) else: api.value.reset(path, 0) else: if not isslave: raises(PropertiesOptionError, "api.value.reset(path)") else: raises(PropertiesOptionError, "api.value.reset(path, 0)") # get value after reset value without permissive if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if isslave: assert api.value.get(path, 0) == empty_value assert api.value.get(path, 1) == second_value[1] else: assert api.value.get(path) == empty_value elif kwargs.get('permissive', False): if isslave: raises(PropertiesOptionError, "api.value.get(path, 0)") assert api.permissive.value.get(path, 0) == empty_value assert api.permissive.value.get(path, 1) == second_value[1] else: raises(PropertiesOptionError, "api.value.get(path)") assert api.permissive.value.get(path) == first_value # reset value with permissive if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if not isslave: api.permissive.value.reset(path) else: api.permissive.value.reset(path, 1) elif kwargs.get('permissive', False): if not isslave: api.permissive.value.reset(path) else: api.permissive.value.reset(path, 1) else: if not isslave: raises(PropertiesOptionError, "api.permissive.value.reset(path)") else: raises(PropertiesOptionError, "api.permissive.value.reset(path, 1)") # get value after reset value with permissive if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if isslave: assert api.value.get(path, 0) == empty_value assert api.value.get(path, 1) == empty_value else: assert api.value.get(path) == empty_value elif kwargs.get('permissive', False): if isslave: raises(PropertiesOptionError, "api.value.get(path, 0)") raises(PropertiesOptionError, "api.value.get(path, 1)") assert api.permissive.value.get(path, 0) == empty_value assert api.permissive.value.get(path, 1) == empty_value else: raises(PropertiesOptionError, "api.value.get(path)") assert api.permissive.value.get(path) == empty_value @autocheck def autocheck_value2(*args, **kwargs): """re set value """ autocheck_value(*args, **kwargs) @autocheck def autocheck_property(api, path, **kwargs): """get property from path """ # check if is a multi or a slave if not kwargs.get('propertyerror', False): multi = api.permissive.option.ismulti(path) isslave = api.permissive.option.isslave(path) else: raises(PropertiesOptionError, "api.permissive.option.ismulti(path)") raises(PropertiesOptionError, "api.permissive.option.isslave(path)") multi = api.unrestraint.option.ismulti(path) isslave = api.unrestraint.option.isslave(path) # 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.property.get(path)) == set(default_props) else: assert set(api.property.get(path, 0)) == set(default_props) assert set(api.property.get(path, 1)) == set(default_props) else: raises(PropertiesOptionError, "api.property.get(path)") # get properties with permissive if not isslave: raises(APIError, "api.unrestraint.property.get(path)") else: raises(APIError, "api.unrestraint.property.get(path, 0)") if not kwargs.get('propertyerror', False): if not isslave: assert set(api.permissive.property.get(path)) == set(default_props) else: assert set(api.permissive.property.get(path, 0)) == set(default_props) assert set(api.permissive.property.get(path, 1)) == set(default_props) else: if not isslave: raises(PropertiesOptionError, "api.permissive.property.get(path)") else: raises(PropertiesOptionError, "api.permissive.property.get(path, 0)") # set properties without permissive if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): api.property.set(path, properties) else: raises(PropertiesOptionError, "api.property.set(path, properties)") # check properties after set without permissive if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): assert set(api.property.get(path)) == set(properties) assert set(api.permissive.property.get(path)) == set(properties) elif kwargs.get('permissive', False): raises(PropertiesOptionError, "api.property.get(path)") if not isslave: assert set(api.permissive.property.get(path)) == set(default_props) else: assert set(api.permissive.property.get(path, 0)) == set(default_props) assert set(api.permissive.property.get(path, 1)) == set(default_props) else: if not isslave: raises(PropertiesOptionError, "api.property.get(path)") raises(PropertiesOptionError, "api.permissive.property.get(path)") else: raises(PropertiesOptionError, "api.property.get(path, 0)") raises(PropertiesOptionError, "api.permissive.property.get(path, 0)") # set properties with permissive if not kwargs.get('propertyerror', False): api.permissive.property.set(path, properties) else: raises(PropertiesOptionError, "api.permissive.property.set(path, properties)") # check properties after set with permissive if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if not isslave: assert set(api.property.get(path)) == set(properties) assert set(api.permissive.property.get(path)) == set(properties) else: assert set(api.property.get(path, 0)) == set(properties) assert set(api.permissive.property.get(path, 0)) == set(properties) assert set(api.property.get(path, 1)) == set(properties) assert set(api.permissive.property.get(path, 1)) == set(properties) elif kwargs.get('permissive', False): if not isslave: raises(PropertiesOptionError, "api.property.get(path)") assert set(api.permissive.property.get(path)) == set(properties) else: raises(PropertiesOptionError, "api.property.get(path, 0)") assert set(api.permissive.property.get(path, 0)) == set(properties) raises(PropertiesOptionError, "api.property.get(path, 1)") assert set(api.permissive.property.get(path, 1)) == set(properties) else: if not isslave: raises(PropertiesOptionError, "api.property.get(path)") raises(PropertiesOptionError, "api.permissive.property.get(path)") else: raises(PropertiesOptionError, "api.property.get(path, 0)") raises(PropertiesOptionError, "api.permissive.property.get(path, 0)") @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.permissive.option.ismulti(path) isslave = api.permissive.option.isslave(path) else: raises(PropertiesOptionError, "api.permissive.option.ismulti(path)") raises(PropertiesOptionError, "api.permissive.option.isslave(path)") multi = api.unrestraint.option.ismulti(path) isslave = api.unrestraint.option.isslave(path) # 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.property.get(path)) == set(properties) assert set(api.permissive.property.get(path)) == set(properties) elif kwargs.get('permissive', False): if not isslave: assert set(api.permissive.property.get(path)) == set(properties) else: assert set(api.permissive.property.get(path, 0)) == set(properties) assert set(api.permissive.property.get(path, 1)) == set(properties) # reset properties without permissive if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): api.property.reset(path) else: raises(PropertiesOptionError, "api.property.reset(path)") # check properties if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if not isslave: assert set(api.property.get(path)) == set(default_props) assert set(api.permissive.property.get(path)) == set(default_props) else: assert set(api.property.get(path, 0)) == set(default_props) assert set(api.permissive.property.get(path, 0)) == set(default_props) assert set(api.property.get(path, 1)) == set(default_props) assert set(api.permissive.property.get(path, 1)) == set(default_props) elif kwargs.get('permissive', False): if not isslave: assert set(api.permissive.property.get(path)) == set(properties) else: assert set(api.permissive.property.get(path, 0)) == set(properties) assert set(api.permissive.property.get(path, 1)) == set(properties) # reset properties with permissive raises(APIError, "api.unrestraint.property.set(path, properties)") raises(APIError, "api.unrestraint.property.reset(path)") if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): api.permissive.property.set(path, properties) api.permissive.property.reset(path) elif kwargs.get('permissive', False): api.permissive.property.reset(path) # check properties if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if not isslave: assert set(api.property.get(path)) == set(default_props) assert set(api.permissive.property.get(path)) == set(default_props) else: assert set(api.property.get(path, 0)) == set(default_props) assert set(api.permissive.property.get(path, 0)) == set(default_props) assert set(api.property.get(path, 1)) == set(default_props) assert set(api.permissive.property.get(path, 1)) == set(default_props) elif kwargs.get('permissive', False): if not isslave: assert set(api.permissive.property.get(path)) == set(default_props) else: assert set(api.permissive.property.get(path, 0)) == set(default_props) assert set(api.permissive.property.get(path, 1)) == set(default_props) @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.permissive.option.isslave(path) else: raises(PropertiesOptionError, "api.permissive.option.isslave(path)") isslave = api.unrestraint.option.isslave(path) # get owner without permissive if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if not isslave: assert api.owner.get(path) == 'user' else: assert api.owner.get(path, 0) == 'user' assert api.owner.get(path, 1) == 'user' else: if not isslave: raises(PropertiesOptionError, "api.owner.get(path)") else: raises(PropertiesOptionError, "api.owner.get(path, 0)") raises(PropertiesOptionError, "api.owner.get(path, 1)") # get owner with permissive if not kwargs.get('propertyerror', False): if not isslave: assert api.permissive.owner.get(path) == 'user' else: assert api.permissive.owner.get(path, 0) == 'default' assert api.permissive.owner.get(path, 1) == 'user' else: if not isslave: raises(PropertiesOptionError, "api.permissive.owner.get(path)") else: raises(PropertiesOptionError, "api.permissive.owner.get(path, 0)") # test if is default owner without permissive if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): assert api.owner.isdefault(path) is False else: raises(PropertiesOptionError, "api.owner.isdefault(path)") # test if is default owner with permissive if not kwargs.get('propertyerror', False): assert api.permissive.owner.isdefault(path) is False else: raises(PropertiesOptionError, "api.permissive.owner.isdefault(path)") @autocheck def autocheck_set_owner(api, path, **kwargs): # test set owner without permissive if not kwargs.get('propertyerror', False): isslave = api.permissive.option.isslave(path) else: raises(PropertiesOptionError, "api.permissive.option.isslave(path)") isslave = False # set owner without permissive if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if not isslave: api.owner.set(path, 'new_user') else: api.owner.set(path, 1, 'new_user') else: if not isslave: raises(PropertiesOptionError, "api.owner.set(path, 'new_user')") else: raises(PropertiesOptionError, "api.owner.set(path, 1, 'new_user')") # check owner set without permissive if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if not isslave: assert api.owner.get(path) == 'new_user' assert api.permissive.owner.get(path) == 'new_user' else: assert api.owner.get(path, 1) == 'new_user' assert api.permissive.owner.get(path, 1) == 'new_user' elif not kwargs.get('propertyerror', False): if not isslave: assert api.permissive.owner.get(path) == 'user' else: assert api.permissive.owner.get(path, 1) == 'user' # set owner with permissive if not kwargs.get('propertyerror', False): if not isslave: api.permissive.owner.set(path, 'new_user1') else: api.permissive.owner.set(path, 1, 'new_user1') else: if not isslave: raises(PropertiesOptionError, "api.permissive.owner.set(path, 'new_user1')") else: raises(PropertiesOptionError, "api.permissive.owner.set(path, 1, 'new_user1')") # get owner set with permissive if not kwargs.get('propertyerror', False): if not isslave: assert api.permissive.owner.get(path) == 'new_user1' else: assert api.permissive.owner.get(path, 0) == 'default' assert api.permissive.owner.get(path, 1) == 'new_user1' @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.getname(path) assert current_name == api.permissive.option.getname(path) assert current_name == api.unrestraint.option.getname(path) doc = api.option.getdoc(path) assert doc == api.permissive.option.getdoc(path) assert doc == api.unrestraint.option.getdoc(path) elif not kwargs.get('propertyerror', False): raises(PropertiesOptionError, "api.option.getname(path)") current_name = api.permissive.option.getname(path) assert current_name == api.unrestraint.option.getname(path) raises(PropertiesOptionError, "api.option.getdoc(path)") doc = api.permissive.option.getdoc(path) assert doc == api.unrestraint.option.getdoc(path) else: raises(PropertiesOptionError, "api.option.getname(path)") raises(PropertiesOptionError, "api.permissive.option.getname(path)") current_name = api.unrestraint.option.getname(path) raises(PropertiesOptionError, "api.option.getdoc(path)") raises(PropertiesOptionError, "api.permissive.option.getdoc(path)") doc = api.unrestraint.option.getdoc(path) 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) def check_all(api, path, multi, **kwargs): text = u' {} launch tests for {}'.format(ICON, path) if multi: text += u' as a multi' print(text) for func in autocheck_registers: print(u' {} {}'.format(ICON, func.__name__)) func(api, path, **kwargs) def make_api(options, multi): def make_option(path): option_infos = path.split('_') option_type = 'str' option_properties = [] for option_info in option_infos[1:]: if option_info in OPTIONS_TYPE: option_type = option_info elif option_info in PROPERTIES: option_properties.append(option_info) else: raise Exception('unknown {} in {}'.format(option_info, path)) args = [option_infos[0], "{}'s option".format(option_infos[0])] 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): infos = path.split('_') name = infos[0] properties = [] kwargs = {} optiondescription = OptionDescription for info in infos[1:]: if info in PROPERTIES: properties.append(info) elif info == 'master': if not multi: return optiondescription = MasterSlaves elif info == 'dyn': optiondescription = DynOptionDescription kwargs['callback'] = return_list else: raise Exception('unknown {} in {}'.format(info, path)) 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) return optiondescription(name, "{}'s optiondescription".format(name), options, **kwargs) collect_options = {} for option in options: if option is None: continue local_collect_options = collect_options for optiondescription in option.split('.')[:-1]: local_collect_options.setdefault(optiondescription, {}) local_collect_options = local_collect_options[optiondescription] path = '.'.join(option.split('.')[:-1]) option_name = option.split('.')[-1] local_collect_options.setdefault("options", []).append(make_option(option_name)) rootod = make_optiondescriptions('root', collect_options) if rootod is None: return cfg = Config(rootod) return getapi(cfg) DICT_PATHS = [ #test a config without optiondescription OrderedDict({'first': 'first', 'second': 'second_disabled', 'third': 'third_hidden'}), #test a config with an optiondescription OrderedDict({'subod.first': 'subod.first', 'subod.second': 'subod.second_disabled', 'subod.third': 'subod.third_hidden'}), #test a config with two optiondescription OrderedDict({'subod.subsubod.first': 'subod.subsubod.first', 'subod.subsubod.second': 'subod.subsubod.second_disabled', 'subod.subsubod.third': 'subod.subsubod.third_hidden'}), #test a config with mix of different optiondescription OrderedDict({'first': 'first', 'subod.second': 'subod.second_disabled', 'subod.subsubod.third': 'subod.subsubod.third_hidden'}), #test a config with masterslaves OrderedDict({'first.first': 'first_master.first', 'first.second': 'first_master.second_disabled', 'first.third': 'first_master.third_hidden'}), ##test a config with dynoption OrderedDict({'subodval1.firstval1': 'subod_dyn.first', 'subodval1.secondval1': 'subod_dyn.second_disabled', 'subodval1.thirdval1': 'subod_dyn.third_hidden', 'subodval2.firstval2': None, 'subodval2.secondval2': None, 'subodval2.thirdval2': None}), #test a config with dynoption subdir OrderedDict({'subod.subodval1.firstval1': 'subod.subod_dyn.first', 'subod.subodval1.secondval1': 'subod.subod_dyn.second_disabled', 'subod.subodval1.thirdval1': 'subod.subod_dyn.third_hidden', 'subod.subodval2.firstval2': None, 'subod.subodval2.secondval2': None, 'subod.subodval2.thirdval2': None}) ] @pytest.fixture(scope="function", params=DICT_PATHS) def paths(request): print(u'\n{} {}: {}'.format(ICON, request.function.__name__, request.param)) return request.param def test_options(paths): lpaths = list(paths.keys()) for multi in (False, True): api = make_api(paths.values(), multi) 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) @display_info def test_tree_od_permissive(): """permissive when optiondescription is hidden """ tpaths = [ OrderedDict({'subod.subsubod.first': 'subod.subsubod_hidden.first', 'subod.subsubod.second': 'subod.subsubod_hidden.second', 'subod.subsubod.third': 'subod.subsubod_hidden.third_hidden'}), OrderedDict({'subod.subodval1.firstval1': 'subod.subod_dyn_hidden.first', 'subod.subodval1.secondval1': 'subod.subod_dyn_hidden.second', 'subod.subodval1.thirdval1': 'subod.subod_dyn_hidden.third_hidden', 'subod.subodval2.firstval2': None, 'subod.subodval2.secondval2': None, 'subod.subodval2.thirdval2': None}) ] for paths in tpaths: lpaths = list(paths.keys()) for multi in (False, True): api = make_api(paths.values(), 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'])