def test_work_with_not_dotty_dict_like_objects(self):
# Assume dict-like objects does not support dot notation
self.dotty['already.exist.custom'] = UserDict({
'not_dotty': {
'user_dict': 'I am deeply nested user dict value'
}
})
# Accessing not existing key from dict-like object should raise KeyError
self.assertRaises(KeyError, self.dotty['already.exist.custom.key_value'])
# One can access not Dotty dict-like object with dot notation
self.assertEqual(self.dotty['already.exist.custom.not_dotty.user_dict'],
'I am deeply nested user dict value')
# one can add new key to not dotty dict-like object with dot notation
self.dotty['already.exist.custom.not_dotty.new_key'] = 'new key inside not dotty dict'
self.assertEqual(
self.dotty['already.exist.custom'],
{
'not_dotty': {
'user_dict': 'I am deeply nested user dict value',
'new_key': 'new key inside not dotty dict',
}
}
)
评论列表
文章目录