1
0
Fork 1
mirror of https://gitlab.postmarketos.org/postmarketOS/pmbootstrap.git synced 2025-07-13 11:29:46 +03:00

fix tests

Signed-off-by: Casey Connolly <kcxt@postmarketos.org>
This commit is contained in:
Casey Connolly 2025-05-26 18:42:22 +02:00
parent 88afc10e95
commit e44ef84b4b
9 changed files with 27 additions and 17 deletions

View file

@ -10,6 +10,9 @@ if [ "$(id -u)" = 0 ]; then
openssl \
py3-pytest \
py3-pytest-cov \
kpartx \
losetup \
android-tools \
sudo
exec su "${TESTUSER:-build}" -c "sh -e $0"
fi

View file

@ -78,7 +78,7 @@ def apk_mocks(monkeypatch) -> dict | None:
def create_apk(pkgname: str, arch: Arch) -> Path:
apk_file = get_context().config.work / "packages" / "edge" / arch / f"{pkgname}-5.5-r0.apk"
apk_file = get_context().config.cache / "packages" / "edge" / arch / f"{pkgname}-5.5-r0.apk"
apk_file.parent.mkdir(parents=True, exist_ok=True)
apk_file.touch()
return apk_file

View file

@ -24,4 +24,4 @@ def test_load(config_file):
assert config.ui == "gnome"
assert config.providers == {}
assert config.mirrors["pmaports"] is not None
assert ".pytest_tmp" in config.work.parts
assert ".pytest_tmp" in config.cache.parts

View file

@ -148,10 +148,10 @@ def pmb_args(config_file, mock_context, logfile):
init_args(args)
print(f"WORK: {get_context().config.work}")
print(f"WORK: {get_context().config.cache}")
# Sanity check
assert ".pytest_tmp" in get_context().config.work.parts
assert ".pytest_tmp" in get_context().config.cache.parts
@pytest.fixture

View file

@ -8,26 +8,26 @@ from pmb.core.context import get_context
from pmb.core.chroot import Chroot, ChrootType
def test_valid_chroots(pmb_args, mock_devices_find_path):
def test_valid_chroots(pmb_args, mock_devices_find_path, foreign_arch):
"""Test that Chroot objects work as expected"""
work = get_context().config.work
localdir = get_context().config.work
chroot = Chroot.native()
assert chroot.type == ChrootType.NATIVE
assert chroot.name == ""
assert chroot.arch in Arch.supported()
assert not chroot.exists() # Shouldn't be created
assert chroot.path == work / "chroot_native"
assert chroot.path == localdir / "chroot_native"
assert str(chroot) == "native"
chroot = Chroot.buildroot(Arch.aarch64)
chroot = Chroot.buildroot(foreign_arch)
assert chroot.type == ChrootType.BUILDROOT
assert chroot.name == "aarch64"
assert chroot.arch == Arch.aarch64
assert chroot.name == f"{foreign_arch}"
assert chroot.arch == foreign_arch
assert not chroot.exists() # Shouldn't be created
assert chroot.path == work / "chroot_buildroot_aarch64"
assert str(chroot) == "buildroot_aarch64"
assert chroot.path == localdir / f"chroot_buildroot_{foreign_arch}"
assert str(chroot) == f"buildroot_{foreign_arch}"
# FIXME: implicily assumes that we're mocking the qemu-amd64 deviceinfo
chroot = Chroot(ChrootType.ROOTFS, "qemu-amd64")
@ -35,7 +35,7 @@ def test_valid_chroots(pmb_args, mock_devices_find_path):
assert chroot.name == "qemu-amd64"
assert chroot.arch == Arch.x86_64
assert not chroot.exists() # Shouldn't be created
assert chroot.path == work / "chroot_rootfs_qemu-amd64"
assert chroot.path == localdir / "chroot_rootfs_qemu-amd64"
assert str(chroot) == "rootfs_qemu-amd64"

View file

@ -22,7 +22,7 @@ def test_pkgrepo_pmaports(pmaports, monkeypatch):
pkgrepo_paths.cache_disable()
pkgrepo_default_path.cache_disable()
paths = pkgrepo_paths()
paths = pkgrepo_paths(with_extra_repos="disabled")
print(f"[master] pkgrepo_paths: {paths}")
assert len(paths) == 1
assert "pmaports" in paths[0].name
@ -32,9 +32,6 @@ def test_pkgrepo_pmaports(pmaports, monkeypatch):
assert default_path.name == "pmaports"
# Test extra-repos
paths = pkgrepo_paths(with_extra_repos="disabled")
assert len(paths) == 1
paths = pkgrepo_paths(with_extra_repos="enabled")
assert len(paths) == 2

View file

@ -15,6 +15,7 @@ systemd = always
timezone = Europe/Berlin
ui = gnome
work = {0}
cache = {0}/cache
[providers]

View file

@ -44,6 +44,9 @@ def progs() -> dict[str, str]:
@pytest.fixture
def bootimg(progs: dict[str, str], tmp_path: Path) -> Callable:
if Path("/in-pmbootstrap").exists():
pytest.skip("Nested chroot unsupported")
path: Path = tmp_path / "boot.img"
cmd = [
progs["mkbootimg"],

View file

@ -175,6 +175,12 @@ def random_valid_deviceinfo(tmp_path):
info["codename"] = tmp_path.name[7:]
info["chassis"] = random.choice(deviceinfo_chassis_types)
info["arch"] = random.choice(["armhf", "aarch64", "x86_64"])
# FIXME: we can't keep adding properties here manually as we make more of them
# discrete types..
if "rootfs_image_sector_size" in info:
info["rootfs_image_sector_size"] = random.choice([512, 2048, 4096])
if "boot_part_start" in info:
info["boot_part_start"] = random.choice([0, 2048, 4096])
# Now write it all out to a file
with open(path, "w") as f: