diff options
Diffstat (limited to 'lib/portage/tests/bin')
-rw-r--r-- | lib/portage/tests/bin/meson.build | 14 | ||||
-rw-r--r-- | lib/portage/tests/bin/setup_env.py | 7 | ||||
-rw-r--r-- | lib/portage/tests/bin/test_doins.py | 12 | ||||
-rw-r--r-- | lib/portage/tests/bin/test_eapi7_ver_funcs.py | 30 | ||||
-rw-r--r-- | lib/portage/tests/bin/test_filter_bash_env.py | 27 |
5 files changed, 44 insertions, 46 deletions
diff --git a/lib/portage/tests/bin/meson.build b/lib/portage/tests/bin/meson.build new file mode 100644 index 000000000..519972f0a --- /dev/null +++ b/lib/portage/tests/bin/meson.build @@ -0,0 +1,14 @@ +py.install_sources( + [ + 'setup_env.py', + 'test_dobin.py', + 'test_dodir.py', + 'test_doins.py', + 'test_eapi7_ver_funcs.py', + 'test_filter_bash_env.py', + '__init__.py', + '__test__.py', + ], + subdir : 'portage/tests/bin', + pure : not native_extensions +) diff --git a/lib/portage/tests/bin/setup_env.py b/lib/portage/tests/bin/setup_env.py index faef118b0..5787f8768 100644 --- a/lib/portage/tests/bin/setup_env.py +++ b/lib/portage/tests/bin/setup_env.py @@ -1,5 +1,5 @@ # setup_env.py -- Make sure bin subdir has sane env for testing -# Copyright 2007-2013 Gentoo Foundation +# Copyright 2007-2024 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 import tempfile @@ -78,10 +78,7 @@ def portage_func(func, args, exit_status=0): f = open("/dev/null", "wb") fd_pipes = {0: 0, 1: f.fileno(), 2: f.fileno()} - def pre_exec(): - os.chdir(env["S"]) - - spawn([func] + args.split(), env=env, fd_pipes=fd_pipes, pre_exec=pre_exec) + spawn([func] + args.split(), env=env, fd_pipes=fd_pipes, cwd=env["S"]) f.close() diff --git a/lib/portage/tests/bin/test_doins.py b/lib/portage/tests/bin/test_doins.py index cb6b3a9dc..75a93ef9b 100644 --- a/lib/portage/tests/bin/test_doins.py +++ b/lib/portage/tests/bin/test_doins.py @@ -16,7 +16,7 @@ exists_in_D = setup_env.exists_in_D class DoIns(setup_env.BinTestCase): def testDoIns(self): - """Tests the most basic senario.""" + """Tests the most basic scenario.""" self.init() try: env = setup_env.env @@ -98,8 +98,8 @@ class DoIns(setup_env.BinTestCase): pass uid = os.lstat(os.path.join(env["S"], "test")).st_uid pw = pwd.getpwuid(uid) - # Similary to testDoInsOptionUid, use user name. - env["INSOPTIONS"] = "-o %s" % pw.pw_name + # Similarly to testDoInsOptionUid, use user name. + env["INSOPTIONS"] = f"-o {pw.pw_name}" doins("test") st = os.lstat(env["D"] + "/test") if st.st_uid != uid: @@ -115,7 +115,7 @@ class DoIns(setup_env.BinTestCase): with open(os.path.join(env["S"], "test"), "w"): pass gid = os.lstat(os.path.join(env["S"], "test")).st_gid - # Similary to testDoInsOptionUid, use gid. + # Similarly to testDoInsOptionUid, use gid. env["INSOPTIONS"] = "-g %d" % gid doins("test") st = os.lstat(env["D"] + "/test") @@ -133,8 +133,8 @@ class DoIns(setup_env.BinTestCase): pass gid = os.lstat(os.path.join(env["S"], "test")).st_gid gr = grp.getgrgid(gid) - # Similary to testDoInsOptionUid, use group name. - env["INSOPTIONS"] = "-g %s" % gr.gr_name + # Similarly to testDoInsOptionUid, use group name. + env["INSOPTIONS"] = f"-g {gr.gr_name}" doins("test") st = os.lstat(env["D"] + "/test") if st.st_gid != gid: diff --git a/lib/portage/tests/bin/test_eapi7_ver_funcs.py b/lib/portage/tests/bin/test_eapi7_ver_funcs.py index a01901e27..0483a35b3 100644 --- a/lib/portage/tests/bin/test_eapi7_ver_funcs.py +++ b/lib/portage/tests/bin/test_eapi7_ver_funcs.py @@ -14,9 +14,9 @@ class TestEAPI7VerFuncs(TestCase): Test that commands in test_cases produce expected output. """ with tempfile.NamedTemporaryFile("w") as test_script: - test_script.write('source "%s"/eapi7-ver-funcs.sh\n' % (PORTAGE_BIN_PATH,)) + test_script.write(f'source "{PORTAGE_BIN_PATH}"/eapi7-ver-funcs.sh\n') for cmd, exp in test_cases: - test_script.write("%s\n" % (cmd,)) + test_script.write(f"{cmd}\n") test_script.flush() s = subprocess.Popen( @@ -29,18 +29,16 @@ class TestEAPI7VerFuncs(TestCase): for test_case, result in zip(test_cases, sout.decode().splitlines()): cmd, exp = test_case - self.assertEqual( - result, exp, "%s -> %s; expected: %s" % (cmd, result, exp) - ) + self.assertEqual(result, exp, f"{cmd} -> {result}; expected: {exp}") def _test_return(self, test_cases): """ Test that commands in test_cases give appropriate exit codes. """ with tempfile.NamedTemporaryFile("w+") as test_script: - test_script.write('source "%s"/eapi7-ver-funcs.sh\n' % (PORTAGE_BIN_PATH,)) + test_script.write(f'source "{PORTAGE_BIN_PATH}"/eapi7-ver-funcs.sh\n') for cmd, exp in test_cases: - test_script.write("%s; echo $?\n" % (cmd,)) + test_script.write(f"{cmd}; echo $?\n") test_script.flush() s = subprocess.Popen( @@ -53,9 +51,7 @@ class TestEAPI7VerFuncs(TestCase): for test_case, result in zip(test_cases, sout.decode().splitlines()): cmd, exp = test_case - self.assertEqual( - result, exp, "%s -> %s; expected: %s" % (cmd, result, exp) - ) + self.assertEqual(result, exp, f"{cmd} -> {result}; expected: {exp}") def _test_fail(self, test_cases): """ @@ -63,13 +59,10 @@ class TestEAPI7VerFuncs(TestCase): """ for cmd in test_cases: - test = """ -source "%s"/eapi7-ver-funcs.sh -die() { exit 1; } -%s""" % ( - PORTAGE_BIN_PATH, - cmd, - ) + test = f""" +source "{PORTAGE_BIN_PATH}"/eapi7-ver-funcs.sh +die() {{ exit 1; }} +{cmd}""" s = subprocess.Popen( ["bash", "-c", test], stdout=subprocess.PIPE, stderr=subprocess.PIPE @@ -78,8 +71,7 @@ die() { exit 1; } self.assertEqual( s.returncode, 1, - '"%s" did not fail; output: %s; %s)' - % (cmd, sout.decode(), serr.decode()), + f'"{cmd}" did not fail; output: {sout.decode()}; {serr.decode()})', ) def test_ver_cut(self): diff --git a/lib/portage/tests/bin/test_filter_bash_env.py b/lib/portage/tests/bin/test_filter_bash_env.py index 7f0bdf52f..9040a5fef 100644 --- a/lib/portage/tests/bin/test_filter_bash_env.py +++ b/lib/portage/tests/bin/test_filter_bash_env.py @@ -1,4 +1,4 @@ -# Copyright 2018 Gentoo Foundation +# Copyright 2018-2023 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 import difflib @@ -12,11 +12,10 @@ from portage.tests import TestCase class TestFilterBashEnv(TestCase): def testTestFilterBashEnv(self): - test_cases = ( ( "RDEPEND BASH.* _EPATCH_ECLASS", - br"""declare -ir BASHPID="28997" + rb"""declare -ir BASHPID="28997" declare -rx A="portage-2.3.24.tar.bz2" declare -- DESKTOP_DATABASE_DIR="/usr/share/applications" declare PDEPEND=" @@ -34,12 +33,10 @@ declare -- _EUTILS_ECLASS="1" declare -- f get_libdir () { - local CONF_LIBDIR; - if [ -n "${CONF_LIBDIR_OVERRIDE}" ]; then - echo ${CONF_LIBDIR_OVERRIDE}; - else - get_abi_LIBDIR; - fi + local libdir_var="LIBDIR_${ABI}"; + local libdir="lib"; + [[ -n ${ABI} && -n ${!libdir_var} ]] && libdir=${!libdir_var}; + echo "${libdir}" } make_wrapper () { @@ -53,7 +50,7 @@ use_if_iuse () use $1 } """, - br"""declare -x A="portage-2.3.24.tar.bz2" + rb"""declare -x A="portage-2.3.24.tar.bz2" declare -- DESKTOP_DATABASE_DIR="/usr/share/applications" declare PDEPEND=" !build? ( @@ -66,12 +63,10 @@ declare -- _EUTILS_ECLASS="1" declare -- f get_libdir () { - local CONF_LIBDIR; - if [ -n "${CONF_LIBDIR_OVERRIDE}" ]; then - echo ${CONF_LIBDIR_OVERRIDE}; - else - get_abi_LIBDIR; - fi + local libdir_var="LIBDIR_${ABI}"; + local libdir="lib"; + [[ -n ${ABI} && -n ${!libdir_var} ]] && libdir=${!libdir_var}; + echo "${libdir}" } make_wrapper () { |