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


Python configure.Configuration类代码示例

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


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

示例1: test_ref

def test_ref():
    src_yaml = """
    foo: bar
    ref_foo: !ref:foo
    """

    src = Configuration.from_string(src_yaml)
    print_yaml("yaml for src", src)
    assert src.ref_foo == src.foo

    missing_ref_yaml = """
    foo: bar
    ref_foo: !ref:bar
    """

    raised_key_error = True
    with pytest.raises(KeyError):
        Configuration.from_string(missing_ref_yaml)
        raised_key_error = False
    assert raised_key_error
    logger.debug("Raised KeyError")

    # use previous context ...
    ref_src_foo_yaml = """
    ref_src_foo:  !ref:foo
    """
    ref_src_foo = Configuration.from_string(ref_src_foo_yaml, configure=False)
    merged = deepcopy(src).merge(ref_src_foo)
    merged.configure()
    print_yaml("yaml that refs src", merged)
开发者ID:pcaruana,项目名称:khaleesi,代码行数:30,代码来源:test_configure.py

示例2: test_overwrite_tag

def test_overwrite_tag():
    src_yaml = """
    foo: bar
    """

    overwrite_fail_yaml = """
    foo: [1, 2, 3]
    """
    src = Configuration.from_string(src_yaml)
    print_yaml("Src", src)

    overwrite_fail = Configuration.from_string(overwrite_fail_yaml)
    print_yaml("Overwrite fail", overwrite_fail)

    error_raised = True
    with pytest.raises(ConfigurationError):
        logger.debug("Going to merge configs that should fail")
        merged = deepcopy(src).merge(overwrite_fail)
        logger.critical("You should never see this")
        error_raised = False
    assert error_raised
    logger.debug("Raised ConfigurationError")
    assert src.foo == 'bar'

    # ### use overwrite to overwrite src.foo
    overwrite_yaml = """
    foo: !overwrite [1, 2, 3]
    """
    overwrite = Configuration.from_string(overwrite_yaml)
    print_yaml("Overwrite", overwrite)

    merged = deepcopy(src).merge(overwrite)
    print_yaml("Merged", merged)
开发者ID:pcaruana,项目名称:khaleesi,代码行数:33,代码来源:test_configure.py

示例3: test_lookup

def test_lookup():
    src_yaml = """
    foo: bar
    ref_foo: !lookup foo
    """

    src = Configuration.from_string(src_yaml, configure=False)
    from ksgen.yaml_utils import LookupDirective
    LookupDirective.lookup_table = src
    print_yaml("yaml for src", src)

    # use previous context ...
    ref_src_foo_yaml = """
    ref_src_foo:  !lookup foo
    missing_lookup: !lookup non.existent.key
    """
    ref_src_foo = Configuration.from_string(ref_src_foo_yaml, configure=False)
    merged = deepcopy(src).merge(ref_src_foo)
    LookupDirective.lookup_table = merged
    print_yaml("yaml that refs src", merged)

    import yaml
    final_config = Configuration.from_string(yaml.safe_dump(merged))
    print_yaml("yaml that refs src", final_config)
    assert final_config.ref_foo == src.foo
    assert final_config.ref_src_foo == src.foo
    assert final_config.missing_lookup == '{{ non.existent.key }}'
开发者ID:pcaruana,项目名称:khaleesi,代码行数:27,代码来源:test_configure.py

示例4: test_merge

def test_merge():
    d1 = {
        "d1": [1, 2, 3],
        "s": "foo",
        "a": [1, 2, 3],
        "nested_dict": {
            "d1": "ok",
            "d": "ok"
        }
    }
    c1 = Configuration.from_dict(d1)
    print_yaml("d1", d1)

    d2 = {
        "d2": "foobar",
        "s": "foobar",
        "a": [3, 4, 5],
        "nested_dict": {
            "d2": "ok",
            "d": {
                "foo": "bar"
            }
        }
    }
    c2 = Configuration.from_dict(d2)
    print_yaml("d2", d2)

    c3 = c1.merge(c2)
    print_yaml("Merged", dict(c3))
开发者ID:rbrady,项目名称:khaleesi,代码行数:29,代码来源:test_configure.py

示例5: test_merge_error

def test_merge_error():
    src_dict = {
        "d1": [1, 2, 3],
        "s": "foo",
        "a": [1, 2, 3],
        "nested_dict": {
            "d1": "ok",
            "d": "ok"
        }
    }

    other_dict = {
        "d2": "foobar",
        "s": "foobar",
        "a": [3, 4, 5],
        "nested_dict": {
            "d2": "ok",
            "d": {            # ### raises ConfigError
                "foo": "bar"
            }
        }
    }
    src = Configuration.from_dict(src_dict)
    print_yaml("src", src)

    other = Configuration.from_dict(other_dict)
    print_yaml("other", other)

    with pytest.raises(ConfigurationError):
        merged = deepcopy(src).merge(other)
        print_yaml("Merged", dict(merged))
    logger.info("Merge raised configuration error")
开发者ID:pcaruana,项目名称:khaleesi,代码行数:32,代码来源:test_configure.py

示例6: test_lookups_in_extends

def test_lookups_in_extends():
    src = Configuration.from_file(TEST_DIR + '/data/extends/extends.yml')
    print_yaml("Extends using !lookup:", src)
    src.configure()
    from ksgen.yaml_utils import LookupDirective
    LookupDirective.lookup_table = src
    print_yaml("Extends using !lookup:", src)
开发者ID:pcaruana,项目名称:khaleesi,代码行数:7,代码来源:test_configure.py

示例7: load

    def load(self):
        if self._loaded:
            return

        self._file_list = []
        self._invalid_paths = []
        self._create_file_list(self._settings, self._file_list)

        logger.info(
            "\nList of files to load :\n  - %s",
            '\n  - '.join([
                x[len(self._config_dir) + 1:] for x in self._file_list
            ]))

        if self._invalid_paths:
            logger.info("invalid files :\n %s", '\n'.join(self._invalid_paths))
            raise OptionError(self._invalid_paths)

        all_cfg = Configuration.from_dict({})
        for f in self._file_list:
            cfg = load_configuration(f, self._config_dir)

            try:
                del cfg[DEFAULTS_TAG]
            except KeyError:
                pass
            else:
                logger.debug("Successfully removed default traces from %s" % f)

            all_cfg.merge(cfg)
        self._all_settings.merge(all_cfg)
        self._loaded = True
开发者ID:Haoxing-Wang,项目名称:InfraRed,代码行数:32,代码来源:settings.py

示例8: test_load_from_file

    def test_load_from_file(self):
        filename = path.join(path.dirname(__file__), 'examples', 'example.default.conf')
        c = Configuration.from_file(filename)
        c.configure()

        self.assertEqual(c.a, 1)
        self.assertIsInstance(c.b, timedelta)
        self.assertEqual(c.b, timedelta(days=1))
开发者ID:alfred82santa,项目名称:configure,代码行数:8,代码来源:tests.py

示例9: test_array_extend

def test_array_extend():
    src_dict = {
        "src": [11, 12, 13],
        "merge": [100, 101, 102],
        'nested_dict': {
            'src': [111, 112, 113],
            'merge': [1000, 1001, 1002]
        }
    }

    other_dict = {
        "other": [22, 22, 23],
        "merge": [200, 202, 202],
        'nested_dict': {
            'other': [222, 222, 223],
            'merge': [2000, 2002, 2002]
        }
    }

    src = Configuration.from_dict(src_dict)
    print_yaml("Src", src)

    other = Configuration.from_dict(other_dict)
    print_yaml("Other", other)

    merged = deepcopy(src).merge(other)
    print_yaml("merged", merged)

    print_yaml("Src after merge", src)
    print_yaml("Other after merge", other)

    assert verify_key_val(src, src_dict, 'merge')
    assert verify_key_val(src, src_dict, 'src')
    assert verify_key_val(src, src_dict, 'nested_dict.merge')
    assert verify_key_val(src, src_dict, 'nested_dict.src')

    with pytest.raises(KeyError):
        verify_key_val(src, src_dict, 'other')

    assert verify_key_val(merged, src_dict, 'src')
    assert verify_key_val(merged, other_dict, 'other')
    assert merged['merge'] == src_dict['merge'] + other_dict['merge']
    assert verify_key_val(merged, src_dict, 'nested_dict.src')
    assert verify_key_val(merged, other_dict, 'nested_dict.other')
开发者ID:pcaruana,项目名称:khaleesi,代码行数:44,代码来源:test_configure.py

示例10: validate_configuration

def validate_configuration(options):
    # must have 3 sections common



if __name__ == '__main__':
    parser = build_argument_parser()
    options = parser.parse_args()
    config = Configuration.from_file(options.config)
    
开发者ID:PGower,项目名称:DifferenceEngine,代码行数:9,代码来源:DifferenceEngine.py

示例11: test_simple_merge

def test_simple_merge():
    src_dict = {
        "merge": "src merge",
        "src": 'src only',
        'nested_dict': {
            'merge': 'nested src merge',
            'src': 'nested src only'
        }
    }

    other_dict = {
        "merge": "other merge",
        "other": 'other only',
        'nested_dict': {
            'merge': 'nested other merge',
            'other': 'nested other only'
        }
    }

    src = Configuration.from_dict(src_dict)
    print_yaml("Src", src)

    other = Configuration.from_dict(other_dict)
    print_yaml("Other", other)

    merged = deepcopy(src).merge(other)
    print_yaml("merged", merged)

    print_yaml("Src after merge", src)
    print_yaml("Other after merge", other)

    assert verify_key_val(src, src_dict, 'merge')
    assert verify_key_val(src, src_dict, 'src')
    assert verify_key_val(src, src_dict, 'nested_dict.merge')
    assert verify_key_val(src, src_dict, 'nested_dict.src')

    with pytest.raises(KeyError):
        verify_key_val(src, src_dict, 'other')

    assert verify_key_val(merged, other_dict, 'merge')
    assert verify_key_val(merged, src_dict, 'src')
    assert verify_key_val(merged, other_dict, 'other')
    return
开发者ID:pcaruana,项目名称:khaleesi,代码行数:43,代码来源:test_configure.py

示例12: configuration_loader

def configuration_loader(filename):
    from collections import Mapping
    from configure import Configuration
    config = Configuration.from_file(filename)
    config.configure()

    def to_dict(mapping):
        return {k: (to_dict(v) if isinstance(v, Mapping) else v) for k, v in mapping.items()}

    return to_dict(config)
开发者ID:alfred82santa,项目名称:aio-service-client,代码行数:10,代码来源:spec_loaders.py

示例13: test_limit_chars

def test_limit_chars():
    src_yaml = """
    substr: !limit_chars [ 'abcdefghijklmnopqrstuvwxyz', 7 ]
    zero: !limit_chars [ 'abcdefghijklmnopqrstuvwxyz', 0 ]

    """
    src = Configuration.from_string(src_yaml)
    print_yaml("Src", src)

    assert src.substr == 'abcdefg'
    assert src.zero == ''
开发者ID:pcaruana,项目名称:khaleesi,代码行数:11,代码来源:test_configure.py

示例14: validate

def validate(config_path):
    try:
        config = Configuration.configure(config_path)
    except ConfigurationError as ce:
        logger.exception(ce)
    try:
        with open('config.schema.yaml', 'r') as f:
            schema = yaml.load(f)
    except:
        
    schema = yaml.load('')
    v = DEConfigValidator
开发者ID:PGower,项目名称:DifferenceEngine,代码行数:12,代码来源:config.py

示例15: test_random

def test_random():
    src_yaml = """
    random: !random 8

    """
    random_so_far = set()

    for x in range(2 ** 12):
        src = Configuration.from_string(src_yaml)
        if src.random in random_so_far:
            print len(random_so_far)
            assert src.random not in random_so_far
        random_so_far.add(src.random)
开发者ID:pcaruana,项目名称:khaleesi,代码行数:13,代码来源:test_configure.py


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