pmbootstrap-meow/test/test_helpers_repo_missing.py
Oliver Smith 933c4d0f0d new action: 'pmbootstrap repo_missing'
Add a new action that lists all aports, for which no binary packages
exist. Only list packages that can be built for the relevant arch
(specified with --arch). This works recursively: when a package can be
built for a certain arch, but one of its dependencies
(or their depends) can not be built for that arch, then don't list it.

This action will be used for the new sr.ht based build infrastructure,
to figure out which packages need to be built ahead of time (so we can
trigger each of them as single build job). Determining the order of the
packages to be built is not determined with pmbootstrap, the serverside
code of build.postmarketos.org takes care of that.

For testing purposes, a single package can also be specified and the
action will list if it can be built for that arch with its
dependencies, and what needs to be built exactly.

Add pmb/helpers/package.py to hold functions that work on both pmaports
and (binary package) repos - in contrary to the existing
pmb/helpers/pmaports.py (see previous commit) and pmb/helpers/repo.py,
which only work with one of those.

Refactoring:
* pmb/helpers/pmaports.py: add a get_list() function, which lists all
  aports and use it instead of writing the same glob loop over and over
* add pmb.helpers.pmaports.get(), which finds an APKBUILD and parses it
  in one step.
* rename pmb.build._package.check_arch to ...check_arch_abort to
  distinguish it from the other check_arch function
2018-12-01 21:30:59 +00:00

158 lines
5.3 KiB
Python

"""
Copyright 2018 Oliver Smith
This file is part of pmbootstrap.
pmbootstrap is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
pmbootstrap is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with pmbootstrap. If not, see <http://www.gnu.org/licenses/>.
"""
import os
import pytest
import sys
# Import from parent directory
sys.path.insert(0, os.path.realpath(
os.path.join(os.path.dirname(__file__) + "/..")))
import pmb.build.other
@pytest.fixture
def args(request):
import pmb.parse
sys.argv = ["pmbootstrap", "init"]
args = pmb.parse.arguments()
args.log = args.work + "/log_testsuite.txt"
pmb.helpers.logging.init(args)
request.addfinalizer(args.logfd.close)
return args
def test_filter_missing_packages_invalid(args):
""" Test ...repo_missing.filter_missing_packages(): invalid package """
func = pmb.helpers.repo_missing.filter_missing_packages
with pytest.raises(RuntimeError) as e:
func(args, "armhf", ["invalid-package-name"])
assert str(e.value).startswith("Could not find aport")
def test_filter_missing_packages_binary_exists(args):
""" Test ...repo_missing.filter_missing_packages(): binary exists """
func = pmb.helpers.repo_missing.filter_missing_packages
assert func(args, "armhf", ["busybox"]) == []
def test_filter_missing_packages_pmaports(args, monkeypatch):
""" Test ...repo_missing.filter_missing_packages(): pmaports """
build_is_necessary = None
func = pmb.helpers.repo_missing.filter_missing_packages
def stub(args, arch, pmaport):
return build_is_necessary
monkeypatch.setattr(pmb.build, "is_necessary", stub)
build_is_necessary = True
assert func(args, "x86_64", ["busybox", "hello-world"]) == ["hello-world"]
build_is_necessary = False
assert func(args, "x86_64", ["busybox", "hello-world"]) == []
def test_filter_aport_packages(args):
""" Test ...repo_missing.filter_aport_packages() """
func = pmb.helpers.repo_missing.filter_aport_packages
assert func(args, "armhf", ["busybox", "hello-world"]) == ["hello-world"]
def test_filter_arch_packages(args, monkeypatch):
""" Test ...repo_missing.filter_arch_packages() """
func = pmb.helpers.repo_missing.filter_arch_packages
check_arch = None
def stub(args, arch, pmaport):
return check_arch
monkeypatch.setattr(pmb.helpers.package, "check_arch_recurse", stub)
check_arch = False
assert func(args, "armhf", ["hello-world"]) == []
check_arch = True
assert func(args, "armhf", []) == []
def test_get_relevant_packages(args, monkeypatch):
""" Test ...repo_missing.get_relevant_packages() """
# Set up fake return values
stub_data = {"check_arch_recurse": False,
"depends_recurse": ["a", "b", "c", "d"],
"filter_arch_packages": ["a", "b", "c"],
"filter_aport_packages": ["b", "a"],
"filter_missing_packages": ["a"]}
def stub(args, arch, pmaport):
return stub_data["check_arch_recurse"]
monkeypatch.setattr(pmb.helpers.package, "check_arch_recurse", stub)
def stub(args, arch, pmaport):
return stub_data["depends_recurse"]
monkeypatch.setattr(pmb.helpers.package, "depends_recurse", stub)
def stub(args, arch, pmaport):
return stub_data["filter_arch_packages"]
monkeypatch.setattr(pmb.helpers.repo_missing, "filter_arch_packages", stub)
def stub(args, arch, pmaport):
return stub_data["filter_aport_packages"]
monkeypatch.setattr(pmb.helpers.repo_missing, "filter_aport_packages",
stub)
def stub(args, arch, pmaport):
return stub_data["filter_missing_packages"]
monkeypatch.setattr(pmb.helpers.repo_missing, "filter_missing_packages",
stub)
# No given package
func = pmb.helpers.repo_missing.get_relevant_packages
assert func(args, "armhf") == ["a"]
assert func(args, "armhf", built=True) == ["a", "b"]
# Package can't be built for given arch
with pytest.raises(RuntimeError) as e:
func(args, "armhf", "a")
assert "can't be built" in str(e.value)
# Package can be built for given arch
stub_data["check_arch_recurse"] = True
assert func(args, "armhf", "a") == ["a"]
assert func(args, "armhf", "a", True) == ["a", "b"]
def test_generate_output_format(args, monkeypatch):
""" Test ...repo_missing.generate_output_format() """
def stub(args, pkgname, arch):
return {"pkgname": "hello-world", "version": "1.0-r0",
"depends": ["depend1", "depend2"]}
monkeypatch.setattr(pmb.helpers.package, "get", stub)
def stub(args, pkgname):
return "main"
monkeypatch.setattr(pmb.helpers.pmaports, "get_repo", stub)
func = pmb.helpers.repo_missing.generate_output_format
ret = [{"pkgname": "hello-world",
"repo": "main",
"version": "1.0-r0",
"depends": ["depend1", "depend2"]}]
assert func(args, "armhf", ["hello-world"]) == ret