本文整理汇总了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)