当前位置: 首页>>代码示例>>Python>>正文


Python AttrDict.bravo方法代码示例

本文整理汇总了Python中attrdict.AttrDict.bravo方法的典型用法代码示例。如果您正苦于以下问题:Python AttrDict.bravo方法的具体用法?Python AttrDict.bravo怎么用?Python AttrDict.bravo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在attrdict.AttrDict的用法示例。


在下文中一共展示了AttrDict.bravo方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_default_dict

# 需要导入模块: from attrdict import AttrDict [as 别名]
# 或者: from attrdict.AttrDict import bravo [as 别名]
    def test_default_dict(self):
        """
        test attrdict's defaultdict support.
        """
        from attrdict import AttrDict

        self.assertRaises(KeyError, lambda: AttrDict()['foo'])
        self.assertRaises(AttributeError, lambda: AttrDict().foo)

        adict = AttrDict(default_factory=lambda: ('foo', 'bar', 'baz'))

        self.assertEqual(adict['foo'], ('foo', 'bar', 'baz'))
        self.assertEqual(adict('bar'), ('foo', 'bar', 'baz'))
        self.assertEqual(adict.baz, ('foo', 'bar', 'baz'))
        self.assertEqual(adict.get('lorem'), None)
        self.assertEqual(adict.get('ipsum', 'alpha'), 'alpha')

        # make sure this doesn't break access
        adict.bravo = 'charlie'

        self.assertEqual(adict['bravo'], 'charlie')
        self.assertEqual(adict('bravo'), 'charlie')
        self.assertEqual(adict.bravo, 'charlie')
        self.assertEqual(adict.get('bravo'), 'charlie')
        self.assertEqual(adict.get('bravo', 'alpha'), 'charlie')
开发者ID:explody,项目名称:AttrDict,代码行数:27,代码来源:tests.py

示例2: test_default_dict_pass_key

# 需要导入模块: from attrdict import AttrDict [as 别名]
# 或者: from attrdict.AttrDict import bravo [as 别名]
    def test_default_dict_pass_key(self):
        """
        test attrdict's defaultdict support.
        """
        from attrdict import AttrDict

        adict = AttrDict(default_factory=lambda foo: (foo, 'bar', 'baz'),
                         pass_key=True)

        self.assertEqual(adict['foo'], ('foo', 'bar', 'baz'))
        self.assertEqual(adict('bar'), ('bar', 'bar', 'baz'))
        self.assertEqual(adict.baz, ('baz', 'bar', 'baz'))
        self.assertEqual(adict.get('lorem'), None)
        self.assertEqual(adict.get('ipsum', 'alpha'), 'alpha')

        # make sure this doesn't break access
        adict.bravo = 'charlie'

        self.assertEqual(adict['bravo'], 'charlie')
        self.assertEqual(adict('bravo'), 'charlie')
        self.assertEqual(adict.bravo, 'charlie')
        self.assertEqual(adict.get('bravo'), 'charlie')
        self.assertEqual(adict.get('bravo', 'alpha'), 'charlie')
开发者ID:jtratner,项目名称:AttrDict,代码行数:25,代码来源:tests.py

示例3: test_default_dict_pass_key

# 需要导入模块: from attrdict import AttrDict [as 别名]
# 或者: from attrdict.AttrDict import bravo [as 别名]
    def test_default_dict_pass_key(self):
        """
        test attrdict's defaultdict support.
        """
        from attrdict import AttrDict

        adict = AttrDict(default_factory=lambda foo: (foo, 'bar', 'baz'),
                         pass_key=True)

        self.assertEqual(adict['foo'], ('foo', 'bar', 'baz'))
        self.assertEqual(adict('bar'), ('bar', 'bar', 'baz'))
        self.assertEqual(adict.baz, ('baz', 'bar', 'baz'))
        self.assertEqual(adict.get('lorem'), None)
        self.assertEqual(adict.get('ipsum', 'alpha'), 'alpha')

        # make sure this doesn't break access
        adict.bravo = 'charlie'

        self.assertEqual(adict['bravo'], 'charlie')
        self.assertEqual(adict('bravo'), 'charlie')
        self.assertEqual(adict.bravo, 'charlie')
        self.assertEqual(adict.get('bravo'), 'charlie')
        self.assertEqual(adict.get('bravo', 'alpha'), 'charlie')

        # make sure missing doesn't happen on hidden attributes
        adict = AttrDict(default_factory=lambda: 'default')

        self.assertEqual(adict.works, 'default')

        self.assertRaises(AttributeError, lambda: adict._hidden)
        self.assertEqual(adict.get('_hidden'), None)

        self.assertRaises(AttributeError, lambda: adict.__magic__)
        self.assertEqual(adict.get('__magic__'), None)

        # but this should work
        self.assertEqual(adict('_this_is_fine'), 'default')
开发者ID:explody,项目名称:AttrDict,代码行数:39,代码来源:tests.py


注:本文中的attrdict.AttrDict.bravo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。