Esempio n. 1
0
def test_load_yaml_file_bad_yaml(caplog, tmp_path):
    yaml_path = tmp_path / "test.yaml"
    yaml_path.write_text("foo: bara-b-c: xyz\n")

    with pytest.raises(YamlValidationError):
        yaml_utils.load_yaml_file(str(yaml_path))

    assert [r.message for r in caplog.records] == []
Esempio n. 2
0
    def test_stripped_source_keys(self):
        self._snapcraft_yaml.update_part(
            "my-part",
            {
                "plugin": "nil",
                "source": self._source.path,
                "source-checksum": "strip-me",
                "source-branch": "strip-me",
                "source-commit": "strip-me",
                "source-depth": "strip-me",
                "source-subdir": "test-sub-dir",
                "source-tag": "strip-me",
                "source-type": "local",
            },
        )

        self.load_project_and_worktree()
        self._wt.prepare_repository()

        config = yaml_utils.load_yaml_file(
            str(Path(self._dest.path, "repo", "snap", "snapcraft.yaml")))

        self.assertThat(
            config["parts"]["my-part"],
            Equals(
                OrderedDict([
                    ("plugin", "nil"),
                    ("source", "sources/my-part/my-part.tar.gz"),
                    ("source-subdir", "test-sub-dir"),
                    ("source-type", "tar"),
                ])),
        )
Esempio n. 3
0
    def test_load_yaml_file(self):
        path = os.path.join(self.path, "test.yaml")
        with open(path, "w") as f:
            f.write("foo: bar")

        cfg = yaml_utils.load_yaml_file(path)

        self.assertThat(cfg, Equals({"foo": "bar"}))
Esempio n. 4
0
def test_load_yaml_file(caplog, tmp_path):
    yaml_path = tmp_path / "test.yaml"
    yaml_path.write_text("foo: bar")

    cfg = yaml_utils.load_yaml_file(str(yaml_path))

    assert cfg == {"foo": "bar"}
    assert [r.message for r in caplog.records] == []
Esempio n. 5
0
def test_load_yaml_file_with_duplicate_warnings(caplog, tmp_path):
    yaml_path = tmp_path / "test.yaml"
    yaml_path.write_text("foo: bar\nfoo: bar2")

    cfg = yaml_utils.load_yaml_file(str(yaml_path))

    assert cfg == {"foo": "bar2"}
    assert [r.message for r in caplog.records
            ] == ["Duplicate key in YAML detected: 'foo'"]
Esempio n. 6
0
def _load_config(file_path: str) -> Dict[str, str]:
    try:
        config = yaml_utils.load_yaml_file(file_path)
    except FileNotFoundError:
        return dict()
    else:
        echo.info(f"Using config file: {file_path}")
        echo.warning(
            "Configuration file is experimental and is subject to change.")
        return _convert_key_dashes_to_underscores(config)
Esempio n. 7
0
def test_load_yaml_file_nested_duplicates(caplog, tmp_path):
    yaml_path = tmp_path / "test.yaml"
    yaml_path.write_text(
        "foo: bar\nnest:\n  foo: bar2\n  baz: bar3\n  baz: bar4")

    cfg = yaml_utils.load_yaml_file(str(yaml_path))

    assert cfg == {"foo": "bar", "nest": {"foo": "bar2", "baz": "bar4"}}
    assert [r.message for r in caplog.records
            ] == ["Duplicate key in YAML detected: 'baz'"]
Esempio n. 8
0
    def __init__(self, *, snapcraft_yaml_file_path) -> None:
        self.snapcraft_yaml_file_path = snapcraft_yaml_file_path
        self.__raw_snapcraft = yaml_utils.load_yaml_file(snapcraft_yaml_file_path)

        try:
            self.name = self.__raw_snapcraft["name"]
        except KeyError as key_error:
            raise snapcraft.yaml_utils.errors.YamlValidationError(
                "'name' is a required property in {!r}".format(snapcraft_yaml_file_path)
            ) from key_error
        self.version = self.__raw_snapcraft.get("version")
        self.summary = self.__raw_snapcraft.get("summary")
        self.description = self.__raw_snapcraft.get("description")
        self.confinement = self.__raw_snapcraft.get("confinement")
        self.architectures = self.__raw_snapcraft.get("architectures")
        self.grade = self.__raw_snapcraft.get("grade")
        self.base = self.__raw_snapcraft.get("base")
        self.build_base = self.__raw_snapcraft.get("build-base")
        self.type = self.__raw_snapcraft.get("type")