allow packages without package function

This commit is contained in:
Evgenii Alekseev 2024-09-17 03:33:25 +03:00
parent e553d96d33
commit e98b7ff4ab
2 changed files with 11 additions and 3 deletions

View File

@ -100,7 +100,7 @@ class Pkgbuild(Mapping[str, Any]):
def io(package_name: str) -> IO[str]:
# try to read package specific function and fallback to default otherwise
content = self.get(f"package_{package_name}") or self["package"]
content = self.get(f"package_{package_name}") or self.get("package") or ""
return StringIO(content)
return {package: self.from_io(io(package)) for package in packages}

View File

@ -66,14 +66,14 @@ def test_from_io_empty(pkgbuild_ahriman: Pkgbuild, mocker: MockerFixture) -> Non
def test_packages(pkgbuild_ahriman: Pkgbuild) -> None:
"""
must correctly generate load package function
must correctly load package function
"""
assert pkgbuild_ahriman.packages() == {pkgbuild_ahriman["pkgbase"]: Pkgbuild({})}
def test_packages_multi(resource_path_root: Path) -> None:
"""
must correctly generate load list of package functions
must correctly load list of package functions
"""
pkgbuild = Pkgbuild.from_file(resource_path_root / "models" / "package_gcc10_pkgbuild")
packages = pkgbuild.packages()
@ -83,6 +83,14 @@ def test_packages_multi(resource_path_root: Path) -> None:
assert all("depends" in package for package in packages.values())
def test_packages_empty(pkgbuild_ahriman: Pkgbuild) -> None:
"""
must correctly load packages without package functionn
"""
del pkgbuild_ahriman.fields["package()"]
assert pkgbuild_ahriman.packages() == {pkgbuild_ahriman["pkgbase"]: Pkgbuild({})}
def test_getitem(pkgbuild_ahriman: Pkgbuild) -> None:
"""
must return element by key