From 6b6fa5e4992a0045873fcc891370728eb4bf1135 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Tue, 14 Aug 2018 23:07:07 +0200 Subject: [PATCH] remove getapi in tests --- test/auto/test_auto.py | 909 +++++++++++++------------- test/test_config.py | 300 +++------ test/test_config_domain.py | 189 +++--- test/test_config_ip.py | 322 +++++---- test/test_dereference.py | 2 +- test/test_duplicate_config.py | 24 +- test/test_dyn_optiondescription.py | 112 ++-- test/test_freeze.py | 35 +- test/test_mandatory.py | 62 +- test/test_masterslaves.py | 70 +- test/test_option.py | 6 +- test/test_option_callback.py | 116 ++-- test/test_option_consistency.py | 78 +-- test/test_option_default.py | 18 +- test/test_option_owner.py | 22 +- test/test_option_setting.py | 66 +- test/test_option_type.py | 16 +- test/test_option_validator.py | 48 +- test/test_option_with_special_name.py | 4 +- test/test_permissive.py | 22 +- test/test_requires.py | 66 +- test/test_submulti.py | 78 +-- test/test_symlink.py | 32 +- 23 files changed, 1205 insertions(+), 1392 deletions(-) diff --git a/test/auto/test_auto.py b/test/auto/test_auto.py index 642ce5f..85780e8 100644 --- a/test/auto/test_auto.py +++ b/test/auto/test_auto.py @@ -8,7 +8,7 @@ from .autopath import do_autopath do_autopath() from tiramisu import Config, MetaConfig, \ StrOption, SymLinkOption, OptionDescription, MasterSlaves, DynOptionDescription, \ - getapi, submulti, undefined, owners, Params, ParamOption + submulti, undefined, owners, Params, ParamOption from tiramisu.error import PropertiesOptionError, APIError, ConfigError, SlaveError from collections import OrderedDict ICON = u'\u2937' @@ -70,97 +70,97 @@ def autocheck(func): @autocheck -def autocheck_option_multi(api, pathread, pathwrite, confread, confwrite, **kwargs): +def autocheck_option_multi(cfg, pathread, pathwrite, confread, confwrite, **kwargs): if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - api.option(pathread).option.ismulti() - api.option(pathread).option.issubmulti() - api.option(pathread).option.ismaster() - api.option(pathread).option.isslave() + cfg.option(pathread).option.ismulti() + cfg.option(pathread).option.issubmulti() + cfg.option(pathread).option.ismaster() + cfg.option(pathread).option.isslave() 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()") + raises(PropertiesOptionError, "cfg.option(pathread).option.ismulti()") + raises(PropertiesOptionError, "cfg.option(pathread).option.issubmulti()") + raises(PropertiesOptionError, "cfg.option(pathread).option.ismaster()") + raises(PropertiesOptionError, "cfg.option(pathread).option.isslave()") if not kwargs.get('propertyerror', False): - api.forcepermissive.option(pathread).option.ismulti() - api.forcepermissive.option(pathread).option.issubmulti() - api.forcepermissive.option(pathread).option.ismaster() - api.forcepermissive.option(pathread).option.isslave() + cfg.forcepermissive.option(pathread).option.ismulti() + cfg.forcepermissive.option(pathread).option.issubmulti() + cfg.forcepermissive.option(pathread).option.ismaster() + cfg.forcepermissive.option(pathread).option.isslave() 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()") + raises(PropertiesOptionError, "cfg.forcepermissive.option(pathread).option.ismulti()") + raises(PropertiesOptionError, "cfg.forcepermissive.option(pathread).option.issubmulti()") + raises(PropertiesOptionError, "cfg.forcepermissive.option(pathread).option.ismaster()") + raises(PropertiesOptionError, "cfg.forcepermissive.option(pathread).option.isslave()") - api.unrestraint.option(pathread).option.ismulti() - api.unrestraint.option(pathread).option.issubmulti() - api.unrestraint.option(pathread).option.ismaster() - api.unrestraint.option(pathread).option.isslave() + cfg.unrestraint.option(pathread).option.ismulti() + cfg.unrestraint.option(pathread).option.issubmulti() + cfg.unrestraint.option(pathread).option.ismaster() + cfg.unrestraint.option(pathread).option.isslave() @autocheck -def autocheck_default_owner(api, pathread, pathwrite, confread, confwrite, **kwargs): +def autocheck_default_owner(cfg, pathread, pathwrite, confread, confwrite, **kwargs): """check different value of owner when any value is set to this option """ - isslave = api.unrestraint.option(pathread).option.isslave() + isslave = cfg.unrestraint.option(pathread).option.isslave() # check if owner is a string "default" and 'isdefault' def do(conf): if not isslave: if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - assert api.config(conf).option(pathread).owner.get() == 'default' - assert api.forcepermissive.config(conf).option(pathread).owner.get() == 'default' + assert cfg.config(conf).option(pathread).owner.get() == 'default' + assert cfg.forcepermissive.config(conf).option(pathread).owner.get() == 'default' # - assert api.config(conf).option(pathread).owner.isdefault() - assert api.forcepermissive.config(conf).option(pathread).owner.isdefault() + assert cfg.config(conf).option(pathread).owner.isdefault() + assert cfg.forcepermissive.config(conf).option(pathread).owner.isdefault() elif not kwargs.get('propertyerror', False): - raises(PropertiesOptionError, "api.config(conf).option(pathread).owner.get()") - assert api.forcepermissive.config(conf).option(pathread).owner.get() == 'default' + raises(PropertiesOptionError, "cfg.config(conf).option(pathread).owner.get()") + assert cfg.forcepermissive.config(conf).option(pathread).owner.get() == 'default' # - raises(PropertiesOptionError, "api.config(conf).option(pathread).owner.isdefault()") - assert api.forcepermissive.config(conf).option(pathread).owner.isdefault() + raises(PropertiesOptionError, "cfg.config(conf).option(pathread).owner.isdefault()") + assert cfg.forcepermissive.config(conf).option(pathread).owner.isdefault() else: - raises(PropertiesOptionError, "api.config(conf).option(pathread).owner.get()") - raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread).owner.get()") + raises(PropertiesOptionError, "cfg.config(conf).option(pathread).owner.get()") + raises(PropertiesOptionError, "cfg.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()") + raises(PropertiesOptionError, "cfg.config(conf).option(pathread).owner.isdefault()") + raises(PropertiesOptionError, "cfg.forcepermissive.config(conf).option(pathread).owner.isdefault()") # - assert api.unrestraint.config(conf).option(pathread).owner.get() == 'default' - assert api.unrestraint.config(conf).option(pathread).owner.isdefault() + assert cfg.unrestraint.config(conf).option(pathread).owner.get() == 'default' + assert cfg.unrestraint.config(conf).option(pathread).owner.isdefault() else: if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - assert api.config(conf).option(pathread, 0).owner.get() == 'default' - assert api.forcepermissive.config(conf).option(pathread, 0).owner.get() == 'default' + assert cfg.config(conf).option(pathread, 0).owner.get() == 'default' + assert cfg.forcepermissive.config(conf).option(pathread, 0).owner.get() == 'default' # - assert api.config(conf).option(pathread, 0).owner.isdefault() - assert api.forcepermissive.config(conf).option(pathread, 0).owner.isdefault() + assert cfg.config(conf).option(pathread, 0).owner.isdefault() + assert cfg.forcepermissive.config(conf).option(pathread, 0).owner.isdefault() elif not kwargs.get('propertyerror', False): - raises(PropertiesOptionError, "api.config(conf).option(pathread, 0).owner.get()") - assert api.forcepermissive.config(conf).option(pathread, 0).owner.get() == 'default' + raises(PropertiesOptionError, "cfg.config(conf).option(pathread, 0).owner.get()") + assert cfg.forcepermissive.config(conf).option(pathread, 0).owner.get() == 'default' # - raises(PropertiesOptionError, "api.config(conf).option(pathread, 0).owner.isdefault()") - assert api.forcepermissive.config(conf).option(pathread, 0).owner.isdefault() + raises(PropertiesOptionError, "cfg.config(conf).option(pathread, 0).owner.isdefault()") + assert cfg.forcepermissive.config(conf).option(pathread, 0).owner.isdefault() else: - raises(PropertiesOptionError, "api.config(conf).option(pathread, 0).owner.get()") - raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread, 0).owner.get()") + raises(PropertiesOptionError, "cfg.config(conf).option(pathread, 0).owner.get()") + raises(PropertiesOptionError, "cfg.forcepermissive.config(conf).option(pathread, 0).owner.get()") # - raises(PropertiesOptionError, "api.config(conf).option(pathread, 0).owner.isdefault()") - raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread, 0).owner.isdefault()") - assert api.unrestraint.config(conf).option(pathread, 0).owner.get() == 'default' - assert api.unrestraint.config(conf).option(pathread, 0).owner.isdefault() + raises(PropertiesOptionError, "cfg.config(conf).option(pathread, 0).owner.isdefault()") + raises(PropertiesOptionError, "cfg.forcepermissive.config(conf).option(pathread, 0).owner.isdefault()") + assert cfg.unrestraint.config(conf).option(pathread, 0).owner.get() == 'default' + assert cfg.unrestraint.config(conf).option(pathread, 0).owner.isdefault() do(confread) if confread != confwrite: do(confwrite) -def _autocheck_default_value(api, path, conf, **kwargs): +def _autocheck_default_value(cfg, path, conf, **kwargs): """set and get values """ # check if is a multi, a master or a slave - multi = api.unrestraint.option(path).option.ismulti() - submulti_ = api.unrestraint.option(path).option.issubmulti() - isslave = api.unrestraint.option(path).option.isslave() + multi = cfg.unrestraint.option(path).option.ismulti() + submulti_ = cfg.unrestraint.option(path).option.issubmulti() + isslave = cfg.unrestraint.option(path).option.isslave() # set default value (different if value is multi or not) empty_value = kwargs['default'] @@ -169,43 +169,43 @@ def _autocheck_default_value(api, path, conf, **kwargs): # cannot test for slave (we cannot get all values for a slave) if not isslave: if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - assert api.config(conf).option(path).value.get() == empty_value - assert api.forcepermissive.config(conf).option(path).value.get() == empty_value + assert cfg.config(conf).option(path).value.get() == empty_value + assert cfg.forcepermissive.config(conf).option(path).value.get() == empty_value elif not kwargs.get('propertyerror', False): - raises(PropertiesOptionError, "api.config(conf).option(path).value.get()") - assert api.forcepermissive.config(conf).option(path).value.get() == empty_value + raises(PropertiesOptionError, "cfg.config(conf).option(path).value.get()") + assert cfg.forcepermissive.config(conf).option(path).value.get() == empty_value else: - raises(PropertiesOptionError, "api.config(conf).option(path).value.get()") - raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(path).value.get()") + raises(PropertiesOptionError, "cfg.config(conf).option(path).value.get()") + raises(PropertiesOptionError, "cfg.forcepermissive.config(conf).option(path).value.get()") else: if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - assert api.config(conf).option(path, 0).value.get() == empty_value - assert api.config(conf).option(path, 1).value.get() == empty_value - assert api.forcepermissive.config(conf).option(path, 0).value.get() == empty_value - assert api.forcepermissive.config(conf).option(path, 1).value.get() == empty_value + assert cfg.config(conf).option(path, 0).value.get() == empty_value + assert cfg.config(conf).option(path, 1).value.get() == empty_value + assert cfg.forcepermissive.config(conf).option(path, 0).value.get() == empty_value + assert cfg.forcepermissive.config(conf).option(path, 1).value.get() == empty_value elif not kwargs.get('propertyerror', False): - raises(PropertiesOptionError, "api.config(conf).option(path, 0).value.get()") - assert api.forcepermissive.config(conf).option(path, 0).value.get() == empty_value - assert api.forcepermissive.config(conf).option(path, 1).value.get() == empty_value + raises(PropertiesOptionError, "cfg.config(conf).option(path, 0).value.get()") + assert cfg.forcepermissive.config(conf).option(path, 0).value.get() == empty_value + assert cfg.forcepermissive.config(conf).option(path, 1).value.get() == empty_value else: - raises(PropertiesOptionError, "api.config(conf).option(path, 0).value.get()") - raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(path, 0).value.get()") + raises(PropertiesOptionError, "cfg.config(conf).option(path, 0).value.get()") + raises(PropertiesOptionError, "cfg.forcepermissive.config(conf).option(path, 0).value.get()") @autocheck -def autocheck_default_value(api, pathread, pathwrite, confread, confwrite, **kwargs): - _autocheck_default_value(api, pathread, confread, **kwargs) +def autocheck_default_value(cfg, pathread, pathwrite, confread, confwrite, **kwargs): + _autocheck_default_value(cfg, pathread, confread, **kwargs) if confread != confwrite: - _autocheck_default_value(api, pathread, confwrite, **kwargs) + _autocheck_default_value(cfg, pathread, confwrite, **kwargs) -def _set_value(api, pathwrite, conf, **kwargs): +def _set_value(cfg, pathwrite, conf, **kwargs): set_permissive = kwargs.get('set_permissive', True) - 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() + multi = cfg.unrestraint.option(pathwrite).option.ismulti() + submulti_ = cfg.unrestraint.option(pathwrite).option.issubmulti() + ismaster = cfg.unrestraint.option(pathwrite).option.ismaster() + isslave = cfg.unrestraint.option(pathwrite).option.isslave() if not multi: first_value = FIRST_VALUE elif submulti_ is False: @@ -224,65 +224,65 @@ def _set_value(api, pathwrite, conf, **kwargs): # for master must append, not set if ismaster: if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - raises(APIError, "api.config(conf).option(pathwrite, 0).value.set(first_value[0])") + raises(APIError, "cfg.config(conf).option(pathwrite, 0).value.set(first_value[0])") if not set_permissive: - api.config(conf).option(pathwrite).value.set([first_value[0]]) + cfg.config(conf).option(pathwrite).value.set([first_value[0]]) else: - api.forcepermissive.config(conf).option(pathwrite).value.set([first_value[0]]) + cfg.forcepermissive.config(conf).option(pathwrite).value.set([first_value[0]]) elif not kwargs.get('propertyerror', False): - raises(PropertiesOptionError, "api.config(conf).option(pathwrite).value.set([first_value[0]])") + raises(PropertiesOptionError, "cfg.config(conf).option(pathwrite).value.set([first_value[0]])") if set_permissive: - api.forcepermissive.config(conf).option(pathwrite).value.set([first_value[0]]) + cfg.forcepermissive.config(conf).option(pathwrite).value.set([first_value[0]]) else: - raises(PropertiesOptionError, "api.config(conf).option(pathwrite).value.set([first_value[0]])") + raises(PropertiesOptionError, "cfg.config(conf).option(pathwrite).value.set([first_value[0]])") raises(PropertiesOptionError, - "api.forcepermissive.config(conf).option(pathwrite).value.set([first_value[0]])") + "cfg.forcepermissive.config(conf).option(pathwrite).value.set([first_value[0]])") if len(first_value) > 1: - raises(APIError, "api.unrestraint.config(conf).option(pathwrite).value.set(first_value[1])") + raises(APIError, "cfg.unrestraint.config(conf).option(pathwrite).value.set(first_value[1])") elif isslave: if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if not set_permissive: - api.config(conf).option(pathwrite, 1).value.set(second_value) + cfg.config(conf).option(pathwrite, 1).value.set(second_value) else: - api.forcepermissive.config(conf).option(pathwrite, 1).value.set(second_value) + cfg.forcepermissive.config(conf).option(pathwrite, 1).value.set(second_value) elif not kwargs.get('propertyerror', False): - raises(PropertiesOptionError, "api.config(conf).option(pathwrite, 1).value.set(second_value)") + raises(PropertiesOptionError, "cfg.config(conf).option(pathwrite, 1).value.set(second_value)") if set_permissive: - api.forcepermissive.config(conf).option(pathwrite, 1).value.set(second_value) + cfg.forcepermissive.config(conf).option(pathwrite, 1).value.set(second_value) else: - raises(PropertiesOptionError, "api.config(conf).option(pathwrite, 1).value.set(second_value)") + raises(PropertiesOptionError, "cfg.config(conf).option(pathwrite, 1).value.set(second_value)") raises(PropertiesOptionError, - "api.forcepermissive.config(conf).option(pathwrite, 1).value.set(second_value)") + "cfg.forcepermissive.config(conf).option(pathwrite, 1).value.set(second_value)") raises(APIError, - "api.unrestraint.config(conf).option(pathwrite).value.set([second_value, second_value])") + "cfg.unrestraint.config(conf).option(pathwrite).value.set([second_value, second_value])") else: if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if not set_permissive: - api.config(conf).option(pathwrite).value.set(first_value) + cfg.config(conf).option(pathwrite).value.set(first_value) else: - api.forcepermissive.config(conf).option(pathwrite).value.set(first_value) + cfg.forcepermissive.config(conf).option(pathwrite).value.set(first_value) elif not kwargs.get('propertyerror', False): - raises(PropertiesOptionError, "api.config(conf).option(pathwrite).value.set(first_value)") + raises(PropertiesOptionError, "cfg.config(conf).option(pathwrite).value.set(first_value)") if set_permissive: - api.forcepermissive.config(conf).option(pathwrite).value.set(first_value) + cfg.forcepermissive.config(conf).option(pathwrite).value.set(first_value) else: - raises(PropertiesOptionError, "api.config(conf).option(pathwrite).value.set(first_value)") - raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathwrite).value.set(first_value)") - #FIXME raises(APIError, "api.unrestraint.config(conf).option(pathwrite).value.set(first_value)") + raises(PropertiesOptionError, "cfg.config(conf).option(pathwrite).value.set(first_value)") + raises(PropertiesOptionError, "cfg.forcepermissive.config(conf).option(pathwrite).value.set(first_value)") + #FIXME raises(APIError, "cfg.unrestraint.config(conf).option(pathwrite).value.set(first_value)") @autocheck -def autocheck_set_value(api, pathread, pathwrite, confread, confwrite, **kwargs): - _set_value(api, pathwrite, confwrite, **kwargs) +def autocheck_set_value(cfg, pathread, pathwrite, confread, confwrite, **kwargs): + _set_value(cfg, pathwrite, confwrite, **kwargs) @autocheck -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) +def autocheck_get_value_permissive(cfg, pathread, pathwrite, confread, confwrite, **kwargs): + multi = cfg.unrestraint.option(pathread).option.ismulti() + submulti_ = cfg.unrestraint.option(pathread).option.issubmulti() + isslave = cfg.unrestraint.option(pathread).option.isslave() + _set_value(cfg, pathwrite, confwrite, **kwargs) empty_value = kwargs['default'] if not multi: first_value = FIRST_VALUE @@ -295,47 +295,47 @@ def autocheck_get_value_permissive(api, pathread, pathwrite, confread, confwrite # get value after set value without permissive if isslave: if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - assert api.config(conf).option(pathread, 0).value.get() == empty_value - assert api.forcepermissive.config(conf).option(pathread, 0).value.get() == empty_value + assert cfg.config(conf).option(pathread, 0).value.get() == empty_value + assert cfg.forcepermissive.config(conf).option(pathread, 0).value.get() == empty_value if submulti_: - 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] + assert cfg.config(conf).option(pathread, 1).value.get() == SUBLIST_SECOND_VALUE[1] + assert cfg.forcepermissive.config(conf).option(pathread, 1).value.get() == SUBLIST_SECOND_VALUE[1] else: - 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] + assert cfg.config(conf).option(pathread, 1).value.get() == LIST_SECOND_VALUE[1] + assert cfg.forcepermissive.config(conf).option(pathread, 1).value.get() == LIST_SECOND_VALUE[1] elif kwargs.get('permissive', False): - 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 + raises(PropertiesOptionError, "assert cfg.config(conf).option(pathread, 0).value.get()") + raises(PropertiesOptionError, "assert cfg.config(conf).option(pathread, 1).value.get()") + assert cfg.forcepermissive.config(conf).option(pathread, 0).value.get() == empty_value if submulti_: - assert api.forcepermissive.config(conf).option(pathread, 1).value.get() == SUBLIST_SECOND_VALUE[1] + assert cfg.forcepermissive.config(conf).option(pathread, 1).value.get() == SUBLIST_SECOND_VALUE[1] else: - assert api.forcepermissive.config(conf).option(pathread, 1).value.get() == LIST_SECOND_VALUE[1] + assert cfg.forcepermissive.config(conf).option(pathread, 1).value.get() == LIST_SECOND_VALUE[1] else: - 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()") + raises(PropertiesOptionError, "assert cfg.config(conf).option(pathread, 0).value.get()") + raises(PropertiesOptionError, "assert cfg.config(conf).option(pathread, 1).value.get()") + raises(PropertiesOptionError, "assert cfg.forcepermissive.config(conf).option(pathread, 0).value.get()") + raises(PropertiesOptionError, "assert cfg.forcepermissive.config(conf).option(pathread, 1).value.get()") else: if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - assert api.config(conf).option(pathread).value.get() == first_value - assert api.forcepermissive.config(conf).option(pathread).value.get() == first_value + assert cfg.config(conf).option(pathread).value.get() == first_value + assert cfg.forcepermissive.config(conf).option(pathread).value.get() == first_value elif kwargs.get('permissive', False): - raises(PropertiesOptionError, "api.config(conf).option(pathread).value.get()") - assert api.forcepermissive.config(conf).option(pathread).value.get() == first_value + raises(PropertiesOptionError, "cfg.config(conf).option(pathread).value.get()") + assert cfg.forcepermissive.config(conf).option(pathread).value.get() == first_value else: - raises(PropertiesOptionError, "api.config(conf).option(pathread).value.get()") - raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread).value.get()") + raises(PropertiesOptionError, "cfg.config(conf).option(pathread).value.get()") + raises(PropertiesOptionError, "cfg.forcepermissive.config(conf).option(pathread).value.get()") do(confread) if confread != confwrite: do(confwrite) -def _autocheck_get_value(api, pathread, conf, **kwargs): +def _autocheck_get_value(cfg, pathread, conf, **kwargs): set_permissive = kwargs.get('set_permissive', True) - multi = api.unrestraint.option(pathread).option.ismulti() - submulti_ = api.unrestraint.option(pathread).option.issubmulti() - isslave = api.unrestraint.option(pathread).option.isslave() + multi = cfg.unrestraint.option(pathread).option.ismulti() + submulti_ = cfg.unrestraint.option(pathread).option.issubmulti() + isslave = cfg.unrestraint.option(pathread).option.isslave() empty_value = kwargs['default'] if not multi: first_value = FIRST_VALUE @@ -354,71 +354,71 @@ def _autocheck_get_value(api, pathread, conf, **kwargs): # get value after set value without permissive if isslave: if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - assert api.config(conf).option(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 + assert cfg.config(conf).option(pathread, 0).value.get() == empty_value + assert cfg.config(conf).option(pathread, 1).value.get() == second_value + assert cfg.forcepermissive.config(conf).option(pathread, 0).value.get() == empty_value + assert cfg.forcepermissive.config(conf).option(pathread, 1).value.get() == second_value elif kwargs.get('permissive', False): - raises(PropertiesOptionError, "api.config(conf).option(pathread, 0).value.get()") - assert api.forcepermissive.config(conf).option(pathread, 0).value.get() == empty_value + raises(PropertiesOptionError, "cfg.config(conf).option(pathread, 0).value.get()") + assert cfg.forcepermissive.config(conf).option(pathread, 0).value.get() == empty_value if set_permissive: - assert api.forcepermissive.config(conf).option(pathread, 1).value.get() == second_value + assert cfg.forcepermissive.config(conf).option(pathread, 1).value.get() == second_value else: - assert api.forcepermissive.config(conf).option(pathread, 1).value.get() == empty_value + assert cfg.forcepermissive.config(conf).option(pathread, 1).value.get() == empty_value else: - raises(PropertiesOptionError, "api.config(conf).option(pathread, 0).value.get()") - raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread, 0).value.get()") + raises(PropertiesOptionError, "cfg.config(conf).option(pathread, 0).value.get()") + raises(PropertiesOptionError, "cfg.forcepermissive.config(conf).option(pathread, 0).value.get()") else: if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - assert api.config(conf).option(pathread).value.get() == first_value - assert api.forcepermissive.config(conf).option(pathread).value.get() == first_value + assert cfg.config(conf).option(pathread).value.get() == first_value + assert cfg.forcepermissive.config(conf).option(pathread).value.get() == first_value elif kwargs.get('permissive', False): - raises(PropertiesOptionError, "api.config(conf).option(pathread).value.get()") + raises(PropertiesOptionError, "cfg.config(conf).option(pathread).value.get()") if set_permissive: - assert api.forcepermissive.config(conf).option(pathread).value.get() == first_value + assert cfg.forcepermissive.config(conf).option(pathread).value.get() == first_value else: - assert api.forcepermissive.config(conf).option(pathread).value.get() == empty_value + assert cfg.forcepermissive.config(conf).option(pathread).value.get() == empty_value else: - raises(PropertiesOptionError, "api.config(conf).option(pathread).value.get()") - raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread).value.get()") + raises(PropertiesOptionError, "cfg.config(conf).option(pathread).value.get()") + raises(PropertiesOptionError, "cfg.forcepermissive.config(conf).option(pathread).value.get()") @autocheck -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) +def autocheck_get_value(cfg, pathread, pathwrite, confread, confwrite, **kwargs): + _set_value(cfg, pathwrite, confwrite, set_permissive=False, **kwargs) + _autocheck_get_value(cfg, pathread, confread, set_permissive=False, **kwargs) if pathread.endswith('val1'): val2_path = pathread.replace('val1', 'val2') - _autocheck_default_value(api, val2_path, confread, **kwargs) + _autocheck_default_value(cfg, val2_path, confread, **kwargs) if confread != confwrite: - _autocheck_get_value(api, pathread, confwrite, set_permissive=False, **kwargs) + _autocheck_get_value(cfg, pathread, confwrite, set_permissive=False, **kwargs) if pathread.endswith('val1'): - _autocheck_default_value(api, val2_path, confwrite, **kwargs) + _autocheck_default_value(cfg, val2_path, confwrite, **kwargs) @autocheck -def autocheck_value_slave(api, pathread, pathwrite, confread, confwrite, **kwargs): - isslave = api.unrestraint.option(pathread).option.isslave() +def autocheck_value_slave(cfg, pathread, pathwrite, confread, confwrite, **kwargs): + isslave = cfg.unrestraint.option(pathread).option.isslave() if not isslave: if kwargs.get('propertyerror', False): - raises(APIError, "api.unrestraint.config(confread).option(pathread).value.len()") + raises(APIError, "cfg.unrestraint.config(confread).option(pathread).value.len()") return if kwargs.get('propertyerror', False): - raises(PropertiesOptionError, "api.option(pathread).value.len()") - raises(PropertiesOptionError, "api.forcepermissive.option(pathread).value.len()") + raises(PropertiesOptionError, "cfg.option(pathread).value.len()") + raises(PropertiesOptionError, "cfg.forcepermissive.option(pathread).value.len()") return - multi = api.unrestraint.option(pathread).option.ismulti() - submulti_ = api.forcepermissive.option(pathread).option.issubmulti() + multi = cfg.unrestraint.option(pathread).option.ismulti() + submulti_ = cfg.forcepermissive.option(pathread).option.issubmulti() empty_value = kwargs['default'] def do(conf): if not kwargs.get('permissive', False): - length = api.config(conf).option(pathread).value.len() - assert api.forcepermissive.config(conf).option(pathread).value.len() == length + length = cfg.config(conf).option(pathread).value.len() + assert cfg.forcepermissive.config(conf).option(pathread).value.len() == length else: - raises(PropertiesOptionError, "api.config(conf).option(pathread).value.len()") - length = api.forcepermissive.config(conf).option(pathread).value.len() + raises(PropertiesOptionError, "cfg.config(conf).option(pathread).value.len()") + length = cfg.forcepermissive.config(conf).option(pathread).value.len() assert length == 2 do(confread) if confread != confwrite: @@ -427,7 +427,7 @@ def autocheck_value_slave(api, pathread, pathwrite, confread, confwrite, **kwarg length = 2 value = [] for idx in range(length): - value.append(api.forcepermissive.option(pathread, idx).value.get()) + value.append(cfg.forcepermissive.option(pathread, idx).value.get()) assert value == [empty_value, empty_value] # cannot access to a slave with index too high @@ -436,22 +436,22 @@ def autocheck_value_slave(api, pathread, pathwrite, confread, confwrite, **kwarg else: value = SUBLIST_FIRST_VALUE[0] - 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')") + raises(SlaveError, "cfg.forcepermissive.option(pathread, length).value.get()") + raises(SlaveError, "cfg.forcepermissive.option(pathread, length).value.set(value)") + raises(SlaveError, "cfg.forcepermissive.option(pathread, length).value.reset()") + raises(SlaveError, "cfg.forcepermissive.option(pathread, length).owner.get()") + raises(SlaveError, "cfg.forcepermissive.option(pathread, length).owner.isdefault()") + raises(SlaveError, "cfg.forcepermissive.option(pathread, length).property.get()") + raises(SlaveError, "cfg.forcepermissive.option(pathread, length).owner.set('new_user')") + raises(SlaveError, "cfg.forcepermissive.option(pathread, length).property.add('prop')") @autocheck -def autocheck_reset_value(api, pathread, pathwrite, confread, confwrite, **kwargs): +def autocheck_reset_value(cfg, pathread, pathwrite, confread, confwrite, **kwargs): # check if is a multi, a master or a slave - multi = api.unrestraint.option(pathread).option.ismulti() - submulti_ = api.unrestraint.option(pathread).option.issubmulti() - isslave = api.unrestraint.option(pathread).option.isslave() + multi = cfg.unrestraint.option(pathread).option.ismulti() + submulti_ = cfg.unrestraint.option(pathread).option.issubmulti() + isslave = cfg.unrestraint.option(pathread).option.isslave() # set default value (different if value is multi or not) if not multi: @@ -464,55 +464,55 @@ def autocheck_reset_value(api, pathread, pathwrite, confread, confwrite, **kwarg first_value = SUBLIST_FIRST_VALUE second_value = SUBLIST_SECOND_VALUE empty_value = kwargs['default'] - _set_value(api, pathwrite, confwrite, **kwargs) + _set_value(cfg, pathwrite, confwrite, **kwargs) # reset value without permissive if not isslave: if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - api.config(confwrite).option(pathwrite).value.reset() + cfg.config(confwrite).option(pathwrite).value.reset() #else: - #FIXME raises(PropertiesOptionError, "api.config(confwrite).option(pathwrite).value.reset()") + #FIXME raises(PropertiesOptionError, "cfg.config(confwrite).option(pathwrite).value.reset()") else: if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - api.config(confwrite).option(pathwrite, 0).value.reset() + cfg.config(confwrite).option(pathwrite, 0).value.reset() #else: - #FIXME raises(PropertiesOptionError, "api.config(confwrite).option(pathwrite, 0).value.reset()") + #FIXME raises(PropertiesOptionError, "cfg.config(confwrite).option(pathwrite, 0).value.reset()") # get value after reset value without permissive def do(conf): if isslave: if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - assert api.config(conf).option(pathread, 0).value.get() == empty_value - assert api.config(conf).option(pathread, 1).value.get() == second_value[1] + assert cfg.config(conf).option(pathread, 0).value.get() == empty_value + assert cfg.config(conf).option(pathread, 1).value.get() == second_value[1] elif kwargs.get('permissive', False): - 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] + raises(PropertiesOptionError, "cfg.config(conf).option(pathread, 0).value.get()") + assert cfg.forcepermissive.config(conf).option(pathread, 0).value.get() == empty_value + assert cfg.forcepermissive.config(conf).option(pathread, 1).value.get() == second_value[1] else: if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - assert api.config(conf).option(pathread).value.get() == empty_value + assert cfg.config(conf).option(pathread).value.get() == empty_value elif kwargs.get('permissive', False): - raises(PropertiesOptionError, "api.config(conf).option(pathread).value.get()") - assert api.forcepermissive.config(conf).option(pathread).value.get() == first_value + raises(PropertiesOptionError, "cfg.config(conf).option(pathread).value.get()") + assert cfg.forcepermissive.config(conf).option(pathread).value.get() == first_value do(confread) if confread != confwrite: do(confwrite) @autocheck -def autocheck_append_value(api, pathread, pathwrite, confread, confwrite, **kwargs): - ismaster = api.unrestraint.option(pathread).option.ismaster() - submulti_ = api.unrestraint.option(pathread).option.issubmulti() +def autocheck_append_value(cfg, pathread, pathwrite, confread, confwrite, **kwargs): + ismaster = cfg.unrestraint.option(pathread).option.ismaster() + submulti_ = cfg.unrestraint.option(pathread).option.issubmulti() if not ismaster: return if not kwargs.get('propertyerror', False): - master_value = api.forcepermissive.config(confread).option(pathread).value.get() + master_value = cfg.forcepermissive.config(confread).option(pathread).value.get() len_value = len(master_value) master_value.append(undefined) - 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() + assert len(cfg.forcepermissive.config(confread).option(pathread).value.get()) == len_value + cfg.forcepermissive.config(confwrite).option(pathread).value.set(master_value) + new_master_value = cfg.forcepermissive.config(confread).option(pathread).value.get() len_new = len(new_master_value) assert len_value + 1 == len_new assert new_master_value[-1] == kwargs['default_multi'] @@ -522,22 +522,22 @@ def autocheck_append_value(api, pathread, pathwrite, confread, confwrite, **kwar else: slave_path += '.third' for idx in range(len_new): - assert api.forcepermissive.config(confread).option(slave_path, idx).value.get() == kwargs['default_multi'] + assert cfg.forcepermissive.config(confread).option(slave_path, idx).value.get() == kwargs['default_multi'] # if not submulti_: value = 'value' else: value = ['value'] master_value.append(value) - assert len(api.forcepermissive.config(confread).option(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 + assert len(cfg.forcepermissive.config(confread).option(pathread).value.get()) == len(new_master_value) + cfg.forcepermissive.config(confwrite).option(pathread).value.set(master_value) + assert cfg.forcepermissive.config(confread).option(pathread).value.get()[-1] == value @autocheck -def autocheck_pop_value(api, pathread, pathwrite, confread, confwrite, **kwargs): - ismaster = api.unrestraint.option(pathread).option.ismaster() - submulti_ = api.unrestraint.option(pathread).option.issubmulti() +def autocheck_pop_value(cfg, pathread, pathwrite, confread, confwrite, **kwargs): + ismaster = cfg.unrestraint.option(pathread).option.ismaster() + submulti_ = cfg.unrestraint.option(pathread).option.issubmulti() if not ismaster: return @@ -554,77 +554,77 @@ def autocheck_pop_value(api, pathread, pathwrite, confread, confwrite, **kwargs) a_slave += '.third' + a_slave[-4:] else: a_slave += '.third' - api.forcepermissive.config(confwrite).option(pathread).value.set(values) - api.forcepermissive.config(confwrite).option(a_slave, 1).value.set(slave_value) - api.forcepermissive.config(confread).option(a_slave, 0).value.get() == kwargs['default_multi'] - assert api.forcepermissive.config(confread).option(a_slave, 0).owner.isdefault() is True - api.forcepermissive.config(confread).option(a_slave, 1).value.get() == slave_value - 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 + cfg.forcepermissive.config(confwrite).option(pathread).value.set(values) + cfg.forcepermissive.config(confwrite).option(a_slave, 1).value.set(slave_value) + cfg.forcepermissive.config(confread).option(a_slave, 0).value.get() == kwargs['default_multi'] + assert cfg.forcepermissive.config(confread).option(a_slave, 0).owner.isdefault() is True + cfg.forcepermissive.config(confread).option(a_slave, 1).value.get() == slave_value + assert cfg.forcepermissive.config(confread).option(a_slave, 1).owner.isdefault() is False + cfg.forcepermissive.config(confread).option(a_slave, 2).value.get() == kwargs['default_multi'] + assert cfg.forcepermissive.config(confread).option(a_slave, 2).owner.isdefault() is True + cfg.forcepermissive.config(confread).option(a_slave, 3).value.get() == kwargs['default_multi'] + assert cfg.forcepermissive.config(confread).option(a_slave, 3).owner.isdefault() is True # - api.forcepermissive.config(confwrite).option(pathread).value.pop(3) - api.forcepermissive.config(confread).option(a_slave, 0).value.get() == kwargs['default_multi'] - assert api.forcepermissive.config(confread).option(a_slave, 0).owner.isdefault() is True - api.forcepermissive.config(confread).option(a_slave, 1).value.get() == slave_value - 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 + cfg.forcepermissive.config(confwrite).option(pathread).value.pop(3) + cfg.forcepermissive.config(confread).option(a_slave, 0).value.get() == kwargs['default_multi'] + assert cfg.forcepermissive.config(confread).option(a_slave, 0).owner.isdefault() is True + cfg.forcepermissive.config(confread).option(a_slave, 1).value.get() == slave_value + assert cfg.forcepermissive.config(confread).option(a_slave, 1).owner.isdefault() is False + cfg.forcepermissive.config(confread).option(a_slave, 2).value.get() == kwargs['default_multi'] + assert cfg.forcepermissive.config(confread).option(a_slave, 2).owner.isdefault() is True # - api.forcepermissive.config(confwrite).option(pathread).value.pop(0) - api.forcepermissive.config(confread).option(a_slave, 0).value.get() == slave_value - 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 + cfg.forcepermissive.config(confwrite).option(pathread).value.pop(0) + cfg.forcepermissive.config(confread).option(a_slave, 0).value.get() == slave_value + assert cfg.forcepermissive.config(confread).option(a_slave, 0).owner.isdefault() is False + cfg.forcepermissive.config(confread).option(a_slave, 1).value.get() == kwargs['default_multi'] + assert cfg.forcepermissive.config(confread).option(a_slave, 1).owner.isdefault() is True # - api.forcepermissive.config(confwrite).option(pathread).value.pop(0) - api.forcepermissive.config(confread).option(a_slave, 0).value.get() == kwargs['default_multi'] - assert api.forcepermissive.config(confread).option(a_slave, 0).owner.isdefault() is True + cfg.forcepermissive.config(confwrite).option(pathread).value.pop(0) + cfg.forcepermissive.config(confread).option(a_slave, 0).value.get() == kwargs['default_multi'] + assert cfg.forcepermissive.config(confread).option(a_slave, 0).owner.isdefault() is True @autocheck -def autocheck_reset_value_permissive(api, pathread, pathwrite, confread, confwrite, **kwargs): +def autocheck_reset_value_permissive(cfg, pathread, pathwrite, confread, confwrite, **kwargs): # check if is a multi, a master or a slave - isslave = api.unrestraint.option(pathread).option.isslave() - _set_value(api, pathwrite, confwrite, **kwargs) + isslave = cfg.unrestraint.option(pathread).option.isslave() + _set_value(cfg, pathwrite, confwrite, **kwargs) # reset value with permissive if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if not isslave: - api.forcepermissive.config(confwrite).option(pathwrite).value.reset() + cfg.forcepermissive.config(confwrite).option(pathwrite).value.reset() else: - api.forcepermissive.option(pathwrite, 1).value.reset() + cfg.forcepermissive.option(pathwrite, 1).value.reset() elif kwargs.get('permissive', False): if not isslave: - api.forcepermissive.config(confwrite).option(pathwrite).value.reset() + cfg.forcepermissive.config(confwrite).option(pathwrite).value.reset() else: - api.forcepermissive.option(pathwrite, 1).value.reset() + cfg.forcepermissive.option(pathwrite, 1).value.reset() #FIXME else: # if not isslave: - # raises(PropertiesOptionError, "api.forcepermissive.config(confwrite).option(pathwrite).value.reset()") + # raises(PropertiesOptionError, "cfg.forcepermissive.config(confwrite).option(pathwrite).value.reset()") # else: - # raises(PropertiesOptionError, "api.forcepermissive.option(pathwrite, 1).value.reset()") - _autocheck_default_value(api, pathread, confread, **kwargs) + # raises(PropertiesOptionError, "cfg.forcepermissive.option(pathwrite, 1).value.reset()") + _autocheck_default_value(cfg, pathread, confread, **kwargs) if confread != confwrite: - _autocheck_default_value(api, pathwrite, confwrite, **kwargs) + _autocheck_default_value(cfg, pathwrite, confwrite, **kwargs) @autocheck -def autocheck_display(api, pathread, pathwrite, confread, confwrite, **kwargs): +def autocheck_display(cfg, pathread, pathwrite, confread, confwrite, **kwargs): """re set value """ if kwargs['callback']: return make_dict = kwargs['make_dict'] make_dict_value = kwargs['make_dict_value'] - assert api.config(confread).option.make_dict() == make_dict + assert cfg.config(confread).option.make_dict() == make_dict if confread != confwrite: - assert(api.config(confwrite).option.make_dict()) == make_dict - _set_value(api, pathwrite, confwrite, **kwargs) - assert api.config(confread).option.make_dict() == make_dict_value + assert(cfg.config(confwrite).option.make_dict()) == make_dict + _set_value(cfg, pathwrite, confwrite, **kwargs) + assert cfg.config(confread).option.make_dict() == make_dict_value if confread != confwrite: - assert(api.config(confwrite).option.make_dict()) == make_dict_value + assert(cfg.config(confwrite).option.make_dict()) == make_dict_value def _getproperties(multi, isslave, kwargs): @@ -642,81 +642,81 @@ def _getproperties(multi, isslave, kwargs): return default_props, frozenset(properties) -def _check_properties(api, pathread, conf, kwargs, props_permissive, props): - if not api.unrestraint.option(pathread).option.isslave(): +def _check_properties(cfg, pathread, conf, kwargs, props_permissive, props): + if not cfg.unrestraint.option(pathread).option.isslave(): if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - assert set(api.config(conf).option(pathread).property.get()) == set(props_permissive) - assert set(api.config(conf).option(pathread).property.get()) == set(props) + assert set(cfg.config(conf).option(pathread).property.get()) == set(props_permissive) + assert set(cfg.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()") + raises(PropertiesOptionError, "cfg.config(conf).option(pathread).property.get()") + raises(PropertiesOptionError, "cfg.config(conf).option(pathread).property.get()") if not kwargs.get('propertyerror', False): - assert set(api.forcepermissive.config(conf).option(pathread).property.get()) == set(props_permissive) - assert set(api.forcepermissive.config(conf).option(pathread).property.get()) == set(props) + assert set(cfg.forcepermissive.config(conf).option(pathread).property.get()) == set(props_permissive) + assert set(cfg.forcepermissive.config(conf).option(pathread).property.get()) == set(props) else: - assert PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread).property.get()" - assert PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread).property.get()" - 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) + assert PropertiesOptionError, "cfg.forcepermissive.config(conf).option(pathread).property.get()" + assert PropertiesOptionError, "cfg.forcepermissive.config(conf).option(pathread).property.get()" + assert set(cfg.unrestraint.config(conf).option(pathread).property.get()) == set(props_permissive) + assert set(cfg.unrestraint.config(conf).option(pathread).property.get()) == set(props) else: if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - assert set(api.config(conf).option(pathread, 0).property.get()) == set(props_permissive) - assert set(api.config(conf).option(pathread, 0).property.get()) == set(props) + assert set(cfg.config(conf).option(pathread, 0).property.get()) == set(props_permissive) + assert set(cfg.config(conf).option(pathread, 0).property.get()) == set(props) # - assert set(api.config(conf).option(pathread, 1).property.get()) == set(props_permissive) - assert set(api.config(conf).option(pathread, 1).property.get()) == set(props) + assert set(cfg.config(conf).option(pathread, 1).property.get()) == set(props_permissive) + assert set(cfg.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, "cfg.config(conf).option(pathread, 0).property.get()") + raises(PropertiesOptionError, "cfg.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()") + raises(PropertiesOptionError, "cfg.config(conf).option(pathread, 1).property.get()") + raises(PropertiesOptionError, "cfg.config(conf).option(pathread, 1).property.get()") if not kwargs.get('propertyerror', False): - assert set(api.forcepermissive.config(conf).option(pathread, 0).property.get()) == set(props_permissive) - assert set(api.forcepermissive.config(conf).option(pathread, 0).property.get()) == set(props) + assert set(cfg.forcepermissive.config(conf).option(pathread, 0).property.get()) == set(props_permissive) + assert set(cfg.forcepermissive.config(conf).option(pathread, 0).property.get()) == set(props) # - assert set(api.forcepermissive.config(conf).option(pathread, 1).property.get()) == set(props_permissive) - assert set(api.forcepermissive.config(conf).option(pathread, 1).property.get()) == set(props) + assert set(cfg.forcepermissive.config(conf).option(pathread, 1).property.get()) == set(props_permissive) + assert set(cfg.forcepermissive.config(conf).option(pathread, 1).property.get()) == set(props) else: - raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread, 0).property.get()") - raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread, 0).property.get()") + raises(PropertiesOptionError, "cfg.forcepermissive.config(conf).option(pathread, 0).property.get()") + raises(PropertiesOptionError, "cfg.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) + raises(PropertiesOptionError, "cfg.forcepermissive.config(conf).option(pathread, 1).property.get()") + raises(PropertiesOptionError, "cfg.forcepermissive.config(conf).option(pathread, 1).property.get()") + assert set(cfg.unrestraint.config(conf).option(pathread, 0).property.get()) == set(props_permissive) + assert set(cfg.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) + assert set(cfg.unrestraint.config(conf).option(pathread, 1).property.get()) == set(props_permissive) + assert set(cfg.unrestraint.config(conf).option(pathread, 1).property.get()) == set(props) @autocheck -def autocheck_property(api, pathread, pathwrite, confread, confwrite, **kwargs): +def autocheck_property(cfg, pathread, pathwrite, confread, confwrite, **kwargs): """get property from path """ # check if is a multi or a slave - multi = api.unrestraint.option(pathread).option.ismulti() - isslave = api.unrestraint.option(pathread).option.isslave() + multi = cfg.unrestraint.option(pathread).option.ismulti() + isslave = cfg.unrestraint.option(pathread).option.isslave() default_props, properties = _getproperties(multi, isslave, kwargs) - _check_properties(api, pathread, confread, kwargs, default_props, default_props) + _check_properties(cfg, pathread, confread, kwargs, default_props, default_props) if confread != confwrite: - _check_properties(api, pathread, confwrite, kwargs, default_props, default_props) + _check_properties(cfg, pathread, confwrite, kwargs, default_props, default_props) # set properties without permissive for prop in properties: - api.unrestraint.config(confwrite).option(pathwrite).property.add(prop) - _check_properties(api, pathread, confread, kwargs, properties, properties) + cfg.unrestraint.config(confwrite).option(pathwrite).property.add(prop) + _check_properties(cfg, pathread, confread, kwargs, properties, properties) if confread != confwrite: - _check_properties(api, pathread, confwrite, kwargs, properties, properties) + _check_properties(cfg, pathread, confwrite, kwargs, properties, properties) -def _property_permissive(api, pathread, pathwrite, confread, confwrite, **kwargs): +def _property_permissive(cfg, pathread, pathwrite, confread, confwrite, **kwargs): # check if is a multi or a slave - multi = api.unrestraint.option(pathread).option.ismulti() - isslave = api.unrestraint.option(pathread).option.isslave() + multi = cfg.unrestraint.option(pathread).option.ismulti() + isslave = cfg.unrestraint.option(pathread).option.isslave() # define properties properties = copy(PROPERTIES_LIST) @@ -731,243 +731,243 @@ def _property_permissive(api, pathread, pathwrite, confread, confwrite, **kwargs default_props.extend(extra_properties) default_props, properties = _getproperties(multi, isslave, kwargs) - _check_properties(api, pathread, confwrite, kwargs, default_props, default_props) + _check_properties(cfg, pathread, confwrite, kwargs, default_props, default_props) if confwrite != confread: - _check_properties(api, pathread, confread, kwargs, default_props, default_props) + _check_properties(cfg, pathread, confread, kwargs, default_props, default_props) # set properties with permissive for prop in properties: if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - api.config(confwrite).option(pathwrite).property.add(prop) + cfg.config(confwrite).option(pathwrite).property.add(prop) if not kwargs.get('propertyerror', False): - api.forcepermissive.config(confwrite).option(pathwrite).property.add(prop) - api.unrestraint.config(confwrite).option(pathwrite).property.add(prop) + cfg.forcepermissive.config(confwrite).option(pathwrite).property.add(prop) + cfg.unrestraint.config(confwrite).option(pathwrite).property.add(prop) - _check_properties(api, pathread, confwrite, kwargs, properties, properties) + _check_properties(cfg, pathread, confwrite, kwargs, properties, properties) if confwrite != confread: - _check_properties(api, pathread, confread, kwargs, properties, properties) + _check_properties(cfg, pathread, confread, kwargs, properties, properties) @autocheck -def autocheck_property_permissive(api, pathread, pathwrite, confread, confwrite, **kwargs): - _property_permissive(api, pathread, pathwrite, confread, confwrite, **kwargs) +def autocheck_property_permissive(cfg, pathread, pathwrite, confread, confwrite, **kwargs): + _property_permissive(cfg, pathread, pathwrite, confread, confwrite, **kwargs) @autocheck -def autocheck_reset_property(api, pathread, pathwrite, confread, confwrite, **kwargs): +def autocheck_reset_property(cfg, pathread, pathwrite, confread, confwrite, **kwargs): """check properties after set with permissive """ # check if is a multi or a slave - multi = api.unrestraint.option(pathread).option.ismulti() - isslave = api.unrestraint.option(pathread).option.isslave() + multi = cfg.unrestraint.option(pathread).option.ismulti() + isslave = cfg.unrestraint.option(pathread).option.isslave() default_props, properties = _getproperties(multi, isslave, kwargs) - _property_permissive(api, pathread, pathwrite, confread, confwrite, **kwargs) + _property_permissive(cfg, pathread, pathwrite, confread, confwrite, **kwargs) # reset properties without permissive - api.unrestraint.config(confwrite).option(pathwrite).property.reset() + cfg.unrestraint.config(confwrite).option(pathwrite).property.reset() - _check_properties(api, pathread, confread, kwargs, default_props, default_props) + _check_properties(cfg, pathread, confread, kwargs, default_props, default_props) if confread != confwrite: - _check_properties(api, pathread, confwrite, kwargs, default_props, default_props) + _check_properties(cfg, pathread, confwrite, kwargs, default_props, default_props) @autocheck -def autocheck_reset_property_permissive(api, pathread, pathwrite, confread, confwrite, **kwargs): +def autocheck_reset_property_permissive(cfg, pathread, pathwrite, confread, confwrite, **kwargs): # check if is a multi or a slave - multi = api.unrestraint.option(pathread).option.ismulti() - isslave = api.unrestraint.option(pathread).option.isslave() + multi = cfg.unrestraint.option(pathread).option.ismulti() + isslave = cfg.unrestraint.option(pathread).option.isslave() default_props, properties = _getproperties(multi, isslave, kwargs) - _property_permissive(api, pathread, pathwrite, confread, confwrite, **kwargs) + _property_permissive(cfg, pathread, pathwrite, confread, confwrite, **kwargs) for prop in properties: - api.unrestraint.option(pathwrite).property.add(prop) - api.unrestraint.option(pathwrite).property.reset() + cfg.unrestraint.option(pathwrite).property.add(prop) + cfg.unrestraint.option(pathwrite).property.reset() - _check_properties(api, pathread, confwrite, kwargs, default_props, default_props) + _check_properties(cfg, pathread, confwrite, kwargs, default_props, default_props) if confread != confwrite: - _check_properties(api, pathread, confread, kwargs, default_props, default_props) + _check_properties(cfg, pathread, confread, kwargs, default_props, default_props) @autocheck -def autocheck_context_owner(api, pathread, pathwrite, confread, confwrite, **kwargs): - owner = api.owner.get() +def autocheck_context_owner(cfg, pathread, pathwrite, confread, confwrite, **kwargs): + owner = cfg.owner.get() assert owner == kwargs['owner'] -def _check_owner(api, pathread, conf, kwargs, owner, permissive_owner): - isslave = api.unrestraint.option(pathread).option.isslave() +def _check_owner(cfg, pathread, conf, kwargs, owner, permissive_owner): + isslave = cfg.unrestraint.option(pathread).option.isslave() if not isslave: if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - assert api.config(conf).option(pathread).owner.get() == owner - assert api.forcepermissive.config(conf).option(pathread).owner.get() == owner + assert cfg.config(conf).option(pathread).owner.get() == owner + assert cfg.forcepermissive.config(conf).option(pathread).owner.get() == owner elif not kwargs.get('propertyerror', False): - raises(PropertiesOptionError, "api.config(conf).option(pathread).owner.get()") - assert api.forcepermissive.config(conf).option(pathread).owner.get() == permissive_owner + raises(PropertiesOptionError, "cfg.config(conf).option(pathread).owner.get()") + assert cfg.forcepermissive.config(conf).option(pathread).owner.get() == permissive_owner else: - raises(PropertiesOptionError, "api.config(conf).option(pathread).owner.get()") - raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread).owner.get()") + raises(PropertiesOptionError, "cfg.config(conf).option(pathread).owner.get()") + raises(PropertiesOptionError, "cfg.forcepermissive.config(conf).option(pathread).owner.get()") else: if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - 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 + assert cfg.config(conf).option(pathread, 0).owner.get() == 'default' + assert cfg.forcepermissive.config(conf).option(pathread, 0).owner.get() == 'default' + assert cfg.config(conf).option(pathread, 1).owner.get() == owner + assert cfg.forcepermissive.config(conf).option(pathread, 1).owner.get() == owner elif not kwargs.get('propertyerror', False): - 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 + raises(PropertiesOptionError, "cfg.config(conf).option(pathread, 0).owner.get()") + raises(PropertiesOptionError, "cfg.config(conf).option(pathread, 1).owner.get()") + assert cfg.forcepermissive.config(conf).option(pathread, 0).owner.get() == 'default' + assert cfg.forcepermissive.config(conf).option(pathread, 1).owner.get() == permissive_owner else: - raises(PropertiesOptionError, "api.config(conf).option(pathread, 0).owner.get()") - raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread, 0).owner.get()") + raises(PropertiesOptionError, "cfg.config(conf).option(pathread, 0).owner.get()") + raises(PropertiesOptionError, "cfg.forcepermissive.config(conf).option(pathread, 0).owner.get()") @autocheck -def autocheck_owner_with_value(api, pathread, pathwrite, confread, confwrite, **kwargs): +def autocheck_owner_with_value(cfg, pathread, pathwrite, confread, confwrite, **kwargs): """value is now changed, check owner in this case """ - _set_value(api, pathwrite, confwrite, **kwargs) - _check_owner(api, pathread, confwrite, kwargs, kwargs['owner'], kwargs['owner']) + _set_value(cfg, pathwrite, confwrite, **kwargs) + _check_owner(cfg, pathread, confwrite, kwargs, kwargs['owner'], kwargs['owner']) if confread != confwrite: - _check_owner(api, pathread, confread, kwargs, kwargs['owner'], kwargs['owner']) + _check_owner(cfg, pathread, confread, kwargs, kwargs['owner'], kwargs['owner']) @autocheck -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) +def autocheck_default_owner_with_value(cfg, pathread, pathwrite, confread, confwrite, **kwargs): + isslave = cfg.unrestraint.option(pathread).option.isslave() + _set_value(cfg, pathwrite, confwrite, **kwargs) # test if is default owner without permissive if not isslave: if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - assert api.config(confwrite).option(pathread).owner.isdefault() is False + assert cfg.config(confwrite).option(pathread).owner.isdefault() is False if confwrite != confread: - assert api.config(confread).option(pathread).owner.isdefault() is False + assert cfg.config(confread).option(pathread).owner.isdefault() is False #FIXME else: - # raises(PropertiesOptionError, "api.config(confwrite).option(pathread).owner.isdefault()") - # raises(PropertiesOptionError, "api.config(confread).option(pathread).owner.isdefault()") + # raises(PropertiesOptionError, "cfg.config(confwrite).option(pathread).owner.isdefault()") + # raises(PropertiesOptionError, "cfg.config(confread).option(pathread).owner.isdefault()") else: if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - assert api.config(confwrite).option(pathread, 0).owner.isdefault() is True - assert api.config(confwrite).option(pathread, 1).owner.isdefault() is False + assert cfg.config(confwrite).option(pathread, 0).owner.isdefault() is True + assert cfg.config(confwrite).option(pathread, 1).owner.isdefault() is False if confwrite != confread: - assert api.config(confread).option(pathread, 0).owner.isdefault() is True - assert api.config(confread).option(pathread, 1).owner.isdefault() is False + assert cfg.config(confread).option(pathread, 0).owner.isdefault() is True + assert cfg.config(confread).option(pathread, 1).owner.isdefault() is False #FIXME else: - # raises(PropertiesOptionError, "api.config(confwrite).option(pathread, 0).owner.isdefault()") - # raises(PropertiesOptionError, "api.config(confread).option(pathread, 0).owner.isdefault()") + # raises(PropertiesOptionError, "cfg.config(confwrite).option(pathread, 0).owner.isdefault()") + # raises(PropertiesOptionError, "cfg.config(confread).option(pathread, 0).owner.isdefault()") @autocheck -def autocheck_default_owner_with_value_permissive(api, pathread, pathwrite, confread, confwrite, **kwargs): +def autocheck_default_owner_with_value_permissive(cfg, pathread, pathwrite, confread, confwrite, **kwargs): # check if is a isslave - isslave = api.unrestraint.option(pathread).option.isslave() + isslave = cfg.unrestraint.option(pathread).option.isslave() - _set_value(api, pathwrite, confwrite, **kwargs) + _set_value(cfg, pathwrite, confwrite, **kwargs) def do(conf): # test if is default owner with permissive if not kwargs.get('propertyerror', False): if not isslave: - assert api.forcepermissive.config(conf).option(pathread).owner.isdefault() is False + assert cfg.forcepermissive.config(conf).option(pathread).owner.isdefault() is False else: - assert api.forcepermissive.config(conf).option(pathread, 0).owner.isdefault() is True - assert api.forcepermissive.config(conf).option(pathread, 1).owner.isdefault() is False + assert cfg.forcepermissive.config(conf).option(pathread, 0).owner.isdefault() is True + assert cfg.forcepermissive.config(conf).option(pathread, 1).owner.isdefault() is False #FIXME else: - # raises(PropertiesOptionError, "api.forcepermissive.config(conf).option(pathread).owner.isdefault()") + # raises(PropertiesOptionError, "cfg.forcepermissive.config(conf).option(pathread).owner.isdefault()") do(confwrite) if confwrite != confread: do(confread) @autocheck -def autocheck_set_owner_no_value(api, pathread, pathwrite, confread, confwrite, **kwargs): - isslave = api.unrestraint.option(pathread).option.isslave() +def autocheck_set_owner_no_value(cfg, pathread, pathwrite, confread, confwrite, **kwargs): + isslave = cfg.unrestraint.option(pathread).option.isslave() if not kwargs.get('propertyerror', False): if not isslave: - raises(ConfigError, "api.forcepermissive.config(confwrite).option(pathwrite).owner.set('new_user')") + raises(ConfigError, "cfg.forcepermissive.config(confwrite).option(pathwrite).owner.set('new_user')") else: - raises(ConfigError, "api.forcepermissive.option(pathwrite, 1).owner.set('new_user')") + raises(ConfigError, "cfg.forcepermissive.option(pathwrite, 1).owner.set('new_user')") @autocheck -def autocheck_set_owner(api, pathread, pathwrite, confread, confwrite, **kwargs): +def autocheck_set_owner(cfg, pathread, pathwrite, confread, confwrite, **kwargs): # test set owner without permissive - isslave = api.unrestraint.option(pathread).option.isslave() + isslave = cfg.unrestraint.option(pathread).option.isslave() - _set_value(api, pathwrite, confwrite, **kwargs) + _set_value(cfg, pathwrite, confwrite, **kwargs) # set owner without permissive if not isslave: if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - api.config(confwrite).option(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')") + cfg.config(confwrite).option(pathwrite).owner.set('new_user') + raises(ConfigError, "cfg.config(confwrite).option(pathwrite).owner.set('default')") + raises(ConfigError, "cfg.config(confwrite).option(pathwrite).owner.set('forced')") + raises(ConfigError, "cfg.config(confwrite).option(pathwrite).owner.set('meta')") #FIXME else: - # raises(PropertiesOptionError, "api.config(confwrite).option(pathwrite).owner.set('new_user')") + # raises(PropertiesOptionError, "cfg.config(confwrite).option(pathwrite).owner.set('new_user')") else: if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - api.option(pathwrite, 1).owner.set('new_user') + cfg.option(pathwrite, 1).owner.set('new_user') #FIXME else: - # raises(PropertiesOptionError, "api.option(pathwrite, 1).owner.set('new_user')") + # raises(PropertiesOptionError, "cfg.option(pathwrite, 1).owner.set('new_user')") - _check_owner(api, pathread, confwrite, kwargs, owners.new_user, kwargs['owner']) + _check_owner(cfg, pathread, confwrite, kwargs, owners.new_user, kwargs['owner']) if confwrite != confread: - _check_owner(api, pathread, confread, kwargs, owners.new_user, owners.meta) + _check_owner(cfg, pathread, confread, kwargs, owners.new_user, owners.meta) @autocheck -def autocheck_set_owner_permissive(api, pathread, pathwrite, confread, confwrite, **kwargs): - isslave = api.unrestraint.option(pathread).option.isslave() +def autocheck_set_owner_permissive(cfg, pathread, pathwrite, confread, confwrite, **kwargs): + isslave = cfg.unrestraint.option(pathread).option.isslave() - _set_value(api, pathwrite, confwrite, **kwargs) + _set_value(cfg, pathwrite, confwrite, **kwargs) # set owner with permissive if not kwargs.get('propertyerror', False): if not isslave: - api.forcepermissive.config(confwrite).option(pathwrite).owner.set('new_user1') + cfg.forcepermissive.config(confwrite).option(pathwrite).owner.set('new_user1') else: - api.forcepermissive.option(pathwrite, 1).owner.set('new_user1') + cfg.forcepermissive.option(pathwrite, 1).owner.set('new_user1') #FIXME else: # if not isslave: # raises(PropertiesOptionError, - # "api.forcepermissive.config(confwrite).option(pathwrite).owner.set('new_user1')") + # "cfg.forcepermissive.config(confwrite).option(pathwrite).owner.set('new_user1')") # else: # raises(PropertiesOptionError, - # "api.forcepermissive.option(pathwrite, 1).owner.set('new_user1')") + # "cfg.forcepermissive.option(pathwrite, 1).owner.set('new_user1')") - _check_owner(api, pathread, confwrite, kwargs, 'new_user1', 'new_user1') + _check_owner(cfg, pathread, confwrite, kwargs, 'new_user1', 'new_user1') if confwrite != confread: - _check_owner(api, pathread, confread, kwargs, 'new_user1', 'new_user1') + _check_owner(cfg, pathread, confread, kwargs, 'new_user1', 'new_user1') @autocheck -def autocheck_option(api, pathread, pathwrite, confread, confwrite, **kwargs): +def autocheck_option(cfg, 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() + current_name = cfg.option(pathread).option.name() + assert current_name == cfg.forcepermissive.option(pathread).option.name() + assert current_name == cfg.unrestraint.option(pathread).option.name() + doc = cfg.option(pathread).option.doc() + assert doc == cfg.forcepermissive.option(pathread).option.doc() + assert doc == cfg.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() + raises(PropertiesOptionError, "cfg.option(pathread).option.name()") + current_name = cfg.forcepermissive.option(pathread).option.name() + assert current_name == cfg.unrestraint.option(pathread).option.name() + raises(PropertiesOptionError, "cfg.option(pathread).option.doc()") + doc = cfg.forcepermissive.option(pathread).option.doc() + assert doc == cfg.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() + raises(PropertiesOptionError, "cfg.option(pathread).option.name()") + raises(PropertiesOptionError, "cfg.forcepermissive.option(pathread).option.name()") + current_name = cfg.unrestraint.option(pathread).option.name() + raises(PropertiesOptionError, "cfg.option(pathread).option.doc()") + raises(PropertiesOptionError, "cfg.forcepermissive.option(pathread).option.doc()") + doc = cfg.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] @@ -978,100 +978,100 @@ def autocheck_option(api, pathread, pathwrite, confread, confwrite, **kwargs): @autocheck -def autocheck_permissive(api, pathread, pathwrite, confread, confwrite, **kwargs): +def autocheck_permissive(cfg, pathread, pathwrite, confread, confwrite, **kwargs): """test permissive for hidden and disabled value """ # no permissive before - assert api.unrestraint.config(confread).option(pathread).permissive.get() == frozenset() + assert cfg.unrestraint.config(confread).option(pathread).permissive.get() == frozenset() if kwargs.get('permissive_od', False): - assert api.unrestraint.config(confread).option(pathread.rsplit('.', 1)[0]).permissive.get() == frozenset() + assert cfg.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) # # with meta confread == confwrite - _autocheck_default_value(api, pathread, confread, **kwargs) + _autocheck_default_value(cfg, pathread, confread, **kwargs) # set permissive - api.unrestraint.config(confwrite).option(pathwrite).permissive.set(frozenset(['disabled'])) + cfg.unrestraint.config(confwrite).option(pathwrite).permissive.set(frozenset(['disabled'])) callback = kwargs['callback'] if callback: if pathread.endswith('val1') or pathread.endswith('val2'): call_path = pathread[:-4] + 'call' + pathread[-4:] else: call_path = pathread + 'call' - api.unrestraint.config(confwrite).option(call_path).permissive.set(frozenset(['disabled'])) + cfg.unrestraint.config(confwrite).option(call_path).permissive.set(frozenset(['disabled'])) # have permissive - assert api.unrestraint.config(confwrite).option(pathread).permissive.get() == frozenset(['disabled']) + assert cfg.unrestraint.config(confwrite).option(pathread).permissive.get() == frozenset(['disabled']) if confwrite != confread: - assert api.unrestraint.config(confread).option(pathread).permissive.get() == frozenset(['disabled']) + assert cfg.unrestraint.config(confread).option(pathread).permissive.get() == frozenset(['disabled']) # can access to disabled value ckwargs = copy(kwargs) ckwargs['propertyerror'] = False - _autocheck_default_value(api, pathread, confread, **ckwargs) + _autocheck_default_value(cfg, pathread, confread, **ckwargs) - api.unrestraint.config(confwrite).option(pathwrite).permissive.set(frozenset(['disabled', 'hidden'])) + cfg.unrestraint.config(confwrite).option(pathwrite).permissive.set(frozenset(['disabled', 'hidden'])) if kwargs['callback']: - api.unrestraint.config(confwrite).option(call_path).permissive.set(frozenset(['disabled', 'hidden'])) + cfg.unrestraint.config(confwrite).option(call_path).permissive.set(frozenset(['disabled', 'hidden'])) # can access to all value except when optiondescript have hidden if not ckwargs.get('permissive_od', False): ckwargs['permissive'] = False - _autocheck_default_value(api, pathread, confread, **ckwargs) + _autocheck_default_value(cfg, pathread, confread, **ckwargs) if confread != confwrite: - _autocheck_default_value(api, pathread, confwrite, **ckwargs) + _autocheck_default_value(cfg, pathread, confwrite, **ckwargs) if ckwargs.get('permissive_od', False): # set permissive to OptionDescription - api.unrestraint.config(confwrite).option(pathwrite.rsplit('.', 1)[0]).permissive.set(frozenset(['disabled', + cfg.unrestraint.config(confwrite).option(pathwrite.rsplit('.', 1)[0]).permissive.set(frozenset(['disabled', 'hidden'])) ckwargs['permissive'] = False - _autocheck_default_value(api, pathread, confread, **ckwargs) + _autocheck_default_value(cfg, pathread, confread, **ckwargs) if confread != confwrite: - _autocheck_default_value(api, pathread, confwrite, **ckwargs) + _autocheck_default_value(cfg, pathread, confwrite, **ckwargs) # only hidden - api.unrestraint.config(confwrite).option(pathwrite).permissive.set(frozenset(['hidden'])) + cfg.unrestraint.config(confwrite).option(pathwrite).permissive.set(frozenset(['hidden'])) if callback: - api.unrestraint.config(confwrite).option(call_path).permissive.set(frozenset(['hidden'])) + cfg.unrestraint.config(confwrite).option(call_path).permissive.set(frozenset(['hidden'])) if ckwargs.get('permissive_od', False): - _autocheck_default_value(api, pathread, confread, **ckwargs) + _autocheck_default_value(cfg, pathread, confread, **ckwargs) if confread != confwrite: - _autocheck_default_value(api, pathread, confwrite, **ckwargs) - api.unrestraint.config(confwrite).option(pathwrite.rsplit('.', 1)[0]).permissive.set(frozenset(['hidden'])) + _autocheck_default_value(cfg, pathread, confwrite, **ckwargs) + cfg.unrestraint.config(confwrite).option(pathwrite.rsplit('.', 1)[0]).permissive.set(frozenset(['hidden'])) ckwargs = copy(kwargs) ckwargs['permissive'] = False - _autocheck_default_value(api, pathread, confread, **ckwargs) + _autocheck_default_value(cfg, pathread, confread, **ckwargs) if confread != confwrite: - _autocheck_default_value(api, pathread, confwrite, **ckwargs) + _autocheck_default_value(cfg, pathread, confwrite, **ckwargs) # no permissive - api.unrestraint.config(confwrite).option(pathwrite).permissive.set(frozenset()) + cfg.unrestraint.config(confwrite).option(pathwrite).permissive.set(frozenset()) if callback: - api.unrestraint.config(confwrite).option(call_path).permissive.set(frozenset()) + cfg.unrestraint.config(confwrite).option(call_path).permissive.set(frozenset()) if ckwargs.get('permissive_od', False): - _autocheck_default_value(api, pathread, confread, **ckwargs) + _autocheck_default_value(cfg, pathread, confread, **ckwargs) if confread != confwrite: - _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) + _autocheck_default_value(cfg, pathread, confwrite, **ckwargs) + cfg.unrestraint.config(confwrite).option(pathwrite.rsplit('.', 1)[0]).permissive.set(frozenset()) + _autocheck_default_value(cfg, pathread, confread, **kwargs) if confread != confwrite: - _autocheck_default_value(api, pathread, confwrite, **kwargs) + _autocheck_default_value(cfg, pathread, confwrite, **kwargs) @autocheck -def autocheck_option_get(api, pathread, pathwrite, confread, confwrite, **kwargs): +def autocheck_option_get(cfg, pathread, pathwrite, confread, confwrite, **kwargs): if '.' in pathread: name = pathread.rsplit('.', 1)[1] else: name = pathread - assert api.unrestraint.option(pathread).option.name() == name + assert cfg.unrestraint.option(pathread).option.name() == name @autocheck -def autocheck_find(api, pathread, pathwrite, confread, confwrite, **kwargs): +def autocheck_find(cfg, pathread, pathwrite, confread, confwrite, **kwargs): def _getoption(opt): opt = opt.option.get() if opt.impl_is_dynsymlinkoption(): @@ -1088,20 +1088,20 @@ def autocheck_find(api, pathread, pathwrite, confread, confwrite, **kwargs): name = pathread.rsplit('.', 1)[1] else: name = pathread - option = _getoption(api.unrestraint.option(pathread)) + option = _getoption(cfg.unrestraint.option(pathread)) def do(conf): if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - assert option == _getoption(api.config(conf).option.find(name, first=True)) - assert option == _getoption(api.forcepermissive.config(conf).option.find(name, first=True)) + assert option == _getoption(cfg.config(conf).option.find(name, first=True)) + assert option == _getoption(cfg.forcepermissive.config(conf).option.find(name, first=True)) elif kwargs.get('permissive', False): - raises(AttributeError, "api.config(conf).option.find(name, first=True)") - assert option == _getoption(api.forcepermissive.config(conf).option.find(name, first=True)) + raises(AttributeError, "cfg.config(conf).option.find(name, first=True)") + assert option == _getoption(cfg.forcepermissive.config(conf).option.find(name, first=True)) else: - 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)) - assert [option] == _getoptions(api.unrestraint.config(conf).option.find(name)) + raises(AttributeError, "cfg.config(conf).option.find(name, first=True)") + raises(AttributeError, "cfg.forcepermissive.config(conf).option.find(name, first=True)") + assert option == _getoption(cfg.unrestraint.config(conf).option.find(name, first=True)) + assert [option] == _getoptions(cfg.unrestraint.config(conf).option.find(name)) do(confread) if confread != confwrite: do(confwrite) @@ -1310,15 +1310,14 @@ def check_all(cfg, paths_, path, meta, multi, default, default_multi, require, c confread = cfg_name ncfg = MetaConfig([ncfg], session_id='metatest') weakrefs.append(weakref.ref(cfg)) - api = getapi(ncfg) ckwargs = copy(kwargs) if meta: - api.owner.set('meta') + ncfg.owner.set('meta') ckwargs['owner'] = owners.meta else: ckwargs['owner'] = OWNER - if api.unrestraint.option(path).option.isslave(): + if ncfg.unrestraint.option(path).option.isslave(): dirname = path.rsplit('.', 1)[0] master_path = dirname + '.first' master_path_2 = None @@ -1330,14 +1329,14 @@ def check_all(cfg, paths_, path, meta, multi, default, default_multi, require, c value = SUBLIST_SECOND_VALUE else: value = LIST_SECOND_VALUE - api.option(master_path).value.set(value) + ncfg.option(master_path).value.set(value) ckwargs['make_dict'][master_path] = value ckwargs['make_dict_value'][master_path] = value if symlink: ckwargs['make_dict'][master_path + 'link'] = value ckwargs['make_dict_value'][master_path + 'link'] = value if master_path_2: - api.option(master_path_2).value.set(value) + ncfg.option(master_path_2).value.set(value) ckwargs['make_dict'][master_path_2] = value ckwargs['make_dict_value'][master_path_2] = value if symlink: @@ -1393,13 +1392,12 @@ def check_all(cfg, paths_, path, meta, multi, default, default_multi, require, c do('val1', 'val2') do('val2', 'val1') - #FIXME devrait etre dans la config ca ... - api.property.read_write() + ncfg.property.read_write() if req: name = 'extraoptrequire' if symlink: name += 'link' - api.option(name).value.set('value') + ncfg.option(name).value.set('value') if 'permissive' in ckwargs and not 'permissive_od' in ckwargs or \ 'propertyerror' in ckwargs and not 'propertyerror_od' in ckwargs: for to_del in ['permissive', 'propertyerror', 'extra_properties']: @@ -1413,7 +1411,7 @@ def check_all(cfg, paths_, path, meta, multi, default, default_multi, require, c else: pathwrite = path try: - func(api, pathread, pathwrite, confread, confwrite, **ckwargs) + func(ncfg, pathread, pathwrite, confread, confwrite, **ckwargs) except Exception as err: msg = u'error in function {} for {}'.format(func.__name__, path) if multi is True: @@ -1428,7 +1426,6 @@ def check_all(cfg, paths_, path, meta, multi, default, default_multi, require, c msg += u' (symlink)' print(u'{}: {}'.format(msg, ckwargs)) raise err - del api del ncfg diff --git a/test/test_config.py b/test/test_config.py index 524571d..bdacc0a 100644 --- a/test/test_config.py +++ b/test/test_config.py @@ -12,7 +12,7 @@ from tiramisu import Config from tiramisu.config import SubConfig from tiramisu.i18n import _ from tiramisu import Config, IntOption, FloatOption, StrOption, ChoiceOption, \ - BoolOption, UnicodeOption, OptionDescription, getapi, undefined + BoolOption, UnicodeOption, OptionDescription, undefined from tiramisu.error import ConflictError, ConfigError, PropertiesOptionError, APIError @@ -45,8 +45,7 @@ def test_base_config(): gcdummy = BoolOption('dummy', 'dummy', default=False) descr = OptionDescription('tiramisu', '', [gcdummy]) cfg = Config(descr) - api = getapi(cfg) - assert api.option('dummy').value.get() is False + assert cfg.option('dummy').value.get() is False #dmo = cfg.unwrap_from_path('dummy') #assert dmo.impl_getname() == 'dummy' @@ -82,62 +81,49 @@ def test_base_config_name(): def test_base_config_force_permissive(): descr = make_description() config = Config(descr) - api = getapi(config) - api.property.read_write() - api.permissive.set(frozenset(['hidden'])) - raises(PropertiesOptionError, "api.option('boolop').value.get()") - assert api.forcepermissive.option('boolop').value.get() is True + config.property.read_write() + config.permissive.set(frozenset(['hidden'])) + raises(PropertiesOptionError, "config.option('boolop').value.get()") + assert config.forcepermissive.option('boolop').value.get() is True def test_base_config_in_a_tree(): "how options are organized into a tree, see :ref:`tree`" descr = make_description() config = Config(descr) - api = getapi(config) # - api.option('bool').value.set(False) + config.option('bool').value.set(False) # - assert api.option('gc.name').value.get() == 'ref' - api.option('gc.name').value.set('framework') - assert api.option('gc.name').value.get() == 'framework' + assert config.option('gc.name').value.get() == 'ref' + config.option('gc.name').value.set('framework') + assert config.option('gc.name').value.get() == 'framework' # - assert api.option('objspace').value.get() == 'std' - api.option('objspace').value.set('thunk') - assert api.option('objspace').value.get() == 'thunk' + assert config.option('objspace').value.get() == 'std' + config.option('objspace').value.set('thunk') + assert config.option('objspace').value.get() == 'thunk' # - assert api.option('gc.float').value.get() == 2.3 - api.option('gc.float').value.set(3.4) - assert api.option('gc.float').value.get() == 3.4 + assert config.option('gc.float').value.get() == 2.3 + config.option('gc.float').value.set(3.4) + assert config.option('gc.float').value.get() == 3.4 # - assert api.option('int').value.get() == 0 - api.option('int').value.set(123) - assert api.option('int').value.get() == 123 + assert config.option('int').value.get() == 0 + config.option('int').value.set(123) + assert config.option('int').value.get() == 123 # - assert api.option('wantref').value.get() is False - api.option('wantref').value.set(True) - assert api.option('wantref').value.get() is True + assert config.option('wantref').value.get() is False + config.option('wantref').value.set(True) + assert config.option('wantref').value.get() is True # - assert api.option('str').value.get() == 'abc' - api.option('str').value.set('def') - assert api.option('str').value.get() == 'def' + assert config.option('str').value.get() == 'abc' + config.option('str').value.set('def') + assert config.option('str').value.get() == 'def' # - raises(AttributeError, "api.option('gc.foo').value.get()") + raises(AttributeError, "config.option('gc.foo').value.get()") ## config = Config(descr) - api = getapi(config) - assert api.option('bool').value.get() is True - assert api.option('gc.name').value.get() == 'ref' - assert api.option('wantframework').value.get() is False - - -#def test_cfgimpl_get_home_by_path(): -# " :meth:`tiramisu.config.SubConfig.cfgimpl_get_home_by_path()` to retrieve a path" -# descr = make_description() -# config = Config(descr) -# api = getapi(config) -# api.option('bool').value.set(False) -# assert config.cfgimpl_get_home_by_path('gc.dummy', None)[1] == 'dummy' -# assert config.cfgimpl_get_home_by_path('dummy', None)[1] == 'dummy' + assert config.option('bool').value.get() is True + assert config.option('gc.name').value.get() == 'ref' + assert config.option('wantframework').value.get() is False def test_not_valid_properties(): @@ -147,68 +133,27 @@ def test_not_valid_properties(): def test_information_config(): descr = make_description() config = Config(descr) - api = getapi(config) string = 'some informations' # - api.information.set('info', string) - assert api.information.get('info') == string + config.information.set('info', string) + assert config.information.get('info') == string # - raises(ValueError, "api.information.get('noinfo')") - assert api.information.get('noinfo', 'default') == 'default' - api.information.reset('info') - raises(ValueError, "api.information.get('info')") - raises(ValueError, "api.information.reset('noinfo')") + raises(ValueError, "config.information.get('noinfo')") + assert config.information.get('noinfo', 'default') == 'default' + config.information.reset('info') + raises(ValueError, "config.information.get('info')") + raises(ValueError, "config.information.reset('noinfo')") def test_config_impl_get_path_by_opt(): descr = make_description() config = Config(descr) - api = getapi(config) - dummy = api.option('gc.dummy').option.get() - boo = api.option('bool').option.get() + dummy = config.option('gc.dummy').option.get() + boo = config.option('bool').option.get() unknown = IntOption('test', '') unknown assert config._config.cfgimpl_get_description().impl_get_path_by_opt(boo) == 'bool' assert config._config.cfgimpl_get_description().impl_get_path_by_opt(dummy) == 'gc.dummy' - #raises(AttributeError, "config.cfgimpl_get_description().impl_get_path_by_opt(unknown)") - - -#def test_config_impl_get_path_by_opt_od(): -# descr = make_description() -# config = Config(descr) -# api = getapi(config) -# dummy = api.option.get('gc.dummy') -# dummy -# raises(ConfigError, "config.getattr('gc', None).cfgimpl_get_description().impl_get_path_by_opt(dummy)") -# -# -#def test_config_impl_get_opt_by_path(): -# descr = make_description() -# config = Config(descr) -# api = getapi(config) -# dummy = api.option.get('gc.dummy') -# boo = api.option.get('bool') -# assert config.cfgimpl_get_description().impl_get_opt_by_path('bool') == boo -# assert config.cfgimpl_get_description().impl_get_opt_by_path('gc.dummy') == dummy -# raises(AttributeError, "config.cfgimpl_get_description().impl_get_opt_by_path('gc.unknown')") -# raises(ConfigError, "config.getattr('gc', None).cfgimpl_get_description().impl_get_opt_by_path('gc.unknown')") - - -#def test_information_display(): -# g1 = IntOption('g1', '', 1) -# g2 = StrOption('g2', '', 'héhé') -# g3 = UnicodeOption('g3', '', u'héhé') -# g4 = BoolOption('g4', '', True) -# g5 = StrOption('g5', '') -# d1 = OptionDescription('od', '', [g1, g2, g3, g4, g5]) -# root = OptionDescription('root', '', [d1]) -# config = Config(root) -# assert str(config.od) == """g1 = 1 -#g2 = héhé -#g3 = héhé -#g4 = True -#g5 = None""" -# assert str(config) == '[od]' def to_tuple(val): @@ -234,22 +179,21 @@ def test_get_modified_values(): d1 = OptionDescription('od', '', [g1, g2, g3, g4, g5, g6]) root = OptionDescription('root', '', [d1]) config = Config(root) - api = getapi(config) - assert to_tuple(api.value.exportation()) == ((), (), (), ()) - api.option('od.g5').value.set('yes') - assert to_tuple(api.value.exportation()) == (('od.g5',), (None,), ('yes',), ('user',)) - api.option('od.g4').value.set(True) - assert to_tuple(api.value.exportation()) == (('od.g5', 'od.g4'), (None, None), ('yes', True), ('user', 'user')) - api.option('od.g4').value.reset() - assert to_tuple(api.value.exportation()) == (('od.g5',), (None,), ('yes',), ('user',)) - api.option('od.g6').value.set([undefined]) - assert to_tuple(api.value.exportation()) == (('od.g5', 'od.g6'), (None, None), ('yes', (None,)), ('user', 'user')) - api.option('od.g6').value.set([]) - assert to_tuple(api.value.exportation()) == (('od.g5', 'od.g6'), (None, None), ('yes', tuple()), ('user', 'user')) - api.option('od.g6').value.set(['3']) - assert to_tuple(api.value.exportation()) == (('od.g5', 'od.g6'), (None, None), ('yes', ('3',)), ('user', 'user')) - api.option('od.g6').value.set([]) - assert to_tuple(api.value.exportation()) == (('od.g5', 'od.g6'), (None, None), ('yes', tuple()), ('user', 'user')) + assert to_tuple(config.value.exportation()) == ((), (), (), ()) + config.option('od.g5').value.set('yes') + assert to_tuple(config.value.exportation()) == (('od.g5',), (None,), ('yes',), ('user',)) + config.option('od.g4').value.set(True) + assert to_tuple(config.value.exportation()) == (('od.g5', 'od.g4'), (None, None), ('yes', True), ('user', 'user')) + config.option('od.g4').value.reset() + assert to_tuple(config.value.exportation()) == (('od.g5',), (None,), ('yes',), ('user',)) + config.option('od.g6').value.set([undefined]) + assert to_tuple(config.value.exportation()) == (('od.g5', 'od.g6'), (None, None), ('yes', (None,)), ('user', 'user')) + config.option('od.g6').value.set([]) + assert to_tuple(config.value.exportation()) == (('od.g5', 'od.g6'), (None, None), ('yes', tuple()), ('user', 'user')) + config.option('od.g6').value.set(['3']) + assert to_tuple(config.value.exportation()) == (('od.g5', 'od.g6'), (None, None), ('yes', ('3',)), ('user', 'user')) + config.option('od.g6').value.set([]) + assert to_tuple(config.value.exportation()) == (('od.g5', 'od.g6'), (None, None), ('yes', tuple()), ('user', 'user')) def test_get_modified_values_not_modif(): @@ -257,39 +201,10 @@ def test_get_modified_values_not_modif(): d1 = OptionDescription('od', '', [g1]) root = OptionDescription('root', '', [d1]) config = Config(root) - api = getapi(config) - assert api.option('od.g1').value.get() == [] - value = api.option('od.g1').value.get() + assert config.option('od.g1').value.get() == [] + value = config.option('od.g1').value.get() value.append('val') - assert api.option('od.g1').value.get() == [] - - -#def test_has_value(): -# g1 = IntOption('g1', '', 1) -# g2 = StrOption('g2', '', 'héhé') -# g3 = UnicodeOption('g3', '', u'héhé') -# g4 = BoolOption('g4', '', True) -# g5 = StrOption('g5', '') -# d1 = OptionDescription('od', '', [g1, g2, g3, g4, g5]) -# root = OptionDescription('root', '', [d1]) -# config = Config(root) -# api = getapi(config) -# assert not g5 in config.cfgimpl_get_values() -# api.option('od.g5').value.set('yes') -# assert g5 in config.cfgimpl_get_values() - - -#def test_values_not_setitem(): -# g1 = IntOption('g1', '', 1) -# g2 = StrOption('g2', '', 'héhé') -# g3 = UnicodeOption('g3', '', u'héhé') -# g4 = BoolOption('g4', '', True) -# g5 = StrOption('g5', '') -# d1 = OptionDescription('od', '', [g1, g2, g3, g4, g5]) -# root = OptionDescription('root', '', [d1]) -# config = Config(root) -# config -# raises(ConfigError, "config.cfgimpl_get_values()[g1] = 2") + assert config.option('od.g1').value.get() == [] def test_duplicated_option(): @@ -311,9 +226,7 @@ def test_duplicated_option_diff_od(): def test_cannot_assign_value_to_option_description(): descr = make_description() cfg = Config(descr) - api = getapi(cfg) - api - raises(APIError, "api.option('gc').value.set(3)") + raises(APIError, "cfg.option('gc').value.set(3)") def test_config_multi(): @@ -322,53 +235,30 @@ def test_config_multi(): i3 = IntOption('test3', '', default=[2], multi=True, default_multi=1) od = OptionDescription('test', '', [i1, i2, i3]) config = Config(od) - api = getapi(config) - assert api.option('test1').value.get() == [] - assert api.option('test2').value.get() == [] - api.option('test2').value.set([undefined]) - assert api.option('test2').value.get() == [1] - assert api.option('test3').value.get() == [2] - api.option('test3').value.set([undefined, undefined]) - assert api.option('test3').value.get() == [2, 1] + assert config.option('test1').value.get() == [] + assert config.option('test2').value.get() == [] + config.option('test2').value.set([undefined]) + assert config.option('test2').value.get() == [1] + assert config.option('test3').value.get() == [2] + config.option('test3').value.set([undefined, undefined]) + assert config.option('test3').value.get() == [2, 1] def test_no_validation(): i1 = IntOption('test1', '') od = OptionDescription('test', '', [i1]) - cfg = Config(od) - api = getapi(cfg) - api.property.read_write() - api.option('test1').value.set(1) - raises(ValueError, "api.option('test1').value.set('yes')") - assert api.option('test1').value.get() == 1 - api.property.pop('validator') - api.option('test1').value.set('yes') - assert api.option('test1').value.get() == 'yes' - api.property.add('validator') - raises(ValueError, "api.option('test1').value.get()") - api.option('test1').value.reset() - assert api.option('test1').value.get() is None - - -#def test_delete_config_with_subconfig(): -# test = IntOption('test', '') -# multi = IntOption('multi', '', multi=True) -# od = OptionDescription('od', '', [test, multi]) -# odroot = OptionDescription('odroot', '', [od]) -# cfg = Config(odroot) -# api = getapi(cfg) -# sub = cfg.od -# val = cfg.cfgimpl_get_values() -# setting = cfg.cfgimpl_get_settings() -# assert api.option('od.test').value.get() is None -# assert api.option('od.multi').value.get() == [] -# api.config.make_dict() -# del(api) -# del(cfg) -# raises(ConfigError, 'val[test]') -# raises(ConfigError, 'val[multi]') -# raises(ConfigError, 'setting[test]') -# raises(ConfigError, 'sub.make_dict()') + config = Config(od) + config.property.read_write() + config.option('test1').value.set(1) + raises(ValueError, "config.option('test1').value.set('yes')") + assert config.option('test1').value.get() == 1 + config.property.pop('validator') + config.option('test1').value.set('yes') + assert config.option('test1').value.get() == 'yes' + config.property.add('validator') + raises(ValueError, "config.option('test1').value.get()") + config.option('test1').value.reset() + assert config.option('test1').value.get() is None def test_subconfig(): @@ -380,43 +270,6 @@ def test_subconfig(): raises(TypeError, "SubConfig(i, weakref.ref(c))") -#def test_config_weakref(): -# o = OptionDescription('val', '', []) -# o2 = OptionDescription('val', '', [o]) -# c = Config(o2) -# SubConfig(o, weakref.ref(c)) -# raises(ValueError, "SubConfig(o, c)") -# s = SubConfig(o, weakref.ref(c)) -# assert s._cfgimpl_get_context() == c -# del(c) -# raises(ConfigError, "s._cfgimpl_get_context()") - - -#def test_config_str(): -# gcdummy = BoolOption('dummy', 'dummy', default=False) -# gcdummy1 = BoolOption('dummy1', 'dummy', default=False, properties=('disabled',)) -# o = OptionDescription('o', '', [gcdummy, gcdummy1]) -# descr = OptionDescription('tiramisu', '', [o]) -# cfg = Config(descr) -# api = getapi(cfg) -# api.property.read_only() -# str(cfg) -# str(cfg.o) - - -#def test_config_od_function(): -# gcdummy = BoolOption('dummy', 'dummy', default=False) -# gcdummy1 = BoolOption('dummy1', 'dummy', default=False, properties=('disabled',)) -# o = OptionDescription('o', '', [gcdummy, gcdummy1]) -# descr = OptionDescription('tiramisu', '', [o]) -# cfg = Config(descr) -# try: -# print(cfg.impl_get_opt_by_path()) -# except AttributeError as err: -# assert str(err) == _('unknown Option {0} in OptionDescription {1}' -# '').format('impl_get_opt_by_path', descr.impl_getname()) - - def test_config_subconfig(): i1 = IntOption('i1', '') i2 = IntOption('i2', '', default=1) @@ -425,5 +278,4 @@ def test_config_subconfig(): od1 = OptionDescription('od1', '', [i1, i2, i3, i4]) od2 = OptionDescription('od2', '', [od1]) conf1 = Config(od2, session_id='conf1') - api = getapi(conf1) raises(ConfigError, "conf2 = Config(od1, session_id='conf2')") diff --git a/test/test_config_domain.py b/test/test_config_domain.py index 7c98fa3..b9a98e1 100644 --- a/test/test_config_domain.py +++ b/test/test_config_domain.py @@ -8,7 +8,6 @@ from tiramisu import Config from tiramisu.option import DomainnameOption, EmailOption, URLOption, OptionDescription from tiramisu.error import ValueWarning from tiramisu.i18n import _ -from tiramisu import getapi def test_domainname(): @@ -16,50 +15,48 @@ def test_domainname(): f = DomainnameOption('f', '', allow_without_dot=True) g = DomainnameOption('g', '', allow_ip=True) od = OptionDescription('a', '', [d, f, g]) - c = Config(od) - api = getapi(c) - api.property.read_write() - api.option('d').value.set('toto.com') - raises(ValueError, "api.option('d').value.set('toto')") - api.option('d').value.set('toto3.com') - raises(ValueError, "api.option('d').value.set('toto_super.com')") - api.option('d').value.set('toto-.com') - raises(ValueError, "api.option('d').value.set('toto..com')") + cfg = Config(od) + cfg.property.read_write() + cfg.option('d').value.set('toto.com') + raises(ValueError, "cfg.option('d').value.set('toto')") + cfg.option('d').value.set('toto3.com') + raises(ValueError, "cfg.option('d').value.set('toto_super.com')") + cfg.option('d').value.set('toto-.com') + raises(ValueError, "cfg.option('d').value.set('toto..com')") # - api.option('f').value.set('toto.com') - api.option('f').value.set('toto') - api.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea') - raises(ValueError, "api.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamean')") - api.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nd') - api.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnameto.olongthathavemorethanmaximumsizeforatruedomainnameanditsnoteas.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowie') - raises(ValueError, "api.option('d').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnameto.olongthathavemorethanmaximumsizeforatruedomainnameanditsnoteas.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowien')") - api.option('f').value.set('d') - api.option('f').value.set('d.t') + cfg.option('f').value.set('toto.com') + cfg.option('f').value.set('toto') + cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea') + raises(ValueError, "cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamean')") + cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nd') + cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnameto.olongthathavemorethanmaximumsizeforatruedomainnameanditsnoteas.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowie') + raises(ValueError, "cfg.option('d').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnameto.olongthathavemorethanmaximumsizeforatruedomainnameanditsnoteas.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowien')") + cfg.option('f').value.set('d') + cfg.option('f').value.set('d.t') # - raises(ValueError, "api.option('f').value.set('192.168.1.1')") - api.option('g').value.set('toto.com') - api.option('g').value.set('192.168.1.0') - api.option('g').value.set('192.168.1.29') + raises(ValueError, "cfg.option('f').value.set('192.168.1.1')") + cfg.option('g').value.set('toto.com') + cfg.option('g').value.set('192.168.1.0') + cfg.option('g').value.set('192.168.1.29') def test_domainname_upper(): d = DomainnameOption('d', '') od = OptionDescription('a', '', [d]) - c = Config(od) - api = getapi(c) - api.property.read_write() - api.option('d').value.set('toto.com') + cfg = Config(od) + cfg.property.read_write() + cfg.option('d').value.set('toto.com') msg = _('some characters are uppercase') has_error = False try: - api.option('d').value.set('TOTO.COM') + cfg.option('d').value.set('TOTO.COM') except ValueError as err: assert msg in str(err) has_error = True assert has_error is True has_error = False try: - api.option('d').value.set('toTo.com') + cfg.option('d').value.set('toTo.com') except ValueError as err: assert msg in str(err) has_error = True @@ -72,34 +69,33 @@ def test_domainname_warning(): g = DomainnameOption('g', '', allow_ip=True, warnings_only=True) od = OptionDescription('a', '', [d, f, g]) warnings.simplefilter("always", ValueWarning) - c = Config(od) - api = getapi(c) - api.property.read_write() - api.option('d').value.set('toto.com') - raises(ValueError, "api.option('d').value.set('toto')") - api.option('d').value.set('toto3.com') + cfg = Config(od) + cfg.property.read_write() + cfg.option('d').value.set('toto.com') + raises(ValueError, "cfg.option('d').value.set('toto')") + cfg.option('d').value.set('toto3.com') with warnings.catch_warnings(record=True) as w: - api.option('d').value.set('toto_super.com') + cfg.option('d').value.set('toto_super.com') assert len(w) == 1 with warnings.catch_warnings(record=True) as w: - api.option('d').value.set('toto-.com') + cfg.option('d').value.set('toto-.com') assert len(w) == 0 - raises(ValueError, "api.option('d').value.set('toto..com')") + raises(ValueError, "cfg.option('d').value.set('toto..com')") # - api.option('f').value.set('toto.com') - api.option('f').value.set('toto') - api.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea') - raises(ValueError, "api.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamean')") - api.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nd') - api.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnameto.olongthathavemorethanmaximumsizeforatruedomainnameanditsnoteas.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowie') - raises(ValueError, "api.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainname.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnamet.olongthathavemorethanmaximumsizeforatruedomainnameanditsnotea.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowie.xxxx')") - api.option('f').value.set('d') - api.option('f').value.set('d.t') + cfg.option('f').value.set('toto.com') + cfg.option('f').value.set('toto') + cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea') + raises(ValueError, "cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamean')") + cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nd') + cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnameto.olongthathavemorethanmaximumsizeforatruedomainnameanditsnoteas.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowie') + raises(ValueError, "cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainname.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnamet.olongthathavemorethanmaximumsizeforatruedomainnameanditsnotea.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowie.xxxx')") + cfg.option('f').value.set('d') + cfg.option('f').value.set('d.t') # - raises(ValueError, "api.option('f').value.set('192.168.1.1')") - api.option('g').value.set('toto.com') - api.option('g').value.set('192.168.1.0') - api.option('g').value.set('192.168.1.29') + raises(ValueError, "cfg.option('f').value.set('192.168.1.1')") + cfg.option('g').value.set('toto.com') + cfg.option('g').value.set('192.168.1.0') + cfg.option('g').value.set('192.168.1.29') def test_special_domain_name(): @@ -108,73 +104,68 @@ def test_special_domain_name(): d = DomainnameOption('d', '') e = DomainnameOption('e', '', type_='netbios') od = OptionDescription('a', '', [d, e]) - c = Config(od) - api = getapi(c) - api.property.read_write() - api.option('d').value.set('1toto.com') - api.option('d').value.set('123toto.com') - api.option('e').value.set('toto') - api.option('e').value.set('1toto') + cfg = Config(od) + cfg.property.read_write() + cfg.option('d').value.set('1toto.com') + cfg.option('d').value.set('123toto.com') + cfg.option('e').value.set('toto') + cfg.option('e').value.set('1toto') def test_domainname_netbios(): d = DomainnameOption('d', '', type_='netbios') e = DomainnameOption('e', '', "toto", type_='netbios') od = OptionDescription('a', '', [d, e]) - c = Config(od) - api = getapi(c) - api.property.read_write() - raises(ValueError, "api.option('d').value.set('toto.com')") - api.option('d').value.set('toto') - raises(ValueError, "api.option('d').value.set('domainnametoolong')") + cfg = Config(od) + cfg.property.read_write() + raises(ValueError, "cfg.option('d').value.set('toto.com')") + cfg.option('d').value.set('toto') + raises(ValueError, "cfg.option('d').value.set('domainnametoolong')") def test_domainname_hostname(): d = DomainnameOption('d', '', type_='hostname') e = DomainnameOption('e', '', "toto", type_='hostname') od = OptionDescription('a', '', [d, e]) - c = Config(od) - api = getapi(c) - api.property.read_write() - raises(ValueError, "api.option('d').value.set('toto.com')") - api.option('d').value.set('toto') - api.option('d').value.set('domainnametoolong') + cfg = Config(od) + cfg.property.read_write() + raises(ValueError, "cfg.option('d').value.set('toto.com')") + cfg.option('d').value.set('toto') + cfg.option('d').value.set('domainnametoolong') def test_email(): e = EmailOption('e', '') od = OptionDescription('a', '', [e]) - c = Config(od) - api = getapi(c) - api.property.read_write() - api.option('e').value.set('foo-bar.baz@example.com') - api.option('e').value.set('root@foo.com') - api.option('e').value.set('root@domain') - raises(ValueError, "api.option('e').value.set(1)") - raises(ValueError, "api.option('e').value.set('root')") - raises(ValueError, "api.option('e').value.set('root[]@domain')") + cfg = Config(od) + cfg.property.read_write() + cfg.option('e').value.set('foo-bar.baz@example.com') + cfg.option('e').value.set('root@foo.com') + cfg.option('e').value.set('root@domain') + raises(ValueError, "cfg.option('e').value.set(1)") + raises(ValueError, "cfg.option('e').value.set('root')") + raises(ValueError, "cfg.option('e').value.set('root[]@domain')") def test_url(): u = URLOption('u', '') od = OptionDescription('a', '', [u]) - c = Config(od) - api = getapi(c) - api.property.read_write() - api.option('u').value.set('http://foo.com') - api.option('u').value.set('https://foo.com') - api.option('u').value.set('https://foo.com/') - raises(ValueError, "api.option('u').value.set(1)") - raises(ValueError, "api.option('u').value.set('ftp://foo.com')") - raises(ValueError, "api.option('u').value.set('foo.com')") - raises(ValueError, "api.option('u').value.set(':/foo.com')") - raises(ValueError, "api.option('u').value.set('foo.com/http://')") - api.option('u').value.set('https://foo.com/index.html') - api.option('u').value.set('https://foo.com/index.html?var=value&var2=val2') - raises(ValueError, "api.option('u').value.set('https://foo.com/index\\n.html')") - api.option('u').value.set('https://foo.com:8443') - api.option('u').value.set('https://foo.com:8443/') - api.option('u').value.set('https://foo.com:8443/index.html') - raises(ValueError, "api.option('u').value.set('https://foo.com:84438989')") - api.option('u').value.set('https://foo.com:8443/INDEX') - raises(ValueError, "api.option('u').value.set('https://FOO.COM:8443')") + cfg = Config(od) + cfg.property.read_write() + cfg.option('u').value.set('http://foo.com') + cfg.option('u').value.set('https://foo.com') + cfg.option('u').value.set('https://foo.com/') + raises(ValueError, "cfg.option('u').value.set(1)") + raises(ValueError, "cfg.option('u').value.set('ftp://foo.com')") + raises(ValueError, "cfg.option('u').value.set('foo.com')") + raises(ValueError, "cfg.option('u').value.set(':/foo.com')") + raises(ValueError, "cfg.option('u').value.set('foo.com/http://')") + cfg.option('u').value.set('https://foo.com/index.html') + cfg.option('u').value.set('https://foo.com/index.html?var=value&var2=val2') + raises(ValueError, "cfg.option('u').value.set('https://foo.com/index\\n.html')") + cfg.option('u').value.set('https://foo.com:8443') + cfg.option('u').value.set('https://foo.com:8443/') + cfg.option('u').value.set('https://foo.com:8443/index.html') + raises(ValueError, "cfg.option('u').value.set('https://foo.com:84438989')") + cfg.option('u').value.set('https://foo.com:8443/INDEX') + raises(ValueError, "cfg.option('u').value.set('https://FOO.COM:8443')") diff --git a/test/test_config_ip.py b/test/test_config_ip.py index 6259d54..6b8bc59 100644 --- a/test/test_config_ip.py +++ b/test/test_config_ip.py @@ -4,7 +4,7 @@ do_autopath() import warnings from py.test import raises from tiramisu import Config ,IPOption, NetworkOption, NetmaskOption, \ - PortOption, BroadcastOption, OptionDescription, getapi + PortOption, BroadcastOption, OptionDescription from tiramisu.error import ValueWarning @@ -14,23 +14,22 @@ def test_ip(): d = IPOption('d', '', warnings_only=True, private_only=True) warnings.simplefilter("always", ValueWarning) od = OptionDescription('od', '', [a, b, d]) - c = Config(od) - api = getapi(c) - api.option('a').value.set('192.168.1.1') - api.option('a').value.set('192.168.1.0') - api.option('a').value.set('88.88.88.88') - api.option('a').value.set('0.0.0.0') - raises(ValueError, "api.option('a').value.set('255.255.255.0')") - api.option('b').value.set('192.168.1.1') - api.option('b').value.set('192.168.1.0') - raises(ValueError, "api.option('b').value.set('88.88.88.88')") - api.option('b').value.set('0.0.0.0') - raises(ValueError, "api.option('b').value.set('255.255.255.0')") - raises(ValueError, "api.option('a').value.set('333.0.1.20')") + config = Config(od) + config.option('a').value.set('192.168.1.1') + config.option('a').value.set('192.168.1.0') + config.option('a').value.set('88.88.88.88') + config.option('a').value.set('0.0.0.0') + raises(ValueError, "config.option('a').value.set('255.255.255.0')") + config.option('b').value.set('192.168.1.1') + config.option('b').value.set('192.168.1.0') + raises(ValueError, "config.option('b').value.set('88.88.88.88')") + config.option('b').value.set('0.0.0.0') + raises(ValueError, "config.option('b').value.set('255.255.255.0')") + raises(ValueError, "config.option('a').value.set('333.0.1.20')") raises(ValueError, "IPOption('a', 'ip', default='192.000.023.01')") with warnings.catch_warnings(record=True) as w: - api.option('d').value.set('88.88.88.88') + config.option('d').value.set('88.88.88.88') assert len(w) == 1 @@ -38,8 +37,7 @@ def test_ip_default(): a = IPOption('a', '', '88.88.88.88') od = OptionDescription('od', '', [a]) c = Config(od) - api = getapi(c) - api.option('a').value.get() == '88.88.88.88' + c.option('a').value.get() == '88.88.88.88' def test_ip_reserved(): @@ -49,11 +47,10 @@ def test_ip_reserved(): od = OptionDescription('od', '', [a, b, c]) warnings.simplefilter("always", ValueWarning) cfg = Config(od) - api = getapi(cfg) - raises(ValueError, "api.option('a').value.set('226.94.1.1')") - api.option('b').value.set('226.94.1.1') + raises(ValueError, "cfg.option('a').value.set('226.94.1.1')") + cfg.option('b').value.set('226.94.1.1') with warnings.catch_warnings(record=True) as w: - api.option('c').value.set('226.94.1.1') + cfg.option('c').value.set('226.94.1.1') assert len(w) == 1 @@ -62,19 +59,18 @@ def test_network(): b = NetworkOption('b', '', warnings_only=True) od = OptionDescription('od', '', [a, b]) warnings.simplefilter("always", ValueWarning) - c = Config(od) - api = getapi(c) - api.option('a').value.set('192.168.1.1') - api.option('a').value.set('192.168.1.0') - api.option('a').value.set('88.88.88.88') - api.option('a').value.set('0.0.0.0') - raises(ValueError, "api.option('a').value.set(1)") - raises(ValueError, "api.option('a').value.set('1.1.1.1.1')") - raises(ValueError, "api.option('a').value.set('255.255.255.0')") - raises(ValueError, "api.option('a').value.set('192.168.001.0')") - raises(ValueError, "api.option('a').value.set('333.168.1.1')") + cfg = Config(od) + cfg.option('a').value.set('192.168.1.1') + cfg.option('a').value.set('192.168.1.0') + cfg.option('a').value.set('88.88.88.88') + cfg.option('a').value.set('0.0.0.0') + raises(ValueError, "cfg.option('a').value.set(1)") + raises(ValueError, "cfg.option('a').value.set('1.1.1.1.1')") + raises(ValueError, "cfg.option('a').value.set('255.255.255.0')") + raises(ValueError, "cfg.option('a').value.set('192.168.001.0')") + raises(ValueError, "cfg.option('a').value.set('333.168.1.1')") with warnings.catch_warnings(record=True) as w: - api.option('b').value.set('255.255.255.0') + cfg.option('b').value.set('255.255.255.0') assert len(w) == 1 @@ -85,30 +81,28 @@ def test_network_invalid(): def test_netmask(): a = NetmaskOption('a', '') od = OptionDescription('od', '', [a]) - c = Config(od) - api = getapi(c) - raises(ValueError, "api.option('a').value.set('192.168.1.1.1')") - raises(ValueError, "api.option('a').value.set('192.168.1.1')") - raises(ValueError, "api.option('a').value.set('192.168.1.0')") - raises(ValueError, "api.option('a').value.set('88.88.88.88')") - raises(ValueError, "api.option('a').value.set('255.255.255.000')") - raises(ValueError, "api.option('a').value.set(2)") - api.option('a').value.set('0.0.0.0') - api.option('a').value.set('255.255.255.0') + cfg = Config(od) + raises(ValueError, "cfg.option('a').value.set('192.168.1.1.1')") + raises(ValueError, "cfg.option('a').value.set('192.168.1.1')") + raises(ValueError, "cfg.option('a').value.set('192.168.1.0')") + raises(ValueError, "cfg.option('a').value.set('88.88.88.88')") + raises(ValueError, "cfg.option('a').value.set('255.255.255.000')") + raises(ValueError, "cfg.option('a').value.set(2)") + cfg.option('a').value.set('0.0.0.0') + cfg.option('a').value.set('255.255.255.0') def test_broadcast(): a = BroadcastOption('a', '') od = OptionDescription('od', '', [a]) - c = Config(od) - api = getapi(c) - raises(ValueError, "api.option('a').value.set('192.168.1.255.1')") - raises(ValueError, "api.option('a').value.set('192.168.001.255')") - raises(ValueError, "api.option('a').value.set('192.168.0.300')") - raises(ValueError, "api.option('a').value.set(1)") - raises(ValueError, "api.option('a').value.set(2)") - api.option('a').value.set('0.0.0.0') - api.option('a').value.set('255.255.255.0') + cfg = Config(od) + raises(ValueError, "cfg.option('a').value.set('192.168.1.255.1')") + raises(ValueError, "cfg.option('a').value.set('192.168.001.255')") + raises(ValueError, "cfg.option('a').value.set('192.168.0.300')") + raises(ValueError, "cfg.option('a').value.set(1)") + raises(ValueError, "cfg.option('a').value.set(2)") + cfg.option('a').value.set('0.0.0.0') + cfg.option('a').value.set('255.255.255.0') def test_port(): @@ -119,60 +113,59 @@ def test_port(): e = PortOption('e', '', allow_zero=True, allow_private=True) f = PortOption('f', '', allow_private=True) od = OptionDescription('od', '', [a, b, c, d, e, f]) - c = Config(od) - api = getapi(c) - raises(ValueError, "api.option('a').value.set(0)") - api.option('a').value.set(1) - api.option('a').value.set(1023) - api.option('a').value.set(1024) - api.option('a').value.set(49151) - raises(ValueError, "api.option('a').value.set(49152)") - raises(ValueError, "api.option('a').value.set(65535)") - raises(ValueError, "api.option('a').value.set(65536)") + cfg = Config(od) + raises(ValueError, "cfg.option('a').value.set(0)") + cfg.option('a').value.set(1) + cfg.option('a').value.set(1023) + cfg.option('a').value.set(1024) + cfg.option('a').value.set(49151) + raises(ValueError, "cfg.option('a').value.set(49152)") + raises(ValueError, "cfg.option('a').value.set(65535)") + raises(ValueError, "cfg.option('a').value.set(65536)") - api.option('b').value.set(0) - api.option('b').value.set(1) - api.option('b').value.set(1023) - api.option('b').value.set(1024) - api.option('b').value.set(49151) - raises(ValueError, "api.option('b').value.set(49152)") - raises(ValueError, "api.option('b').value.set(65535)") - raises(ValueError, "api.option('b').value.set(65536)") + cfg.option('b').value.set(0) + cfg.option('b').value.set(1) + cfg.option('b').value.set(1023) + cfg.option('b').value.set(1024) + cfg.option('b').value.set(49151) + raises(ValueError, "cfg.option('b').value.set(49152)") + raises(ValueError, "cfg.option('b').value.set(65535)") + raises(ValueError, "cfg.option('b').value.set(65536)") - api.option('c').value.set(0) - api.option('c').value.set(1) - api.option('c').value.set(1023) - raises(ValueError, "api.option('c').value.set(1024)") - raises(ValueError, "api.option('c').value.set(49151)") - raises(ValueError, "api.option('c').value.set(49152)") - raises(ValueError, "api.option('c').value.set(65535)") - raises(ValueError, "api.option('c').value.set(65536)") + cfg.option('c').value.set(0) + cfg.option('c').value.set(1) + cfg.option('c').value.set(1023) + raises(ValueError, "cfg.option('c').value.set(1024)") + raises(ValueError, "cfg.option('c').value.set(49151)") + raises(ValueError, "cfg.option('c').value.set(49152)") + raises(ValueError, "cfg.option('c').value.set(65535)") + raises(ValueError, "cfg.option('c').value.set(65536)") - api.option('d').value.set(0) - raises(ValueError, "api.option('d').value.set(1)") - raises(ValueError, "api.option('d').value.set(1023)") - raises(ValueError, "api.option('d').value.set(1024)") - raises(ValueError, "api.option('d').value.set(49151)") - raises(ValueError, "api.option('d').value.set(49152)") - raises(ValueError, "api.option('d').value.set(65535)") - raises(ValueError, "api.option('d').value.set(65536)") + cfg.option('d').value.set(0) + raises(ValueError, "cfg.option('d').value.set(1)") + raises(ValueError, "cfg.option('d').value.set(1023)") + raises(ValueError, "cfg.option('d').value.set(1024)") + raises(ValueError, "cfg.option('d').value.set(49151)") + raises(ValueError, "cfg.option('d').value.set(49152)") + raises(ValueError, "cfg.option('d').value.set(65535)") + raises(ValueError, "cfg.option('d').value.set(65536)") - api.option('e').value.set(0) - api.option('e').value.set(1) - api.option('e').value.set(1023) - api.option('e').value.set(1024) - api.option('e').value.set(49151) - api.option('e').value.set(49152) - api.option('e').value.set(65535) + cfg.option('e').value.set(0) + cfg.option('e').value.set(1) + cfg.option('e').value.set(1023) + cfg.option('e').value.set(1024) + cfg.option('e').value.set(49151) + cfg.option('e').value.set(49152) + cfg.option('e').value.set(65535) - raises(ValueError, "api.option('f').value.set(0)") - api.option('f').value.set(1) - api.option('f').value.set(1023) - api.option('f').value.set(1024) - api.option('f').value.set(49151) - api.option('f').value.set(49152) - api.option('f').value.set(65535) - raises(ValueError, "api.option('f').value.set(65536)") + raises(ValueError, "cfg.option('f').value.set(0)") + cfg.option('f').value.set(1) + cfg.option('f').value.set(1023) + cfg.option('f').value.set(1024) + cfg.option('f').value.set(49151) + cfg.option('f').value.set(49152) + cfg.option('f').value.set(65535) + raises(ValueError, "cfg.option('f').value.set(65536)") def test_port_range(): @@ -183,72 +176,71 @@ def test_port_range(): e = PortOption('e', '', allow_range=True, allow_zero=True, allow_private=True) f = PortOption('f', '', allow_range=True, allow_private=True) od = OptionDescription('od', '', [a, b, c, d, e, f]) - c = Config(od) - api = getapi(c) - raises(ValueError, "api.option('a').value.set(0)") - api.option('a').value.set(1) - api.option('a').value.set(1023) - api.option('a').value.set(1024) - api.option('a').value.set(49151) - raises(ValueError, "api.option('a').value.set(49152)") - raises(ValueError, "api.option('a').value.set(65535)") - raises(ValueError, "api.option('a').value.set(65536)") - api.option('a').value.set('1:49151') - raises(ValueError, "api.option('a').value.set('0:49151')") - raises(ValueError, "api.option('a').value.set('1:49152')") + cfg = Config(od) + raises(ValueError, "cfg.option('a').value.set(0)") + cfg.option('a').value.set(1) + cfg.option('a').value.set(1023) + cfg.option('a').value.set(1024) + cfg.option('a').value.set(49151) + raises(ValueError, "cfg.option('a').value.set(49152)") + raises(ValueError, "cfg.option('a').value.set(65535)") + raises(ValueError, "cfg.option('a').value.set(65536)") + cfg.option('a').value.set('1:49151') + raises(ValueError, "cfg.option('a').value.set('0:49151')") + raises(ValueError, "cfg.option('a').value.set('1:49152')") - api.option('b').value.set(0) - api.option('b').value.set(1) - api.option('b').value.set(1023) - api.option('b').value.set(1024) - api.option('b').value.set(49151) - raises(ValueError, "api.option('b').value.set(49152)") - raises(ValueError, "api.option('b').value.set(65535)") - raises(ValueError, "api.option('b').value.set(65536)") - api.option('b').value.set('0:49151') - raises(ValueError, "api.option('b').value.set('0:49152')") + cfg.option('b').value.set(0) + cfg.option('b').value.set(1) + cfg.option('b').value.set(1023) + cfg.option('b').value.set(1024) + cfg.option('b').value.set(49151) + raises(ValueError, "cfg.option('b').value.set(49152)") + raises(ValueError, "cfg.option('b').value.set(65535)") + raises(ValueError, "cfg.option('b').value.set(65536)") + cfg.option('b').value.set('0:49151') + raises(ValueError, "cfg.option('b').value.set('0:49152')") - api.option('c').value.set(0) - api.option('c').value.set(1) - api.option('c').value.set(1023) - raises(ValueError, "api.option('c').value.set(1024)") - raises(ValueError, "api.option('c').value.set(49151)") - raises(ValueError, "api.option('c').value.set(49152)") - raises(ValueError, "api.option('c').value.set(65535)") - raises(ValueError, "api.option('c').value.set(65536)") - api.option('c').value.set('0:1023') - raises(ValueError, "api.option('c').value.set('0:1024')") + cfg.option('c').value.set(0) + cfg.option('c').value.set(1) + cfg.option('c').value.set(1023) + raises(ValueError, "cfg.option('c').value.set(1024)") + raises(ValueError, "cfg.option('c').value.set(49151)") + raises(ValueError, "cfg.option('c').value.set(49152)") + raises(ValueError, "cfg.option('c').value.set(65535)") + raises(ValueError, "cfg.option('c').value.set(65536)") + cfg.option('c').value.set('0:1023') + raises(ValueError, "cfg.option('c').value.set('0:1024')") - api.option('d').value.set(0) - raises(ValueError, "api.option('d').value.set(1)") - raises(ValueError, "api.option('d').value.set(1023)") - raises(ValueError, "api.option('d').value.set(1024)") - raises(ValueError, "api.option('d').value.set(49151)") - raises(ValueError, "api.option('d').value.set(49152)") - raises(ValueError, "api.option('d').value.set(65535)") - raises(ValueError, "api.option('d').value.set(65536)") - raises(ValueError, "api.option('d').value.set('0:0')") - raises(ValueError, "api.option('d').value.set('0:1')") + cfg.option('d').value.set(0) + raises(ValueError, "cfg.option('d').value.set(1)") + raises(ValueError, "cfg.option('d').value.set(1023)") + raises(ValueError, "cfg.option('d').value.set(1024)") + raises(ValueError, "cfg.option('d').value.set(49151)") + raises(ValueError, "cfg.option('d').value.set(49152)") + raises(ValueError, "cfg.option('d').value.set(65535)") + raises(ValueError, "cfg.option('d').value.set(65536)") + raises(ValueError, "cfg.option('d').value.set('0:0')") + raises(ValueError, "cfg.option('d').value.set('0:1')") - api.option('e').value.set(0) - api.option('e').value.set(1) - api.option('e').value.set(1023) - api.option('e').value.set(1024) - api.option('e').value.set(49151) - api.option('e').value.set(49152) - api.option('e').value.set(65535) - api.option('e').value.set('0:65535') - raises(ValueError, "api.option('e').value.set('0:65536')") + cfg.option('e').value.set(0) + cfg.option('e').value.set(1) + cfg.option('e').value.set(1023) + cfg.option('e').value.set(1024) + cfg.option('e').value.set(49151) + cfg.option('e').value.set(49152) + cfg.option('e').value.set(65535) + cfg.option('e').value.set('0:65535') + raises(ValueError, "cfg.option('e').value.set('0:65536')") - raises(ValueError, "api.option('f').value.set(0)") - api.option('f').value.set(1) - api.option('f').value.set(1023) - api.option('f').value.set(1024) - api.option('f').value.set(49151) - api.option('f').value.set(49152) - api.option('f').value.set(65535) - raises(ValueError, "api.option('f').value.set(65536)") - api.option('f').value.set('1:65535') - api.option('f').value.set('3:4') - raises(ValueError, "api.option('f').value.set('0:65535')") - raises(ValueError, "api.option('f').value.set('4:3')") + raises(ValueError, "cfg.option('f').value.set(0)") + cfg.option('f').value.set(1) + cfg.option('f').value.set(1023) + cfg.option('f').value.set(1024) + cfg.option('f').value.set(49151) + cfg.option('f').value.set(49152) + cfg.option('f').value.set(65535) + raises(ValueError, "cfg.option('f').value.set(65536)") + cfg.option('f').value.set('1:65535') + cfg.option('f').value.set('3:4') + raises(ValueError, "cfg.option('f').value.set('0:65535')") + raises(ValueError, "cfg.option('f').value.set('4:3')") diff --git a/test/test_dereference.py b/test/test_dereference.py index f698719..cae0596 100644 --- a/test/test_dereference.py +++ b/test/test_dereference.py @@ -4,7 +4,7 @@ do_autopath() from tiramisu import BoolOption, IntOption, StrOption, IPOption, NetmaskOption, \ SymLinkOption, OptionDescription, DynOptionDescription, submulti, \ - Config, GroupConfig, MetaConfig, getapi, Params, ParamOption + Config, GroupConfig, MetaConfig, Params, ParamOption import weakref diff --git a/test/test_duplicate_config.py b/test/test_duplicate_config.py index 1cdb200..f5e9ab6 100644 --- a/test/test_duplicate_config.py +++ b/test/test_duplicate_config.py @@ -5,7 +5,7 @@ do_autopath() from tiramisu.setting import groups from tiramisu import Config from tiramisu import ChoiceOption, BoolOption, IntOption, \ - StrOption, OptionDescription, getapi + StrOption, OptionDescription from .test_state import _diff_opts, _diff_conf from py.test import raises @@ -49,12 +49,10 @@ def make_description(): def test_duplicate(): cfg = Config(make_description()) ncfg = cfg.config.duplicate() - api = getapi(cfg) - api2 = getapi(ncfg) - assert api.option('creole.general.numero_etab').value.get() == None - api.option('creole.general.numero_etab').value.set('oui') - assert api.option('creole.general.numero_etab').value.get() == 'oui' - assert api2.option('creole.general.numero_etab').value.get() == None + assert cfg.option('creole.general.numero_etab').value.get() == None + cfg.option('creole.general.numero_etab').value.set('oui') + assert cfg.option('creole.general.numero_etab').value.get() == 'oui' + assert ncfg.option('creole.general.numero_etab').value.get() == None # _diff_opts(cfg.cfgimpl_get_description(), ncfg.cfgimpl_get_description()) # _diff_conf(cfg, ncfg) # cfg.creole.general.numero_etab = 'oui' @@ -69,10 +67,8 @@ def test_duplicate_force_store_value(): descr = make_description() conf = Config(descr) conf2 = Config(descr) - api = getapi(conf) - api2 = getapi(conf2) - assert to_tuple(api.value.exportation()) == (('creole.general.wantref',), (None,), (False,), ('forced',)) - assert to_tuple(api2.value.exportation()) == (('creole.general.wantref',), (None,), (False,), ('forced',)) - api.option('creole.general.wantref').value.set(True) - assert to_tuple(api.value.exportation()) == (('creole.general.wantref',), (None,), (True,), ('user',)) - assert to_tuple(api2.value.exportation()) == (('creole.general.wantref',), (None,), (False,), ('forced',)) + assert to_tuple(conf.value.exportation()) == (('creole.general.wantref',), (None,), (False,), ('forced',)) + assert to_tuple(conf2.value.exportation()) == (('creole.general.wantref',), (None,), (False,), ('forced',)) + conf.option('creole.general.wantref').value.set(True) + assert to_tuple(conf.value.exportation()) == (('creole.general.wantref',), (None,), (True,), ('user',)) + assert to_tuple(conf2.value.exportation()) == (('creole.general.wantref',), (None,), (False,), ('forced',)) diff --git a/test/test_dyn_optiondescription.py b/test/test_dyn_optiondescription.py index 4f6227f..03ba3fa 100644 --- a/test/test_dyn_optiondescription.py +++ b/test/test_dyn_optiondescription.py @@ -8,7 +8,7 @@ from tiramisu import BoolOption, StrOption, ChoiceOption, IPOption, \ UnicodeOption, PortOption, BroadcastOption, DomainnameOption, \ EmailOption, URLOption, UsernameOption, FilenameOption, SymLinkOption, \ OptionDescription, DynOptionDescription, DynSymLinkOption, submulti, MasterSlaves, \ - Config, getapi, Params, ParamOption, ParamValue + Config, Params, ParamOption, ParamValue from tiramisu.error import PropertiesOptionError, ConfigError, ConflictError from tiramisu.storage import delete_session @@ -57,8 +57,7 @@ def test_build_dyndescription(): dod = DynOptionDescription('dod', '', [st1], callback=return_list) od1 = OptionDescription('od', '', [dod]) cfg = Config(od1) - api = getapi(cfg) - assert api.option.make_dict() == {'dodval1.stval1': None, 'dodval2.stval2': None} + assert cfg.option.make_dict() == {'dodval1.stval1': None, 'dodval2.stval2': None} def test_build_dyndescription_raise(): @@ -66,8 +65,7 @@ def test_build_dyndescription_raise(): dod = DynOptionDescription('dod', '', [st1], callback=return_raise) od1 = OptionDescription('od', '', [dod]) cfg = Config(od1) - api = getapi(cfg) - raises(ConfigError, "api.option.make_dict()") + raises(ConfigError, "cfg.option.make_dict()") def test_build_dyndescription_not_list(): @@ -75,8 +73,7 @@ def test_build_dyndescription_not_list(): dod = DynOptionDescription('dod', '', [st1], callback=return_str) od1 = OptionDescription('od', '', [dod]) cfg = Config(od1) - api = getapi(cfg) - raises(ValueError, "api.option.make_dict()") + raises(ValueError, "cfg.option.make_dict()") def test_subpath_dyndescription(): @@ -84,7 +81,7 @@ def test_subpath_dyndescription(): dod = DynOptionDescription('dod', '', [st1], callback=return_list) od1 = OptionDescription('od', '', [dod]) od2 = OptionDescription('od', '', [od1]) - api = getapi(Config(od2)) + api = Config(od2) assert api.option.make_dict() == {'od.dodval1.stval1': None, 'od.dodval2.stval2': None} @@ -93,7 +90,7 @@ def test_list_dyndescription(): dod = DynOptionDescription('dod', '', [st], callback=return_list) od = OptionDescription('od', '', [dod]) od2 = OptionDescription('od', '', [od]) - api = getapi(Config(od2)) + api = Config(od2) assert api.option('od.dodval1.stval1').value.get() is None assert api.option('od.dodval2.stval2').value.get() is None @@ -103,7 +100,7 @@ def test_unknown_dyndescription(): dod = DynOptionDescription('dod', '', [st], callback=return_list) od = OptionDescription('od', '', [dod]) od2 = OptionDescription('od', '', [od]) - api = getapi(Config(od2)) + api = Config(od2) raises(AttributeError, "api.option('od.dodval3').value.get()") raises(AttributeError, "api.option('od.dodval1.novalue').value.get()") raises(AttributeError, "api.option('od.dodval1.stnoval1').value.get()") @@ -114,7 +111,7 @@ def test_getdoc_dyndescription(): dod = DynOptionDescription('dod', 'doc2', [st1], callback=return_list) od1 = OptionDescription('od', '', [dod]) od2 = OptionDescription('od', '', [od1]) - api = getapi(Config(od2)) + api = Config(od2) assert api.option('od.dodval1.stval1').option.name() == 'stval1' assert api.option('od.dodval2.stval2').option.name() == 'stval2' assert api.option('od.dodval1').option.name() == 'dodval1' @@ -130,7 +127,7 @@ def test_mod_dyndescription(): dod = DynOptionDescription('dod', '', [st], callback=return_list) od = OptionDescription('od', '', [dod]) od2 = OptionDescription('od', '', [od]) - api = getapi(Config(od2)) + api = Config(od2) owner = api.owner.get() # assert api.option('od.dodval1.stval1').value.get() is None @@ -156,7 +153,7 @@ def test_del_dyndescription(): dod = DynOptionDescription('dod', '', [st], callback=return_list) od = OptionDescription('od', '', [dod]) od2 = OptionDescription('od', '', [od]) - api = getapi(Config(od2)) + api = Config(od2) owner = api.owner.get() assert api.option('od.dodval1.stval1').value.get() is None assert api.option('od.dodval2.stval2').value.get() is None @@ -171,7 +168,7 @@ def test_multi_dyndescription(): dod = DynOptionDescription('dod', '', [st], callback=return_list) od = OptionDescription('od', '', [dod]) od2 = OptionDescription('od', '', [od]) - api = getapi(Config(od2)) + api = Config(od2) owner = api.owner.get() assert api.option('od.dodval1.stval1').value.get() == [] assert api.option('od.dodval2.stval2').value.get() == [] @@ -198,7 +195,7 @@ def test_prop_dyndescription(): dod = DynOptionDescription('dod', '', [st], callback=return_list) od = OptionDescription('od', '', [dod]) od2 = OptionDescription('od', '', [od]) - api = getapi(Config(od2)) + api = Config(od2) assert set(api.option('od.dodval1.stval1').property.get()) == set(['test']) assert set(api.option('od.dodval2.stval2').property.get()) == set(['test']) api.option('od.dodval2.stval2').property.add('test2') @@ -230,7 +227,7 @@ def test_callback_dyndescription(): dod = DynOptionDescription('dod', '', [st], callback=return_list) od = OptionDescription('od', '', [dod]) od2 = OptionDescription('od', '', [od]) - api = getapi(Config(od2)) + api = Config(od2) owner = api.owner.get() assert api.option('od.dodval1.stval1').value.get() == 'val' assert api.option('od.dodval2.stval2').value.get() == 'val' @@ -253,7 +250,7 @@ def test_callback_list_dyndescription(): dod = DynOptionDescription('dod', '', [st], callback=return_list) od = OptionDescription('od', '', [dod]) od2 = OptionDescription('od', '', [od]) - api = getapi(Config(od2)) + api = Config(od2) owner = api.owner.get() assert api.option('od.dodval1.stval1').value.get() == ['val1', 'val2'] assert api.option('od.dodval2.stval2').value.get() == ['val2', 'val2'] @@ -271,7 +268,7 @@ def test_mandatory_dyndescription(): dod = DynOptionDescription('dod', '', [st], callback=return_list) od = OptionDescription('od', '', [dod]) od2 = OptionDescription('od', '', [od]) - api = getapi(Config(od2)) + api = Config(od2) api.property.read_only() raises(PropertiesOptionError, "api.option('od.dodval1.stval1').value.get()") raises(PropertiesOptionError, "api.option('od.dodval2.stval2').value.get()") @@ -293,8 +290,7 @@ def test_build_dyndescription_context(): dod = DynOptionDescription('dod', '', [st1], callback=return_list, callback_params=Params(ParamOption(val1))) od1 = OptionDescription('od', '', [dod, val1]) cfg = Config(od1) - api = getapi(cfg) - assert api.option.make_dict() == {'dodval1.stval1': None, 'dodval2.stval2': None, 'val1': ['val1', 'val2']} + assert cfg.option.make_dict() == {'dodval1.stval1': None, 'dodval2.stval2': None, 'val1': ['val1', 'val2']} def test_subpath_dyndescription_context(): @@ -303,7 +299,7 @@ def test_subpath_dyndescription_context(): dod = DynOptionDescription('dod', '', [st1], callback=return_list, callback_params=Params(ParamOption(val1))) od1 = OptionDescription('od', '', [dod, val1]) od2 = OptionDescription('od', '', [od1]) - api = getapi(Config(od2)) + api = Config(od2) assert api.option.make_dict() == {'od.dodval1.stval1': None, 'od.dodval2.stval2': None, 'od.val1': ['val1', 'val2']} @@ -313,7 +309,7 @@ def test_list_dyndescription_context(): dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params=Params(ParamOption(val1))) od = OptionDescription('od', '', [dod, val1]) od2 = OptionDescription('od', '', [od]) - api = getapi(Config(od2)) + api = Config(od2) assert api.option('od.dodval1.stval1').value.get() is None assert api.option('od.dodval2.stval2').value.get() is None raises(AttributeError, "api.option('od.dodval3').value.get()") @@ -325,7 +321,7 @@ def test_mod_dyndescription_context(): dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params=Params(ParamOption(val1))) od = OptionDescription('od', '', [dod, val1]) od2 = OptionDescription('od', '', [od]) - api = getapi(Config(od2)) + api = Config(od2) owner = api.owner.get() assert api.option('od.dodval1.stval1').value.get() is None assert api.option('od.dodval2.stval2').value.get() is None @@ -349,7 +345,7 @@ def test_del_dyndescription_context(): dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params=Params(ParamOption(val1))) od = OptionDescription('od', '', [dod, val1]) od2 = OptionDescription('od', '', [od]) - api = getapi(Config(od2)) + api = Config(od2) owner = api.owner.get() assert api.option('od.dodval1.stval1').value.get() is None assert api.option('od.dodval2.stval2').value.get() is None @@ -365,7 +361,7 @@ def test_multi_dyndescription_context(): dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params=Params(ParamOption(val1))) od = OptionDescription('od', '', [dod, val1]) od2 = OptionDescription('od', '', [od]) - api = getapi(Config(od2)) + api = Config(od2) owner = api.owner.get() assert api.option('od.dodval1.stval1').value.get() == [] assert api.option('od.dodval2.stval2').value.get() == [] @@ -393,7 +389,7 @@ def test_prop_dyndescription_context(): dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params=Params(ParamOption(val1))) od = OptionDescription('od', '', [dod, val1]) od2 = OptionDescription('od', '', [od]) - api = getapi(Config(od2)) + api = Config(od2) assert set(api.option('od.dodval1.stval1').property.get()) == set(['test']) assert set(api.option('od.dodval2.stval2').property.get()) == set(['test']) api.option('od.dodval2.stval2').property.add('test2') @@ -410,7 +406,7 @@ def test_callback_dyndescription_context(): dod = DynOptionDescription('dod', '', [st], callback=return_list) od = OptionDescription('od', '', [dod, val1]) od2 = OptionDescription('od', '', [od]) - api = getapi(Config(od2)) + api = Config(od2) owner = api.owner.get() assert api.option('od.dodval1.stval1').value.get() == 'val' assert api.option('od.dodval2.stval2').value.get() == 'val' @@ -434,7 +430,7 @@ def test_mandatory_dyndescription_context(): dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params=Params(ParamOption(val1))) od = OptionDescription('od', '', [dod, val1]) od2 = OptionDescription('od', '', [od]) - api = getapi(Config(od2)) + api = Config(od2) api.property.read_only() raises(PropertiesOptionError, "api.option('od.dodval1.stval1').value.get()") raises(PropertiesOptionError, "api.option('od.dodval2.stval2').value.get()") @@ -456,7 +452,7 @@ def test_increase_dyndescription_context(): dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params=Params(ParamOption(val1))) od = OptionDescription('od', '', [dod, val1]) od2 = OptionDescription('od', '', [od]) - api = getapi(Config(od2)) + api = Config(od2) api.property.read_write() assert api.option('od.dodval1.stval1').value.get() is None assert api.option('od.dodval2.stval2').value.get() is None @@ -473,7 +469,7 @@ def test_decrease_dyndescription_context(): dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params=Params(ParamOption(val1))) od = OptionDescription('od', '', [dod, val1]) od2 = OptionDescription('od', '', [od]) - api = getapi(Config(od2)) + api = Config(od2) owner = api.owner.get() api.property.read_write() assert api.option('od.dodval1.stval1').value.get() is None @@ -508,7 +504,7 @@ def test_requires_dyndescription(): dod = DynOptionDescription('dod', '', [st1], callback=return_list) od1 = OptionDescription('od', '', [dod]) od2 = OptionDescription('od', '', [od1, boolean]) - api = getapi(Config(od2)) + api = Config(od2) api.property.read_write() assert api.option('od.dodval1.stval1').value.get() is None assert api.option('od.dodval2.stval2').value.get() is None @@ -554,7 +550,7 @@ def test_requires_dyndescription2(): 'action': 'disabled'}]) od1 = OptionDescription('od', '', [dod]) od2 = OptionDescription('od', '', [od1, boolean]) - api = getapi(Config(od2)) + api = Config(od2) api.property.read_write() assert api.option('od.dodval1.stval1').value.get() is None assert api.option('od.dodval2.stval2').value.get() is None @@ -598,7 +594,7 @@ def test_validator_dyndescription(): dod = DynOptionDescription('dod', '', [st], callback=return_list) od = OptionDescription('od', '', [dod, val1]) od2 = OptionDescription('od', '', [od]) - api = getapi(Config(od2)) + api = Config(od2) assert api.option('od.dodval1.stval1').value.get() == 'val' raises(ValueError, "api.option('od.dodval1.stval1').value.set('no')") api.option('od.dodval1.stval1').value.set('val') @@ -610,7 +606,7 @@ def test_makedict_dyndescription_context(): dod = DynOptionDescription('dod', '', [st], callback=return_list) od = OptionDescription('od', '', [dod, val1]) od2 = OptionDescription('od', '', [od]) - api = getapi(Config(od2)) + api = Config(od2) api.option('od.dodval1.stval1').value.set('yes') assert api.option.make_dict() == {'od.val1': ['val1', 'val2'], 'od.dodval1.stval1': 'yes', 'od.dodval2.stval2': None} assert api.option.make_dict(flatten=True) == {'val1': ['val1', 'val2'], 'stval1': 'yes', 'stval2': None} @@ -625,7 +621,7 @@ def test_find_dyndescription_context(): dod = DynOptionDescription('dod', '', [st], callback=return_list) od = OptionDescription('od', '', [dod, val1]) od2 = OptionDescription('od', '', [od]) - api = getapi(Config(od2)) + api = Config(od2) api.option('od.dodval1.stval1').value.set('yes') assert api.option.find('stval1', first=True).value.get() == "yes" assert isinstance(api.option.find('stval1', first=True).option.get(), DynSymLinkOption) @@ -645,7 +641,7 @@ def test_information_dyndescription_context(): od2 = OptionDescription('od', '', [od]) dod.impl_set_information('testod', 'val1') st.impl_set_information('testst', 'val2') - api = getapi(Config(od2)) + api = Config(od2) api.information.set('testcfgod', 'val3') assert api.option('od.dodval1').information.get('testod') == 'val1' assert api.option('od.dodval2').information.get('testod') == 'val1' @@ -661,7 +657,7 @@ def test_consistency_dyndescription(): od1 = OptionDescription('od', '', [dod]) st1.impl_add_consistency('not_equal', st2) od2 = OptionDescription('od', '', [od1]) - api = getapi(Config(od2)) + api = Config(od2) api.option('od.dodval1.stval1').value.set('yes') raises(ValueError, "api.option('od.dodval1.st2val1').value.set('yes')") api.option('od.dodval2.stval2').value.set('yes') @@ -680,7 +676,7 @@ def test_consistency_dyndescription_default(): od = OptionDescription('od', '', [dod]) st.impl_add_consistency('not_equal', st2) od2 = OptionDescription('od', '', [od]) - api = getapi(Config(od2)) + api = Config(od2) raises(ValueError, "api.option('od.dodval1.st2val1').value.set('yes')") raises(ValueError, "api.option('od.dodval2.st2val2').value.set('yes')") @@ -767,7 +763,7 @@ def test_all_dyndescription(): domain, email, url, username, filename], callback=return_list) od = OptionDescription('od', '', [dod]) - api = getapi(Config(od)) + api = Config(od) assert api.option('dodval1.stval1').value.get() is None assert api.option('dodval1.ipval1').value.get() is None assert api.option('dodval1.networkval1').value.get() is None @@ -846,12 +842,11 @@ def test_consistency_ip_netmask_dyndescription(): netb.impl_add_consistency('ip_netmask', ipa) od1 = OptionDescription('od', '', [dod]) cfg = Config(od1) - api = getapi(cfg) - api.option('dodval1.aval1').value.set('192.168.1.1') - api.option('dodval1.bval1').value.set('255.255.255.0') - api.option('dodval2.aval2').value.set('192.168.1.2') - api.option('dodval2.bval2').value.set('255.255.255.255') - api.option('dodval2.bval2').value.set('255.255.255.0') + cfg.option('dodval1.aval1').value.set('192.168.1.1') + cfg.option('dodval1.bval1').value.set('255.255.255.0') + cfg.option('dodval2.aval2').value.set('192.168.1.2') + cfg.option('dodval2.bval2').value.set('255.255.255.255') + cfg.option('dodval2.bval2').value.set('255.255.255.0') def test_consistency_ip_in_network_dyndescription(): @@ -862,10 +857,9 @@ def test_consistency_ip_in_network_dyndescription(): ipc.impl_add_consistency('in_network', neta, netb) od1 = OptionDescription('od', '', [dod]) cfg = Config(od1) - api = getapi(cfg) - api.option('dodval1.aval1').value.set('192.168.1.0') - api.option('dodval1.bval1').value.set('255.255.255.0') - api.option('dodval1.cval1').value.set('192.168.1.1') + cfg.option('dodval1.aval1').value.set('192.168.1.0') + cfg.option('dodval1.bval1').value.set('255.255.255.0') + cfg.option('dodval1.cval1').value.set('192.168.1.1') def test_masterslaves_dyndescription(): @@ -875,7 +869,7 @@ def test_masterslaves_dyndescription(): st = DynOptionDescription('st', '', [stm], callback=return_list) od = OptionDescription('od', '', [st]) od2 = OptionDescription('od', '', [od]) - api = getapi(Config(od2)) + api = Config(od2) owner = api.owner.get() # assert api.option.make_dict() == {'od.stval1.st1val1.st2val1': [], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': []} @@ -933,7 +927,7 @@ def test_masterslaves_default_multi_dyndescription(): st = DynOptionDescription('st', '', [stm], callback=return_list) od = OptionDescription('od', '', [st]) od2 = OptionDescription('od', '', [od]) - api = getapi(Config(od2)) + api = Config(od2) owner = api.owner.get() # assert api.option('od.stval1.st1val1.st1val1').value.get() == [] @@ -957,7 +951,7 @@ def test_masterslaves_submulti_dyndescription(): std = DynOptionDescription('st', '', [stm], callback=return_list) od1 = OptionDescription('od', '', [std]) od2 = OptionDescription('od', '', [od1]) - api = getapi(Config(od2)) + api = Config(od2) owner = api.owner.get() # assert api.option('od.stval1.st1val1.st1val1').value.get() == [] @@ -1032,7 +1026,7 @@ def test_masterslaves_callback_dyndescription(): st1 = DynOptionDescription('st', '', [stm], callback=return_list) od1 = OptionDescription('od', '', [st1]) od2 = OptionDescription('od', '', [od1]) - api = getapi(Config(od2)) + api = Config(od2) owner = api.owner.get() assert api.option.make_dict() == {'od.stval1.st1val1.st2val1': [], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': []} assert api.option('od.stval1.st1val1.st1val1').value.get() ==[] @@ -1093,7 +1087,7 @@ def test_masterslaves_callback_value_dyndescription(): st = DynOptionDescription('st', '', [stm], callback=return_list) od = OptionDescription('od', '', [st]) od2 = OptionDescription('od', '', [od]) - api = getapi(Config(od2)) + api = Config(od2) assert api.option('od.stval1.st1val1.st1val1').value.get() == [] api.option('od.stval1.st1val1.st1val1').value.set(['yes']) assert api.option('od.stval1.st1val1.st1val1').value.get() == ['yes'] @@ -1109,7 +1103,7 @@ def test_masterslaves_callback_nomulti_dyndescription(): stt = DynOptionDescription('st', '', [stm], callback=return_list) od1 = OptionDescription('od', '', [stt]) od2 = OptionDescription('od', '', [od1, v11]) - api = getapi(Config(od2)) + api = Config(od2) assert api.option('od.stval1.st1val1.st1val1').value.get() == [] api.option('od.stval1.st1val1.st1val1').value.set(['yes']) assert api.option('od.stval1.st1val1.st1val1').value.get() == ['yes'] @@ -1124,7 +1118,7 @@ def test_masterslaves_callback_samegroup_dyndescription(): stt = DynOptionDescription('st', '', [stm], callback=return_list) od1 = OptionDescription('od', '', [stt]) od2 = OptionDescription('od', '', [od1]) - api = getapi(Config(od2)) + api = Config(od2) owner = api.owner.get() assert api.option.make_dict() == {'od.stval1.st1val1.st1val1': [], 'od.stval1.st1val1.st2val1': [], @@ -1203,8 +1197,7 @@ def test_invalid_samevalue_dyndescription(): dod = DynOptionDescription('dod', '', [st1], callback=return_same_list) od1 = OptionDescription('od', '', [dod]) cfg = Config(od1) - api = getapi(cfg) - raises(ValueError, "api.option.make_dict()") + raises(ValueError, "cfg.option.make_dict()") def test_invalid_name_dyndescription(): @@ -1212,5 +1205,4 @@ def test_invalid_name_dyndescription(): dod = DynOptionDescription('dod', '', [st1], callback=return_wrong_list) od1 = OptionDescription('od', '', [dod]) cfg = Config(od1) - api = getapi(cfg) - raises(ValueError, "api.option.make_dict()") + raises(ValueError, "cfg.option.make_dict()") diff --git a/test/test_freeze.py b/test/test_freeze.py index 3065e2e..f67c305 100644 --- a/test/test_freeze.py +++ b/test/test_freeze.py @@ -8,7 +8,7 @@ from py.test import raises from tiramisu.setting import owners, groups from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \ StrOption, OptionDescription, SymLinkOption, MasterSlaves, Config, \ - getapi, Params, ParamContext, ParamOption, ParamValue + Params, ParamContext, ParamOption, ParamValue from tiramisu.error import PropertiesOptionError, ConfigError @@ -67,7 +67,7 @@ def return_val3(context, value): def test_freeze_whole_config(): descr = make_description_freeze() - api = getapi(Config(descr)) + api = Config(descr) api.property.read_write() api.property.add('everything_frozen') assert api.option('gc.dummy').value.get() is False @@ -96,7 +96,7 @@ def test_freeze_whole_config(): def test_freeze_one_option(): "freeze an option " descr = make_description_freeze() - api = getapi(Config(descr)) + api = Config(descr) api.property.read_write() #freeze only one option api.option('gc.dummy').property.add('frozen') @@ -113,7 +113,7 @@ def test_frozen_value(): "setattr a frozen value at the config level" s = StrOption("string", "", default="string") descr = OptionDescription("options", "", [s]) - api = getapi(Config(descr)) + api = Config(descr) api.property.read_write() api.property.add('frozen') api.option('string').property.add('frozen') @@ -128,7 +128,7 @@ def test_frozen_value(): def test_freeze(): "freeze a whole configuration object" descr = make_description_freeze() - api = getapi(Config(descr)) + api = Config(descr) api.property.read_write() api.property.add('frozen') api.option('gc.name').property.add('frozen') @@ -142,7 +142,7 @@ def test_freeze(): def test_freeze_multi(): descr = make_description_freeze() - api = getapi(Config(descr)) + api = Config(descr) api.property.read_write() api.property.add('frozen') api.option('boolop').property.add('frozen') @@ -157,12 +157,11 @@ def test_freeze_multi(): def test_force_store_value(): descr = make_description_freeze() conf = Config(descr) - api = getapi(conf) - compare(api.value.exportation(), (('wantref', 'wantref2', 'wantref3'), (None, None, None), (False, False, (False,)), ('forced', 'forced', 'forced'))) - api.option('wantref').value.set(True) - compare(api.value.exportation(), (('wantref', 'wantref2', 'wantref3'), (None, None, None), (True, False, (False,)), ('user', 'forced', 'forced'))) - api.option('wantref').value.reset() - compare(api.value.exportation(), (('wantref', 'wantref2', 'wantref3'), (None, None, None), (False, False, (False,)), ('forced', 'forced', 'forced'))) + compare(conf.value.exportation(), (('wantref', 'wantref2', 'wantref3'), (None, None, None), (False, False, (False,)), ('forced', 'forced', 'forced'))) + conf.option('wantref').value.set(True) + compare(conf.value.exportation(), (('wantref', 'wantref2', 'wantref3'), (None, None, None), (True, False, (False,)), ('user', 'forced', 'forced'))) + conf.option('wantref').value.reset() + compare(conf.value.exportation(), (('wantref', 'wantref2', 'wantref3'), (None, None, None), (False, False, (False,)), ('forced', 'forced', 'forced'))) def test_force_store_value_no_requirement(): @@ -185,7 +184,7 @@ def test_force_store_value_masterslaves_slave(): # b = IntOption('int', 'Test int option', multi=True, properties=('force_store_value',)) # c = StrOption('str', 'Test string option', multi=True) # descr = MasterSlaves("int", "", [b, c]) -# api = getapi(Config(descr)) +# api = Config(descr) # assert api.value.get() == {'int': ('forced', ())} @@ -194,28 +193,28 @@ def test_force_store_value_masterslaves_sub(): c = StrOption('str', 'Test string option', multi=True) descr = MasterSlaves("int", "", [b, c]) odr = OptionDescription('odr', '', [descr]) - api = getapi(Config(odr)) + api = Config(odr) compare(api.value.exportation(), (('int.int',), (None,), (tuple(),), ('forced',))) def test_force_store_value_callback(): b = IntOption('int', 'Test int option', properties=('force_store_value',), callback=return_val) descr = OptionDescription("int", "", [b]) - api = getapi(Config(descr)) + api = Config(descr) compare(api.value.exportation(), (('int',), (None,), (1,), ('forced',))) def test_force_store_value_callback_params(): b = IntOption('int', 'Test int option', properties=('force_store_value',), callback=return_val2, callback_params=Params(kwargs={'value': ParamValue(2)})) descr = OptionDescription("int", "", [b]) - api = getapi(Config(descr)) + api = Config(descr) compare(api.value.exportation(), (('int',), (None,), (2,), ('forced',))) def test_force_store_value_callback_params_2(): b = IntOption('int', 'Test int option', properties=('force_store_value',), callback=return_val3, callback_params=Params(ParamContext(), {'value': ParamValue(2)})) descr = OptionDescription("int", "", [b]) - api = getapi(Config(descr)) + api = Config(descr) compare(api.value.exportation(), (('int',), (None,), (2,), ('forced',))) @@ -223,5 +222,5 @@ def test_force_store_value_callback_params_with_opt(): a = IntOption('val1', "", 2) b = IntOption('int', 'Test int option', properties=('force_store_value',), callback=return_val2, callback_params=Params(kwargs={'value': ParamOption(a)})) descr = OptionDescription("int", "", [a, b]) - api = getapi(Config(descr)) + api = Config(descr) compare(api.value.exportation(), (('int',), (None,), (2,), ('forced',))) diff --git a/test/test_mandatory.py b/test/test_mandatory.py index 37e51cb..db2c711 100644 --- a/test/test_mandatory.py +++ b/test/test_mandatory.py @@ -6,7 +6,7 @@ from py.test import raises from tiramisu.api import TIRAMISU_VERSION from tiramisu import Config from tiramisu import IntOption, StrOption, UnicodeOption, OptionDescription, \ - SymLinkOption, MasterSlaves, getapi, undefined, Params, ParamOption + SymLinkOption, MasterSlaves, undefined, Params, ParamOption from tiramisu.error import PropertiesOptionError, ConfigError from tiramisu.setting import groups @@ -71,7 +71,7 @@ def make_description3(): def test_mandatory_ro(): descr = make_description() - api = getapi(Config(descr)) + api = Config(descr) api.property.read_only() prop = [] try: @@ -87,7 +87,7 @@ def test_mandatory_ro(): def test_mandatory_rw(): descr = make_description() - api = getapi(Config(descr)) + api = Config(descr) api.property.read_write() #not mandatory in rw api.option('str1').value.get() @@ -97,7 +97,7 @@ def test_mandatory_rw(): def test_mandatory_default(): descr = make_description() - api = getapi(Config(descr)) + api = Config(descr) api.property.read_only() #not mandatory in rw api.option('str').value.get() @@ -118,7 +118,7 @@ def test_mandatory_default(): def test_mandatory_delete(): descr = make_description() - api = getapi(Config(descr)) + api = Config(descr) api.property.read_only() api.option('str').value.get() try: @@ -145,7 +145,7 @@ def test_mandatory_delete(): #valeur vide : None, '', u'', ... def test_mandatory_none(): descr = make_description() - api = getapi(Config(descr)) + api = Config(descr) api.option('str1').value.set(None) assert api.option('str1').owner.get() == 'user' api.property.read_only() @@ -159,7 +159,7 @@ def test_mandatory_none(): def test_mandatory_empty(): descr = make_description() - api = getapi(Config(descr)) + api = Config(descr) api.option('str1').value.set('') assert api.option('str1').owner.get() == 'user' api.property.read_only() @@ -173,7 +173,7 @@ def test_mandatory_empty(): def test_mandatory_multi_none(): descr = make_description() - api = getapi(Config(descr)) + api = Config(descr) api.option('str3').value.set([None]) assert api.option('str3').owner.get() == 'user' api.property.read_only() @@ -197,7 +197,7 @@ def test_mandatory_multi_none(): def test_mandatory_multi_empty(): descr = make_description() - api = getapi(Config(descr)) + api = Config(descr) api.option('str3').value.set([]) assert api.option('str3').owner.get() == 'user' api.property.read_only() @@ -233,7 +233,7 @@ def test_mandatory_multi_empty(): def test_mandatory_multi_empty_allow_empty_list(): descr = make_description() - api = getapi(Config(descr)) + api = Config(descr) api.option('str4').value.set([]) assert api.option('str4').owner.get() == 'user' api.property.read_only() @@ -265,7 +265,7 @@ def test_mandatory_multi_empty_allow_empty_list(): def test_mandatory_multi_append(): descr = make_description() - api = getapi(Config(descr)) + api = Config(descr) api.option('str3').value.set(['yes']) api.property.read_write() api.option('str3').value.get().append(None) @@ -273,7 +273,7 @@ def test_mandatory_multi_append(): def test_mandatory_disabled(): descr = make_description() - api = getapi(Config(descr)) + api = Config(descr) api.option('str1').value.get() api.option('str1').property.add('disabled') api.property.read_only() @@ -291,7 +291,7 @@ def test_mandatory_disabled(): def test_mandatory_unicode(): descr = make_description() - api = getapi(Config(descr)) + api = Config(descr) api.option('unicode2').value.get() api.property.read_only() prop = [] @@ -313,7 +313,7 @@ def test_mandatory_unicode(): def test_mandatory_warnings_ro(): descr = make_description() - api = getapi(Config(descr)) + api = Config(descr) api.option('str').value.set('') api.property.read_only() proc = [] @@ -331,7 +331,7 @@ def test_mandatory_warnings_ro(): def test_mandatory_warnings_rw(): descr = make_description() - api = getapi(Config(descr)) + api = Config(descr) api.option('str').value.set('') api.property.read_write() api.option('str').value.get() @@ -342,7 +342,7 @@ def test_mandatory_warnings_rw(): def test_mandatory_warnings_disabled(): descr = make_description() - api = getapi(Config(descr)) + api = Config(descr) api.option('str').value.set('') api.property.read_write() api.option('str').value.get() @@ -353,7 +353,7 @@ def test_mandatory_warnings_disabled(): def test_mandatory_warnings_hidden(): descr = make_description() - api = getapi(Config(descr)) + api = Config(descr) api.option('str').value.set('') api.property.read_write() api.permissive.set(frozenset(['hidden'])) @@ -365,7 +365,7 @@ def test_mandatory_warnings_hidden(): def test_mandatory_warnings_frozen(): descr = make_description() - api = getapi(Config(descr)) + api = Config(descr) api.option('str').value.set('') api.property.read_write() api.option('str').value.get() @@ -383,7 +383,7 @@ def test_mandatory_master(): interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) #interface1.impl_set_group_type(groups.master) descr = OptionDescription('o', '', [interface1]) - api = getapi(Config(descr)) + api = Config(descr) api.property.read_only() raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()") @@ -396,7 +396,7 @@ def test_mandatory_warnings_master(): interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) #interface1.impl_set_group_type(groups.master) descr = OptionDescription('o', '', [interface1]) - api = getapi(Config(descr)) + api = Config(descr) assert list(api.value.mandatory_warnings()) == ['ip_admin_eth0.ip_admin_eth0'] @@ -407,7 +407,7 @@ def test_mandatory_master_empty(): interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) #interface1.impl_set_group_type(groups.master) descr = OptionDescription('o', '', [interface1]) - api = getapi(Config(descr)) + api = Config(descr) api.property.read_write() assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] # @@ -450,7 +450,7 @@ def test_mandatory_warnings_master_empty(): interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) #interface1.impl_set_group_type(groups.master) descr = OptionDescription('o', '', [interface1]) - api = getapi(Config(descr)) + api = Config(descr) api.property.read_write() api.option('ip_admin_eth0.ip_admin_eth0').value.set([undefined]) assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [None] @@ -475,7 +475,7 @@ def test_mandatory_slave(): interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) #interface1.impl_set_group_type(groups.master) descr = OptionDescription('o', '', [interface1]) - api = getapi(Config(descr)) + api = Config(descr) api.property.read_only() assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] # @@ -505,7 +505,7 @@ def test_mandatory_warnings_slave(): interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) #interface1.impl_set_group_type(groups.master) descr = OptionDescription('o', '', [interface1]) - api = getapi(Config(descr)) + api = Config(descr) api.property.read_only() assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] # @@ -517,7 +517,7 @@ def test_mandatory_warnings_slave(): def test_mandatory_warnings_symlink(): descr = make_description_sym() - api = getapi(Config(descr)) + api = Config(descr) api.option('str').value.set('') api.property.read_write() api.option('str').value.get() @@ -529,7 +529,7 @@ def test_mandatory_warnings_symlink(): #def test_mandatory_warnings_validate(): # descr = make_description3() -# api = getapi(Config(descr)) +# api = Config(descr) # api.option('str').value.set('') # raises(ValueError, "list(api.value.mandatory_warnings())") # api.option('str').value.set('test') @@ -538,7 +538,7 @@ def test_mandatory_warnings_symlink(): def test_mandatory_warnings_validate_empty(): descr = make_description2() - api = getapi(Config(descr)) + api = Config(descr) api.option('str').value.set('') api.property.read_only() assert list(api.value.mandatory_warnings()) == ['str', 'str1', 'str3', 'unicode1'] @@ -553,7 +553,7 @@ def test_mandatory_warnings_requires(): properties=('mandatory', )) stroption3 = StrOption('str3', 'Test string option', multi=True, requires=[{'option': stroption, 'expected': 'yes', 'action': 'mandatory', 'transitive': False}]) descr = OptionDescription('tiram', '', [stroption, stroption1, stroption2, stroption3]) - api = getapi(Config(descr)) + api = Config(descr) api.option('str').value.set('') api.property.read_write() api.option('str').value.get() @@ -572,7 +572,7 @@ def test_mandatory_warnings_requires_masterslaves(): stroption2 = StrOption('str2', 'Test string option', multi=True, requires=[{'option': stroption, 'expected': 'yes', 'action': 'mandatory', 'transitive': False}]) masterslave = MasterSlaves('master', 'masterslaves', [stroption1, stroption2]) descr = OptionDescription('tiram', '', [stroption, masterslave]) - api = getapi(Config(descr)) + api = Config(descr) api.option('str').value.set('') api.option('master.str1').value.set(['str']) assert list(api.value.mandatory_warnings()) == ['str'] @@ -586,7 +586,7 @@ def test_mandatory_warnings_requires_masterslaves_slave(): stroption2 = StrOption('str2', 'Test string option', multi=True, requires=[{'option': stroption1, 'expected': 'yes', 'action': 'mandatory', 'transitive': False}]) masterslave = MasterSlaves('master', 'masterslaves', [stroption, stroption1, stroption2]) descr = OptionDescription('tiram', '', [masterslave]) - api = getapi(Config(descr)) + api = Config(descr) api.option('master.str').value.set(['str']) assert list(api.value.mandatory_warnings()) == [] api.option('master.str1', 0).value.set('yes') @@ -596,7 +596,7 @@ def test_mandatory_warnings_requires_masterslaves_slave(): def test_mandatory_od_disabled(): descr = make_description() descr = OptionDescription('od', '', [descr]) - api = getapi(Config(descr)) + api = Config(descr) api.property.read_only() assert list(api.value.mandatory_warnings()) == ['tiram.str1', 'tiram.unicode2', 'tiram.str3'] api.option('tiram').property.add('disabled') diff --git a/test/test_masterslaves.py b/test/test_masterslaves.py index 53195ab..a85ec30 100644 --- a/test/test_masterslaves.py +++ b/test/test_masterslaves.py @@ -4,7 +4,7 @@ do_autopath() from tiramisu.setting import groups, owners from tiramisu import ChoiceOption, BoolOption, IntOption, IPOption, NetmaskOption, \ - StrOption, OptionDescription, MasterSlaves, Config, getapi + StrOption, OptionDescription, MasterSlaves, Config from tiramisu.error import SlaveError, PropertiesOptionError, APIError, ConfigError from tiramisu.api import TIRAMISU_VERSION @@ -60,7 +60,7 @@ def make_description(): def test_base_config(): descr = make_description() - api = getapi(Config(descr)) + api = Config(descr) api.property.read_write() assert api.option('creole.general.activer_proxy_client').value.get() is False assert api.option('creole.general.nom_machine').value.get() == "eoleng" @@ -80,7 +80,7 @@ def test_base_config(): def test_make_dict_filter(): descr = make_description() - api = getapi(Config(descr)) + api = Config(descr) api.property.read_write() subresult = {'numero_etab': None, 'nombre_interfaces': 1, 'serveur_ntp': [], 'mode_conteneur_actif': False, @@ -97,7 +97,7 @@ def test_make_dict_filter(): def test_get_group_type(): descr = make_description() - api = getapi(Config(descr)) + api = Config(descr) api.property.read_write() grp = api.option('creole.general') assert grp.group_type() == groups.family @@ -108,7 +108,7 @@ def test_get_group_type(): def test_iter_on_groups(): descr = make_description() - api = getapi(Config(descr)) + api = Config(descr) api.property.read_write() result = api.option('creole').list('optiondescription', group_type=groups.family) group_names = [res.option.name() for res in result] @@ -120,7 +120,7 @@ def test_iter_on_groups(): def test_iter_on_groups_force_permissive(): descr = make_description() - api = getapi(Config(descr)) + api = Config(descr) api.property.read_write() api.permissive.set(frozenset(['hidden'])) result = api.forcepermissive.option('creole.general').list() @@ -138,7 +138,7 @@ def test_iter_on_groups_force_permissive(): def test_iter_group_on_groups_force_permissive(): descr = make_description() - api = getapi(Config(descr)) + api = Config(descr) api.property.read_write() api.permissive.set(frozenset(['hidden'])) result = api.forcepermissive.option('creole').list(type='optiondescription', group_type=groups.family) @@ -148,7 +148,7 @@ def test_iter_group_on_groups_force_permissive(): def test_iter_on_groups_props(): descr = make_description() - api = getapi(Config(descr)) + api = Config(descr) api.property.read_write() api.option('creole.interface1').property.add('disabled') result = api.option('creole').list(type='optiondescription', group_type=groups.family) @@ -157,14 +157,14 @@ def test_iter_on_groups_props(): def test_iter_on_empty_group(): - api = getapi(Config(OptionDescription("name", "descr", []))) + api = Config(OptionDescription("name", "descr", [])) api.property.read_write() result = list(api.option.list(type='optiondescription')) assert result == [] def test_iter_not_group(): - api = getapi(Config(OptionDescription("name", "descr", []))) + api = Config(OptionDescription("name", "descr", [])) api.property.read_write() raises(TypeError, "list(api.option.list(type='optiondescription', group_type='family'))") @@ -184,7 +184,7 @@ def test_groups_is_master(): var = StrOption('var', "ip réseau autorisé", multi=True) od2 = OptionDescription('od2', '', [var]) od1 = OptionDescription('od', '', [interface1, od2]) - api = getapi(Config(od1)) + api = Config(od1) assert not api.option('od2').option.ismasterslaves() assert api.option('ip_admin_eth0').option.ismasterslaves() assert not api.option('od2.var').option.ismaster() @@ -219,7 +219,7 @@ def test_groups_with_master_make_dict(): netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) od = OptionDescription('root', '', [interface1]) - api = getapi(Config(od)) + api = Config(od) assert api.option.make_dict() == {'ip_admin_eth0.ip_admin_eth0': [], 'ip_admin_eth0.netmask_admin_eth0': []} api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip1', 'ip2']) assert api.option.make_dict() == {'ip_admin_eth0.ip_admin_eth0': ['ip1', 'ip2'], 'ip_admin_eth0.netmask_admin_eth0': [None, None]} @@ -230,7 +230,7 @@ def test_groups_with_master_hidden_in_config(): netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, properties=('hidden',)) interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) od = OptionDescription('root', '', [interface1]) - api = getapi(Config(od)) + api = Config(od) api.property.read_write() api.permissive.set(frozenset(['hidden'])) assert api.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] @@ -245,7 +245,7 @@ def test_groups_with_master_hidden_in_config2(): netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, properties=('hidden',)) interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) od = OptionDescription('root', '', [interface1]) - api = getapi(Config(od)) + api = Config(od) api.property.read_write() api.permissive.set(frozenset(['hidden'])) assert api.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] @@ -272,7 +272,7 @@ def test_groups_with_master_reset_empty(): netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) od_ = OptionDescription('root', '', [interface1]) - api = getapi(Config(od_)) + api = Config(od_) api.property.read_write() api.option('ip_admin_eth0.ip_admin_eth0').value.reset() raises(SlaveError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset()") @@ -285,7 +285,7 @@ def test_groups_with_master_reset_out_of_range(): netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) od_ = OptionDescription('root', '', [interface1]) - api = getapi(Config(od_)) + api = Config(od_) api.property.read_write() api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) api.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0') @@ -301,7 +301,7 @@ def test_groups_with_master_hidden_in_config3(): interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) od = OptionDescription('root', '', [interface1]) #interface1.impl_set_group_type(groups.master) - api = getapi(Config(od)) + api = Config(od) api.property.read_write() api.permissive.set(frozenset(['hidden'])) assert api.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] @@ -325,7 +325,7 @@ def test_values_with_master_disabled_master(): interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) #interface1.impl_set_group_type(groups.master) maconfig = OptionDescription('toto', '', [interface1]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145']) api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0) @@ -356,7 +356,7 @@ def test_values_with_master_and_slaves(): interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) #interface1.impl_set_group_type(groups.master) maconfig = OptionDescription('toto', '', [interface1]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() owner = api.owner.get() assert interface1.impl_get_group_type() == groups.master @@ -378,7 +378,7 @@ def test_reset_values_with_master_and_slaves(): interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) #interface1.impl_set_group_type(groups.master) maconfig = OptionDescription('toto', '', [interface1]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() owner = api.owner.get() assert interface1.impl_get_group_type() == groups.master @@ -408,7 +408,7 @@ def test_reset_values_with_master_and_slaves_default(): interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) #interface1.impl_set_group_type(groups.master) maconfig = OptionDescription('toto', '', [interface1]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() owner = api.owner.get() assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault() @@ -449,7 +449,7 @@ def test_values_with_master_and_slaves_slave(): interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) #interface1.impl_set_group_type(groups.master) maconfig = OptionDescription('toto', '', [interface1]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() raises(SlaveError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')") @@ -478,7 +478,7 @@ def test_values_with_master_and_slaves_pop(): interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) #interface1.impl_set_group_type(groups.master) maconfig = OptionDescription('toto', '', [interface1]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145']) api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0') @@ -498,7 +498,7 @@ def test_values_with_master_and_slaves_master(): interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) #interface1.impl_set_group_type(groups.master) maconfig = OptionDescription('toto', '', [interface1]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"]) api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"]) @@ -520,7 +520,7 @@ def test_values_with_master_and_slaves_master_pop(): netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) maconfig = OptionDescription('toto', '', [interface1]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", "192.168.230.146"]) api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.0.0') @@ -552,7 +552,7 @@ def test_values_with_master_owner(): interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) #interface1.impl_set_group_type(groups.master) maconfig = OptionDescription('toto', '', [interface1]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() owner = api.owner.get() assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault() @@ -569,7 +569,7 @@ def test_values_with_master_disabled(): interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) #interface1.impl_set_group_type(groups.master) maconfig = OptionDescription('toto', '', [interface1]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"]) api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0) @@ -598,7 +598,7 @@ def test_values_with_master_disabled(): def test_multi_non_valid_value(): ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) maconfig = OptionDescription('toto', '', [ip_admin_eth0]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() api.option('ip_admin_eth0').value.set(['a']) raises(ValueError, "api.option('ip_admin_eth0').value.set([1])") @@ -610,7 +610,7 @@ def test_multi_master_default_slave(): interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) #interface1.impl_set_group_type(groups.master) maconfig = OptionDescription('toto', '', [interface1]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] @@ -622,7 +622,7 @@ def test_groups_with_master_get_modified_value(): interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) #interface1.impl_set_group_type(groups.master) maconfig = OptionDescription('toto', '', [interface1]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() compare(api.value.exportation(), ((), (), (), ())) api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) @@ -640,7 +640,7 @@ def test_groups_with_master_importation(): interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) #interface1.impl_set_group_type(groups.master) maconfig = OptionDescription('toto', '', [interface1]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() api.value.importation((('ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0',), (None, (0, 1)), (('192.168.1.1', '192.168.1.0'), ('255.255.255.255', '255.255.255.0')), ('user', ('user', 'user')))) api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1', '192.168.1.0'] @@ -657,7 +657,7 @@ def test_wrong_index(): interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) od1 = OptionDescription('od', '', [interface1]) maconfig = OptionDescription('toto', '', [od1]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() assert api.option('od.ip_admin_eth0.ip_admin_eth0').option.get() raises(APIError, "api.option('od.ip_admin_eth0.ip_admin_eth0', 0).option.get()") @@ -698,7 +698,7 @@ def test_slave_not_same(): interface1 = MasterSlaves('interface1', '', [ip_admin_eth1, netmask_admin_eth1]) od1 = OptionDescription('od', '', [interface0, interface1]) maconfig = OptionDescription('toto', '', [od1]) - raises(ConfigError, "getapi(Config(maconfig))") + raises(ConfigError, "Config(maconfig)") def test_slave_not_same_not_equal(): @@ -711,7 +711,7 @@ def test_slave_not_same_not_equal(): interface1 = MasterSlaves('interface1', '', [ip_admin_eth1, netmask_admin_eth1]) od1 = OptionDescription('od', '', [interface0, interface1]) maconfig = OptionDescription('toto', '', [od1]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() @@ -721,4 +721,4 @@ def test_slave_force_store_value(): interface0 = MasterSlaves('interface0', '', [ip_admin_eth0, netmask_admin_eth0]) od1 = OptionDescription('od', '', [interface0]) maconfig = OptionDescription('toto', '', [od1]) - raises(ConfigError, "getapi(Config(maconfig))") + raises(ConfigError, "Config(maconfig)") diff --git a/test/test_option.py b/test/test_option.py index cbc11f1..e7039dd 100644 --- a/test/test_option.py +++ b/test/test_option.py @@ -7,7 +7,7 @@ do_autopath() from py.test import raises from tiramisu.error import APIError -from tiramisu import IntOption, OptionDescription, Config, getapi +from tiramisu import IntOption, OptionDescription, Config def a_func(): @@ -102,7 +102,7 @@ def test_unknown_option(): i = IntOption('test', '') od1 = OptionDescription('od', '', [i]) od2 = OptionDescription('od', '', [od1]) - api = getapi(Config(od2)) + api = Config(od2) # test is an option, not an optiondescription raises(TypeError, "api.option('od.test.unknown').value.get()") # unknown is an unknown option @@ -117,6 +117,6 @@ def test_asign_optiondescription(): i = IntOption('test', '') od1 = OptionDescription('od', '', [i]) od2 = OptionDescription('od', '', [od1]) - api = getapi(Config(od2)) + api = Config(od2) raises(APIError, "api.option('od').value.set('test')") raises(APIError, "api.option('od').value.reset()") diff --git a/test/test_option_callback.py b/test/test_option_callback.py index f0a8f52..e520e3a 100644 --- a/test/test_option_callback.py +++ b/test/test_option_callback.py @@ -8,7 +8,7 @@ from tiramisu.config import KernelConfig from tiramisu.setting import groups, owners from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \ StrOption, OptionDescription, SymLinkOption, IPOption, NetmaskOption, MasterSlaves, \ - getapi, undefined, Params, ParamOption, ParamValue, ParamContext + undefined, Params, ParamOption, ParamValue, ParamContext from tiramisu.api import TIRAMISU_VERSION from tiramisu.error import PropertiesOptionError, ConflictError, SlaveError, ConfigError from tiramisu.i18n import _ @@ -126,7 +126,7 @@ def test_hidden_if_in(): stroption = StrOption('str', 'Test string option', default="abc", requires=({'option': intoption, 'expected': 1, 'action': 'hidden'},)) descr = OptionDescription('constraints', '', [stroption, intoption]) - api = getapi(Config(descr)) + api = Config(descr) api.property.read_write() assert not 'hidden' in api.option('str').property.get() api.option('int').value.set(1) @@ -150,7 +150,7 @@ def test_hidden_if_in_with_group(): requires=({'option': intoption, 'expected': 1, 'action': 'hidden'},)) descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption, stroption, intoption]) - api = getapi(Config(descr)) + api = Config(descr) api.property.read_write() assert not 'hidden' in api.option('str').property.get() api.option('int').value.set(1) @@ -172,7 +172,7 @@ def test_disabled_with_group(): requires=({'option': intoption, 'expected': 1, 'action': 'disabled'},)) descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption, stroption, intoption]) - api = getapi(Config(descr)) + api = Config(descr) api.property.read_write() assert api.option('gc.name').value.get() api.option('int').value.set(1) @@ -206,7 +206,7 @@ def make_description_callback(): def test_has_callback(): descr = make_description_callback() # here the owner is 'default' - api = getapi(Config(descr)) + api = Config(descr) api.property.read_write() api.option('bool').value.set(False) # because dummy has a callback @@ -217,7 +217,7 @@ def test_has_callback(): def test_freeze_and_has_callback(): descr = make_description_callback() - api = getapi(Config(descr)) + api = Config(descr) api.property.read_write() api.option('bool').value.set(False) api.property.add('freeze') @@ -228,7 +228,7 @@ def test_freeze_and_has_callback(): def test_callback(): val1 = StrOption('val1', "", callback=return_val) maconfig = OptionDescription('rootconfig', '', [val1]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() assert api.option('val1').value.get() == 'val' api.option('val1').value.set('new-val') @@ -259,7 +259,7 @@ def test_callback_with_context(): params = Params((context,), {'value': value}) val1 = StrOption("val1", "", callback=is_config, callback_params=params) maconfig = OptionDescription('rootconfig', '', [val1]) - api = getapi(Config(maconfig)) + api = Config(maconfig) assert api.option('val1').value.get() == 'yes' @@ -268,14 +268,14 @@ def test_callback_with_context_named(): params = Params(kwargs={'config': context}) val1 = StrOption("val1", "", callback=is_config, callback_params=params) maconfig = OptionDescription('rootconfig', '', [val1]) - api = getapi(Config(maconfig)) + api = Config(maconfig) assert api.option('val1').value.get() == 'yes' def test_callback_with_error(): val1 = StrOption("val1", "", callback=is_config, callback_params=Params(ParamValue('string'), kwargs={'value': ParamValue('string')})) maconfig = OptionDescription('rootconfig', '', [val1]) - api = getapi(Config(maconfig)) + api = Config(maconfig) assert api.option('val1').value.get() == 'no' @@ -285,7 +285,7 @@ def test_callback_with_context_value(): val1 = StrOption("val1", "") val2 = StrOption("val2", "", callback=ret_from_config, callback_params=params) maconfig = OptionDescription('rootconfig', '', [val1, val2]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.option('val1').value.set('yes') assert api.option('val1').value.get() == 'yes' assert api.option('val2').value.get() == 'yes' @@ -301,7 +301,7 @@ def test_callback_value(): val4 = StrOption('val4', "", callback=return_value, callback_params=Params(kwargs={'value': ParamOption(val1)})) val5 = StrOption('val5', "", callback=return_value, callback_params=Params(ParamValue('yes'))) maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4, val5]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() assert api.option('val1').value.get() == 'val' assert api.option('val2').value.get() == 'val' @@ -324,7 +324,7 @@ def test_callback_value_tuple(): val3 = StrOption('val3', "", callback=return_concat, callback_params=Params((ParamOption(val1), ParamOption(val2)))) val4 = StrOption('val4', "", callback=return_concat, callback_params=Params((ParamValue('yes'), ParamValue('no')))) maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() assert api.option('val1').value.get() == 'val1' assert api.option('val2').value.get() == 'val2' @@ -341,7 +341,7 @@ def test_callback_value_force_permissive(): val2 = StrOption('val2', "", callback=return_value, callback_params=Params(ParamOption(val1))) val3 = StrOption('val3', "", callback=return_value, callback_params=Params(ParamOption(val1, True))) maconfig = OptionDescription('rootconfig', '', [val1, val2, val3]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_only() raises(ConfigError, "api.option('val2').value.get()") api.option('val3').value.get() is None @@ -352,7 +352,7 @@ def test_callback_symlink(): val2 = SymLinkOption('val2', val1) val3 = StrOption('val3', "", callback=return_value, callback_params=Params(ParamOption(val2))) maconfig = OptionDescription('rootconfig', '', [val1, val2, val3]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() assert api.option('val1').value.get() == 'val' assert api.option('val2').value.get() == 'val' @@ -368,7 +368,7 @@ def test_callback_symlink(): def test_callback_list(): val1 = StrOption('val1', "", callback=return_list) maconfig = OptionDescription('rootconfig', '', [val1]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() raises(ValueError, "api.option('val1').value.get()") @@ -378,7 +378,7 @@ def test_callback_list2(): #val2 = StrOption('val2', "", callback=return_value, callback_params=Params(ParamOption(val1))) val2 = StrOption('val2', "", callback=return_value, callback_params=Params(ParamOption(val1))) # , 'forcepermissive': False}]}) maconfig = OptionDescription('rootconfig', '', [val1, val2]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() raises(ValueError, "api.option('val1').value.get()") #cfg.val2 @@ -388,7 +388,7 @@ def test_callback_list2(): def test_callback_multi(): val1 = StrOption('val1', "", callback=return_val, multi=True) maconfig = OptionDescription('rootconfig', '', [val1]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() assert api.option('val1').value.get() == ['val'] api.option('val1').value.set(['new-val']) @@ -413,7 +413,7 @@ def test_callback_multi_value(): val3 = StrOption('val3', "", multi=True, callback=return_value, callback_params=params2) val4 = StrOption('val4', "", multi=True, callback=return_list2, callback_params=params3) maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() assert api.option('val1').value.get() == ['val'] assert api.option('val2').value.get() == ['val'] @@ -439,7 +439,7 @@ def test_callback_multi_value(): def test_callback_multi_list(): val1 = StrOption('val1', "", callback=return_list, multi=True) maconfig = OptionDescription('rootconfig', '', [val1]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() assert api.option('val1').value.get() == ['val', 'val'] api.option('val1').value.set(['new-val']) @@ -453,7 +453,7 @@ def test_callback_multi_list(): def test_callback_multi_list_extend(): val1 = StrOption('val1', "", callback=return_list2, callback_params=Params((ParamValue(['1', '2', '3']), ParamValue(['4', '5']))), multi=True) maconfig = OptionDescription('rootconfig', '', [val1]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() assert api.option('val1').value.get() == ['1', '2', '3', '4', '5'] @@ -462,7 +462,7 @@ def test_callback_multi_callback(): val1 = StrOption('val1', "", multi=True, callback=return_val) interface1 = OptionDescription('val1', '', [val1]) maconfig = OptionDescription('rootconfig', '', [interface1]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() assert api.option('val1.val1').value.get() == ['val'] api.option('val1.val1').value.set(['val1', undefined]) @@ -475,7 +475,7 @@ def test_callback_master_and_slaves_master(): interface1 = MasterSlaves('val1', '', [val1, val2]) #interface1.impl_set_group_type(groups.master) maconfig = OptionDescription('rootconfig', '', [interface1]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() assert api.option('val1.val1').value.get() == ['val'] api.option('val1.val1').value.set([undefined, undefined]) @@ -490,7 +490,7 @@ def test_callback_slave(): interface1 = MasterSlaves('val1', '', [val1, val2]) #interface1.impl_set_group_type(groups.master) maconfig = OptionDescription('rootconfig', '', [interface1]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() api.option('val1.val1').value.set(['val']) assert api.option('val1.val2', 0).value.get() == 'string' @@ -516,7 +516,7 @@ def test_callback_master_and_slaves_master2(): interface1 = MasterSlaves('val1', '', [val1, val2, val3, val4]) #interface1.impl_set_group_type(groups.master) maconfig = OptionDescription('rootconfig', '', [interface1]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() api.option('val1.val1').value.set(['val']) assert api.option('val1.val4', 0).value.get() == 'val2' @@ -532,7 +532,7 @@ def test_callback_master_and_slaves_master_mandatory(): interface1 = MasterSlaves('val1', '', [val1, val3, val4]) #interface1.impl_set_group_type(groups.master) maconfig = OptionDescription('rootconfig', '', [val, interface1]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_only() assert api.option('val1.val3', 0).value.get() == 'val' assert api.option('val1.val4', 0).value.get() == 'val' @@ -555,7 +555,7 @@ def test_callback_master_and_slaves_master_mandatory2(): interface1 = MasterSlaves('val1', '', [val1, val3, val4]) #interface1.impl_set_group_type(groups.master) maconfig = OptionDescription('rootconfig', '', [val, val_, interface1]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_only() assert api.option('val1.val3', 0).value.get() == 'val' assert api.option('val1.val3', 1).value.get() == 'val_' @@ -584,7 +584,7 @@ def test_callback_master_and_slaves_master_mandatory3(): interface1 = MasterSlaves('val1', '', [val1, val3, val4]) #interface1.impl_set_group_type(groups.master) maconfig = OptionDescription('rootconfig', '', [val, val_, interface1]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_only() assert api.option('val1.val3', 0).value.get() == 'val' assert api.option('val1.val3', 1).value.get() == 'val_' @@ -611,7 +611,7 @@ def test_callback_master_and_slaves_master_mandatory4(): interface1 = MasterSlaves('val1', '', [val1, val3, val4]) #interface1.impl_set_group_type(groups.master) maconfig = OptionDescription('rootconfig', '', [val, interface1]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_only() #raises(IndexError, "api.option('val1.val3').value.get()") assert api.option('val1.val3', 0).value.get() == 'val' @@ -635,7 +635,7 @@ def test_callback_master_and_slaves_master3(): interface1 = MasterSlaves('val1', '', [val1, val2, val3, val4]) #interface1.impl_set_group_type(groups.master) maconfig = OptionDescription('rootconfig', '', [interface1]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() assert list(api.value.mandatory_warnings()) == ['val1.val1'] @@ -648,7 +648,7 @@ def test_callback_master_and_slaves_master4(): interface1 = MasterSlaves('val1', '', [val1, val2, val3, val4]) #interface1.impl_set_group_type(groups.master) maconfig = OptionDescription('rootconfig', '', [interface1]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() api.property.add('expert') api.permissive.set(frozenset(['expert'])) @@ -667,7 +667,7 @@ def test_consistency_master_and_slaves_master_mandatory_transitive(): interface1 = MasterSlaves('val1', '', [val1, val2]) interface2 = MasterSlaves('val3', '', [val3, val4]) maconfig = OptionDescription('rootconfig', '', [interface1, interface2]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() err = None try: @@ -694,7 +694,7 @@ def test_consistency_master_and_slaves_master_mandatory_non_transitive(): #interface1.impl_set_group_type(groups.master) #interface2.impl_set_group_type(groups.master) maconfig = OptionDescription('rootconfig', '', [interface1, interface2]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() if TIRAMISU_VERSION == 2: assert list(api.value.mandatory_warnings()) == ["val1.val1", "val1.val2"] @@ -708,7 +708,7 @@ def test_callback_master_and_slaves_master_list(): interface1 = MasterSlaves('val1', '', [val1, val2]) #interface1.impl_set_group_type(groups.master) maconfig = OptionDescription('rootconfig', '', [interface1]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() assert api.option('val1.val1').value.get() == ['val', 'val'] assert api.option('val1.val2', 0).value.get() == None @@ -733,7 +733,7 @@ def test_callback_master_and_slaves_master_slave_list(): interface1 = MasterSlaves('val1', '', [val1, val2]) #interface1.impl_set_group_type(groups.master) maconfig = OptionDescription('rootconfig', '', [interface1]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() assert api.option('val1.val1').value.get() == [] api.option('val1.val1').value.set(['val1']) @@ -746,7 +746,7 @@ def test_callback_master_and_slaves_slave(): interface1 = MasterSlaves('val1', '', [val1, val2]) #interface1.impl_set_group_type(groups.master) maconfig = OptionDescription('rootconfig', '', [interface1]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() assert api.option('val1.val1').value.get() == [] # @@ -787,7 +787,7 @@ def test_callback_master_and_slaves(): interface1 = MasterSlaves('val1', '', [val1, val2]) #interface1.impl_set_group_type(groups.master) maconfig = OptionDescription('rootconfig', '', [interface1]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() @@ -797,7 +797,7 @@ def test_callback_master_and_slaves_slave_cal(): val2 = StrOption('val2', "", multi=True, callback=return_val) interface1 = MasterSlaves('val1', '', [val1, val2]) maconfig = OptionDescription('rootconfig', '', [interface1, val3]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() # assert api.option('val3').value.get() == [] @@ -835,7 +835,7 @@ def test_callback_master_and_slaves_master_disabled(): interface1 = MasterSlaves('val1', '', [val1, val2]) #interface1.impl_set_group_type(groups.master) maconfig = OptionDescription('rootconfig', '', [interface1]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() raises(PropertiesOptionError, "api.option('val1.val1').value.get()") raises(PropertiesOptionError, "api.option('val1.val1').value.set(['yes'])") @@ -849,7 +849,7 @@ def test_callback_master_and_slaves_master_callback_disabled(): interface1 = MasterSlaves('val1', '', [val1, val2]) #interface1.impl_set_group_type(groups.master) maconfig = OptionDescription('rootconfig', '', [interface1, val0]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() raises(ConfigError, "api.option('val1.val1').value.get()") raises(ConfigError, "api.option('val1.val2').value.get()") @@ -865,7 +865,7 @@ def test_callback_master_and_slaves_slave_disabled(): interface1 = MasterSlaves('val1', '', [val1, val2]) #interface1.impl_set_group_type(groups.master) maconfig = OptionDescription('rootconfig', '', [interface1]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() assert api.option('val1.val1').value.get() == [] #raises(PropertiesOptionError, "api.option('val1.val2').value.get()") @@ -894,7 +894,7 @@ def test_callback_master_and_slaves_slave_callback_disabled(): interface1 = MasterSlaves('val1', '', [val1, val2]) #interface1.impl_set_group_type(groups.master) maconfig = OptionDescription('rootconfig', '', [interface1, val0]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() assert api.option('val1.val1').value.get() == [] api.option('val1.val1').value.set(['yes']) @@ -917,7 +917,7 @@ def test_callback_master_and_slaves_value(): interface1 = MasterSlaves('val1', '', [val1, val2, val3, val5, val6]) #interface1.impl_set_group_type(groups.master) maconfig = OptionDescription('rootconfig', '', [interface1, val4]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() api.option('val4').value.get() == ['val10', 'val11'] assert api.option('val1.val1').value.get() == [] @@ -993,7 +993,7 @@ def test_callback_different_type(): interface1 = MasterSlaves('val1', '', [val1, val2]) #interface1.impl_set_group_type(groups.master) maconfig = OptionDescription('rootconfig', '', [interface1, val, val_]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() assert api.option('val1.val1').value.get() == [] api.option('val1.val1').value.set([1]) @@ -1016,7 +1016,7 @@ def test_callback_hidden(): od1 = OptionDescription('od1', '', [opt1], properties=('hidden',)) od2 = OptionDescription('od2', '', [opt2]) maconfig = OptionDescription('rootconfig', '', [od1, od2]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() raises(PropertiesOptionError, "api.option('od1.opt1').value.get()") # do not raise, forcepermissive @@ -1029,7 +1029,7 @@ def test_callback_hidden_permissive(): od1 = OptionDescription('od1', '', [opt1], properties=('hidden',)) od2 = OptionDescription('od2', '', [opt2]) maconfig = OptionDescription('rootconfig', '', [od1, od2]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.permissive.set(frozenset(['hidden'])) api.property.read_write() raises(PropertiesOptionError, "api.option('od1.opt1').value.get()") @@ -1042,7 +1042,7 @@ def test_callback_hidden_permissive_callback(): od1 = OptionDescription('od1', '', [opt1], properties=('hidden',)) od2 = OptionDescription('od2', '', [opt2]) maconfig = OptionDescription('rootconfig', '', [od1, od2]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() raises(PropertiesOptionError, "api.option('od1.opt1').value.get()") api.option('od2.opt2').value.get() @@ -1054,7 +1054,7 @@ def test_callback_two_disabled(): od1 = OptionDescription('od1', '', [opt1]) od2 = OptionDescription('od2', '', [opt2]) maconfig = OptionDescription('rootconfig', '', [od1, od2]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() raises(PropertiesOptionError, "api.option('od2.opt2').value.get()") @@ -1065,7 +1065,7 @@ def test_callback_two_disabled2(): od1 = OptionDescription('od1', '', [opt1]) od2 = OptionDescription('od2', '', [opt2]) maconfig = OptionDescription('rootconfig', '', [od1, od2]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() api.permissive.set(frozenset(['hidden'])) raises(PropertiesOptionError, "api.option('od2.opt2').value.get()") @@ -1078,7 +1078,7 @@ def test_callback_calculating_invalid(): od1 = OptionDescription('od1', '', [opt1]) od2 = OptionDescription('od2', '', [opt2]) maconfig = OptionDescription('rootconfig', '', [od1, od2]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() raises(ValueError, "api.option('od2.opt2').value.get()") api.unrestraint.option('od2.opt2').property.add('disabled') @@ -1091,7 +1091,7 @@ def test_callback_calculating_disabled(): od1 = OptionDescription('od1', '', [opt1]) od2 = OptionDescription('od2', '', [opt2]) maconfig = OptionDescription('rootconfig', '', [od1, od2]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() raises(ConfigError, "api.option('od2.opt2').value.get()") @@ -1102,7 +1102,7 @@ def test_callback_calculating_mandatory(): od1 = OptionDescription('od1', '', [opt1]) od2 = OptionDescription('od2', '', [opt2]) maconfig = OptionDescription('rootconfig', '', [od1, od2]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_only() raises(ConfigError, "api.option('od2.opt2').value.get()") @@ -1113,7 +1113,7 @@ def test_callback_calculating_mandatory_multi(): od1 = OptionDescription('od1', '', [opt1]) od2 = OptionDescription('od2', '', [opt2]) maconfig = OptionDescription('rootconfig', '', [od1, od2]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_only() raises(ConfigError, "api.option('od2.opt2').value.get()") @@ -1124,7 +1124,7 @@ def test_callback_two_disabled_multi(): od1 = OptionDescription('od1', '', [opt1]) od2 = OptionDescription('od2', '', [opt2]) maconfig = OptionDescription('rootconfig', '', [od1, od2]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() raises(PropertiesOptionError, "api.option('od2.opt2').value.get()") @@ -1134,7 +1134,7 @@ def test_callback_multi_list_params(): val2 = StrOption('val2', "", multi=True, callback=return_list, callback_params=Params(ParamOption(val1))) oval2 = OptionDescription('val2', '', [val2]) maconfig = OptionDescription('rootconfig', '', [val1, oval2]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() assert api.option('val2.val2').value.get() == ['val', 'val'] @@ -1144,7 +1144,7 @@ def test_callback_multi_list_params_key(): val2 = StrOption('val2', "", multi=True, callback=return_list, callback_params=Params(kwargs={'value': ParamOption(val1)})) oval2 = OptionDescription('val2', '', [val2]) maconfig = OptionDescription('rootconfig', '', [val1, oval2]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() assert api.option('val2.val2').value.get() == ['val', 'val'] @@ -1157,7 +1157,7 @@ def test_masterslaves_callback_description(): st = OptionDescription('st', '', [stm]) od = OptionDescription('od', '', [st]) od2 = OptionDescription('od', '', [od]) - api = getapi(Config(od2)) + api = Config(od2) owner = api.owner.get() assert api.option('od.st.st1.st1').value.get() == [] assert api.option('od.st.st1.st1').owner.isdefault() @@ -1174,7 +1174,7 @@ def test_callback_raise(): od1 = OptionDescription('od1', '', [opt1]) od2 = OptionDescription('od2', '', [opt2]) maconfig = OptionDescription('rootconfig', '', [od1, od2]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() try: api.option('od1.opt1').value.get() diff --git a/test/test_option_consistency.py b/test/test_option_consistency.py index 56f399f..a5c1de5 100644 --- a/test/test_option_consistency.py +++ b/test/test_option_consistency.py @@ -6,7 +6,7 @@ from py.test import raises from tiramisu.setting import owners, groups from tiramisu import IPOption, NetworkOption, NetmaskOption, IntOption,\ BroadcastOption, StrOption, SymLinkOption, OptionDescription, submulti, MasterSlaves,\ - Config, getapi, undefined, Params, ParamOption + Config, undefined, Params, ParamOption from tiramisu.error import ConfigError, ValueWarning, PropertiesOptionError from tiramisu.api import TIRAMISU_VERSION import warnings @@ -52,7 +52,7 @@ def test_consistency_warnings_only(): b = IntOption('b', '') od = OptionDescription('od', '', [a, b]) a.impl_add_consistency('not_equal', b, warnings_only=True) - api = getapi(Config(od)) + api = Config(od) api.option('a').value.set(1) warnings.simplefilter("always", ValueWarning) with warnings.catch_warnings(record=True) as w: @@ -66,7 +66,7 @@ def test_consistency_warnings_only_more_option(): d = IntOption('d', '') od = OptionDescription('od', '', [a, b, d]) a.impl_add_consistency('not_equal', b, d, warnings_only=True) - api = getapi(Config(od)) + api = Config(od) api.option('a').value.set(1) warnings.simplefilter("always", ValueWarning) with warnings.catch_warnings(record=True) as w: @@ -88,7 +88,7 @@ def test_consistency_not_equal(): b = IntOption('b', '') od = OptionDescription('od', '', [a, b]) a.impl_add_consistency('not_equal', b) - api = getapi(Config(od)) + api = Config(od) assert api.option('a').value.get() is None assert api.option('b').value.get() is None api.option('a').value.set(1) @@ -107,7 +107,7 @@ def test_consistency_not_equal_many_opts(): f = IntOption('f', '') od = OptionDescription('od', '', [a, b, c, d, e, f]) a.impl_add_consistency('not_equal', b, c, d, e, f) - api = getapi(Config(od)) + api = Config(od) assert api.option('a').value.get() is None assert api.option('b').value.get() is None # @@ -139,7 +139,7 @@ def test_consistency_not_equal_many_opts_one_disabled(): g = IntOption('g', '', properties=('disabled',)) od = OptionDescription('od', '', [a, b, c, d, e, f, g]) a.impl_add_consistency('not_equal', b, c, d, e, f, g, transitive=False) - api = getapi(Config(od)) + api = Config(od) api.property.read_write() assert api.option('a').value.get() is None assert api.option('b').value.get() is None @@ -209,7 +209,7 @@ def test_consistency_not_equal_symlink(): c = SymLinkOption('c', a) od = OptionDescription('od', '', [a, b, c]) a.impl_add_consistency('not_equal', b) - api = getapi(Config(od)) + api = Config(od) assert set(od._cache_consistencies.keys()) == set([a, b]) @@ -235,7 +235,7 @@ def test_consistency_not_equal_masterslave(): od2 = OptionDescription('b', '', [od]) #od.impl_set_group_type(groups.master) a.impl_add_consistency('not_equal', b) - api = getapi(Config(od2)) + api = Config(od2) assert api.option('a.a').value.get() == [] api.option('a.a').value.set([1]) api.option('a.a').value.reset() @@ -290,7 +290,7 @@ def test_consistency_not_equal_masterslaves_default(): od2 = OptionDescription('a', '', [od]) #od.impl_set_group_type(groups.master) a.impl_add_consistency('not_equal', b) - api = getapi(Config(od2)) + api = Config(od2) assert api.option('a.a').value.get() == [] raises(ValueError, "api.option('a.a').value.set([1])") api.option('a.a').value.set([2]) @@ -302,7 +302,7 @@ def test_consistency_not_equal_multi(): b = IntOption('b', '', multi=True) od = OptionDescription('a', '', [a, b]) a.impl_add_consistency('not_equal', b) - api = getapi(Config(od)) + api = Config(od) assert api.option('a').value.get() == [] assert api.option('b').value.get() == [] api.option('a').value.set([1]) @@ -337,7 +337,7 @@ def test_consistency_not_equal_master_default(): od = MasterSlaves('a', '', [a, b]) a.impl_add_consistency('not_equal', b) od2 = OptionDescription('a', '', [od]) - api = getapi(Config(od2)) + api = Config(od2) # default_multi not tested raises(ValueError, "api.option('a.b', 0).value.get()") api.option('a.b', 0).value.set(3) @@ -350,7 +350,7 @@ def test_consistency_not_equal_multi_default_modif(): b = IntOption('b', '', multi=True, default=[1, 2]) od = OptionDescription('a', '', [a, b]) a.impl_add_consistency('not_equal', b) - api = getapi(Config(od)) + api = Config(od) assert api.option('a').value.get() == [] assert api.option('b').value.get() == [1, 2] raises(ValueError, "api.option('a').value.set([1])") @@ -379,7 +379,7 @@ def test_consistency_default_diff(): b = IntOption('b', '', 1) od = OptionDescription('od', '', [a, b]) a.impl_add_consistency('not_equal', b) - api = getapi(Config(od)) + api = Config(od) raises(ValueError, "api.option('a').value.set(1)") api.option('a').value.set(2) api.option('b').value.set(3) @@ -394,7 +394,7 @@ def test_consistency_ip_netmask(): b = NetmaskOption('b', '') od = OptionDescription('od', '', [a, b]) b.impl_add_consistency('ip_netmask', a) - api = getapi(Config(od)) + api = Config(od) api.option('a').value.set('192.168.1.1') api.option('b').value.set('255.255.255.0') api.option('a').value.set('192.168.1.2') @@ -409,7 +409,7 @@ def test_consistency_network_netmask(): b = NetmaskOption('b', '') od = OptionDescription('od', '', [a, b]) b.impl_add_consistency('network_netmask', a) - api = getapi(Config(od)) + api = Config(od) api.option('a').value.set('192.168.1.1') api.option('b').value.set('255.255.255.255') api.option('b').value.reset() @@ -427,7 +427,7 @@ def test_consistency_ip_in_network(): c.impl_add_consistency('in_network', a, b) d.impl_add_consistency('in_network', a, b, warnings_only=True) warnings.simplefilter("always", ValueWarning) - api = getapi(Config(od)) + api = Config(od) api.option('a').value.set('192.168.1.0') api.option('b').value.set('255.255.255.0') api.option('c').value.set('192.168.1.1') @@ -455,7 +455,7 @@ def test_consistency_ip_in_network(): # c = NetmaskOption('c', '') # od = OptionDescription('od', '', [a, b, c]) # c.impl_add_consistency('ip_netmask', a, b) -# api = getapi(Config(od)) +# api = Config(od) # api.option('a').value.set('192.168.1.1') # api.option('b').value.set('192.168.1.0') # raises(ConfigError, "api.option('c').value.set('255.255.255.0')") @@ -474,7 +474,7 @@ def test_consistency_ip_netmask_multi(): od = MasterSlaves('a', '', [a, b]) b.impl_add_consistency('ip_netmask', a) od2 = OptionDescription('od2', '', [od]) - api = getapi(Config(od2)) + api = Config(od2) api.option('a.a').value.set(['192.168.1.1']) api.option('a.b', 0).value.set('255.255.255.0') api.option('a.a').value.set(['192.168.1.2']) @@ -489,7 +489,7 @@ def test_consistency_network_netmask_multi(): od = MasterSlaves('a', '', [a, b]) b.impl_add_consistency('network_netmask', a) od2 = OptionDescription('od', '', [od]) - api = getapi(Config(od2)) + api = Config(od2) api.option('a.a').value.set(['192.168.1.1']) api.option('a.b', 0).value.set('255.255.255.255') api.option('a.b', 0).value.reset() @@ -505,7 +505,7 @@ def test_consistency_network_netmask_multi_slave_default_multi(): od2 = OptionDescription('od2', '', [od]) #od.impl_set_group_type(groups.master) b.impl_add_consistency('network_netmask', a) - api = getapi(Config(od2)) + api = Config(od2) api.property.read_write() api.option('a.a').value.set([undefined]) assert api.option('a.a').value.get() == ['192.168.1.0'] @@ -519,7 +519,7 @@ def test_consistency_network_netmask_multi_slave_default(): #od.impl_set_group_type(groups.master) b.impl_add_consistency('network_netmask', a) od2 = OptionDescription('od2', '', [od]) - api = getapi(Config(od2)) + api = Config(od2) api.property.read_write() api.property.pop('cache') assert api.option('a.a').value.get() == [] @@ -555,7 +555,7 @@ def test_consistency_network_netmask_multi_slave_callback(): #od.impl_set_group_type(groups.master) b.impl_add_consistency('network_netmask', a) od2 = OptionDescription('od2', '', [od]) - api = getapi(Config(od2)) + api = Config(od2) api.property.read_write() api.property.pop('cache') assert api.option('a.a').value.get() == [] @@ -578,7 +578,7 @@ def test_consistency_network_netmask_multi_slave_callback_value(): #od.impl_set_group_type(groups.master) b.impl_add_consistency('network_netmask', a) od2 = OptionDescription('od2', '', [od]) - api = getapi(Config(od2)) + api = Config(od2) api.property.read_write() api.property.pop('cache') assert api.option('a.a').value.get() == [] @@ -603,7 +603,7 @@ def test_consistency_ip_netmask_multi_master(): #od.impl_set_group_type(groups.master) b.impl_add_consistency('ip_netmask', a) od2 = OptionDescription('od2', '', [od]) - api = getapi(Config(od2)) + api = Config(od2) api.option('a.a').value.set(['192.168.1.1']) api.option('a.b', 0).value.set('255.255.255.0') api.option('a.a').value.set(['192.168.1.2']) @@ -622,7 +622,7 @@ def test_consistency_network_netmask_multi_master(): #od.impl_set_group_type(groups.master) b.impl_add_consistency('network_netmask', a) od2 = OptionDescription('od2', '', [od]) - api = getapi(Config(od2)) + api = Config(od2) api.option('a.a').value.set(['192.168.1.1']) api.option('a.b', 0).value.set('255.255.255.255') api.option('a.b', 0).value.reset() @@ -640,7 +640,7 @@ def test_consistency_broadcast(): b.impl_add_consistency('network_netmask', a) c.impl_add_consistency('broadcast', a, b) od2 = OptionDescription('od2', '', [od]) - api = getapi(Config(od2)) + api = Config(od2) #first, test network_netmask api.option('a.a').value.set(['192.168.1.128']) raises(ValueError, "api.option('a.a').value.set(['255.255.255.0'])") @@ -667,7 +667,7 @@ def test_consistency_broadcast_error(): od2 = OptionDescription('od2', '', [od]) b.impl_add_consistency('network_netmask', a) c.impl_add_consistency('broadcast', a) - api = getapi(Config(od2)) + api = Config(od2) raises(ConfigError, "api.option('a.a').value.set(['192.168.1.0'])") @@ -678,7 +678,7 @@ def test_consistency_broadcast_warnings(): c = NetmaskOption('c', '', properties=('mandatory', 'disabled')) od = OptionDescription('a', '', [a, b, c]) b.impl_add_consistency('network_netmask', a, warnings_only=True) - api = getapi(Config(od)) + api = Config(od) with warnings.catch_warnings(record=True) as w: api.option('a').value.set('192.168.1.4') api.option('b').value.set('255.255.255.0') @@ -716,7 +716,7 @@ def test_consistency_not_all(): #od.impl_set_group_type(groups.master) b.impl_add_consistency('network_netmask', a) od2 = OptionDescription('od2', '', [od]) - api = getapi(Config(od2)) + api = Config(od2) api.option('a.a').value.set(['192.168.1.0']) api.option('a.b', 0).value.set('255.255.255.0') api.option('a.c', 0).value.set('192.168.1.255') @@ -727,7 +727,7 @@ def test_consistency_permissive(): b = IntOption('b', '', 2, properties=('hidden',)) od = OptionDescription('od', '', [a, b]) a.impl_add_consistency('not_equal', b) - api = getapi(Config(od)) + api = Config(od) api.property.read_write() api.permissive.set(frozenset(['hidden'])) api.option('a').value.set(1) @@ -738,7 +738,7 @@ def test_consistency_disabled(): b = IntOption('b', '', properties=('disabled',)) od = OptionDescription('od', '', [a, b]) a.impl_add_consistency('not_equal', b) - api = getapi(Config(od)) + api = Config(od) api.property.read_write() raises(PropertiesOptionError, "api.option('a').value.set(1)") @@ -748,7 +748,7 @@ def test_consistency_disabled_transitive(): b = IntOption('b', '', properties=('disabled',)) od = OptionDescription('od', '', [a, b]) a.impl_add_consistency('not_equal', b, transitive=False) - api = getapi(Config(od)) + api = Config(od) api.property.read_write() api.option('a').value.set(1) @@ -761,7 +761,7 @@ def test_consistency_disabled_transitive_2(): od = OptionDescription('od', '', [a, b, c, d]) a.impl_add_consistency('not_equal', b) a.impl_add_consistency('in_network', c, d, transitive=False) - api = getapi(Config(od)) + api = Config(od) api.property.read_write() api.option('a').value.set('192.168.1.1') raises(ValueError, "api.option('b').value.set('192.168.1.1')") @@ -782,7 +782,7 @@ def test_consistency_with_callback(): c = IPOption('c', '', callback=return_val, callback_params=Params(ParamOption(a))) od = OptionDescription('od', '', [a, b, c]) c.impl_add_consistency('in_network', a, b) - api = getapi(Config(od)) + api = Config(od) api.option('c').value.get() @@ -795,7 +795,7 @@ def test_consistency_double_warnings(): a.impl_add_consistency('not_equal', b, warnings_only=True) a.impl_add_consistency('not_equal', c, warnings_only=True) od2 = OptionDescription('od2', '', [od]) - api = getapi(Config(od2)) + api = Config(od2) with warnings.catch_warnings(record=True) as w: api.option('od.a').value.set(1) assert w != [] @@ -824,7 +824,7 @@ def test_consistency_warnings_error(): warnings.simplefilter("always", ValueWarning) a.impl_add_consistency('not_equal', b, warnings_only=True) a.impl_add_consistency('not_equal', c) - api = getapi(Config(od)) + api = Config(od) with warnings.catch_warnings(record=True) as w: raises(ValueError, "api.option('a').value.set(1)") assert w == [] @@ -836,7 +836,7 @@ def test_consistency_network_netmask_mandatory(): od = MasterSlaves('a', '', [a, b]) b.impl_add_consistency('network_netmask', a) od2 = OptionDescription('od2', '', [od]) - api = getapi(Config(od2)) + api = Config(od2) api.property.read_only() api.property.pop('mandatory') api.option.make_dict() @@ -847,7 +847,7 @@ def test_consistency_has_dependency(): b = NetmaskOption('b', '') od = OptionDescription('od', '', [a, b]) b.impl_add_consistency('ip_netmask', a) - api = getapi(Config(od)) + api = Config(od) assert api.option('a').option.has_dependency() is True assert api.option('b').option.has_dependency() is True assert api.option('a').option.has_dependency(False) is True @@ -859,7 +859,7 @@ def test_consistency_not_equal_has_dependency(): b = IntOption('b', '') od = OptionDescription('od', '', [a, b]) a.impl_add_consistency('not_equal', b) - api = getapi(Config(od)) + api = Config(od) assert api.option('a').option.has_dependency() is False assert api.option('b').option.has_dependency() is False assert api.option('a').option.has_dependency(False) is True diff --git a/test/test_option_default.py b/test/test_option_default.py index 1abebe4..c9e13c6 100644 --- a/test/test_option_default.py +++ b/test/test_option_default.py @@ -7,7 +7,7 @@ from py.test import raises from tiramisu.setting import owners from tiramisu.error import PropertiesOptionError, ConfigError from tiramisu import IntOption, FloatOption, StrOption, ChoiceOption, \ - BoolOption, OptionDescription, MasterSlaves, Config, getapi, undefined + BoolOption, OptionDescription, MasterSlaves, Config, undefined def make_description(): @@ -45,7 +45,7 @@ def test_default_is_none(): dummy1 = BoolOption('dummy1', 'doc dummy') dummy2 = BoolOption('dummy2', 'doc dummy') group = OptionDescription('group', '', [dummy1, dummy2]) - api = getapi(Config(group)) + api = Config(group) # so when the default value is not set, there is actually a default value assert api.option('dummy1').value.get() is None assert api.option('dummy2').value.get() is None @@ -62,7 +62,7 @@ def test_force_default_on_freeze(): dummy1 = BoolOption('dummy1', 'doc dummy', default=False, properties=('force_default_on_freeze',)) dummy2 = BoolOption('dummy2', 'doc dummy', default=True) group = OptionDescription('group', '', [dummy1, dummy2]) - api = getapi(Config(group)) + api = Config(group) api.property.read_write() owner = api.owner.get() api.option('dummy1').value.set(True) @@ -87,7 +87,7 @@ def test_force_default_on_freeze_multi(): dummy1 = BoolOption('dummy1', 'doc dummy', default=[False], properties=('force_default_on_freeze',), multi=True) dummy2 = BoolOption('dummy2', 'doc dummy', default=[True], multi=True) group = OptionDescription('group', '', [dummy1, dummy2]) - api = getapi(Config(group)) + api = Config(group) api.property.read_write() api.option('dummy1').value.set([undefined, True]) api.option('dummy2').value.set([undefined, False]) @@ -120,7 +120,7 @@ def test_force_default_on_freeze_master_frozen(): dummy2 = BoolOption('dummy2', 'Test string option', multi=True) descr = MasterSlaves("dummy1", "", [dummy1, dummy2]) descr = OptionDescription("root", "", [descr]) - api = getapi(Config(descr)) + api = Config(descr) raises(ConfigError, "api.option('dummy1.dummy1').property.pop('frozen')") @@ -129,7 +129,7 @@ def test_force_default_on_freeze_slave(): dummy2 = BoolOption('dummy2', 'Test string option', multi=True, properties=('force_default_on_freeze',)) descr = MasterSlaves("dummy1", "", [dummy1, dummy2]) descr = OptionDescription("root", "", [descr]) - api = getapi(Config(descr)) + api = Config(descr) api.property.read_write() owners.addowner("frozenmultislave2") api.option('dummy1.dummy1').value.set([True]) @@ -175,14 +175,14 @@ def test_overrides_changes_option_value(): "with config.override(), the default is changed and the value is changed" descr = OptionDescription("test", "", [ BoolOption("b", "", default=False)]) - api = getapi(Config(descr)) + api = Config(descr) api.option('b').value.set(True) def test_choice_with_no_default(): descr = OptionDescription("test", "", [ ChoiceOption("backend", "", ("c", "cli"))]) - api = getapi(Config(descr)) + api = Config(descr) assert api.option('backend').value.get() is None api.option('backend').value.set('c') @@ -190,5 +190,5 @@ def test_choice_with_no_default(): def test_choice_with_default(): descr = OptionDescription("test", "", [ ChoiceOption("backend", "", ("c", "cli"), default="cli")]) - api = getapi(Config(descr)) + api = Config(descr) assert api.option('backend').value.get() == 'cli' diff --git a/test/test_option_owner.py b/test/test_option_owner.py index fed3303..2ae87ee 100644 --- a/test/test_option_owner.py +++ b/test/test_option_owner.py @@ -5,7 +5,7 @@ from py.test import raises from tiramisu.setting import owners, groups from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \ - StrOption, OptionDescription, SymLinkOption, MasterSlaves, Config, getapi + StrOption, OptionDescription, SymLinkOption, MasterSlaves, Config from tiramisu.error import ConfigError, ConstError, PropertiesOptionError, APIError @@ -34,7 +34,7 @@ def make_description(): def test_default_owner(): gcdummy = BoolOption('dummy', 'dummy', default=False) descr = OptionDescription('tiramisu', '', [gcdummy]) - api = getapi(Config(descr)) + api = Config(descr) assert api.option('dummy').value.get() is False assert api.option('dummy').owner.get() == 'default' api.option('dummy').value.set(True) @@ -45,7 +45,7 @@ def test_default_owner(): def test_hidden_owner(): gcdummy = BoolOption('dummy', 'dummy', default=False, properties=('hidden',)) descr = OptionDescription('tiramisu', '', [gcdummy]) - api = getapi(Config(descr)) + api = Config(descr) api.property.read_write() #raises(PropertiesOptionError, "api.forcepermissive.option('dummy').owner.get()") #raises(PropertiesOptionError, "api.option('dummy').owner.isdefault()") @@ -58,7 +58,7 @@ def test_hidden_owner(): def test_addowner(): gcdummy = BoolOption('dummy', 'dummy', default=False) descr = OptionDescription('tiramisu', '', [gcdummy]) - api = getapi(Config(descr)) + api = Config(descr) assert api.option('dummy').value.get() is False assert api.option('dummy').owner.get() == 'default' assert api.option('dummy').owner.isdefault() @@ -81,7 +81,7 @@ def test_delete_owner(): def test_owner_is_not_a_string(): gcdummy = BoolOption('dummy', 'dummy', default=False) descr = OptionDescription('tiramisu', '', [gcdummy]) - api = getapi(Config(descr)) + api = Config(descr) assert api.option('dummy').value.get() is False assert api.option('dummy').owner.get() == owners.default assert api.option('dummy').owner.get() == 'default' @@ -93,7 +93,7 @@ def test_owner_is_not_a_string(): def test_setowner_without_valid_owner(): gcdummy = BoolOption('dummy', 'dummy', default=False) descr = OptionDescription('tiramisu', '', [gcdummy]) - api = getapi(Config(descr)) + api = Config(descr) assert api.option('dummy').value.get() is False assert api.option('dummy').owner.get() == 'default' @@ -101,7 +101,7 @@ def test_setowner_without_valid_owner(): def test_setowner_for_value(): gcdummy = BoolOption('dummy', 'dummy', default=False) descr = OptionDescription('tiramisu', '', [gcdummy]) - api = getapi(Config(descr)) + api = Config(descr) assert api.option('dummy').value.get() is False assert api.option('dummy').owner.get() == 'default' owners.addowner("new2") @@ -115,7 +115,7 @@ def test_setowner_for_value(): def test_setowner_read_only(): gcdummy = BoolOption('dummy', 'dummy', default=False) descr = OptionDescription('tiramisu', '', [gcdummy]) - api = getapi(Config(descr)) + api = Config(descr) api.property.read_write() assert api.option('dummy').value.get() is False assert api.option('dummy').owner.get() == 'default' @@ -132,7 +132,7 @@ def test_setowner_optiondescription(): gcdummy = BoolOption('dummy', 'dummy', default=False) descr1 = OptionDescription('tiramisu', '', [gcdummy]) descr = OptionDescription('tiramisu', '', [descr1]) - api = getapi(Config(descr)) + api = Config(descr) raises(APIError, "api.option('tiramisu').owner.get()") raises(APIError, "api.option('tiramisu').owner.set('user')") @@ -142,7 +142,7 @@ def test_setowner_symlinkoption(): s = SymLinkOption('symdummy', gcdummy) descr1 = OptionDescription('tiramisu', '', [gcdummy, s]) descr = OptionDescription('tiramisu', '', [descr1]) - api = getapi(Config(descr)) + api = Config(descr) assert api.option('tiramisu.symdummy').owner.isdefault() api.option('tiramisu.dummy').value.set(True) assert not api.option('tiramisu.symdummy').owner.isdefault() @@ -154,7 +154,7 @@ def test_owner_masterslaves(): c = StrOption('str', 'Test string option', multi=True) descr = MasterSlaves("int", "", [b, c]) od = OptionDescription('od', '', [descr]) - api = getapi(Config(od)) + api = Config(od) raises(ConfigError, "api.option('int.str', 0).owner.set('user')") api.option('int.int').value.set([0, 1]) diff --git a/test/test_option_setting.py b/test/test_option_setting.py index 0f5361a..7c29ad0 100644 --- a/test/test_option_setting.py +++ b/test/test_option_setting.py @@ -8,7 +8,7 @@ from tiramisu.i18n import _ from tiramisu.error import display_list, ConfigError from tiramisu.setting import owners, groups from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \ - StrOption, OptionDescription, MasterSlaves, Config, getapi, undefined + StrOption, OptionDescription, MasterSlaves, Config, undefined from tiramisu.error import PropertiesOptionError from tiramisu.api import TIRAMISU_VERSION @@ -40,7 +40,7 @@ def test_attribute_access(): "Once set, option values can't be changed again by attribute access" s = StrOption("string", "", default="string") descr = OptionDescription("options", "", [s]) - api = getapi(Config(descr)) + api = Config(descr) # let's try to change it again api.option('string').value.set('foo') assert api.option('string').value.get() == 'foo' @@ -49,7 +49,7 @@ def test_attribute_access(): def test_setitem(): s = StrOption("string", "", default=["string", "sdfsdf"], default_multi="prout", multi=True) descr = OptionDescription("options", "", [s]) - api = getapi(Config(descr)) + api = Config(descr) api.option('string').value.set([undefined, 'foo']) assert api.option('string').value.get() == ['string', 'foo'] @@ -58,7 +58,7 @@ def test_reset(): "if value is None, resets to default owner" s = StrOption("string", "", default="string") descr = OptionDescription("options", "", [s]) - api = getapi(Config(descr)) + api = Config(descr) api.option('string').value.set('foo') assert api.option('string').value.get() == "foo" assert api.option('string').owner.get() ==owners.user @@ -70,7 +70,7 @@ def test_reset(): def test_reset_with_multi(): s = StrOption("string", "", default=["string"], default_multi="string", multi=True) descr = OptionDescription("options", "", [s]) - api = getapi(Config(descr)) + api = Config(descr) # api.option('string').value.set([]) api.option('string').value.reset() assert api.option('string').value.get() == ["string"] @@ -88,17 +88,17 @@ def test_default_with_multi(): "default with multi is a list" s = StrOption("string", "", default=[], default_multi="string", multi=True) descr = OptionDescription("options", "", [s]) - api = getapi(Config(descr)) + api = Config(descr) assert api.option('string').value.get() == [] s = StrOption("string", "", default=None, default_multi="string", multi=True) descr = OptionDescription("options", "", [s]) - api = getapi(Config(descr)) + api = Config(descr) assert api.option('string').value.get() == [] def test_idontexist(): descr = make_description() - api = getapi(Config(descr)) + api = Config(descr) api.option.make_dict() raises(AttributeError, "api.option('idontexist').value.get()") @@ -107,7 +107,7 @@ def test_idontexist(): def test_attribute_access_with_multi(): s = StrOption("string", "", default=["string"], default_multi="string", multi=True) descr = OptionDescription("options", "", [s]) - api = getapi(Config(descr)) + api = Config(descr) api.option('string').value.set(["foo", "bar"]) assert api.option('string').value.get() == ["foo", "bar"] @@ -115,7 +115,7 @@ def test_attribute_access_with_multi(): def test_item_access_with_multi(): s = StrOption("string", "", default=["string"], multi=True) descr = OptionDescription("options", "", [s]) - api = getapi(Config(descr)) + api = Config(descr) api.option('string').value.set(["foo", "bar"]) assert api.option('string').value.get() == ["foo", "bar"] api.option('string').value.set(["changetest", "bar"]) @@ -125,7 +125,7 @@ def test_item_access_with_multi(): def test_access_with_multi_default(): s = StrOption("string", "", default=["string"], multi=True) descr = OptionDescription("options", "", [s]) - api = getapi(Config(descr)) + api = Config(descr) assert api.option('string').owner.get() =='default' api.option('string').value.set(["foo", "bar"]) assert api.option('string').value.get() == ["foo", "bar"] @@ -138,7 +138,7 @@ def test_multi_with_requires(): stroption = StrOption('str', 'Test string option', default=["abc"], default_multi="abc", requires=[{'option': intoption, 'expected': 1, 'action': 'hidden'}], multi=True) descr = OptionDescription("options", "", [s, intoption, stroption]) - api = getapi(Config(descr)) + api = Config(descr) api.property.read_write() assert not 'hidden' in api.option('str').property.get() api.option('int').value.set(1) @@ -152,7 +152,7 @@ def test__requires_with_inverted(): stroption = StrOption('str', 'Test string option', default=["abc"], default_multi="abc", requires=[{'option': intoption, 'expected': 1, 'action': 'hide', 'inverse': True}], multi=True) descr = OptionDescription("options", "", [s, intoption, stroption]) - api = getapi(Config(descr)) + api = Config(descr) assert not 'hidden' in api.option('str').property.get() api.option('int').value.set(1) assert not 'hidden' in api.option('str').property.get() @@ -165,7 +165,7 @@ def test_multi_with_requires_in_another_group(): requires=[{'option': intoption, 'expected': 1, 'action': 'hidden'}], multi=True) descr = OptionDescription("opt", "", [stroption]) descr2 = OptionDescription("opt2", "", [intoption, s, descr]) - api = getapi(Config(descr2)) + api = Config(descr2) api.property.read_write() assert not 'hidden' in api.option('opt.str').property.get() api.option('int').value.set(1) @@ -180,7 +180,7 @@ def test_multi_with_requires_in_another_group_inverse(): requires=[{'option': intoption, 'expected': 0, 'action': 'hidden', 'inverse': True}], multi=True) descr = OptionDescription("opt", "", [stroption]) descr2 = OptionDescription("opt2", "", [intoption, s, descr]) - api = getapi(Config(descr2)) + api = Config(descr2) api.property.read_write() assert not 'hidden' in api.option('opt.str').property.get() api.option('int').value.set(1) @@ -195,7 +195,7 @@ def test_apply_requires_from_config(): requires=[{'option': intoption, 'expected': 1, 'action': 'hidden'}], multi=True) descr = OptionDescription("opt", "", [stroption]) descr2 = OptionDescription("opt2", "", [intoption, s, descr]) - api = getapi(Config(descr2)) + api = Config(descr2) api.property.read_write() assert not 'hidden' in api.option('opt.str').property.get() api.option('int').value.set(1) @@ -210,7 +210,7 @@ def test_apply_requires_with_disabled(): requires=[{'option': intoption, 'expected': 1, 'action': 'disabled'}], multi=True) descr = OptionDescription("opt", "", [stroption]) descr2 = OptionDescription("opt2", "", [intoption, s, descr]) - api = getapi(Config(descr2)) + api = Config(descr2) api.property.read_write() assert not 'disabled' in api.option('opt.str').property.get() api.option('int').value.set(1) @@ -225,7 +225,7 @@ def test_multi_with_requires_with_disabled_in_another_group(): requires=[{'option': intoption, 'expected': 1, 'action': 'disabled'}], multi=True) descr = OptionDescription("opt", "", [stroption]) descr2 = OptionDescription("opt2", "", [intoption, s, descr]) - api = getapi(Config(descr2)) + api = Config(descr2) api.property.read_write() assert not 'disabled' in api.option('opt.str').property.get() api.option('int').value.set(1) @@ -271,7 +271,7 @@ def test_multi_with_requires_that_is_masterslave_slave(): d = StrOption('str1', 'Test string option', requires=[{'option': c, 'expected': '1', 'action': 'hidden'}], multi=True) descr = MasterSlaves("int", "", [b, c, d]) descr2 = OptionDescription('od', '', [descr]) - api = getapi(Config(descr2)) + api = Config(descr2) api.property.read_write() assert api.option('int.int').value.get() == [0] assert api.option('int.str', 0).value.get() == None @@ -297,7 +297,7 @@ def test_multi_with_requires_that_is_masterslave_slave_inverse(): d = StrOption('str1', 'Test string option', requires=[{'option': c, 'expected': None, 'action': 'hidden', 'inverse': True}], multi=True) descr = MasterSlaves("int", "", [b, c, d]) descr2 = OptionDescription('od', '', [descr]) - api = getapi(Config(descr2)) + api = Config(descr2) api.property.read_write() assert api.option('int.int').value.get() == [0] assert api.option('int.str', 0).value.get() is None @@ -334,7 +334,7 @@ def test_multi_with_requires_that_is_not_same_masterslave(): def test_multi_with_bool(): s = BoolOption("bool", "", default=[False], multi=True) descr = OptionDescription("options", "", [s]) - api = getapi(Config(descr)) + api = Config(descr) api.option('bool').value.set([True, False]) assert api.option('bool').value.get() == [True, False] @@ -342,7 +342,7 @@ def test_multi_with_bool(): def test_choice_access_with_multi(): ch = ChoiceOption("t1", "", ("a", "b"), default=["a"], multi=True) descr = OptionDescription("options", "", [ch]) - api = getapi(Config(descr)) + api = Config(descr) api.option('t1').value.set(["a", "b", "a", "b"]) assert api.option('t1').value.get() == ["a", "b", "a", "b"] @@ -351,7 +351,7 @@ def test_choice_access_with_multi(): def test_accepts_multiple_changes_from_option(): s = StrOption("string", "", default="string") descr = OptionDescription("options", "", [s]) - api = getapi(Config(descr)) + api = Config(descr) api.option('string').value.set("egg") assert api.option('string').option.default() == "string" assert api.option('string').value.get() == "egg" @@ -371,7 +371,7 @@ def test_allow_multiple_changes_from_config(): s2 = StrOption("string2", "", default="string") suboption = OptionDescription("bip", "", [s2]) descr = OptionDescription("options", "", [s, suboption]) - api = getapi(Config(descr)) + api = Config(descr) api.option('string').value.set("oh") assert api.option('string').value.get() == "oh" api.option('string').value.set("blah") @@ -382,7 +382,7 @@ def test_allow_multiple_changes_from_config(): # accessing a value by the get method def test_access_by_get(): descr = make_description() - api = getapi(Config(descr)) + api = Config(descr) raises(AttributeError, "api.option.find('idontexist')") assert api.option.find('wantref', first=True).value.get() is False assert api.option.find('dummy', first=True).value.get() is False @@ -396,14 +396,14 @@ def test_access_by_get_whith_hide(): BoolOption("d1", "")]), BoolOption("b2", ""), BoolOption("d1", "")]) - api = getapi(Config(descr)) + api = Config(descr) api.property.read_write() raises(AttributeError, "api.option.find('b1').value.get()") def test_append_properties(): descr = make_description() - api = getapi(Config(descr)) + api = Config(descr) assert api.option('gc.dummy').property.get() == set() api.option('gc.dummy').property.add('test') assert api.option('gc.dummy').property.get() == {'test'} @@ -413,7 +413,7 @@ def test_append_properties(): def test_reset_properties(): descr = make_description() - api = getapi(Config(descr)) + api = Config(descr) assert api.option('gc.dummy').property.get() == set() api.option('gc.dummy').property.add('frozen') assert api.option('gc.dummy').property.get() == {'frozen'} @@ -424,7 +424,7 @@ def test_reset_properties(): def test_properties_cached(): b1 = BoolOption("b1", "", properties=('test',)) descr = OptionDescription("opt", "", [OptionDescription("sub", "", [b1])]) - api = getapi(Config(descr)) + api = Config(descr) api.property.read_write() assert api.option('sub.b1').property.get() == {'test'} @@ -433,7 +433,7 @@ def test_append_properties_force_store_value(): gcdummy = BoolOption('dummy', 'dummy', default=False, properties=('force_store_value',)) gcgroup = OptionDescription('gc', '', [gcdummy]) descr = OptionDescription('tiramisu', '', [gcgroup]) - api = getapi(Config(descr)) + api = Config(descr) assert api.option('gc.dummy').property.get() == {'force_store_value'} api.option('gc.dummy').property.add('test') assert api.option('gc.dummy').property.get() == {'force_store_value', 'test'} @@ -443,7 +443,7 @@ def test_reset_properties_force_store_value(): gcdummy = BoolOption('dummy', 'dummy', default=False, properties=('force_store_value',)) gcgroup = OptionDescription('gc', '', [gcdummy]) descr = OptionDescription('tiramisu', '', [gcgroup]) - api = getapi(Config(descr)) + api = Config(descr) assert api.property.exportation() == {} api.property.add('frozen') if TIRAMISU_VERSION == 2: @@ -491,7 +491,7 @@ def test_set_modified_value(): gcdummy = BoolOption('dummy', 'dummy', default=False, properties=('force_store_value',)) gcgroup = OptionDescription('gc', '', [gcdummy]) descr = OptionDescription('tiramisu', '', [gcgroup]) - api = getapi(Config(descr)) + api = Config(descr) assert api.property.exportation() == {} api.property.importation({None: set(('frozen', 'cache', 'validator', 'warnings'))}) assert api.property.exportation() == \ @@ -526,7 +526,7 @@ def test_pprint(): val3 = StrOption('val3', "", requires=[{'option': stroption, 'expected': '2', 'action': 'hidden', 'inverse': True}]) descr = OptionDescription("options", "", [s, s2, s3, intoption, stroption, descr2, val3]) - api = getapi(Config(descr)) + api = Config(descr) api.property.read_write() api.option('int').value.set(1) err = None diff --git a/test/test_option_type.py b/test/test_option_type.py index 48867c7..0a48273 100644 --- a/test/test_option_type.py +++ b/test/test_option_type.py @@ -6,7 +6,7 @@ do_autopath() from py.test import raises from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \ - PasswordOption, StrOption, DateOption, OptionDescription, Config, getapi + PasswordOption, StrOption, DateOption, OptionDescription, Config from tiramisu.error import PropertiesOptionError @@ -42,7 +42,7 @@ def make_description(): # ____________________________________________________________ def test_is_hidden(): descr = make_description() - api = getapi(Config(descr)) + api = Config(descr) api.property.read_write() assert not 'frozen' in api.forcepermissive.option('gc.dummy').property.get() # setattr @@ -53,7 +53,7 @@ def test_is_hidden(): def test_group_is_hidden(): descr = make_description() - api = getapi(Config(descr)) + api = Config(descr) api.property.read_write() api.option('gc').property.add('hidden') raises(PropertiesOptionError, "api.option('gc.dummy').value.get()") @@ -74,7 +74,7 @@ def test_group_is_hidden(): def test_group_is_hidden_multi(): descr = make_description() - api = getapi(Config(descr)) + api = Config(descr) api.property.read_write() api.option('objspace').property.add('hidden') raises(PropertiesOptionError, "api.option('objspace').value.get()") @@ -92,7 +92,7 @@ def test_group_is_hidden_multi(): def test_global_show(): descr = make_description() - api = getapi(Config(descr)) + api = Config(descr) api.property.read_write() api.forcepermissive.option('gc.dummy').property.add('hidden') assert 'hidden' in api.forcepermissive.option('gc.dummy').property.get() @@ -101,7 +101,7 @@ def test_global_show(): def test_with_many_subgroups(): descr = make_description() - api = getapi(Config(descr)) + api = Config(descr) #booltwo = config.unwrap_from_path('gc.subgroup.booltwo') #setting = config.cfgimpl_get_settings() assert not 'hidden' in api.option('gc.subgroup.booltwo').property.get() @@ -112,7 +112,7 @@ def test_with_many_subgroups(): def test_password_option(): o = PasswordOption('o', '') d = OptionDescription('d', '', [o]) - api = getapi(Config(d)) + api = Config(d) api.option('o').value.set('a_valid_password') raises(ValueError, "api.option('o').value.set(1)") @@ -121,7 +121,7 @@ def test_password_option(): def test_date_option(): o = DateOption('o', '') d = OptionDescription('d', '', [o]) - api = getapi(Config(d)) + api = Config(d) api.option('o').value.set('2017-02-04') api.option('o').value.set('2017-2-4') diff --git a/test/test_option_validator.py b/test/test_option_validator.py index 2994628..439910c 100644 --- a/test/test_option_validator.py +++ b/test/test_option_validator.py @@ -4,7 +4,7 @@ do_autopath() import warnings from py.test import raises -from tiramisu import BoolOption, StrOption, OptionDescription, MasterSlaves, Config, getapi, Params, ParamValue, ParamOption, ParamContext +from tiramisu import BoolOption, StrOption, OptionDescription, MasterSlaves, Config, Params, ParamValue, ParamOption, ParamContext from tiramisu.setting import groups from tiramisu.error import ValueWarning, ConfigError from tiramisu.i18n import _ @@ -101,7 +101,7 @@ def test_validator(): raises(ValueError, "StrOption('opt2', '', validator=return_false, default='val')") opt2 = StrOption('opt2', '', validator=return_false) root = OptionDescription('root', '', [opt1, opt2]) - api = getapi(Config(root)) + api = Config(root) assert api.option('opt1').value.get() == 'val' raises(ValueError, "api.option('opt2').value.set('val')") try: @@ -116,7 +116,7 @@ def test_validator_params(): raises(ValueError, "StrOption('opt2', '', validator=return_false, validator_params=Params(ParamValue('yes')), default='val')") opt2 = StrOption('opt2', '', validator=return_false, validator_params=Params(ParamValue('yes'))) root = OptionDescription('root', '', [opt1, opt2]) - api = getapi(Config(root)) + api = Config(root) assert api.option('opt1').value.get() == 'val' raises(ValueError, "api.option('opt2').value.set('val')") @@ -124,7 +124,7 @@ def test_validator_params(): def test_validator_params_value_values(): opt1 = StrOption('opt1', '', validator=value_values, default=['val'], multi=True) root = OptionDescription('root', '', [opt1]) - api = getapi(Config(root)) + api = Config(root) assert api.option('opt1').value.get() == ['val'] api.option('opt1').value.set(['val1', 'val2']) @@ -132,7 +132,7 @@ def test_validator_params_value_values(): def test_validator_params_value_values_index(): opt1 = StrOption('opt1', '', validator=value_values_index, default=['val'], multi=True) root = OptionDescription('root', '', [opt1]) - api = getapi(Config(root)) + api = Config(root) assert api.option('opt1').value.get() == ['val'] api.option('opt1').value.set(['val1', 'val2']) @@ -143,7 +143,7 @@ def test_validator_params_value_values_master(): interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) #interface1.impl_set_group_type(groups.master) root = OptionDescription('root', '', [interface1]) - api = getapi(Config(root)) + api = Config(root) assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val2']) @@ -154,7 +154,7 @@ def test_validator_params_value_values_index_master(): interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) #interface1.impl_set_group_type(groups.master) root = OptionDescription('root', '', [interface1]) - api = getapi(Config(root)) + api = Config(root) assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val2']) @@ -165,7 +165,7 @@ def test_validator_params_value_values_slave(): interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) #interface1.impl_set_group_type(groups.master) root = OptionDescription('root', '', [interface1]) - api = getapi(Config(root)) + api = Config(root) assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val']) api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1') @@ -179,7 +179,7 @@ def test_validator_params_value_values_index_slave(): interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) #interface1.impl_set_group_type(groups.master) root = OptionDescription('root', '', [interface1]) - api = getapi(Config(root)) + api = Config(root) assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val']) api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1') @@ -202,7 +202,7 @@ def test_validator_params_value_values_kwargs_empty(): interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) #interface1.impl_set_group_type(groups.master) root = OptionDescription('root', '', [v, interface1]) - api = getapi(Config(root)) + api = Config(root) assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip'] api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip', 'val']) #cfg.ip_admin_eth0.ip_admin_eth0.append('val') @@ -220,7 +220,7 @@ def test_validator_params_value_values_kwargs(): interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) #interface1.impl_set_group_type(groups.master) root = OptionDescription('root', '', [v, interface1]) - api = getapi(Config(root)) + api = Config(root) assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip'] api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1') api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip', 'val']) @@ -237,7 +237,7 @@ def test_validator_params_value_values_kwargs_values(): interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) #interface1.impl_set_group_type(groups.master) root = OptionDescription('root', '', [interface1]) - api = getapi(Config(root)) + api = Config(root) assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val']) api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1') @@ -255,7 +255,7 @@ def test_validator_params_value_values_kwargs2(): interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) #interface1.impl_set_group_type(groups.master) root = OptionDescription('root', '', [interface1]) - api = getapi(Config(root)) + api = Config(root) assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val']) api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1') @@ -272,7 +272,7 @@ def test_validator_params_value_values_kwargs_index(): interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) #interface1.impl_set_group_type(groups.master) root = OptionDescription('root', '', [interface1]) - api = getapi(Config(root)) + api = Config(root) assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val']) api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1') @@ -283,7 +283,7 @@ def test_validator_params_value_values_kwargs_index(): def test_validator_params_context(): opt1 = StrOption('opt1', '', validator=is_context, validator_params=Params(ParamContext()), default='val') root = OptionDescription('root', '', [opt1]) - api = getapi(Config(root)) + api = Config(root) assert 'validator' in api.property.get() assert api.option('opt1').value.get() == 'val' assert 'validator' in api.property.get() @@ -293,7 +293,7 @@ def test_validator_params_context_value(): opt1 = StrOption('opt1', '', 'yes') opt2 = StrOption('opt2', '', validator=valid_from_config, validator_params=Params(ParamContext()), default='val') root = OptionDescription('root', '', [opt1, opt2]) - api = getapi(Config(root)) + api = Config(root) assert api.option('opt1').value.get() == 'yes' assert api.option('opt2').value.get() == 'val' api.option('opt1').value.set('no') @@ -304,7 +304,7 @@ def test_validator_params_key(): opt1 = StrOption('opt1', '', validator=return_true, validator_params=Params(kwargs={'param': ParamValue('yes')}), default='val') raises(ConfigError, "StrOption('opt2', '', validator=return_true, validator_params=Params(kwargs={'param_unknown': ParamValue('yes')}), default='val')") root = OptionDescription('root', '', [opt1]) - api = getapi(Config(root)) + api = Config(root) assert api.option('opt1').value.get() == 'val' @@ -312,7 +312,7 @@ def test_validator_params_option(): opt0 = StrOption('opt0', '', default='yes') opt1 = StrOption('opt1', '', validator=return_true, validator_params=Params(ParamOption(opt0)), default='val') r = OptionDescription('root', '', [opt0, opt1]) - api = getapi(Config(r)) + api = Config(r) assert api.option('opt1').value.get() == 'val' api.option('opt0').value.set('val') raises(ValueError, "api.option('opt1').value.get()") @@ -321,7 +321,7 @@ def test_validator_params_option(): def test_validator_multi(): opt1 = StrOption('opt1', '', validator=return_if_val, multi=True) root = OptionDescription('root', '', [opt1]) - api = getapi(Config(root)) + api = Config(root) assert api.option('opt1').value.get() == [] api.option('opt1').value.set(['val']) assert api.option('opt1').value.get() == ['val'] @@ -333,7 +333,7 @@ def test_validator_warning(): opt2 = StrOption('opt2', '', validator=return_false, warnings_only=True) opt3 = StrOption('opt3', '', validator=return_if_val, multi=True, warnings_only=True) root = OptionDescription('root', '', [opt1, opt2, opt3]) - api = getapi(Config(root)) + api = Config(root) assert api.option('opt1').value.get() == 'val' warnings.simplefilter("always", ValueWarning) with warnings.catch_warnings(record=True) as w: @@ -375,7 +375,7 @@ def test_validator_warning_disabled(): opt2 = StrOption('opt2', '', validator=return_false, warnings_only=True) opt3 = StrOption('opt3', '', validator=return_if_val, multi=True, warnings_only=True) root = OptionDescription('root', '', [opt1, opt2, opt3]) - api = getapi(Config(root)) + api = Config(root) api.property.pop('warnings') assert api.option('opt1').value.get() == 'val' warnings.simplefilter("always", ValueWarning) @@ -411,7 +411,7 @@ def test_validator_warning_master_slave(): #interface1.impl_set_group_type(groups.master) assert interface1.impl_get_group_type() == groups.master root = OptionDescription('root', '', [interface1]) - api = getapi(Config(root)) + api = Config(root) warnings.simplefilter("always", ValueWarning) with warnings.catch_warnings(record=True) as w: api.option('ip_admin_eth0.ip_admin_eth0').value.set([None]) @@ -462,7 +462,7 @@ def test_validator_slave_param(): interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) #interface1.impl_set_group_type(groups.master) root = OptionDescription('root', '', [interface1]) - api = getapi(Config(root)) + api = Config(root) assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] api.option('ip_admin_eth0.ip_admin_eth0').value.set(['yes']) api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val') @@ -478,7 +478,7 @@ def test_validator_dependencies(): validator_params=Params(kwargs={'param': ParamOption(ip_admin_eth0)})) opt2 = StrOption('opt2', '', validator=return_false) root = OptionDescription('root', '', [ip_admin_eth0, netmask_admin_eth0, opt2]) - api = getapi(Config(root)) + api = Config(root) assert api.option('ip_admin_eth0').option.has_dependency() is False assert api.option('netmask_admin_eth0').option.has_dependency() is True assert api.option('opt2').option.has_dependency() is False diff --git a/test/test_option_with_special_name.py b/test/test_option_with_special_name.py index e8cfc18..462c3b5 100644 --- a/test/test_option_with_special_name.py +++ b/test/test_option_with_special_name.py @@ -5,7 +5,7 @@ do_autopath() from py.test import raises from tiramisu import BoolOption, OptionDescription, ChoiceOption,\ - IntOption, FloatOption, StrOption, Config, getapi + IntOption, FloatOption, StrOption, Config def make_description(): @@ -36,7 +36,7 @@ def test_root_config_answers_ok(): gcdummy = BoolOption('dummy', 'dummy', default=False) boolop = BoolOption('boolop', 'Test boolean option op', default=True) descr = OptionDescription('tiramisu', '', [gcdummy, boolop]) - api = getapi(Config(descr)) + api = Config(descr) #settings = cfg.cfgimpl_get_settings() #settings.append('hidden') diff --git a/test/test_permissive.py b/test/test_permissive.py index fea0fef..f4de786 100644 --- a/test/test_permissive.py +++ b/test/test_permissive.py @@ -4,7 +4,7 @@ do_autopath() from py.test import raises -from tiramisu import IntOption, UnicodeOption, OptionDescription, Config, getapi +from tiramisu import IntOption, UnicodeOption, OptionDescription, Config from tiramisu.error import PropertiesOptionError from tiramisu.api import TIRAMISU_VERSION @@ -17,7 +17,7 @@ def make_description(): def test_permissive(): descr = make_description() - api = getapi(Config(descr)) + api = Config(descr) api.property.read_write() api.property.read_write() props = frozenset() @@ -46,7 +46,7 @@ def test_permissive(): def test_permissive_mandatory(): descr = make_description() - api = getapi(Config(descr)) + api = Config(descr) api.property.read_only() props = frozenset() try: @@ -73,7 +73,7 @@ def test_permissive_mandatory(): def test_permissive_frozen(): descr = make_description() - api = getapi(Config(descr)) + api = Config(descr) api.property.read_write() api.unrestraint.permissive.set(frozenset(['frozen', 'disabled'])) try: @@ -101,14 +101,14 @@ def test_permissive_frozen(): if TIRAMISU_VERSION == 3: def test_invalid_permissive(): descr = make_description() - api = getapi(Config(descr)) + api = Config(descr) api.property.read_write() raises(TypeError, "api.unrestraint.permissive.set(['frozen', 'disabled'])") def test_permissive_option(): descr = make_description() - api = getapi(Config(descr)) + api = Config(descr) api.property.read_write() props = frozenset() @@ -164,7 +164,7 @@ def test_permissive_option(): def test_permissive_option_cache(): descr = make_description() - api = getapi(Config(descr)) + api = Config(descr) api.property.read_write() props = frozenset() @@ -220,7 +220,7 @@ def test_permissive_option_cache(): def test_permissive_option_mandatory(): descr = make_description() - api = getapi(Config(descr)) + api = Config(descr) api.property.read_only() props = frozenset() try: @@ -247,7 +247,7 @@ def test_permissive_option_mandatory(): def test_permissive_option_frozen(): descr = make_description() - api = getapi(Config(descr)) + api = Config(descr) api.property.read_write() api.unrestraint.option('u1').permissive.set(frozenset(['frozen', 'disabled'])) api.option('u1').value.set(1) @@ -261,7 +261,7 @@ def test_permissive_option_frozen(): if TIRAMISU_VERSION == 3: def test_invalid_option_permissive(): descr = make_description() - api = getapi(Config(descr)) + api = Config(descr) api.property.read_write() raises(TypeError, "api.unrestraint.option('u1').permissive.set(['frozen', 'disabled'])") @@ -270,7 +270,7 @@ def test_remove_option_permissive(): var1 = UnicodeOption('var1', '', u'value', properties=('hidden',)) od1 = OptionDescription('od1', '', [var1]) rootod = OptionDescription('rootod', '', [od1]) - api = getapi(Config(rootod)) + api = Config(rootod) api.property.read_write() raises(PropertiesOptionError, "api.option('od1.var1').value.get()") api.forcepermissive.option('od1.var1').permissive.set(frozenset(['hidden'])) diff --git a/test/test_requires.py b/test/test_requires.py index 1113b53..f07e4dc 100644 --- a/test/test_requires.py +++ b/test/test_requires.py @@ -8,7 +8,7 @@ from tiramisu.setting import groups from tiramisu import setting setting.expires_time = 1 from tiramisu import IPOption, OptionDescription, BoolOption, IntOption, StrOption, \ - MasterSlaves, Config, getapi + MasterSlaves, Config from tiramisu.error import PropertiesOptionError, RequirementError from py.test import raises @@ -17,7 +17,7 @@ def test_properties(): a = BoolOption('activate_service', '', True) b = IPOption('ip_address_service', '', properties=('disabled',)) od = OptionDescription('service', '', [a, b]) - api = getapi(Config(od)) + api = Config(od) api.property.read_write() props = [] try: @@ -44,7 +44,7 @@ def test_requires(): b = IPOption('ip_address_service', '', requires=[{'option': a, 'expected': False, 'action': 'disabled'}]) od = OptionDescription('service', '', [a, b]) - api = getapi(Config(od)) + api = Config(od) api.property.read_write() api.option('ip_address_service').value.get() api.option('activate_service').value.set(False) @@ -63,7 +63,7 @@ def test_requires_inverse(): b = IPOption('ip_address_service', '', requires=[{'option': a, 'expected': False, 'action': 'disabled', 'inverse': True}]) od = OptionDescription('service', '', [a, b]) - api = getapi(Config(od)) + api = Config(od) api.property.read_write() props = [] try: @@ -85,7 +85,7 @@ def test_requires_self(): a = StrOption('ip_address_service', '', requires=[{'option': 'self', 'expected': 'b', 'action': 'disabled'}]) od = OptionDescription('service', '', [a]) - api = getapi(Config(od)) + api = Config(od) api.property.read_write() assert api.option('ip_address_service').value.get() == None api.option('ip_address_service').value.set('a') @@ -104,7 +104,7 @@ def test_requires_with_requires(): b = IPOption('ip_address_service', '', requires=[{'option': a, 'expected': False, 'action': 'disabled'}]) od = OptionDescription('service', '', [a, b]) - api = getapi(Config(od)) + api = Config(od) api.property.read_write() api.option('ip_address_service').property.add('test') api.option('ip_address_service').value.get() @@ -145,7 +145,7 @@ def test_requires_same_action(): 'action': 'disabled', 'inverse': False, 'transitive': True, 'same_action': False}]) od1 = OptionDescription('service', '', [activate_service, activate_service_web, ip_address_service_web]) - api = getapi(Config(od1)) + api = Config(od1) api.property.read_write() api.property.add('new') api.option('activate_service').value.get() @@ -178,7 +178,7 @@ def test_multiple_requires(): requires=[{'option': a, 'expected': 'yes', 'action': 'disabled'}, {'option': a, 'expected': 'ok', 'action': 'disabled'}]) od = OptionDescription('service', '', [a, b]) - api = getapi(Config(od)) + api = Config(od) api.property.read_write() api.option('ip_address_service').value.get() api.option('activate_service').value.set('yes') @@ -207,7 +207,7 @@ def test_multiple_requires_cumulative(): requires=[{'option': a, 'expected': 'yes', 'action': 'disabled'}, {'option': a, 'expected': 'yes', 'action': 'hidden'}]) od = OptionDescription('service', '', [a, b]) - api = getapi(Config(od)) + api = Config(od) api.property.read_write() api.option('ip_address_service').value.get() api.option('activate_service').value.set('yes') @@ -231,7 +231,7 @@ def test_multiple_requires_cumulative_inverse(): requires=[{'option': a, 'expected': 'yes', 'action': 'disabled', 'inverse': True}, {'option': a, 'expected': 'yes', 'action': 'hidden', 'inverse': True}]) od = OptionDescription('service', '', [a, b]) - api = getapi(Config(od)) + api = Config(od) api.property.read_write() props = [] try: @@ -265,7 +265,7 @@ def test_multiple_requires_inverse(): requires=[{'option': a, 'expected': 'yes', 'action': 'disabled', 'inverse': True}, {'option': a, 'expected': 'ok', 'action': 'disabled', 'inverse': True}]) od = OptionDescription('service', '', [a, b]) - api = getapi(Config(od)) + api = Config(od) api.property.read_write() props = [] try: @@ -297,7 +297,7 @@ def test_requires_transitive(): d = IPOption('ip_address_service_web', '', requires=[{'option': b, 'expected': False, 'action': 'disabled'}]) od = OptionDescription('service', '', [a, b, d]) - api = getapi(Config(od)) + api = Config(od) api.property.read_write() api.option('activate_service').value.get() api.option('activate_service_web').value.get() @@ -327,7 +327,7 @@ def test_requires_transitive_owner(): d = IPOption('ip_address_service_web', '', requires=[{'option': b, 'expected': False, 'action': 'disabled'}]) od = OptionDescription('service', '', [a, b, d]) - api = getapi(Config(od)) + api = Config(od) api.property.read_write() api.option('activate_service').value.get() api.option('activate_service_web').value.get() @@ -352,7 +352,7 @@ def test_requires_transitive_bis(): d = IPOption('ip_address_service_web', '', requires=[{'option': b, 'expected': True, 'action': 'disabled', 'inverse': True}]) od = OptionDescription('service', '', [a, abis, b, d]) - api = getapi(Config(od)) + api = Config(od) api.property.read_write() # api.option('activate_service_web').value.get() @@ -381,7 +381,7 @@ def test_requires_transitive_hidden_permissive(): d = IPOption('ip_address_service_web', '', requires=[{'option': b, 'expected': False, 'action': 'disabled'}]) od = OptionDescription('service', '', [a, b, d]) - api = getapi(Config(od)) + api = Config(od) api.property.read_write() api.option('activate_service').value.get() api.option('ip_address_service_web').value.get() @@ -398,7 +398,7 @@ def test_requires_transitive_hidden_disabled(): d = IPOption('ip_address_service_web', '', requires=[{'option': b, 'expected': False, 'action': 'disabled'}]) od = OptionDescription('service', '', [a, b, d]) - api = getapi(Config(od)) + api = Config(od) api.property.read_write() api.option('activate_service').value.get() api.option('activate_service_web').value.get() @@ -422,7 +422,7 @@ def test_requires_transitive_hidden_disabled_multiple(): d = IPOption('ip_address_service_web', '', requires=[{'option': b, 'expected': False, 'action': 'mandatory'}]) od = OptionDescription('service', '', [a, b, d]) - api = getapi(Config(od)) + api = Config(od) api.property.read_write() api.option('activate_service').value.get() api.option('activate_service_web').value.get() @@ -459,7 +459,7 @@ def test_requires_not_transitive(): requires=[{'option': b, 'expected': False, 'action': 'disabled', 'transitive': False}]) od = OptionDescription('service', '', [a, b, d]) - api = getapi(Config(od)) + api = Config(od) api.property.read_write() api.option('activate_service').value.get() api.option('activate_service_web').value.get() @@ -484,7 +484,7 @@ def test_requires_not_transitive_not_same_action(): requires=[{'option': b, 'expected': False, 'action': 'hidden', 'transitive': False}]) od = OptionDescription('service', '', [a, b, d]) - api = getapi(Config(od)) + api = Config(od) api.property.read_write() api.option('activate_service').value.get() api.option('activate_service_web').value.get() @@ -506,7 +506,7 @@ def test_requires_None(): b = IPOption('ip_address_service', '', requires=[{'option': a, 'expected': None, 'action': 'disabled'}]) od = OptionDescription('service', '', [a, b]) - api = getapi(Config(od)) + api = Config(od) api.property.read_write() props = [] try: @@ -525,7 +525,7 @@ def test_requires_multi_disabled(): requires=[{'option': a, 'expected': True, 'action': 'disabled'}, {'option': b, 'expected': 1, 'action': 'disabled'}]) od = OptionDescription('service', '', [a, b, c]) - api = getapi(Config(od)) + api = Config(od) api.property.read_write() api.option('ip_address_service').value.get() @@ -564,7 +564,7 @@ def test_requires_multi_disabled_new_format(): c = IPOption('ip_address_service', '', requires=[{'expected': [{'option': a, 'value': True}, {'option': b, 'value': 1}], 'action': 'disabled'}]) od = OptionDescription('service', '', [a, b, c]) - api = getapi(Config(od)) + api = Config(od) api.property.read_write() api.option('ip_address_service').value.get() @@ -627,7 +627,7 @@ def test_requires_multi_disabled_new_format_and(): c = IPOption('ip_address_service', '', requires=[{'expected': [{'option': a, 'value': True}, {'option': b, 'value': 1}], 'action': 'disabled', 'operator': 'and'}]) od = OptionDescription('service', '', [a, b, c]) - api = getapi(Config(od)) + api = Config(od) api.property.read_write() api.option('ip_address_service').value.get() @@ -667,7 +667,7 @@ def test_requires_multi_disabled_new_format_and_2(): requires=[{'expected': [{'option': a, 'value': True}, {'option': b, 'value': 1}], 'action': 'disabled', 'operator': 'and'}, {'expected': [{'option': a, 'value': False}, {'option': b, 'value': 1}], 'action': 'expert'}]) od = OptionDescription('service', '', [a, b, c]) - api = getapi(Config(od)) + api = Config(od) api.property.add('expert') api.property.read_write() api.option('ip_address_service').value.get() @@ -707,7 +707,7 @@ def test_requires_multi_disabled_inverse(): {'option': b, 'expected': 1, 'action': 'disabled', 'inverse': True}]) od = OptionDescription('service', '', [a, b, c]) - api = getapi(Config(od)) + api = Config(od) api.property.read_write() props = [] @@ -767,7 +767,7 @@ def test_requires_multi_disabled_2(): y = copy(list_bools) y.append(z) od = OptionDescription('service', '', y) - api = getapi(Config(od)) + api = Config(od) api.property.read_write() api.option('z').value.get() @@ -815,7 +815,7 @@ def test_requires_multi_disabled_inverse_2(): y = copy(list_bools) y.append(z) od = OptionDescription('service', '', y) - api = getapi(Config(od)) + api = Config(od) api.property.read_write() props = [] @@ -850,7 +850,7 @@ def test_requires_requirement_append(): b = IPOption('ip_address_service', '', requires=[{'option': a, 'expected': False, 'action': 'disabled'}]) od = OptionDescription('service', '', [a, b]) - api = getapi(Config(od)) + api = Config(od) api.property.read_write() api.property.get() api.option('ip_address_service').property.get() @@ -866,7 +866,7 @@ def test_requires_different_inverse(): {'option': a, 'expected': True, 'action': 'disabled', 'inverse': True}, {'option': a, 'expected': True, 'action': 'disabled', 'inverse': False}]) od = OptionDescription('service', '', [a, b]) - api = getapi(Config(od)) + api = Config(od) api.property.read_write() raises(PropertiesOptionError, "api.option('ip_address_service').value.get()") api.option('activate_service').value.set(False) @@ -880,7 +880,7 @@ def test_requires_different_inverse_unicode(): {'option': a, 'expected': True, 'action': 'disabled', 'inverse': True}, {'option': d, 'expected': 'val1', 'action': 'disabled', 'inverse': False}]) od = OptionDescription('service', '', [a, d, b]) - api = getapi(Config(od)) + api = Config(od) api.property.read_write() assert api.option('ip_address_service').value.get() == None api.option('activate_service').value.set(False) @@ -899,7 +899,7 @@ def test_requires_recursive_path(): requires=[{'option': a, 'expected': False, 'action': 'disabled'}]) od1 = OptionDescription('service', '', [a, b], requires=[{'option': a, 'expected': False, 'action': 'disabled'}]) od = OptionDescription('base', '', [od1]) - api = getapi(Config(od)) + api = Config(od) api.property.read_write() raises(RequirementError, "api.option('service.a').value.get()") @@ -932,7 +932,7 @@ def test_master_slave_requires(): interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) #interface1.impl_set_group_type(groups.master) maconfig = OptionDescription('toto', '', [interface1]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2']) @@ -962,7 +962,7 @@ def test_master_slave_requires_no_master(): interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) #interface1.impl_set_group_type(groups.master) maconfig = OptionDescription('toto', '', [activate, interface1]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2']) diff --git a/test/test_submulti.py b/test/test_submulti.py index 7323a9f..823a1ec 100644 --- a/test/test_submulti.py +++ b/test/test_submulti.py @@ -7,7 +7,7 @@ from py.test import raises from tiramisu.api import TIRAMISU_VERSION from tiramisu.setting import groups, owners from tiramisu import StrOption, IntOption, OptionDescription, submulti, MasterSlaves, Config, \ - MetaConfig, getapi, undefined, Params, ParamOption + MetaConfig, undefined, Params, ParamOption from tiramisu.error import SlaveError @@ -40,7 +40,7 @@ def test_submulti(): multi2 = StrOption('multi2', '', default_multi=default_multi, multi=submulti) multi3 = StrOption('multi3', '', default=[['yes']], multi=submulti) od = OptionDescription('od', '', [multi, multi2, multi3]) - api = getapi(Config(od)) + api = Config(od) assert api.option('multi').owner.get() == owners.default assert api.option('multi').value.get() == [] assert api.option('multi').owner.get() == owners.default @@ -62,7 +62,7 @@ def test_append_submulti(): multi2 = StrOption('multi2', '', default_multi=default_multi, multi=submulti) multi3 = StrOption('multi3', '', default=[['yes']], multi=submulti) od = OptionDescription('od', '', [multi, multi2, multi3]) - api = getapi(Config(od)) + api = Config(od) owner = api.owner.get() assert api.option('multi').value.get() == [] assert api.option('multi').owner.get() == owners.default @@ -98,7 +98,7 @@ def test_append_unvalide_submulti(): multi2 = StrOption('multi2', '', default_multi=default_multi, multi=submulti) multi3 = StrOption('multi3', '', default=[['yes']], multi=submulti) od = OptionDescription('od', '', [multi, multi2, multi3]) - api = getapi(Config(od)) + api = Config(od) assert api.option('multi').value.get() == [] assert api.option('multi').owner.get() == owners.default raises(ValueError, "api.option('multi').value.set([[1]])") @@ -126,7 +126,7 @@ def test_pop_submulti(): multi2 = StrOption('multi2', '', default_multi=default_multi, multi=submulti) multi3 = StrOption('multi3', '', default=[['yes']], multi=submulti) od = OptionDescription('od', '', [multi, multi2, multi3]) - api = getapi(Config(od)) + api = Config(od) owner = api.owner.get() assert api.option('multi').value.get() == [] assert api.option('multi3').owner.get() == owners.default @@ -149,7 +149,7 @@ def test_pop_submulti(): def test_callback_submulti_str(): multi = StrOption('multi', '', multi=submulti, callback=return_val) od = OptionDescription('od', '', [multi]) - api = getapi(Config(od)) + api = Config(od) api.property.read_write() owner = api.owner.get() assert api.option('multi').owner.get() == owners.default @@ -164,7 +164,7 @@ def test_callback_submulti_str(): def test_callback_submulti_list(): multi = StrOption('multi', '', multi=submulti, callback=return_list) od = OptionDescription('od', '', [multi]) - api = getapi(Config(od)) + api = Config(od) api.property.read_write() owner = api.owner.get() assert api.option('multi').value.get() == [['val', 'val']] @@ -181,7 +181,7 @@ def test_callback_submulti_list(): def test_callback_submulti_list_list(): multi = StrOption('multi', '', multi=submulti, callback=return_list2) od = OptionDescription('od', '', [multi]) - api = getapi(Config(od)) + api = Config(od) api.property.read_write() owner = api.owner.get() assert api.option('multi').value.get() == [['val', 'val']] @@ -216,7 +216,7 @@ def test_values_with_master_and_slaves_submulti(): interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) #interface1.impl_set_group_type(groups.master) maconfig = OptionDescription('toto', '', [interface1]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() owner = api.owner.get() assert interface1.impl_get_group_type() == groups.master @@ -242,7 +242,7 @@ def test_reset_values_with_master_and_slaves_submulti(): interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) #interface1.impl_set_group_type(groups.master) maconfig = OptionDescription('toto', '', [interface1]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() owner = api.owner.get() assert interface1.impl_get_group_type() == groups.master @@ -269,7 +269,7 @@ def test_values_with_master_and_slaves_slave_submulti(): interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) #interface1.impl_set_group_type(groups.master) maconfig = OptionDescription('toto', '', [interface1]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() raises(SlaveError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(['255.255.255.0'])") api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145']) @@ -289,7 +289,7 @@ def test_values_with_master_and_slaves_master_submulti(): interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) #interface1.impl_set_group_type(groups.master) maconfig = OptionDescription('toto', '', [interface1]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"]) api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", "192.168.230.145"]) @@ -310,7 +310,7 @@ def test_values_with_master_owner_submulti(): interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) #interface1.impl_set_group_type(groups.master) maconfig = OptionDescription('toto', '', [interface1]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() owner = api.owner.get() assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.default @@ -326,7 +326,7 @@ def test_values_with_master_disabled_submulti(): netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=submulti) interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) maconfig = OptionDescription('toto', '', [interface1]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145']) api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0) @@ -352,7 +352,7 @@ def test__master_is_submulti(): interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) #interface1.impl_set_group_type(groups.master) maconfig = OptionDescription('toto', '', [interface1]) - api = getapi(Config(maconfig)) + api = Config(maconfig) api.property.read_write() owner = api.owner.get() assert interface1.impl_get_group_type() == groups.master @@ -374,7 +374,7 @@ def test_callback_submulti(): multi = StrOption('multi', '', multi=submulti) multi2 = StrOption('multi2', '', multi=submulti, callback=return_val, callback_params=Params(ParamOption(multi))) od = OptionDescription('multi', '', [multi, multi2]) - api = getapi(Config(od)) + api = Config(od) api.property.read_write() owner = api.owner.get() assert api.option('multi').owner.get() == owners.default @@ -390,7 +390,7 @@ def test_callback_submulti(): def test_submulti_unique(): i = IntOption('int', '', multi=submulti, unique=True) o = OptionDescription('od', '', [i]) - api = getapi(Config(o)) + api = Config(o) assert api.option('int').value.get() == [] api.option('int').value.set([[0]]) assert api.option('int').value.get() == [[0]] @@ -412,20 +412,17 @@ def test_multi_submulti_meta(): multi = StrOption('multi', '', multi=submulti) od = OptionDescription('od', '', [multi]) conf1 = Config(od, session_id='conf1') - api1 = getapi(conf1) - api1.property.read_write() + conf1.property.read_write() conf2 = Config(od, session_id='conf2') - api2 = getapi(conf2) - api2.property.read_write() + conf2.property.read_write() meta = MetaConfig([conf1, conf2]) - api3 = getapi(meta) - api3.property.read_write() - api3.option('multi').value.set([['val']]) - assert api3.option('multi').value.get() == [['val']] - api3.config('conf1').option('multi').value.set([['val', None]]) - assert api1.option('multi').value.get() == [['val', None]] - assert api3.config('conf1').option('multi').value.get() == [['val', None]] - assert api3.option('multi').value.get() == [['val']] + meta.property.read_write() + meta.option('multi').value.set([['val']]) + assert meta.option('multi').value.get() == [['val']] + meta.config('conf1').option('multi').value.set([['val', None]]) + assert conf1.option('multi').value.get() == [['val', None]] + assert meta.config('conf1').option('multi').value.get() == [['val', None]] + assert meta.option('multi').value.get() == [['val']] def test_multi_submulti_meta_no_cache(): @@ -433,18 +430,15 @@ def test_multi_submulti_meta_no_cache(): multi = StrOption('multi', '', multi=submulti) od = OptionDescription('od', '', [multi]) conf1 = Config(od, session_id='conf1') - api1 = getapi(conf1) - api1.property.read_write() + conf1.property.read_write() conf2 = Config(od, session_id='conf2') - api2 = getapi(conf2) - api2.property.read_write() + conf1.property.read_write() meta = MetaConfig([conf1, conf2]) - api3 = getapi(meta) - api3.property.read_write() - api3.property.pop('cache') - api3.option('multi').value.set([['val']]) - assert api3.option('multi').value.get() == [['val']] - api3.config('conf1').option('multi').value.set([['val', None]]) - assert api1.option('multi').value.get() == [['val', None]] - assert api3.config('conf1').option('multi').value.get() == [['val', None]] - assert api3.option('multi').value.get() == [['val']] + meta.property.read_write() + meta.property.pop('cache') + meta.option('multi').value.set([['val']]) + assert meta.option('multi').value.get() == [['val']] + meta.config('conf1').option('multi').value.set([['val', None]]) + assert conf1.option('multi').value.get() == [['val', None]] + assert meta.config('conf1').option('multi').value.get() == [['val', None]] + assert meta.option('multi').value.get() == [['val']] diff --git a/test/test_symlink.py b/test/test_symlink.py index 1cbb7ae..8a43397 100644 --- a/test/test_symlink.py +++ b/test/test_symlink.py @@ -3,7 +3,7 @@ from .autopath import do_autopath do_autopath() from tiramisu import BoolOption, StrOption, SymLinkOption, \ - OptionDescription, MasterSlaves, Config, getapi + OptionDescription, MasterSlaves, Config from tiramisu.error import PropertiesOptionError, ConfigError from tiramisu.setting import groups, owners from tiramisu.api import TIRAMISU_VERSION @@ -21,7 +21,7 @@ def test_symlink_option(): linkopt = SymLinkOption("c", boolopt) descr = OptionDescription("opt", "", [linkopt, OptionDescription("s1", "", [boolopt])]) - api = getapi(Config(descr)) + api = Config(descr) assert api.option('s1.b').value.get() is False api.option("s1.b").value.set(True) api.option("s1.b").value.set(False) @@ -40,7 +40,7 @@ def test_symlink_assign_option(): linkopt = SymLinkOption("c", boolopt) descr = OptionDescription("opt", "", [linkopt, OptionDescription("s1", "", [boolopt])]) - api = getapi(Config(descr)) + api = Config(descr) raises(ConfigError, "api.option('c').value.set(True)") @@ -49,7 +49,7 @@ def test_symlink_del_option(): linkopt = SymLinkOption("c", boolopt) descr = OptionDescription("opt", "", [linkopt, OptionDescription("s1", "", [boolopt])]) - api = getapi(Config(descr)) + api = Config(descr) raises(TypeError, "api.option('c').value.reset()") @@ -57,7 +57,7 @@ def test_symlink_addproperties(): boolopt = BoolOption('b', '', default=True, properties=('test',)) linkopt = SymLinkOption("c", boolopt) descr = OptionDescription('opt', '', [boolopt, linkopt]) - api = getapi(Config(descr)) + api = Config(descr) api.property.read_write() raises(TypeError, "api.option('c').property.add('new')") raises(TypeError, "api.option('c').property.reset()") @@ -67,7 +67,7 @@ def test_symlink_addpermissive(): boolopt = BoolOption('b', '', default=True, properties=('test',)) linkopt = SymLinkOption("c", boolopt) descr = OptionDescription('opt', '', [boolopt, linkopt]) - api = getapi(Config(descr)) + api = Config(descr) api.property.read_write() raises(TypeError, "api.option('c').permissive.set(frozenset(['new']))") raises(TypeError, "api.option('c').permissive.reset()") @@ -77,7 +77,7 @@ def test_symlink_getproperties(): boolopt = BoolOption('b', '', default=True, properties=('test',)) linkopt = SymLinkOption("c", boolopt) descr = OptionDescription('opt', '', [boolopt, linkopt]) - api = getapi(Config(descr)) + api = Config(descr) api.property.read_write() if TIRAMISU_VERSION == 2: assert boolopt.impl_getproperties() == linkopt.impl_getproperties() == ('test',) @@ -90,7 +90,7 @@ def test_symlink_getcallback(): boolopt = BoolOption('b', '', callback=return_value) linkopt = SymLinkOption("c", boolopt) descr = OptionDescription('opt', '', [boolopt, linkopt]) - api = getapi(Config(descr)) + api = Config(descr) api.property.read_write() assert boolopt.impl_has_callback() == linkopt.impl_has_callback() == True assert boolopt.impl_get_callback() == linkopt.impl_get_callback() == (return_value, None) @@ -103,7 +103,7 @@ def test_symlink_requires(): 'action': 'disabled'}]) linkopt = SymLinkOption("c", stropt) descr = OptionDescription('opt', '', [boolopt, stropt, linkopt]) - api = getapi(Config(descr)) + api = Config(descr) api.property.read_write() assert api.option('b').value.get() is True assert api.option('s').value.get() is None @@ -136,7 +136,7 @@ def test_symlink_multi(): linkopt = SymLinkOption("c", boolopt) descr = OptionDescription("opt", "", [linkopt, OptionDescription("s1", "", [boolopt])]) - api = getapi(Config(descr)) + api = Config(descr) assert api.option('s1.b').value.get() == [False] assert api.option('c').value.get() == [False] api.option('s1.b').value.set([True]) @@ -158,7 +158,7 @@ def test_symlink_assign(): linkopt = SymLinkOption("c", boolopt) descr = OptionDescription("opt", "", [linkopt, OptionDescription("s1", "", [boolopt])]) - api = getapi(Config(descr)) + api = Config(descr) raises(ConfigError, "api.option('c').value.set(True)") @@ -167,7 +167,7 @@ def test_symlink_owner(): linkopt = SymLinkOption("c", boolopt) descr = OptionDescription("opt", "", [linkopt, OptionDescription("s1", "", [boolopt])]) - api = getapi(Config(descr)) + api = Config(descr) assert api.option('s1.b').owner.isdefault() assert api.option('c').owner.isdefault() api.option('s1.b').value.set(True) @@ -206,7 +206,7 @@ def test_symlink_with_master(): interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) master = SymLinkOption('master', ip_admin_eth0) od = OptionDescription('root', '', [interface1, master]) - api = getapi(Config(od)) + api = Config(od) assert api.option.make_dict() == {'ip_admin_eth0.ip_admin_eth0': [], 'ip_admin_eth0.netmask_admin_eth0': [], 'master': []} api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val2']) assert api.option.make_dict() == {'ip_admin_eth0.ip_admin_eth0': ['val1', 'val2'], 'ip_admin_eth0.netmask_admin_eth0': [None, None], 'master': ['val1', 'val2']} @@ -218,7 +218,7 @@ def test_symlink_with_slave(): interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) slave = SymLinkOption('slave', netmask_admin_eth0) od = OptionDescription('root', '', [interface1, slave]) - api = getapi(Config(od)) + api = Config(od) assert api.option.make_dict() == {'ip_admin_eth0.ip_admin_eth0': [], 'ip_admin_eth0.netmask_admin_eth0': [], 'slave': []} api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val2']) assert api.option.make_dict() == {'ip_admin_eth0.ip_admin_eth0': ['val1', 'val2'], 'ip_admin_eth0.netmask_admin_eth0': [None, None], 'slave': [None, None]} @@ -243,7 +243,7 @@ def test_symlink_dependency(): linkopt = SymLinkOption("c", boolopt) descr = OptionDescription("opt", "", [linkopt, OptionDescription("s1", "", [boolopt])]) - api = getapi(Config(descr)) + api = Config(descr) assert api.option('s1.b').option.has_dependency() is False assert api.option('c').option.has_dependency() is True assert api.option('s1.b').option.has_dependency(False) is True @@ -254,7 +254,7 @@ def test_symlink_makedict(): linkopt = SymLinkOption("c", boolopt) descr = OptionDescription("opt", "", [linkopt, OptionDescription("s1", "", [boolopt])]) - api = getapi(Config(descr)) + api = Config(descr) assert api.option.make_dict() == {'c': False, 's1.b': False} api.option('s1.b').value.set(True) assert api.option.make_dict() == {'c': True, 's1.b': True}