Improved remove method to accept a single key or args.
This commit is contained in:
parent
3136b57fdb
commit
50c0439f9b
|
@ -93,7 +93,10 @@ class benedict(IODict, KeypathDict, ParseDict):
|
|||
for d in dicts:
|
||||
dict_util.merge(self, d)
|
||||
|
||||
def remove(self, keys):
|
||||
def remove(self, keys, *args):
|
||||
if isinstance(keys, string_types):
|
||||
keys = [keys]
|
||||
keys += args
|
||||
for key in keys:
|
||||
try:
|
||||
del self[key]
|
||||
|
|
|
@ -911,7 +911,21 @@ class BenedictTestCase(unittest.TestCase):
|
|||
self.assertEqual(b.pop('b.c'), 2)
|
||||
# self.assertTrue(isinstance(b.pop('b.d'), benedict))
|
||||
|
||||
def test_remove(self):
|
||||
def test_remove_with_key(self):
|
||||
d = {
|
||||
'a': 1,
|
||||
'b': 2,
|
||||
'c': '4',
|
||||
}
|
||||
b = benedict(d)
|
||||
b.remove('c')
|
||||
r = {
|
||||
'a': 1,
|
||||
'b': 2,
|
||||
}
|
||||
self.assertEqual(b, r)
|
||||
|
||||
def test_remove_with_keys_list(self):
|
||||
d = {
|
||||
'a': 1,
|
||||
'b': 2,
|
||||
|
@ -928,6 +942,23 @@ class BenedictTestCase(unittest.TestCase):
|
|||
}
|
||||
self.assertEqual(b, r)
|
||||
|
||||
def test_remove_with_keys_args(self):
|
||||
d = {
|
||||
'a': 1,
|
||||
'b': 2,
|
||||
'c': '4',
|
||||
'e': '5',
|
||||
'f': 6,
|
||||
'g': 7,
|
||||
}
|
||||
b = benedict(d)
|
||||
b.remove('c', 'e', 'f', 'g', 'x', 'y', 'z')
|
||||
r = {
|
||||
'a': 1,
|
||||
'b': 2,
|
||||
}
|
||||
self.assertEqual(b, r)
|
||||
|
||||
def test_remove_with_keypath(self):
|
||||
d = {
|
||||
'a': {
|
||||
|
|
Loading…
Reference in New Issue