aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/portage/tests/ebuild')
-rw-r--r--lib/portage/tests/ebuild/meson.build17
-rw-r--r--lib/portage/tests/ebuild/test_array_fromfile_eof.py2
-rw-r--r--lib/portage/tests/ebuild/test_config.py10
-rw-r--r--lib/portage/tests/ebuild/test_doebuild_fd_pipes.py136
-rw-r--r--lib/portage/tests/ebuild/test_doebuild_spawn.py6
-rw-r--r--lib/portage/tests/ebuild/test_fetch.py97
-rw-r--r--lib/portage/tests/ebuild/test_ipc_daemon.py33
-rw-r--r--lib/portage/tests/ebuild/test_shell_quote.py2
-rw-r--r--lib/portage/tests/ebuild/test_spawn.py10
-rw-r--r--lib/portage/tests/ebuild/test_use_expand_incremental.py8
10 files changed, 177 insertions, 144 deletions
diff --git a/lib/portage/tests/ebuild/meson.build b/lib/portage/tests/ebuild/meson.build
new file mode 100644
index 000000000..0c4407c70
--- /dev/null
+++ b/lib/portage/tests/ebuild/meson.build
@@ -0,0 +1,17 @@
+py.install_sources(
+ [
+ 'test_array_fromfile_eof.py',
+ 'test_config.py',
+ 'test_doebuild_fd_pipes.py',
+ 'test_doebuild_spawn.py',
+ 'test_fetch.py',
+ 'test_ipc_daemon.py',
+ 'test_shell_quote.py',
+ 'test_spawn.py',
+ 'test_use_expand_incremental.py',
+ '__init__.py',
+ '__test__.py',
+ ],
+ subdir : 'portage/tests/ebuild',
+ pure : not native_extensions
+)
diff --git a/lib/portage/tests/ebuild/test_array_fromfile_eof.py b/lib/portage/tests/ebuild/test_array_fromfile_eof.py
index 2054eee42..282a613be 100644
--- a/lib/portage/tests/ebuild/test_array_fromfile_eof.py
+++ b/lib/portage/tests/ebuild/test_array_fromfile_eof.py
@@ -27,7 +27,7 @@ class ArrayFromfileEofTestCase(TestCase):
a = array.array("B")
try:
a.fromfile(f, len(input_bytes) + 1)
- except (EOFError, IOError):
+ except (EOFError, OSError):
# python-3.0 lost data here
eof = True
diff --git a/lib/portage/tests/ebuild/test_config.py b/lib/portage/tests/ebuild/test_config.py
index d123d9abb..743b30bfb 100644
--- a/lib/portage/tests/ebuild/test_config.py
+++ b/lib/portage/tests/ebuild/test_config.py
@@ -1,7 +1,6 @@
# Copyright 2010-2020 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
-import io
import tempfile
import portage
@@ -84,7 +83,6 @@ class ConfigTestCase(TestCase):
playground.cleanup()
def testLicenseManager(self):
-
user_config = {
"package.license": (
"dev-libs/* TEST",
@@ -112,7 +110,7 @@ class ConfigTestCase(TestCase):
self.assertEqual(lic_man._accept_license_str, None)
self.assertEqual(lic_man._accept_license, None)
self.assertEqual(lic_man._license_groups, {"EULA": frozenset(["TEST"])})
- self.assertEqual(lic_man._undef_lic_groups, set(["TEST"]))
+ self.assertEqual(lic_man._undef_lic_groups, {"TEST"})
self.assertEqual(lic_man.extract_global_changes(), "TEST TEST2")
self.assertEqual(lic_man.extract_global_changes(), "")
@@ -196,7 +194,6 @@ class ConfigTestCase(TestCase):
playground.cleanup()
def testPackageMaskOrder(self):
-
ebuilds = {
"dev-libs/A-1": {},
"dev-libs/B-1": {},
@@ -263,7 +260,6 @@ class ConfigTestCase(TestCase):
playground.cleanup()
def testManifest(self):
-
distfiles = {
"B-2.tar.bz2": b"binary\0content",
"C-2.zip": b"binary\0content",
@@ -370,7 +366,7 @@ class ConfigTestCase(TestCase):
user_config_dir = os.path.join(eprefix, USER_CONFIG_PATH)
os.makedirs(user_config_dir)
- with io.open(
+ with open(
os.path.join(user_config_dir, "package.env"),
mode="w",
encoding=_encodings["content"],
@@ -381,7 +377,7 @@ class ConfigTestCase(TestCase):
env_dir = os.path.join(user_config_dir, "env")
os.makedirs(env_dir)
for k, v in env_files.items():
- with io.open(
+ with open(
os.path.join(env_dir, k), mode="w", encoding=_encodings["content"]
) as f:
for line in v:
diff --git a/lib/portage/tests/ebuild/test_doebuild_fd_pipes.py b/lib/portage/tests/ebuild/test_doebuild_fd_pipes.py
index e0c75c872..445fcf6c4 100644
--- a/lib/portage/tests/ebuild/test_doebuild_fd_pipes.py
+++ b/lib/portage/tests/ebuild/test_doebuild_fd_pipes.py
@@ -1,6 +1,8 @@
-# Copyright 2013-2016 Gentoo Foundation
+# Copyright 2013-2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
+import multiprocessing
+
import portage
from portage import os
from portage.tests import TestCase
@@ -12,15 +14,9 @@ from _emerge.Package import Package
from _emerge.PipeReader import PipeReader
-class DoebuildProcess(ForkProcess):
-
- __slots__ = ("doebuild_kwargs", "doebuild_pargs")
-
- def _run(self):
- return portage.doebuild(*self.doebuild_pargs, **self.doebuild_kwargs)
-
-
class DoebuildFdPipesTestCase(TestCase):
+ output_fd = 200
+
def testDoebuild(self):
"""
Invoke portage.doebuild() with the fd_pipes parameter, and
@@ -29,22 +25,24 @@ class DoebuildFdPipesTestCase(TestCase):
supported for API consumers (see bug #475812).
"""
- output_fd = 200
+ output_fd = self.output_fd
ebuild_body = ["S=${WORKDIR}"]
- for phase_func in (
- "pkg_info",
- "pkg_nofetch",
- "pkg_pretend",
- "pkg_setup",
- "src_unpack",
- "src_prepare",
- "src_configure",
- "src_compile",
- "src_test",
- "src_install",
+ for phase_func, default in (
+ ("pkg_info", False),
+ ("pkg_nofetch", False),
+ ("pkg_pretend", False),
+ ("pkg_setup", False),
+ ("pkg_config", False),
+ ("src_unpack", False),
+ ("src_prepare", True),
+ ("src_configure", False),
+ ("src_compile", False),
+ ("src_test", False),
+ ("src_install", False),
):
ebuild_body.append(
- ("%s() { echo ${EBUILD_PHASE}" " 1>&%s; }") % (phase_func, output_fd)
+ ("%s() { %secho ${EBUILD_PHASE}" " 1>&%s; }")
+ % (phase_func, "default; " if default else "", output_fd)
)
ebuild_body.append("")
@@ -52,11 +50,24 @@ class DoebuildFdPipesTestCase(TestCase):
ebuilds = {
"app-misct/foo-1": {
- "EAPI": "5",
+ "EAPI": "8",
+ "IUSE": "+foo +bar",
+ "REQUIRED_USE": "|| ( foo bar )",
"MISC_CONTENT": ebuild_body,
}
}
+ # Populate configdict["pkg"]["USE"] with something arbitrary in order
+ # to try and trigger bug 675748 in doebuild _validate_deps.
+ arbitrary_package_use = "baz"
+
+ user_config = {
+ # In order to trigger bug 675748, package.env must be non-empty,
+ # but the referenced env file can be empty.
+ "package.env": (f"app-misct/foo {os.devnull}",),
+ "package.use": (f"app-misct/foo {arbitrary_package_use}",),
+ }
+
# Override things that may be unavailable, or may have portability
# issues when running tests in exotic environments.
# prepstrip - bug #447810 (bash read builtin EINTR problem)
@@ -65,7 +76,7 @@ class DoebuildFdPipesTestCase(TestCase):
self.assertEqual(true_binary is None, False, "true command not found")
dev_null = open(os.devnull, "wb")
- playground = ResolverPlayground(ebuilds=ebuilds)
+ playground = ResolverPlayground(ebuilds=ebuilds, user_config=user_config)
try:
QueryCommand._db = playground.trees
root_config = playground.trees[playground.eroot]["root_config"]
@@ -107,39 +118,50 @@ class DoebuildFdPipesTestCase(TestCase):
type_name="ebuild",
)
settings.setcpv(pkg)
- ebuildpath = portdb.findname(cpv)
- self.assertNotEqual(ebuildpath, None)
-
- for phase in (
- "info",
- "nofetch",
- "pretend",
- "setup",
- "unpack",
- "prepare",
- "configure",
- "compile",
- "test",
- "install",
- "qmerge",
- "clean",
- "merge",
+
+ # Demonstrate that settings.configdict["pkg"]["USE"] contains our arbitrary
+ # package.use setting in order to trigger bug 675748.
+ self.assertEqual(settings.configdict["pkg"]["USE"], arbitrary_package_use)
+
+ # Try to trigger the config.environ() split_LC_ALL assertion for bug 925863.
+ settings["LC_ALL"] = "C"
+
+ source_ebuildpath = portdb.findname(cpv)
+ self.assertNotEqual(source_ebuildpath, None)
+
+ for phase, tree, ebuildpath in (
+ ("info", "porttree", source_ebuildpath),
+ ("nofetch", "porttree", source_ebuildpath),
+ ("pretend", "porttree", source_ebuildpath),
+ ("setup", "porttree", source_ebuildpath),
+ ("unpack", "porttree", source_ebuildpath),
+ ("prepare", "porttree", source_ebuildpath),
+ ("configure", "porttree", source_ebuildpath),
+ ("compile", "porttree", source_ebuildpath),
+ ("test", "porttree", source_ebuildpath),
+ ("install", "porttree", source_ebuildpath),
+ ("qmerge", "porttree", source_ebuildpath),
+ ("clean", "porttree", source_ebuildpath),
+ ("merge", "porttree", source_ebuildpath),
+ ("clean", "porttree", source_ebuildpath),
+ ("config", "vartree", root_config.trees["vartree"].dbapi.findname(cpv)),
):
+ if ebuildpath is not source_ebuildpath:
+ self.assertNotEqual(ebuildpath, None)
- pr, pw = os.pipe()
+ pr, pw = multiprocessing.Pipe(duplex=False)
- producer = DoebuildProcess(
- doebuild_pargs=(ebuildpath, phase),
- doebuild_kwargs={
+ producer = ForkProcess(
+ target=self._doebuild,
+ fd_pipes={
+ 1: dev_null.fileno(),
+ },
+ args=(QueryCommand._db, pw, ebuildpath, phase),
+ kwargs={
"settings": settings,
- "mydbapi": portdb,
- "tree": "porttree",
+ "mydbapi": root_config.trees[tree].dbapi,
+ "tree": tree,
"vartree": root_config.trees["vartree"],
- "fd_pipes": {
- 1: dev_null.fileno(),
- 2: dev_null.fileno(),
- output_fd: pw,
- },
"prev_mtimes": {},
},
)
@@ -152,7 +174,7 @@ class DoebuildFdPipesTestCase(TestCase):
task_scheduler.start()
finally:
# PipeReader closes pr
- os.close(pw)
+ pw.close()
task_scheduler.wait()
output = portage._unicode_decode(consumer.getvalue()).rstrip("\n")
@@ -169,3 +191,11 @@ class DoebuildFdPipesTestCase(TestCase):
dev_null.close()
playground.cleanup()
QueryCommand._db = None
+
+ @staticmethod
+ def _doebuild(db, pw, *args, **kwargs):
+ QueryCommand._db = db
+ kwargs["fd_pipes"] = {
+ DoebuildFdPipesTestCase.output_fd: pw.fileno(),
+ }
+ return portage.doebuild(*args, **kwargs)
diff --git a/lib/portage/tests/ebuild/test_doebuild_spawn.py b/lib/portage/tests/ebuild/test_doebuild_spawn.py
index ef0ae5847..cac844f8f 100644
--- a/lib/portage/tests/ebuild/test_doebuild_spawn.py
+++ b/lib/portage/tests/ebuild/test_doebuild_spawn.py
@@ -1,4 +1,4 @@
-# Copyright 2010-2015 Gentoo Foundation
+# Copyright 2010-2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
import textwrap
@@ -28,7 +28,6 @@ class DoebuildSpawnTestCase(TestCase):
"""
def testDoebuildSpawn(self):
-
ebuild_body = textwrap.dedent(
"""
pkg_nofetch() { : ; }
@@ -81,13 +80,14 @@ class DoebuildSpawnTestCase(TestCase):
settings["T"] = os.path.join(settings["PORTAGE_BUILDDIR"], "temp")
for x in ("PORTAGE_BUILDDIR", "HOME", "T"):
os.makedirs(settings[x])
+ os.makedirs(os.path.join(settings["PORTAGE_BUILDDIR"], ".ipc"))
# Create a fake environment, to pretend as if the ebuild
# has been sourced already.
open(os.path.join(settings["T"], "environment"), "wb").close()
scheduler = SchedulerInterface(global_event_loop())
+ self.assertTrue(scheduler._loop is global_event_loop()._loop)
for phase in ("_internal_test",):
-
# Test EbuildSpawnProcess by calling doebuild.spawn() with
# returnpid=False. This case is no longer used by portage
# internals since EbuildPhase is used instead and that passes
diff --git a/lib/portage/tests/ebuild/test_fetch.py b/lib/portage/tests/ebuild/test_fetch.py
index cfca0d4e1..1856bb52b 100644
--- a/lib/portage/tests/ebuild/test_fetch.py
+++ b/lib/portage/tests/ebuild/test_fetch.py
@@ -1,8 +1,9 @@
-# Copyright 2019-2021 Gentoo Authors
+# Copyright 2019-2023 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
import functools
import io
+import shlex
import tempfile
import types
@@ -36,7 +37,6 @@ from _emerge.Package import Package
class EbuildFetchTestCase(TestCase):
def testEbuildFetch(self):
-
user_config = {
"make.conf": ('GENTOO_MIRRORS="{scheme}://{host}:{port}"',),
}
@@ -71,7 +71,6 @@ class EbuildFetchTestCase(TestCase):
user_config_subst = user_config.copy()
for configname, configdata in user_config.items():
-
configdata_sub = []
for line in configdata:
configdata_sub.append(
@@ -131,21 +130,19 @@ class EbuildFetchTestCase(TestCase):
),
)
- fetchcommand = portage.util.shlex_split(playground.settings["FETCHCOMMAND"])
+ fetchcommand = shlex.split(playground.settings["FETCHCOMMAND"])
fetch_bin = portage.process.find_binary(fetchcommand[0])
if fetch_bin is None:
self.skipTest(
- "FETCHCOMMAND not found: {}".format(playground.settings["FETCHCOMMAND"])
+ f"FETCHCOMMAND not found: {playground.settings['FETCHCOMMAND']}"
)
eubin = os.path.join(playground.eprefix, "usr", "bin")
os.symlink(fetch_bin, os.path.join(eubin, os.path.basename(fetch_bin)))
- resumecommand = portage.util.shlex_split(playground.settings["RESUMECOMMAND"])
+ resumecommand = shlex.split(playground.settings["RESUMECOMMAND"])
resume_bin = portage.process.find_binary(resumecommand[0])
if resume_bin is None:
self.skipTest(
- "RESUMECOMMAND not found: {}".format(
- playground.settings["RESUMECOMMAND"]
- )
+ f"RESUMECOMMAND not found: {playground.settings['RESUMECOMMAND']}"
)
if resume_bin != fetch_bin:
os.symlink(resume_bin, os.path.join(eubin, os.path.basename(resume_bin)))
@@ -162,7 +159,7 @@ class EbuildFetchTestCase(TestCase):
for layout_lines in mirror_layouts:
settings = config(clone=playground.settings)
- layout_data = "".join("{}\n".format(line) for line in layout_lines)
+ layout_data = "".join(f"{line}\n" for line in layout_lines)
mirror_conf = MirrorLayoutConfig()
mirror_conf.read_from_file(io.StringIO(layout_data))
layouts = mirror_conf.get_all_layouts()
@@ -171,10 +168,10 @@ class EbuildFetchTestCase(TestCase):
for k, v in orig_distfiles.items():
filename = DistfileName(
k,
- digests=dict(
- (algo, checksum_str(v, hashname=algo))
+ digests={
+ algo: checksum_str(v, hashname=algo)
for algo in MANIFEST2_HASH_DEFAULTS
- ),
+ },
)
distfiles[filename] = v
@@ -182,11 +179,11 @@ class EbuildFetchTestCase(TestCase):
for layout in layouts:
content["/distfiles/" + layout.get_path(filename)] = v
# upstream path
- content["/distfiles/{}.txt".format(k)] = v
+ content[f"/distfiles/{k}.txt"] = v
shutil.rmtree(settings["DISTDIR"])
os.makedirs(settings["DISTDIR"])
- with open(os.path.join(settings["DISTDIR"], "layout.conf"), "wt") as f:
+ with open(os.path.join(settings["DISTDIR"], "layout.conf"), "w") as f:
f.write(layout_data)
if any(isinstance(layout, ContentHashLayout) for layout in layouts):
@@ -203,11 +200,7 @@ class EbuildFetchTestCase(TestCase):
# Demonstrate that fetch preserves a stale file in DISTDIR when no digests are given.
foo_uri = {
- "foo": (
- "{scheme}://{host}:{port}/distfiles/foo".format(
- scheme=scheme, host=host, port=server.server_port
- ),
- )
+ "foo": (f"{scheme}://{host}:{server.server_port}/distfiles/foo",)
}
foo_path = os.path.join(settings["DISTDIR"], "foo")
foo_stale_content = b"stale content\n"
@@ -254,9 +247,11 @@ class EbuildFetchTestCase(TestCase):
"""
% orig_fetchcommand.replace("${FILE}", "${FILE}.__download__")
)
- settings["FETCHCOMMAND"] = '"%s" "%s" "${URI}" "${DISTDIR}" "${FILE}"' % (
- BASH_BINARY,
- temp_fetchcommand,
+ settings["FETCHCOMMAND"] = (
+ '"{}" "{}" "${{URI}}" "${{DISTDIR}}" "${{FILE}}"'.format(
+ BASH_BINARY,
+ temp_fetchcommand,
+ )
)
settings.features.add("skiprocheck")
settings.features.remove("distlocks")
@@ -284,7 +279,7 @@ class EbuildFetchTestCase(TestCase):
portage._python_interpreter,
"-b",
"-Wd",
- os.path.join(self.bindir, "emirrordist"),
+ os.path.join(str(self.bindir), "emirrordist"),
"--distfiles",
settings["DISTDIR"],
"--config-root",
@@ -341,16 +336,7 @@ class EbuildFetchTestCase(TestCase):
)
)
- # Tests only work with one ebuild at a time, so the config
- # pool only needs a single config instance.
- class config_pool:
- @staticmethod
- def allocate():
- return settings
-
- @staticmethod
- def deallocate(settings):
- pass
+ config_pool = config_pool_cls(settings)
def async_fetch(pkg, ebuild_path):
fetcher = EbuildFetcher(
@@ -455,7 +441,7 @@ class EbuildFetchTestCase(TestCase):
self.assertEqual(f.read(), distfiles[k])
# Test PORTAGE_RO_DISTDIRS
- settings["PORTAGE_RO_DISTDIRS"] = '"{}"'.format(ro_distdir)
+ settings["PORTAGE_RO_DISTDIRS"] = f'"{ro_distdir}"'
orig_fetchcommand = settings["FETCHCOMMAND"]
orig_resumecommand = settings["RESUMECOMMAND"]
try:
@@ -578,13 +564,13 @@ class EbuildFetchTestCase(TestCase):
emdisopts, portdb, asyncio.get_event_loop()
) as emdisconf:
# Copy revisions from bar to foo.
- for revision_key in emdisconf.content_db["filename:{}".format("bar")]:
+ for revision_key in emdisconf.content_db["filename:bar"]:
emdisconf.content_db.add(
DistfileName("foo", digests=dict(revision_key))
)
# Copy revisions from foo to bar.
- for revision_key in emdisconf.content_db["filename:{}".format("foo")]:
+ for revision_key in emdisconf.content_db["filename:foo"]:
emdisconf.content_db.add(
DistfileName("bar", digests=dict(revision_key))
)
@@ -592,12 +578,12 @@ class EbuildFetchTestCase(TestCase):
content_db_state = dict(emdisconf.content_db.items())
self.assertEqual(content_db_state, dict(emdisconf.content_db.items()))
self.assertEqual(
- [
+ {
k[len("filename:") :]
for k in content_db_state
if k.startswith("filename:")
- ],
- ["bar", "foo"],
+ },
+ {"bar", "foo"},
)
self.assertEqual(
content_db_state["filename:foo"], content_db_state["filename:bar"]
@@ -630,12 +616,12 @@ class EbuildFetchTestCase(TestCase):
emdisconf.content_db.remove(filename)
# foo should still have a content revision corresponding to bar's content.
self.assertEqual(
- [
+ {
k[len("filename:") :]
for k in emdisconf.content_db
if k.startswith("filename:")
- ],
- ["bar", "foo"],
+ },
+ {"bar", "foo"},
)
self.assertEqual(len(emdisconf.content_db["filename:foo"]), 1)
self.assertEqual(
@@ -744,10 +730,10 @@ class EbuildFetchTestCase(TestCase):
filename = DistfileName(
"foo-1.tar.gz",
- digests=dict(
- (algo, checksum_str(b"", hashname=algo))
+ digests={
+ algo: checksum_str(b"", hashname=algo)
for algo in MANIFEST2_HASH_DEFAULTS
- ),
+ },
)
# Raise KeyError for a hash algorithm SHA1 which is not in MANIFEST2_HASH_DEFAULTS.
@@ -851,10 +837,10 @@ class EbuildFetchTestCase(TestCase):
def test_filename_hash_layout_get_filenames(self):
filename = DistfileName(
"foo-1.tar.gz",
- digests=dict(
- (algo, checksum_str(b"", hashname=algo))
+ digests={
+ algo: checksum_str(b"", hashname=algo)
for algo in MANIFEST2_HASH_DEFAULTS
- ),
+ },
)
layouts = (
FlatLayout(),
@@ -886,3 +872,16 @@ class EbuildFetchTestCase(TestCase):
self.assertEqual(filename_result, str(filename))
finally:
shutil.rmtree(distdir)
+
+
+# Tests only work with one ebuild at a time, so the config
+# pool only needs a single config instance.
+class config_pool_cls:
+ def __init__(self, settings):
+ self._settings = settings
+
+ def allocate(self):
+ return self._settings
+
+ def deallocate(self, settings):
+ pass
diff --git a/lib/portage/tests/ebuild/test_ipc_daemon.py b/lib/portage/tests/ebuild/test_ipc_daemon.py
index e20b6fff1..b8777fe94 100644
--- a/lib/portage/tests/ebuild/test_ipc_daemon.py
+++ b/lib/portage/tests/ebuild/test_ipc_daemon.py
@@ -1,4 +1,4 @@
-# Copyright 2010-2016 Gentoo Foundation
+# Copyright 2010-2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
import tempfile
@@ -21,20 +21,7 @@ from _emerge.EbuildBuildDir import EbuildBuildDir
from _emerge.EbuildIpcDaemon import EbuildIpcDaemon
-class SleepProcess(ForkProcess):
- """
- Emulate the sleep command, in order to ensure a consistent
- return code when it is killed by SIGTERM (see bug #437180).
- """
-
- __slots__ = ("seconds",)
-
- def _run(self):
- time.sleep(self.seconds)
-
-
class IpcDaemonTestCase(TestCase):
-
_SCHEDULE_TIMEOUT = 40 # seconds
def testIpcDaemon(self):
@@ -66,10 +53,10 @@ class IpcDaemonTestCase(TestCase):
build_dir = EbuildBuildDir(scheduler=event_loop, settings=env)
event_loop.run_until_complete(build_dir.async_lock())
- ensure_dirs(env["PORTAGE_BUILDDIR"])
+ ensure_dirs(os.path.join(env["PORTAGE_BUILDDIR"], ".ipc"))
- input_fifo = os.path.join(env["PORTAGE_BUILDDIR"], ".ipc_in")
- output_fifo = os.path.join(env["PORTAGE_BUILDDIR"], ".ipc_out")
+ input_fifo = os.path.join(env["PORTAGE_BUILDDIR"], ".ipc", "in")
+ output_fifo = os.path.join(env["PORTAGE_BUILDDIR"], ".ipc", "out")
os.mkfifo(input_fifo)
os.mkfifo(output_fifo)
@@ -90,6 +77,7 @@ class IpcDaemonTestCase(TestCase):
task_scheduler = TaskScheduler(
iter([daemon, proc]), max_jobs=2, event_loop=event_loop
)
+ self.assertTrue(task_scheduler._loop is event_loop._loop)
self.received_command = False
@@ -125,7 +113,9 @@ class IpcDaemonTestCase(TestCase):
daemon = EbuildIpcDaemon(
commands=commands, input_fifo=input_fifo, output_fifo=output_fifo
)
- proc = SleepProcess(seconds=sleep_time_s)
+ # Emulate the sleep command, in order to ensure a consistent
+ # return code when it is killed by SIGTERM (see bug #437180).
+ proc = ForkProcess(target=time.sleep, args=(sleep_time_s,))
task_scheduler = TaskScheduler(
iter([daemon, proc]), max_jobs=2, event_loop=event_loop
)
@@ -171,8 +161,13 @@ class IpcDaemonTestCase(TestCase):
)
task_scheduler.addExitListener(self._exit_callback)
- try:
+ async def start_task_scheduler():
+ # This fails unless the event loop is running, since it needs
+ # the loop to setup a ChildWatcher.
task_scheduler.start()
+
+ try:
+ event_loop.run_until_complete(start_task_scheduler())
event_loop.run_until_complete(self._run_done)
event_loop.run_until_complete(task_scheduler.async_wait())
finally:
diff --git a/lib/portage/tests/ebuild/test_shell_quote.py b/lib/portage/tests/ebuild/test_shell_quote.py
index 7c9cb6428..885ff34b9 100644
--- a/lib/portage/tests/ebuild/test_shell_quote.py
+++ b/lib/portage/tests/ebuild/test_shell_quote.py
@@ -101,6 +101,6 @@ class ShellQuoteTestCase(TestCase):
("?abcxyz?", '"?abcxyz?"'),
]
- for (data, expected_result) in test_data:
+ for data, expected_result in test_data:
result = _shell_quote(data)
self.assertEqual(result, expected_result)
diff --git a/lib/portage/tests/ebuild/test_spawn.py b/lib/portage/tests/ebuild/test_spawn.py
index ad8e121db..c73171f04 100644
--- a/lib/portage/tests/ebuild/test_spawn.py
+++ b/lib/portage/tests/ebuild/test_spawn.py
@@ -2,7 +2,6 @@
# Distributed under the terms of the GNU General Public License v2
import errno
-import io
import tempfile
import portage
from portage import os
@@ -23,7 +22,7 @@ class SpawnTestCase(TestCase):
null_fd = os.open("/dev/null", os.O_RDWR)
test_string = 2 * "blah blah blah\n"
proc = SpawnProcess(
- args=[BASH_BINARY, "-c", "echo -n '%s'" % test_string],
+ args=[BASH_BINARY, "-c", f"echo -n '{test_string}'"],
env={},
fd_pipes={0: portage._get_stdin().fileno(), 1: null_fd, 2: null_fd},
scheduler=global_event_loop(),
@@ -32,9 +31,8 @@ class SpawnTestCase(TestCase):
proc.start()
os.close(null_fd)
self.assertEqual(proc.wait(), os.EX_OK)
- f = io.open(
+ f = open(
_unicode_encode(logfile, encoding=_encodings["fs"], errors="strict"),
- mode="r",
encoding=_encodings["content"],
errors="strict",
)
@@ -42,14 +40,14 @@ class SpawnTestCase(TestCase):
f.close()
# When logging passes through a pty, this comparison will fail
# unless the oflag terminal attributes have the termios.OPOST
- # bit disabled. Otherwise, tranformations such as \n -> \r\n
+ # bit disabled. Otherwise, transformations such as \n -> \r\n
# may occur.
self.assertEqual(test_string, log_content)
finally:
if logfile:
try:
os.unlink(logfile)
- except EnvironmentError as e:
+ except OSError as e:
if e.errno != errno.ENOENT:
raise
del e
diff --git a/lib/portage/tests/ebuild/test_use_expand_incremental.py b/lib/portage/tests/ebuild/test_use_expand_incremental.py
index 23c8d17b3..a4d24425f 100644
--- a/lib/portage/tests/ebuild/test_use_expand_incremental.py
+++ b/lib/portage/tests/ebuild/test_use_expand_incremental.py
@@ -1,7 +1,6 @@
# Copyright 2014 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-import io
from portage import os, _encodings
from portage.dep import Atom
@@ -13,7 +12,6 @@ from portage.util import ensure_dirs
class UseExpandIncrementalTestCase(TestCase):
def testUseExpandIncremental(self):
-
profiles = (
(
"base",
@@ -100,13 +98,13 @@ class UseExpandIncrementalTestCase(TestCase):
prof_path = os.path.join(profile_root, p)
ensure_dirs(prof_path)
for k, v in data.items():
- with io.open(
+ with open(
os.path.join(prof_path, k),
mode="w",
encoding=_encodings["repo.content"],
) as f:
for line in v:
- f.write("%s\n" % line)
+ f.write(f"{line}\n")
# The config must be reloaded in order to account
# for the above profile customizations.
@@ -122,7 +120,7 @@ class UseExpandIncrementalTestCase(TestCase):
settings.setcpv(pkg)
expected = frozenset(expected_use)
got = frozenset(settings["PORTAGE_USE"].split())
- self.assertEqual(got, expected, "%s != %s" % (got, expected))
+ self.assertEqual(got, expected, f"{got} != {expected}")
finally:
playground.cleanup()