当前位置: 首页>>代码示例>>Python>>正文


Python settings.SettingsProxy类代码示例

本文整理汇总了Python中indico.core.settings.SettingsProxy的典型用法代码示例。如果您正苦于以下问题:Python SettingsProxy类的具体用法?Python SettingsProxy怎么用?Python SettingsProxy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了SettingsProxy类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_delete_propagate

def test_delete_propagate(mocker):
    Setting = mocker.patch('indico.core.settings.core.Setting')
    SettingPrincipal = mocker.patch('indico.core.settings.core.SettingPrincipal')
    proxy = SettingsProxy('foo', {'reg': None}, acls={'acl'})
    proxy.delete('reg', 'acl')
    Setting.delete.assert_called_once_with('foo', 'reg')
    SettingPrincipal.delete.assert_called_with('foo', 'acl')
开发者ID:,项目名称:,代码行数:7,代码来源:

示例2: test_proxy_strict

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'
开发者ID:,项目名称:,代码行数:8,代码来源:

示例3: test_set_multi_propagate

def test_set_multi_propagate(mocker):
    Setting = mocker.patch('indico.core.settings.core.Setting')
    SettingPrincipal = mocker.patch('indico.core.settings.core.SettingPrincipal')
    proxy = SettingsProxy('foo', {'reg': None}, acls={'acl'})
    proxy.set_multi({
        'reg': 'bar',
        'acl': {'u'}
    })
    Setting.set_multi.assert_called_once_with('foo', {'reg': 'bar'})
    SettingPrincipal.set_acl_multi.assert_called_with('foo', {'acl': {'u'}})
开发者ID:,项目名称:,代码行数:10,代码来源:

示例4: test_proxy_defaults

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'}
开发者ID:,项目名称:,代码行数:9,代码来源:

示例5: test_proxy_delete_all

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
开发者ID:,项目名称:,代码行数:8,代码来源:

示例6: test_proxy_converters_all

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}
开发者ID:,项目名称:,代码行数:11,代码来源:

示例7: test_proxy_preload

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
开发者ID:,项目名称:,代码行数:16,代码来源:

示例8: test_proxy_strict_off

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'
开发者ID:,项目名称:,代码行数:6,代码来源:

示例9: test_get_all_acls

def test_get_all_acls():
    proxy = SettingsProxy('foo', {'reg': None}, acls={'acl'})
    assert proxy.get_all() == {'reg': None, 'acl': set()}
开发者ID:,项目名称:,代码行数:3,代码来源:

示例10: test_proxy_cache_mutable

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')
开发者ID:,项目名称:,代码行数:6,代码来源:


注:本文中的indico.core.settings.SettingsProxy类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。