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


Python manager.ConfigManager类代码示例

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


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

示例1: test_nested_options

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')
开发者ID:willkg,项目名称:everett,代码行数:27,代码来源:test_component.py

示例2: main

def main(args):
    # Build configuration object just like we do in Antenna.
    config = ConfigManager([
        # Pull configuration from env file specified as ANTENNA_ENV
        ConfigEnvFileEnv([os.environ.get('ANTENNA_ENV')]),

        # Pull configuration from environment variables
        ConfigOSEnv()
    ])

    # We create it in the crashstorage namespace because that's how Antenna
    # uses it. This makes it easier to use existing configuration.
    conn = S3Connection(config.with_namespace('crashstorage'), no_verify=True)

    # First, check to see if the bucket is already created.
    try:
        print('Checking to see if bucket "%s" exists...' % conn.bucket)
        conn.verify_configuration()
        print('Bucket exists.')

    except ClientError as exc:
        print(str(exc))
        if 'HeadBucket operation: Not Found' in str(exc):
            print('Bucket not found. Creating %s ...' % conn.bucket)
            # Create the bucket.
            conn._create_bucket()
            print('Bucket created.')
        else:
            raise
开发者ID:willkg,项目名称:antenna,代码行数:29,代码来源:create_s3_bucket.py

示例3: test_config_from_dict

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'
开发者ID:willkg,项目名称:everett,代码行数:10,代码来源:test_manager.py

示例4: pytest_runtest_setup

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()
开发者ID:willkg,项目名称:antenna,代码行数:10,代码来源:conftest.py

示例5: test_parse_class_config

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'
        ]
    )
开发者ID:willkg,项目名称:everett,代码行数:27,代码来源:test_manager.py

示例6: test_is_fennec

    def test_is_fennec(self):
        raw_crash = {
            'ProductName': 'Fennec'
        }

        throttler = Throttler(ConfigManager.from_dict({}))
        assert throttler.throttle(raw_crash) == (ACCEPT, 'is_fennec', 100)
开发者ID:willkg,项目名称:antenna,代码行数:7,代码来源:test_throttler.py

示例7: test_timing

    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)
开发者ID:willkg,项目名称:antenna,代码行数:7,代码来源:test_metrics.py

示例8: test_is_firefox

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

示例9: test_gauge

    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)
开发者ID:willkg,项目名称:antenna,代码行数:7,代码来源:test_metrics.py

示例10: test_incr

    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)
开发者ID:willkg,项目名称:antenna,代码行数:7,代码来源:test_metrics.py

示例11: test_is_thunderbird_seamonkey

    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)
开发者ID:willkg,项目名称:antenna,代码行数:7,代码来源:test_throttler.py

示例12: test_get_namespace

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']
开发者ID:willkg,项目名称:everett,代码行数:26,代码来源:test_component.py

示例13: test_raw_value

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'
开发者ID:willkg,项目名称:everett,代码行数:31,代码来源:test_component.py

示例14: test_doc

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)
开发者ID:willkg,项目名称:everett,代码行数:25,代码来源:test_component.py

示例15: test_is_nightly

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


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