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


Python ConfigDict._set_fallback方法代码示例

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


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

示例1: test_fallback

# 需要导入模块: from bottle import ConfigDict [as 别名]
# 或者: from bottle.ConfigDict import _set_fallback [as 别名]
    def test_fallback(self):
        fallback = ConfigDict()
        fallback['key'] = 'fallback'
        primary = ConfigDict()
        primary._set_fallback(fallback)

        # Check copy of existing values from fallback to primary
        self.assertEqual(primary['key'], 'fallback')

        # Check value change in fallback
        fallback['key'] = 'fallback2'
        self.assertEqual(fallback['key'], 'fallback2')
        self.assertEqual(primary['key'], 'fallback2')

        # Check value change in primary
        primary['key'] = 'primary'
        self.assertEqual(fallback['key'], 'fallback2')
        self.assertEqual(primary['key'], 'primary')

        # Check delete of mirrored value in primary
        del primary['key']
        self.assertEqual(fallback['key'], 'fallback2')
        self.assertEqual(primary['key'], 'fallback2')

        # Check delete on mirrored key in fallback
        del fallback['key']
        self.assertTrue('key' not in primary)
        self.assertTrue('key' not in fallback)

        # Check new key in fallback
        fallback['key2'] = 'fallback'
        self.assertEqual(fallback['key2'], 'fallback')
        self.assertEqual(primary['key2'], 'fallback')

        # Check new key in primary
        primary['key3'] = 'primary'
        self.assertEqual(primary['key3'], 'primary')
        self.assertTrue('key3' not in fallback)

        # Check delete of primary-only key
        del primary['key3']
        self.assertTrue('key3' not in primary)
        self.assertTrue('key3' not in fallback)

        # Check delete of fallback value
        del fallback['key2']
        self.assertTrue('key2' not in primary)
        self.assertTrue('key2' not in fallback)
开发者ID:326029212,项目名称:bottle,代码行数:50,代码来源:test_config.py


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