-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_forget.py
More file actions
35 lines (29 loc) · 1.6 KB
/
test_forget.py
File metadata and controls
35 lines (29 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from arrayutilities import Arr
import unittest
class TestArr(unittest.TestCase):
def test_forget_flat_key(self):
test_dict = {'a': 1, 'b': 2, 'c': 3}
Arr.forget(test_dict, 'b')
self.assertNotIn('b', test_dict, "Key 'b' should be removed from the dictionary")
def test_forget_nested_key(self):
test_dict = {'a': 1, 'b': {'c': 2, 'd': 3}}
Arr.forget(test_dict, 'b.c')
self.assertNotIn('c', test_dict['b'], "Nested key 'c' should be removed from dictionary under 'b'")
def test_forget_non_existent_key(self):
test_dict = {'a': 1, 'b': 2}
Arr.forget(test_dict, 'c')
self.assertIn('a', test_dict, "Existing keys should remain unchanged when non-existent key is specified")
self.assertIn('b', test_dict, "Existing keys should remain unchanged when non-existent key is specified")
def test_forget_multiple_keys(self):
test_dict = {'a': 1, 'b': 2, 'c': {'d': 3, 'e': 4}}
Arr.forget(test_dict, ['a', 'c.d'])
self.assertNotIn('a', test_dict, "Key 'a' should be removed")
self.assertNotIn('d', test_dict['c'], "Nested key 'd' should be removed under 'c'")
self.assertIn('e', test_dict['c'], "Key 'e' under 'c' should remain")
def test_forget_empty_keys_list(self):
test_dict = {'a': 1, 'b': 2}
Arr.forget(test_dict, [])
self.assertIn('a', test_dict, "Dictionary should remain unchanged when empty key list is provided")
self.assertIn('b', test_dict, "Dictionary should remain unchanged when empty key list is provided")
if __name__ == '__main__':
unittest.main()