pmbootstrap-meow/test/test_config_user.py
Oliver Smith e605a0af32
test/pmb_test: prepare for common test code (!1876)
Replace the "Add topdir to import path" boilerplate lines in each test
file with a simple "import pmb_test". Use the "# noqa" comment if
"pmb_test" is not used further in the test file, so flake8 does not
complain about an unused module.

Make the path to the testdata available as pmb_test.const.testdata, and
use pmb.config.pmb_src to access the topdir in all tests.

This is in preparation for new "pmbootstrap status" related tests, which
will have shared test code in test/pmb_test/. Also, this makes the
pmbootstrap codebase more consistent with the bpo codebase, which has a
similar "import bpo_test" mechanism.
2020-02-24 03:01:04 +03:00

83 lines
2.8 KiB
Python

"""
Copyright 2020 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 sys
import pytest
import pmb_test # noqa
import pmb.aportgen
import pmb.config
import pmb.helpers.frontend
import pmb.helpers.logging
import pmb.helpers.run
@pytest.fixture
def args(tmpdir, request):
import pmb.parse
sys.argv = ["pmbootstrap.py", "chroot"]
args = pmb.parse.arguments()
args.log = args.work + "/log_testsuite.txt"
pmb.helpers.logging.init(args)
request.addfinalizer(args.logfd.close)
return args
def change_config(monkeypatch, path_config, key, value):
args = args_patched(monkeypatch, ["pmbootstrap.py", "-c", path_config, "config",
key, value])
pmb.helpers.frontend.config(args)
def args_patched(monkeypatch, argv):
monkeypatch.setattr(sys, "argv", argv)
return pmb.parse.arguments()
def test_config_user(args, tmpdir, monkeypatch):
# Temporary paths
tmpdir = str(tmpdir)
path_work = tmpdir + "/work"
path_config = tmpdir + "/pmbootstrap.cfg"
# Generate default config (only uses tmpdir)
cmd = pmb.helpers.run.flat_cmd(["./pmbootstrap.py",
"-c", path_config,
"-w", path_work,
"--aports", args.aports,
"init"])
pmb.helpers.run.user(args, ["sh", "-c", "yes '' | " + cmd],
pmb.config.pmb_src)
# Load and verify default config
argv = ["pmbootstrap.py", "-c", path_config, "config"]
args_default = args_patched(monkeypatch, argv)
assert args_default.work == path_work
# Modify jobs count
change_config(monkeypatch, path_config, "jobs", "9000")
assert args_patched(monkeypatch, argv).jobs == "9000"
# Override jobs count via commandline (-j)
argv_jobs = ["pmbootstrap.py", "-c", path_config, "-j", "1000", "config"]
assert args_patched(monkeypatch, argv_jobs).jobs == "1000"
# Override a config option with something that evaluates to false
argv_empty = ["pmbootstrap.py", "-c", path_config, "-w", "",
"--details-to-stdout", "config"]
assert args_patched(monkeypatch, argv_empty).work == ""