diff --git a/ChangeLog b/ChangeLog index 882742f..4142405 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +Wed May 17 22:11:55 2017 +0200 Emmanuel Garette + * add 'remove' to Multi + Sun Feb 12 10:30:13 2017 +0200 Emmanuel Garette * error in external function should returns explicit error message all errors will be ConfigError diff --git a/test/test_parsing_group.py b/test/test_parsing_group.py index dc34954..9065608 100644 --- a/test/test_parsing_group.py +++ b/test/test_parsing_group.py @@ -263,6 +263,28 @@ def test_values_with_master_disabled_master(): raises(PropertiesOptionError, "cfg.ip_admin_eth0.netmask_admin_eth0[0] = '192.168.230.145'") +def test_values_with_master_remove(): + ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) + netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) + interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) + interface1.impl_set_group_type(groups.master) + maconfig = OptionDescription('toto', '', [interface1]) + cfg = Config(maconfig) + cfg.read_write() + cfg.ip_admin_eth0.ip_admin_eth0.append('192.168.230.145') + cfg.ip_admin_eth0.ip_admin_eth0.remove('192.168.230.145') + raises(ValueError, "cfg.ip_admin_eth0.ip_admin_eth0.remove('192.168.230.14')") + cfg.ip_admin_eth0.ip_admin_eth0.append('192.168.230.15') + cfg.ip_admin_eth0.netmask_admin_eth0[-1] = '255.255.255.0' + cfg.ip_admin_eth0.ip_admin_eth0.append('192.168.230.16') + cfg.ip_admin_eth0.netmask_admin_eth0[-1] = '255.255.255.128' + assert cfg.ip_admin_eth0.ip_admin_eth0 == ['192.168.230.15', '192.168.230.16'] + assert cfg.ip_admin_eth0.netmask_admin_eth0 == ['255.255.255.0', '255.255.255.128'] + cfg.ip_admin_eth0.ip_admin_eth0.remove('192.168.230.15') + assert cfg.ip_admin_eth0.ip_admin_eth0 == ['192.168.230.16'] + assert cfg.ip_admin_eth0.netmask_admin_eth0 == ['255.255.255.128'] + + def test_master_not_valid_name(): ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) diff --git a/tiramisu/value.py b/tiramisu/value.py index 4faa0ef..8406071 100644 --- a/tiramisu/value.py +++ b/tiramisu/value.py @@ -924,6 +924,10 @@ class Multi(list): self._store(force=force) return ret + def remove(self, value): + idx = self.index(value) + return self.pop(idx) + def _store(self, force=False, index=None): values = self._getcontext().cfgimpl_get_values() if not force: