* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/ebuild/
@ 2019-10-19 1:38 Zac Medico
0 siblings, 0 replies; 11+ messages in thread
From: Zac Medico @ 2019-10-19 1:38 UTC (permalink / raw
To: gentoo-commits
commit: ab481a27e3a672ec762140f9d7cc6be883665a7b
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sat Oct 19 01:32:45 2019 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sat Oct 19 01:36:15 2019 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=ab481a27
testEbuildFetch: add mirror support
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
lib/portage/tests/ebuild/test_fetch.py | 25 +++++++++++++++++++++++--
1 file changed, 23 insertions(+), 2 deletions(-)
diff --git a/lib/portage/tests/ebuild/test_fetch.py b/lib/portage/tests/ebuild/test_fetch.py
index ac45f8720..c0a76b701 100644
--- a/lib/portage/tests/ebuild/test_fetch.py
+++ b/lib/portage/tests/ebuild/test_fetch.py
@@ -29,6 +29,13 @@ class EbuildFetchTestCase(TestCase):
def testEbuildFetch(self):
+ user_config = {
+ "make.conf":
+ (
+ 'GENTOO_MIRRORS="{scheme}://{host}:{port}"',
+ ),
+ }
+
distfiles = {
'bar': b'bar\n',
'foo': b'foo\n',
@@ -37,7 +44,6 @@ class EbuildFetchTestCase(TestCase):
ebuilds = {
'dev-libs/A-1': {
'EAPI': '7',
- 'RESTRICT': 'primaryuri',
'SRC_URI': '''{scheme}://{host}:{port}/distfiles/bar.txt -> bar
{scheme}://{host}:{port}/distfiles/foo.txt -> foo''',
},
@@ -47,7 +53,13 @@ class EbuildFetchTestCase(TestCase):
scheme = 'http'
host = '127.0.0.1'
content = {}
+
+ content['/distfiles/layout.conf'] = b'[structure]\n0=flat\n'
+
for k, v in distfiles.items():
+ # mirror path
+ content['/distfiles/{}'.format(k)] = v
+ # upstream path
content['/distfiles/{}.txt'.format(k)] = v
with AsyncHTTPServer(host, content, loop) as server:
@@ -58,7 +70,16 @@ class EbuildFetchTestCase(TestCase):
scheme=scheme, host=host, port=server.server_port)
ebuilds_subst[cpv] = metadata
- playground = ResolverPlayground(ebuilds=ebuilds_subst, distfiles=distfiles)
+ user_config_subst = user_config.copy()
+ for configname, configdata in user_config.items():
+
+ configdata_sub = []
+ for line in configdata:
+ configdata_sub.append(line.format(
+ scheme=scheme, host=host, port=server.server_port))
+ user_config_subst[configname] = tuple(configdata_sub)
+
+ playground = ResolverPlayground(ebuilds=ebuilds_subst, distfiles=distfiles, user_config=user_config_subst)
ro_distdir = tempfile.mkdtemp()
eubin = os.path.join(playground.eprefix, "usr", "bin")
try:
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/ebuild/
@ 2019-10-19 5:29 Zac Medico
0 siblings, 0 replies; 11+ messages in thread
From: Zac Medico @ 2019-10-19 5:29 UTC (permalink / raw
To: gentoo-commits
commit: 4331274f2faca6052f771eb2c4840afd25efa58c
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sat Oct 19 05:25:27 2019 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sat Oct 19 05:27:20 2019 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=4331274f
testEbuildFetch: test emirrordist invocation
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
lib/portage/tests/ebuild/test_fetch.py | 24 +++++++++++++++++++++++-
1 file changed, 23 insertions(+), 1 deletion(-)
diff --git a/lib/portage/tests/ebuild/test_fetch.py b/lib/portage/tests/ebuild/test_fetch.py
index c0a76b701..da63d9dea 100644
--- a/lib/portage/tests/ebuild/test_fetch.py
+++ b/lib/portage/tests/ebuild/test_fetch.py
@@ -9,11 +9,12 @@ import tempfile
import portage
from portage import shutil, os
-from portage.const import BASH_BINARY
+from portage.const import BASH_BINARY, PORTAGE_PYM_PATH
from portage.tests import TestCase
from portage.tests.resolver.ResolverPlayground import ResolverPlayground
from portage.tests.util.test_socks5 import AsyncHTTPServer
from portage.util.configparser import ConfigParserError
+from portage.util.futures import asyncio
from portage.util.futures.executor.fork import ForkExecutor
from portage.util._async.SchedulerInterface import SchedulerInterface
from portage.util._eventloop.global_event_loop import global_event_loop
@@ -98,6 +99,27 @@ class EbuildFetchTestCase(TestCase):
portdb = root_config.trees["porttree"].dbapi
settings = config(clone=playground.settings)
+ emirrordist_cmd = (portage._python_interpreter, '-b', '-Wd',
+ os.path.join(self.bindir, 'emirrordist'),
+ '--distfiles', settings['DISTDIR'],
+ '--config-root', settings['EPREFIX'],
+ '--repositories-configuration', settings.repositories.config_string(),
+ '--repo', 'test_repo', '--mirror')
+
+ env = os.environ.copy()
+ env['PYTHONPATH'] = ':'.join(
+ filter(None, [PORTAGE_PYM_PATH] + os.environ.get('PYTHONPATH', '').split(':')))
+
+ for k in distfiles:
+ os.unlink(os.path.join(settings['DISTDIR'], k))
+
+ proc = loop.run_until_complete(asyncio.create_subprocess_exec(*emirrordist_cmd, env=env))
+ self.assertEqual(loop.run_until_complete(proc.wait()), 0)
+
+ for k in distfiles:
+ with open(os.path.join(settings['DISTDIR'], k), 'rb') as f:
+ self.assertEqual(f.read(), distfiles[k])
+
# Tests only work with one ebuild at a time, so the config
# pool only needs a single config instance.
class config_pool:
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/ebuild/
@ 2019-10-19 23:15 Zac Medico
0 siblings, 0 replies; 11+ messages in thread
From: Zac Medico @ 2019-10-19 23:15 UTC (permalink / raw
To: gentoo-commits
commit: 491b3ff4d35194765c8ee93c6a438097551fd07e
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sat Oct 19 23:12:46 2019 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sat Oct 19 23:13:30 2019 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=491b3ff4
testEbuildFetch: demonstrate fetch behavior with stale file and no digests
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
lib/portage/tests/ebuild/test_fetch.py | 31 ++++++++++++++++++++++++++++++-
1 file changed, 30 insertions(+), 1 deletion(-)
diff --git a/lib/portage/tests/ebuild/test_fetch.py b/lib/portage/tests/ebuild/test_fetch.py
index da63d9dea..f50fea0dd 100644
--- a/lib/portage/tests/ebuild/test_fetch.py
+++ b/lib/portage/tests/ebuild/test_fetch.py
@@ -20,7 +20,7 @@ from portage.util._async.SchedulerInterface import SchedulerInterface
from portage.util._eventloop.global_event_loop import global_event_loop
from portage.package.ebuild.config import config
from portage.package.ebuild.digestgen import digestgen
-from portage.package.ebuild.fetch import (_download_suffix, FlatLayout,
+from portage.package.ebuild.fetch import (_download_suffix, fetch, FlatLayout,
FilenameHashLayout, MirrorLayoutConfig)
from _emerge.EbuildFetcher import EbuildFetcher
from _emerge.Package import Package
@@ -51,6 +51,12 @@ class EbuildFetchTestCase(TestCase):
}
loop = SchedulerInterface(global_event_loop())
+
+ def run_async(func, *args, **kwargs):
+ with ForkExecutor(loop=loop) as executor:
+ return loop.run_until_complete(loop.run_in_executor(executor,
+ functools.partial(func, *args, **kwargs)))
+
scheme = 'http'
host = '127.0.0.1'
content = {}
@@ -99,6 +105,29 @@ class EbuildFetchTestCase(TestCase):
portdb = root_config.trees["porttree"].dbapi
settings = config(clone=playground.settings)
+ # 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_path = os.path.join(settings['DISTDIR'], 'foo')
+ foo_stale_content = b'stale content\n'
+ with open(foo_path, 'wb') as f:
+ f.write(b'stale content\n')
+
+ self.assertTrue(bool(run_async(fetch, foo_uri, settings, try_mirrors=False)))
+
+ with open(foo_path, 'rb') as f:
+ self.assertEqual(f.read(), foo_stale_content)
+ with open(foo_path, 'rb') as f:
+ self.assertNotEqual(f.read(), distfiles['foo'])
+
+ # Remove the stale file in order to forcefully update it.
+ os.unlink(foo_path)
+
+ self.assertTrue(bool(run_async(fetch, foo_uri, settings, try_mirrors=False)))
+
+ with open(foo_path, 'rb') as f:
+ self.assertEqual(f.read(), distfiles['foo'])
+
+ # Test emirrordist invocation.
emirrordist_cmd = (portage._python_interpreter, '-b', '-Wd',
os.path.join(self.bindir, 'emirrordist'),
'--distfiles', settings['DISTDIR'],
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/ebuild/
@ 2020-03-22 1:12 Zac Medico
0 siblings, 0 replies; 11+ messages in thread
From: Zac Medico @ 2020-03-22 1:12 UTC (permalink / raw
To: gentoo-commits
commit: b59cf8bd11e48ebee2b3da185de48fd0f9aec4b8
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sun Mar 22 01:10:04 2020 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sun Mar 22 01:10:40 2020 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=b59cf8bd
DoebuildSpawnTestCase: add $HOME variable
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
lib/portage/tests/ebuild/test_doebuild_spawn.py | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/lib/portage/tests/ebuild/test_doebuild_spawn.py b/lib/portage/tests/ebuild/test_doebuild_spawn.py
index 7750f87b3..aedd0b8de 100644
--- a/lib/portage/tests/ebuild/test_doebuild_spawn.py
+++ b/lib/portage/tests/ebuild/test_doebuild_spawn.py
@@ -66,9 +66,11 @@ class DoebuildSpawnTestCase(TestCase):
settings['PORTAGE_BUILDDIR'] = os.path.join(
settings['PORTAGE_TMPDIR'], cpv)
settings['PYTHONDONTWRITEBYTECODE'] = os.environ.get('PYTHONDONTWRITEBYTECODE', '')
+ settings['HOME'] = os.path.join(
+ settings['PORTAGE_BUILDDIR'], 'homedir')
settings['T'] = os.path.join(
settings['PORTAGE_BUILDDIR'], 'temp')
- for x in ('PORTAGE_BUILDDIR', 'T'):
+ for x in ('PORTAGE_BUILDDIR', 'HOME', 'T'):
os.makedirs(settings[x])
# Create a fake environment, to pretend as if the ebuild
# has been sourced already.
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/ebuild/
@ 2020-07-19 21:55 Zac Medico
0 siblings, 0 replies; 11+ messages in thread
From: Zac Medico @ 2020-07-19 21:55 UTC (permalink / raw
To: gentoo-commits
commit: 601a10bfb9c2641b56366c0d512b01da9c6fa79d
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sun Jul 19 21:34:39 2020 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sun Jul 19 21:44:03 2020 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=601a10bf
EbuildFetchTestCase: fix PORTAGE_DEPCACHEDIR leakage from calling env
Reported-by: Sam James <sam <AT> gentoo.org>
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
lib/portage/tests/ebuild/test_fetch.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/portage/tests/ebuild/test_fetch.py b/lib/portage/tests/ebuild/test_fetch.py
index 232f78b5e..5b67dc519 100644
--- a/lib/portage/tests/ebuild/test_fetch.py
+++ b/lib/portage/tests/ebuild/test_fetch.py
@@ -1,4 +1,4 @@
-# Copyright 2019 Gentoo Authors
+# Copyright 2019-2020 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
import functools
@@ -167,7 +167,7 @@ class EbuildFetchTestCase(TestCase):
'--repositories-configuration', settings.repositories.config_string(),
'--repo', 'test_repo', '--mirror')
- env = os.environ.copy()
+ env = settings.environ()
env['PYTHONPATH'] = ':'.join(
filter(None, [PORTAGE_PYM_PATH] + os.environ.get('PYTHONPATH', '').split(':')))
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/ebuild/
@ 2020-08-03 23:28 Zac Medico
0 siblings, 0 replies; 11+ messages in thread
From: Zac Medico @ 2020-08-03 23:28 UTC (permalink / raw
To: gentoo-commits
commit: 3f2c0a15dab3b1b0c432c8c3cb4a59257710c5b1
Author: Aaron Bauman <bman <AT> gentoo <DOT> org>
AuthorDate: Mon Aug 3 22:43:13 2020 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Mon Aug 3 23:28:02 2020 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=3f2c0a15
lib/portage/tests/ebuild/test_config.py: fix whitespace
Signed-off-by: Aaron Bauman <bman <AT> gentoo.org>
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
lib/portage/tests/ebuild/test_config.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/portage/tests/ebuild/test_config.py b/lib/portage/tests/ebuild/test_config.py
index 60f3ecab4..a48f1329f 100644
--- a/lib/portage/tests/ebuild/test_config.py
+++ b/lib/portage/tests/ebuild/test_config.py
@@ -1,4 +1,4 @@
-# Copyright 2010-2015 Gentoo Foundation
+# Copyright 2010-2020 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
import io
@@ -85,7 +85,7 @@ class ConfigTestCase(TestCase):
"package.license":
(
"dev-libs/* TEST",
- "dev-libs/A -TEST2",
+ "dev-libs/A -TEST2",
"=dev-libs/A-2 TEST3 @TEST",
"*/* @EULA TEST2",
"=dev-libs/C-1 *",
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/ebuild/
@ 2021-02-21 8:33 Zac Medico
0 siblings, 0 replies; 11+ messages in thread
From: Zac Medico @ 2021-02-21 8:33 UTC (permalink / raw
To: gentoo-commits
commit: d84cfb857bcb29c5710710b119dee634bbd4d1a4
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sun Feb 21 08:19:06 2021 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sun Feb 21 08:32:59 2021 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=d84cfb85
testEbuildFetch: refactor to test multiple layout preferences
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
lib/portage/tests/ebuild/test_fetch.py | 115 ++++++++++++++++++++++++---------
1 file changed, 83 insertions(+), 32 deletions(-)
diff --git a/lib/portage/tests/ebuild/test_fetch.py b/lib/portage/tests/ebuild/test_fetch.py
index 5b67dc519..c5ea8253b 100644
--- a/lib/portage/tests/ebuild/test_fetch.py
+++ b/lib/portage/tests/ebuild/test_fetch.py
@@ -1,4 +1,4 @@
-# Copyright 2019-2020 Gentoo Authors
+# Copyright 2019-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
import functools
@@ -50,23 +50,10 @@ class EbuildFetchTestCase(TestCase):
loop = SchedulerInterface(global_event_loop())
- def run_async(func, *args, **kwargs):
- with ForkExecutor(loop=loop) as executor:
- return loop.run_until_complete(loop.run_in_executor(executor,
- functools.partial(func, *args, **kwargs)))
-
scheme = 'http'
host = '127.0.0.1'
content = {}
- content['/distfiles/layout.conf'] = b'[structure]\n0=flat\n'
-
- for k, v in distfiles.items():
- # mirror path
- content['/distfiles/{}'.format(k)] = v
- # upstream path
- content['/distfiles/{}.txt'.format(k)] = v
-
with AsyncHTTPServer(host, content, loop) as server:
ebuilds_subst = {}
for cpv, metadata in ebuilds.items():
@@ -86,22 +73,86 @@ class EbuildFetchTestCase(TestCase):
playground = ResolverPlayground(ebuilds=ebuilds_subst, distfiles=distfiles, user_config=user_config_subst)
ro_distdir = tempfile.mkdtemp()
- eubin = os.path.join(playground.eprefix, "usr", "bin")
try:
- fetchcommand = portage.util.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']))
- os.symlink(fetch_bin, os.path.join(eubin, os.path.basename(fetch_bin)))
- resumecommand = portage.util.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']))
- if resume_bin != fetch_bin:
- os.symlink(resume_bin, os.path.join(eubin, os.path.basename(resume_bin)))
- root_config = playground.trees[playground.eroot]['root_config']
- portdb = root_config.trees["porttree"].dbapi
+ self._testEbuildFetch(loop, scheme, host, distfiles, ebuilds, content, server, playground, ro_distdir)
+ finally:
+ shutil.rmtree(ro_distdir)
+ playground.cleanup()
+
+ def _testEbuildFetch(
+ self,
+ loop,
+ scheme,
+ host,
+ distfiles,
+ ebuilds,
+ content,
+ server,
+ playground,
+ ro_distdir,
+ ):
+ mirror_layouts = (
+ (
+ "[structure]",
+ "0=filename-hash BLAKE2B 8",
+ "1=flat",
+ ),
+ (
+ "[structure]",
+ "1=filename-hash BLAKE2B 8",
+ "0=flat",
+ ),
+ )
+
+ fetchcommand = portage.util.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"])
+ )
+ 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"])
+ resume_bin = portage.process.find_binary(resumecommand[0])
+ if resume_bin is None:
+ self.skipTest(
+ "RESUMECOMMAND not found: {}".format(
+ playground.settings["RESUMECOMMAND"]
+ )
+ )
+ if resume_bin != fetch_bin:
+ os.symlink(resume_bin, os.path.join(eubin, os.path.basename(resume_bin)))
+ root_config = playground.trees[playground.eroot]["root_config"]
+ portdb = root_config.trees["porttree"].dbapi
+
+ def run_async(func, *args, **kwargs):
+ with ForkExecutor(loop=loop) as executor:
+ return loop.run_until_complete(
+ loop.run_in_executor(
+ executor, functools.partial(func, *args, **kwargs)
+ )
+ )
+
+ for layout_lines in mirror_layouts:
settings = config(clone=playground.settings)
+ layout_data = "".join("{}\n".format(line) for line in layout_lines)
+ mirror_conf = MirrorLayoutConfig()
+ mirror_conf.read_from_file(io.StringIO(layout_data))
+ layouts = mirror_conf.get_all_layouts()
+ content["/distfiles/layout.conf"] = layout_data.encode("utf8")
+
+ for k, v in distfiles.items():
+ # mirror path
+ for layout in layouts:
+ content["/distfiles/" + layout.get_path(k)] = v
+ # upstream path
+ content["/distfiles/{}.txt".format(k)] = v
+
+ for filename in os.listdir(settings["DISTDIR"]):
+ try:
+ os.unlink(os.path.join(settings["DISTDIR"], filename))
+ except OSError:
+ pass
# 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),)}
@@ -172,7 +223,10 @@ class EbuildFetchTestCase(TestCase):
filter(None, [PORTAGE_PYM_PATH] + os.environ.get('PYTHONPATH', '').split(':')))
for k in distfiles:
- os.unlink(os.path.join(settings['DISTDIR'], k))
+ try:
+ os.unlink(os.path.join(settings['DISTDIR'], k))
+ except OSError:
+ pass
proc = loop.run_until_complete(asyncio.create_subprocess_exec(*emirrordist_cmd, env=env))
self.assertEqual(loop.run_until_complete(proc.wait()), 0)
@@ -354,9 +408,6 @@ class EbuildFetchTestCase(TestCase):
os.chmod(settings['DISTDIR'], orig_distdir_mode)
settings.features.remove('skiprocheck')
settings.features.add('distlocks')
- finally:
- shutil.rmtree(ro_distdir)
- playground.cleanup()
def test_flat_layout(self):
self.assertTrue(FlatLayout.verify_args(('flat',)))
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/ebuild/
@ 2021-05-24 6:20 Zac Medico
0 siblings, 0 replies; 11+ messages in thread
From: Zac Medico @ 2021-05-24 6:20 UTC (permalink / raw
To: gentoo-commits
commit: 0339031c22f3e30d95d1234ce08a47ae5df8e3f8
Author: Felix Bier <flx.bier <AT> gmail <DOT> com>
AuthorDate: Tue May 18 20:53:11 2021 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Mon May 24 06:17:13 2021 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=0339031c
Add unit tests for _shell_quote
This commit adds unit tests that cover the existing functionality of
_shell_quote, by checking that various special characters are
escaped/quoted correctly.
Signed-off-by: Felix Bier <felix.bier <AT> rohde-schwarz.com>
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
lib/portage/tests/ebuild/test_shell_quote.py | 79 ++++++++++++++++++++++++++++
1 file changed, 79 insertions(+)
diff --git a/lib/portage/tests/ebuild/test_shell_quote.py b/lib/portage/tests/ebuild/test_shell_quote.py
new file mode 100644
index 000000000..ce419488a
--- /dev/null
+++ b/lib/portage/tests/ebuild/test_shell_quote.py
@@ -0,0 +1,79 @@
+# Copyright 2021 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+from portage import _shell_quote
+from portage.tests import TestCase
+
+class ShellQuoteTestCase(TestCase):
+
+ def testShellQuote(self):
+ test_data = [
+
+ # String contains no special characters, should be preserved.
+ ("abc","abc"),
+
+ # String contains whitespace, should be double-quoted to prevent word splitting.
+ ("abc xyz","\"abc xyz\""),
+ ("abc xyz","\"abc xyz\""),
+ (" abcxyz ","\" abcxyz \""),
+ ("abc\txyz","\"abc\txyz\""),
+ ("abc\t\txyz","\"abc\t\txyz\""),
+ ("\tabcxyz\t","\"\tabcxyz\t\""),
+ ("abc\nxyz","\"abc\nxyz\""),
+ ("abc\n\nxyz","\"abc\n\nxyz\""),
+ ("\nabcxyz\n","\"\nabcxyz\n\""),
+
+ # String contains > or <, should be double-quoted to prevent redirection.
+ ("abc>xyz","\"abc>xyz\""),
+ ("abc>>xyz","\"abc>>xyz\""),
+ (">abcxyz>","\">abcxyz>\""),
+ ("abc<xyz","\"abc<xyz\""),
+ ("abc<<xyz","\"abc<<xyz\""),
+ ("<abcxyz<","\"<abcxyz<\""),
+
+ # String contains =, should be double-quoted to prevent assignment.
+ ("abc=xyz","\"abc=xyz\""),
+ ("abc==xyz","\"abc==xyz\""),
+ ("=abcxyz=","\"=abcxyz=\""),
+
+ # String contains *, should be double-quoted to prevent globbing.
+ ("abc*xyz","\"abc*xyz\""),
+ ("abc**xyz","\"abc**xyz\""),
+ ("*abcxyz*","\"*abcxyz*\""),
+
+ # String contains $, should be escaped to prevent parameter expansion.
+ # Also double-quoted, though not strictly needed.
+ ("abc$xyz","\"abc\\$xyz\""),
+ ("abc$$xyz","\"abc\\$\\$xyz\""),
+ ("$abcxyz$","\"\\$abcxyz\\$\""),
+
+ # String contains `, should be escaped to prevent command substitution.
+ # Also double-quoted, though not strictly needed.
+ ("abc`xyz","\"abc\\`xyz\""),
+ ("abc``xyz","\"abc\\`\\`xyz\""),
+ ("`abc`","\"\\`abc\\`\""),
+
+ # String contains \, should be escaped to prevent it from escaping
+ # the next character. Also double-quoted, though not strictly needed.
+ ("abc\\xyz", "\"abc\\\\xyz\""),
+ ("abc\\\\xyz", "\"abc\\\\\\\\xyz\""),
+ ("\\abcxyz\\", "\"\\\\abcxyz\\\\\""),
+
+ # String contains ", should be escaped to prevent it from unexpectedly
+ # ending a previous double-quote or starting a new double-quote. Also
+ # double-quoted, though not strictly needed.
+ ("abc\"xyz","\"abc\\\"xyz\""),
+ ("abc\"\"xyz","\"abc\\\"\\\"xyz\""),
+ ("\"abcxyz\"","\"\\\"abcxyz\\\"\""),
+
+ # String contains ', should be double-quoted to prevent it from unexpectedly
+ # ending a previous single-quote or starting a new single-quote.
+ ("abc'xyz","\"abc'xyz\""),
+ ("abc''xyz","\"abc''xyz\""),
+ ("'abcxyz'","\"'abcxyz'\""),
+
+ ]
+
+ for (data,expected_result) in test_data:
+ result = _shell_quote(data)
+ self.assertEqual(result, expected_result)
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/ebuild/
@ 2023-10-30 5:09 Zac Medico
0 siblings, 0 replies; 11+ messages in thread
From: Zac Medico @ 2023-10-30 5:09 UTC (permalink / raw
To: gentoo-commits
commit: 6a7297abca88c5d86ac299e51a52547baac791f1
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Mon Oct 30 04:43:42 2023 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Mon Oct 30 04:47:55 2023 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=6a7297ab
test_doebuild_fd_pipes.py: multiprocessing spawn compat
Use multiprocessing.Pipe for compatibility with the spawn
start method. Also pass QueryCommand._db to the child
process, like MergeProcess does.
Bug: https://bugs.gentoo.org/916247
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
lib/portage/tests/ebuild/test_doebuild_fd_pipes.py | 30 ++++++++++++++--------
1 file changed, 20 insertions(+), 10 deletions(-)
diff --git a/lib/portage/tests/ebuild/test_doebuild_fd_pipes.py b/lib/portage/tests/ebuild/test_doebuild_fd_pipes.py
index 51ddc23908..678486ed16 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-2023 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
@@ -13,6 +15,8 @@ from _emerge.PipeReader import PipeReader
class DoebuildFdPipesTestCase(TestCase):
+ output_fd = 200
+
def testDoebuild(self):
"""
Invoke portage.doebuild() with the fd_pipes parameter, and
@@ -21,7 +25,7 @@ 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",
@@ -117,21 +121,19 @@ class DoebuildFdPipesTestCase(TestCase):
"clean",
"merge",
):
- pr, pw = os.pipe()
+ pr, pw = multiprocessing.Pipe(duplex=False)
producer = ForkProcess(
- target=portage.doebuild,
- args=(ebuildpath, phase),
+ target=self._doebuild,
+ fd_pipes={
+ 1: dev_null.fileno(),
+ },
+ args=(QueryCommand._db, pw, ebuildpath, phase),
kwargs={
"settings": settings,
"mydbapi": portdb,
"tree": "porttree",
"vartree": root_config.trees["vartree"],
- "fd_pipes": {
- 1: dev_null.fileno(),
- 2: dev_null.fileno(),
- output_fd: pw,
- },
"prev_mtimes": {},
},
)
@@ -144,7 +146,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")
@@ -161,3 +163,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)
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/ebuild/
@ 2023-12-05 6:11 Zac Medico
0 siblings, 0 replies; 11+ messages in thread
From: Zac Medico @ 2023-12-05 6:11 UTC (permalink / raw
To: gentoo-commits
commit: 4de288937ad740d5373a0b77a84e224af636ce1e
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Tue Dec 5 05:07:39 2023 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Tue Dec 5 06:10:41 2023 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=4de28893
EbuildFetchTestCase: Fix dict/shelve key order assumption
Bug: https://bugs.gentoo.org/919105
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
lib/portage/tests/ebuild/test_fetch.py | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/lib/portage/tests/ebuild/test_fetch.py b/lib/portage/tests/ebuild/test_fetch.py
index a9ca030ff9..9b9260008c 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
@@ -577,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"]
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/ebuild/
@ 2023-12-31 0:01 Zac Medico
0 siblings, 0 replies; 11+ messages in thread
From: Zac Medico @ 2023-12-31 0:01 UTC (permalink / raw
To: gentoo-commits
commit: 60c196dc162a376ee8b4856a4dc6b07d8a85bb3c
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sat Dec 30 22:59:19 2023 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sun Dec 31 00:00:01 2023 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=60c196dc
EbuildFetchTestCase: Fix dict/shelve key order assumption
Just like 4de288937ad7.
Bug: https://bugs.gentoo.org/921107
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
lib/portage/tests/ebuild/test_fetch.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/lib/portage/tests/ebuild/test_fetch.py b/lib/portage/tests/ebuild/test_fetch.py
index 9b9260008c..bc8c052746 100644
--- a/lib/portage/tests/ebuild/test_fetch.py
+++ b/lib/portage/tests/ebuild/test_fetch.py
@@ -615,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(
^ permalink raw reply related [flat|nested] 11+ messages in thread
end of thread, other threads:[~2023-12-31 0:01 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-05-24 6:20 [gentoo-commits] proj/portage:master commit in: lib/portage/tests/ebuild/ Zac Medico
-- strict thread matches above, loose matches on Subject: below --
2023-12-31 0:01 Zac Medico
2023-12-05 6:11 Zac Medico
2023-10-30 5:09 Zac Medico
2021-02-21 8:33 Zac Medico
2020-08-03 23:28 Zac Medico
2020-07-19 21:55 Zac Medico
2020-03-22 1:12 Zac Medico
2019-10-19 23:15 Zac Medico
2019-10-19 5:29 Zac Medico
2019-10-19 1:38 Zac Medico
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox