From e4c129efc58633d14c1ceeda8919978a395b3f1f Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Sat, 24 Aug 2013 22:32:54 +0200 Subject: [PATCH] getowner need now an option --- test/test_config_api.py | 1 + test/test_freeze.py | 8 ++--- test/test_mandatory.py | 12 +++---- test/test_metaconfig.py | 64 ++++++++++++++++----------------- test/test_option_consistency.py | 4 +-- test/test_option_owner.py | 18 +++++----- test/test_option_setting.py | 14 ++++---- test/test_parsing_group.py | 60 ++++++++++++++++--------------- test/test_symlink.py | 11 +++--- tiramisu/config.py | 12 ++++--- 10 files changed, 106 insertions(+), 98 deletions(-) diff --git a/test/test_config_api.py b/test/test_config_api.py index fee50e7..62a74c0 100644 --- a/test/test_config_api.py +++ b/test/test_config_api.py @@ -94,6 +94,7 @@ def test_make_dict(): assert d == {"s1.a": True, "int": 43} d2 = config.make_dict(flatten=True) assert d2 == {'a': True, 'int': 43} + raises(ValueError, 'd2 = config.make_dict(withvalue="3")') def test_find_in_config(): diff --git a/test/test_freeze.py b/test/test_freeze.py index 4240f07..b79138f 100644 --- a/test/test_freeze.py +++ b/test/test_freeze.py @@ -141,15 +141,15 @@ def test_freeze_get_multi(): def test_force_store_value(): descr = make_description_freeze() conf = Config(descr) - assert conf.getowner('wantref') == 'default' + assert conf.getowner(conf.unwrap_from_path('wantref')) == 'default' conf.wantref - assert conf.getowner('wantref') == 'user' + assert conf.getowner(conf.unwrap_from_path('wantref')) == 'user' def test_force_store_value_ro(): descr = make_description_freeze() conf = Config(descr) conf.read_only() - assert conf.getowner('wantref') == 'default' + assert conf.getowner(conf.unwrap_from_path('wantref')) == 'default' conf.wantref - assert conf.getowner('wantref') == 'user' + assert conf.getowner(conf.unwrap_from_path('wantref')) == 'user' diff --git a/test/test_mandatory.py b/test/test_mandatory.py index 58a8454..aad04ee 100644 --- a/test/test_mandatory.py +++ b/test/test_mandatory.py @@ -71,7 +71,7 @@ def test_mandatory_none(): descr = make_description() config = Config(descr) config.str1 = None - assert config.getowner('str1') == 'user' + assert config.getowner(config.unwrap_from_path('str1')) == 'user' config.read_only() prop = [] try: @@ -85,7 +85,7 @@ def test_mandatory_empty(): descr = make_description() config = Config(descr) config.str1 = '' - assert config.getowner('str1') == 'user' + assert config.getowner(config.unwrap_from_path('str1')) == 'user' config.read_only() prop = [] try: @@ -100,7 +100,7 @@ def test_mandatory_multi_none(): config = Config(descr) config.str3 = [None] config.read_only() - assert config.getowner('str3') == 'user' + assert config.getowner(config.unwrap_from_path('str3')) == 'user' prop = [] try: config.str3 @@ -110,7 +110,7 @@ def test_mandatory_multi_none(): config.read_write() config.str3 = ['yes', None] config.read_only() - assert config.getowner('str3') == 'user' + assert config.getowner(config.unwrap_from_path('str3')) == 'user' prop = [] try: config.str3 @@ -124,7 +124,7 @@ def test_mandatory_multi_empty(): config = Config(descr) config.str3 = [''] config.read_only() - assert config.getowner('str3') == 'user' + assert config.getowner(config.unwrap_from_path('str3')) == 'user' prop = [] try: config.str3 @@ -134,7 +134,7 @@ def test_mandatory_multi_empty(): config.read_write() config.str3 = ['yes', ''] config.read_only() - assert config.getowner('str3') == 'user' + assert config.getowner(config.unwrap_from_path('str3')) == 'user' prop = [] try: config.str3 diff --git a/test/test_metaconfig.py b/test/test_metaconfig.py index 138fb84..defb9af 100644 --- a/test/test_metaconfig.py +++ b/test/test_metaconfig.py @@ -31,69 +31,69 @@ def test_none(): meta = make_description() conf1, conf2 = meta._impl_children assert conf1.od1.i3 is conf2.od1.i3 is None - assert conf1.getowner('od1.i3') is conf2.getowner('od1.i3') is owners.default + assert conf1.getowner(conf1.unwrap_from_path('od1.i3')) is conf2.getowner(conf2.unwrap_from_path('od1.i3')) is owners.default meta.od1.i3 = 3 assert conf1.od1.i3 == conf2.od1.i3 == 3 - assert conf1.getowner('od1.i3') is conf2.getowner('od1.i3') is owners.meta + assert conf1.getowner(conf1.unwrap_from_path('od1.i3')) is conf2.getowner(conf2.unwrap_from_path('od1.i3')) is owners.meta meta.od1.i3 = 3 conf1.od1.i3 = 2 assert conf1.od1.i3 == 2 assert conf2.od1.i3 == 3 - assert conf1.getowner('od1.i3') is owners.user - assert conf2.getowner('od1.i3') is owners.meta + assert conf1.getowner(conf1.unwrap_from_path('od1.i3')) is owners.user + assert conf2.getowner(conf2.unwrap_from_path('od1.i3')) is owners.meta meta.od1.i3 = 4 assert conf1.od1.i3 == 2 assert conf2.od1.i3 == 4 - assert conf1.getowner('od1.i3') is owners.user - assert conf2.getowner('od1.i3') is owners.meta + assert conf1.getowner(conf1.unwrap_from_path('od1.i3')) is owners.user + assert conf2.getowner(conf2.unwrap_from_path('od1.i3')) is owners.meta del(meta.od1.i3) assert conf1.od1.i3 == 2 assert conf2.od1.i3 is None - assert conf1.getowner('od1.i3') is owners.user - assert conf2.getowner('od1.i3') is owners.default + assert conf1.getowner(conf1.unwrap_from_path('od1.i3')) is owners.user + assert conf2.getowner(conf2.unwrap_from_path('od1.i3')) is owners.default del(conf1.od1.i3) assert conf1.od1.i3 is conf2.od1.i3 is None - assert conf1.getowner('od1.i3') is conf2.getowner('od1.i3') is owners.default + assert conf1.getowner(conf1.unwrap_from_path('od1.i3')) is conf2.getowner(conf2.unwrap_from_path('od1.i3')) is owners.default def test_default(): meta = make_description() conf1, conf2 = meta._impl_children assert conf1.od1.i2 == conf2.od1.i2 == 1 - assert conf1.getowner('od1.i2') is conf2.getowner('od1.i2') is owners.default + assert conf1.getowner(conf1.unwrap_from_path('od1.i2')) is conf2.getowner(conf2.unwrap_from_path('od1.i2')) is owners.default meta.od1.i2 = 3 assert conf1.od1.i2 == conf2.od1.i2 == 3 - assert conf1.getowner('od1.i2') is conf2.getowner('od1.i2') is owners.meta + assert conf1.getowner(conf1.unwrap_from_path('od1.i2')) is conf2.getowner(conf2.unwrap_from_path('od1.i2')) is owners.meta meta.od1.i2 = 3 conf1.od1.i2 = 2 assert conf1.od1.i2 == 2 assert conf2.od1.i2 == 3 - assert conf1.getowner('od1.i2') is owners.user - assert conf2.getowner('od1.i2') is owners.meta + assert conf1.getowner(conf1.unwrap_from_path('od1.i2')) is owners.user + assert conf2.getowner(conf2.unwrap_from_path('od1.i2')) is owners.meta meta.od1.i2 = 4 assert conf1.od1.i2 == 2 assert conf2.od1.i2 == 4 - assert conf1.getowner('od1.i2') is owners.user - assert conf2.getowner('od1.i2') is owners.meta + assert conf1.getowner(conf1.unwrap_from_path('od1.i2')) is owners.user + assert conf2.getowner(conf2.unwrap_from_path('od1.i2')) is owners.meta del(meta.od1.i2) assert conf1.od1.i2 == 2 assert conf2.od1.i2 == 1 - assert conf1.getowner('od1.i2') is owners.user - assert conf2.getowner('od1.i2') is owners.default + assert conf1.getowner(conf1.unwrap_from_path('od1.i2')) is owners.user + assert conf2.getowner(conf2.unwrap_from_path('od1.i2')) is owners.default del(conf1.od1.i2) assert conf1.od1.i2 == conf2.od1.i2 == 1 - assert conf1.getowner('od1.i2') is conf2.getowner('od1.i2') is owners.default + assert conf1.getowner(conf1.unwrap_from_path('od1.i2')) is conf2.getowner(conf2.unwrap_from_path('od1.i2')) is owners.default def test_contexts(): meta = make_description() conf1, conf2 = meta._impl_children assert conf1.od1.i2 == conf2.od1.i2 == 1 - assert conf1.getowner('od1.i2') is conf2.getowner('od1.i2') is owners.default + assert conf1.getowner(conf1.unwrap_from_path('od1.i2')) is conf2.getowner(conf2.unwrap_from_path('od1.i2')) is owners.default meta.set_contexts('od1.i2', 6) assert meta.od1.i2 == 1 assert conf1.od1.i2 == conf2.od1.i2 == 6 - assert conf1.getowner('od1.i2') is conf2.getowner('od1.i2') is owners.user + assert conf1.getowner(conf1.unwrap_from_path('od1.i2')) is conf2.getowner(conf2.unwrap_from_path('od1.i2')) is owners.user def test_find(): @@ -110,32 +110,32 @@ def test_meta_meta(): meta2.cfgimpl_get_settings().setowner(owners.meta) conf1, conf2 = meta1._impl_children assert conf1.od1.i2 == conf2.od1.i2 == 1 - assert conf1.getowner('od1.i2') is conf2.getowner('od1.i2') is owners.default + assert conf1.getowner(conf1.unwrap_from_path('od1.i2')) is conf2.getowner(conf2.unwrap_from_path('od1.i2')) is owners.default meta2.od1.i2 = 3 assert conf1.od1.i2 == conf2.od1.i2 == 3 - assert conf1.getowner('od1.i2') is conf2.getowner('od1.i2') is owners.meta + assert conf1.getowner(conf1.unwrap_from_path('od1.i2')) is conf2.getowner(conf2.unwrap_from_path('od1.i2')) is owners.meta meta2.od1.i2 = 3 conf1.od1.i2 = 2 assert conf1.od1.i2 == 2 assert conf2.od1.i2 == 3 - assert conf1.getowner('od1.i2') is owners.user - assert conf2.getowner('od1.i2') is owners.meta + assert conf1.getowner(conf1.unwrap_from_path('od1.i2')) is owners.user + assert conf2.getowner(conf2.unwrap_from_path('od1.i2')) is owners.meta meta2.od1.i2 = 4 assert conf1.od1.i2 == 2 assert conf2.od1.i2 == 4 - assert conf1.getowner('od1.i2') is owners.user - assert conf2.getowner('od1.i2') is owners.meta + assert conf1.getowner(conf1.unwrap_from_path('od1.i2')) is owners.user + assert conf2.getowner(conf2.unwrap_from_path('od1.i2')) is owners.meta del(meta2.od1.i2) assert conf1.od1.i2 == 2 assert conf2.od1.i2 == 1 - assert conf1.getowner('od1.i2') is owners.user - assert conf2.getowner('od1.i2') is owners.default + assert conf1.getowner(conf1.unwrap_from_path('od1.i2')) is owners.user + assert conf2.getowner(conf2.unwrap_from_path('od1.i2')) is owners.default del(conf1.od1.i2) assert conf1.od1.i2 == conf2.od1.i2 == 1 - assert conf1.getowner('od1.i2') is conf2.getowner('od1.i2') is owners.default + assert conf1.getowner(conf1.unwrap_from_path('od1.i2')) is conf2.getowner(conf2.unwrap_from_path('od1.i2')) is owners.default meta1.od1.i2 = 6 assert conf1.od1.i2 == conf2.od1.i2 == 6 - assert conf1.getowner('od1.i2') is conf2.getowner('od1.i2') is owners.meta + assert conf1.getowner(conf1.unwrap_from_path('od1.i2')) is conf2.getowner(conf2.unwrap_from_path('od1.i2')) is owners.meta def test_meta_meta_set(): @@ -145,7 +145,7 @@ def test_meta_meta_set(): conf1, conf2 = meta1._impl_children meta2.set_contexts('od1.i1', 7) assert conf1.od1.i1 == conf2.od1.i1 == 7 - assert conf1.getowner('od1.i1') is conf2.getowner('od1.i1') is owners.user + assert conf1.getowner(conf1.unwrap_from_path('od1.i1')) is conf2.getowner(conf2.unwrap_from_path('od1.i1')) is owners.user assert [conf1, conf2] == meta2.find_first_contexts(byname='i1', byvalue=7) conf1.od1.i1 = 8 assert [conf2] == meta2.find_first_contexts(byname='i1', byvalue=7) @@ -164,7 +164,7 @@ def test_not_meta(): conf1, conf2 = meta._impl_children meta.set_contexts('od1.i1', 7) assert conf1.od1.i1 == conf2.od1.i1 == 7 - assert conf1.getowner('od1.i1') is conf2.getowner('od1.i1') is owners.user + assert conf1.getowner(conf1.unwrap_from_path('od1.i1')) is conf2.getowner(conf2.unwrap_from_path('od1.i1')) is owners.user def test_meta_path(): diff --git a/test/test_option_consistency.py b/test/test_option_consistency.py index d273c66..72aeadb 100644 --- a/test/test_option_consistency.py +++ b/test/test_option_consistency.py @@ -52,9 +52,9 @@ def test_consistency_default_diff(): raises(ValueError, "c.a = 1") c.a = 2 c.b = 3 - assert c.getowner('a') is owners.user + assert c.getowner(a) is owners.user raises(ValueError, "del(c.a)") - assert c.getowner('a') is owners.user + assert c.getowner(a) is owners.user def test_consistency_ip_netmask(): diff --git a/test/test_option_owner.py b/test/test_option_owner.py index 12e10e7..dbefd07 100644 --- a/test/test_option_owner.py +++ b/test/test_option_owner.py @@ -34,9 +34,9 @@ def test_default_owner(): descr = OptionDescription('tiramisu', '', [gcdummy]) cfg = Config(descr) assert cfg.dummy is False - assert cfg.getowner('dummy') == 'default' + assert cfg.getowner(gcdummy) == 'default' cfg.dummy = True - assert cfg.getowner('dummy') == owners.user + assert cfg.getowner(gcdummy) == owners.user def test_add_owner(): @@ -44,11 +44,11 @@ def test_add_owner(): descr = OptionDescription('tiramisu', '', [gcdummy]) cfg = Config(descr) assert cfg.dummy is False - assert cfg.getowner('dummy') == 'default' + assert cfg.getowner(gcdummy) == 'default' owners.add_owner("gen_config") cfg.cfgimpl_get_settings().setowner(owners.gen_config) cfg.dummy = True - assert cfg.getowner('dummy') == owners.gen_config + assert cfg.getowner(gcdummy) == owners.gen_config def test_owner_is_not_a_string(): @@ -56,11 +56,11 @@ def test_owner_is_not_a_string(): descr = OptionDescription('tiramisu', '', [gcdummy]) cfg = Config(descr) assert cfg.dummy is False - assert cfg.getowner('dummy') == owners.default - assert cfg.getowner('dummy') == 'default' - assert isinstance(cfg.getowner('dummy'), owners.Owner) + assert cfg.getowner(gcdummy) == owners.default + assert cfg.getowner(gcdummy) == 'default' + assert isinstance(cfg.getowner(gcdummy), owners.Owner) cfg.dummy = True - assert cfg.getowner('dummy') == 'user' + assert cfg.getowner(gcdummy) == 'user' def test_setowner_without_valid_owner(): @@ -68,5 +68,5 @@ def test_setowner_without_valid_owner(): descr = OptionDescription('tiramisu', '', [gcdummy]) cfg = Config(descr) assert cfg.dummy is False - assert cfg.getowner('dummy') == 'default' + assert cfg.getowner(gcdummy) == 'default' raises(TypeError, "cfg.cfgimpl_get_settings().setowner('gen_config')") diff --git a/test/test_option_setting.py b/test/test_option_setting.py index a181941..a841b9b 100644 --- a/test/test_option_setting.py +++ b/test/test_option_setting.py @@ -56,10 +56,10 @@ def test_reset(): config = Config(descr) config.string = "foo" assert config.string == "foo" - assert config.getowner('string') == owners.user + assert config.getowner(s) == owners.user del(config.string) assert config.string == 'string' - assert config.getowner('string') == owners.default + assert config.getowner(s) == owners.default def test_reset_with_multi(): @@ -69,13 +69,13 @@ def test_reset_with_multi(): # config.string = [] del(config.string) assert config.string == ["string"] - assert config.getowner('string') == 'default' + assert config.getowner(s) == 'default' config.string = ["eggs", "spam", "foo"] - assert config.getowner('string') == 'user' + assert config.getowner(s) == 'user' config.string = [] del(config.string) # assert config.string == ["string"] - assert config.getowner('string') == 'default' + assert config.getowner(s) == 'default' raises(ValueError, "config.string = None") @@ -121,10 +121,10 @@ def test_access_with_multi_default(): s = StrOption("string", "", default=["string"], multi=True) descr = OptionDescription("options", "", [s]) config = Config(descr) - assert config.getowner('string') == 'default' + assert config.getowner(s) == 'default' config.string = ["foo", "bar"] assert config.string == ["foo", "bar"] - assert config.getowner('string') == 'user' + assert config.getowner(s) == 'user' def test_multi_with_requires(): diff --git a/test/test_parsing_group.py b/test/test_parsing_group.py index b649207..5f4985c 100644 --- a/test/test_parsing_group.py +++ b/test/test_parsing_group.py @@ -63,13 +63,17 @@ def test_make_dict_filter(): descr = make_description() config = Config(descr) config.read_write() - result = {'general.numero_etab': None, 'general.nombre_interfaces': 1, - 'general.serveur_ntp': [], 'general.mode_conteneur_actif': False, - 'general.time_zone': 'Paris', 'general.nom_machine': 'eoleng', - 'general.activer_proxy_client': False} + subresult = {'numero_etab': None, 'nombre_interfaces': 1, + 'serveur_ntp': [], 'mode_conteneur_actif': False, + 'time_zone': 'Paris', 'nom_machine': 'eoleng', + 'activer_proxy_client': False} + result = {} + for key, value in subresult.items(): + result['general.' + key] = value assert config.creole.make_dict(withoption='numero_etab') == result raises(AttributeError, "config.creole.make_dict(withoption='numero_etab', withvalue='toto')") assert config.creole.make_dict(withoption='numero_etab', withvalue=None) == result + assert config.creole.general.make_dict(withoption='numero_etab') == subresult def test_get_group_type(): @@ -168,14 +172,14 @@ def test_values_with_master_and_slaves(): cfg.read_write() owner = cfg.cfgimpl_get_settings().getowner() assert interface1.impl_get_group_type() == groups.master - assert cfg.getowner("ip_admin_eth0.ip_admin_eth0") == owners.default - assert cfg.getowner("ip_admin_eth0.netmask_admin_eth0") == owners.default + assert cfg.getowner(ip_admin_eth0) == owners.default + assert cfg.getowner(netmask_admin_eth0) == owners.default assert cfg.ip_admin_eth0.netmask_admin_eth0 == [] cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145") assert cfg.ip_admin_eth0.ip_admin_eth0 == ["192.168.230.145"] assert cfg.ip_admin_eth0.netmask_admin_eth0 == [None] - assert cfg.getowner("ip_admin_eth0.ip_admin_eth0") == owner - assert cfg.getowner("ip_admin_eth0.netmask_admin_eth0") == owners.default + assert cfg.getowner(ip_admin_eth0) == owner + assert cfg.getowner(netmask_admin_eth0) == owners.default def test_reset_values_with_master_and_slaves(): @@ -188,14 +192,14 @@ def test_reset_values_with_master_and_slaves(): cfg.read_write() owner = cfg.cfgimpl_get_settings().getowner() assert interface1.impl_get_group_type() == groups.master - assert cfg.getowner("ip_admin_eth0.ip_admin_eth0") == owners.default - assert cfg.getowner("ip_admin_eth0.netmask_admin_eth0") == owners.default + assert cfg.getowner(ip_admin_eth0) == owners.default + assert cfg.getowner(netmask_admin_eth0) == owners.default cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145") - assert cfg.getowner("ip_admin_eth0.ip_admin_eth0") == owner - assert cfg.getowner("ip_admin_eth0.netmask_admin_eth0") == owners.default + assert cfg.getowner(ip_admin_eth0) == owner + assert cfg.getowner(netmask_admin_eth0) == owners.default del(cfg.ip_admin_eth0.ip_admin_eth0) - assert cfg.getowner("ip_admin_eth0.ip_admin_eth0") == owners.default - assert cfg.getowner("ip_admin_eth0.netmask_admin_eth0") == owners.default + assert cfg.getowner(ip_admin_eth0) == owners.default + assert cfg.getowner(netmask_admin_eth0) == owners.default assert cfg.ip_admin_eth0.ip_admin_eth0 == [] assert cfg.ip_admin_eth0.netmask_admin_eth0 == [] @@ -254,14 +258,14 @@ def test_values_with_master_owner(): cfg = Config(maconfig) cfg.read_write() owner = cfg.cfgimpl_get_settings().getowner() - assert cfg.getowner("ip_admin_eth0.ip_admin_eth0") == owners.default - assert cfg.getowner("ip_admin_eth0.netmask_admin_eth0") == owners.default + assert cfg.getowner(ip_admin_eth0) == owners.default + assert cfg.getowner(netmask_admin_eth0) == owners.default cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145") - assert cfg.getowner("ip_admin_eth0.ip_admin_eth0") == owner - assert cfg.getowner("ip_admin_eth0.netmask_admin_eth0") == owners.default + assert cfg.getowner(ip_admin_eth0) == owner + assert cfg.getowner(netmask_admin_eth0) == owners.default cfg.ip_admin_eth0.ip_admin_eth0.pop(0) - assert cfg.getowner("ip_admin_eth0.ip_admin_eth0") == owner - assert cfg.getowner("ip_admin_eth0.netmask_admin_eth0") == owners.default + assert cfg.getowner(ip_admin_eth0) == owner + assert cfg.getowner(netmask_admin_eth0) == owners.default def test_values_with_master_disabled(): @@ -303,10 +307,10 @@ def test_multi_insert(): c = Config(od) c.read_write() assert c.var == ['ok'] - assert c.getowner("var") == owners.default + assert c.getowner(var) == owners.default c.var.insert(0, 'nok') assert c.var == ['nok', 'ok'] - assert c.getowner("var") != owners.default + assert c.getowner(var) != owners.default def test_multi_insert_master(): @@ -327,10 +331,10 @@ def test_multi_sort(): c = Config(od) c.read_write() assert c.var == ['ok', 'nok'] - assert c.getowner("var") == owners.default + assert c.getowner(var) == owners.default c.var.sort() assert c.var == ['nok', 'ok'] - assert c.getowner("var") != owners.default + assert c.getowner(var) != owners.default def test_multi_sort_master(): @@ -351,10 +355,10 @@ def test_multi_reverse(): c = Config(od) c.read_write() assert c.var == ['ok', 'nok'] - assert c.getowner("var") == owners.default + assert c.getowner(var) == owners.default c.var.reverse() assert c.var == ['nok', 'ok'] - assert c.getowner("var") != owners.default + assert c.getowner(var) != owners.default def test_multi_reverse_master(): @@ -375,10 +379,10 @@ def test_multi_extend(): c = Config(od) c.read_write() assert c.var == ['ok', 'nok'] - assert c.getowner("var") == owners.default + assert c.getowner(var) == owners.default c.var.extend(['pok']) assert c.var == ['ok', 'nok', 'pok'] - assert c.getowner("var") != owners.default + assert c.getowner(var) != owners.default def test_multi_extend_master(): diff --git a/test/test_symlink.py b/test/test_symlink.py index 1acdbb8..fcbcc03 100644 --- a/test/test_symlink.py +++ b/test/test_symlink.py @@ -1,3 +1,4 @@ +# coding: utf-8 import autopath from tiramisu.option import BoolOption, StrOption, SymLinkOption, \ @@ -84,11 +85,11 @@ def test_symlink_owner(): descr = OptionDescription("opt", "", [linkopt, OptionDescription("s1", "", [boolopt])]) config = Config(descr) - assert config.getowner('s1.b') == owners.default - assert config.getowner('c') == owners.default + assert config.getowner(boolopt) == owners.default + assert config.getowner(linkopt) == owners.default config.c = True - assert config.getowner('s1.b') != owners.default - assert config.getowner('c') != owners.default + assert config.getowner(boolopt) != owners.default + assert config.getowner(linkopt) != owners.default def test_symlink_get_information(): @@ -112,7 +113,7 @@ def test_symlink_master(): def test_symlink_slaves(): a = StrOption('a', "", multi=True) - ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) + ip_admin_eth0 = StrOption('ip_admin_eth0', u"ip réseau autorisé", multi=True) netmask_admin_eth0 = SymLinkOption('netmask_admin_eth0', a) interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) raises(ValueError, 'interface1.impl_set_group_type(groups.master)') diff --git a/tiramisu/config.py b/tiramisu/config.py index b3a65db..4c830d2 100644 --- a/tiramisu/config.py +++ b/tiramisu/config.py @@ -484,11 +484,13 @@ class CommonConfig(SubConfig): "read write is a global config's setting, see `settings.py`" self.cfgimpl_get_settings().read_write() - def getowner(self, path): + def getowner(self, opt): """convenience method to retrieve an option's owner from the config itself """ - opt = self.cfgimpl_get_description().impl_get_opt_by_path(path) + if not isinstance(opt, Option) and not isinstance(opt, SymLinkOption): + raise TypeError(_('opt in getowner must be an option not {0}' + '').format(type(opt))) return self.cfgimpl_get_values().getowner(opt) def unwrap_from_path(self, path, force_permissive=False): @@ -552,9 +554,9 @@ class MetaConfig(CommonConfig): if meta: for child in children: if not isinstance(child, CommonConfig): - raise ValueError(_("metaconfig's children " - "must be config, not {0}" - ).format(type(child))) + raise TypeError(_("metaconfig's children " + "must be config, not {0}" + ).format(type(child))) if self._impl_descr is None: self._impl_descr = child.cfgimpl_get_description() elif not self._impl_descr is child.cfgimpl_get_description():