Enforced BaseDict pointer tests.

This commit is contained in:
Fabio Caccamo 2020-09-23 10:19:13 +02:00
parent 722000bec0
commit a7301ee1f8
2 changed files with 36 additions and 1 deletions

View File

@ -46,7 +46,8 @@ SERVER:
# @unittest.skip('testing copy and pointers failure')
def test_pointers_with_benedict_casting(self):
servers = benedict(self.load_dict())
d = self.load_dict()
servers = benedict(d)
s01_ptr=servers['SERVER.S01']
self.assertTrue(isinstance(s01_ptr, benedict))
self.assertEqual(type(s01_ptr), benedict)
@ -54,3 +55,20 @@ SERVER:
s01_ptr['location']['building']='ptr_building'
s01_ptr['credentials']['username']='ptr_unsername'
self.assertEqual(s01_ptr, servers['SERVER.S01'])
# @unittest.skip('testing copy and pointers failure')
def test_pointers_after_pointer_update(self):
d = self.load_dict()
b = benedict(d)
d['SERVER']['S01']['alias'] = 'new_alias'
d['SERVER_2'] = 'server_2'
self.assertEqual(b, d)
self.assertEqual(b.dict(), d)
# @unittest.skip('testing copy and pointers failure')
def test_pointers_after_pointer_clear(self):
d = self.load_dict()
b = benedict(d)
d.clear()
self.assertEqual(b, d)
self.assertEqual(b.dict(), d)

View File

@ -27,3 +27,20 @@ class github_issue_0034_test_case(unittest.TestCase):
})
dumped = json.dumps(b, sort_keys=True)
self.assertEqual(dumped, '{"a": 1, "b": {"c": {"d": 2}}}')
def test_json_dumps_after_pointer_update(self):
d = {
'a': 1,
'b': {
'c': {
'd': 2,
},
},
}
b = benedict(d)
d['a'] = 2
d['b']['c']['d'] = 3
self.assertEqual(d, b.dict())
self.assertEqual(b, b.dict())
dumped = json.dumps(b, sort_keys=True)
self.assertEqual(dumped, '{"a": 2, "b": {"c": {"d": 3}}}')