forked from Mirror/pmbootstrap
tests: fix tests (MR 2252)
Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
This commit is contained in:
parent
e6c737f342
commit
b89e300c26
2 changed files with 50 additions and 10 deletions
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue