tests: fix tests (MR 2252)

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
This commit is contained in:
Caleb Connolly 2024-06-22 19:22:04 +02:00 committed by Oliver Smith
parent e6c737f342
commit b89e300c26
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB
2 changed files with 50 additions and 10 deletions

View file

@ -16,27 +16,66 @@ def apk_mocks(monkeypatch):
monkeypatch.setattr(pmb.config.pmaports, "read_config", _pmaports_config) monkeypatch.setattr(pmb.config.pmaports, "read_config", _pmaports_config)
def _apkindex_package(_package, _arch, _must_exist=False, indexes=None): def _apkindex_package(_package, _arch, _must_exist=False, indexes=None):
return { if _package == "package1":
"name": _package, return {
"version": "5.5-r0", "pkgname": _package,
"arch": str(_arch), "version": "5.5-r0",
} "arch": str(_arch),
"depends": ["package2"],
}
if _package == "package2":
return {
"pkgname": _package,
"version": "5.5-r0",
"arch": str(_arch),
"depends": [],
}
if _package == "package3":
return {
"pkgname": _package,
"version": "5.5-r0",
"arch": str(_arch),
"depends": ["package1", "package4"],
}
# Test recursive dependency
if _package == "package4":
return {
"pkgname": _package,
"version": "5.5-r0",
"arch": str(_arch),
"depends": ["package3"],
}
monkeypatch.setattr(pmb.parse.apkindex, "package", _apkindex_package) monkeypatch.setattr(pmb.parse.apkindex, "package", _apkindex_package)
def create_apk(pkgname, arch):
apk_file = get_context().config.work / "packages" / "edge" / arch / f"{pkgname}-5.5-r0.apk"
apk_file.parent.mkdir(parents=True, exist_ok=True)
apk_file.touch()
return apk_file
def test_get_local_apks(pmb_args, apk_mocks): def test_get_local_apks(pmb_args, apk_mocks):
"""Ensure packages_get_locally_built_apks() returns paths for local apks""" """Ensure packages_get_locally_built_apks() returns paths for local apks"""
pkgname = "hello-world" pkgname = "package1"
arch = Arch.x86_64 arch = Arch.x86_64
apk_file = get_context().config.work / "packages" / "edge" / arch / f"{pkgname}-5.5-r0.apk" apk_file = create_apk(pkgname, arch)
apk_file.parent.mkdir(parents=True)
apk_file.touch()
local = packages_get_locally_built_apks([pkgname, "fake-package"], arch) local = packages_get_locally_built_apks([pkgname, "fake-package"], arch)
print(local) print(local)
assert len(local) == 1 assert len(local) == 1
assert local[0].parts[-2:] == apk_file.parts[-2:] assert local[0].parts[-2:] == apk_file.parts[-2:]
create_apk("package2", arch)
create_apk("package3", arch)
create_apk("package4", arch)
# Test recursive dependencies
local = packages_get_locally_built_apks(["package3"], arch)
print(local)
assert len(local) == 4

View file

@ -8,6 +8,7 @@ from pmb.core.pkgrepo import pkgrepo_paths, pkgrepo_default_path
@pytest.mark.parametrize("config_file", ["no-repos"], indirect=True) @pytest.mark.parametrize("config_file", ["no-repos"], indirect=True)
def test_pkgrepo_paths_no_repos(pmb_args): def test_pkgrepo_paths_no_repos(pmb_args):
"""Test pkgrepo_paths() with no repositories. Should raise a RuntimeError.""" """Test pkgrepo_paths() with no repositories. Should raise a RuntimeError."""
pkgrepo_paths.cache_disable()
with pytest.raises(RuntimeError): with pytest.raises(RuntimeError):
paths = pkgrepo_paths() paths = pkgrepo_paths()
print(paths) print(paths)