support delitem for Multi

This commit is contained in:
Emmanuel Garette 2017-03-17 21:27:42 +01:00
parent 6bf7e309c6
commit ac6ea1e7e4
2 changed files with 15 additions and 1 deletions

View file

@ -227,7 +227,8 @@ def test_get_modified_values():
g3 = UnicodeOption('g3', '', u'héhé')
g4 = BoolOption('g4', '', True)
g5 = StrOption('g5', '')
d1 = OptionDescription('od', '', [g1, g2, g3, g4, g5])
g6 = StrOption('g6', '', multi=True)
d1 = OptionDescription('od', '', [g1, g2, g3, g4, g5, g6])
root = OptionDescription('root', '', [d1])
config = Config(root)
assert config.cfgimpl_get_values().get_modified_values() == {}
@ -235,6 +236,16 @@ def test_get_modified_values():
assert config.cfgimpl_get_values().get_modified_values() == {'od.g5': ('user', 'yes')}
config.od.g4 = True
assert config.cfgimpl_get_values().get_modified_values() == {'od.g5': ('user', 'yes'), 'od.g4': ('user', True)}
del config.od.g4
assert config.cfgimpl_get_values().get_modified_values() == {'od.g5': ('user', 'yes')}
config.od.g6.append()
assert config.cfgimpl_get_values().get_modified_values() == {'od.g5': ('user', 'yes'), 'od.g6': ('user', (None,))}
config.od.g6.pop(0)
assert config.cfgimpl_get_values().get_modified_values() == {'od.g5': ('user', 'yes'), 'od.g6': ('user', tuple())}
config.od.g6.append('3')
assert config.cfgimpl_get_values().get_modified_values() == {'od.g5': ('user', 'yes'), 'od.g6': ('user', ('3',))}
del config.od.g6[0]
assert config.cfgimpl_get_values().get_modified_values() == {'od.g5': ('user', 'yes'), 'od.g6': ('user', tuple())}
def test_has_value():

View file

@ -787,6 +787,9 @@ class Multi(list):
raise value
return value
def __delitem__(self, index):
return self.pop(index)
def _getdefaultvalue(self, index):
values = self._getcontext().cfgimpl_get_values()
value = values._getdefaultvalue(self.opt, self.path, True, index,