2020-02-03 17:25:54 +00:00
|
|
|
import unittest
|
|
|
|
|
2022-10-14 14:53:06 +00:00
|
|
|
from benedict.core import remove as _remove
|
|
|
|
|
2020-02-03 17:25:54 +00:00
|
|
|
|
|
|
|
class remove_test_case(unittest.TestCase):
|
2022-02-13 10:35:43 +00:00
|
|
|
"""
|
|
|
|
This class describes a remove test case.
|
|
|
|
"""
|
2020-02-03 17:25:54 +00:00
|
|
|
|
|
|
|
def test_remove_with_single_key(self):
|
|
|
|
d = {
|
2022-02-13 10:35:43 +00:00
|
|
|
"a": 1,
|
|
|
|
"b": 2,
|
|
|
|
"c": 3,
|
2020-02-03 17:25:54 +00:00
|
|
|
}
|
2022-02-13 10:35:43 +00:00
|
|
|
_remove(d, "c")
|
2020-02-03 17:25:54 +00:00
|
|
|
r = {
|
2022-02-13 10:35:43 +00:00
|
|
|
"a": 1,
|
|
|
|
"b": 2,
|
2020-02-03 17:25:54 +00:00
|
|
|
}
|
|
|
|
self.assertEqual(d, r)
|
|
|
|
|
|
|
|
def test_remove_with_multiple_keys_as_args(self):
|
|
|
|
d = {
|
2022-02-13 10:35:43 +00:00
|
|
|
"a": 1,
|
|
|
|
"b": 2,
|
|
|
|
"c": 3,
|
|
|
|
"d": 4,
|
|
|
|
"e": 5,
|
2020-02-03 17:25:54 +00:00
|
|
|
}
|
2022-02-13 10:35:43 +00:00
|
|
|
_remove(d, "c", "d", "e")
|
2020-02-03 17:25:54 +00:00
|
|
|
r = {
|
2022-02-13 10:35:43 +00:00
|
|
|
"a": 1,
|
|
|
|
"b": 2,
|
2020-02-03 17:25:54 +00:00
|
|
|
}
|
|
|
|
self.assertEqual(d, r)
|
|
|
|
|
|
|
|
def test_remove_with_multiple_keys_as_list(self):
|
|
|
|
d = {
|
2022-02-13 10:35:43 +00:00
|
|
|
"a": 1,
|
|
|
|
"b": 2,
|
|
|
|
"c": 3,
|
|
|
|
"d": 4,
|
|
|
|
"e": 5,
|
2020-02-03 17:25:54 +00:00
|
|
|
}
|
2022-02-13 10:35:43 +00:00
|
|
|
_remove(d, ["c", "d", "e"])
|
2020-02-03 17:25:54 +00:00
|
|
|
r = {
|
2022-02-13 10:35:43 +00:00
|
|
|
"a": 1,
|
|
|
|
"b": 2,
|
2020-02-03 17:25:54 +00:00
|
|
|
}
|
|
|
|
self.assertEqual(d, r)
|