test_dotty_dict.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:dotty_dict 作者: pawelzny 项目源码 文件源码
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',
                }
            }
        )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号