add 'remove' to Multi
This commit is contained in:
parent
ac5bf93953
commit
026179d9b7
|
@ -1,3 +1,6 @@
|
|||
Wed May 17 22:11:55 2017 +0200 Emmanuel Garette <egarette@cadoles.com>
|
||||
* add 'remove' to Multi
|
||||
|
||||
Sun Feb 12 10:30:13 2017 +0200 Emmanuel Garette <egarette@cadoles.com>
|
||||
* error in external function should returns explicit error message
|
||||
all errors will be ConfigError
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue