forked from Mirror/pmbootstrap
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.
63 lines
2.3 KiB
Python
63 lines
2.3 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 subprocess
|
|
import os
|
|
import pmb_test # noqa
|
|
import pmb.config
|
|
|
|
|
|
def test_chroot_interactive_shell():
|
|
"""
|
|
Open a shell with 'pmbootstrap chroot' and pass 'echo hello_world\n' as stdin.
|
|
"""
|
|
os.chdir(pmb.config.pmb_src)
|
|
ret = subprocess.check_output(["./pmbootstrap.py", "-q", "chroot", "sh"],
|
|
timeout=300, input="echo hello_world\n",
|
|
universal_newlines=True,
|
|
stderr=subprocess.STDOUT)
|
|
assert ret == "hello_world\n"
|
|
|
|
|
|
def test_chroot_interactive_shell_user():
|
|
"""
|
|
Open a shell with 'pmbootstrap chroot' as user, and test the resulting ID.
|
|
"""
|
|
os.chdir(pmb.config.pmb_src)
|
|
ret = subprocess.check_output(["./pmbootstrap.py", "-q", "chroot",
|
|
"--user", "sh"], timeout=300, input="id -un",
|
|
universal_newlines=True,
|
|
stderr=subprocess.STDOUT)
|
|
assert ret == "pmos\n"
|
|
|
|
|
|
def test_chroot_arguments():
|
|
"""
|
|
Open a shell with 'pmbootstrap chroot' for every architecture, pass 'uname -m\n'
|
|
as stdin and check the output
|
|
"""
|
|
os.chdir(pmb.config.pmb_src)
|
|
|
|
for arch in ["armhf", "aarch64", "x86_64"]:
|
|
ret = subprocess.check_output(["./pmbootstrap.py", "-q", "chroot", "-b", arch,
|
|
"sh"], timeout=300, input="uname -m\n",
|
|
universal_newlines=True, stderr=subprocess.STDOUT)
|
|
if arch == "armhf":
|
|
assert ret == "armv7l\n"
|
|
else:
|
|
assert ret == arch + "\n"
|