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


Python ConfigDict._make_overlay方法代码示例

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


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

示例1: test_gc_overlays

# 需要导入模块: from bottle import ConfigDict [as 别名]
# 或者: from bottle.ConfigDict import _make_overlay [as 别名]
 def test_gc_overlays(self):
     root = ConfigDict()
     overlay = root._make_overlay()
     del overlay
     import gc; gc.collect()
     root._make_overlay()  # This triggers the weakref-collect
     self.assertEqual(len(root._overlays), 1)
开发者ID:sideffect0,项目名称:bottle,代码行数:9,代码来源:test_config.py

示例2: test_overlay

# 需要导入模块: from bottle import ConfigDict [as 别名]
# 或者: from bottle.ConfigDict import _make_overlay [as 别名]
    def test_overlay(self):
        source = ConfigDict()
        source['key'] = 'source'
        intermediate = source._make_overlay()
        overlay = intermediate._make_overlay()

        # Overlay contains values from source
        self.assertEqual(overlay['key'], 'source')
        self.assertEqual(overlay.get('key'), 'source')
        self.assertTrue('key' in overlay)

        # Overlay is updated with source
        source['key'] = 'source2'
        self.assertEqual(source['key'], 'source2')
        self.assertEqual(overlay['key'], 'source2')

        # Overlay 'overlays' source (hence the name)
        overlay['key'] = 'overlay'
        self.assertEqual(source['key'], 'source2')
        self.assertEqual(intermediate['key'], 'source2')
        self.assertEqual(overlay['key'], 'overlay')

        # Deleting an overlayed key restores the value from source
        del overlay['key']
        self.assertEqual(source['key'], 'source2')
        self.assertEqual(overlay['key'], 'source2')

        # Deleting a virtual key is actually not possible.
        with self.assertRaises(KeyError):
            del overlay['key']

        # Deleting a key in the source also removes it from overlays.
        del source['key']
        self.assertTrue('key' not in overlay)
        self.assertTrue('key' not in intermediate)
        self.assertTrue('key' not in source)

        # New keys in source are copied to overlay
        source['key2'] = 'source'
        self.assertEqual(source['key2'], 'source')
        self.assertEqual(intermediate['key2'], 'source')
        self.assertEqual(overlay['key2'], 'source')

        # New keys in overlay do not change the source
        overlay['key3'] = 'overlay'
        self.assertEqual(overlay['key3'], 'overlay')
        self.assertTrue('key3' not in intermediate)
        self.assertTrue('key3' not in source)

        # Setting the same key in the source does not affect the overlay
        # because it already has this key.
        source['key3'] = 'source'
        self.assertEqual(source['key3'], 'source')
        self.assertEqual(intermediate['key3'], 'source')
        self.assertEqual(overlay['key3'], 'overlay')

        # But as soon as the overlayed key is deleted, it gets the
        # copy from the source
        del overlay['key3']
        self.assertEqual(source['key3'], 'source')
        self.assertEqual(overlay['key3'], 'source')
开发者ID:sideffect0,项目名称:bottle,代码行数:63,代码来源:test_config.py


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