Пример #1
0
    def test_with_include(self):
        with write_file("nodes:\n  - foo\n  - bar\nstart-retries: 1") as include_path:
            with write_file("core:\n  backend: zookeeper\nbackend: !include {}".format(include_path)) as main_path:
                raw = yaml.load_file(main_path)
                scheme = {"core": {"backend": optconf.Option(default="noop", type=str, help="")}}
                config = optconf.make_config(raw, scheme)
                assert raw["backend"]["nodes"] == ["foo", "bar"]
                assert config.core.backend == "zookeeper"

                typetools.merge_dicts(scheme, {"backend": zookeeper.Backend.get_options()})
                config = optconf.make_config(raw, scheme)
                assert config.backend.nodes == ["foo", "bar"]
                assert config.backend.timeout == 10.0
Пример #2
0
    def test_with_include(self):
        with write_file(
                "nodes:\n  - foo\n  - bar\nstart-retries: 1") as include_path:
            with write_file(
                    "core:\n  backend: zookeeper\nbackend: !include {}".format(
                        include_path)) as main_path:
                raw = load_yaml_file(main_path)
                scheme = {
                    "core": {
                        "backend":
                        optconf.Option(default="noop", type=str, help=""),
                    },
                }
                config = optconf.make_config(raw, scheme)
                assert raw["backend"]["nodes"] == ["foo", "bar"]
                assert config.core.backend == "zookeeper"

                _merge_dicts(scheme,
                             {"backend": zookeeper.Backend.get_options()})
                config = optconf.make_config(raw, scheme)
                assert config.backend.nodes == ["foo", "bar"]
                assert config.backend.timeout == 10.0
Пример #3
0
 def test_yaml_not_a_section(self, scheme):
     with write_file("section1: 5") as path:
         raw = load_yaml_file(path)
         with pytest.raises(ValueError):
             optconf.make_config(raw, scheme)
Пример #4
0
 def test_yaml_invalid_value(self, scheme):
     with write_file("key1: x") as path:
         raw = load_yaml_file(path)
         with pytest.raises(ValueError):
             optconf.make_config(raw, scheme)
Пример #5
0
 def test_yaml_syntax_error(self):
     with write_file("&") as path:
         with pytest.raises(ValueError):
             load_yaml_file(path)
Пример #6
0
 def test_yaml_root_error(self, scheme):
     with write_file("foobar") as path:
         raw = load_yaml_file(path)
         with pytest.raises(ValueError):
             optconf.make_config(raw, scheme)
Пример #7
0
 def test_yaml_not_a_section(self, scheme):
     with write_file("section1: 5") as path:
         raw = yaml.load_file(path)
         with pytest.raises(ValueError):
             optconf.make_config(raw, scheme)
Пример #8
0
 def test_yaml_invalid_value(self, scheme):
     with write_file("key1: x") as path:
         raw = yaml.load_file(path)
         with pytest.raises(ValueError):
             optconf.make_config(raw, scheme)
Пример #9
0
 def test_yaml_syntax_error(self):
     with write_file("&") as path:
         with pytest.raises(ValueError):
             yaml.load_file(path)
Пример #10
0
 def test_yaml_root_error(self, scheme):
     with write_file("foobar") as path:
         raw = yaml.load_file(path)
         with pytest.raises(ValueError):
             optconf.make_config(raw, scheme)