Exemplo n.º 1
0
    def test_correctness(self, tmpdir, spec):
        config_file = os.path.join(str(tmpdir), "config.yaml")
        logging_config_file = os.path.join(str(tmpdir), "logging.json")

        bg_utils.generate_config_file(
            spec, ["-c", config_file, "-l", logging_config_file])

        spec.add_source(label="config_file",
                        source_type="yaml",
                        filename=config_file)
        config = spec.load_config("config_file")

        # Defaults from spec
        assert config.log.file is None
        assert config.log.level == "INFO"

        # Value passed in
        assert config.log.config_file == logging_config_file

        # Ensure that bootstrap items were not written to file
        assert config.configuration.file is None
        assert config.configuration.type is None

        with open(config_file) as f:
            yaml_config = yaml.safe_load(f)
        assert "configuration" not in yaml_config
Exemplo n.º 2
0
    def test_omit_bootstrap(self, spec, tmpdir):
        filename = os.path.join(str(tmpdir), "temp.yaml")
        bg_utils.generate_config_file(spec, ["-c", filename])

        with open(filename) as f:
            config = yaml.safe_load(f)

        assert "log" in config
        assert "configuration" not in config
Exemplo n.º 3
0
    def test_stdout(self, spec, capsys, file_type):
        bg_utils.generate_config_file(spec, ["-t", file_type])

        # Just make sure we printed something
        assert capsys.readouterr().out
Exemplo n.º 4
0
    def test_file_infer_type(self, spec, tmpdir, file_type):
        filename = os.path.join(str(tmpdir), "temp." + file_type)
        bg_utils.generate_config_file(spec, ["-c", filename])

        assert os.path.getsize(filename) > 0
Exemplo n.º 5
0
def generate_config():
    spec = YapconfSpec(SPECIFICATION, env_prefix="BG_")
    bg_utils.generate_config_file(spec, sys.argv[1:])