コード例 #1
0
ファイル: test_core_optconf.py プロジェクト: nikicat/powny
    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
ファイル: test_core_optconf.py プロジェクト: nikicat/powny
 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
ファイル: test_core_optconf.py プロジェクト: nikicat/powny
 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
ファイル: test_core_optconf.py プロジェクト: nikicat/powny
 def test_yaml_syntax_error(self):
     with write_file("&") as path:
         with pytest.raises(ValueError):
             yaml.load_file(path)
コード例 #10
0
ファイル: test_core_optconf.py プロジェクト: nikicat/powny
 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)