From 071035854b3a5cf7f490cd5c85d86a3dc4aff59c Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Wed, 12 Oct 2016 20:49:56 +0200 Subject: [PATCH] slave with requires could not raise --- test/test_option_setting.py | 19 ++++++++++++++++--- test/test_requires.py | 14 ++++++++++++++ tiramisu/option/masterslave.py | 5 ++++- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/test/test_option_setting.py b/test/test_option_setting.py index cf6914d..8bd6d14 100644 --- a/test/test_option_setting.py +++ b/test/test_option_setting.py @@ -246,14 +246,27 @@ def test_multi_with_requires_that_is_masterslave_master(): raises(ValueError, "Config(descr)") -def test_multi_with_requires_that_is_masterslave2(): +def test_multi_with_requires_that_is_masterslave_slave(): b = IntOption('int', 'Test int option', default=[0], multi=True) c = StrOption('str', 'Test string option', multi=True) d = StrOption('str1', 'Test string option', requires=[{'option': c, 'expected': '1', 'action': 'hidden'}], multi=True) descr = OptionDescription("int", "", [b, c, d]) descr.impl_set_group_type(groups.master) - Config(descr) - + config = Config(descr) + config.read_write() + assert config.int == [0] + assert config.str == [None] + assert config.str1 == [None] + config.int = [0, 1] + assert config.int == [0, 1] + assert config.str == [None, None] + assert config.str1 == [None, None] + config.str = [None, '1'] + config.read_only() + assert config.str1 == [None, None] + config.read_write() + assert config.str1[0] is None + raises(PropertiesOptionError, 'config.str1[1]') def test_multi_with_requires_that_is_not_same_masterslave(): b = IntOption('int', 'Test int option', default=[0], multi=True) diff --git a/test/test_requires.py b/test/test_requires.py index dace0ca..5395160 100644 --- a/test/test_requires.py +++ b/test/test_requires.py @@ -644,6 +644,12 @@ def test_master_slave_requires(): cfg.ip_admin_eth0.ip_admin_eth0.append('192.168.1.1') assert cfg.ip_admin_eth0.netmask_admin_eth0[0] is None raises(PropertiesOptionError, "cfg.ip_admin_eth0.netmask_admin_eth0[1]") + cfg.ip_admin_eth0.ip_admin_eth0[1] = '192.168.1.2' + assert cfg.ip_admin_eth0.netmask_admin_eth0[1] is None + cfg.ip_admin_eth0.netmask_admin_eth0[1] = '255.255.255.255' + assert cfg.ip_admin_eth0.netmask_admin_eth0[1] == '255.255.255.255' + cfg.ip_admin_eth0.ip_admin_eth0[1] = '192.168.1.1' + raises(PropertiesOptionError, "cfg.ip_admin_eth0.netmask_admin_eth0[1]") def test_master_slave_requires_no_master(): @@ -668,3 +674,11 @@ def test_master_slave_requires_no_master(): raises(PropertiesOptionError, "cfg.ip_admin_eth0.netmask_admin_eth0") raises(PropertiesOptionError, "cfg.ip_admin_eth0.netmask_admin_eth0[0]") raises(PropertiesOptionError, "cfg.ip_admin_eth0.netmask_admin_eth0[1]") + cfg.activate = True + assert cfg.ip_admin_eth0.netmask_admin_eth0 == [None, None] + cfg.ip_admin_eth0.netmask_admin_eth0 = [None, '255.255.255.255'] + assert cfg.ip_admin_eth0.netmask_admin_eth0[1] == '255.255.255.255' + cfg.activate = False + raises(PropertiesOptionError, "cfg.ip_admin_eth0.netmask_admin_eth0") + raises(PropertiesOptionError, "cfg.ip_admin_eth0.netmask_admin_eth0[0]") + raises(PropertiesOptionError, "cfg.ip_admin_eth0.netmask_admin_eth0[1]") diff --git a/tiramisu/option/masterslave.py b/tiramisu/option/masterslave.py index 7f5e048..b47de82 100644 --- a/tiramisu/option/masterslave.py +++ b/tiramisu/option/masterslave.py @@ -230,10 +230,13 @@ class MasterSlaves(object): multi.append_properties_error(value) else: return value - else: + elif index is None: multi.append(value, setitem=False, force=True, validate=validate, force_permissive=force_permissive) one_has_value = True + else: + multi = value + one_has_value = True if not one_has_value: #raise last err if returns_raise: