本文整理汇总了Python中indico.core.settings.SettingsProxy.set方法的典型用法代码示例。如果您正苦于以下问题:Python SettingsProxy.set方法的具体用法?Python SettingsProxy.set怎么用?Python SettingsProxy.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类indico.core.settings.SettingsProxy
的用法示例。
在下文中一共展示了SettingsProxy.set方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_proxy_delete_all
# 需要导入模块: from indico.core.settings import SettingsProxy [as 别名]
# 或者: from indico.core.settings.SettingsProxy import set [as 别名]
def test_proxy_delete_all():
defaults = {'hello': 'world', 'foo': None}
proxy = SettingsProxy('test', defaults)
assert proxy.get_all() == defaults
proxy.set('hello', 'test')
assert proxy.get_all() == {'hello': 'test', 'foo': None}
proxy.delete_all()
assert proxy.get_all() == defaults
示例2: test_proxy_defaults
# 需要导入模块: from indico.core.settings import SettingsProxy [as 别名]
# 或者: from indico.core.settings.SettingsProxy import set [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'}
示例3: test_proxy_converters_all
# 需要导入模块: from indico.core.settings import SettingsProxy [as 别名]
# 或者: from indico.core.settings.SettingsProxy import set [as 别名]
def test_proxy_converters_all():
epoch_dt = datetime(1970, 1, 1, tzinfo=pytz.utc)
xmas_dt = datetime(2016, 12, 24, 20, tzinfo=pytz.utc)
newyear_dt = datetime(2017, 1, 2, tzinfo=pytz.utc)
duration = timedelta(days=2)
defaults = {'epoch': epoch_dt, 'xmas': None, 'newyear': None, 'duration': None}
converters = {name: DatetimeConverter if name != 'duration' else TimedeltaConverter for name in defaults}
proxy = SettingsProxy('test', defaults, converters=converters)
proxy.set('xmas', xmas_dt)
proxy.set_multi({'newyear': newyear_dt, 'duration': duration})
assert proxy.get_all() == {'epoch': epoch_dt, 'xmas': xmas_dt, 'newyear': newyear_dt, 'duration': duration}
示例4: test_proxy_preload
# 需要导入模块: from indico.core.settings import SettingsProxy [as 别名]
# 或者: from indico.core.settings.SettingsProxy import set [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
示例5: test_proxy_strict_off
# 需要导入模块: from indico.core.settings import SettingsProxy [as 别名]
# 或者: from indico.core.settings.SettingsProxy import set [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'