當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。