test_context.py 文件源码

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

项目:charm-helpers 作者: juju 项目源码 文件源码
def test_relationinfo_local(self):
        r = context.RelationInfo('rel:10', hookenv.local_unit())

        # Updates work, with standard strings.
        r[sentinel.key] = 'value'
        hookenv.relation_set.assert_called_once_with(
            'rel:10', {sentinel.key: 'value'})

        # Python 2 unicode strings work too.
        hookenv.relation_set.reset_mock()
        r[sentinel.key] = six.u('value')
        hookenv.relation_set.assert_called_once_with(
            'rel:10', {sentinel.key: six.u('value')})

        # Byte strings fail under Python 3.
        if six.PY3:
            with self.assertRaises(ValueError):
                r[sentinel.key] = six.b('value')

        # Deletes work
        del r[sentinel.key]
        hookenv.relation_set.assert_called_with('rel:10', {sentinel.key: None})

        # Attempting to write a non-string fails
        with self.assertRaises(ValueError):
            r[sentinel.key] = 42
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号