forked from Mirror/pmbootstrap
install_is_necessary used to do the following things: 1. Error out if there's no binary package but pmb was invoked as "pmbootstrap install" and build_pkgs_on_install is disabled. 2. Build the package if necessary. 3. Return if a package "needs to be installed" (Boolean or Float). The only caller of the function is pmb.chroot.apk.install. It would not add the package to the long "apk add" command if according to 3. it does not need to be installed. When I implemented this a few years ago, I probably thought it would be useful to not unnecessarily pass packages to apk. But this actually makes it more complicated and doesn't have a benefit, apk is perfectly capable of recognizing which packages it had already installed. Replace the function with a much simpler pmb.chroot.apk.install_build, which only does 1. and 2. Change the order of the package, arch arguments to match called functions pmb.parse.apkindex.package and pmb.build.package.
57 lines
1.7 KiB
Python
57 lines
1.7 KiB
Python
# Copyright 2022 Oliver Smith
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
import pytest
|
|
import sys
|
|
|
|
import pmb_test # noqa
|
|
import pmb.chroot.apk
|
|
|
|
|
|
@pytest.fixture
|
|
def args(tmpdir, request):
|
|
import pmb.parse
|
|
sys.argv = ["pmbootstrap.py", "init"]
|
|
args = pmb.parse.arguments()
|
|
args.log = args.work + "/log_testsuite.txt"
|
|
pmb.helpers.logging.init(args)
|
|
request.addfinalizer(pmb.helpers.logging.logfd.close)
|
|
return args
|
|
|
|
|
|
def test_install_build(monkeypatch, args):
|
|
func = pmb.chroot.apk.install_build
|
|
ret_apkindex_package = None
|
|
|
|
def fake_build_package(args, package, arch):
|
|
return "build-pkg"
|
|
monkeypatch.setattr(pmb.build, "package", fake_build_package)
|
|
|
|
def fake_apkindex_package(args, package, arch, must_exist):
|
|
return ret_apkindex_package
|
|
monkeypatch.setattr(pmb.parse.apkindex, "package", fake_apkindex_package)
|
|
|
|
package = "hello-world"
|
|
arch = "x86_64"
|
|
|
|
# invoked as pmb install, build_pkgs_on_install disabled
|
|
args.action = "install"
|
|
args.build_pkgs_on_install = False
|
|
with pytest.raises(RuntimeError) as e:
|
|
func(args, package, arch)
|
|
assert "no binary package found" in str(e.value)
|
|
|
|
# invoked as pmb install, build_pkgs_on_install disabled, binary exists
|
|
args.action = "install"
|
|
args.build_pkgs_on_install = False
|
|
ret_apkindex_package = {"pkgname": "hello-world"}
|
|
assert func(args, package, arch) is None
|
|
|
|
# invoked as pmb install, build_pkgs_on_install enabled
|
|
args.action = "install"
|
|
args.build_pkgs_on_install = True
|
|
assert func(args, package, arch) == "build-pkg"
|
|
|
|
# invoked as not pmb install
|
|
args.action = "chroot"
|
|
args.build_pkgs_on_install = False
|
|
assert func(args, package, arch) == "build-pkg"
|