本文整理匯總了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)