本文整理汇总了Python中indico.core.settings.SettingsProxy.get方法的典型用法代码示例。如果您正苦于以下问题:Python SettingsProxy.get方法的具体用法?Python SettingsProxy.get怎么用?Python SettingsProxy.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类indico.core.settings.SettingsProxy
的用法示例。
在下文中一共展示了SettingsProxy.get方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_proxy_defaults
# 需要导入模块: from indico.core.settings import SettingsProxy [as 别名]
# 或者: from indico.core.settings.SettingsProxy import get [as 别名]
def test_proxy_defaults():
proxy = SettingsProxy('test', {'hello': 'world', 'foo': None})
assert proxy.get('hello') == 'world'
assert proxy.get('foo') is None
assert proxy.get('foo', 'bar') == 'bar'
assert not proxy.get_all(True)
proxy.set('foo', 'bar')
assert proxy.get_all(True) == {'foo': 'bar'}
assert proxy.get_all() == {'hello': 'world', 'foo': 'bar'}
示例2: test_proxy_preload
# 需要导入模块: from indico.core.settings import SettingsProxy [as 别名]
# 或者: from indico.core.settings.SettingsProxy import get [as 别名]
def test_proxy_preload(count_queries):
defaults = {'hello': 'world', 'foo': None, 'bar': None}
proxy = SettingsProxy('test', defaults)
proxy.set('bar', 'test')
with count_queries() as cnt:
# this one preloads
assert proxy.get('hello') == 'world'
assert cnt() == 1
with count_queries() as cnt:
# this one has no value in the db
assert proxy.get('foo') is None
assert proxy.get('foo', 'bar') == 'bar'
assert cnt() == 0
with count_queries() as cnt:
assert proxy.get('bar') is 'test'
assert cnt() == 0
示例3: test_proxy_strict
# 需要导入模块: from indico.core.settings import SettingsProxy [as 别名]
# 或者: from indico.core.settings.SettingsProxy import get [as 别名]
def test_proxy_strict():
proxy = SettingsProxy('test', {'hello': 'world'})
pytest.raises(ValueError, proxy.get, 'foo')
pytest.raises(ValueError, proxy.get, 'foo', 'bar')
pytest.raises(ValueError, proxy.set, 'foo', 'foobar')
pytest.raises(ValueError, proxy.set_multi, {'hello': 'world', 'foo': 'foobar'})
pytest.raises(ValueError, proxy.delete, 'hello', 'foo')
assert proxy.get('hello') == 'world'
示例4: test_proxy_strict_off
# 需要导入模块: from indico.core.settings import SettingsProxy [as 别名]
# 或者: from indico.core.settings.SettingsProxy import get [as 别名]
def test_proxy_strict_off():
proxy = SettingsProxy('test', {}, False)
assert proxy.get('foo') is None
proxy.get('foo', 'bar') == 'bar'
proxy.set('foo', 'foobar')
assert proxy.get('foo') == 'foobar'
示例5: test_proxy_cache_mutable
# 需要导入模块: from indico.core.settings import SettingsProxy [as 别名]
# 或者: from indico.core.settings.SettingsProxy import get [as 别名]
def test_proxy_cache_mutable():
proxy = SettingsProxy('test', {'foo': []})
foo = proxy.get('foo')
assert foo is not proxy.defaults['foo']
foo.append('test')
assert not proxy.get('foo')