WIP: test: type annotate suffix + pathlib (MR 2252)

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
This commit is contained in:
Caleb Connolly 2024-03-13 02:31:01 +00:00 committed by Oliver Smith
parent 9301412f90
commit 3bfc6474bb
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB
38 changed files with 164 additions and 128 deletions

View file

@ -2,39 +2,40 @@
# SPDX-License-Identifier: GPL-3.0-or-later
""" Test pmb/chroot/mount.py """
import os
from pmb.core.types import PmbArgs
import pytest
import sys
import pmb_test # noqa
import pmb.chroot
from pmb.core import Chroot
@pytest.fixture
def args(tmpdir, request):
import pmb.parse
sys.argv = ["pmbootstrap", "init"]
args = pmb.parse.arguments()
args.log = args.work + "/log_testsuite.txt"
args.log = pmb.config.work / "log_testsuite.txt"
pmb.helpers.logging.init(args)
request.addfinalizer(pmb.helpers.logging.logfd.close)
return args
def test_chroot_mount(args):
suffix = "native"
mnt_dir = f"{args.work}/chroot_native/mnt/pmbootstrap"
def test_chroot_mount(args: PmbArgs):
chroot = Chroot.native()
mnt_dir = chroot / "mnt/pmbootstrap"
# Run something in the chroot to have the dirs created
pmb.chroot.root(args, ["true"])
assert os.path.exists(mnt_dir)
assert os.path.exists(f"{mnt_dir}/packages")
assert mnt_dir.exists()
assert (mnt_dir / "packages").exists()
# Umount everything, like in pmb.install.install_system_image
pmb.helpers.mount.umount_all(args, f"{args.work}/chroot_{suffix}")
pmb.helpers.mount.umount_all(args, chroot.path)
# Remove all /mnt/pmbootstrap dirs
pmb.chroot.remove_mnt_pmbootstrap(args, suffix)
assert not os.path.exists(mnt_dir)
pmb.chroot.remove_mnt_pmbootstrap(args, chroot)
assert not mnt_dir.exists()
# Run again: it should not crash
pmb.chroot.remove_mnt_pmbootstrap(args, suffix)
pmb.chroot.remove_mnt_pmbootstrap(args, chroot)