slave with requires could not raise 2.0
authorEmmanuel Garette <egarette@cadoles.com>
Wed, 12 Oct 2016 18:49:56 +0000 (20:49 +0200)
committerEmmanuel Garette <egarette@cadoles.com>
Wed, 12 Oct 2016 18:49:56 +0000 (20:49 +0200)
test/test_option_setting.py
test/test_requires.py
tiramisu/option/masterslave.py

index cf6914d..8bd6d14 100644 (file)
@@ -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)
index dace0ca..5395160 100644 (file)
@@ -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]")
index 7f5e048..b47de82 100644 (file)
@@ -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: