aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/portage/tests/ebuild/test_fetch.py')
-rw-r--r--lib/portage/tests/ebuild/test_fetch.py92
1 files changed, 45 insertions, 47 deletions
diff --git a/lib/portage/tests/ebuild/test_fetch.py b/lib/portage/tests/ebuild/test_fetch.py
index cfca0d4e1..4812eb430 100644
--- a/lib/portage/tests/ebuild/test_fetch.py
+++ b/lib/portage/tests/ebuild/test_fetch.py
@@ -1,4 +1,4 @@
-# Copyright 2019-2021 Gentoo Authors
+# Copyright 2019-2023 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
import functools
@@ -36,7 +36,6 @@ from _emerge.Package import Package
class EbuildFetchTestCase(TestCase):
def testEbuildFetch(self):
-
user_config = {
"make.conf": ('GENTOO_MIRRORS="{scheme}://{host}:{port}"',),
}
@@ -71,7 +70,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(
@@ -135,7 +133,7 @@ class EbuildFetchTestCase(TestCase):
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)))
@@ -143,9 +141,7 @@ class EbuildFetchTestCase(TestCase):
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 +158,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 +167,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 +178,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 +199,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 +246,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 +278,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 +335,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 +440,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 +563,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 +577,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 +615,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 +729,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 +836,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 +871,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