本文整理汇总了Python中everett.manager.ConfigManager.from_dict方法的典型用法代码示例。如果您正苦于以下问题:Python ConfigManager.from_dict方法的具体用法?Python ConfigManager.from_dict怎么用?Python ConfigManager.from_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类everett.manager.ConfigManager
的用法示例。
在下文中一共展示了ConfigManager.from_dict方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_config_from_dict
# 需要导入模块: from everett.manager import ConfigManager [as 别名]
# 或者: from everett.manager.ConfigManager import from_dict [as 别名]
def test_config_from_dict():
config = ConfigManager.from_dict({})
assert config('FOO', raise_error=False) is NO_VALUE
config = ConfigManager.from_dict({
'FOO': 'bar'
})
assert config('FOO', raise_error=False) == 'bar'
示例2: pytest_runtest_setup
# 需要导入模块: from everett.manager import ConfigManager [as 别名]
# 或者: from everett.manager.ConfigManager import from_dict [as 别名]
def pytest_runtest_setup():
# Make sure we set up logging and metrics to sane default values.
setup_logging(ConfigManager.from_dict({
'HOST_ID': '',
'LOGGING_LEVEL': 'DEBUG',
}))
setup_metrics(metrics.LoggingMetrics, ConfigManager.from_dict({}))
# Wipe any registered heartbeat functions
reset_hb_funs()
示例3: test_parse_class_config
# 需要导入模块: from everett.manager import ConfigManager [as 别名]
# 或者: from everett.manager.ConfigManager import from_dict [as 别名]
def test_parse_class_config():
config = ConfigManager.from_dict({
'foo_cls': 'hashlib.doesnotexist',
'bar_cls': 'doesnotexist.class',
})
with pytest.raises(InvalidValueError) as exc_info:
config('foo_cls', parser=parse_class)
assert (
str(exc_info.value) ==
'ValueError: "doesnotexist" is not a valid member of hashlib\n'
'namespace=None key=foo_cls requires a value parseable by everett.manager.parse_class'
)
with pytest.raises(InvalidValueError) as exc_info:
config('bar_cls', parser=parse_class)
assert (
str(exc_info.value) in
[
# Python 3
'ImportError: No module named \'doesnotexist\'\n'
'namespace=None key=bar_cls requires a value parseable by everett.manager.parse_class',
# Python 3.6
'ModuleNotFoundError: No module named \'doesnotexist\'\n'
'namespace=None key=bar_cls requires a value parseable by everett.manager.parse_class'
]
)
示例4: test_timing
# 需要导入模块: from everett.manager import ConfigManager [as 别名]
# 或者: from everett.manager.ConfigManager import from_dict [as 别名]
def test_timing(self):
metrics.metrics_configure(metrics.DogStatsdMetrics, ConfigManager.from_dict({}))
mymetrics = metrics.get_metrics('foobar')
with patch.object(metrics._metrics_impl.client, 'timing') as mock_timing:
mymetrics.timing('key1', 1000)
mock_timing.assert_called_with(metric='foobar.key1', value=1000)
示例5: test_nested_options
# 需要导入模块: from everett.manager import ConfigManager [as 别名]
# 或者: from everett.manager.ConfigManager import from_dict [as 别名]
def test_nested_options():
"""Verify nested BoundOptions works."""
config = ConfigManager.from_dict({})
class Foo(RequiredConfigMixin):
required_config = ConfigOptions()
required_config.add_option(
'option1',
default='opt1default',
parser=str
)
class Bar(RequiredConfigMixin):
required_config = ConfigOptions()
required_config.add_option(
'option2',
default='opt2default',
parser=str
)
config = ConfigManager.basic_config()
config = config.with_options(Foo)
config = config.with_options(Bar)
assert config('option2') == 'opt2default'
with pytest.raises(ConfigurationError):
config('option1')
示例6: test_is_thunderbird_seamonkey
# 需要导入模块: from everett.manager import ConfigManager [as 别名]
# 或者: from everett.manager.ConfigManager import from_dict [as 别名]
def test_is_thunderbird_seamonkey(self, product):
raw_crash = {
'ProductName': product
}
throttler = Throttler(ConfigManager.from_dict({}))
assert throttler.throttle(raw_crash) == (ACCEPT, 'is_thunderbird_seamonkey', 100)
示例7: test_gauge
# 需要导入模块: from everett.manager import ConfigManager [as 别名]
# 或者: from everett.manager.ConfigManager import from_dict [as 别名]
def test_gauge(self):
metrics.metrics_configure(metrics.DogStatsdMetrics, ConfigManager.from_dict({}))
mymetrics = metrics.get_metrics('foobar')
with patch.object(metrics._metrics_impl.client, 'gauge') as mock_gauge:
mymetrics.gauge('key1', 5)
mock_gauge.assert_called_with(metric='foobar.key1', value=5)
示例8: test_doc
# 需要导入模块: from everett.manager import ConfigManager [as 别名]
# 或者: from everett.manager.ConfigManager import from_dict [as 别名]
def test_doc():
config = ConfigManager.from_dict({
'FOO_BAR': 'bat'
})
class SomeComponent(RequiredConfigMixin):
required_config = ConfigOptions()
required_config.add_option(
'foo_bar',
parser=int,
doc='omg!'
)
def __init__(self, config):
self.config = config.with_options(self)
comp = SomeComponent(config)
try:
# This throws an exception becase "bat" is not an int
comp.config('foo_bar')
except Exception as exc:
# We're going to lazily assert that omg! is in exc msg because if it
# is, it came from the option and that's what we want to know.
assert 'omg!' in str(exc)
示例9: test_incr
# 需要导入模块: from everett.manager import ConfigManager [as 别名]
# 或者: from everett.manager.ConfigManager import from_dict [as 别名]
def test_incr(self):
metrics.metrics_configure(metrics.DogStatsdMetrics, ConfigManager.from_dict({}))
mymetrics = metrics.get_metrics('foobar')
with patch.object(metrics._metrics_impl.client, 'increment') as mock_incr:
mymetrics.incr('key1')
mock_incr.assert_called_with(metric='foobar.key1', value=1)
示例10: test_get_namespace
# 需要导入模块: from everett.manager import ConfigManager [as 别名]
# 或者: from everett.manager.ConfigManager import from_dict [as 别名]
def test_get_namespace():
config = ConfigManager.from_dict({
'FOO': 'abc',
'FOO_BAR': 'abc',
'FOO_BAR_BAZ': 'abc',
})
assert config.get_namespace() == []
class SomeComponent(RequiredConfigMixin):
required_config = ConfigOptions()
required_config.add_option(
'foo',
parser=int
)
def __init__(self, config):
self.config = config.with_options(self)
def my_namespace_is(self):
return self.config.get_namespace()
comp = SomeComponent(config)
assert comp.my_namespace_is() == []
comp = SomeComponent(config.with_namespace('foo'))
assert comp.my_namespace_is() == ['foo']
示例11: test_raw_value
# 需要导入模块: from everett.manager import ConfigManager [as 别名]
# 或者: from everett.manager.ConfigManager import from_dict [as 别名]
def test_raw_value():
config = ConfigManager.from_dict({
'FOO_BAR': '1'
})
class SomeComponent(RequiredConfigMixin):
required_config = ConfigOptions()
required_config.add_option(
'foo_bar',
parser=int
)
def __init__(self, config):
self.config = config.with_options(self)
comp = SomeComponent(config)
assert comp.config('foo_bar') == 1
assert comp.config('foo_bar', raw_value=True) == '1'
class SomeComponent(RequiredConfigMixin):
required_config = ConfigOptions()
required_config.add_option('bar', parser=int)
def __init__(self, config):
self.config = config.with_options(self)
comp = SomeComponent(config.with_namespace('foo'))
assert comp.config('bar') == 1
assert comp.config('bar', raw_value=True) == '1'
示例12: test_is_fennec
# 需要导入模块: from everett.manager import ConfigManager [as 别名]
# 或者: from everett.manager.ConfigManager import from_dict [as 别名]
def test_is_fennec(self):
raw_crash = {
'ProductName': 'Fennec'
}
throttler = Throttler(ConfigManager.from_dict({}))
assert throttler.throttle(raw_crash) == (ACCEPT, 'is_fennec', 100)
示例13: test_is_firefox
# 需要导入模块: from everett.manager import ConfigManager [as 别名]
# 或者: from everett.manager.ConfigManager import from_dict [as 别名]
def test_is_firefox(self, randommock):
with randommock(0.09):
raw_crash = {
'ProductName': 'Firefox',
}
throttler = Throttler(ConfigManager.from_dict({}))
assert throttler.throttle(raw_crash) == (ACCEPT, 'is_firefox_desktop', 10)
with randommock(0.9):
raw_crash = {
'ProductName': 'Firefox',
}
throttler = Throttler(ConfigManager.from_dict({}))
assert throttler.throttle(raw_crash) == (DEFER, 'is_firefox_desktop', 10)
示例14: test_alternate_keys
# 需要导入模块: from everett.manager import ConfigManager [as 别名]
# 或者: from everett.manager.ConfigManager import from_dict [as 别名]
def test_alternate_keys(key, alternate_keys, expected):
config = ConfigManager.from_dict({
'FOO': 'foo_abc',
'FOO_BAR': 'foo_bar_abc',
'FOO_BAR_BAZ': 'foo_bar_baz_abc',
})
assert config(key, alternate_keys=alternate_keys) == expected
示例15: test_is_nightly
# 需要导入模块: from everett.manager import ConfigManager [as 别名]
# 或者: from everett.manager.ConfigManager import from_dict [as 别名]
def test_is_nightly(self, channel):
raw_crash = {
'ProductName': 'Test',
'ReleaseChannel': channel
}
throttler = Throttler(ConfigManager.from_dict({}))
assert throttler.throttle(raw_crash) == (ACCEPT, 'is_nightly', 100)