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