* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/emerge/
@ 2020-03-08 7:33 Zac Medico
0 siblings, 0 replies; 38+ messages in thread
From: Zac Medico @ 2020-03-08 7:33 UTC (permalink / raw
To: gentoo-commits
commit: 0552665627bf85f01ae28cafebc885dcb6d26ef3
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sun Mar 8 07:31:08 2020 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sun Mar 8 07:31:50 2020 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=05526656
SimpleEmergeTestCase: run tests in coroutine method
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
lib/portage/tests/emerge/test_simple.py | 25 ++++++++++++++++++-------
1 file changed, 18 insertions(+), 7 deletions(-)
diff --git a/lib/portage/tests/emerge/test_simple.py b/lib/portage/tests/emerge/test_simple.py
index f5cd6f3d2..6aafff180 100644
--- a/lib/portage/tests/emerge/test_simple.py
+++ b/lib/portage/tests/emerge/test_simple.py
@@ -1,4 +1,4 @@
-# Copyright 2011-2019 Gentoo Authors
+# Copyright 2011-2020 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
import subprocess
@@ -14,6 +14,9 @@ from portage.tests import TestCase
from portage.tests.resolver.ResolverPlayground import ResolverPlayground
from portage.util import (ensure_dirs, find_updated_config_files,
shlex_split)
+from portage.util.futures import asyncio
+from portage.util.futures.compat_coroutine import coroutine
+
class SimpleEmergeTestCase(TestCase):
@@ -201,6 +204,15 @@ call_has_and_best_version() {
playground = ResolverPlayground(
ebuilds=ebuilds, installed=installed, debug=debug)
+
+ loop = asyncio._wrap_loop()
+ loop.run_until_complete(asyncio.ensure_future(
+ self._async_test_simple(playground, metadata_xml_files), loop=loop))
+
+ @coroutine
+ def _async_test_simple(self, playground, metadata_xml_files):
+
+ debug = playground.debug
settings = playground.settings
eprefix = settings["EPREFIX"]
eroot = settings["EROOT"]
@@ -487,15 +499,14 @@ move dev-util/git dev-vcs/git
else:
local_env = env
- proc = subprocess.Popen(args,
- env=local_env, stdout=stdout)
+ proc = yield asyncio.create_subprocess_exec(*args,
+ env=local_env, stderr=None, stdout=stdout)
if debug:
- proc.wait()
+ yield proc.wait()
else:
- output = proc.stdout.readlines()
- proc.wait()
- proc.stdout.close()
+ output, _err = yield proc.communicate()
+ yield proc.wait()
if proc.returncode != os.EX_OK:
for line in output:
sys.stderr.write(_unicode_decode(line))
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/emerge/
@ 2020-03-08 22:29 Zac Medico
0 siblings, 0 replies; 38+ messages in thread
From: Zac Medico @ 2020-03-08 22:29 UTC (permalink / raw
To: gentoo-commits
commit: c27dd521ae8b6fb4eea632b52b98df9d2af7cb5e
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sun Mar 8 21:43:41 2020 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sun Mar 8 22:04:55 2020 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=c27dd521
SimpleEmergeTestCase: test binhost support
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
lib/portage/tests/emerge/test_simple.py | 48 ++++++++++++++++++++++++++++++---
1 file changed, 45 insertions(+), 3 deletions(-)
diff --git a/lib/portage/tests/emerge/test_simple.py b/lib/portage/tests/emerge/test_simple.py
index 6aafff180..19ab72457 100644
--- a/lib/portage/tests/emerge/test_simple.py
+++ b/lib/portage/tests/emerge/test_simple.py
@@ -5,19 +5,38 @@ import subprocess
import sys
import portage
-from portage import os
+from portage import shutil, os
from portage import _unicode_decode
from portage.const import (BASH_BINARY, PORTAGE_BASE_PATH,
PORTAGE_PYM_PATH, USER_CONFIG_PATH)
+from portage.cache.mappings import Mapping
from portage.process import find_binary
from portage.tests import TestCase
from portage.tests.resolver.ResolverPlayground import ResolverPlayground
+from portage.tests.util.test_socks5 import AsyncHTTPServer
from portage.util import (ensure_dirs, find_updated_config_files,
shlex_split)
from portage.util.futures import asyncio
from portage.util.futures.compat_coroutine import coroutine
+class BinhostContentMap(Mapping):
+ def __init__(self, remote_path, local_path):
+ self._remote_path = remote_path
+ self._local_path = local_path
+
+ def __getitem__(self, request_path):
+ safe_path = os.path.normpath(request_path)
+ if not safe_path.startswith(self._remote_path + '/'):
+ raise KeyError(request_path)
+ local_path = os.path.join(self._local_path, safe_path[len(self._remote_path)+1:])
+ try:
+ with open(local_path, 'rb') as f:
+ return f.read()
+ except EnvironmentError:
+ raise KeyError(request_path)
+
+
class SimpleEmergeTestCase(TestCase):
def _have_python_xml(self):
@@ -207,10 +226,10 @@ call_has_and_best_version() {
loop = asyncio._wrap_loop()
loop.run_until_complete(asyncio.ensure_future(
- self._async_test_simple(playground, metadata_xml_files), loop=loop))
+ self._async_test_simple(loop, playground, metadata_xml_files), loop=loop))
@coroutine
- def _async_test_simple(self, playground, metadata_xml_files):
+ def _async_test_simple(self, loop, playground, metadata_xml_files):
debug = playground.debug
settings = playground.settings
@@ -265,6 +284,16 @@ call_has_and_best_version() {
cross_root = os.path.join(eprefix, "cross_root")
cross_eroot = os.path.join(cross_root, eprefix.lstrip(os.sep))
+ binhost_dir = os.path.join(eprefix, "binhost")
+ binhost_address = '127.0.0.1'
+ binhost_remote_path = '/binhost'
+ binhost_server = AsyncHTTPServer(binhost_address,
+ BinhostContentMap(binhost_remote_path, binhost_dir), loop).__enter__()
+ binhost_uri = 'http://{address}:{port}{path}'.format(
+ address=binhost_address,
+ port=binhost_server.server_port,
+ path=binhost_remote_path)
+
test_commands = (
emerge_cmd + ("--usepkgonly", "--root", cross_root, "--quickpkg-direct=y", "dev-libs/A"),
env_update_cmd,
@@ -390,6 +419,18 @@ call_has_and_best_version() {
portageq_cmd + ("has_version", cross_eroot, "dev-libs/B"),
)
+ # Test binhost support if FETCHCOMMAND is available.
+ fetchcommand = portage.util.shlex_split(playground.settings['FETCHCOMMAND'])
+ fetch_bin = portage.process.find_binary(fetchcommand[0])
+ if fetch_bin is not None:
+ test_commands = test_commands + (
+ lambda: os.rename(pkgdir, binhost_dir),
+ ({"PORTAGE_BINHOST": binhost_uri},) + \
+ emerge_cmd + ("-e", "--getbinpkgonly", "dev-libs/A"),
+ lambda: shutil.rmtree(pkgdir),
+ lambda: os.rename(binhost_dir, pkgdir),
+ )
+
distdir = playground.distdir
pkgdir = playground.pkgdir
fake_bin = os.path.join(eprefix, "bin")
@@ -514,4 +555,5 @@ move dev-util/git dev-vcs/git
self.assertEqual(os.EX_OK, proc.returncode,
"emerge failed with args %s" % (args,))
finally:
+ binhost_server.__exit__(None, None, None)
playground.cleanup()
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/emerge/
@ 2020-08-03 19:30 Zac Medico
0 siblings, 0 replies; 38+ messages in thread
From: Zac Medico @ 2020-08-03 19:30 UTC (permalink / raw
To: gentoo-commits
commit: e8944b35c070d550a6c552dcd2ba5300efda01d0
Author: Aaron Bauman <bman <AT> gentoo <DOT> org>
AuthorDate: Mon Aug 3 19:06:05 2020 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Mon Aug 3 19:22:52 2020 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=e8944b35
lib/portage/tests/emerge/test_simple.py: drop unused-import
Signed-off-by: Aaron Bauman <bman <AT> gentoo.org>
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
lib/portage/tests/emerge/test_simple.py | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/lib/portage/tests/emerge/test_simple.py b/lib/portage/tests/emerge/test_simple.py
index 19ab72457..e8144c55f 100644
--- a/lib/portage/tests/emerge/test_simple.py
+++ b/lib/portage/tests/emerge/test_simple.py
@@ -7,8 +7,7 @@ import sys
import portage
from portage import shutil, os
from portage import _unicode_decode
-from portage.const import (BASH_BINARY, PORTAGE_BASE_PATH,
- PORTAGE_PYM_PATH, USER_CONFIG_PATH)
+from portage.const import (BASH_BINARY, PORTAGE_PYM_PATH, USER_CONFIG_PATH)
from portage.cache.mappings import Mapping
from portage.process import find_binary
from portage.tests import TestCase
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/emerge/
@ 2020-08-03 23:28 Zac Medico
0 siblings, 0 replies; 38+ messages in thread
From: Zac Medico @ 2020-08-03 23:28 UTC (permalink / raw
To: gentoo-commits
commit: 590d1810c90330ac9174082604d027733b476245
Author: Aaron Bauman <bman <AT> gentoo <DOT> org>
AuthorDate: Mon Aug 3 22:43:22 2020 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Mon Aug 3 23:28:04 2020 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=590d1810
lib/portage/tests/emerge/test_simple.py: fix whitespace
Signed-off-by: Aaron Bauman <bman <AT> gentoo.org>
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
lib/portage/tests/emerge/test_simple.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/portage/tests/emerge/test_simple.py b/lib/portage/tests/emerge/test_simple.py
index e8144c55f..94b3076c1 100644
--- a/lib/portage/tests/emerge/test_simple.py
+++ b/lib/portage/tests/emerge/test_simple.py
@@ -339,7 +339,7 @@ call_has_and_best_version() {
emerge_cmd + ("--oneshot", "--usepkg", "dev-libs/B",),
# trigger clean prior to pkg_pretend as in bug #390711
- ebuild_cmd + (test_ebuild, "unpack"),
+ ebuild_cmd + (test_ebuild, "unpack"),
emerge_cmd + ("--oneshot", "dev-libs/A",),
emerge_cmd + ("--noreplace", "dev-libs/A",),
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/emerge/
@ 2020-10-12 18:03 Zac Medico
0 siblings, 0 replies; 38+ messages in thread
From: Zac Medico @ 2020-10-12 18:03 UTC (permalink / raw
To: gentoo-commits
commit: 3cd49702014c6641190c858744ce4ea4a047366f
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Mon Oct 12 17:57:12 2020 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Mon Oct 12 18:00:05 2020 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=3cd49702
SimpleEmergeTestCase: fix TypeError: write() argument must be str, not int
Bug: https://bugs.gentoo.org/748012
Fixes: 0552665627bf ("SimpleEmergeTestCase: run tests in coroutine method")
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
lib/portage/tests/emerge/test_simple.py | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/lib/portage/tests/emerge/test_simple.py b/lib/portage/tests/emerge/test_simple.py
index 8635b70e4..25cb54de3 100644
--- a/lib/portage/tests/emerge/test_simple.py
+++ b/lib/portage/tests/emerge/test_simple.py
@@ -558,8 +558,7 @@ move dev-util/git dev-vcs/git
output, _err = yield proc.communicate()
yield proc.wait()
if proc.returncode != os.EX_OK:
- for line in output:
- sys.stderr.write(_unicode_decode(line))
+ portage.writemsg(output)
self.assertEqual(os.EX_OK, proc.returncode,
"emerge failed with args %s" % (args,))
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/emerge/
@ 2020-10-17 9:21 Zac Medico
0 siblings, 0 replies; 38+ messages in thread
From: Zac Medico @ 2020-10-17 9:21 UTC (permalink / raw
To: gentoo-commits
commit: ac712bb826266719c39a797499c10ec512c5d4f9
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sat Oct 17 09:19:32 2020 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sat Oct 17 09:19:43 2020 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=ac712bb8
lib/portage/tests/emerge/test_simple.py: drop unused-import
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
lib/portage/tests/emerge/test_simple.py | 2 --
1 file changed, 2 deletions(-)
diff --git a/lib/portage/tests/emerge/test_simple.py b/lib/portage/tests/emerge/test_simple.py
index 25cb54de3..8ba74c609 100644
--- a/lib/portage/tests/emerge/test_simple.py
+++ b/lib/portage/tests/emerge/test_simple.py
@@ -2,11 +2,9 @@
# Distributed under the terms of the GNU General Public License v2
import subprocess
-import sys
import portage
from portage import shutil, os
-from portage import _unicode_decode
from portage.const import (BASH_BINARY, BINREPOS_CONF_FILE, PORTAGE_PYM_PATH, USER_CONFIG_PATH)
from portage.cache.mappings import Mapping
from portage.process import find_binary
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/emerge/
@ 2021-01-18 12:20 Zac Medico
0 siblings, 0 replies; 38+ messages in thread
From: Zac Medico @ 2021-01-18 12:20 UTC (permalink / raw
To: gentoo-commits
commit: 05555e4c062e9dc87ce290e29816df9d8871f25b
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Mon Jan 18 11:42:30 2021 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Mon Jan 18 11:43:18 2021 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=05555e4c
SimpleEmergeTestCase: Use async and await syntax
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
lib/portage/tests/emerge/test_simple.py | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/lib/portage/tests/emerge/test_simple.py b/lib/portage/tests/emerge/test_simple.py
index 1638fcb66..d26146aa9 100644
--- a/lib/portage/tests/emerge/test_simple.py
+++ b/lib/portage/tests/emerge/test_simple.py
@@ -1,4 +1,4 @@
-# Copyright 2011-2020 Gentoo Authors
+# Copyright 2011-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
import subprocess
@@ -14,7 +14,6 @@ from portage.tests.util.test_socks5 import AsyncHTTPServer
from portage.util import (ensure_dirs, find_updated_config_files,
shlex_split)
from portage.util.futures import asyncio
-from portage.util.futures.compat_coroutine import coroutine
class BinhostContentMap(Mapping):
@@ -225,8 +224,7 @@ call_has_and_best_version() {
loop.run_until_complete(asyncio.ensure_future(
self._async_test_simple(playground, metadata_xml_files, loop=loop), loop=loop))
- @coroutine
- def _async_test_simple(self, playground, metadata_xml_files, loop=None):
+ async def _async_test_simple(self, playground, metadata_xml_files, loop):
debug = playground.debug
settings = playground.settings
@@ -548,14 +546,14 @@ move dev-util/git dev-vcs/git
else:
local_env = env
- proc = yield asyncio.create_subprocess_exec(*args,
- env=local_env, stderr=None, stdout=stdout, loop=loop)
+ proc = await asyncio.create_subprocess_exec(*args,
+ env=local_env, stderr=None, stdout=stdout)
if debug:
- yield proc.wait()
+ await proc.wait()
else:
- output, _err = yield proc.communicate()
- yield proc.wait()
+ output, _err = await proc.communicate()
+ await proc.wait()
if proc.returncode != os.EX_OK:
portage.writemsg(output)
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/emerge/
@ 2022-09-25 19:12 Mike Gilbert
0 siblings, 0 replies; 38+ messages in thread
From: Mike Gilbert @ 2022-09-25 19:12 UTC (permalink / raw
To: gentoo-commits
commit: 54590b592f4bbb65d66445214be2a6a9351ee112
Author: David Palao <david.palao <AT> gmail <DOT> com>
AuthorDate: Fri Sep 16 19:46:34 2022 +0000
Commit: Mike Gilbert <floppym <AT> gentoo <DOT> org>
CommitDate: Sun Sep 25 19:10:55 2022 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=54590b59
test(actions): fixed little issue in UT
Signed-off-by: David Palao <david.palao <AT> gmail.com>
Signed-off-by: Mike Gilbert <floppym <AT> gentoo.org>
lib/portage/tests/emerge/test_actions.py | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)
diff --git a/lib/portage/tests/emerge/test_actions.py b/lib/portage/tests/emerge/test_actions.py
index ee59cef5e..d93e44bad 100644
--- a/lib/portage/tests/emerge/test_actions.py
+++ b/lib/portage/tests/emerge/test_actions.py
@@ -22,14 +22,11 @@ class RunActionTestCase(TestCase):
If the implementation changes, the mocks can be adjusted to play its
role.
"""
+
@patch("_emerge.actions.profile_check")
@patch("_emerge.actions.adjust_configs")
@patch("_emerge.actions.apply_priorities")
- def test_binary_trees_populate_called(
- self,
- papply,
- padjust,
- profile_ckeck):
+ def test_binary_trees_populate_called(self, papply, padjust, profile_ckeck):
"""Ensure that ``binarytree.populate`` API is correctly used.
The point of this test is to ensure that the ``populate`` method
is called as expected: since it is the first time that ``populate``
@@ -37,7 +34,7 @@ class RunActionTestCase(TestCase):
"""
config = MagicMock()
config.action = None
- config.opts = {"--quiet": True, "--usepkg": True}
+ config.opts = {"--quiet": True, "--usepkg": True, "--package-moves": "n"}
bt = MagicMock()
tree = {"bintree": bt}
trees = {"first": tree}
@@ -45,6 +42,4 @@ class RunActionTestCase(TestCase):
run_action(config)
- bt.populate.assert_called_once_with(
- getbinpkgs=False, getbinpkg_refresh=True
- )
+ bt.populate.assert_called_once_with(getbinpkgs=False, getbinpkg_refresh=True)
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/emerge/
@ 2023-05-26 15:45 Sam James
0 siblings, 0 replies; 38+ messages in thread
From: Sam James @ 2023-05-26 15:45 UTC (permalink / raw
To: gentoo-commits
commit: 1f7afc93d4e3df77915019ca6d7b02da52ecf3b8
Author: David Palao <david.palao <AT> gmail <DOT> com>
AuthorDate: Fri May 26 09:27:42 2023 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri May 26 15:44:38 2023 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=1f7afc93
tests: fix the inst gid and uid in some envs for tests
...where they were, by mistake, switched
Signed-off-by: David Palao <david.palao <AT> gmail.com>
Signed-off-by: Sam James <sam <AT> gentoo.org>
lib/portage/tests/emerge/test_config_protect.py | 4 ++--
lib/portage/tests/emerge/test_emerge_blocker_file_collision.py | 4 ++--
lib/portage/tests/emerge/test_emerge_slot_abi.py | 4 ++--
lib/portage/tests/emerge/test_simple.py | 2 +-
4 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/lib/portage/tests/emerge/test_config_protect.py b/lib/portage/tests/emerge/test_config_protect.py
index 97d0c236f..ec359833e 100644
--- a/lib/portage/tests/emerge/test_config_protect.py
+++ b/lib/portage/tests/emerge/test_config_protect.py
@@ -217,8 +217,8 @@ src_install() {
"INFODIR": "",
"INFOPATH": "",
"PATH": path,
- "PORTAGE_INST_GID": str(os.getuid()), # str(portage.data.portage_gid),
- "PORTAGE_INST_UID": str(os.getgid()), # str(portage.data.portage_uid),
+ "PORTAGE_INST_GID": str(os.getgid()), # str(portage.data.portage_gid),
+ "PORTAGE_INST_UID": str(os.getuid()), # str(portage.data.portage_uid),
"PORTAGE_PYTHON": portage_python,
"PORTAGE_REPOSITORIES": settings.repositories.config_string(),
"PORTAGE_TMPDIR": portage_tmpdir,
diff --git a/lib/portage/tests/emerge/test_emerge_blocker_file_collision.py b/lib/portage/tests/emerge/test_emerge_blocker_file_collision.py
index d21287401..6f7a96af9 100644
--- a/lib/portage/tests/emerge/test_emerge_blocker_file_collision.py
+++ b/lib/portage/tests/emerge/test_emerge_blocker_file_collision.py
@@ -121,8 +121,8 @@ src_install() {
"PORTAGE_REPOSITORIES": settings.repositories.config_string(),
"PYTHONDONTWRITEBYTECODE": os.environ.get("PYTHONDONTWRITEBYTECODE", ""),
"PYTHONPATH": pythonpath,
- "PORTAGE_INST_GID": str(os.getuid()),
- "PORTAGE_INST_UID": str(os.getgid()),
+ "PORTAGE_INST_GID": str(os.getgid()),
+ "PORTAGE_INST_UID": str(os.getuid()),
}
if "__PORTAGE_TEST_HARDLINK_LOCKS" in os.environ:
diff --git a/lib/portage/tests/emerge/test_emerge_slot_abi.py b/lib/portage/tests/emerge/test_emerge_slot_abi.py
index 51cd3c43c..197685975 100644
--- a/lib/portage/tests/emerge/test_emerge_slot_abi.py
+++ b/lib/portage/tests/emerge/test_emerge_slot_abi.py
@@ -129,8 +129,8 @@ class SlotAbiEmergeTestCase(TestCase):
"PORTAGE_REPOSITORIES": settings.repositories.config_string(),
"PYTHONDONTWRITEBYTECODE": os.environ.get("PYTHONDONTWRITEBYTECODE", ""),
"PYTHONPATH": pythonpath,
- "PORTAGE_INST_GID": str(os.getuid()),
- "PORTAGE_INST_UID": str(os.getgid()),
+ "PORTAGE_INST_GID": str(os.getgid()),
+ "PORTAGE_INST_UID": str(os.getuid()),
}
if "__PORTAGE_TEST_HARDLINK_LOCKS" in os.environ:
diff --git a/lib/portage/tests/emerge/test_simple.py b/lib/portage/tests/emerge/test_simple.py
index 50b7eee31..ab85ad441 100644
--- a/lib/portage/tests/emerge/test_simple.py
+++ b/lib/portage/tests/emerge/test_simple.py
@@ -620,7 +620,7 @@ call_has_and_best_version() {
"INFOPATH": "",
"PATH": path,
"PKGDIR": pkgdir,
- "PORTAGE_INST_GID": str(os.getuid()), # str(portage.data.portage_gid),
+ "PORTAGE_INST_GID": str(os.getgid()), # str(portage.data.portage_gid),
"PORTAGE_INST_UID": str(os.getuid()), # str(portage.data.portage_uid),
"PORTAGE_PYTHON": portage_python,
"PORTAGE_REPOSITORIES": settings.repositories.config_string(),
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/emerge/
@ 2023-05-26 15:45 Sam James
0 siblings, 0 replies; 38+ messages in thread
From: Sam James @ 2023-05-26 15:45 UTC (permalink / raw
To: gentoo-commits
commit: c8b30294591be75516e369ae9566885c47e594d3
Author: David Palao <david.palao <AT> gmail <DOT> com>
AuthorDate: Wed May 17 13:38:42 2023 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri May 26 15:44:37 2023 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=c8b30294
tests: pytest: the last four failing tests with pytest fixed
The issue was: when the full test suite was run, the four tests
would fail. But not when they were run alone. The reason: the
environment where those tests was run on was wrong when the full
suite was run, and not when the individual tests were executed.
It was fixed by adding:
"PORTAGE_INST_GID": str(os.getuid()),
"PORTAGE_INST_UID": str(os.getgid()),
to the environments used by the commands exercised in those tests.
Signed-off-by: David Palao <david.palao <AT> gmail.com>
Signed-off-by: Sam James <sam <AT> gentoo.org>
lib/portage/tests/emerge/test_config_protect.py | 4 ++--
lib/portage/tests/emerge/test_emerge_blocker_file_collision.py | 2 ++
lib/portage/tests/emerge/test_emerge_slot_abi.py | 2 ++
lib/portage/tests/emerge/test_simple.py | 4 ++--
4 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/lib/portage/tests/emerge/test_config_protect.py b/lib/portage/tests/emerge/test_config_protect.py
index 399611ea1..0b8308a34 100644
--- a/lib/portage/tests/emerge/test_config_protect.py
+++ b/lib/portage/tests/emerge/test_config_protect.py
@@ -217,8 +217,8 @@ src_install() {
"INFODIR": "",
"INFOPATH": "",
"PATH": path,
- "PORTAGE_INST_GID": str(portage.data.portage_gid),
- "PORTAGE_INST_UID": str(portage.data.portage_uid),
+ "PORTAGE_INST_GID": str(os.getuid()), # str(portage.data.portage_gid),
+ "PORTAGE_INST_UID": str(os.getgid()), # str(portage.data.portage_uid),
"PORTAGE_PYTHON": portage_python,
"PORTAGE_REPOSITORIES": settings.repositories.config_string(),
"PORTAGE_TMPDIR": portage_tmpdir,
diff --git a/lib/portage/tests/emerge/test_emerge_blocker_file_collision.py b/lib/portage/tests/emerge/test_emerge_blocker_file_collision.py
index b160fe1c6..a05fc47a9 100644
--- a/lib/portage/tests/emerge/test_emerge_blocker_file_collision.py
+++ b/lib/portage/tests/emerge/test_emerge_blocker_file_collision.py
@@ -121,6 +121,8 @@ src_install() {
"PORTAGE_REPOSITORIES": settings.repositories.config_string(),
"PYTHONDONTWRITEBYTECODE": os.environ.get("PYTHONDONTWRITEBYTECODE", ""),
"PYTHONPATH": pythonpath,
+ "PORTAGE_INST_GID": str(os.getuid()),
+ "PORTAGE_INST_UID": str(os.getgid()),
}
if "__PORTAGE_TEST_HARDLINK_LOCKS" in os.environ:
diff --git a/lib/portage/tests/emerge/test_emerge_slot_abi.py b/lib/portage/tests/emerge/test_emerge_slot_abi.py
index e38d0fcac..3fc13e08f 100644
--- a/lib/portage/tests/emerge/test_emerge_slot_abi.py
+++ b/lib/portage/tests/emerge/test_emerge_slot_abi.py
@@ -129,6 +129,8 @@ class SlotAbiEmergeTestCase(TestCase):
"PORTAGE_REPOSITORIES": settings.repositories.config_string(),
"PYTHONDONTWRITEBYTECODE": os.environ.get("PYTHONDONTWRITEBYTECODE", ""),
"PYTHONPATH": pythonpath,
+ "PORTAGE_INST_GID": str(os.getuid()),
+ "PORTAGE_INST_UID": str(os.getgid()),
}
if "__PORTAGE_TEST_HARDLINK_LOCKS" in os.environ:
diff --git a/lib/portage/tests/emerge/test_simple.py b/lib/portage/tests/emerge/test_simple.py
index 0e5333250..86c5dccc4 100644
--- a/lib/portage/tests/emerge/test_simple.py
+++ b/lib/portage/tests/emerge/test_simple.py
@@ -620,8 +620,8 @@ call_has_and_best_version() {
"INFOPATH": "",
"PATH": path,
"PKGDIR": pkgdir,
- "PORTAGE_INST_GID": str(portage.data.portage_gid),
- "PORTAGE_INST_UID": str(portage.data.portage_uid),
+ "PORTAGE_INST_GID": str(os.getuid()), # str(portage.data.portage_gid),
+ "PORTAGE_INST_UID": str(os.getuid()), # str(portage.data.portage_uid),
"PORTAGE_PYTHON": portage_python,
"PORTAGE_REPOSITORIES": settings.repositories.config_string(),
"PORTAGE_TMPDIR": portage_tmpdir,
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/emerge/
@ 2023-10-30 3:14 Sam James
0 siblings, 0 replies; 38+ messages in thread
From: Sam James @ 2023-10-30 3:14 UTC (permalink / raw
To: gentoo-commits
commit: 95fb92aef6724394d65fa072c4109a4cc54ee3d3
Author: David Palao <david.palao <AT> gmail <DOT> com>
AuthorDate: Fri Jun 9 15:19:35 2023 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Oct 30 03:14:21 2023 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=95fb92ae
tests/emerge/test_simple.py: refactor function to make test commands
Signed-off-by: David Palao <david.palao <AT> gmail.com>
Signed-off-by: Sam James <sam <AT> gentoo.org>
lib/portage/tests/emerge/test_simple.py | 92 +++++++++++++++++++--------------
1 file changed, 53 insertions(+), 39 deletions(-)
diff --git a/lib/portage/tests/emerge/test_simple.py b/lib/portage/tests/emerge/test_simple.py
index 1c7d1bafbe..35e221311e 100644
--- a/lib/portage/tests/emerge/test_simple.py
+++ b/lib/portage/tests/emerge/test_simple.py
@@ -223,32 +223,9 @@ class BinhostContentMap(Mapping):
raise KeyError(request_path)
-@pytest.mark.parametrize("binpkg_format", SUPPORTED_GENTOO_BINPKG_FORMATS)
-def test_simple_emerge(binpkg_format):
- playground = ResolverPlayground(
- ebuilds=_AVAILABLE_EBUILDS,
- installed=_INSTALLED_EBUILDS,
- debug=False,
- user_config={
- "make.conf": (f'BINPKG_FORMAT="{binpkg_format}"',),
- },
- )
-
- loop = asyncio._wrap_loop()
- loop.run_until_complete(
- asyncio.ensure_future(
- _async_test_simple(playground, _METADATA_XML_FILES, loop=loop),
- loop=loop,
- )
- )
-
-
-async def _async_test_simple(playground, metadata_xml_files, loop):
- debug = playground.debug
- settings = playground.settings
+def make_test_commands(settings, trees, binhost_uri):
eprefix = settings["EPREFIX"]
eroot = settings["EROOT"]
- trees = playground.trees
portdb = trees[eroot]["porttree"].dbapi
test_repo_location = settings.repositories["test_repo"].location
var_cache_edb = os.path.join(eprefix, "var", "cache", "edb")
@@ -322,18 +299,6 @@ async def _async_test_simple(playground, metadata_xml_files, loop):
cross_root = os.path.join(eprefix, "cross_root")
cross_eroot = os.path.join(cross_root, eprefix.lstrip(os.sep))
- binhost_dir = os.path.join(eprefix, "binhost")
- binhost_address = "127.0.0.1"
- binhost_remote_path = "/binhost"
- binhost_server = AsyncHTTPServer(
- binhost_address, BinhostContentMap(binhost_remote_path, binhost_dir), loop
- ).__enter__()
- binhost_uri = "http://{address}:{port}{path}".format(
- address=binhost_address,
- port=binhost_server.server_port,
- path=binhost_remote_path,
- )
-
binpkg_format = settings.get("BINPKG_FORMAT", SUPPORTED_GENTOO_BINPKG_FORMATS[0])
assert binpkg_format in ("xpak", "gpkg")
if binpkg_format == "xpak":
@@ -554,7 +519,7 @@ async def _async_test_simple(playground, metadata_xml_files, loop):
with open(binrepos_conf_file, "w") as f:
f.write("[test-binhost]\n")
f.write(f"sync-uri = {binhost_uri}\n")
- fetchcommand = portage.util.shlex_split(playground.settings["FETCHCOMMAND"])
+ fetchcommand = portage.util.shlex_split(settings["FETCHCOMMAND"])
fetch_bin = portage.process.find_binary(fetchcommand[0])
if fetch_bin is not None:
test_commands = test_commands + (
@@ -571,6 +536,56 @@ async def _async_test_simple(playground, metadata_xml_files, loop):
lambda: shutil.rmtree(pkgdir),
lambda: os.rename(binhost_dir, pkgdir),
)
+ return test_commands
+
+
+@pytest.mark.parametrize("binpkg_format", SUPPORTED_GENTOO_BINPKG_FORMATS)
+def test_simple_emerge(binpkg_format):
+ playground = ResolverPlayground(
+ ebuilds=_AVAILABLE_EBUILDS,
+ installed=_INSTALLED_EBUILDS,
+ debug=False,
+ user_config={
+ "make.conf": (f'BINPKG_FORMAT="{binpkg_format}"',),
+ },
+ )
+
+ loop = asyncio._wrap_loop()
+ loop.run_until_complete(
+ asyncio.ensure_future(
+ _async_test_simple(playground, _METADATA_XML_FILES, loop=loop),
+ loop=loop,
+ )
+ )
+
+
+async def _async_test_simple(playground, metadata_xml_files, loop):
+ debug = playground.debug
+ settings = playground.settings
+ trees = playground.trees
+ eprefix = settings["EPREFIX"]
+ binhost_dir = os.path.join(eprefix, "binhost")
+ binhost_address = "127.0.0.1"
+ binhost_remote_path = "/binhost"
+ binhost_server = AsyncHTTPServer(
+ binhost_address, BinhostContentMap(binhost_remote_path, binhost_dir), loop
+ ).__enter__()
+ binhost_uri = "http://{address}:{port}{path}".format(
+ address=binhost_address,
+ port=binhost_server.server_port,
+ path=binhost_remote_path,
+ )
+
+ test_commands = make_test_commands(settings, trees, binhost_uri)
+
+ test_repo_location = settings.repositories["test_repo"].location
+ var_cache_edb = os.path.join(eprefix, "var", "cache", "edb")
+ cachedir = os.path.join(var_cache_edb, "dep")
+ cachedir_pregen = os.path.join(test_repo_location, "metadata", "md5-cache")
+
+ cross_prefix = os.path.join(eprefix, "cross_prefix")
+ cross_root = os.path.join(eprefix, "cross_root")
+ cross_eroot = os.path.join(cross_root, eprefix.lstrip(os.sep))
distdir = playground.distdir
pkgdir = playground.pkgdir
@@ -611,7 +626,7 @@ async def _async_test_simple(playground, metadata_xml_files, loop):
"PKGDIR": pkgdir,
"PORTAGE_INST_GID": str(os.getgid()), # str(portage.data.portage_gid),
"PORTAGE_INST_UID": str(os.getuid()), # str(portage.data.portage_uid),
- "PORTAGE_PYTHON": portage_python,
+ "PORTAGE_PYTHON": portage._python_interpreter,
"PORTAGE_REPOSITORIES": settings.repositories.config_string(),
"PORTAGE_TMPDIR": portage_tmpdir,
"PORTAGE_LOGDIR": portage_tmpdir,
@@ -667,7 +682,6 @@ slotmove =app-doc/pms-3 2 3
move dev-util/git dev-vcs/git
"""
)
-
if debug:
# The subprocess inherits both stdout and stderr, for
# debugging purposes.
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/emerge/
@ 2023-10-30 3:14 Sam James
0 siblings, 0 replies; 38+ messages in thread
From: Sam James @ 2023-10-30 3:14 UTC (permalink / raw
To: gentoo-commits
commit: 1450a9c5ddf45656545cfcd92c0917173adc9c54
Author: David Palao <david.palao <AT> gmail <DOT> com>
AuthorDate: Wed Jun 21 10:55:29 2023 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Oct 30 03:14:22 2023 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=1450a9c5
tests/emerge: Add async_loop and binhost fixtures
Add async_loop and binhost fixtures.
This is a refactor: some setup code is moved from conftest.py to
test_simple.py.
Signed-off-by: David Palao <david.palao <AT> gmail.com>
Signed-off-by: Sam James <sam <AT> gentoo.org>
lib/portage/tests/emerge/conftest.py | 47 ++++++++++
lib/portage/tests/emerge/test_simple.py | 151 +++++++++++++-------------------
2 files changed, 106 insertions(+), 92 deletions(-)
diff --git a/lib/portage/tests/emerge/conftest.py b/lib/portage/tests/emerge/conftest.py
index 8b62613fd6..716bb6a85e 100644
--- a/lib/portage/tests/emerge/conftest.py
+++ b/lib/portage/tests/emerge/conftest.py
@@ -3,6 +3,10 @@
from portage.const import SUPPORTED_GENTOO_BINPKG_FORMATS
from portage.tests.resolver.ResolverPlayground import ResolverPlayground
+from portage.cache.mappings import Mapping
+from portage.tests.util.test_socks5 import AsyncHTTPServer
+from portage import os
+from portage.util.futures import asyncio
import pytest
@@ -163,6 +167,30 @@ _INSTALLED_EBUILDS = {
}
+class BinhostContentMap(Mapping):
+ def __init__(self, remote_path, local_path):
+ self._remote_path = remote_path
+ self._local_path = local_path
+
+ def __getitem__(self, request_path):
+ safe_path = os.path.normpath(request_path)
+ if not safe_path.startswith(self._remote_path + "/"):
+ raise KeyError(request_path)
+ local_path = os.path.join(
+ self._local_path, safe_path[len(self._remote_path) + 1 :]
+ )
+ try:
+ with open(local_path, "rb") as f:
+ return f.read()
+ except OSError:
+ raise KeyError(request_path)
+
+
+@pytest.fixture()
+def async_loop():
+ yield asyncio._wrap_loop()
+
+
@pytest.fixture(params=SUPPORTED_GENTOO_BINPKG_FORMATS)
def playground(request):
"""Fixture that provides instances of ``ResolverPlayground``
@@ -178,3 +206,22 @@ def playground(request):
)
yield playground
playground.cleanup()
+
+
+@pytest.fixture()
+def binhost(playground, async_loop):
+ settings = playground.settings
+ eprefix = settings["EPREFIX"]
+ binhost_dir = os.path.join(eprefix, "binhost")
+ binhost_address = "127.0.0.1"
+ binhost_remote_path = "/binhost"
+ binhost_server = AsyncHTTPServer(
+ binhost_address, BinhostContentMap(binhost_remote_path, binhost_dir), async_loop
+ ).__enter__()
+ binhost_uri = "http://{address}:{port}{path}".format(
+ address=binhost_address,
+ port=binhost_server.server_port,
+ path=binhost_remote_path,
+ )
+ yield {"server": binhost_server, "uri": binhost_uri}
+ binhost_server.__exit__(None, None, None)
diff --git a/lib/portage/tests/emerge/test_simple.py b/lib/portage/tests/emerge/test_simple.py
index 2aa9b1bfc0..0389961740 100644
--- a/lib/portage/tests/emerge/test_simple.py
+++ b/lib/portage/tests/emerge/test_simple.py
@@ -15,10 +15,8 @@ from portage.const import (
USER_CONFIG_PATH,
SUPPORTED_GENTOO_BINPKG_FORMATS,
)
-from portage.cache.mappings import Mapping
from portage.process import find_binary
from portage.tests import cnf_bindir, cnf_sbindir, cnf_etc_path
-from portage.tests.util.test_socks5 import AsyncHTTPServer
from portage.util import ensure_dirs, find_updated_config_files, shlex_split
from portage.util.futures import asyncio
@@ -48,25 +46,6 @@ def _have_python_xml():
return True
-class BinhostContentMap(Mapping):
- def __init__(self, remote_path, local_path):
- self._remote_path = remote_path
- self._local_path = local_path
-
- def __getitem__(self, request_path):
- safe_path = os.path.normpath(request_path)
- if not safe_path.startswith(self._remote_path + "/"):
- raise KeyError(request_path)
- local_path = os.path.join(
- self._local_path, safe_path[len(self._remote_path) + 1 :]
- )
- try:
- with open(local_path, "rb") as f:
- return f.read()
- except OSError:
- raise KeyError(request_path)
-
-
def make_test_commands(settings, trees, binhost_uri):
eprefix = settings["EPREFIX"]
eroot = settings["EROOT"]
@@ -383,34 +362,24 @@ def make_test_commands(settings, trees, binhost_uri):
return test_commands
-def test_simple_emerge(playground):
- loop = asyncio._wrap_loop()
- loop.run_until_complete(
+def test_simple_emerge(async_loop, playground, binhost):
+ async_loop.run_until_complete(
asyncio.ensure_future(
- _async_test_simple(playground, _METADATA_XML_FILES, loop=loop),
- loop=loop,
+ _async_test_simple(
+ playground, binhost, _METADATA_XML_FILES, loop=async_loop
+ ),
+ loop=async_loop,
)
)
-async def _async_test_simple(playground, metadata_xml_files, loop):
+async def _async_test_simple(playground, binhost, metadata_xml_files, loop):
debug = playground.debug
settings = playground.settings
trees = playground.trees
eprefix = settings["EPREFIX"]
- binhost_dir = os.path.join(eprefix, "binhost")
- binhost_address = "127.0.0.1"
- binhost_remote_path = "/binhost"
- binhost_server = AsyncHTTPServer(
- binhost_address, BinhostContentMap(binhost_remote_path, binhost_dir), loop
- ).__enter__()
- binhost_uri = "http://{address}:{port}{path}".format(
- address=binhost_address,
- port=binhost_server.server_port,
- path=binhost_remote_path,
- )
- test_commands = make_test_commands(settings, trees, binhost_uri)
+ test_commands = make_test_commands(settings, trees, binhost["uri"])
test_repo_location = settings.repositories["test_repo"].location
var_cache_edb = os.path.join(eprefix, "var", "cache", "edb")
@@ -494,62 +463,60 @@ async def _async_test_simple(playground, metadata_xml_files, loop):
true_symlinks = ["find", "prepstrip", "sed", "scanelf"]
true_binary = find_binary("true")
assert true_binary is not None, "true command not found"
- try:
- for d in dirs:
- ensure_dirs(d)
- for x in true_symlinks:
- os.symlink(true_binary, os.path.join(fake_bin, x))
- for x in etc_symlinks:
- os.symlink(os.path.join(cnf_etc_path, x), os.path.join(eprefix, "etc", x))
- with open(os.path.join(var_cache_edb, "counter"), "wb") as f:
- f.write(b"100")
- # non-empty system set keeps --depclean quiet
- with open(os.path.join(profile_path, "packages"), "w") as f:
- f.write("*dev-libs/token-system-pkg")
- for cp, xml_data in metadata_xml_files:
- with open(os.path.join(test_repo_location, cp, "metadata.xml"), "w") as f:
- f.write(playground.metadata_xml_template % xml_data)
- with open(os.path.join(updates_dir, "1Q-2010"), "w") as f:
- f.write(
- """
+
+ for d in dirs:
+ ensure_dirs(d)
+ for x in true_symlinks:
+ os.symlink(true_binary, os.path.join(fake_bin, x))
+ for x in etc_symlinks:
+ os.symlink(os.path.join(cnf_etc_path, x), os.path.join(eprefix, "etc", x))
+ with open(os.path.join(var_cache_edb, "counter"), "wb") as f:
+ f.write(b"100")
+ # non-empty system set keeps --depclean quiet
+ with open(os.path.join(profile_path, "packages"), "w") as f:
+ f.write("*dev-libs/token-system-pkg")
+ for cp, xml_data in metadata_xml_files:
+ with open(os.path.join(test_repo_location, cp, "metadata.xml"), "w") as f:
+ f.write(playground.metadata_xml_template % xml_data)
+ with open(os.path.join(updates_dir, "1Q-2010"), "w") as f:
+ f.write(
+ """
slotmove =app-doc/pms-3 2 3
move dev-util/git dev-vcs/git
"""
- )
+ )
+ if debug:
+ # The subprocess inherits both stdout and stderr, for
+ # debugging purposes.
+ stdout = None
+ else:
+ # The subprocess inherits stderr so that any warnings
+ # triggered by python -Wd will be visible.
+ stdout = subprocess.PIPE
+
+ for idx, args in enumerate(test_commands):
+ if hasattr(args, "__call__"):
+ args()
+ continue
+
+ if isinstance(args[0], dict):
+ local_env = env.copy()
+ local_env.update(args[0])
+ args = args[1:]
+ else:
+ local_env = env
+
+ # with self.subTest(cmd=args, i=idx):
+ proc = await asyncio.create_subprocess_exec(
+ *args, env=local_env, stderr=None, stdout=stdout
+ )
+
if debug:
- # The subprocess inherits both stdout and stderr, for
- # debugging purposes.
- stdout = None
+ await proc.wait()
else:
- # The subprocess inherits stderr so that any warnings
- # triggered by python -Wd will be visible.
- stdout = subprocess.PIPE
-
- for idx, args in enumerate(test_commands):
- if hasattr(args, "__call__"):
- args()
- continue
-
- if isinstance(args[0], dict):
- local_env = env.copy()
- local_env.update(args[0])
- args = args[1:]
- else:
- local_env = env
-
- # with self.subTest(cmd=args, i=idx):
- proc = await asyncio.create_subprocess_exec(
- *args, env=local_env, stderr=None, stdout=stdout
- )
+ output, _err = await proc.communicate()
+ await proc.wait()
+ if proc.returncode != os.EX_OK:
+ portage.writemsg(output)
- if debug:
- await proc.wait()
- else:
- output, _err = await proc.communicate()
- await proc.wait()
- if proc.returncode != os.EX_OK:
- portage.writemsg(output)
-
- assert os.EX_OK == proc.returncode, f"emerge failed with args {args}"
- finally:
- binhost_server.__exit__(None, None, None)
+ assert os.EX_OK == proc.returncode, f"emerge failed with args {args}"
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/emerge/
@ 2023-10-30 3:14 Sam James
0 siblings, 0 replies; 38+ messages in thread
From: Sam James @ 2023-10-30 3:14 UTC (permalink / raw
To: gentoo-commits
commit: 2dde25d65a1131f8298265ead1028716a814f27d
Author: David Palao <david.palao <AT> gmail <DOT> com>
AuthorDate: Fri Jul 7 13:29:23 2023 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Oct 30 03:14:22 2023 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=2dde25d6
tests/emerge: test_simple.py: Complete pytest parametrization
Complete pytest parametrization. The test_simple_emerge is completely
parametrized in commands and in binary formats. This commit is the first
implementation. Further refactorings/improvements shall follow.
Signed-off-by: David Palao <david.palao <AT> gmail.com>
Signed-off-by: Sam James <sam <AT> gentoo.org>
lib/portage/tests/emerge/conftest.py | 590 ++++++++++++++++++++++----------
lib/portage/tests/emerge/test_simple.py | 19 +-
2 files changed, 419 insertions(+), 190 deletions(-)
diff --git a/lib/portage/tests/emerge/conftest.py b/lib/portage/tests/emerge/conftest.py
index 6f78f17935..a637aa885b 100644
--- a/lib/portage/tests/emerge/conftest.py
+++ b/lib/portage/tests/emerge/conftest.py
@@ -12,9 +12,11 @@ from portage.tests.resolver.ResolverPlayground import ResolverPlayground
from portage.cache.mappings import Mapping
from portage.tests.util.test_socks5 import AsyncHTTPServer
from portage import os
+from portage import shutil
from portage.util.futures import asyncio
from portage.tests import cnf_bindir, cnf_sbindir
from portage.process import find_binary
+from portage.util import find_updated_config_files, shlex_split
import portage
import pytest
@@ -176,6 +178,36 @@ _INSTALLED_EBUILDS = {
}
+# class SimpleTestCommand:
+# """A class that represents a simple test case command,
+# including post checks, preparation and cleanup.
+# """
+# def __init__(self, command, *options, environment=None):
+# self._command = command
+# self._options = options
+# if environment is None:
+# environment = {}
+# self.environment = environment
+
+# def prepare(self):
+# ...
+
+# def cleanup(self):
+# ...
+
+
+_TEST_COMMAND_NAMES_FETCHCOMMAND = [
+ "mv {pkgdir} {binhost_dir}",
+ "emerge -eG dev-libs/A",
+ "rm -R {pkgdir} (1)",
+ "mv {binhost_dir} {pkgdir}",
+ "rm {binrepos_conf_file}",
+ "mv {pkgdir} {binhost_dir} (2)",
+ "PORTAGE_BINHOST={binhost_uri} emerge -feG dev-libs/A",
+ "rm -R {pkgdir} (2)",
+ "mv {binhost_dir} {pkgdir} (2)",
+]
+
_TEST_COMMAND_NAMES = [
"emerge_w_parse_intermixed_args",
"emerge --root --quickpkg-direct-root",
@@ -204,7 +236,66 @@ _TEST_COMMAND_NAMES = [
"emerge --metadata",
"rm -rf {cachedir} (6)",
"emerge --oneshot virtual/foo",
-]
+ "foo pkg missing",
+ "FEATURES=unmerge-backup emerge --unmerge virtual/foo",
+ "foo pkg exists",
+ "emerge --pretend dev-libs/A",
+ "ebuild dev-libs/A-1 manifest clean package merge",
+ "emerge --pretend --tree --complete-graph dev-libs/A",
+ "emerge -p dev-libs/B",
+ "emerge -p --newrepo dev-libs/B",
+ "emerge -B dev-libs/B",
+ "emerge -1k dev-libs/B",
+ "ebuild dev-libs/A-1 unpack",
+ "emerge -1 dev-libs/A",
+ "emerge -n dev-libs/A",
+ "emerge --config dev-libs/A",
+ "emerge --info dev-libs/A dev-libs/B",
+ "emerge -pcv dev-libs/B",
+ "emerge -pc",
+ "emerge -c",
+ "quickpkg --include-config y dev-libs/A",
+ "no protected files",
+ "rm /etc/A-0",
+ "emerge -K dev-libs/A",
+ "one protected file",
+ "emaint --check all",
+ "emaint --fix all",
+ "fixpackages",
+ "regenworld",
+ "portageq match {eroot} dev-libs/A",
+ "portageq best_visible {eroot} dev-libs/A",
+ "portageq best_visible {eroot} binary dev-libs/A",
+ "portageq contents {eroot} dev-libs/A-1",
+ "portageq metadata {eroot} ebuild dev-libs/A-1 EAPI IUSE RDEPEND",
+ "portageq metadata {eroot} binary dev-libs/A-1 EAPI USE RDEPEND",
+ "portageq metadata {eroot} installed dev-libs/A-1 EAPI USE RDEPEND",
+ "portageq owners {eroot} {eroot}usr",
+ "emerge -p {eroot}usr",
+ "emerge -pCq {eroot}usr",
+ "emerge -Cq dev-libs/A",
+ "emerge -Cq dev-libs/B",
+ (
+ "EMERGE_DEFAULT_OPTS=--autounmask=n "
+ "emerge --autounmask --autounmask-continue dev-libs/C"
+ ),
+ "portageq match {eroot} dev-libs/D[flag]",
+ "EPREFIX={cross_prefix} emerge dev-libs/C",
+ "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/C",
+ "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/D",
+ "ROOT={cross_root} emerge dev-libs/D",
+ "portageq has_version {cross_eroot} dev-libs/D",
+ "EPREFIX={cross_prefix} emerge -K dev-libs/A",
+ "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/A",
+ "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/B",
+ "EPREFIX={cross_prefix} emerge -Cq dev-libs/B",
+ "EPREFIX={cross_prefix} emerge -Cq dev-libs/A",
+ "EPREFIX={cross_prefix} emerge dev-libs/A",
+ "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/A (2)",
+ "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/B (2)",
+ "ROOT={cross_root} emerge dev-libs/B",
+ "portageq has_version {cross_eroot} dev-libs/B",
+] + _TEST_COMMAND_NAMES_FETCHCOMMAND
def pytest_generate_tests(metafunc):
@@ -221,6 +312,18 @@ def _have_python_xml():
return True
+def _check_foo_file(pkgdir, filename, must_exist) -> None:
+ assert (
+ os.path.exists(os.path.join(pkgdir, "virtual", "foo", filename)) == must_exist
+ )
+
+
+def _check_number_of_protected_files(must_have, eroot, config_protect) -> None:
+ assert must_have == len(
+ list(find_updated_config_files(eroot, shlex_split(config_protect)))
+ )
+
+
class BinhostContentMap(Mapping):
def __init__(self, remote_path, local_path):
self._remote_path = remote_path
@@ -240,13 +343,13 @@ class BinhostContentMap(Mapping):
raise KeyError(request_path)
-@pytest.fixture()
+@pytest.fixture(scope="module")
def async_loop():
yield asyncio._wrap_loop()
-@pytest.fixture(params=SUPPORTED_GENTOO_BINPKG_FORMATS)
-def playground(request):
+@pytest.fixture(params=SUPPORTED_GENTOO_BINPKG_FORMATS, scope="module")
+def playground(request, tmp_path_factory):
"""Fixture that provides instances of ``ResolverPlayground``
each one with one supported value for ``BINPKG_FORMAT``."""
binpkg_format = request.param
@@ -257,6 +360,7 @@ def playground(request):
user_config={
"make.conf": (f'BINPKG_FORMAT="{binpkg_format}"',),
},
+ eprefix=str(tmp_path_factory.mktemp("eprefix", numbered=True)),
)
yield playground
playground.cleanup()
@@ -287,6 +391,7 @@ def simple_command(playground, binhost, request):
eprefix = settings["EPREFIX"]
eroot = settings["EROOT"]
trees = playground.trees
+ pkgdir = playground.pkgdir
portdb = trees[eroot]["porttree"].dbapi
test_repo_location = settings.repositories["test_repo"].location
var_cache_edb = os.path.join(eprefix, "var", "cache", "edb")
@@ -434,185 +539,308 @@ def simple_command(playground, binhost, request):
)
test_commands["emerge --metadata"] = emerge_cmd + ("--metadata",)
test_commands["rm -rf {cachedir} (6)"] = rm_cmd + ("-rf", cachedir)
+
test_commands["emerge --oneshot virtual/foo"] = emerge_cmd + (
"--oneshot",
"virtual/foo",
)
- # test_commands["virtual/foo exists"] = (
- # lambda: self.assertFalse(
- # os.path.exists(os.path.join(pkgdir, "virtual", "foo", foo_filename))
- # )
- # )
- # ({"FEATURES": "unmerge-backup"},) + emerge_cmd + ("--unmerge", "virtual/foo"),
- # lambda: self.assertTrue(
- # os.path.exists(os.path.join(pkgdir, "virtual", "foo", foo_filename))
- # ),
- # emerge_cmd + ("--pretend", "dev-libs/A"),
- # ebuild_cmd + (test_ebuild, "manifest", "clean", "package", "merge"),
- # emerge_cmd + ("--pretend", "--tree", "--complete-graph", "dev-libs/A"),
- # emerge_cmd + ("-p", "dev-libs/B"),
- # emerge_cmd + ("-p", "--newrepo", "dev-libs/B"),
- # emerge_cmd
- # + (
- # "-B",
- # "dev-libs/B",
- # ),
- # emerge_cmd
- # + (
- # "--oneshot",
- # "--usepkg",
- # "dev-libs/B",
- # ),
- # # trigger clean prior to pkg_pretend as in bug #390711
- # ebuild_cmd + (test_ebuild, "unpack"),
- # emerge_cmd
- # + (
- # "--oneshot",
- # "dev-libs/A",
- # ),
- # emerge_cmd
- # + (
- # "--noreplace",
- # "dev-libs/A",
- # ),
- # emerge_cmd
- # + (
- # "--config",
- # "dev-libs/A",
- # ),
- # emerge_cmd + ("--info", "dev-libs/A", "dev-libs/B"),
- # emerge_cmd + ("--pretend", "--depclean", "--verbose", "dev-libs/B"),
- # emerge_cmd
- # + (
- # "--pretend",
- # "--depclean",
- # ),
- # emerge_cmd + ("--depclean",),
- # quickpkg_cmd
- # + (
- # "--include-config",
- # "y",
- # "dev-libs/A",
- # ),
- # # Test bug #523684, where a file renamed or removed by the
- # # admin forces replacement files to be merged with config
- # # protection.
- # lambda: self.assertEqual(
- # 0,
- # len(
- # list(
- # find_updated_config_files(
- # eroot, shlex_split(settings["CONFIG_PROTECT"])
- # )
- # )
- # ),
- # ),
- # lambda: os.unlink(os.path.join(eprefix, "etc", "A-0")),
- # emerge_cmd + ("--usepkgonly", "dev-libs/A"),
- # lambda: self.assertEqual(
- # 1,
- # len(
- # list(
- # find_updated_config_files(
- # eroot, shlex_split(settings["CONFIG_PROTECT"])
- # )
- # )
- # ),
- # ),
- # emaint_cmd + ("--check", "all"),
- # emaint_cmd + ("--fix", "all"),
- # fixpackages_cmd,
- # regenworld_cmd,
- # portageq_cmd + ("match", eroot, "dev-libs/A"),
- # portageq_cmd + ("best_visible", eroot, "dev-libs/A"),
- # portageq_cmd + ("best_visible", eroot, "binary", "dev-libs/A"),
- # portageq_cmd + ("contents", eroot, "dev-libs/A-1"),
- # portageq_cmd
- # + ("metadata", eroot, "ebuild", "dev-libs/A-1", "EAPI", "IUSE", "RDEPEND"),
- # portageq_cmd
- # + ("metadata", eroot, "binary", "dev-libs/A-1", "EAPI", "USE", "RDEPEND"),
- # portageq_cmd
- # + (
- # "metadata",
- # eroot,
- # "installed",
- # "dev-libs/A-1",
- # "EAPI",
- # "USE",
- # "RDEPEND",
- # ),
- # portageq_cmd + ("owners", eroot, eroot + "usr"),
- # emerge_cmd + ("-p", eroot + "usr"),
- # emerge_cmd + ("-p", "--unmerge", "-q", eroot + "usr"),
- # emerge_cmd + ("--unmerge", "--quiet", "dev-libs/A"),
- # emerge_cmd + ("-C", "--quiet", "dev-libs/B"),
- # # If EMERGE_DEFAULT_OPTS contains --autounmask=n, then --autounmask
- # # must be specified with --autounmask-continue.
- # ({"EMERGE_DEFAULT_OPTS": "--autounmask=n"},)
- # + emerge_cmd
- # + (
- # "--autounmask",
- # "--autounmask-continue",
- # "dev-libs/C",
- # ),
- # # Verify that the above --autounmask-continue command caused
- # # USE=flag to be applied correctly to dev-libs/D.
- # portageq_cmd + ("match", eroot, "dev-libs/D[flag]"),
- # # Test cross-prefix usage, including chpathtool for binpkgs.
- # # EAPI 7
- # ({"EPREFIX": cross_prefix},) + emerge_cmd + ("dev-libs/C",),
- # ({"EPREFIX": cross_prefix},)
- # + portageq_cmd
- # + ("has_version", cross_prefix, "dev-libs/C"),
- # ({"EPREFIX": cross_prefix},)
- # + portageq_cmd
- # + ("has_version", cross_prefix, "dev-libs/D"),
- # ({"ROOT": cross_root},) + emerge_cmd + ("dev-libs/D",),
- # portageq_cmd + ("has_version", cross_eroot, "dev-libs/D"),
- # # EAPI 5
- # ({"EPREFIX": cross_prefix},) + emerge_cmd + ("--usepkgonly", "dev-libs/A"),
- # ({"EPREFIX": cross_prefix},)
- # + portageq_cmd
- # + ("has_version", cross_prefix, "dev-libs/A"),
- # ({"EPREFIX": cross_prefix},)
- # + portageq_cmd
- # + ("has_version", cross_prefix, "dev-libs/B"),
- # ({"EPREFIX": cross_prefix},) + emerge_cmd + ("-C", "--quiet", "dev-libs/B"),
- # ({"EPREFIX": cross_prefix},) + emerge_cmd + ("-C", "--quiet", "dev-libs/A"),
- # ({"EPREFIX": cross_prefix},) + emerge_cmd + ("dev-libs/A",),
- # ({"EPREFIX": cross_prefix},)
- # + portageq_cmd
- # + ("has_version", cross_prefix, "dev-libs/A"),
- # ({"EPREFIX": cross_prefix},)
- # + portageq_cmd
- # + ("has_version", cross_prefix, "dev-libs/B"),
- # # Test ROOT support
- # ({"ROOT": cross_root},) + emerge_cmd + ("dev-libs/B",),
- # portageq_cmd + ("has_version", cross_eroot, "dev-libs/B"),
- # )
-
- # # Test binhost support if FETCHCOMMAND is available.
- # binrepos_conf_file = os.path.join(os.sep, eprefix, BINREPOS_CONF_FILE)
- # binhost_uri = binhost["uri"]
- # binhost_dir = binhost["dir"]
- # with open(binrepos_conf_file, "w") as f:
- # f.write("[test-binhost]\n")
- # f.write(f"sync-uri = {binhost_uri}\n")
- # fetchcommand = portage.util.shlex_split(settings["FETCHCOMMAND"])
- # fetch_bin = portage.process.find_binary(fetchcommand[0])
- # if fetch_bin is not None:
- # test_commands = test_commands + (
- # lambda: os.rename(pkgdir, binhost_dir),
- # emerge_cmd + ("-e", "--getbinpkgonly", "dev-libs/A"),
- # lambda: shutil.rmtree(pkgdir),
- # lambda: os.rename(binhost_dir, pkgdir),
- # # Remove binrepos.conf and test PORTAGE_BINHOST.
- # lambda: os.unlink(binrepos_conf_file),
- # lambda: os.rename(pkgdir, binhost_dir),
- # ({"PORTAGE_BINHOST": binhost_uri},)
- # + emerge_cmd
- # + ("-fe", "--getbinpkgonly", "dev-libs/A"),
- # lambda: shutil.rmtree(pkgdir),
- # lambda: os.rename(binhost_dir, pkgdir),
- # )
+ test_commands["foo pkg missing"] = lambda: _check_foo_file(
+ pkgdir, foo_filename, must_exist=False
+ )
+
+ test_commands["FEATURES=unmerge-backup emerge --unmerge virtual/foo"] = (
+ ({"FEATURES": "unmerge-backup"},) + emerge_cmd + ("--unmerge", "virtual/foo")
+ )
+ test_commands["foo pkg exists"] = lambda: _check_foo_file(
+ pkgdir, foo_filename, must_exist=True
+ )
+
+ test_commands["emerge --pretend dev-libs/A"] = emerge_cmd + (
+ "--pretend",
+ "dev-libs/A",
+ )
+
+ test_commands["ebuild dev-libs/A-1 manifest clean package merge"] = ebuild_cmd + (
+ test_ebuild,
+ "manifest",
+ "clean",
+ "package",
+ "merge",
+ )
+ test_commands[
+ "emerge --pretend --tree --complete-graph dev-libs/A"
+ ] = emerge_cmd + ("--pretend", "--tree", "--complete-graph", "dev-libs/A")
+ test_commands["emerge -p dev-libs/B"] = emerge_cmd + ("-p", "dev-libs/B")
+ test_commands["emerge -p --newrepo dev-libs/B"] = emerge_cmd + (
+ "-p",
+ "--newrepo",
+ "dev-libs/B",
+ )
+ test_commands["emerge -B dev-libs/B"] = emerge_cmd + (
+ "-B",
+ "dev-libs/B",
+ )
+ test_commands["emerge -1k dev-libs/B"] = emerge_cmd + (
+ "--oneshot",
+ "--usepkg",
+ "dev-libs/B",
+ )
+ # trigger clean prior to pkg_pretend as in bug #390711
+ test_commands["ebuild dev-libs/A-1 unpack"] = ebuild_cmd + (test_ebuild, "unpack")
+ test_commands["emerge -1 dev-libs/A"] = emerge_cmd + ("--oneshot", "dev-libs/A")
+ test_commands["emerge -n dev-libs/A"] = emerge_cmd + ("--noreplace", "dev-libs/A")
+ test_commands["emerge --config dev-libs/A"] = emerge_cmd + (
+ "--config",
+ "dev-libs/A",
+ )
+ test_commands["emerge --info dev-libs/A dev-libs/B"] = emerge_cmd + (
+ "--info",
+ "dev-libs/A",
+ "dev-libs/B",
+ )
+ test_commands["emerge -pcv dev-libs/B"] = emerge_cmd + (
+ "--pretend",
+ "--depclean",
+ "--verbose",
+ "dev-libs/B",
+ )
+ test_commands["emerge -pc"] = emerge_cmd + ("--pretend", "--depclean")
+ test_commands["emerge -c"] = emerge_cmd + ("--depclean",)
+ test_commands["quickpkg --include-config y dev-libs/A"] = quickpkg_cmd + (
+ "--include-config",
+ "y",
+ "dev-libs/A",
+ )
+ # Test bug #523684, where a file renamed or removed by the
+ # admin forces replacement files to be merged with config
+ # protection.
+ test_commands["no protected files"] = lambda: _check_number_of_protected_files(
+ 0, eroot, settings["CONFIG_PROTECT"]
+ )
+ # Another "it is not a test command" case; actually setup:
+ test_commands["rm /etc/A-0"] = lambda: os.unlink(
+ os.path.join(eprefix, "etc", "A-0")
+ )
+ test_commands["emerge -K dev-libs/A"] = emerge_cmd + ("--usepkgonly", "dev-libs/A")
+ test_commands["one protected file"] = lambda: _check_number_of_protected_files(
+ 1, eroot, settings["CONFIG_PROTECT"]
+ )
+
+ test_commands["emaint --check all"] = emaint_cmd + ("--check", "all")
+ test_commands["emaint --fix all"] = emaint_cmd + ("--fix", "all")
+ test_commands["fixpackages"] = fixpackages_cmd
+ test_commands["regenworld"] = regenworld_cmd
+ test_commands["portageq match {eroot} dev-libs/A"] = portageq_cmd + (
+ "match",
+ eroot,
+ "dev-libs/A",
+ )
+ test_commands["portageq best_visible {eroot} dev-libs/A"] = portageq_cmd + (
+ "best_visible",
+ eroot,
+ "dev-libs/A",
+ )
+ test_commands["portageq best_visible {eroot} binary dev-libs/A"] = portageq_cmd + (
+ "best_visible",
+ eroot,
+ "binary",
+ "dev-libs/A",
+ )
+ test_commands["portageq contents {eroot} dev-libs/A-1"] = portageq_cmd + (
+ "contents",
+ eroot,
+ "dev-libs/A-1",
+ )
+ test_commands[
+ "portageq metadata {eroot} ebuild dev-libs/A-1 EAPI IUSE RDEPEND"
+ ] = portageq_cmd + (
+ "metadata",
+ eroot,
+ "ebuild",
+ "dev-libs/A-1",
+ "EAPI",
+ "IUSE",
+ "RDEPEND",
+ )
+ test_commands[
+ "portageq metadata {eroot} binary dev-libs/A-1 EAPI USE RDEPEND"
+ ] = portageq_cmd + (
+ "metadata",
+ eroot,
+ "binary",
+ "dev-libs/A-1",
+ "EAPI",
+ "USE",
+ "RDEPEND",
+ )
+ test_commands[
+ "portageq metadata {eroot} installed dev-libs/A-1 EAPI USE RDEPEND"
+ ] = portageq_cmd + (
+ "metadata",
+ eroot,
+ "installed",
+ "dev-libs/A-1",
+ "EAPI",
+ "USE",
+ "RDEPEND",
+ )
+ test_commands["portageq owners {eroot} {eroot}usr"] = portageq_cmd + (
+ "owners",
+ eroot,
+ eroot + "usr",
+ )
+ test_commands["emerge -p {eroot}usr"] = emerge_cmd + ("-p", eroot + "usr")
+ test_commands["emerge -pCq {eroot}usr"] = emerge_cmd + (
+ "-p",
+ "--unmerge",
+ "-q",
+ eroot + "usr",
+ )
+ test_commands["emerge -Cq dev-libs/A"] = emerge_cmd + (
+ "--unmerge",
+ "--quiet",
+ "dev-libs/A",
+ )
+ test_commands["emerge -Cq dev-libs/B"] = emerge_cmd + (
+ "-C",
+ "--quiet",
+ "dev-libs/B",
+ )
+
+ # autounmask:
+ # If EMERGE_DEFAULT_OPTS contains --autounmask=n, then --autounmask
+ # must be specified with --autounmask-continue.
+ test_commands[
+ "EMERGE_DEFAULT_OPTS=--autounmask=n "
+ "emerge --autounmask --autounmask-continue dev-libs/C"
+ ] = (
+ ({"EMERGE_DEFAULT_OPTS": "--autounmask=n"},)
+ + emerge_cmd
+ + ("--autounmask", "--autounmask-continue", "dev-libs/C")
+ )
+ # Verify that the above --autounmask-continue command caused
+ # USE=flag to be applied correctly to dev-libs/D.
+ test_commands["portageq match {eroot} dev-libs/D[flag]"] = portageq_cmd + (
+ "match",
+ eroot,
+ "dev-libs/D[flag]",
+ )
+ # Test cross-prefix usage, including chpathtool for binpkgs.
+ # EAPI 7
+ test_commands["EPREFIX={cross_prefix} emerge dev-libs/C"] = (
+ ({"EPREFIX": cross_prefix},) + emerge_cmd + ("dev-libs/C",)
+ )
+ test_commands[
+ "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/C"
+ ] = (
+ ({"EPREFIX": cross_prefix},)
+ + portageq_cmd
+ + ("has_version", cross_prefix, "dev-libs/C")
+ )
+ test_commands[
+ "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/D"
+ ] = (
+ ({"EPREFIX": cross_prefix},)
+ + portageq_cmd
+ + ("has_version", cross_prefix, "dev-libs/D")
+ )
+ test_commands["ROOT={cross_root} emerge dev-libs/D"] = (
+ ({"ROOT": cross_root},) + emerge_cmd + ("dev-libs/D",)
+ )
+ test_commands["portageq has_version {cross_eroot} dev-libs/D"] = portageq_cmd + (
+ "has_version",
+ cross_eroot,
+ "dev-libs/D",
+ )
+ # EAPI 5
+ test_commands["EPREFIX={cross_prefix} emerge -K dev-libs/A"] = (
+ ({"EPREFIX": cross_prefix},) + emerge_cmd + ("--usepkgonly", "dev-libs/A")
+ )
+ test_commands[
+ "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/A"
+ ] = (
+ ({"EPREFIX": cross_prefix},)
+ + portageq_cmd
+ + ("has_version", cross_prefix, "dev-libs/A")
+ )
+ test_commands[
+ "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/B"
+ ] = (
+ ({"EPREFIX": cross_prefix},)
+ + portageq_cmd
+ + ("has_version", cross_prefix, "dev-libs/B")
+ )
+ test_commands["EPREFIX={cross_prefix} emerge -Cq dev-libs/B"] = (
+ ({"EPREFIX": cross_prefix},) + emerge_cmd + ("-C", "--quiet", "dev-libs/B")
+ )
+ test_commands["EPREFIX={cross_prefix} emerge -Cq dev-libs/A"] = (
+ ({"EPREFIX": cross_prefix},) + emerge_cmd + ("-C", "--quiet", "dev-libs/A")
+ )
+ test_commands["EPREFIX={cross_prefix} emerge dev-libs/A"] = (
+ ({"EPREFIX": cross_prefix},) + emerge_cmd + ("dev-libs/A",)
+ )
+ test_commands[
+ "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/A (2)"
+ ] = (
+ ({"EPREFIX": cross_prefix},)
+ + portageq_cmd
+ + ("has_version", cross_prefix, "dev-libs/A")
+ )
+ test_commands[
+ "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/B (2)"
+ ] = (
+ ({"EPREFIX": cross_prefix},)
+ + portageq_cmd
+ + ("has_version", cross_prefix, "dev-libs/B")
+ )
+ # Test ROOT support
+ test_commands["ROOT={cross_root} emerge dev-libs/B"] = (
+ ({"ROOT": cross_root},) + emerge_cmd + ("dev-libs/B",)
+ )
+ test_commands["portageq has_version {cross_eroot} dev-libs/B"] = portageq_cmd + (
+ "has_version",
+ cross_eroot,
+ "dev-libs/B",
+ )
+
+ # Test binhost support if FETCHCOMMAND is available.
+ binrepos_conf_file = os.path.join(os.sep, eprefix, BINREPOS_CONF_FILE)
+ binhost_uri = binhost["uri"]
+ binhost_dir = binhost["dir"]
+ with open(binrepos_conf_file, "w") as f:
+ f.write("[test-binhost]\n")
+ f.write(f"sync-uri = {binhost_uri}\n")
+ fetchcommand = portage.util.shlex_split(settings["FETCHCOMMAND"])
+ fetch_bin = portage.process.find_binary(fetchcommand[0])
+ if fetch_bin is None:
+ for command_name in _TEST_COMMAND_NAMES_FETCHCOMMAND:
+ test_commands[command_name] = lambda: ...
+ else:
+ test_commands["mv {pkgdir} {binhost_dir}"] = lambda: os.rename(
+ pkgdir, binhost_dir
+ )
+ test_commands["emerge -eG dev-libs/A"] = emerge_cmd + (
+ "-e",
+ "--getbinpkgonly",
+ "dev-libs/A",
+ )
+ test_commands["rm -R {pkgdir} (1)"] = lambda: shutil.rmtree(pkgdir)
+ test_commands["mv {binhost_dir} {pkgdir}"] = lambda: os.rename(
+ binhost_dir, pkgdir
+ )
+ # Remove binrepos.conf and test PORTAGE_BINHOST.
+ test_commands["rm {binrepos_conf_file}"] = lambda: os.unlink(binrepos_conf_file)
+ test_commands["mv {pkgdir} {binhost_dir} (2)"] = lambda: os.rename(
+ pkgdir, binhost_dir
+ )
+ test_commands["PORTAGE_BINHOST={binhost_uri} emerge -feG dev-libs/A"] = (
+ ({"PORTAGE_BINHOST": binhost_uri},)
+ + emerge_cmd
+ + ("-fe", "--getbinpkgonly", "dev-libs/A")
+ )
+ test_commands["rm -R {pkgdir} (2)"] = lambda: shutil.rmtree(pkgdir)
+ test_commands["mv {binhost_dir} {pkgdir} (2)"] = lambda: os.rename(
+ binhost_dir, pkgdir
+ )
+
return test_commands[request.param]
diff --git a/lib/portage/tests/emerge/test_simple.py b/lib/portage/tests/emerge/test_simple.py
index 6e417f8de3..700ddd9764 100644
--- a/lib/portage/tests/emerge/test_simple.py
+++ b/lib/portage/tests/emerge/test_simple.py
@@ -4,15 +4,14 @@
import subprocess
import portage
-from portage import shutil, os
+from portage import os
from portage.const import (
PORTAGE_PYM_PATH,
USER_CONFIG_PATH,
- SUPPORTED_GENTOO_BINPKG_FORMATS,
)
from portage.process import find_binary
from portage.tests import cnf_etc_path
-from portage.util import ensure_dirs, find_updated_config_files, shlex_split
+from portage.util import ensure_dirs
from portage.util.futures import asyncio
@@ -32,10 +31,6 @@ _METADATA_XML_FILES = (
)
-class SimpleTestCommand:
- ...
-
-
def test_simple_emerge(async_loop, playground, binhost, simple_command):
async_loop.run_until_complete(
asyncio.ensure_future(
@@ -145,9 +140,15 @@ async def _async_test_simple(playground, binhost, command, metadata_xml_files, l
for d in dirs:
ensure_dirs(d)
for x in true_symlinks:
- os.symlink(true_binary, os.path.join(fake_bin, x))
+ try:
+ os.symlink(true_binary, os.path.join(fake_bin, x))
+ except FileExistsError:
+ pass
for x in etc_symlinks:
- os.symlink(os.path.join(cnf_etc_path, x), os.path.join(eprefix, "etc", x))
+ try:
+ os.symlink(os.path.join(cnf_etc_path, x), os.path.join(eprefix, "etc", x))
+ except FileExistsError:
+ pass
with open(os.path.join(var_cache_edb, "counter"), "wb") as f:
f.write(b"100")
# non-empty system set keeps --depclean quiet
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/emerge/
@ 2023-10-30 3:14 Sam James
0 siblings, 0 replies; 38+ messages in thread
From: Sam James @ 2023-10-30 3:14 UTC (permalink / raw
To: gentoo-commits
commit: 51702de8fc2501c6d51157d9933c21295091e5f1
Author: David Palao <david.palao <AT> gmail <DOT> com>
AuthorDate: Fri Jul 7 14:45:20 2023 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Oct 30 03:14:23 2023 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=51702de8
tests/emerge: conftest.py: Fix issue in simple_command fixture
Fix issue in simple_command fixture. It was bad-defined in case
the argument parser missed the ability to parse intermixed args.
Also that command was renamed to make it more descriptive.
Signed-off-by: David Palao <david.palao <AT> gmail.com>
Signed-off-by: Sam James <sam <AT> gentoo.org>
lib/portage/tests/emerge/conftest.py | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/lib/portage/tests/emerge/conftest.py b/lib/portage/tests/emerge/conftest.py
index cfaf18c5f9..7675d4c78c 100644
--- a/lib/portage/tests/emerge/conftest.py
+++ b/lib/portage/tests/emerge/conftest.py
@@ -209,7 +209,7 @@ _TEST_COMMAND_NAMES_FETCHCOMMAND = [
]
_TEST_COMMAND_NAMES = [
- "emerge_w_parse_intermixed_args",
+ "emerge -1 dev-libs/A -v dev-libs/B",
"emerge --root --quickpkg-direct-root",
"emerge --quickpkg-direct-root",
"env-update",
@@ -475,12 +475,15 @@ def simple_command(playground, binhost, request):
test_commands = {}
if hasattr(argparse.ArgumentParser, "parse_intermixed_args"):
- test_commands["emerge_w_parse_intermixed_args"] = emerge_cmd + (
+ parse_intermixed_command = emerge_cmd + (
"--oneshot",
"dev-libs/A",
"-v",
"dev-libs/A",
)
+ else:
+ parse_intermixed_command = lambda: ...
+ test_commands["emerge -1 dev-libs/A -v dev-libs/B"] = parse_intermixed_command
test_commands["emerge --root --quickpkg-direct-root"] = emerge_cmd + (
"--usepkgonly",
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/emerge/
@ 2023-10-30 3:14 Sam James
0 siblings, 0 replies; 38+ messages in thread
From: Sam James @ 2023-10-30 3:14 UTC (permalink / raw
To: gentoo-commits
commit: a621e10e998eee127affb7bb2ba0da67aad751e7
Author: David Palao <david.palao <AT> gmail <DOT> com>
AuthorDate: Fri Jul 7 14:58:00 2023 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Oct 30 03:14:23 2023 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=a621e10e
pytest: Add some markers: ft, unit and stress
Add some markers: ft, unit and stress. And mark
test_simple.test_simple_emerge with ft, such that those tests can be
triggered with::
pytest -m ft
Signed-off-by: David Palao <david.palao <AT> gmail.com>
Signed-off-by: Sam James <sam <AT> gentoo.org>
lib/portage/tests/emerge/test_simple.py | 3 +++
1 file changed, 3 insertions(+)
diff --git a/lib/portage/tests/emerge/test_simple.py b/lib/portage/tests/emerge/test_simple.py
index 700ddd9764..692c6a9cb4 100644
--- a/lib/portage/tests/emerge/test_simple.py
+++ b/lib/portage/tests/emerge/test_simple.py
@@ -3,6 +3,8 @@
import subprocess
+import pytest
+
import portage
from portage import os
from portage.const import (
@@ -31,6 +33,7 @@ _METADATA_XML_FILES = (
)
+@pytest.mark.ft
def test_simple_emerge(async_loop, playground, binhost, simple_command):
async_loop.run_until_complete(
asyncio.ensure_future(
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/emerge/
@ 2023-10-30 3:14 Sam James
0 siblings, 0 replies; 38+ messages in thread
From: Sam James @ 2023-10-30 3:14 UTC (permalink / raw
To: gentoo-commits
commit: 4ce856328d23fffdd193b5fd1ceaab5e1bf414a8
Author: David Palao <david.palao <AT> gmail <DOT> com>
AuthorDate: Wed Jun 21 10:03:53 2023 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Oct 30 03:14:22 2023 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=4ce85632
tests/emerge/test_simple.py: move playground cleaunp to fixture
Signed-off-by: David Palao <david.palao <AT> gmail.com>
Signed-off-by: Sam James <sam <AT> gentoo.org>
lib/portage/tests/emerge/conftest.py | 4 +++-
lib/portage/tests/emerge/test_simple.py | 1 -
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/lib/portage/tests/emerge/conftest.py b/lib/portage/tests/emerge/conftest.py
index 18077de257..8b62613fd6 100644
--- a/lib/portage/tests/emerge/conftest.py
+++ b/lib/portage/tests/emerge/conftest.py
@@ -168,7 +168,7 @@ def playground(request):
"""Fixture that provides instances of ``ResolverPlayground``
each one with one supported value for ``BINPKG_FORMAT``."""
binpkg_format = request.param
- yield ResolverPlayground(
+ playground = ResolverPlayground(
ebuilds=_AVAILABLE_EBUILDS,
installed=_INSTALLED_EBUILDS,
debug=False,
@@ -176,3 +176,5 @@ def playground(request):
"make.conf": (f'BINPKG_FORMAT="{binpkg_format}"',),
},
)
+ yield playground
+ playground.cleanup()
diff --git a/lib/portage/tests/emerge/test_simple.py b/lib/portage/tests/emerge/test_simple.py
index 0907c51b33..2aa9b1bfc0 100644
--- a/lib/portage/tests/emerge/test_simple.py
+++ b/lib/portage/tests/emerge/test_simple.py
@@ -553,4 +553,3 @@ move dev-util/git dev-vcs/git
assert os.EX_OK == proc.returncode, f"emerge failed with args {args}"
finally:
binhost_server.__exit__(None, None, None)
- playground.cleanup()
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/emerge/
@ 2023-10-30 3:14 Sam James
0 siblings, 0 replies; 38+ messages in thread
From: Sam James @ 2023-10-30 3:14 UTC (permalink / raw
To: gentoo-commits
commit: 33fd1883b4099965dd3f885ab8d8850b6ea6040c
Author: David Palao <david.palao <AT> gmail <DOT> com>
AuthorDate: Fri Jul 7 15:15:51 2023 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Oct 30 03:14:23 2023 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=33fd1883
tests/emerge: test_simple.py, conftest.py: Refactor
Refactor:
- _TEST_COMMAND_*NAMES -> _SIMPLE_COMMAND_*SEQUENCE
- Added NOOP
- defined global constant
Signed-off-by: David Palao <david.palao <AT> gmail.com>
Signed-off-by: Sam James <sam <AT> gentoo.org>
lib/portage/tests/emerge/conftest.py | 53 +++++++++++++++++----------------
lib/portage/tests/emerge/test_simple.py | 12 ++++----
2 files changed, 33 insertions(+), 32 deletions(-)
diff --git a/lib/portage/tests/emerge/conftest.py b/lib/portage/tests/emerge/conftest.py
index 7675d4c78c..9cb4691f56 100644
--- a/lib/portage/tests/emerge/conftest.py
+++ b/lib/portage/tests/emerge/conftest.py
@@ -177,26 +177,7 @@ _INSTALLED_EBUILDS = {
},
}
-
-# class SimpleTestCommand:
-# """A class that represents a simple test case command,
-# including post checks, preparation and cleanup.
-# """
-# def __init__(self, command, *options, environment=None):
-# self._command = command
-# self._options = options
-# if environment is None:
-# environment = {}
-# self.environment = environment
-
-# def prepare(self):
-# ...
-
-# def cleanup(self):
-# ...
-
-
-_TEST_COMMAND_NAMES_FETCHCOMMAND = [
+_SIMPLE_COMMAND_FETCHCOMMAND_SEQUENCE = [
"mv {pkgdir} {binhost_dir}",
"emerge -eG dev-libs/A",
"rm -R {pkgdir}",
@@ -208,7 +189,7 @@ _TEST_COMMAND_NAMES_FETCHCOMMAND = [
"mv {binhost_dir} {pkgdir}",
]
-_TEST_COMMAND_NAMES = [
+_SIMPLE_COMMAND_SEQUENCE = [
"emerge -1 dev-libs/A -v dev-libs/B",
"emerge --root --quickpkg-direct-root",
"emerge --quickpkg-direct-root",
@@ -295,12 +276,32 @@ _TEST_COMMAND_NAMES = [
"EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/B",
"ROOT={cross_root} emerge dev-libs/B",
"portageq has_version {cross_eroot} dev-libs/B",
-] + _TEST_COMMAND_NAMES_FETCHCOMMAND
+] + _SIMPLE_COMMAND_FETCHCOMMAND_SEQUENCE
+
+NOOP = lambda: ...
+
+
+# class SimpleTestCommand:
+# """A class that represents a simple test case command,
+# including post checks, preparation and cleanup.
+# """
+# def __init__(self, command, *options, environment=None):
+# self._command = command
+# self._options = options
+# if environment is None:
+# environment = {}
+# self.environment = environment
+
+# def prepare(self):
+# ...
+
+# def cleanup(self):
+# ...
def pytest_generate_tests(metafunc):
if "simple_command" in metafunc.fixturenames:
- metafunc.parametrize("simple_command", _TEST_COMMAND_NAMES, indirect=True)
+ metafunc.parametrize("simple_command", _SIMPLE_COMMAND_SEQUENCE, indirect=True)
def _have_python_xml():
@@ -482,7 +483,7 @@ def simple_command(playground, binhost, request):
"dev-libs/A",
)
else:
- parse_intermixed_command = lambda: ...
+ parse_intermixed_command = NOOP
test_commands["emerge -1 dev-libs/A -v dev-libs/B"] = parse_intermixed_command
test_commands["emerge --root --quickpkg-direct-root"] = emerge_cmd + (
@@ -792,8 +793,8 @@ def simple_command(playground, binhost, request):
fetchcommand = portage.util.shlex_split(settings["FETCHCOMMAND"])
fetch_bin = portage.process.find_binary(fetchcommand[0])
if fetch_bin is None:
- for command_name in _TEST_COMMAND_NAMES_FETCHCOMMAND:
- test_commands[command_name] = lambda: ...
+ for command_name in _SIMPLE_COMMAND_FETCHCOMMAND_SEQUENCE:
+ test_commands[command_name] = NOOP
else:
test_commands["mv {pkgdir} {binhost_dir}"] = lambda: os.rename(
pkgdir, binhost_dir
diff --git a/lib/portage/tests/emerge/test_simple.py b/lib/portage/tests/emerge/test_simple.py
index 692c6a9cb4..12a16f2d93 100644
--- a/lib/portage/tests/emerge/test_simple.py
+++ b/lib/portage/tests/emerge/test_simple.py
@@ -32,6 +32,11 @@ _METADATA_XML_FILES = (
),
)
+_1Q_2010_UPDATE = """
+slotmove =app-doc/pms-3 2 3
+move dev-util/git dev-vcs/git
+"""
+
@pytest.mark.ft
def test_simple_emerge(async_loop, playground, binhost, simple_command):
@@ -161,12 +166,7 @@ async def _async_test_simple(playground, binhost, command, metadata_xml_files, l
with open(os.path.join(test_repo_location, cp, "metadata.xml"), "w") as f:
f.write(playground.metadata_xml_template % xml_data)
with open(os.path.join(updates_dir, "1Q-2010"), "w") as f:
- f.write(
- """
-slotmove =app-doc/pms-3 2 3
-move dev-util/git dev-vcs/git
-"""
- )
+ f.write(_1Q_2010_UPDATE)
if debug:
# The subprocess inherits both stdout and stderr, for
# debugging purposes.
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/emerge/
@ 2023-10-30 3:14 Sam James
0 siblings, 0 replies; 38+ messages in thread
From: Sam James @ 2023-10-30 3:14 UTC (permalink / raw
To: gentoo-commits
commit: 70482a9ea15fe27eea0ce3095defa12d98fcce75
Author: David Palao <david.palao <AT> gmail <DOT> com>
AuthorDate: Wed Jun 21 09:00:54 2023 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Oct 30 03:14:21 2023 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=70482a9e
tests/emerge: add initial conftest.py
Add initial conftest.py
It contains a basic ``playground`` fixture, which is parametrized
to yield a ``ResolverPlayground`` instance for each value of
``SUPPORTED_GENTOO_BINPKG_FORMATS``.
Signed-off-by: David Palao <david.palao <AT> gmail.com>
Signed-off-by: Sam James <sam <AT> gentoo.org>
lib/portage/tests/emerge/conftest.py | 178 ++++++++++++++++++++++++++++++++
lib/portage/tests/emerge/test_simple.py | 168 +-----------------------------
2 files changed, 179 insertions(+), 167 deletions(-)
diff --git a/lib/portage/tests/emerge/conftest.py b/lib/portage/tests/emerge/conftest.py
new file mode 100644
index 0000000000..18077de257
--- /dev/null
+++ b/lib/portage/tests/emerge/conftest.py
@@ -0,0 +1,178 @@
+# Copyright 2023 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+from portage.const import SUPPORTED_GENTOO_BINPKG_FORMATS
+from portage.tests.resolver.ResolverPlayground import ResolverPlayground
+
+import pytest
+
+
+_INSTALL_SOMETHING = """
+S="${WORKDIR}"
+
+pkg_pretend() {
+ einfo "called pkg_pretend for $CATEGORY/$PF"
+}
+
+src_install() {
+ einfo "installing something..."
+ insinto /usr/lib/${P}
+ echo "blah blah blah" > "${T}"/regular-file
+ doins "${T}"/regular-file
+ dosym regular-file /usr/lib/${P}/symlink || die
+
+ # Test CONFIG_PROTECT
+ insinto /etc
+ newins "${T}"/regular-file ${PN}-${SLOT%/*}
+
+ # Test code for bug #381629, using a copyright symbol encoded with latin-1.
+ # We use $(printf "\\xa9") rather than $'\\xa9', since printf apparently
+ # works in any case, while $'\\xa9' transforms to \\xef\\xbf\\xbd under
+ # some conditions. TODO: Find out why it transforms to \\xef\\xbf\\xbd when
+ # running tests for Python 3.2 (even though it's bash that is ultimately
+ # responsible for performing the transformation).
+ local latin_1_dir=/usr/lib/${P}/latin-1-$(printf "\\xa9")-directory
+ insinto "${latin_1_dir}"
+ echo "blah blah blah" > "${T}"/latin-1-$(printf "\\xa9")-regular-file || die
+ doins "${T}"/latin-1-$(printf "\\xa9")-regular-file
+ dosym latin-1-$(printf "\\xa9")-regular-file ${latin_1_dir}/latin-1-$(printf "\\xa9")-symlink || die
+
+ call_has_and_best_version
+}
+
+pkg_config() {
+ einfo "called pkg_config for $CATEGORY/$PF"
+}
+
+pkg_info() {
+ einfo "called pkg_info for $CATEGORY/$PF"
+}
+
+pkg_preinst() {
+ if ! ___eapi_best_version_and_has_version_support_-b_-d_-r; then
+ # The BROOT variable is unset during pkg_* phases for EAPI 7,
+ # therefore best/has_version -b is expected to fail if we attempt
+ # to call it for EAPI 7 here.
+ call_has_and_best_version
+ fi
+}
+
+call_has_and_best_version() {
+ local root_arg
+ if ___eapi_best_version_and_has_version_support_-b_-d_-r; then
+ root_arg="-b"
+ else
+ root_arg="--host-root"
+ fi
+ einfo "called ${EBUILD_PHASE_FUNC} for $CATEGORY/$PF"
+ einfo "EPREFIX=${EPREFIX}"
+ einfo "PORTAGE_OVERRIDE_EPREFIX=${PORTAGE_OVERRIDE_EPREFIX}"
+ einfo "ROOT=${ROOT}"
+ einfo "EROOT=${EROOT}"
+ einfo "SYSROOT=${SYSROOT}"
+ einfo "ESYSROOT=${ESYSROOT}"
+ einfo "BROOT=${BROOT}"
+ # Test that has_version and best_version work correctly with
+ # prefix (involves internal ROOT -> EROOT calculation in order
+ # to support ROOT override via the environment with EAPIs 3
+ # and later which support prefix).
+ if has_version $CATEGORY/$PN:$SLOT ; then
+ einfo "has_version detects an installed instance of $CATEGORY/$PN:$SLOT"
+ einfo "best_version reports that the installed instance is $(best_version $CATEGORY/$PN:$SLOT)"
+ else
+ einfo "has_version does not detect an installed instance of $CATEGORY/$PN:$SLOT"
+ fi
+ if [[ ${EPREFIX} != ${PORTAGE_OVERRIDE_EPREFIX} ]] ; then
+ if has_version ${root_arg} $CATEGORY/$PN:$SLOT ; then
+ einfo "has_version ${root_arg} detects an installed instance of $CATEGORY/$PN:$SLOT"
+ einfo "best_version ${root_arg} reports that the installed instance is $(best_version ${root_arg} $CATEGORY/$PN:$SLOT)"
+ else
+ einfo "has_version ${root_arg} does not detect an installed instance of $CATEGORY/$PN:$SLOT"
+ fi
+ fi
+}
+
+"""
+
+_AVAILABLE_EBUILDS = {
+ "dev-libs/A-1": {
+ "EAPI": "5",
+ "IUSE": "+flag",
+ "KEYWORDS": "x86",
+ "LICENSE": "GPL-2",
+ "MISC_CONTENT": _INSTALL_SOMETHING,
+ "RDEPEND": "flag? ( dev-libs/B[flag] )",
+ },
+ "dev-libs/B-1": {
+ "EAPI": "5",
+ "IUSE": "+flag",
+ "KEYWORDS": "x86",
+ "LICENSE": "GPL-2",
+ "MISC_CONTENT": _INSTALL_SOMETHING,
+ },
+ "dev-libs/C-1": {
+ "EAPI": "7",
+ "KEYWORDS": "~x86",
+ "RDEPEND": "dev-libs/D[flag]",
+ "MISC_CONTENT": _INSTALL_SOMETHING,
+ },
+ "dev-libs/D-1": {
+ "EAPI": "7",
+ "KEYWORDS": "~x86",
+ "IUSE": "flag",
+ "MISC_CONTENT": _INSTALL_SOMETHING,
+ },
+ "virtual/foo-0": {
+ "EAPI": "5",
+ "KEYWORDS": "x86",
+ "LICENSE": "GPL-2",
+ },
+}
+
+_INSTALLED_EBUILDS = {
+ "dev-libs/A-1": {
+ "EAPI": "5",
+ "IUSE": "+flag",
+ "KEYWORDS": "x86",
+ "LICENSE": "GPL-2",
+ "RDEPEND": "flag? ( dev-libs/B[flag] )",
+ "USE": "flag",
+ },
+ "dev-libs/B-1": {
+ "EAPI": "5",
+ "IUSE": "+flag",
+ "KEYWORDS": "x86",
+ "LICENSE": "GPL-2",
+ "USE": "flag",
+ },
+ "dev-libs/depclean-me-1": {
+ "EAPI": "5",
+ "IUSE": "",
+ "KEYWORDS": "x86",
+ "LICENSE": "GPL-2",
+ "USE": "",
+ },
+ "app-misc/depclean-me-1": {
+ "EAPI": "5",
+ "IUSE": "",
+ "KEYWORDS": "x86",
+ "LICENSE": "GPL-2",
+ "RDEPEND": "dev-libs/depclean-me",
+ "USE": "",
+ },
+}
+
+
+@pytest.fixture(params=SUPPORTED_GENTOO_BINPKG_FORMATS)
+def playground(request):
+ """Fixture that provides instances of ``ResolverPlayground``
+ each one with one supported value for ``BINPKG_FORMAT``."""
+ binpkg_format = request.param
+ yield ResolverPlayground(
+ ebuilds=_AVAILABLE_EBUILDS,
+ installed=_INSTALLED_EBUILDS,
+ debug=False,
+ user_config={
+ "make.conf": (f'BINPKG_FORMAT="{binpkg_format}"',),
+ },
+ )
diff --git a/lib/portage/tests/emerge/test_simple.py b/lib/portage/tests/emerge/test_simple.py
index 35e221311e..0907c51b33 100644
--- a/lib/portage/tests/emerge/test_simple.py
+++ b/lib/portage/tests/emerge/test_simple.py
@@ -18,167 +18,11 @@ from portage.const import (
from portage.cache.mappings import Mapping
from portage.process import find_binary
from portage.tests import cnf_bindir, cnf_sbindir, cnf_etc_path
-from portage.tests.resolver.ResolverPlayground import ResolverPlayground
from portage.tests.util.test_socks5 import AsyncHTTPServer
from portage.util import ensure_dirs, find_updated_config_files, shlex_split
from portage.util.futures import asyncio
-_INSTALL_SOMETHING = """
-S="${WORKDIR}"
-
-pkg_pretend() {
- einfo "called pkg_pretend for $CATEGORY/$PF"
-}
-
-src_install() {
- einfo "installing something..."
- insinto /usr/lib/${P}
- echo "blah blah blah" > "${T}"/regular-file
- doins "${T}"/regular-file
- dosym regular-file /usr/lib/${P}/symlink || die
-
- # Test CONFIG_PROTECT
- insinto /etc
- newins "${T}"/regular-file ${PN}-${SLOT%/*}
-
- # Test code for bug #381629, using a copyright symbol encoded with latin-1.
- # We use $(printf "\\xa9") rather than $'\\xa9', since printf apparently
- # works in any case, while $'\\xa9' transforms to \\xef\\xbf\\xbd under
- # some conditions. TODO: Find out why it transforms to \\xef\\xbf\\xbd when
- # running tests for Python 3.2 (even though it's bash that is ultimately
- # responsible for performing the transformation).
- local latin_1_dir=/usr/lib/${P}/latin-1-$(printf "\\xa9")-directory
- insinto "${latin_1_dir}"
- echo "blah blah blah" > "${T}"/latin-1-$(printf "\\xa9")-regular-file || die
- doins "${T}"/latin-1-$(printf "\\xa9")-regular-file
- dosym latin-1-$(printf "\\xa9")-regular-file ${latin_1_dir}/latin-1-$(printf "\\xa9")-symlink || die
-
- call_has_and_best_version
-}
-
-pkg_config() {
- einfo "called pkg_config for $CATEGORY/$PF"
-}
-
-pkg_info() {
- einfo "called pkg_info for $CATEGORY/$PF"
-}
-
-pkg_preinst() {
- if ! ___eapi_best_version_and_has_version_support_-b_-d_-r; then
- # The BROOT variable is unset during pkg_* phases for EAPI 7,
- # therefore best/has_version -b is expected to fail if we attempt
- # to call it for EAPI 7 here.
- call_has_and_best_version
- fi
-}
-
-call_has_and_best_version() {
- local root_arg
- if ___eapi_best_version_and_has_version_support_-b_-d_-r; then
- root_arg="-b"
- else
- root_arg="--host-root"
- fi
- einfo "called ${EBUILD_PHASE_FUNC} for $CATEGORY/$PF"
- einfo "EPREFIX=${EPREFIX}"
- einfo "PORTAGE_OVERRIDE_EPREFIX=${PORTAGE_OVERRIDE_EPREFIX}"
- einfo "ROOT=${ROOT}"
- einfo "EROOT=${EROOT}"
- einfo "SYSROOT=${SYSROOT}"
- einfo "ESYSROOT=${ESYSROOT}"
- einfo "BROOT=${BROOT}"
- # Test that has_version and best_version work correctly with
- # prefix (involves internal ROOT -> EROOT calculation in order
- # to support ROOT override via the environment with EAPIs 3
- # and later which support prefix).
- if has_version $CATEGORY/$PN:$SLOT ; then
- einfo "has_version detects an installed instance of $CATEGORY/$PN:$SLOT"
- einfo "best_version reports that the installed instance is $(best_version $CATEGORY/$PN:$SLOT)"
- else
- einfo "has_version does not detect an installed instance of $CATEGORY/$PN:$SLOT"
- fi
- if [[ ${EPREFIX} != ${PORTAGE_OVERRIDE_EPREFIX} ]] ; then
- if has_version ${root_arg} $CATEGORY/$PN:$SLOT ; then
- einfo "has_version ${root_arg} detects an installed instance of $CATEGORY/$PN:$SLOT"
- einfo "best_version ${root_arg} reports that the installed instance is $(best_version ${root_arg} $CATEGORY/$PN:$SLOT)"
- else
- einfo "has_version ${root_arg} does not detect an installed instance of $CATEGORY/$PN:$SLOT"
- fi
- fi
-}
-
-"""
-
-_AVAILABLE_EBUILDS = {
- "dev-libs/A-1": {
- "EAPI": "5",
- "IUSE": "+flag",
- "KEYWORDS": "x86",
- "LICENSE": "GPL-2",
- "MISC_CONTENT": _INSTALL_SOMETHING,
- "RDEPEND": "flag? ( dev-libs/B[flag] )",
- },
- "dev-libs/B-1": {
- "EAPI": "5",
- "IUSE": "+flag",
- "KEYWORDS": "x86",
- "LICENSE": "GPL-2",
- "MISC_CONTENT": _INSTALL_SOMETHING,
- },
- "dev-libs/C-1": {
- "EAPI": "7",
- "KEYWORDS": "~x86",
- "RDEPEND": "dev-libs/D[flag]",
- "MISC_CONTENT": _INSTALL_SOMETHING,
- },
- "dev-libs/D-1": {
- "EAPI": "7",
- "KEYWORDS": "~x86",
- "IUSE": "flag",
- "MISC_CONTENT": _INSTALL_SOMETHING,
- },
- "virtual/foo-0": {
- "EAPI": "5",
- "KEYWORDS": "x86",
- "LICENSE": "GPL-2",
- },
-}
-
-_INSTALLED_EBUILDS = {
- "dev-libs/A-1": {
- "EAPI": "5",
- "IUSE": "+flag",
- "KEYWORDS": "x86",
- "LICENSE": "GPL-2",
- "RDEPEND": "flag? ( dev-libs/B[flag] )",
- "USE": "flag",
- },
- "dev-libs/B-1": {
- "EAPI": "5",
- "IUSE": "+flag",
- "KEYWORDS": "x86",
- "LICENSE": "GPL-2",
- "USE": "flag",
- },
- "dev-libs/depclean-me-1": {
- "EAPI": "5",
- "IUSE": "",
- "KEYWORDS": "x86",
- "LICENSE": "GPL-2",
- "USE": "",
- },
- "app-misc/depclean-me-1": {
- "EAPI": "5",
- "IUSE": "",
- "KEYWORDS": "x86",
- "LICENSE": "GPL-2",
- "RDEPEND": "dev-libs/depclean-me",
- "USE": "",
- },
-}
-
_METADATA_XML_FILES = (
(
"dev-libs/A",
@@ -539,17 +383,7 @@ def make_test_commands(settings, trees, binhost_uri):
return test_commands
-@pytest.mark.parametrize("binpkg_format", SUPPORTED_GENTOO_BINPKG_FORMATS)
-def test_simple_emerge(binpkg_format):
- playground = ResolverPlayground(
- ebuilds=_AVAILABLE_EBUILDS,
- installed=_INSTALLED_EBUILDS,
- debug=False,
- user_config={
- "make.conf": (f'BINPKG_FORMAT="{binpkg_format}"',),
- },
- )
-
+def test_simple_emerge(playground):
loop = asyncio._wrap_loop()
loop.run_until_complete(
asyncio.ensure_future(
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/emerge/
@ 2023-10-30 3:14 Sam James
0 siblings, 0 replies; 38+ messages in thread
From: Sam James @ 2023-10-30 3:14 UTC (permalink / raw
To: gentoo-commits
commit: f294d967ec63c62caaa9f4d68b9c26acd1b1c95e
Author: David Palao <david.palao <AT> gmail <DOT> com>
AuthorDate: Fri Jun 9 14:43:24 2023 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Oct 30 03:14:21 2023 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=f294d967
tests/emerge/test_simple.py: pytest: introduce binpkg_format param
Signed-off-by: David Palao <david.palao <AT> gmail.com>
Signed-off-by: Sam James <sam <AT> gentoo.org>
lib/portage/tests/emerge/test_simple.py | 38 ++++++++++++++++-----------------
1 file changed, 18 insertions(+), 20 deletions(-)
diff --git a/lib/portage/tests/emerge/test_simple.py b/lib/portage/tests/emerge/test_simple.py
index ee95ef65e5..1c7d1bafbe 100644
--- a/lib/portage/tests/emerge/test_simple.py
+++ b/lib/portage/tests/emerge/test_simple.py
@@ -3,7 +3,8 @@
import argparse
import subprocess
-import sys
+
+import pytest
import portage
from portage import shutil, os
@@ -21,7 +22,6 @@ from portage.tests.resolver.ResolverPlayground import ResolverPlayground
from portage.tests.util.test_socks5 import AsyncHTTPServer
from portage.util import ensure_dirs, find_updated_config_files, shlex_split
from portage.util.futures import asyncio
-from portage.output import colorize
_INSTALL_SOMETHING = """
@@ -223,26 +223,24 @@ class BinhostContentMap(Mapping):
raise KeyError(request_path)
-def test_simple_emerge():
- debug = False
-
- for binpkg_format in SUPPORTED_GENTOO_BINPKG_FORMATS:
- playground = ResolverPlayground(
- ebuilds=_AVAILABLE_EBUILDS,
- installed=_INSTALLED_EBUILDS,
- debug=debug,
- user_config={
- "make.conf": (f'BINPKG_FORMAT="{binpkg_format}"',),
- },
- )
+@pytest.mark.parametrize("binpkg_format", SUPPORTED_GENTOO_BINPKG_FORMATS)
+def test_simple_emerge(binpkg_format):
+ playground = ResolverPlayground(
+ ebuilds=_AVAILABLE_EBUILDS,
+ installed=_INSTALLED_EBUILDS,
+ debug=False,
+ user_config={
+ "make.conf": (f'BINPKG_FORMAT="{binpkg_format}"',),
+ },
+ )
- loop = asyncio._wrap_loop()
- loop.run_until_complete(
- asyncio.ensure_future(
- _async_test_simple(playground, _METADATA_XML_FILES, loop=loop),
- loop=loop,
- )
+ loop = asyncio._wrap_loop()
+ loop.run_until_complete(
+ asyncio.ensure_future(
+ _async_test_simple(playground, _METADATA_XML_FILES, loop=loop),
+ loop=loop,
)
+ )
async def _async_test_simple(playground, metadata_xml_files, loop):
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/emerge/
@ 2023-10-30 3:14 Sam James
0 siblings, 0 replies; 38+ messages in thread
From: Sam James @ 2023-10-30 3:14 UTC (permalink / raw
To: gentoo-commits
commit: 25f666914fd7b7be845d4d1fb9fc276fad566779
Author: David Palao <david.palao <AT> gmail <DOT> com>
AuthorDate: Fri Jun 30 14:05:54 2023 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Oct 30 03:14:22 2023 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=25f66691
tests/emerge: Add simple_command parametrized fixture.
Add simple_command parametrized fixture. This is work in progress:
in order to include post-checks to some tests, a different approach
is needed.
Signed-off-by: David Palao <david.palao <AT> gmail.com>
Signed-off-by: Sam James <sam <AT> gentoo.org>
lib/portage/tests/emerge/conftest.py | 395 +++++++++++++++++++++++++++++++-
lib/portage/tests/emerge/test_simple.py | 391 +++----------------------------
2 files changed, 428 insertions(+), 358 deletions(-)
diff --git a/lib/portage/tests/emerge/conftest.py b/lib/portage/tests/emerge/conftest.py
index 716bb6a85e..6f78f17935 100644
--- a/lib/portage/tests/emerge/conftest.py
+++ b/lib/portage/tests/emerge/conftest.py
@@ -1,12 +1,21 @@
# Copyright 2023 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
-from portage.const import SUPPORTED_GENTOO_BINPKG_FORMATS
+import argparse
+
+from portage.const import (
+ SUPPORTED_GENTOO_BINPKG_FORMATS,
+ BASH_BINARY,
+ BINREPOS_CONF_FILE,
+)
from portage.tests.resolver.ResolverPlayground import ResolverPlayground
from portage.cache.mappings import Mapping
from portage.tests.util.test_socks5 import AsyncHTTPServer
from portage import os
from portage.util.futures import asyncio
+from portage.tests import cnf_bindir, cnf_sbindir
+from portage.process import find_binary
+import portage
import pytest
@@ -167,6 +176,51 @@ _INSTALLED_EBUILDS = {
}
+_TEST_COMMAND_NAMES = [
+ "emerge_w_parse_intermixed_args",
+ "emerge --root --quickpkg-direct-root",
+ "emerge --quickpkg-direct-root",
+ "env-update",
+ "portageq envvar",
+ "etc-update",
+ "dispatch-conf",
+ "emerge --version",
+ "emerge --info",
+ "emerge --info --verbose",
+ "emerge --list-sets",
+ "emerge --check-news",
+ "rm -rf {cachedir}",
+ "rm -rf {cachedir_pregen}",
+ "emerge --regen",
+ "rm -rf {cachedir} (2)",
+ "FEATURES=metadata-transfer emerge --regen",
+ "rm -rf {cachedir} (3)",
+ "FEATURES=metadata-transfer emerge --regen (2)",
+ "rm -rf {cachedir} (4)",
+ "egencache --update",
+ "FEATURES=metadata-transfer emerge --metadata",
+ "rm -rf {cachedir} (5)",
+ "FEATURES=metadata-transfer emerge --metadata (2)",
+ "emerge --metadata",
+ "rm -rf {cachedir} (6)",
+ "emerge --oneshot virtual/foo",
+]
+
+
+def pytest_generate_tests(metafunc):
+ if "simple_command" in metafunc.fixturenames:
+ metafunc.parametrize("simple_command", _TEST_COMMAND_NAMES, indirect=True)
+
+
+def _have_python_xml():
+ try:
+ __import__("xml.etree.ElementTree")
+ __import__("xml.parsers.expat").parsers.expat.ExpatError
+ except (AttributeError, ImportError):
+ return False
+ return True
+
+
class BinhostContentMap(Mapping):
def __init__(self, remote_path, local_path):
self._remote_path = remote_path
@@ -223,5 +277,342 @@ def binhost(playground, async_loop):
port=binhost_server.server_port,
path=binhost_remote_path,
)
- yield {"server": binhost_server, "uri": binhost_uri}
+ yield {"server": binhost_server, "uri": binhost_uri, "dir": binhost_dir}
binhost_server.__exit__(None, None, None)
+
+
+@pytest.fixture()
+def simple_command(playground, binhost, request):
+ settings = playground.settings
+ eprefix = settings["EPREFIX"]
+ eroot = settings["EROOT"]
+ trees = playground.trees
+ portdb = trees[eroot]["porttree"].dbapi
+ test_repo_location = settings.repositories["test_repo"].location
+ var_cache_edb = os.path.join(eprefix, "var", "cache", "edb")
+ cachedir = os.path.join(var_cache_edb, "dep")
+ cachedir_pregen = os.path.join(test_repo_location, "metadata", "md5-cache")
+
+ portage_python = portage._python_interpreter
+ dispatch_conf_cmd = (
+ portage_python,
+ "-b",
+ "-Wd",
+ os.path.join(cnf_sbindir, "dispatch-conf"),
+ )
+ ebuild_cmd = (portage_python, "-b", "-Wd", os.path.join(cnf_bindir, "ebuild"))
+ egencache_cmd = (
+ portage_python,
+ "-b",
+ "-Wd",
+ os.path.join(cnf_bindir, "egencache"),
+ "--repo",
+ "test_repo",
+ "--repositories-configuration",
+ settings.repositories.config_string(),
+ )
+ emerge_cmd = (portage_python, "-b", "-Wd", os.path.join(cnf_bindir, "emerge"))
+ emaint_cmd = (portage_python, "-b", "-Wd", os.path.join(cnf_sbindir, "emaint"))
+ env_update_cmd = (
+ portage_python,
+ "-b",
+ "-Wd",
+ os.path.join(cnf_sbindir, "env-update"),
+ )
+ etc_update_cmd = (BASH_BINARY, os.path.join(cnf_sbindir, "etc-update"))
+ fixpackages_cmd = (
+ portage_python,
+ "-b",
+ "-Wd",
+ os.path.join(cnf_sbindir, "fixpackages"),
+ )
+ portageq_cmd = (
+ portage_python,
+ "-b",
+ "-Wd",
+ os.path.join(cnf_bindir, "portageq"),
+ )
+ quickpkg_cmd = (
+ portage_python,
+ "-b",
+ "-Wd",
+ os.path.join(cnf_bindir, "quickpkg"),
+ )
+ regenworld_cmd = (
+ portage_python,
+ "-b",
+ "-Wd",
+ os.path.join(cnf_sbindir, "regenworld"),
+ )
+
+ rm_binary = find_binary("rm")
+ assert rm_binary is not None, "rm command not found"
+ rm_cmd = (rm_binary,)
+
+ egencache_extra_args = []
+ if _have_python_xml():
+ egencache_extra_args.append("--update-use-local-desc")
+
+ test_ebuild = portdb.findname("dev-libs/A-1")
+ assert test_ebuild is not None
+
+ cross_prefix = os.path.join(eprefix, "cross_prefix")
+ cross_root = os.path.join(eprefix, "cross_root")
+ cross_eroot = os.path.join(cross_root, eprefix.lstrip(os.sep))
+
+ binpkg_format = settings.get("BINPKG_FORMAT", SUPPORTED_GENTOO_BINPKG_FORMATS[0])
+ assert binpkg_format in ("xpak", "gpkg")
+ if binpkg_format == "xpak":
+ foo_filename = "foo-0-1.xpak"
+ elif binpkg_format == "gpkg":
+ foo_filename = "foo-0-1.gpkg.tar"
+
+ test_commands = {}
+
+ if hasattr(argparse.ArgumentParser, "parse_intermixed_args"):
+ test_commands["emerge_w_parse_intermixed_args"] = emerge_cmd + (
+ "--oneshot",
+ "dev-libs/A",
+ "-v",
+ "dev-libs/A",
+ )
+
+ test_commands["emerge --root --quickpkg-direct-root"] = emerge_cmd + (
+ "--usepkgonly",
+ "--root",
+ cross_root,
+ "--quickpkg-direct=y",
+ "--quickpkg-direct-root",
+ "/",
+ "dev-libs/A",
+ )
+ test_commands["emerge --quickpkg-direct-root"] = emerge_cmd + (
+ "--usepkgonly",
+ "--quickpkg-direct=y",
+ "--quickpkg-direct-root",
+ cross_root,
+ "dev-libs/A",
+ )
+ test_commands["env-update"] = env_update_cmd
+ test_commands["portageq envvar"] = portageq_cmd + (
+ "envvar",
+ "-v",
+ "CONFIG_PROTECT",
+ "EROOT",
+ "PORTAGE_CONFIGROOT",
+ "PORTAGE_TMPDIR",
+ "USERLAND",
+ )
+ test_commands["etc-update"] = etc_update_cmd
+ test_commands["dispatch-conf"] = dispatch_conf_cmd
+ test_commands["emerge --version"] = emerge_cmd + ("--version",)
+ test_commands["emerge --info"] = emerge_cmd + ("--info",)
+ test_commands["emerge --info --verbose"] = emerge_cmd + ("--info", "--verbose")
+ test_commands["emerge --list-sets"] = emerge_cmd + ("--list-sets",)
+ test_commands["emerge --check-news"] = emerge_cmd + ("--check-news",)
+ test_commands["rm -rf {cachedir}"] = rm_cmd + ("-rf", cachedir)
+ test_commands["rm -rf {cachedir_pregen}"] = rm_cmd + ("-rf", cachedir_pregen)
+ test_commands["emerge --regen"] = emerge_cmd + ("--regen",)
+ test_commands["rm -rf {cachedir} (2)"] = rm_cmd + ("-rf", cachedir)
+ test_commands["FEATURES=metadata-transfer emerge --regen"] = (
+ ({"FEATURES": "metadata-transfer"},) + emerge_cmd + ("--regen",)
+ )
+ test_commands["rm -rf {cachedir} (3)"] = rm_cmd + ("-rf", cachedir)
+ test_commands["FEATURES=metadata-transfer emerge --regen (2)"] = (
+ ({"FEATURES": "metadata-transfer"},) + emerge_cmd + ("--regen",)
+ )
+ test_commands["rm -rf {cachedir} (4)"] = rm_cmd + ("-rf", cachedir)
+ test_commands["egencache --update"] = (
+ egencache_cmd + ("--update",) + tuple(egencache_extra_args)
+ )
+ test_commands["FEATURES=metadata-transfer emerge --metadata"] = (
+ ({"FEATURES": "metadata-transfer"},) + emerge_cmd + ("--metadata",)
+ )
+ test_commands["rm -rf {cachedir} (5)"] = rm_cmd + ("-rf", cachedir)
+ test_commands["FEATURES=metadata-transfer emerge --metadata (2)"] = (
+ ({"FEATURES": "metadata-transfer"},) + emerge_cmd + ("--metadata",)
+ )
+ test_commands["emerge --metadata"] = emerge_cmd + ("--metadata",)
+ test_commands["rm -rf {cachedir} (6)"] = rm_cmd + ("-rf", cachedir)
+ test_commands["emerge --oneshot virtual/foo"] = emerge_cmd + (
+ "--oneshot",
+ "virtual/foo",
+ )
+ # test_commands["virtual/foo exists"] = (
+ # lambda: self.assertFalse(
+ # os.path.exists(os.path.join(pkgdir, "virtual", "foo", foo_filename))
+ # )
+ # )
+ # ({"FEATURES": "unmerge-backup"},) + emerge_cmd + ("--unmerge", "virtual/foo"),
+ # lambda: self.assertTrue(
+ # os.path.exists(os.path.join(pkgdir, "virtual", "foo", foo_filename))
+ # ),
+ # emerge_cmd + ("--pretend", "dev-libs/A"),
+ # ebuild_cmd + (test_ebuild, "manifest", "clean", "package", "merge"),
+ # emerge_cmd + ("--pretend", "--tree", "--complete-graph", "dev-libs/A"),
+ # emerge_cmd + ("-p", "dev-libs/B"),
+ # emerge_cmd + ("-p", "--newrepo", "dev-libs/B"),
+ # emerge_cmd
+ # + (
+ # "-B",
+ # "dev-libs/B",
+ # ),
+ # emerge_cmd
+ # + (
+ # "--oneshot",
+ # "--usepkg",
+ # "dev-libs/B",
+ # ),
+ # # trigger clean prior to pkg_pretend as in bug #390711
+ # ebuild_cmd + (test_ebuild, "unpack"),
+ # emerge_cmd
+ # + (
+ # "--oneshot",
+ # "dev-libs/A",
+ # ),
+ # emerge_cmd
+ # + (
+ # "--noreplace",
+ # "dev-libs/A",
+ # ),
+ # emerge_cmd
+ # + (
+ # "--config",
+ # "dev-libs/A",
+ # ),
+ # emerge_cmd + ("--info", "dev-libs/A", "dev-libs/B"),
+ # emerge_cmd + ("--pretend", "--depclean", "--verbose", "dev-libs/B"),
+ # emerge_cmd
+ # + (
+ # "--pretend",
+ # "--depclean",
+ # ),
+ # emerge_cmd + ("--depclean",),
+ # quickpkg_cmd
+ # + (
+ # "--include-config",
+ # "y",
+ # "dev-libs/A",
+ # ),
+ # # Test bug #523684, where a file renamed or removed by the
+ # # admin forces replacement files to be merged with config
+ # # protection.
+ # lambda: self.assertEqual(
+ # 0,
+ # len(
+ # list(
+ # find_updated_config_files(
+ # eroot, shlex_split(settings["CONFIG_PROTECT"])
+ # )
+ # )
+ # ),
+ # ),
+ # lambda: os.unlink(os.path.join(eprefix, "etc", "A-0")),
+ # emerge_cmd + ("--usepkgonly", "dev-libs/A"),
+ # lambda: self.assertEqual(
+ # 1,
+ # len(
+ # list(
+ # find_updated_config_files(
+ # eroot, shlex_split(settings["CONFIG_PROTECT"])
+ # )
+ # )
+ # ),
+ # ),
+ # emaint_cmd + ("--check", "all"),
+ # emaint_cmd + ("--fix", "all"),
+ # fixpackages_cmd,
+ # regenworld_cmd,
+ # portageq_cmd + ("match", eroot, "dev-libs/A"),
+ # portageq_cmd + ("best_visible", eroot, "dev-libs/A"),
+ # portageq_cmd + ("best_visible", eroot, "binary", "dev-libs/A"),
+ # portageq_cmd + ("contents", eroot, "dev-libs/A-1"),
+ # portageq_cmd
+ # + ("metadata", eroot, "ebuild", "dev-libs/A-1", "EAPI", "IUSE", "RDEPEND"),
+ # portageq_cmd
+ # + ("metadata", eroot, "binary", "dev-libs/A-1", "EAPI", "USE", "RDEPEND"),
+ # portageq_cmd
+ # + (
+ # "metadata",
+ # eroot,
+ # "installed",
+ # "dev-libs/A-1",
+ # "EAPI",
+ # "USE",
+ # "RDEPEND",
+ # ),
+ # portageq_cmd + ("owners", eroot, eroot + "usr"),
+ # emerge_cmd + ("-p", eroot + "usr"),
+ # emerge_cmd + ("-p", "--unmerge", "-q", eroot + "usr"),
+ # emerge_cmd + ("--unmerge", "--quiet", "dev-libs/A"),
+ # emerge_cmd + ("-C", "--quiet", "dev-libs/B"),
+ # # If EMERGE_DEFAULT_OPTS contains --autounmask=n, then --autounmask
+ # # must be specified with --autounmask-continue.
+ # ({"EMERGE_DEFAULT_OPTS": "--autounmask=n"},)
+ # + emerge_cmd
+ # + (
+ # "--autounmask",
+ # "--autounmask-continue",
+ # "dev-libs/C",
+ # ),
+ # # Verify that the above --autounmask-continue command caused
+ # # USE=flag to be applied correctly to dev-libs/D.
+ # portageq_cmd + ("match", eroot, "dev-libs/D[flag]"),
+ # # Test cross-prefix usage, including chpathtool for binpkgs.
+ # # EAPI 7
+ # ({"EPREFIX": cross_prefix},) + emerge_cmd + ("dev-libs/C",),
+ # ({"EPREFIX": cross_prefix},)
+ # + portageq_cmd
+ # + ("has_version", cross_prefix, "dev-libs/C"),
+ # ({"EPREFIX": cross_prefix},)
+ # + portageq_cmd
+ # + ("has_version", cross_prefix, "dev-libs/D"),
+ # ({"ROOT": cross_root},) + emerge_cmd + ("dev-libs/D",),
+ # portageq_cmd + ("has_version", cross_eroot, "dev-libs/D"),
+ # # EAPI 5
+ # ({"EPREFIX": cross_prefix},) + emerge_cmd + ("--usepkgonly", "dev-libs/A"),
+ # ({"EPREFIX": cross_prefix},)
+ # + portageq_cmd
+ # + ("has_version", cross_prefix, "dev-libs/A"),
+ # ({"EPREFIX": cross_prefix},)
+ # + portageq_cmd
+ # + ("has_version", cross_prefix, "dev-libs/B"),
+ # ({"EPREFIX": cross_prefix},) + emerge_cmd + ("-C", "--quiet", "dev-libs/B"),
+ # ({"EPREFIX": cross_prefix},) + emerge_cmd + ("-C", "--quiet", "dev-libs/A"),
+ # ({"EPREFIX": cross_prefix},) + emerge_cmd + ("dev-libs/A",),
+ # ({"EPREFIX": cross_prefix},)
+ # + portageq_cmd
+ # + ("has_version", cross_prefix, "dev-libs/A"),
+ # ({"EPREFIX": cross_prefix},)
+ # + portageq_cmd
+ # + ("has_version", cross_prefix, "dev-libs/B"),
+ # # Test ROOT support
+ # ({"ROOT": cross_root},) + emerge_cmd + ("dev-libs/B",),
+ # portageq_cmd + ("has_version", cross_eroot, "dev-libs/B"),
+ # )
+
+ # # Test binhost support if FETCHCOMMAND is available.
+ # binrepos_conf_file = os.path.join(os.sep, eprefix, BINREPOS_CONF_FILE)
+ # binhost_uri = binhost["uri"]
+ # binhost_dir = binhost["dir"]
+ # with open(binrepos_conf_file, "w") as f:
+ # f.write("[test-binhost]\n")
+ # f.write(f"sync-uri = {binhost_uri}\n")
+ # fetchcommand = portage.util.shlex_split(settings["FETCHCOMMAND"])
+ # fetch_bin = portage.process.find_binary(fetchcommand[0])
+ # if fetch_bin is not None:
+ # test_commands = test_commands + (
+ # lambda: os.rename(pkgdir, binhost_dir),
+ # emerge_cmd + ("-e", "--getbinpkgonly", "dev-libs/A"),
+ # lambda: shutil.rmtree(pkgdir),
+ # lambda: os.rename(binhost_dir, pkgdir),
+ # # Remove binrepos.conf and test PORTAGE_BINHOST.
+ # lambda: os.unlink(binrepos_conf_file),
+ # lambda: os.rename(pkgdir, binhost_dir),
+ # ({"PORTAGE_BINHOST": binhost_uri},)
+ # + emerge_cmd
+ # + ("-fe", "--getbinpkgonly", "dev-libs/A"),
+ # lambda: shutil.rmtree(pkgdir),
+ # lambda: os.rename(binhost_dir, pkgdir),
+ # )
+ return test_commands[request.param]
diff --git a/lib/portage/tests/emerge/test_simple.py b/lib/portage/tests/emerge/test_simple.py
index 0389961740..6e417f8de3 100644
--- a/lib/portage/tests/emerge/test_simple.py
+++ b/lib/portage/tests/emerge/test_simple.py
@@ -1,22 +1,17 @@
# Copyright 2011-2021, 2023 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
-import argparse
import subprocess
-import pytest
-
import portage
from portage import shutil, os
from portage.const import (
- BASH_BINARY,
- BINREPOS_CONF_FILE,
PORTAGE_PYM_PATH,
USER_CONFIG_PATH,
SUPPORTED_GENTOO_BINPKG_FORMATS,
)
from portage.process import find_binary
-from portage.tests import cnf_bindir, cnf_sbindir, cnf_etc_path
+from portage.tests import cnf_etc_path
from portage.util import ensure_dirs, find_updated_config_files, shlex_split
from portage.util.futures import asyncio
@@ -37,349 +32,32 @@ _METADATA_XML_FILES = (
)
-def _have_python_xml():
- try:
- __import__("xml.etree.ElementTree")
- __import__("xml.parsers.expat").parsers.expat.ExpatError
- except (AttributeError, ImportError):
- return False
- return True
-
-
-def make_test_commands(settings, trees, binhost_uri):
- eprefix = settings["EPREFIX"]
- eroot = settings["EROOT"]
- portdb = trees[eroot]["porttree"].dbapi
- test_repo_location = settings.repositories["test_repo"].location
- var_cache_edb = os.path.join(eprefix, "var", "cache", "edb")
- cachedir = os.path.join(var_cache_edb, "dep")
- cachedir_pregen = os.path.join(test_repo_location, "metadata", "md5-cache")
-
- portage_python = portage._python_interpreter
- dispatch_conf_cmd = (
- portage_python,
- "-b",
- "-Wd",
- os.path.join(cnf_sbindir, "dispatch-conf"),
- )
- ebuild_cmd = (portage_python, "-b", "-Wd", os.path.join(cnf_bindir, "ebuild"))
- egencache_cmd = (
- portage_python,
- "-b",
- "-Wd",
- os.path.join(cnf_bindir, "egencache"),
- "--repo",
- "test_repo",
- "--repositories-configuration",
- settings.repositories.config_string(),
- )
- emerge_cmd = (portage_python, "-b", "-Wd", os.path.join(cnf_bindir, "emerge"))
- emaint_cmd = (portage_python, "-b", "-Wd", os.path.join(cnf_sbindir, "emaint"))
- env_update_cmd = (
- portage_python,
- "-b",
- "-Wd",
- os.path.join(cnf_sbindir, "env-update"),
- )
- etc_update_cmd = (BASH_BINARY, os.path.join(cnf_sbindir, "etc-update"))
- fixpackages_cmd = (
- portage_python,
- "-b",
- "-Wd",
- os.path.join(cnf_sbindir, "fixpackages"),
- )
- portageq_cmd = (
- portage_python,
- "-b",
- "-Wd",
- os.path.join(cnf_bindir, "portageq"),
- )
- quickpkg_cmd = (
- portage_python,
- "-b",
- "-Wd",
- os.path.join(cnf_bindir, "quickpkg"),
- )
- regenworld_cmd = (
- portage_python,
- "-b",
- "-Wd",
- os.path.join(cnf_sbindir, "regenworld"),
- )
-
- rm_binary = find_binary("rm")
- assert rm_binary is not None, "rm command not found"
- rm_cmd = (rm_binary,)
-
- egencache_extra_args = []
- if _have_python_xml():
- egencache_extra_args.append("--update-use-local-desc")
-
- test_ebuild = portdb.findname("dev-libs/A-1")
- assert test_ebuild is not None
-
- cross_prefix = os.path.join(eprefix, "cross_prefix")
- cross_root = os.path.join(eprefix, "cross_root")
- cross_eroot = os.path.join(cross_root, eprefix.lstrip(os.sep))
-
- binpkg_format = settings.get("BINPKG_FORMAT", SUPPORTED_GENTOO_BINPKG_FORMATS[0])
- assert binpkg_format in ("xpak", "gpkg")
- if binpkg_format == "xpak":
- foo_filename = "foo-0-1.xpak"
- elif binpkg_format == "gpkg":
- foo_filename = "foo-0-1.gpkg.tar"
-
- test_commands = ()
-
- if hasattr(argparse.ArgumentParser, "parse_intermixed_args"):
- test_commands += (emerge_cmd + ("--oneshot", "dev-libs/A", "-v", "dev-libs/A"),)
-
- test_commands += (
- emerge_cmd
- + (
- "--usepkgonly",
- "--root",
- cross_root,
- "--quickpkg-direct=y",
- "--quickpkg-direct-root",
- "/",
- "dev-libs/A",
- ),
- emerge_cmd
- + (
- "--usepkgonly",
- "--quickpkg-direct=y",
- "--quickpkg-direct-root",
- cross_root,
- "dev-libs/A",
- ),
- env_update_cmd,
- portageq_cmd
- + (
- "envvar",
- "-v",
- "CONFIG_PROTECT",
- "EROOT",
- "PORTAGE_CONFIGROOT",
- "PORTAGE_TMPDIR",
- "USERLAND",
- ),
- etc_update_cmd,
- dispatch_conf_cmd,
- emerge_cmd + ("--version",),
- emerge_cmd + ("--info",),
- emerge_cmd + ("--info", "--verbose"),
- emerge_cmd + ("--list-sets",),
- emerge_cmd + ("--check-news",),
- rm_cmd + ("-rf", cachedir),
- rm_cmd + ("-rf", cachedir_pregen),
- emerge_cmd + ("--regen",),
- rm_cmd + ("-rf", cachedir),
- ({"FEATURES": "metadata-transfer"},) + emerge_cmd + ("--regen",),
- rm_cmd + ("-rf", cachedir),
- ({"FEATURES": "metadata-transfer"},) + emerge_cmd + ("--regen",),
- rm_cmd + ("-rf", cachedir),
- egencache_cmd + ("--update",) + tuple(egencache_extra_args),
- ({"FEATURES": "metadata-transfer"},) + emerge_cmd + ("--metadata",),
- rm_cmd + ("-rf", cachedir),
- ({"FEATURES": "metadata-transfer"},) + emerge_cmd + ("--metadata",),
- emerge_cmd + ("--metadata",),
- rm_cmd + ("-rf", cachedir),
- emerge_cmd + ("--oneshot", "virtual/foo"),
- lambda: self.assertFalse(
- os.path.exists(os.path.join(pkgdir, "virtual", "foo", foo_filename))
- ),
- ({"FEATURES": "unmerge-backup"},) + emerge_cmd + ("--unmerge", "virtual/foo"),
- lambda: self.assertTrue(
- os.path.exists(os.path.join(pkgdir, "virtual", "foo", foo_filename))
- ),
- emerge_cmd + ("--pretend", "dev-libs/A"),
- ebuild_cmd + (test_ebuild, "manifest", "clean", "package", "merge"),
- emerge_cmd + ("--pretend", "--tree", "--complete-graph", "dev-libs/A"),
- emerge_cmd + ("-p", "dev-libs/B"),
- emerge_cmd + ("-p", "--newrepo", "dev-libs/B"),
- emerge_cmd
- + (
- "-B",
- "dev-libs/B",
- ),
- emerge_cmd
- + (
- "--oneshot",
- "--usepkg",
- "dev-libs/B",
- ),
- # trigger clean prior to pkg_pretend as in bug #390711
- ebuild_cmd + (test_ebuild, "unpack"),
- emerge_cmd
- + (
- "--oneshot",
- "dev-libs/A",
- ),
- emerge_cmd
- + (
- "--noreplace",
- "dev-libs/A",
- ),
- emerge_cmd
- + (
- "--config",
- "dev-libs/A",
- ),
- emerge_cmd + ("--info", "dev-libs/A", "dev-libs/B"),
- emerge_cmd + ("--pretend", "--depclean", "--verbose", "dev-libs/B"),
- emerge_cmd
- + (
- "--pretend",
- "--depclean",
- ),
- emerge_cmd + ("--depclean",),
- quickpkg_cmd
- + (
- "--include-config",
- "y",
- "dev-libs/A",
- ),
- # Test bug #523684, where a file renamed or removed by the
- # admin forces replacement files to be merged with config
- # protection.
- lambda: self.assertEqual(
- 0,
- len(
- list(
- find_updated_config_files(
- eroot, shlex_split(settings["CONFIG_PROTECT"])
- )
- )
- ),
- ),
- lambda: os.unlink(os.path.join(eprefix, "etc", "A-0")),
- emerge_cmd + ("--usepkgonly", "dev-libs/A"),
- lambda: self.assertEqual(
- 1,
- len(
- list(
- find_updated_config_files(
- eroot, shlex_split(settings["CONFIG_PROTECT"])
- )
- )
- ),
- ),
- emaint_cmd + ("--check", "all"),
- emaint_cmd + ("--fix", "all"),
- fixpackages_cmd,
- regenworld_cmd,
- portageq_cmd + ("match", eroot, "dev-libs/A"),
- portageq_cmd + ("best_visible", eroot, "dev-libs/A"),
- portageq_cmd + ("best_visible", eroot, "binary", "dev-libs/A"),
- portageq_cmd + ("contents", eroot, "dev-libs/A-1"),
- portageq_cmd
- + ("metadata", eroot, "ebuild", "dev-libs/A-1", "EAPI", "IUSE", "RDEPEND"),
- portageq_cmd
- + ("metadata", eroot, "binary", "dev-libs/A-1", "EAPI", "USE", "RDEPEND"),
- portageq_cmd
- + (
- "metadata",
- eroot,
- "installed",
- "dev-libs/A-1",
- "EAPI",
- "USE",
- "RDEPEND",
- ),
- portageq_cmd + ("owners", eroot, eroot + "usr"),
- emerge_cmd + ("-p", eroot + "usr"),
- emerge_cmd + ("-p", "--unmerge", "-q", eroot + "usr"),
- emerge_cmd + ("--unmerge", "--quiet", "dev-libs/A"),
- emerge_cmd + ("-C", "--quiet", "dev-libs/B"),
- # If EMERGE_DEFAULT_OPTS contains --autounmask=n, then --autounmask
- # must be specified with --autounmask-continue.
- ({"EMERGE_DEFAULT_OPTS": "--autounmask=n"},)
- + emerge_cmd
- + (
- "--autounmask",
- "--autounmask-continue",
- "dev-libs/C",
- ),
- # Verify that the above --autounmask-continue command caused
- # USE=flag to be applied correctly to dev-libs/D.
- portageq_cmd + ("match", eroot, "dev-libs/D[flag]"),
- # Test cross-prefix usage, including chpathtool for binpkgs.
- # EAPI 7
- ({"EPREFIX": cross_prefix},) + emerge_cmd + ("dev-libs/C",),
- ({"EPREFIX": cross_prefix},)
- + portageq_cmd
- + ("has_version", cross_prefix, "dev-libs/C"),
- ({"EPREFIX": cross_prefix},)
- + portageq_cmd
- + ("has_version", cross_prefix, "dev-libs/D"),
- ({"ROOT": cross_root},) + emerge_cmd + ("dev-libs/D",),
- portageq_cmd + ("has_version", cross_eroot, "dev-libs/D"),
- # EAPI 5
- ({"EPREFIX": cross_prefix},) + emerge_cmd + ("--usepkgonly", "dev-libs/A"),
- ({"EPREFIX": cross_prefix},)
- + portageq_cmd
- + ("has_version", cross_prefix, "dev-libs/A"),
- ({"EPREFIX": cross_prefix},)
- + portageq_cmd
- + ("has_version", cross_prefix, "dev-libs/B"),
- ({"EPREFIX": cross_prefix},) + emerge_cmd + ("-C", "--quiet", "dev-libs/B"),
- ({"EPREFIX": cross_prefix},) + emerge_cmd + ("-C", "--quiet", "dev-libs/A"),
- ({"EPREFIX": cross_prefix},) + emerge_cmd + ("dev-libs/A",),
- ({"EPREFIX": cross_prefix},)
- + portageq_cmd
- + ("has_version", cross_prefix, "dev-libs/A"),
- ({"EPREFIX": cross_prefix},)
- + portageq_cmd
- + ("has_version", cross_prefix, "dev-libs/B"),
- # Test ROOT support
- ({"ROOT": cross_root},) + emerge_cmd + ("dev-libs/B",),
- portageq_cmd + ("has_version", cross_eroot, "dev-libs/B"),
- )
-
- # Test binhost support if FETCHCOMMAND is available.
- binrepos_conf_file = os.path.join(os.sep, eprefix, BINREPOS_CONF_FILE)
- with open(binrepos_conf_file, "w") as f:
- f.write("[test-binhost]\n")
- f.write(f"sync-uri = {binhost_uri}\n")
- fetchcommand = portage.util.shlex_split(settings["FETCHCOMMAND"])
- fetch_bin = portage.process.find_binary(fetchcommand[0])
- if fetch_bin is not None:
- test_commands = test_commands + (
- lambda: os.rename(pkgdir, binhost_dir),
- emerge_cmd + ("-e", "--getbinpkgonly", "dev-libs/A"),
- lambda: shutil.rmtree(pkgdir),
- lambda: os.rename(binhost_dir, pkgdir),
- # Remove binrepos.conf and test PORTAGE_BINHOST.
- lambda: os.unlink(binrepos_conf_file),
- lambda: os.rename(pkgdir, binhost_dir),
- ({"PORTAGE_BINHOST": binhost_uri},)
- + emerge_cmd
- + ("-fe", "--getbinpkgonly", "dev-libs/A"),
- lambda: shutil.rmtree(pkgdir),
- lambda: os.rename(binhost_dir, pkgdir),
- )
- return test_commands
+class SimpleTestCommand:
+ ...
-def test_simple_emerge(async_loop, playground, binhost):
+def test_simple_emerge(async_loop, playground, binhost, simple_command):
async_loop.run_until_complete(
asyncio.ensure_future(
_async_test_simple(
- playground, binhost, _METADATA_XML_FILES, loop=async_loop
+ playground,
+ binhost,
+ simple_command,
+ _METADATA_XML_FILES,
+ loop=async_loop,
),
loop=async_loop,
)
)
-async def _async_test_simple(playground, binhost, metadata_xml_files, loop):
+async def _async_test_simple(playground, binhost, command, metadata_xml_files, loop):
debug = playground.debug
settings = playground.settings
trees = playground.trees
eprefix = settings["EPREFIX"]
- test_commands = make_test_commands(settings, trees, binhost["uri"])
+ # test_commands = make_test_commands(settings, trees, binhost["uri"])
test_repo_location = settings.repositories["test_repo"].location
var_cache_edb = os.path.join(eprefix, "var", "cache", "edb")
@@ -494,29 +172,30 @@ move dev-util/git dev-vcs/git
# triggered by python -Wd will be visible.
stdout = subprocess.PIPE
- for idx, args in enumerate(test_commands):
- if hasattr(args, "__call__"):
- args()
- continue
+ if hasattr(command, "__call__"):
+ command()
+ return
- if isinstance(args[0], dict):
- local_env = env.copy()
- local_env.update(args[0])
- args = args[1:]
- else:
- local_env = env
-
- # with self.subTest(cmd=args, i=idx):
- proc = await asyncio.create_subprocess_exec(
- *args, env=local_env, stderr=None, stdout=stdout
- )
+ if isinstance(command[0], dict):
+ local_env = env.copy()
+ local_env.update(command[0])
+ command = command[1:]
+ else:
+ local_env = env
- if debug:
- await proc.wait()
- else:
- output, _err = await proc.communicate()
- await proc.wait()
- if proc.returncode != os.EX_OK:
- portage.writemsg(output)
+ # with self.subTest(cmd=command, i=idx):
+ proc = await asyncio.create_subprocess_exec(
+ *command, env=local_env, stderr=None, stdout=stdout
+ )
- assert os.EX_OK == proc.returncode, f"emerge failed with args {args}"
+ if debug:
+ await proc.wait()
+ else:
+ output, _err = await proc.communicate()
+ await proc.wait()
+ if proc.returncode != os.EX_OK:
+ portage.writemsg(output)
+
+ real_command = command[0]
+ args = command[1:]
+ assert os.EX_OK == proc.returncode, f"'{real_command}' failed with args '{args}'"
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/emerge/
@ 2023-10-30 3:14 Sam James
0 siblings, 0 replies; 38+ messages in thread
From: Sam James @ 2023-10-30 3:14 UTC (permalink / raw
To: gentoo-commits
commit: 6dd1d051312c74785316975eb3861068ae7c241d
Author: David Palao <david.palao <AT> gmail <DOT> com>
AuthorDate: Fri Jul 7 14:30:51 2023 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Oct 30 03:14:22 2023 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=6dd1d051
tests/emerge: conftest.py: Remove spurious definition of commands
Remove spurious definition of commands. The ``simple_command`` fixture
was repeating the definition of some commands. That's not needed.
Signed-off-by: David Palao <david.palao <AT> gmail.com>
Signed-off-by: Sam James <sam <AT> gentoo.org>
lib/portage/tests/emerge/conftest.py | 61 +++++++++---------------------------
1 file changed, 15 insertions(+), 46 deletions(-)
diff --git a/lib/portage/tests/emerge/conftest.py b/lib/portage/tests/emerge/conftest.py
index a637aa885b..cfaf18c5f9 100644
--- a/lib/portage/tests/emerge/conftest.py
+++ b/lib/portage/tests/emerge/conftest.py
@@ -199,13 +199,13 @@ _INSTALLED_EBUILDS = {
_TEST_COMMAND_NAMES_FETCHCOMMAND = [
"mv {pkgdir} {binhost_dir}",
"emerge -eG dev-libs/A",
- "rm -R {pkgdir} (1)",
+ "rm -R {pkgdir}",
"mv {binhost_dir} {pkgdir}",
"rm {binrepos_conf_file}",
- "mv {pkgdir} {binhost_dir} (2)",
+ "mv {pkgdir} {binhost_dir}",
"PORTAGE_BINHOST={binhost_uri} emerge -feG dev-libs/A",
- "rm -R {pkgdir} (2)",
- "mv {binhost_dir} {pkgdir} (2)",
+ "rm -R {pkgdir}",
+ "mv {binhost_dir} {pkgdir}",
]
_TEST_COMMAND_NAMES = [
@@ -224,17 +224,17 @@ _TEST_COMMAND_NAMES = [
"rm -rf {cachedir}",
"rm -rf {cachedir_pregen}",
"emerge --regen",
- "rm -rf {cachedir} (2)",
+ "rm -rf {cachedir}",
+ "FEATURES=metadata-transfer emerge --regen",
+ "rm -rf {cachedir}",
"FEATURES=metadata-transfer emerge --regen",
- "rm -rf {cachedir} (3)",
- "FEATURES=metadata-transfer emerge --regen (2)",
- "rm -rf {cachedir} (4)",
+ "rm -rf {cachedir}",
"egencache --update",
"FEATURES=metadata-transfer emerge --metadata",
- "rm -rf {cachedir} (5)",
- "FEATURES=metadata-transfer emerge --metadata (2)",
+ "rm -rf {cachedir}",
+ "FEATURES=metadata-transfer emerge --metadata",
"emerge --metadata",
- "rm -rf {cachedir} (6)",
+ "rm -rf {cachedir}",
"emerge --oneshot virtual/foo",
"foo pkg missing",
"FEATURES=unmerge-backup emerge --unmerge virtual/foo",
@@ -291,8 +291,8 @@ _TEST_COMMAND_NAMES = [
"EPREFIX={cross_prefix} emerge -Cq dev-libs/B",
"EPREFIX={cross_prefix} emerge -Cq dev-libs/A",
"EPREFIX={cross_prefix} emerge dev-libs/A",
- "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/A (2)",
- "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/B (2)",
+ "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/A",
+ "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/B",
"ROOT={cross_root} emerge dev-libs/B",
"portageq has_version {cross_eroot} dev-libs/B",
] + _TEST_COMMAND_NAMES_FETCHCOMMAND
@@ -518,27 +518,16 @@ def simple_command(playground, binhost, request):
test_commands["rm -rf {cachedir}"] = rm_cmd + ("-rf", cachedir)
test_commands["rm -rf {cachedir_pregen}"] = rm_cmd + ("-rf", cachedir_pregen)
test_commands["emerge --regen"] = emerge_cmd + ("--regen",)
- test_commands["rm -rf {cachedir} (2)"] = rm_cmd + ("-rf", cachedir)
test_commands["FEATURES=metadata-transfer emerge --regen"] = (
({"FEATURES": "metadata-transfer"},) + emerge_cmd + ("--regen",)
)
- test_commands["rm -rf {cachedir} (3)"] = rm_cmd + ("-rf", cachedir)
- test_commands["FEATURES=metadata-transfer emerge --regen (2)"] = (
- ({"FEATURES": "metadata-transfer"},) + emerge_cmd + ("--regen",)
- )
- test_commands["rm -rf {cachedir} (4)"] = rm_cmd + ("-rf", cachedir)
test_commands["egencache --update"] = (
egencache_cmd + ("--update",) + tuple(egencache_extra_args)
)
test_commands["FEATURES=metadata-transfer emerge --metadata"] = (
({"FEATURES": "metadata-transfer"},) + emerge_cmd + ("--metadata",)
)
- test_commands["rm -rf {cachedir} (5)"] = rm_cmd + ("-rf", cachedir)
- test_commands["FEATURES=metadata-transfer emerge --metadata (2)"] = (
- ({"FEATURES": "metadata-transfer"},) + emerge_cmd + ("--metadata",)
- )
test_commands["emerge --metadata"] = emerge_cmd + ("--metadata",)
- test_commands["rm -rf {cachedir} (6)"] = rm_cmd + ("-rf", cachedir)
test_commands["emerge --oneshot virtual/foo"] = emerge_cmd + (
"--oneshot",
@@ -779,20 +768,7 @@ def simple_command(playground, binhost, request):
test_commands["EPREFIX={cross_prefix} emerge dev-libs/A"] = (
({"EPREFIX": cross_prefix},) + emerge_cmd + ("dev-libs/A",)
)
- test_commands[
- "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/A (2)"
- ] = (
- ({"EPREFIX": cross_prefix},)
- + portageq_cmd
- + ("has_version", cross_prefix, "dev-libs/A")
- )
- test_commands[
- "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/B (2)"
- ] = (
- ({"EPREFIX": cross_prefix},)
- + portageq_cmd
- + ("has_version", cross_prefix, "dev-libs/B")
- )
+
# Test ROOT support
test_commands["ROOT={cross_root} emerge dev-libs/B"] = (
({"ROOT": cross_root},) + emerge_cmd + ("dev-libs/B",)
@@ -824,23 +800,16 @@ def simple_command(playground, binhost, request):
"--getbinpkgonly",
"dev-libs/A",
)
- test_commands["rm -R {pkgdir} (1)"] = lambda: shutil.rmtree(pkgdir)
+ test_commands["rm -R {pkgdir}"] = lambda: shutil.rmtree(pkgdir)
test_commands["mv {binhost_dir} {pkgdir}"] = lambda: os.rename(
binhost_dir, pkgdir
)
# Remove binrepos.conf and test PORTAGE_BINHOST.
test_commands["rm {binrepos_conf_file}"] = lambda: os.unlink(binrepos_conf_file)
- test_commands["mv {pkgdir} {binhost_dir} (2)"] = lambda: os.rename(
- pkgdir, binhost_dir
- )
test_commands["PORTAGE_BINHOST={binhost_uri} emerge -feG dev-libs/A"] = (
({"PORTAGE_BINHOST": binhost_uri},)
+ emerge_cmd
+ ("-fe", "--getbinpkgonly", "dev-libs/A")
)
- test_commands["rm -R {pkgdir} (2)"] = lambda: shutil.rmtree(pkgdir)
- test_commands["mv {binhost_dir} {pkgdir} (2)"] = lambda: os.rename(
- binhost_dir, pkgdir
- )
return test_commands[request.param]
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/emerge/
@ 2023-10-30 3:14 Sam James
0 siblings, 0 replies; 38+ messages in thread
From: Sam James @ 2023-10-30 3:14 UTC (permalink / raw
To: gentoo-commits
commit: f8a5d65523e37043dac60b4572ad35dc6a96a0b6
Author: David Palao <david.palao <AT> gmail <DOT> com>
AuthorDate: Fri Oct 13 15:02:27 2023 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Oct 30 03:14:24 2023 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=f8a5d655
tests/emerge/conftest.py: Split the test commands in monoliths.
Split the test commands in monoliths. Each monolith should be an
indivisible sequence of commands that test some complex
functionality of portage.
Run the tests with::
pytest -m ft
if pytest-xdist is installed, it can be used to speed up::
pytest -m ft -n 8
Signed-off-by: David Palao <david.palao <AT> gmail.com>
Signed-off-by: Sam James <sam <AT> gentoo.org>
lib/portage/tests/emerge/conftest.py | 723 +++++++++++++++++++----------------
1 file changed, 384 insertions(+), 339 deletions(-)
diff --git a/lib/portage/tests/emerge/conftest.py b/lib/portage/tests/emerge/conftest.py
index 27cca5e077..693ae0e6a6 100644
--- a/lib/portage/tests/emerge/conftest.py
+++ b/lib/portage/tests/emerge/conftest.py
@@ -178,22 +178,12 @@ _INSTALLED_EBUILDS = {
},
}
-_BASELINE_COMMAND_FETCHCOMMAND_SEQUENCE = [
- # "mv {pkgdir} {binhost_dir}",
- "emerge -eG dev-libs/A",
- # "rm -R {pkgdir}",
- # "mv {binhost_dir} {pkgdir}",
- # "rm {binrepos_conf_file}",
- # "mv {pkgdir} {binhost_dir}",
- "PORTAGE_BINHOST={binhost_uri} emerge -feG dev-libs/A",
- # "rm -R {pkgdir}",
- # "mv {binhost_dir} {pkgdir}",
-]
_BASELINE_COMMAND_SEQUENCE = [
"emerge -1 dev-libs/A -v dev-libs/B",
- "emerge --root --quickpkg-direct-root",
- "emerge --quickpkg-direct-root",
+ "emerge with quickpkg direct",
+ # "emerge --root --quickpkg-direct-root",
+ # "emerge --quickpkg-direct-root",
"env-update",
"portageq envvar",
"etc-update",
@@ -222,65 +212,68 @@ _BASELINE_COMMAND_SEQUENCE = [
# # "foo pkg missing",
# "FEATURES=unmerge-backup emerge --unmerge virtual/foo",
# # "foo pkg exists",
+ # "emerge --pretend dev-libs/A",
+ # Sequence:
"emerge --regen/--metadata",
#
- "emerge --pretend dev-libs/A",
- "ebuild dev-libs/A-1 manifest clean package merge",
- "emerge --pretend --tree --complete-graph dev-libs/A",
- "emerge -p dev-libs/B",
- "emerge -p --newrepo dev-libs/B",
- "emerge -B dev-libs/B",
- "emerge -1k dev-libs/B",
- "ebuild dev-libs/A-1 unpack",
- "emerge -1 dev-libs/A",
- "emerge -n dev-libs/A",
- "emerge --config dev-libs/A",
- "emerge --info dev-libs/A dev-libs/B",
- "emerge -pcv dev-libs/B",
- "emerge -pc",
- "emerge -c",
- "quickpkg --include-config y dev-libs/A",
- # "no protected files",
- # "rm /etc/A-0",
- "emerge -K dev-libs/A",
- # "one protected file",
- "emaint --check all",
- "emaint --fix all",
- "fixpackages",
- "regenworld",
- "portageq match {eroot} dev-libs/A",
- "portageq best_visible {eroot} dev-libs/A",
- "portageq best_visible {eroot} binary dev-libs/A",
- "portageq contents {eroot} dev-libs/A-1",
- "portageq metadata {eroot} ebuild dev-libs/A-1 EAPI IUSE RDEPEND",
- "portageq metadata {eroot} binary dev-libs/A-1 EAPI USE RDEPEND",
- "portageq metadata {eroot} installed dev-libs/A-1 EAPI USE RDEPEND",
- "portageq owners {eroot} {eroot}usr",
- "emerge -p {eroot}usr",
- "emerge -pCq {eroot}usr",
- "emerge -Cq dev-libs/A",
- "emerge -Cq dev-libs/B",
- (
- "EMERGE_DEFAULT_OPTS=--autounmask=n "
- "emerge --autounmask --autounmask-continue dev-libs/C"
- ),
- "portageq match {eroot} dev-libs/D[flag]",
- "EPREFIX={cross_prefix} emerge dev-libs/C",
- "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/C",
- "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/D",
- "ROOT={cross_root} emerge dev-libs/D",
- "portageq has_version {cross_eroot} dev-libs/D",
- "EPREFIX={cross_prefix} emerge -K dev-libs/A",
- "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/A",
- "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/B",
- "EPREFIX={cross_prefix} emerge -Cq dev-libs/B",
- "EPREFIX={cross_prefix} emerge -Cq dev-libs/A",
- "EPREFIX={cross_prefix} emerge dev-libs/A",
- "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/A",
- "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/B",
- "ROOT={cross_root} emerge dev-libs/B",
- "portageq has_version {cross_eroot} dev-libs/B",
-] + _BASELINE_COMMAND_FETCHCOMMAND_SEQUENCE
+ # "ebuild dev-libs/A-1 manifest clean package merge",
+ # "emerge --pretend --tree --complete-graph dev-libs/A",
+ # "emerge -p dev-libs/B",
+ # "emerge -p --newrepo dev-libs/B",
+ # "emerge -B dev-libs/B",
+ # "emerge -1k dev-libs/B",
+ # "ebuild dev-libs/A-1 unpack",
+ # "emerge -1 dev-libs/A",
+ # "emerge -n dev-libs/A",
+ # "emerge --config dev-libs/A",
+ # "emerge --info dev-libs/A dev-libs/B",
+ # "emerge -pcv dev-libs/B",
+ # "emerge -pc",
+ # "emerge -c",
+ # "quickpkg --include-config y dev-libs/A",
+ # # "no protected files",
+ # # "rm /etc/A-0",
+ # "emerge -K dev-libs/A",
+ # # "one protected file",
+ # "emaint --check all",
+ # "emaint --fix all",
+ # "fixpackages",
+ # "regenworld",
+ # "portageq match {eroot} dev-libs/A",
+ # "portageq best_visible {eroot} dev-libs/A",
+ # "portageq best_visible {eroot} binary dev-libs/A",
+ # "portageq contents {eroot} dev-libs/A-1",
+ # "portageq metadata {eroot} ebuild dev-libs/A-1 EAPI IUSE RDEPEND",
+ # "portageq metadata {eroot} binary dev-libs/A-1 EAPI USE RDEPEND",
+ # "portageq metadata {eroot} installed dev-libs/A-1 EAPI USE RDEPEND",
+ # "portageq owners {eroot} {eroot}usr",
+ # "emerge -p {eroot}usr",
+ # "emerge -pCq {eroot}usr",
+ # "emerge -Cq dev-libs/A",
+ # "emerge -Cq dev-libs/B",
+ "misc package operations",
+ # (
+ # "EMERGE_DEFAULT_OPTS=--autounmask=n "
+ # "emerge --autounmask --autounmask-continue dev-libs/C"
+ # ),
+ # "portageq match {eroot} dev-libs/D[flag]",
+ # "EPREFIX={cross_prefix} emerge dev-libs/C",
+ # "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/C",
+ # "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/D",
+ # "ROOT={cross_root} emerge dev-libs/D",
+ # "portageq has_version {cross_eroot} dev-libs/D",
+ # "EPREFIX={cross_prefix} emerge -K dev-libs/A",
+ # "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/A",
+ # "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/B",
+ # "EPREFIX={cross_prefix} emerge -Cq dev-libs/B",
+ # "EPREFIX={cross_prefix} emerge -Cq dev-libs/A",
+ # "EPREFIX={cross_prefix} emerge dev-libs/A",
+ # "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/A",
+ # "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/B",
+ # "ROOT={cross_root} emerge dev-libs/B",
+ # "portageq has_version {cross_eroot} dev-libs/B",
+ "binhost emerge",
+]
PORTAGE_PYTHON = portage._python_interpreter
NOOP = lambda: ...
@@ -536,7 +529,7 @@ def _generate_all_baseline_commands(playground, binhost):
But, don't use this fixture directly, instead, use the
``baseline_command`` fixture. That improves performance a bit due to
- pytest caching.
+ pytest caching (?).
.. note::
@@ -579,6 +572,7 @@ def _generate_all_baseline_commands(playground, binhost):
test_commands = {}
+ ###
if hasattr(argparse.ArgumentParser, "parse_intermixed_args"):
parse_intermixed_command = Emerge(
"--oneshot",
@@ -589,25 +583,36 @@ def _generate_all_baseline_commands(playground, binhost):
else:
parse_intermixed_command = Noop()
test_commands["emerge -1 dev-libs/A -v dev-libs/B"] = parse_intermixed_command
+ ###
- test_commands["emerge --root --quickpkg-direct-root"] = Emerge(
- "--usepkgonly",
- "--root",
- cross_root,
- "--quickpkg-direct=y",
- "--quickpkg-direct-root",
- "/",
- "dev-libs/A",
+ quickpkg_direct_seq = [
+ # test_commands["emerge --root --quickpkg-direct-root"] =
+ Emerge(
+ "--usepkgonly",
+ "--root",
+ cross_root,
+ "--quickpkg-direct=y",
+ "--quickpkg-direct-root",
+ "/",
+ "dev-libs/A",
+ ),
+ # v needs ^
+ # test_commands["emerge --quickpkg-direct-root"] =
+ Emerge(
+ "--usepkgonly",
+ "--quickpkg-direct=y",
+ "--quickpkg-direct-root",
+ cross_root,
+ "dev-libs/A",
+ ),
+ ]
+ test_commands["emerge with quickpkg direct"] = PortageCommandSequence(
+ *quickpkg_direct_seq
)
- test_commands["emerge --quickpkg-direct-root"] = Emerge(
- "--usepkgonly",
- "--quickpkg-direct=y",
- "--quickpkg-direct-root",
- cross_root,
- "dev-libs/A",
- )
+ ###
test_commands["env-update"] = EnvUpdate()
+ ###
test_commands["portageq envvar"] = Portageq(
"envvar",
"-v",
@@ -617,14 +622,22 @@ def _generate_all_baseline_commands(playground, binhost):
"PORTAGE_TMPDIR",
"USERLAND",
)
+ ###
test_commands["etc-update"] = EtcUpdate()
+ ###
test_commands["dispatch-conf"] = DispatchConf()
+ ###
test_commands["emerge --version"] = Emerge("--version")
+ ###
test_commands["emerge --info"] = Emerge("--info")
+ ###
test_commands["emerge --info --verbose"] = Emerge("--info", "--verbose")
+ ###
test_commands["emerge --list-sets"] = Emerge("--list-sets")
+ ###
test_commands["emerge --check-news"] = Emerge("--check-news")
+ ###
def _rm_cachedir():
shutil.rmtree(cachedir)
@@ -662,260 +675,283 @@ def _generate_all_baseline_commands(playground, binhost):
env_mod={"FEATURES": "unmerge-backup"},
preparation=lambda: _check_foo_file(pkgdir, foo_filename, must_exist=False),
),
+ Emerge(
+ "--pretend",
+ "dev-libs/A",
+ preparation=lambda: _check_foo_file(pkgdir, foo_filename, must_exist=True),
+ ),
]
test_commands["emerge --regen/--metadata"] = PortageCommandSequence(*regen_seq)
- # Assuming that the sequence ends here!
-
- # test_commands["foo pkg exists"] = lambda: _check_foo_file(
- # pkgdir, foo_filename, must_exist=True
- # )
-
- test_commands["emerge --pretend dev-libs/A"] = Emerge(
- "--pretend",
- "dev-libs/A",
- preparation=lambda: _check_foo_file(pkgdir, foo_filename, must_exist=True),
- )
- test_commands["ebuild dev-libs/A-1 manifest clean package merge"] = Ebuild(
- test_ebuild,
- "manifest",
- "clean",
- "package",
- "merge",
- )
- test_commands["emerge --pretend --tree --complete-graph dev-libs/A"] = Emerge(
- "--pretend",
- "--tree",
- "--complete-graph",
- "dev-libs/A",
- )
- test_commands["emerge -p dev-libs/B"] = Emerge("-p", "dev-libs/B")
- test_commands["emerge -p --newrepo dev-libs/B"] = Emerge(
- "-p",
- "--newrepo",
- "dev-libs/B",
- )
- test_commands["emerge -B dev-libs/B"] = Emerge("-B", "dev-libs/B")
- test_commands["emerge -1k dev-libs/B"] = Emerge(
- "--oneshot",
- "--usepkg",
- "dev-libs/B",
- )
- # trigger clean prior to pkg_pretend as in bug #390711
- test_commands["ebuild dev-libs/A-1 unpack"] = Ebuild(test_ebuild, "unpack")
- test_commands["emerge -1 dev-libs/A"] = Emerge("--oneshot", "dev-libs/A")
- test_commands["emerge -n dev-libs/A"] = Emerge("--noreplace", "dev-libs/A")
- test_commands["emerge --config dev-libs/A"] = Emerge(
- "--config",
- "dev-libs/A",
- )
- test_commands["emerge --info dev-libs/A dev-libs/B"] = Emerge(
- "--info",
- "dev-libs/A",
- "dev-libs/B",
- )
- test_commands["emerge -pcv dev-libs/B"] = Emerge(
- "--pretend",
- "--depclean",
- "--verbose",
- "dev-libs/B",
- )
- test_commands["emerge -pc"] = Emerge("--pretend", "--depclean")
- test_commands["emerge -c"] = Emerge(
- "--depclean",
- )
-
- # Test bug #523684, where a file renamed or removed by the
- # admin forces replacement files to be merged with config
- # protection.
- test_commands["quickpkg --include-config y dev-libs/A"] = Quickpkg(
- "--include-config",
- "y",
- "dev-libs/A",
- post_command=lambda: _check_number_of_protected_files(
- 0, eroot, settings["CONFIG_PROTECT"]
+ # test_commands["ebuild dev-libs/A-1 manifest clean package merge"] =
+ abcd_seq = [
+ Ebuild(
+ test_ebuild,
+ "manifest",
+ "clean",
+ "package",
+ "merge",
),
- )
-
- # Another "it is not a test command" case; actually setup:
- # test_commands["rm /etc/A-0"] = lambda: os.unlink(
- # os.path.join(eprefix, "etc", "A-0")
- # )
- test_commands["emerge -K dev-libs/A"] = Emerge(
- "--usepkgonly",
- "dev-libs/A",
- preparation=lambda: os.unlink(os.path.join(eprefix, "etc", "A-0")),
- post_command=lambda: _check_number_of_protected_files(
- 1, eroot, settings["CONFIG_PROTECT"]
+ # test_commands["emerge --pretend --tree --complete-graph dev-libs/A"] =
+ Emerge(
+ "--pretend",
+ "--tree",
+ "--complete-graph",
+ "dev-libs/A",
),
- )
-
- test_commands["emaint --check all"] = Emaint("--check", "all")
- test_commands["emaint --fix all"] = Emaint("--fix", "all")
- test_commands["fixpackages"] = Fixpackages()
- test_commands["regenworld"] = Regenworld()
- test_commands["portageq match {eroot} dev-libs/A"] = Portageq(
- "match",
- eroot,
- "dev-libs/A",
- )
- test_commands["portageq best_visible {eroot} dev-libs/A"] = Portageq(
- "best_visible",
- eroot,
- "dev-libs/A",
- )
- test_commands["portageq best_visible {eroot} binary dev-libs/A"] = Portageq(
- "best_visible",
- eroot,
- "binary",
- "dev-libs/A",
- )
- test_commands["portageq contents {eroot} dev-libs/A-1"] = Portageq(
- "contents",
- eroot,
- "dev-libs/A-1",
- )
- test_commands[
- "portageq metadata {eroot} ebuild dev-libs/A-1 EAPI IUSE RDEPEND"
- ] = Portageq(
- "metadata",
- eroot,
- "ebuild",
- "dev-libs/A-1",
- "EAPI",
- "IUSE",
- "RDEPEND",
- )
- test_commands[
- "portageq metadata {eroot} binary dev-libs/A-1 EAPI USE RDEPEND"
- ] = Portageq(
- "metadata",
- eroot,
- "binary",
- "dev-libs/A-1",
- "EAPI",
- "USE",
- "RDEPEND",
- )
- test_commands[
- "portageq metadata {eroot} installed dev-libs/A-1 EAPI USE RDEPEND"
- ] = Portageq(
- "metadata",
- eroot,
- "installed",
- "dev-libs/A-1",
- "EAPI",
- "USE",
- "RDEPEND",
- )
- test_commands["portageq owners {eroot} {eroot}usr"] = Portageq(
- "owners",
- eroot,
- eroot + "usr",
- )
- test_commands["emerge -p {eroot}usr"] = Emerge("-p", eroot + "usr")
- test_commands["emerge -pCq {eroot}usr"] = Emerge(
- "-p",
- "--unmerge",
- "-q",
- eroot + "usr",
- )
- test_commands["emerge -Cq dev-libs/A"] = Emerge(
- "--unmerge",
- "--quiet",
- "dev-libs/A",
- )
- test_commands["emerge -Cq dev-libs/B"] = Emerge(
- "-C",
- "--quiet",
- "dev-libs/B",
- )
-
- # autounmask:
- # If EMERGE_DEFAULT_OPTS contains --autounmask=n, then --autounmask
- # must be specified with --autounmask-continue.
- test_commands[
- "EMERGE_DEFAULT_OPTS=--autounmask=n "
- "emerge --autounmask --autounmask-continue dev-libs/C"
- ] = Emerge(
- "--autounmask",
- "--autounmask-continue",
- "dev-libs/C",
- env_mod={"EMERGE_DEFAULT_OPTS": "--autounmask=n"},
- )
-
- # Verify that the above --autounmask-continue command caused
- # USE=flag to be applied correctly to dev-libs/D.
- test_commands["portageq match {eroot} dev-libs/D[flag]"] = Portageq(
- "match",
- eroot,
- "dev-libs/D[flag]",
- )
- # Test cross-prefix usage, including chpathtool for binpkgs.
- # EAPI 7
- test_commands["EPREFIX={cross_prefix} emerge dev-libs/C"] = Emerge(
- "dev-libs/C", env_mod={"EPREFIX": cross_prefix}
- )
-
- test_commands[
- "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/C"
- ] = Portageq(
- "has_version", cross_prefix, "dev-libs/C", env_mod={"EPREFIX": cross_prefix}
- )
-
- test_commands[
- "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/D"
- ] = Portageq(
- "has_version", cross_prefix, "dev-libs/D", env_mod={"EPREFIX": cross_prefix}
- )
-
- test_commands["ROOT={cross_root} emerge dev-libs/D"] = Emerge(
- "dev-libs/D", env_mod={"ROOT": cross_root}
- )
-
- test_commands["portageq has_version {cross_eroot} dev-libs/D"] = Portageq(
- "has_version",
- cross_eroot,
- "dev-libs/D",
- )
- # EAPI 5
- test_commands["EPREFIX={cross_prefix} emerge -K dev-libs/A"] = Emerge(
- "--usepkgonly", "dev-libs/A", env_mod={"EPREFIX": cross_prefix}
- )
-
- test_commands[
- "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/A"
- ] = Portageq(
- "has_version", cross_prefix, "dev-libs/A", env_mod={"EPREFIX": cross_prefix}
- )
-
- test_commands[
- "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/B"
- ] = Portageq(
- "has_version", cross_prefix, "dev-libs/B", env_mod={"EPREFIX": cross_prefix}
- )
-
- test_commands["EPREFIX={cross_prefix} emerge -Cq dev-libs/B"] = Emerge(
- "-C", "--quiet", "dev-libs/B", env_mod={"EPREFIX": cross_prefix}
- )
-
- test_commands["EPREFIX={cross_prefix} emerge -Cq dev-libs/A"] = Emerge(
- "-C", "--quiet", "dev-libs/A", env_mod={"EPREFIX": cross_prefix}
- )
-
- test_commands["EPREFIX={cross_prefix} emerge dev-libs/A"] = Emerge(
- "dev-libs/A", env_mod={"EPREFIX": cross_prefix}
- )
-
- # Test ROOT support
- test_commands["ROOT={cross_root} emerge dev-libs/B"] = Emerge(
- "dev-libs/B", env_mod={"ROOT": cross_root}
- )
-
- test_commands["portageq has_version {cross_eroot} dev-libs/B"] = Portageq(
- "has_version",
- cross_eroot,
- "dev-libs/B",
+ # test_commands["emerge -p dev-libs/B"] =
+ Emerge("-p", "dev-libs/B"),
+ # test_commands["emerge -p --newrepo dev-libs/B"] =
+ Emerge(
+ "-p",
+ "--newrepo",
+ "dev-libs/B",
+ ),
+ # test_commands["emerge -B dev-libs/B"] =
+ Emerge("-B", "dev-libs/B"),
+ # test_commands["emerge -1k dev-libs/B"] =
+ Emerge(
+ "--oneshot",
+ "--usepkg",
+ "dev-libs/B",
+ ),
+ # trigger clean prior to pkg_pretend as in bug #390711
+ # test_commands["ebuild dev-libs/A-1 unpack"] =
+ Ebuild(test_ebuild, "unpack"),
+ # test_commands["emerge -1 dev-libs/A"] =
+ Emerge("--oneshot", "dev-libs/A"),
+ # test_commands["emerge -n dev-libs/A"] =
+ Emerge("--noreplace", "dev-libs/A"),
+ # test_commands["emerge --config dev-libs/A"] =
+ Emerge(
+ "--config",
+ "dev-libs/A",
+ ),
+ # test_commands["emerge --info dev-libs/A dev-libs/B"] =
+ Emerge(
+ "--info",
+ "dev-libs/A",
+ "dev-libs/B",
+ ),
+ # test_commands["emerge -pcv dev-libs/B"] =
+ Emerge(
+ "--pretend",
+ "--depclean",
+ "--verbose",
+ "dev-libs/B",
+ ),
+ # test_commands["emerge -pc"] =
+ Emerge("--pretend", "--depclean"),
+ # test_commands["emerge -c"] =
+ Emerge(
+ "--depclean",
+ ),
+ # Test bug #523684, where a file renamed or removed by the
+ # admin forces replacement files to be merged with config
+ # protection.
+ # test_commands["quickpkg --include-config y dev-libs/A"] =
+ Quickpkg(
+ "--include-config",
+ "y",
+ "dev-libs/A",
+ post_command=lambda: _check_number_of_protected_files(
+ 0, eroot, settings["CONFIG_PROTECT"]
+ ),
+ ),
+ # Another "it is not a test command" case; actually setup:
+ # test_commands["rm /etc/A-0"] = lambda: os.unlink(
+ # os.path.join(eprefix, "etc", "A-0")
+ # )
+ # emerge_noreplace_A =
+ Emerge("--noreplace", "dev-libs/A"),
+ # test_commands["emerge -K dev-libs/A"] = PortageCommandSequence(
+ # emerge_noreplace_A,
+ Emerge(
+ "--usepkgonly",
+ "dev-libs/A",
+ preparation=lambda: os.unlink(os.path.join(eprefix, "etc", "A-0")),
+ post_command=lambda: _check_number_of_protected_files(
+ 1, eroot, settings["CONFIG_PROTECT"]
+ ),
+ ),
+ # test_commands["emaint --check all"] =
+ Emaint("--check", "all"),
+ # test_commands["emaint --fix all"] =
+ Emaint("--fix", "all"),
+ # test_commands["fixpackages"] =
+ Fixpackages(),
+ # test_commands["regenworld"] =
+ Regenworld(),
+ # test_commands["portageq match {eroot} dev-libs/A"] =
+ Portageq(
+ "match",
+ eroot,
+ "dev-libs/A",
+ ),
+ # test_commands["portageq best_visible {eroot} dev-libs/A"] =
+ Portageq(
+ "best_visible",
+ eroot,
+ "dev-libs/A",
+ ),
+ # test_commands["portageq best_visible {eroot} binary dev-libs/A"] =
+ Portageq(
+ "best_visible",
+ eroot,
+ "binary",
+ "dev-libs/A",
+ ),
+ # test_commands["portageq contents {eroot} dev-libs/A-1"] =
+ Portageq(
+ "contents",
+ eroot,
+ "dev-libs/A-1",
+ ),
+ # test_commands[
+ # "portageq metadata {eroot} ebuild dev-libs/A-1 EAPI IUSE RDEPEND"
+ # ] =
+ Portageq(
+ "metadata",
+ eroot,
+ "ebuild",
+ "dev-libs/A-1",
+ "EAPI",
+ "IUSE",
+ "RDEPEND",
+ ),
+ # test_commands[
+ # "portageq metadata {eroot} binary dev-libs/A-1 EAPI USE RDEPEND"
+ # ] =
+ Portageq(
+ "metadata",
+ eroot,
+ "binary",
+ "dev-libs/A-1",
+ "EAPI",
+ "USE",
+ "RDEPEND",
+ ),
+ # test_commands[
+ # "portageq metadata {eroot} installed dev-libs/A-1 EAPI USE RDEPEND"
+ # ] =
+ Portageq(
+ "metadata",
+ eroot,
+ "installed",
+ "dev-libs/A-1",
+ "EAPI",
+ "USE",
+ "RDEPEND",
+ ),
+ # test_commands["portageq owners {eroot} {eroot}usr"] =
+ Portageq(
+ "owners",
+ eroot,
+ eroot + "usr",
+ ),
+ # test_commands["emerge -p {eroot}usr"] =
+ Emerge("-p", eroot + "usr"),
+ # test_commands["emerge -pCq {eroot}usr"] =
+ Emerge(
+ "-p",
+ "--unmerge",
+ "-q",
+ eroot + "usr",
+ ),
+ # test_commands["emerge -Cq dev-libs/A"] =
+ Emerge(
+ "--unmerge",
+ "--quiet",
+ "dev-libs/A",
+ ),
+ # test_commands["emerge -Cq dev-libs/B"] =
+ Emerge(
+ "-C",
+ "--quiet",
+ "dev-libs/B",
+ ),
+ # autounmask:
+ # If EMERGE_DEFAULT_OPTS contains --autounmask=n, then --autounmask
+ # must be specified with --autounmask-continue.
+ # test_commands[
+ # "EMERGE_DEFAULT_OPTS=--autounmask=n "
+ # "emerge --autounmask --autounmask-continue dev-libs/C"
+ # ] =
+ Emerge(
+ "--autounmask",
+ "--autounmask-continue",
+ "dev-libs/C",
+ env_mod={"EMERGE_DEFAULT_OPTS": "--autounmask=n"},
+ ),
+ # Verify that the above --autounmask-continue command caused
+ # USE=flag to be applied correctly to dev-libs/D.
+ # test_commands["portageq match {eroot} dev-libs/D[flag]"] =
+ Portageq(
+ "match",
+ eroot,
+ "dev-libs/D[flag]",
+ ),
+ ]
+ test_commands["misc package operations"] = PortageCommandSequence(*abcd_seq)
+
+ cross_prefix_seq = [
+ # Test cross-prefix usage, including chpathtool for binpkgs.
+ # EAPI 7
+ # test_commands["EPREFIX={cross_prefix} emerge dev-libs/C"] =
+ Emerge("dev-libs/C", env_mod={"EPREFIX": cross_prefix}),
+ # test_commands[
+ # "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/C"
+ # ] =
+ Portageq(
+ "has_version", cross_prefix, "dev-libs/C", env_mod={"EPREFIX": cross_prefix}
+ ),
+ # test_commands[
+ # "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/D"
+ # ] =
+ Portageq(
+ "has_version", cross_prefix, "dev-libs/D", env_mod={"EPREFIX": cross_prefix}
+ ),
+ # test_commands["ROOT={cross_root} emerge dev-libs/D"] =
+ Emerge("dev-libs/D", env_mod={"ROOT": cross_root}),
+ # test_commands["portageq has_version {cross_eroot} dev-libs/D"] =
+ Portageq(
+ "has_version",
+ cross_eroot,
+ "dev-libs/D",
+ ),
+ # EAPI 5
+ # test_commands["EPREFIX={cross_prefix} emerge -K dev-libs/A"] =
+ Emerge("--usepkgonly", "dev-libs/A", env_mod={"EPREFIX": cross_prefix}),
+ # test_commands[
+ # "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/A"
+ # ] =
+ Portageq(
+ "has_version", cross_prefix, "dev-libs/A", env_mod={"EPREFIX": cross_prefix}
+ ),
+ # test_commands[
+ # "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/B"
+ # ] =
+ Portageq(
+ "has_version", cross_prefix, "dev-libs/B", env_mod={"EPREFIX": cross_prefix}
+ ),
+ # test_commands["EPREFIX={cross_prefix} emerge -Cq dev-libs/B"] =
+ Emerge("-C", "--quiet", "dev-libs/B", env_mod={"EPREFIX": cross_prefix}),
+ # test_commands["EPREFIX={cross_prefix} emerge -Cq dev-libs/A"] =
+ Emerge("-C", "--quiet", "dev-libs/A", env_mod={"EPREFIX": cross_prefix}),
+ # test_commands["EPREFIX={cross_prefix} emerge dev-libs/A"] =
+ Emerge("dev-libs/A", env_mod={"EPREFIX": cross_prefix}),
+ # Test ROOT support
+ # test_commands["ROOT={cross_root} emerge dev-libs/B"] =
+ Emerge("dev-libs/B", env_mod={"ROOT": cross_root}),
+ # test_commands["portageq has_version {cross_eroot} dev-libs/B"] =
+ Portageq(
+ "has_version",
+ cross_eroot,
+ "dev-libs/B",
+ ),
+ ]
+ test_commands["misc operations with eprefix"] = PortageCommandSequence(
+ *cross_prefix_seq
)
# Test binhost support if FETCHCOMMAND is available.
@@ -927,14 +963,18 @@ def _generate_all_baseline_commands(playground, binhost):
f.write(f"sync-uri = {binhost_uri}\n")
fetchcommand = portage.util.shlex_split(settings["FETCHCOMMAND"])
fetch_bin = portage.process.find_binary(fetchcommand[0])
+
if fetch_bin is None:
- for command_name in _BASELINE_COMMAND_FETCHCOMMAND_SEQUENCE:
- test_commands[command_name] = Noop()
+ test_commands["binhost emerge"] = Noop()
+ # for command_name in _BASELINE_COMMAND_FETCHCOMMAND_SEQUENCE:
+ # test_commands[command_name] = Noop()
else:
# test_commands["mv {pkgdir} {binhost_dir}"] = lambda: os.rename(
# pkgdir, binhost_dir
# )
- test_commands["emerge -eG dev-libs/A"] = Emerge(
+ # test_commands["emerge -eG dev-libs/A"] =
+ make_package = Emerge("--buildpkg", "dev-libs/A")
+ getbinpkgonly = Emerge(
"-e",
"--getbinpkgonly",
"dev-libs/A",
@@ -952,7 +992,8 @@ def _generate_all_baseline_commands(playground, binhost):
os.rename(binhost_dir, pkgdir)
os.unlink(binrepos_conf_file)
- test_commands["PORTAGE_BINHOST={binhost_uri} emerge -feG dev-libs/A"] = Emerge(
+ # test_commands["PORTAGE_BINHOST={binhost_uri} emerge -feG dev-libs/A"] =
+ getbinpkgonly_fetchonly = Emerge(
"-fe",
"--getbinpkgonly",
"dev-libs/A",
@@ -960,6 +1001,10 @@ def _generate_all_baseline_commands(playground, binhost):
preparation=_replace_pkgdir_and_rm_binrepos_conf_file,
)
+ fetch_sequence = PortageCommandSequence(
+ make_package, getbinpkgonly, getbinpkgonly_fetchonly
+ )
+ test_commands["binhost emerge"] = fetch_sequence
yield test_commands
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/emerge/
@ 2023-10-30 3:14 Sam James
0 siblings, 0 replies; 38+ messages in thread
From: Sam James @ 2023-10-30 3:14 UTC (permalink / raw
To: gentoo-commits
commit: 10e6a558c4404d6a0fa8c92634747a1105db6997
Author: David Palao <david.palao <AT> gmail <DOT> com>
AuthorDate: Fri Oct 13 15:16:41 2023 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Oct 30 03:14:25 2023 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=10e6a558
tests/emerge: test_simple.py, conftest.py: Refactor
Refactor. Removed comments and changed simple -> baseline.
Signed-off-by: David Palao <david.palao <AT> gmail.com>
Signed-off-by: Sam James <sam <AT> gentoo.org>
lib/portage/tests/emerge/conftest.py | 178 +--------------------
.../emerge/{test_simple.py => test_baseline.py} | 15 +-
2 files changed, 11 insertions(+), 182 deletions(-)
diff --git a/lib/portage/tests/emerge/conftest.py b/lib/portage/tests/emerge/conftest.py
index 693ae0e6a6..aaa603f731 100644
--- a/lib/portage/tests/emerge/conftest.py
+++ b/lib/portage/tests/emerge/conftest.py
@@ -182,8 +182,6 @@ _INSTALLED_EBUILDS = {
_BASELINE_COMMAND_SEQUENCE = [
"emerge -1 dev-libs/A -v dev-libs/B",
"emerge with quickpkg direct",
- # "emerge --root --quickpkg-direct-root",
- # "emerge --quickpkg-direct-root",
"env-update",
"portageq envvar",
"etc-update",
@@ -193,85 +191,8 @@ _BASELINE_COMMAND_SEQUENCE = [
"emerge --info --verbose",
"emerge --list-sets",
"emerge --check-news",
- #
- # # "rm -rf {cachedir}",
- # # "rm -rf {cachedir_pregen}",
- # "emerge --regen",
- # # "rm -rf {cachedir}",
- # "FEATURES=metadata-transfer emerge --regen",
- # # "rm -rf {cachedir}",
- # "FEATURES=metadata-transfer emerge --regen", # is this second test case needed?
- # # "rm -rf {cachedir}",
- # "egencache --update",
- # "FEATURES=metadata-transfer emerge --metadata",
- # # "rm -rf {cachedir}",
- # "FEATURES=metadata-transfer emerge --metadata (2)",
- # "emerge --metadata",
- # # "rm -rf {cachedir}",
- # "emerge --oneshot virtual/foo",
- # # "foo pkg missing",
- # "FEATURES=unmerge-backup emerge --unmerge virtual/foo",
- # # "foo pkg exists",
- # "emerge --pretend dev-libs/A",
- # Sequence:
"emerge --regen/--metadata",
- #
- # "ebuild dev-libs/A-1 manifest clean package merge",
- # "emerge --pretend --tree --complete-graph dev-libs/A",
- # "emerge -p dev-libs/B",
- # "emerge -p --newrepo dev-libs/B",
- # "emerge -B dev-libs/B",
- # "emerge -1k dev-libs/B",
- # "ebuild dev-libs/A-1 unpack",
- # "emerge -1 dev-libs/A",
- # "emerge -n dev-libs/A",
- # "emerge --config dev-libs/A",
- # "emerge --info dev-libs/A dev-libs/B",
- # "emerge -pcv dev-libs/B",
- # "emerge -pc",
- # "emerge -c",
- # "quickpkg --include-config y dev-libs/A",
- # # "no protected files",
- # # "rm /etc/A-0",
- # "emerge -K dev-libs/A",
- # # "one protected file",
- # "emaint --check all",
- # "emaint --fix all",
- # "fixpackages",
- # "regenworld",
- # "portageq match {eroot} dev-libs/A",
- # "portageq best_visible {eroot} dev-libs/A",
- # "portageq best_visible {eroot} binary dev-libs/A",
- # "portageq contents {eroot} dev-libs/A-1",
- # "portageq metadata {eroot} ebuild dev-libs/A-1 EAPI IUSE RDEPEND",
- # "portageq metadata {eroot} binary dev-libs/A-1 EAPI USE RDEPEND",
- # "portageq metadata {eroot} installed dev-libs/A-1 EAPI USE RDEPEND",
- # "portageq owners {eroot} {eroot}usr",
- # "emerge -p {eroot}usr",
- # "emerge -pCq {eroot}usr",
- # "emerge -Cq dev-libs/A",
- # "emerge -Cq dev-libs/B",
"misc package operations",
- # (
- # "EMERGE_DEFAULT_OPTS=--autounmask=n "
- # "emerge --autounmask --autounmask-continue dev-libs/C"
- # ),
- # "portageq match {eroot} dev-libs/D[flag]",
- # "EPREFIX={cross_prefix} emerge dev-libs/C",
- # "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/C",
- # "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/D",
- # "ROOT={cross_root} emerge dev-libs/D",
- # "portageq has_version {cross_eroot} dev-libs/D",
- # "EPREFIX={cross_prefix} emerge -K dev-libs/A",
- # "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/A",
- # "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/B",
- # "EPREFIX={cross_prefix} emerge -Cq dev-libs/B",
- # "EPREFIX={cross_prefix} emerge -Cq dev-libs/A",
- # "EPREFIX={cross_prefix} emerge dev-libs/A",
- # "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/A",
- # "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/B",
- # "ROOT={cross_root} emerge dev-libs/B",
- # "portageq has_version {cross_eroot} dev-libs/B",
"binhost emerge",
]
@@ -572,7 +493,6 @@ def _generate_all_baseline_commands(playground, binhost):
test_commands = {}
- ###
if hasattr(argparse.ArgumentParser, "parse_intermixed_args"):
parse_intermixed_command = Emerge(
"--oneshot",
@@ -583,10 +503,8 @@ def _generate_all_baseline_commands(playground, binhost):
else:
parse_intermixed_command = Noop()
test_commands["emerge -1 dev-libs/A -v dev-libs/B"] = parse_intermixed_command
- ###
quickpkg_direct_seq = [
- # test_commands["emerge --root --quickpkg-direct-root"] =
Emerge(
"--usepkgonly",
"--root",
@@ -597,7 +515,6 @@ def _generate_all_baseline_commands(playground, binhost):
"dev-libs/A",
),
# v needs ^
- # test_commands["emerge --quickpkg-direct-root"] =
Emerge(
"--usepkgonly",
"--quickpkg-direct=y",
@@ -610,9 +527,7 @@ def _generate_all_baseline_commands(playground, binhost):
*quickpkg_direct_seq
)
- ###
test_commands["env-update"] = EnvUpdate()
- ###
test_commands["portageq envvar"] = Portageq(
"envvar",
"-v",
@@ -622,22 +537,14 @@ def _generate_all_baseline_commands(playground, binhost):
"PORTAGE_TMPDIR",
"USERLAND",
)
- ###
test_commands["etc-update"] = EtcUpdate()
- ###
test_commands["dispatch-conf"] = DispatchConf()
- ###
test_commands["emerge --version"] = Emerge("--version")
- ###
test_commands["emerge --info"] = Emerge("--info")
- ###
test_commands["emerge --info --verbose"] = Emerge("--info", "--verbose")
- ###
test_commands["emerge --list-sets"] = Emerge("--list-sets")
- ###
test_commands["emerge --check-news"] = Emerge("--check-news")
- ###
def _rm_cachedir():
shutil.rmtree(cachedir)
@@ -683,7 +590,6 @@ def _generate_all_baseline_commands(playground, binhost):
]
test_commands["emerge --regen/--metadata"] = PortageCommandSequence(*regen_seq)
- # test_commands["ebuild dev-libs/A-1 manifest clean package merge"] =
abcd_seq = [
Ebuild(
test_ebuild,
@@ -692,64 +598,50 @@ def _generate_all_baseline_commands(playground, binhost):
"package",
"merge",
),
- # test_commands["emerge --pretend --tree --complete-graph dev-libs/A"] =
Emerge(
"--pretend",
"--tree",
"--complete-graph",
"dev-libs/A",
),
- # test_commands["emerge -p dev-libs/B"] =
Emerge("-p", "dev-libs/B"),
- # test_commands["emerge -p --newrepo dev-libs/B"] =
Emerge(
"-p",
"--newrepo",
"dev-libs/B",
),
- # test_commands["emerge -B dev-libs/B"] =
Emerge("-B", "dev-libs/B"),
- # test_commands["emerge -1k dev-libs/B"] =
Emerge(
"--oneshot",
"--usepkg",
"dev-libs/B",
),
# trigger clean prior to pkg_pretend as in bug #390711
- # test_commands["ebuild dev-libs/A-1 unpack"] =
Ebuild(test_ebuild, "unpack"),
- # test_commands["emerge -1 dev-libs/A"] =
Emerge("--oneshot", "dev-libs/A"),
- # test_commands["emerge -n dev-libs/A"] =
Emerge("--noreplace", "dev-libs/A"),
- # test_commands["emerge --config dev-libs/A"] =
Emerge(
"--config",
"dev-libs/A",
),
- # test_commands["emerge --info dev-libs/A dev-libs/B"] =
Emerge(
"--info",
"dev-libs/A",
"dev-libs/B",
),
- # test_commands["emerge -pcv dev-libs/B"] =
Emerge(
"--pretend",
"--depclean",
"--verbose",
"dev-libs/B",
),
- # test_commands["emerge -pc"] =
Emerge("--pretend", "--depclean"),
- # test_commands["emerge -c"] =
Emerge(
"--depclean",
),
# Test bug #523684, where a file renamed or removed by the
# admin forces replacement files to be merged with config
# protection.
- # test_commands["quickpkg --include-config y dev-libs/A"] =
Quickpkg(
"--include-config",
"y",
@@ -758,14 +650,7 @@ def _generate_all_baseline_commands(playground, binhost):
0, eroot, settings["CONFIG_PROTECT"]
),
),
- # Another "it is not a test command" case; actually setup:
- # test_commands["rm /etc/A-0"] = lambda: os.unlink(
- # os.path.join(eprefix, "etc", "A-0")
- # )
- # emerge_noreplace_A =
Emerge("--noreplace", "dev-libs/A"),
- # test_commands["emerge -K dev-libs/A"] = PortageCommandSequence(
- # emerge_noreplace_A,
Emerge(
"--usepkgonly",
"dev-libs/A",
@@ -774,42 +659,31 @@ def _generate_all_baseline_commands(playground, binhost):
1, eroot, settings["CONFIG_PROTECT"]
),
),
- # test_commands["emaint --check all"] =
Emaint("--check", "all"),
- # test_commands["emaint --fix all"] =
Emaint("--fix", "all"),
- # test_commands["fixpackages"] =
Fixpackages(),
- # test_commands["regenworld"] =
Regenworld(),
- # test_commands["portageq match {eroot} dev-libs/A"] =
Portageq(
"match",
eroot,
"dev-libs/A",
),
- # test_commands["portageq best_visible {eroot} dev-libs/A"] =
Portageq(
"best_visible",
eroot,
"dev-libs/A",
),
- # test_commands["portageq best_visible {eroot} binary dev-libs/A"] =
Portageq(
"best_visible",
eroot,
"binary",
"dev-libs/A",
),
- # test_commands["portageq contents {eroot} dev-libs/A-1"] =
Portageq(
"contents",
eroot,
"dev-libs/A-1",
),
- # test_commands[
- # "portageq metadata {eroot} ebuild dev-libs/A-1 EAPI IUSE RDEPEND"
- # ] =
Portageq(
"metadata",
eroot,
@@ -819,9 +693,6 @@ def _generate_all_baseline_commands(playground, binhost):
"IUSE",
"RDEPEND",
),
- # test_commands[
- # "portageq metadata {eroot} binary dev-libs/A-1 EAPI USE RDEPEND"
- # ] =
Portageq(
"metadata",
eroot,
@@ -831,9 +702,6 @@ def _generate_all_baseline_commands(playground, binhost):
"USE",
"RDEPEND",
),
- # test_commands[
- # "portageq metadata {eroot} installed dev-libs/A-1 EAPI USE RDEPEND"
- # ] =
Portageq(
"metadata",
eroot,
@@ -843,28 +711,23 @@ def _generate_all_baseline_commands(playground, binhost):
"USE",
"RDEPEND",
),
- # test_commands["portageq owners {eroot} {eroot}usr"] =
Portageq(
"owners",
eroot,
eroot + "usr",
),
- # test_commands["emerge -p {eroot}usr"] =
Emerge("-p", eroot + "usr"),
- # test_commands["emerge -pCq {eroot}usr"] =
Emerge(
"-p",
"--unmerge",
"-q",
eroot + "usr",
),
- # test_commands["emerge -Cq dev-libs/A"] =
Emerge(
"--unmerge",
"--quiet",
"dev-libs/A",
),
- # test_commands["emerge -Cq dev-libs/B"] =
Emerge(
"-C",
"--quiet",
@@ -873,10 +736,6 @@ def _generate_all_baseline_commands(playground, binhost):
# autounmask:
# If EMERGE_DEFAULT_OPTS contains --autounmask=n, then --autounmask
# must be specified with --autounmask-continue.
- # test_commands[
- # "EMERGE_DEFAULT_OPTS=--autounmask=n "
- # "emerge --autounmask --autounmask-continue dev-libs/C"
- # ] =
Emerge(
"--autounmask",
"--autounmask-continue",
@@ -885,7 +744,6 @@ def _generate_all_baseline_commands(playground, binhost):
),
# Verify that the above --autounmask-continue command caused
# USE=flag to be applied correctly to dev-libs/D.
- # test_commands["portageq match {eroot} dev-libs/D[flag]"] =
Portageq(
"match",
eroot,
@@ -897,53 +755,32 @@ def _generate_all_baseline_commands(playground, binhost):
cross_prefix_seq = [
# Test cross-prefix usage, including chpathtool for binpkgs.
# EAPI 7
- # test_commands["EPREFIX={cross_prefix} emerge dev-libs/C"] =
Emerge("dev-libs/C", env_mod={"EPREFIX": cross_prefix}),
- # test_commands[
- # "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/C"
- # ] =
Portageq(
"has_version", cross_prefix, "dev-libs/C", env_mod={"EPREFIX": cross_prefix}
),
- # test_commands[
- # "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/D"
- # ] =
Portageq(
"has_version", cross_prefix, "dev-libs/D", env_mod={"EPREFIX": cross_prefix}
),
- # test_commands["ROOT={cross_root} emerge dev-libs/D"] =
Emerge("dev-libs/D", env_mod={"ROOT": cross_root}),
- # test_commands["portageq has_version {cross_eroot} dev-libs/D"] =
Portageq(
"has_version",
cross_eroot,
"dev-libs/D",
),
# EAPI 5
- # test_commands["EPREFIX={cross_prefix} emerge -K dev-libs/A"] =
Emerge("--usepkgonly", "dev-libs/A", env_mod={"EPREFIX": cross_prefix}),
- # test_commands[
- # "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/A"
- # ] =
Portageq(
"has_version", cross_prefix, "dev-libs/A", env_mod={"EPREFIX": cross_prefix}
),
- # test_commands[
- # "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/B"
- # ] =
Portageq(
"has_version", cross_prefix, "dev-libs/B", env_mod={"EPREFIX": cross_prefix}
),
- # test_commands["EPREFIX={cross_prefix} emerge -Cq dev-libs/B"] =
Emerge("-C", "--quiet", "dev-libs/B", env_mod={"EPREFIX": cross_prefix}),
- # test_commands["EPREFIX={cross_prefix} emerge -Cq dev-libs/A"] =
Emerge("-C", "--quiet", "dev-libs/A", env_mod={"EPREFIX": cross_prefix}),
- # test_commands["EPREFIX={cross_prefix} emerge dev-libs/A"] =
Emerge("dev-libs/A", env_mod={"EPREFIX": cross_prefix}),
# Test ROOT support
- # test_commands["ROOT={cross_root} emerge dev-libs/B"] =
Emerge("dev-libs/B", env_mod={"ROOT": cross_root}),
- # test_commands["portageq has_version {cross_eroot} dev-libs/B"] =
Portageq(
"has_version",
cross_eroot,
@@ -966,13 +803,8 @@ def _generate_all_baseline_commands(playground, binhost):
if fetch_bin is None:
test_commands["binhost emerge"] = Noop()
- # for command_name in _BASELINE_COMMAND_FETCHCOMMAND_SEQUENCE:
- # test_commands[command_name] = Noop()
else:
- # test_commands["mv {pkgdir} {binhost_dir}"] = lambda: os.rename(
- # pkgdir, binhost_dir
- # )
- # test_commands["emerge -eG dev-libs/A"] =
+ # The next emerge has been added to split this test from the rest:
make_package = Emerge("--buildpkg", "dev-libs/A")
getbinpkgonly = Emerge(
"-e",
@@ -980,19 +812,13 @@ def _generate_all_baseline_commands(playground, binhost):
"dev-libs/A",
preparation=lambda: os.rename(pkgdir, binhost_dir),
)
- # test_commands["rm -R {pkgdir}"] = lambda: shutil.rmtree(pkgdir)
- # test_commands["mv {binhost_dir} {pkgdir}"] = lambda: os.rename(
- # binhost_dir, pkgdir
- # )
- # Remove binrepos.conf and test PORTAGE_BINHOST.
- # test_commands["rm {binrepos_conf_file}"] = lambda: os.unlink(binrepos_conf_file)
+ # Remove binrepos.conf and test PORTAGE_BINHOST.
def _replace_pkgdir_and_rm_binrepos_conf_file():
shutil.rmtree(pkgdir)
os.rename(binhost_dir, pkgdir)
os.unlink(binrepos_conf_file)
- # test_commands["PORTAGE_BINHOST={binhost_uri} emerge -feG dev-libs/A"] =
getbinpkgonly_fetchonly = Emerge(
"-fe",
"--getbinpkgonly",
diff --git a/lib/portage/tests/emerge/test_simple.py b/lib/portage/tests/emerge/test_baseline.py
similarity index 95%
rename from lib/portage/tests/emerge/test_simple.py
rename to lib/portage/tests/emerge/test_baseline.py
index b23e10ddfd..55722d900e 100644
--- a/lib/portage/tests/emerge/test_simple.py
+++ b/lib/portage/tests/emerge/test_baseline.py
@@ -4,7 +4,7 @@
"""This module defines a baseline for portage's functionality.
Multiple portage commands are executed in a sequence in a playground
-(see the ``simple_command`` fixture in ``conftest.py``).
+(see the ``baseline_command`` fixture in ``conftest.py``).
All the commands are triggered from the ``test_portage_baseline`` test.
That test is marked with::
@@ -16,7 +16,12 @@ so that it can selected with that marker, i.e.::
pytest -m ft
``ft`` stands for *functional test*, since that's what it is, a
-functional or end-to-end test.
+functional or end-to-end test, ensuring some functionality of portage.
+
+The test also works with pytest-xdist, e.g.::
+
+ pytest -m ft -n 8
+
"""
import subprocess
@@ -60,7 +65,7 @@ move dev-util/git dev-vcs/git
def test_portage_baseline(async_loop, playground, binhost, baseline_command):
async_loop.run_until_complete(
asyncio.ensure_future(
- _async_test_simple(
+ _async_test_baseline(
playground,
binhost,
baseline_command,
@@ -70,14 +75,12 @@ def test_portage_baseline(async_loop, playground, binhost, baseline_command):
)
-async def _async_test_simple(playground, binhost, commands):
+async def _async_test_baseline(playground, binhost, commands):
debug = playground.debug
settings = playground.settings
trees = playground.trees
eprefix = settings["EPREFIX"]
- # test_commands = make_test_commands(settings, trees, binhost["uri"])
-
test_repo_location = settings.repositories["test_repo"].location
var_cache_edb = os.path.join(eprefix, "var", "cache", "edb")
cachedir = os.path.join(var_cache_edb, "dep")
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/emerge/
@ 2023-10-30 3:14 Sam James
0 siblings, 0 replies; 38+ messages in thread
From: Sam James @ 2023-10-30 3:14 UTC (permalink / raw
To: gentoo-commits
commit: f539a071895d51aab15f8ae359150d8c638de0f9
Author: David Palao <david.palao <AT> gmail <DOT> com>
AuthorDate: Fri Sep 29 15:58:15 2023 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Oct 30 03:14:24 2023 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=f539a071
tests/emerge/conftest.py: Add PortageCommandSequence
Add PortageCommandSequence. Some commands must run in sequence
to test some functionality of portage. This class has been added
to chain commands within a test.
Signed-off-by: David Palao <david.palao <AT> gmail.com>
Signed-off-by: Sam James <sam <AT> gentoo.org>
lib/portage/tests/emerge/conftest.py | 124 +++++++++++++++++------------------
1 file changed, 62 insertions(+), 62 deletions(-)
diff --git a/lib/portage/tests/emerge/conftest.py b/lib/portage/tests/emerge/conftest.py
index 43fde441fd..27cca5e077 100644
--- a/lib/portage/tests/emerge/conftest.py
+++ b/lib/portage/tests/emerge/conftest.py
@@ -203,24 +203,27 @@ _BASELINE_COMMAND_SEQUENCE = [
"emerge --info --verbose",
"emerge --list-sets",
"emerge --check-news",
- # "rm -rf {cachedir}",
- # "rm -rf {cachedir_pregen}",
- "emerge --regen",
- # "rm -rf {cachedir}",
- "FEATURES=metadata-transfer emerge --regen",
- # "rm -rf {cachedir}",
- "FEATURES=metadata-transfer emerge --regen", # is this second test case needed?
- # "rm -rf {cachedir}",
- "egencache --update",
- "FEATURES=metadata-transfer emerge --metadata",
- # "rm -rf {cachedir}",
- "FEATURES=metadata-transfer emerge --metadata (2)",
- "emerge --metadata",
- # "rm -rf {cachedir}",
- "emerge --oneshot virtual/foo",
- # "foo pkg missing",
- "FEATURES=unmerge-backup emerge --unmerge virtual/foo",
- # "foo pkg exists",
+ #
+ # # "rm -rf {cachedir}",
+ # # "rm -rf {cachedir_pregen}",
+ # "emerge --regen",
+ # # "rm -rf {cachedir}",
+ # "FEATURES=metadata-transfer emerge --regen",
+ # # "rm -rf {cachedir}",
+ # "FEATURES=metadata-transfer emerge --regen", # is this second test case needed?
+ # # "rm -rf {cachedir}",
+ # "egencache --update",
+ # "FEATURES=metadata-transfer emerge --metadata",
+ # # "rm -rf {cachedir}",
+ # "FEATURES=metadata-transfer emerge --metadata (2)",
+ # "emerge --metadata",
+ # # "rm -rf {cachedir}",
+ # "emerge --oneshot virtual/foo",
+ # # "foo pkg missing",
+ # "FEATURES=unmerge-backup emerge --unmerge virtual/foo",
+ # # "foo pkg exists",
+ "emerge --regen/--metadata",
+ #
"emerge --pretend dev-libs/A",
"ebuild dev-libs/A-1 manifest clean package merge",
"emerge --pretend --tree --complete-graph dev-libs/A",
@@ -340,6 +343,14 @@ class PortageCommand:
self.post_command()
+class PortageCommandSequence:
+ def __init__(self, *commands):
+ self.commands = commands
+
+ def __iter__(self):
+ yield from self.commands
+
+
class Emerge(PortageCommand):
name = "emerge"
command = (PORTAGE_PYTHON, "-b", "-Wd", os.path.join(cnf_bindir, name))
@@ -621,50 +632,39 @@ def _generate_all_baseline_commands(playground, binhost):
_rm_cachedir()
shutil.rmtree(cachedir_pregen)
- test_commands["emerge --regen"] = Emerge(
- "--regen", preparation=_rm_cachedir_and_pregen
- )
-
- test_commands["FEATURES=metadata-transfer emerge --regen"] = Emerge(
- "--regen", env_mod={"FEATURES": "metadata-transfer"}, preparation=_rm_cachedir
- )
-
- test_commands["egencache --update"] = Egencache(
- "--repo",
- "test_repo",
- "--repositories-configuration",
- playground.settings.repositories.config_string(),
- "--update",
- *egencache_extra_args,
- preparation=_rm_cachedir,
- )
-
- test_commands["FEATURES=metadata-transfer emerge --metadata"] = Emerge(
- "--metadata", env_mod={"FEATURES": "metadata-transfer"}
- )
-
- test_commands["FEATURES=metadata-transfer emerge --metadata (2)"] = Emerge(
- "--metadata",
- env_mod={"FEATURES": "metadata-transfer"},
- preparation=_rm_cachedir,
- )
-
- test_commands["emerge --metadata"] = Emerge("--metadata")
-
- test_commands["emerge --oneshot virtual/foo"] = Emerge(
- "--oneshot", "virtual/foo", preparation=_rm_cachedir
- )
-
- # test_commands["foo pkg missing"] = lambda: _check_foo_file(
- # pkgdir, foo_filename, must_exist=False
- # )
-
- test_commands["FEATURES=unmerge-backup emerge --unmerge virtual/foo"] = Emerge(
- "--unmerge",
- "virtual/foo",
- env_mod={"FEATURES": "unmerge-backup"},
- preparation=lambda: _check_foo_file(pkgdir, foo_filename, must_exist=False),
- )
+ regen_seq = [
+ Emerge("--regen", preparation=_rm_cachedir_and_pregen),
+ Emerge(
+ "--regen",
+ env_mod={"FEATURES": "metadata-transfer"},
+ preparation=_rm_cachedir,
+ ),
+ Egencache(
+ "--repo",
+ "test_repo",
+ "--repositories-configuration",
+ playground.settings.repositories.config_string(),
+ "--update",
+ *egencache_extra_args,
+ preparation=_rm_cachedir,
+ ),
+ Emerge("--metadata", env_mod={"FEATURES": "metadata-transfer"}),
+ Emerge(
+ "--metadata",
+ env_mod={"FEATURES": "metadata-transfer"},
+ preparation=_rm_cachedir,
+ ),
+ Emerge("--metadata"),
+ Emerge("--oneshot", "virtual/foo", preparation=_rm_cachedir),
+ Emerge(
+ "--unmerge",
+ "virtual/foo",
+ env_mod={"FEATURES": "unmerge-backup"},
+ preparation=lambda: _check_foo_file(pkgdir, foo_filename, must_exist=False),
+ ),
+ ]
+ test_commands["emerge --regen/--metadata"] = PortageCommandSequence(*regen_seq)
+ # Assuming that the sequence ends here!
# test_commands["foo pkg exists"] = lambda: _check_foo_file(
# pkgdir, foo_filename, must_exist=True
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/emerge/
@ 2023-10-30 3:14 Sam James
0 siblings, 0 replies; 38+ messages in thread
From: Sam James @ 2023-10-30 3:14 UTC (permalink / raw
To: gentoo-commits
commit: 7ba8f05b82c6d19c6bcfa1f6274050c5dfc40f7a
Author: David Palao <david.palao <AT> gmail <DOT> com>
AuthorDate: Fri Sep 29 14:37:18 2023 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Oct 30 03:14:24 2023 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=7ba8f05b
tests/emerge: test_simple.py, conftest.py: Refactor
Refactor.
Introduced a PortageCommand class to be able to pack together a
sequence of operations that, as a whole, express expected behavior
in portage.
(This commit is a baseline: the refactor works out, but further
refactors must follow).
Signed-off-by: David Palao <david.palao <AT> gmail.com>
Signed-off-by: Sam James <sam <AT> gentoo.org>
lib/portage/tests/emerge/conftest.py | 770 ++++++++++++++++++++++++++------
lib/portage/tests/emerge/test_simple.py | 183 ++++++--
2 files changed, 796 insertions(+), 157 deletions(-)
diff --git a/lib/portage/tests/emerge/conftest.py b/lib/portage/tests/emerge/conftest.py
index ce339d3afc..5bf535cdcf 100644
--- a/lib/portage/tests/emerge/conftest.py
+++ b/lib/portage/tests/emerge/conftest.py
@@ -2,6 +2,7 @@
# Distributed under the terms of the GNU General Public License v2
import argparse
+from typing import Optional, Callable # , Self
from portage.const import (
SUPPORTED_GENTOO_BINPKG_FORMATS,
@@ -178,15 +179,15 @@ _INSTALLED_EBUILDS = {
}
_SIMPLE_COMMAND_FETCHCOMMAND_SEQUENCE = [
- "mv {pkgdir} {binhost_dir}",
+ # "mv {pkgdir} {binhost_dir}",
"emerge -eG dev-libs/A",
- "rm -R {pkgdir}",
- "mv {binhost_dir} {pkgdir}",
- "rm {binrepos_conf_file}",
- "mv {pkgdir} {binhost_dir}",
+ # "rm -R {pkgdir}",
+ # "mv {binhost_dir} {pkgdir}",
+ # "rm {binrepos_conf_file}",
+ # "mv {pkgdir} {binhost_dir}",
"PORTAGE_BINHOST={binhost_uri} emerge -feG dev-libs/A",
- "rm -R {pkgdir}",
- "mv {binhost_dir} {pkgdir}",
+ # "rm -R {pkgdir}",
+ # "mv {binhost_dir} {pkgdir}",
]
_SIMPLE_COMMAND_SEQUENCE = [
@@ -202,24 +203,24 @@ _SIMPLE_COMMAND_SEQUENCE = [
"emerge --info --verbose",
"emerge --list-sets",
"emerge --check-news",
- "rm -rf {cachedir}",
- "rm -rf {cachedir_pregen}",
+ # "rm -rf {cachedir}",
+ # "rm -rf {cachedir_pregen}",
"emerge --regen",
- "rm -rf {cachedir}",
+ # "rm -rf {cachedir}",
"FEATURES=metadata-transfer emerge --regen",
- "rm -rf {cachedir}",
- "FEATURES=metadata-transfer emerge --regen",
- "rm -rf {cachedir}",
+ # "rm -rf {cachedir}",
+ "FEATURES=metadata-transfer emerge --regen", # is this second test case needed?
+ # "rm -rf {cachedir}",
"egencache --update",
"FEATURES=metadata-transfer emerge --metadata",
- "rm -rf {cachedir}",
- "FEATURES=metadata-transfer emerge --metadata",
+ # "rm -rf {cachedir}",
+ "FEATURES=metadata-transfer emerge --metadata (2)",
"emerge --metadata",
- "rm -rf {cachedir}",
+ # "rm -rf {cachedir}",
"emerge --oneshot virtual/foo",
- "foo pkg missing",
+ # "foo pkg missing",
"FEATURES=unmerge-backup emerge --unmerge virtual/foo",
- "foo pkg exists",
+ # "foo pkg exists",
"emerge --pretend dev-libs/A",
"ebuild dev-libs/A-1 manifest clean package merge",
"emerge --pretend --tree --complete-graph dev-libs/A",
@@ -236,10 +237,10 @@ _SIMPLE_COMMAND_SEQUENCE = [
"emerge -pc",
"emerge -c",
"quickpkg --include-config y dev-libs/A",
- "no protected files",
- "rm /etc/A-0",
+ # "no protected files",
+ # "rm /etc/A-0",
"emerge -K dev-libs/A",
- "one protected file",
+ # "one protected file",
"emaint --check all",
"emaint --fix all",
"fixpackages",
@@ -282,27 +283,162 @@ PORTAGE_PYTHON = portage._python_interpreter
NOOP = lambda: ...
-# class SimpleTestCommand:
-# """A class that represents a simple test case command,
-# including post checks, preparation and cleanup.
-# """
-# def __init__(self, command, *options, environment=None):
-# self._command = command
-# self._options = options
-# if environment is None:
-# environment = {}
-# self.environment = environment
+class PortageCommand:
+ """A class that represents a simple test case command,
+ including handling of environment and one-use arguments.
+ """
+
+ command = None
+ name = None
+
+ def __init__(
+ self,
+ *args: tuple[str],
+ env_mod: Optional[dict[str, str]] = None,
+ preparation: Optional[Callable[[], None]] = None,
+ post_command: Optional[Callable[[], None]] = None,
+ ) -> None:
+ self.args = args
+ self.env_mod = env_mod
+ self.preparation = preparation
+ self.post_command = post_command
+
+ def __iter__(self):
+ """To be able to call a function with ``*command`` as argument."""
+ yield self
+
+ @property
+ def env(self) -> dict[str, str]:
+ """This property returns the environment intended to be used
+ with the current test command, including possible modifications.
+ """
+ try:
+ base_environment = self.base_environment
+ except AttributeError:
+ base_environment = {}
+ else:
+ base_environment = base_environment.copy()
+ if self.env_mod:
+ base_environment.update(self.env_mod)
+ return base_environment
+
+ def __call__(self): # -> Self:
+ if self.preparation:
+ self.preparation()
+ try:
+ tuple_command = self.command + self.args
+ except TypeError:
+ # In case self.command is a string:
+ tuple_command = (self.command,) + self.args
+ return tuple_command
+
+ def __bool__(self) -> bool:
+ return bool(self.command)
+
+ def check_command_result(self) -> None:
+ if self.post_command:
+ self.post_command()
+
+
+class Emerge(PortageCommand):
+ name = "emerge"
+ command = (PORTAGE_PYTHON, "-b", "-Wd", os.path.join(cnf_bindir, name))
+
+
+class Noop(PortageCommand):
+ name = "No-op"
+
+
+class EnvUpdate(PortageCommand):
+ name = "env-update"
+ command = (PORTAGE_PYTHON, "-b", "-Wd", os.path.join(cnf_sbindir, name))
+
+
+class DispatchConf(PortageCommand):
+ name = "dispatch-conf"
+ command = (
+ PORTAGE_PYTHON,
+ "-b",
+ "-Wd",
+ os.path.join(cnf_sbindir, name),
+ )
+
+
+class Ebuild(PortageCommand):
+ name = "ebuild"
+ command = (PORTAGE_PYTHON, "-b", "-Wd", os.path.join(cnf_bindir, name))
+
+
+class Egencache(PortageCommand):
+ name = "egencache"
+ command = (
+ PORTAGE_PYTHON,
+ "-b",
+ "-Wd",
+ os.path.join(cnf_bindir, name),
+ )
-# def prepare(self):
-# ...
-# def cleanup(self):
-# ...
+class Emaint(PortageCommand):
+ name = "emaint"
+ command = (PORTAGE_PYTHON, "-b", "-Wd", os.path.join(cnf_sbindir, name))
+
+
+class EtcUpdate(PortageCommand):
+ name = "etc-update"
+ command = (BASH_BINARY, os.path.join(cnf_sbindir, name))
+
+
+class Fixpackages(PortageCommand):
+ name = "fixpackages"
+ command = (
+ PORTAGE_PYTHON,
+ "-b",
+ "-Wd",
+ os.path.join(cnf_sbindir, name),
+ )
+
+
+class Portageq(PortageCommand):
+ name = "portageq"
+ command = (
+ PORTAGE_PYTHON,
+ "-b",
+ "-Wd",
+ os.path.join(cnf_bindir, name),
+ )
+
+
+class Quickpkg(PortageCommand):
+ name = "quickpkg"
+ command = (
+ PORTAGE_PYTHON,
+ "-b",
+ "-Wd",
+ os.path.join(cnf_bindir, name),
+ )
+
+
+class Regenworld(PortageCommand):
+ name = "regenworld"
+ command = (
+ PORTAGE_PYTHON,
+ "-b",
+ "-Wd",
+ os.path.join(cnf_sbindir, name),
+ )
+
+
+class Rm(PortageCommand):
+ name = "rm"
+ command = (find_binary(name),)
def pytest_generate_tests(metafunc):
- if "simple_command" in metafunc.fixturenames:
- metafunc.parametrize("simple_command", _SIMPLE_COMMAND_SEQUENCE, indirect=True)
+ if "baseline_command" in metafunc.fixturenames:
+ metafunc.parametrize(
+ "baseline_command", _SIMPLE_COMMAND_SEQUENCE, indirect=True
+ )
def _have_python_xml():
@@ -387,100 +523,6 @@ def binhost(playground, async_loop):
binhost_server.__exit__(None, None, None)
-@pytest.fixture()
-def emerge():
- yield (PORTAGE_PYTHON, "-b", "-Wd", os.path.join(cnf_bindir, "emerge"))
-
-
-@pytest.fixture()
-def dispatch_conf():
- yield (
- PORTAGE_PYTHON,
- "-b",
- "-Wd",
- os.path.join(cnf_sbindir, "dispatch-conf"),
- )
-
-
-@pytest.fixture()
-def ebuild():
- yield (PORTAGE_PYTHON, "-b", "-Wd", os.path.join(cnf_bindir, "ebuild"))
-
-
-@pytest.fixture()
-def egencache(playground):
- yield (
- PORTAGE_PYTHON,
- "-b",
- "-Wd",
- os.path.join(cnf_bindir, "egencache"),
- "--repo",
- "test_repo",
- "--repositories-configuration",
- playground.settings.repositories.config_string(),
- )
-
-
-@pytest.fixture()
-def emaint():
- yield (PORTAGE_PYTHON, "-b", "-Wd", os.path.join(cnf_sbindir, "emaint"))
-
-
-@pytest.fixture()
-def env_update():
- yield (
- PORTAGE_PYTHON,
- "-b",
- "-Wd",
- os.path.join(cnf_sbindir, "env-update"),
- )
-
-
-@pytest.fixture()
-def etc_update():
- yield (BASH_BINARY, os.path.join(cnf_sbindir, "etc-update"))
-
-
-@pytest.fixture()
-def fixpackages():
- yield (
- PORTAGE_PYTHON,
- "-b",
- "-Wd",
- os.path.join(cnf_sbindir, "fixpackages"),
- )
-
-
-@pytest.fixture()
-def portageq():
- yield (
- PORTAGE_PYTHON,
- "-b",
- "-Wd",
- os.path.join(cnf_bindir, "portageq"),
- )
-
-
-@pytest.fixture()
-def quickpkg():
- yield (
- PORTAGE_PYTHON,
- "-b",
- "-Wd",
- os.path.join(cnf_bindir, "quickpkg"),
- )
-
-
-@pytest.fixture()
-def regenworld():
- yield (
- PORTAGE_PYTHON,
- "-b",
- "-Wd",
- os.path.join(cnf_sbindir, "regenworld"),
- )
-
-
@pytest.fixture()
def _generate_all_simple_commands(
playground,
@@ -889,6 +931,461 @@ def _generate_all_simple_commands(
yield test_commands
+@pytest.fixture()
+def _generate_all_baseline_commands(playground, binhost):
+ """This fixture generates all the commands that
+ ``test_portage_baseline`` will use.
+
+ But, don't use this fixture directly, instead, use the
+ ``baseline_command`` fixture. That improves performance a bit due to
+ pytest caching.
+
+ .. note::
+
+ To add a new command, define it in the local ``test_commands``
+ dict, if not yet defined, and add its key at the correct position
+ in the ``_SIMPLE_COMMAND_SEQUENCE`` list.
+ """
+ settings = playground.settings
+ eprefix = settings["EPREFIX"]
+ eroot = settings["EROOT"]
+ trees = playground.trees
+ pkgdir = playground.pkgdir
+ portdb = trees[eroot]["porttree"].dbapi
+ test_repo_location = settings.repositories["test_repo"].location
+ var_cache_edb = os.path.join(eprefix, "var", "cache", "edb")
+ cachedir = os.path.join(var_cache_edb, "dep")
+ cachedir_pregen = os.path.join(test_repo_location, "metadata", "md5-cache")
+
+ rm_binary = find_binary("rm")
+ assert rm_binary is not None, "rm command not found"
+ rm_cmd = (rm_binary,)
+
+ egencache_extra_args = []
+ if _have_python_xml():
+ egencache_extra_args.append("--update-use-local-desc")
+
+ test_ebuild = portdb.findname("dev-libs/A-1")
+ assert test_ebuild is not None
+
+ cross_prefix = os.path.join(eprefix, "cross_prefix")
+ cross_root = os.path.join(eprefix, "cross_root")
+ cross_eroot = os.path.join(cross_root, eprefix.lstrip(os.sep))
+
+ binpkg_format = settings.get("BINPKG_FORMAT", SUPPORTED_GENTOO_BINPKG_FORMATS[0])
+ assert binpkg_format in ("xpak", "gpkg")
+ if binpkg_format == "xpak":
+ foo_filename = "foo-0-1.xpak"
+ elif binpkg_format == "gpkg":
+ foo_filename = "foo-0-1.gpkg.tar"
+
+ test_commands = {}
+
+ if hasattr(argparse.ArgumentParser, "parse_intermixed_args"):
+ parse_intermixed_command = Emerge(
+ "--oneshot",
+ "dev-libs/A",
+ "-v",
+ "dev-libs/A",
+ )
+ else:
+ parse_intermixed_command = Noop()
+ test_commands["emerge -1 dev-libs/A -v dev-libs/B"] = parse_intermixed_command
+
+ test_commands["emerge --root --quickpkg-direct-root"] = Emerge(
+ "--usepkgonly",
+ "--root",
+ cross_root,
+ "--quickpkg-direct=y",
+ "--quickpkg-direct-root",
+ "/",
+ "dev-libs/A",
+ )
+
+ test_commands["emerge --quickpkg-direct-root"] = Emerge(
+ "--usepkgonly",
+ "--quickpkg-direct=y",
+ "--quickpkg-direct-root",
+ cross_root,
+ "dev-libs/A",
+ )
+ test_commands["env-update"] = EnvUpdate()
+ test_commands["portageq envvar"] = Portageq(
+ "envvar",
+ "-v",
+ "CONFIG_PROTECT",
+ "EROOT",
+ "PORTAGE_CONFIGROOT",
+ "PORTAGE_TMPDIR",
+ "USERLAND",
+ )
+ test_commands["etc-update"] = EtcUpdate()
+ test_commands["dispatch-conf"] = DispatchConf()
+ test_commands["emerge --version"] = Emerge("--version")
+ test_commands["emerge --info"] = Emerge("--info")
+ test_commands["emerge --info --verbose"] = Emerge("--info", "--verbose")
+ test_commands["emerge --list-sets"] = Emerge("--list-sets")
+ test_commands["emerge --check-news"] = Emerge("--check-news")
+
+ # test_commands["rm -rf {cachedir}"] = Rm("-rf", cachedir)
+ # test_commands["rm -rf {cachedir_pregen}"] = Rm("-rf", cachedir_pregen)
+
+ def _rm_cachedir():
+ shutil.rmtree(cachedir)
+
+ def _rm_cachedir_and_pregen():
+ _rm_cachedir()
+ shutil.rmtree(cachedir_pregen)
+
+ test_commands["emerge --regen"] = Emerge(
+ "--regen", preparation=_rm_cachedir_and_pregen
+ )
+
+ test_commands["FEATURES=metadata-transfer emerge --regen"] = Emerge(
+ "--regen", env_mod={"FEATURES": "metadata-transfer"}, preparation=_rm_cachedir
+ )
+
+ test_commands["egencache --update"] = Egencache(
+ "--repo",
+ "test_repo",
+ "--repositories-configuration",
+ playground.settings.repositories.config_string(),
+ "--update",
+ *egencache_extra_args,
+ preparation=_rm_cachedir,
+ )
+
+ test_commands["FEATURES=metadata-transfer emerge --metadata"] = Emerge(
+ "--metadata", env_mod={"FEATURES": "metadata-transfer"}
+ )
+
+ test_commands["FEATURES=metadata-transfer emerge --metadata (2)"] = Emerge(
+ "--metadata",
+ env_mod={"FEATURES": "metadata-transfer"},
+ preparation=_rm_cachedir,
+ )
+
+ test_commands["emerge --metadata"] = Emerge("--metadata")
+
+ test_commands["emerge --oneshot virtual/foo"] = Emerge(
+ "--oneshot", "virtual/foo", preparation=_rm_cachedir
+ )
+
+ # test_commands["foo pkg missing"] = lambda: _check_foo_file(
+ # pkgdir, foo_filename, must_exist=False
+ # )
+
+ test_commands["FEATURES=unmerge-backup emerge --unmerge virtual/foo"] = Emerge(
+ "--unmerge",
+ "virtual/foo",
+ env_mod={"FEATURES": "unmerge-backup"},
+ preparation=lambda: _check_foo_file(pkgdir, foo_filename, must_exist=False),
+ )
+
+ # test_commands["foo pkg exists"] = lambda: _check_foo_file(
+ # pkgdir, foo_filename, must_exist=True
+ # )
+
+ test_commands["emerge --pretend dev-libs/A"] = Emerge(
+ "--pretend",
+ "dev-libs/A",
+ preparation=lambda: _check_foo_file(pkgdir, foo_filename, must_exist=True),
+ )
+
+ test_commands["ebuild dev-libs/A-1 manifest clean package merge"] = Ebuild(
+ test_ebuild,
+ "manifest",
+ "clean",
+ "package",
+ "merge",
+ )
+ test_commands["emerge --pretend --tree --complete-graph dev-libs/A"] = Emerge(
+ "--pretend",
+ "--tree",
+ "--complete-graph",
+ "dev-libs/A",
+ )
+ test_commands["emerge -p dev-libs/B"] = Emerge("-p", "dev-libs/B")
+ test_commands["emerge -p --newrepo dev-libs/B"] = Emerge(
+ "-p",
+ "--newrepo",
+ "dev-libs/B",
+ )
+ test_commands["emerge -B dev-libs/B"] = Emerge("-B", "dev-libs/B")
+ test_commands["emerge -1k dev-libs/B"] = Emerge(
+ "--oneshot",
+ "--usepkg",
+ "dev-libs/B",
+ )
+ # trigger clean prior to pkg_pretend as in bug #390711
+ test_commands["ebuild dev-libs/A-1 unpack"] = Ebuild(test_ebuild, "unpack")
+ test_commands["emerge -1 dev-libs/A"] = Emerge("--oneshot", "dev-libs/A")
+ test_commands["emerge -n dev-libs/A"] = Emerge("--noreplace", "dev-libs/A")
+ test_commands["emerge --config dev-libs/A"] = Emerge(
+ "--config",
+ "dev-libs/A",
+ )
+ test_commands["emerge --info dev-libs/A dev-libs/B"] = Emerge(
+ "--info",
+ "dev-libs/A",
+ "dev-libs/B",
+ )
+ test_commands["emerge -pcv dev-libs/B"] = Emerge(
+ "--pretend",
+ "--depclean",
+ "--verbose",
+ "dev-libs/B",
+ )
+ test_commands["emerge -pc"] = Emerge("--pretend", "--depclean")
+ test_commands["emerge -c"] = Emerge(
+ "--depclean",
+ )
+ test_commands["quickpkg --include-config y dev-libs/A"] = Quickpkg(
+ "--include-config",
+ "y",
+ "dev-libs/A",
+ post_command=lambda: _check_number_of_protected_files(
+ 0, eroot, settings["CONFIG_PROTECT"]
+ ),
+ )
+ # Test bug #523684, where a file renamed or removed by the
+ # admin forces replacement files to be merged with config
+ # protection.
+
+ # test_commands["no protected files"] = lambda: _check_number_of_protected_files(
+ # 0, eroot, settings["CONFIG_PROTECT"]
+ # )
+
+ # Another "it is not a test command" case; actually setup:
+ # test_commands["rm /etc/A-0"] = lambda: os.unlink(
+ # os.path.join(eprefix, "etc", "A-0")
+ # )
+ test_commands["emerge -K dev-libs/A"] = Emerge(
+ "--usepkgonly",
+ "dev-libs/A",
+ preparation=lambda: os.unlink(os.path.join(eprefix, "etc", "A-0")),
+ post_command=lambda: _check_number_of_protected_files(
+ 1, eroot, settings["CONFIG_PROTECT"]
+ ),
+ )
+
+ # test_commands["one protected file"] = lambda: _check_number_of_protected_files(
+ # 1, eroot, settings["CONFIG_PROTECT"]
+ # )
+
+ test_commands["emaint --check all"] = Emaint("--check", "all")
+ test_commands["emaint --fix all"] = Emaint("--fix", "all")
+ test_commands["fixpackages"] = Fixpackages()
+ test_commands["regenworld"] = Regenworld()
+ test_commands["portageq match {eroot} dev-libs/A"] = Portageq(
+ "match",
+ eroot,
+ "dev-libs/A",
+ )
+ test_commands["portageq best_visible {eroot} dev-libs/A"] = Portageq(
+ "best_visible",
+ eroot,
+ "dev-libs/A",
+ )
+ test_commands["portageq best_visible {eroot} binary dev-libs/A"] = Portageq(
+ "best_visible",
+ eroot,
+ "binary",
+ "dev-libs/A",
+ )
+ test_commands["portageq contents {eroot} dev-libs/A-1"] = Portageq(
+ "contents",
+ eroot,
+ "dev-libs/A-1",
+ )
+ test_commands[
+ "portageq metadata {eroot} ebuild dev-libs/A-1 EAPI IUSE RDEPEND"
+ ] = Portageq(
+ "metadata",
+ eroot,
+ "ebuild",
+ "dev-libs/A-1",
+ "EAPI",
+ "IUSE",
+ "RDEPEND",
+ )
+ test_commands[
+ "portageq metadata {eroot} binary dev-libs/A-1 EAPI USE RDEPEND"
+ ] = Portageq(
+ "metadata",
+ eroot,
+ "binary",
+ "dev-libs/A-1",
+ "EAPI",
+ "USE",
+ "RDEPEND",
+ )
+ test_commands[
+ "portageq metadata {eroot} installed dev-libs/A-1 EAPI USE RDEPEND"
+ ] = Portageq(
+ "metadata",
+ eroot,
+ "installed",
+ "dev-libs/A-1",
+ "EAPI",
+ "USE",
+ "RDEPEND",
+ )
+ test_commands["portageq owners {eroot} {eroot}usr"] = Portageq(
+ "owners",
+ eroot,
+ eroot + "usr",
+ )
+ test_commands["emerge -p {eroot}usr"] = Emerge("-p", eroot + "usr")
+ test_commands["emerge -pCq {eroot}usr"] = Emerge(
+ "-p",
+ "--unmerge",
+ "-q",
+ eroot + "usr",
+ )
+ test_commands["emerge -Cq dev-libs/A"] = Emerge(
+ "--unmerge",
+ "--quiet",
+ "dev-libs/A",
+ )
+ test_commands["emerge -Cq dev-libs/B"] = Emerge(
+ "-C",
+ "--quiet",
+ "dev-libs/B",
+ )
+
+ # autounmask:
+ # If EMERGE_DEFAULT_OPTS contains --autounmask=n, then --autounmask
+ # must be specified with --autounmask-continue.
+ test_commands[
+ "EMERGE_DEFAULT_OPTS=--autounmask=n "
+ "emerge --autounmask --autounmask-continue dev-libs/C"
+ ] = Emerge(
+ "--autounmask",
+ "--autounmask-continue",
+ "dev-libs/C",
+ env_mod={"EMERGE_DEFAULT_OPTS": "--autounmask=n"},
+ )
+
+ # Verify that the above --autounmask-continue command caused
+ # USE=flag to be applied correctly to dev-libs/D.
+ test_commands["portageq match {eroot} dev-libs/D[flag]"] = Portageq(
+ "match",
+ eroot,
+ "dev-libs/D[flag]",
+ )
+ # Test cross-prefix usage, including chpathtool for binpkgs.
+ # EAPI 7
+ test_commands["EPREFIX={cross_prefix} emerge dev-libs/C"] = Emerge(
+ "dev-libs/C", env_mod={"EPREFIX": cross_prefix}
+ )
+
+ test_commands[
+ "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/C"
+ ] = Portageq(
+ "has_version", cross_prefix, "dev-libs/C", env_mod={"EPREFIX": cross_prefix}
+ )
+
+ test_commands[
+ "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/D"
+ ] = Portageq(
+ "has_version", cross_prefix, "dev-libs/D", env_mod={"EPREFIX": cross_prefix}
+ )
+
+ test_commands["ROOT={cross_root} emerge dev-libs/D"] = Emerge(
+ "dev-libs/D", env_mod={"ROOT": cross_root}
+ )
+
+ test_commands["portageq has_version {cross_eroot} dev-libs/D"] = Portageq(
+ "has_version",
+ cross_eroot,
+ "dev-libs/D",
+ )
+ # EAPI 5
+ test_commands["EPREFIX={cross_prefix} emerge -K dev-libs/A"] = Emerge(
+ "--usepkgonly", "dev-libs/A", env_mod={"EPREFIX": cross_prefix}
+ )
+
+ test_commands[
+ "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/A"
+ ] = Portageq(
+ "has_version", cross_prefix, "dev-libs/A", env_mod={"EPREFIX": cross_prefix}
+ )
+
+ test_commands[
+ "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/B"
+ ] = Portageq(
+ "has_version", cross_prefix, "dev-libs/B", env_mod={"EPREFIX": cross_prefix}
+ )
+
+ test_commands["EPREFIX={cross_prefix} emerge -Cq dev-libs/B"] = Emerge(
+ "-C", "--quiet", "dev-libs/B", env_mod={"EPREFIX": cross_prefix}
+ )
+
+ test_commands["EPREFIX={cross_prefix} emerge -Cq dev-libs/A"] = Emerge(
+ "-C", "--quiet", "dev-libs/A", env_mod={"EPREFIX": cross_prefix}
+ )
+
+ test_commands["EPREFIX={cross_prefix} emerge dev-libs/A"] = Emerge(
+ "dev-libs/A", env_mod={"EPREFIX": cross_prefix}
+ )
+
+ # Test ROOT support
+ test_commands["ROOT={cross_root} emerge dev-libs/B"] = Emerge(
+ "dev-libs/B", env_mod={"ROOT": cross_root}
+ )
+
+ test_commands["portageq has_version {cross_eroot} dev-libs/B"] = Portageq(
+ "has_version",
+ cross_eroot,
+ "dev-libs/B",
+ )
+
+ # Test binhost support if FETCHCOMMAND is available.
+ binrepos_conf_file = os.path.join(os.sep, eprefix, BINREPOS_CONF_FILE)
+ binhost_uri = binhost["uri"]
+ binhost_dir = binhost["dir"]
+ with open(binrepos_conf_file, "w") as f:
+ f.write("[test-binhost]\n")
+ f.write(f"sync-uri = {binhost_uri}\n")
+ fetchcommand = portage.util.shlex_split(settings["FETCHCOMMAND"])
+ fetch_bin = portage.process.find_binary(fetchcommand[0])
+ if fetch_bin is None:
+ for command_name in _SIMPLE_COMMAND_FETCHCOMMAND_SEQUENCE:
+ test_commands[command_name] = Noop()
+ else:
+ # test_commands["mv {pkgdir} {binhost_dir}"] = lambda: os.rename(
+ # pkgdir, binhost_dir
+ # )
+ test_commands["emerge -eG dev-libs/A"] = Emerge(
+ "-e",
+ "--getbinpkgonly",
+ "dev-libs/A",
+ preparation=lambda: os.rename(pkgdir, binhost_dir),
+ )
+ # test_commands["rm -R {pkgdir}"] = lambda: shutil.rmtree(pkgdir)
+ # test_commands["mv {binhost_dir} {pkgdir}"] = lambda: os.rename(
+ # binhost_dir, pkgdir
+ # )
+ # Remove binrepos.conf and test PORTAGE_BINHOST.
+
+ # test_commands["rm {binrepos_conf_file}"] = lambda: os.unlink(binrepos_conf_file)
+ def _replace_pkgdir_and_rm_binrepos_conf_file():
+ shutil.rmtree(pkgdir)
+ os.rename(binhost_dir, pkgdir)
+ os.unlink(binrepos_conf_file)
+
+ test_commands["PORTAGE_BINHOST={binhost_uri} emerge -feG dev-libs/A"] = Emerge(
+ "-fe",
+ "--getbinpkgonly",
+ "dev-libs/A",
+ env_mod={"PORTAGE_BINHOST": binhost_uri},
+ preparation=_replace_pkgdir_and_rm_binrepos_conf_file,
+ )
+
+ yield test_commands
+
+
@pytest.fixture()
def simple_command(request, _generate_all_simple_commands):
"""A fixture that provides the commands to perform a baseline
@@ -898,3 +1395,14 @@ def simple_command(request, _generate_all_simple_commands):
improvement if the commands are generated only once..
"""
return _generate_all_simple_commands[request.param]
+
+
+@pytest.fixture()
+def baseline_command(request, _generate_all_baseline_commands):
+ """A fixture that provides the commands to perform a baseline
+ functional test of portage. It uses another fixture, namely
+ ``_generate_all_simple_commands``.
+ Pytest caches the fixtures and there is a little performance
+ improvement if the commands are generated only once..
+ """
+ return _generate_all_baseline_commands[request.param]
diff --git a/lib/portage/tests/emerge/test_simple.py b/lib/portage/tests/emerge/test_simple.py
index c0731dabca..d287aaa159 100644
--- a/lib/portage/tests/emerge/test_simple.py
+++ b/lib/portage/tests/emerge/test_simple.py
@@ -57,13 +57,19 @@ move dev-util/git dev-vcs/git
@pytest.mark.ft
-def test_portage_baseline(async_loop, playground, binhost, simple_command):
+def test_portage_baseline(async_loop, playground, binhost, baseline_command):
async_loop.run_until_complete(
asyncio.ensure_future(
+ # _async_test_baseline(
+ # playground,
+ # binhost,
+ # simple_command,
+ # ),
_async_test_simple(
playground,
binhost,
- simple_command,
+ # simple_command,
+ baseline_command,
loop=async_loop,
),
loop=async_loop,
@@ -71,7 +77,7 @@ def test_portage_baseline(async_loop, playground, binhost, simple_command):
)
-async def _async_test_simple(playground, binhost, command, loop):
+async def _async_test_simple(playground, binhost, commands, loop):
debug = playground.debug
settings = playground.settings
trees = playground.trees
@@ -193,30 +199,155 @@ async def _async_test_simple(playground, binhost, command, loop):
# triggered by python -Wd will be visible.
stdout = subprocess.PIPE
- if hasattr(command, "__call__"):
- command()
- return
+ # # command.prepare()
+ # if hasattr(command, "__call__"):
+ # command()
+ # return
+ for command in commands:
+ if command:
+ command.base_environment = env
+ # if isinstance(command[0], dict):
+ # local_env = env.copy()
+ # local_env.update(command[0])
+ # command = command[1:]
+ # else:
+ # local_env = env
+
+ # with self.subTest(cmd=command, i=idx):
+ proc = await asyncio.create_subprocess_exec(
+ *command(), env=command.env, stderr=None, stdout=stdout
+ )
+
+ # command.cleanup()
+
+ if debug:
+ await proc.wait()
+ else:
+ output, _err = await proc.communicate()
+ await proc.wait()
+ if proc.returncode != os.EX_OK:
+ portage.writemsg(output)
+
+ real_command = command.name
+ args = command.args
+ assert (
+ os.EX_OK == proc.returncode
+ ), f"'{real_command}' failed with args '{args}'"
+ command.check_command_result()
+
+
+async def _async_test_baseline(playground, binhost, baseline_command):
+ debug = playground.debug
+ settings = playground.settings
+ trees = playground.trees
+ eprefix = settings["EPREFIX"]
- if isinstance(command[0], dict):
- local_env = env.copy()
- local_env.update(command[0])
- command = command[1:]
- else:
- local_env = env
+ # test_commands = make_test_commands(settings, trees, binhost["uri"])
- # with self.subTest(cmd=command, i=idx):
- proc = await asyncio.create_subprocess_exec(
- *command, env=local_env, stderr=None, stdout=stdout
- )
+ test_repo_location = settings.repositories["test_repo"].location
+ var_cache_edb = os.path.join(eprefix, "var", "cache", "edb")
+ cachedir = os.path.join(var_cache_edb, "dep")
+ cachedir_pregen = os.path.join(test_repo_location, "metadata", "md5-cache")
- if debug:
- await proc.wait()
+ cross_prefix = os.path.join(eprefix, "cross_prefix")
+ cross_root = os.path.join(eprefix, "cross_root")
+ cross_eroot = os.path.join(cross_root, eprefix.lstrip(os.sep))
+
+ distdir = playground.distdir
+ pkgdir = playground.pkgdir
+ fake_bin = os.path.join(eprefix, "bin")
+ portage_tmpdir = os.path.join(eprefix, "var", "tmp", "portage")
+ profile_path = settings.profile_path
+ user_config_dir = os.path.join(os.sep, eprefix, USER_CONFIG_PATH)
+
+ path = os.environ.get("PATH")
+ if path is not None and not path.strip():
+ path = None
+ if path is None:
+ path = ""
else:
- output, _err = await proc.communicate()
- await proc.wait()
- if proc.returncode != os.EX_OK:
- portage.writemsg(output)
-
- real_command = command[0]
- args = command[1:]
- assert os.EX_OK == proc.returncode, f"'{real_command}' failed with args '{args}'"
+ path = ":" + path
+ path = fake_bin + path
+
+ pythonpath = os.environ.get("PYTHONPATH")
+ if pythonpath is not None and not pythonpath.strip():
+ pythonpath = None
+ if pythonpath is not None and pythonpath.split(":")[0] == PORTAGE_PYM_PATH:
+ pass
+ else:
+ if pythonpath is None:
+ pythonpath = ""
+ else:
+ pythonpath = ":" + pythonpath
+ pythonpath = PORTAGE_PYM_PATH + pythonpath
+
+ env = {
+ "PORTAGE_OVERRIDE_EPREFIX": eprefix,
+ "CLEAN_DELAY": "0",
+ "DISTDIR": distdir,
+ "EMERGE_WARNING_DELAY": "0",
+ "INFODIR": "",
+ "INFOPATH": "",
+ "PATH": path,
+ "PKGDIR": pkgdir,
+ "PORTAGE_INST_GID": str(os.getgid()), # str(portage.data.portage_gid),
+ "PORTAGE_INST_UID": str(os.getuid()), # str(portage.data.portage_uid),
+ "PORTAGE_PYTHON": portage._python_interpreter,
+ "PORTAGE_REPOSITORIES": settings.repositories.config_string(),
+ "PORTAGE_TMPDIR": portage_tmpdir,
+ "PORTAGE_LOGDIR": portage_tmpdir,
+ "PYTHONDONTWRITEBYTECODE": os.environ.get("PYTHONDONTWRITEBYTECODE", ""),
+ "PYTHONPATH": pythonpath,
+ "__PORTAGE_TEST_PATH_OVERRIDE": fake_bin,
+ }
+
+ if "__PORTAGE_TEST_HARDLINK_LOCKS" in os.environ:
+ env["__PORTAGE_TEST_HARDLINK_LOCKS"] = os.environ[
+ "__PORTAGE_TEST_HARDLINK_LOCKS"
+ ]
+
+ updates_dir = os.path.join(test_repo_location, "profiles", "updates")
+ dirs = [
+ cachedir,
+ cachedir_pregen,
+ cross_eroot,
+ cross_prefix,
+ distdir,
+ fake_bin,
+ portage_tmpdir,
+ updates_dir,
+ user_config_dir,
+ var_cache_edb,
+ ]
+ etc_symlinks = ("dispatch-conf.conf", "etc-update.conf")
+ # 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)
+ true_symlinks = ["find", "prepstrip", "sed", "scanelf"]
+ true_binary = find_binary("true")
+ assert true_binary is not None, "true command not found"
+
+ for d in dirs:
+ ensure_dirs(d)
+ for x in true_symlinks:
+ try:
+ os.symlink(true_binary, os.path.join(fake_bin, x))
+ except FileExistsError:
+ pass
+ for x in etc_symlinks:
+ try:
+ os.symlink(os.path.join(cnf_etc_path, x), os.path.join(eprefix, "etc", x))
+ except FileExistsError:
+ pass
+ with open(os.path.join(var_cache_edb, "counter"), "wb") as f:
+ f.write(b"100")
+ # non-empty system set keeps --depclean quiet
+ with open(os.path.join(profile_path, "packages"), "w") as f:
+ f.write("*dev-libs/token-system-pkg")
+ for cp, xml_data in _METADATA_XML_FILES:
+ with open(os.path.join(test_repo_location, cp, "metadata.xml"), "w") as f:
+ f.write(playground.metadata_xml_template % xml_data)
+ with open(os.path.join(updates_dir, "1Q-2010"), "w") as f:
+ f.write(_1Q_2010_UPDATE)
+
+ baseline_command(environment=env)
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/emerge/
@ 2023-10-30 3:14 Sam James
0 siblings, 0 replies; 38+ messages in thread
From: Sam James @ 2023-10-30 3:14 UTC (permalink / raw
To: gentoo-commits
commit: 0f0056a0193abc36be61b45184b6bbc2521d525f
Author: David Palao <david.palao <AT> gmail <DOT> com>
AuthorDate: Fri Sep 15 15:51:54 2023 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Oct 30 03:14:24 2023 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=0f0056a0
tests/emerge: test_simple.py: _async_test_simple: Refactor
Refactor.
Removed parameter from function since it's constant.
Signed-off-by: David Palao <david.palao <AT> gmail.com>
Signed-off-by: Sam James <sam <AT> gentoo.org>
lib/portage/tests/emerge/test_simple.py | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/lib/portage/tests/emerge/test_simple.py b/lib/portage/tests/emerge/test_simple.py
index b13add9122..c0731dabca 100644
--- a/lib/portage/tests/emerge/test_simple.py
+++ b/lib/portage/tests/emerge/test_simple.py
@@ -64,7 +64,6 @@ def test_portage_baseline(async_loop, playground, binhost, simple_command):
playground,
binhost,
simple_command,
- _METADATA_XML_FILES,
loop=async_loop,
),
loop=async_loop,
@@ -72,7 +71,7 @@ def test_portage_baseline(async_loop, playground, binhost, simple_command):
)
-async def _async_test_simple(playground, binhost, command, metadata_xml_files, loop):
+async def _async_test_simple(playground, binhost, command, loop):
debug = playground.debug
settings = playground.settings
trees = playground.trees
@@ -180,7 +179,7 @@ async def _async_test_simple(playground, binhost, command, metadata_xml_files, l
# non-empty system set keeps --depclean quiet
with open(os.path.join(profile_path, "packages"), "w") as f:
f.write("*dev-libs/token-system-pkg")
- for cp, xml_data in metadata_xml_files:
+ for cp, xml_data in _METADATA_XML_FILES:
with open(os.path.join(test_repo_location, cp, "metadata.xml"), "w") as f:
f.write(playground.metadata_xml_template % xml_data)
with open(os.path.join(updates_dir, "1Q-2010"), "w") as f:
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/emerge/
@ 2023-10-30 3:14 Sam James
0 siblings, 0 replies; 38+ messages in thread
From: Sam James @ 2023-10-30 3:14 UTC (permalink / raw
To: gentoo-commits
commit: a9071c3a0f69bb4c886ddb324e890590e6872680
Author: David Palao <david.palao <AT> gmail <DOT> com>
AuthorDate: Fri Jul 7 14:58:00 2023 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Oct 30 03:14:25 2023 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=a9071c3a
pytest: Add some markers: ft, unit and stress
Add some markers: ft, unit and stress. And mark
test_simple.test_simple_emerge with ft, such that those tests can be
triggered with::
pytest -m ft
Signed-off-by: David Palao <david.palao <AT> gmail.com>
Signed-off-by: Sam James <sam <AT> gentoo.org>
lib/portage/tests/emerge/test_simple.py | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/lib/portage/tests/emerge/test_simple.py b/lib/portage/tests/emerge/test_simple.py
index 288cac0f28..f452a84c6b 100644
--- a/lib/portage/tests/emerge/test_simple.py
+++ b/lib/portage/tests/emerge/test_simple.py
@@ -5,6 +5,8 @@ import argparse
import subprocess
import sys
+import pytest
+
import portage
from portage import shutil, os
from portage.const import (
@@ -29,12 +31,19 @@ class BinhostContentMap(Mapping):
self._remote_path = remote_path
self._local_path = local_path
- def __getitem__(self, request_path):
- safe_path = os.path.normpath(request_path)
- if not safe_path.startswith(self._remote_path + "/"):
- raise KeyError(request_path)
- local_path = os.path.join(
- self._local_path, safe_path[len(self._remote_path) + 1 :]
+
+@pytest.mark.ft
+def test_simple_emerge(async_loop, playground, binhost, simple_command):
+ async_loop.run_until_complete(
+ asyncio.ensure_future(
+ _async_test_simple(
+ playground,
+ binhost,
+ simple_command,
+ _METADATA_XML_FILES,
+ loop=async_loop,
+ ),
+ loop=async_loop,
)
try:
with open(local_path, "rb") as f:
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/emerge/
@ 2023-10-30 3:14 Sam James
0 siblings, 0 replies; 38+ messages in thread
From: Sam James @ 2023-10-30 3:14 UTC (permalink / raw
To: gentoo-commits
commit: ae5bb29328d709d1b5e5b9f8c8b3e4083a386716
Author: David Palao <david.palao <AT> gmail <DOT> com>
AuthorDate: Fri Jul 7 16:06:20 2023 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Oct 30 03:14:24 2023 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=ae5bb293
tests/emerge/conftest.py: Add a new fixture.
Add a new fixture. It adds one more layer of indirection to the
``simple_command`` fixture. Quick benchmarks tell that it is
faster due to pytest caching.
Signed-off-by: David Palao <david.palao <AT> gmail.com>
Signed-off-by: Sam James <sam <AT> gentoo.org>
lib/portage/tests/emerge/conftest.py | 30 ++++++++++++++++++++++++------
1 file changed, 24 insertions(+), 6 deletions(-)
diff --git a/lib/portage/tests/emerge/conftest.py b/lib/portage/tests/emerge/conftest.py
index 656ee85726..07895501d4 100644
--- a/lib/portage/tests/emerge/conftest.py
+++ b/lib/portage/tests/emerge/conftest.py
@@ -387,12 +387,19 @@ def binhost(playground, async_loop):
@pytest.fixture()
-def simple_command(playground, binhost, request):
- """A fixture that provides the commands to perform a baseline
- functional test of portage.
+def _generate_all_simple_commands(playground, binhost):
+ """This fixture generates all the commands that
+ ``test_portage_baseline`` will use.
+
+ But, don't use this fixture directly, instead, use the
+ ``simple_command`` fixture. That improves performance a bit due to
+ pytest caching.
- To add a new command, define it in the local ``test_commands`` and
- add its key to the ``_SIMPLE_COMMAND_SEQUENCE``.
+ .. note::
+
+ To add a new command, define it in the local ``test_commands``
+ dict, if not yet defined, and add its key at the correct position
+ in the ``_SIMPLE_COMMAND_SEQUENCE`` list.
"""
settings = playground.settings
eprefix = settings["EPREFIX"]
@@ -822,4 +829,15 @@ def simple_command(playground, binhost, request):
+ ("-fe", "--getbinpkgonly", "dev-libs/A")
)
- return test_commands[request.param]
+ yield test_commands
+
+
+@pytest.fixture()
+def simple_command(request, _generate_all_simple_commands):
+ """A fixture that provides the commands to perform a baseline
+ functional test of portage. It uses another fixture, namely
+ ``_generate_all_simple_commands``.
+ Pytest caches the fixtures and there is a little performance
+ improvement if the commands are generated only once..
+ """
+ return _generate_all_simple_commands[request.param]
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/emerge/
@ 2023-10-30 3:14 Sam James
0 siblings, 0 replies; 38+ messages in thread
From: Sam James @ 2023-10-30 3:14 UTC (permalink / raw
To: gentoo-commits
commit: 7580d33654113b7ac5cda2f381d790b427887836
Author: David Palao <david.palao <AT> gmail <DOT> com>
AuthorDate: Fri Jun 9 14:34:19 2023 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Oct 30 03:14:25 2023 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=7580d336
tests/emerge/test_simple.py: port to pytest
port to pytest. BREAKING CHANGE: This is the first, rudimentary
version of ``test_simple.py`` that works exclusively with pytest.
Signed-off-by: David Palao <david.palao <AT> gmail.com>
Signed-off-by: Sam James <sam <AT> gentoo.org>
lib/portage/tests/emerge/test_simple.py | 962 ++++++++++++++++----------------
1 file changed, 470 insertions(+), 492 deletions(-)
diff --git a/lib/portage/tests/emerge/test_simple.py b/lib/portage/tests/emerge/test_simple.py
index 1cc6457ef1..288cac0f28 100644
--- a/lib/portage/tests/emerge/test_simple.py
+++ b/lib/portage/tests/emerge/test_simple.py
@@ -16,7 +16,7 @@ from portage.const import (
)
from portage.cache.mappings import Mapping
from portage.process import find_binary
-from portage.tests import TestCase
+from portage.tests import cnf_bindir, cnf_sbindir, cnf_etc_path
from portage.tests.resolver.ResolverPlayground import ResolverPlayground
from portage.tests.util.test_socks5 import AsyncHTTPServer
from portage.util import ensure_dirs, find_updated_config_files, shlex_split
@@ -142,13 +142,13 @@ call_has_and_best_version() {
"""
- ebuilds = {
+ _AVAILABLE_EBUILDS = {
"dev-libs/A-1": {
"EAPI": "5",
"IUSE": "+flag",
"KEYWORDS": "x86",
"LICENSE": "GPL-2",
- "MISC_CONTENT": install_something,
+ "MISC_CONTENT": _INSTALL_SOMETHING,
"RDEPEND": "flag? ( dev-libs/B[flag] )",
},
"dev-libs/B-1": {
@@ -156,19 +156,19 @@ call_has_and_best_version() {
"IUSE": "+flag",
"KEYWORDS": "x86",
"LICENSE": "GPL-2",
- "MISC_CONTENT": install_something,
+ "MISC_CONTENT": _INSTALL_SOMETHING,
},
"dev-libs/C-1": {
"EAPI": "7",
"KEYWORDS": "~x86",
"RDEPEND": "dev-libs/D[flag]",
- "MISC_CONTENT": install_something,
+ "MISC_CONTENT": _INSTALL_SOMETHING,
},
"dev-libs/D-1": {
"EAPI": "7",
"KEYWORDS": "~x86",
"IUSE": "flag",
- "MISC_CONTENT": install_something,
+ "MISC_CONTENT": _INSTALL_SOMETHING,
},
"virtual/foo-0": {
"EAPI": "5",
@@ -224,473 +224,452 @@ call_has_and_best_version() {
},
),
)
+ try:
+ with open(local_path, "rb") as f:
+ return f.read()
+ except OSError:
+ raise KeyError(request_path)
- for binpkg_format in SUPPORTED_GENTOO_BINPKG_FORMATS:
- with self.subTest(binpkg_format=binpkg_format):
- print(colorize("HILITE", binpkg_format), end=" ... ")
- sys.stdout.flush()
- playground = ResolverPlayground(
- ebuilds=ebuilds,
- installed=installed,
- debug=debug,
- user_config={
- "make.conf": (f'BINPKG_FORMAT="{binpkg_format}"',),
- },
- )
-
- loop = asyncio._wrap_loop()
- loop.run_until_complete(
- asyncio.ensure_future(
- self._async_test_simple(
- playground, metadata_xml_files, loop=loop
- ),
- loop=loop,
- )
- )
- async def _async_test_simple(self, playground, metadata_xml_files, loop):
- debug = playground.debug
- settings = playground.settings
- eprefix = settings["EPREFIX"]
- eroot = settings["EROOT"]
- trees = playground.trees
- portdb = trees[eroot]["porttree"].dbapi
- test_repo_location = settings.repositories["test_repo"].location
- var_cache_edb = os.path.join(eprefix, "var", "cache", "edb")
- cachedir = os.path.join(var_cache_edb, "dep")
- cachedir_pregen = os.path.join(test_repo_location, "metadata", "md5-cache")
-
- portage_python = portage._python_interpreter
- dispatch_conf_cmd = (
- portage_python,
- "-b",
- "-Wd",
- os.path.join(str(self.sbindir), "dispatch-conf"),
- )
- ebuild_cmd = (
- portage_python,
- "-b",
- "-Wd",
- os.path.join(str(self.bindir), "ebuild"),
- )
- egencache_cmd = (
- portage_python,
- "-b",
- "-Wd",
- os.path.join(str(self.bindir), "egencache"),
- "--repo",
- "test_repo",
- "--repositories-configuration",
- settings.repositories.config_string(),
- )
- emerge_cmd = (
- portage_python,
- "-b",
- "-Wd",
- os.path.join(str(self.bindir), "emerge"),
- )
- emaint_cmd = (
- portage_python,
- "-b",
- "-Wd",
- os.path.join(str(self.sbindir), "emaint"),
- )
- env_update_cmd = (
- portage_python,
- "-b",
- "-Wd",
- os.path.join(str(self.sbindir), "env-update"),
- )
- etc_update_cmd = (BASH_BINARY, os.path.join(str(self.sbindir), "etc-update"))
- fixpackages_cmd = (
- portage_python,
- "-b",
- "-Wd",
- os.path.join(str(self.sbindir), "fixpackages"),
- )
- portageq_cmd = (
- portage_python,
- "-b",
- "-Wd",
- os.path.join(str(self.bindir), "portageq"),
- )
- quickpkg_cmd = (
- portage_python,
- "-b",
- "-Wd",
- os.path.join(str(self.bindir), "quickpkg"),
- )
- regenworld_cmd = (
- portage_python,
- "-b",
- "-Wd",
- os.path.join(str(self.sbindir), "regenworld"),
- )
+def test_simple_emerge():
+ debug = False
- rm_binary = find_binary("rm")
- self.assertEqual(rm_binary is None, False, "rm command not found")
- rm_cmd = (rm_binary,)
-
- egencache_extra_args = []
- if self._have_python_xml():
- egencache_extra_args.append("--update-use-local-desc")
-
- test_ebuild = portdb.findname("dev-libs/A-1")
- self.assertFalse(test_ebuild is None)
-
- cross_prefix = os.path.join(eprefix, "cross_prefix")
- cross_root = os.path.join(eprefix, "cross_root")
- cross_eroot = os.path.join(cross_root, eprefix.lstrip(os.sep))
-
- binhost_dir = os.path.join(eprefix, "binhost")
- binhost_address = "127.0.0.1"
- binhost_remote_path = "/binhost"
- binhost_server = AsyncHTTPServer(
- binhost_address, BinhostContentMap(binhost_remote_path, binhost_dir), loop
- ).__enter__()
- binhost_uri = "http://{address}:{port}{path}".format(
- address=binhost_address,
- port=binhost_server.server_port,
- path=binhost_remote_path,
+ for binpkg_format in SUPPORTED_GENTOO_BINPKG_FORMATS:
+ playground = ResolverPlayground(
+ ebuilds=_AVAILABLE_EBUILDS,
+ installed=_INSTALLED_EBUILDS,
+ debug=debug,
+ user_config={
+ "make.conf": (f'BINPKG_FORMAT="{binpkg_format}"',),
+ },
)
- binpkg_format = settings.get(
- "BINPKG_FORMAT", SUPPORTED_GENTOO_BINPKG_FORMATS[0]
+ loop = asyncio._wrap_loop()
+ loop.run_until_complete(
+ asyncio.ensure_future(
+ _async_test_simple(playground, _METADATA_XML_FILES, loop=loop),
+ loop=loop,
+ )
)
- self.assertIn(binpkg_format, ("xpak", "gpkg"))
- if binpkg_format == "xpak":
- foo_filename = "foo-0-1.xpak"
- elif binpkg_format == "gpkg":
- foo_filename = "foo-0-1.gpkg.tar"
-
- test_commands = ()
- if hasattr(argparse.ArgumentParser, "parse_intermixed_args"):
- test_commands += (
- emerge_cmd + ("--oneshot", "dev-libs/A", "-v", "dev-libs/A"),
- )
- test_commands += (
- emerge_cmd
- + (
- "--usepkgonly",
- "--root",
- cross_root,
- "--quickpkg-direct=y",
- "--quickpkg-direct-root",
- "/",
- "dev-libs/A",
- ),
- emerge_cmd
- + (
- "--usepkgonly",
- "--quickpkg-direct=y",
- "--quickpkg-direct-root",
- cross_root,
- "dev-libs/A",
- ),
- env_update_cmd,
- portageq_cmd
- + (
- "envvar",
- "-v",
- "CONFIG_PROTECT",
- "EROOT",
- "PORTAGE_CONFIGROOT",
- "PORTAGE_TMPDIR",
- "USERLAND",
- ),
- etc_update_cmd,
- dispatch_conf_cmd,
- emerge_cmd + ("--version",),
- emerge_cmd + ("--info",),
- emerge_cmd + ("--info", "--verbose"),
- emerge_cmd + ("--list-sets",),
- emerge_cmd + ("--check-news",),
- rm_cmd + ("-rf", cachedir),
- rm_cmd + ("-rf", cachedir_pregen),
- emerge_cmd + ("--regen",),
- rm_cmd + ("-rf", cachedir),
- ({"FEATURES": "metadata-transfer"},) + emerge_cmd + ("--regen",),
- rm_cmd + ("-rf", cachedir),
- ({"FEATURES": "metadata-transfer"},) + emerge_cmd + ("--regen",),
- rm_cmd + ("-rf", cachedir),
- egencache_cmd + ("--update",) + tuple(egencache_extra_args),
- ({"FEATURES": "metadata-transfer"},) + emerge_cmd + ("--metadata",),
- rm_cmd + ("-rf", cachedir),
- ({"FEATURES": "metadata-transfer"},) + emerge_cmd + ("--metadata",),
- emerge_cmd + ("--metadata",),
- rm_cmd + ("-rf", cachedir),
- emerge_cmd + ("--oneshot", "virtual/foo"),
- lambda: self.assertFalse(
- os.path.exists(os.path.join(pkgdir, "virtual", "foo", foo_filename))
- ),
- ({"FEATURES": "unmerge-backup"},)
- + emerge_cmd
- + ("--unmerge", "virtual/foo"),
- lambda: self.assertTrue(
- os.path.exists(os.path.join(pkgdir, "virtual", "foo", foo_filename))
- ),
- emerge_cmd + ("--pretend", "dev-libs/A"),
- ebuild_cmd + (test_ebuild, "manifest", "clean", "package", "merge"),
- emerge_cmd + ("--pretend", "--tree", "--complete-graph", "dev-libs/A"),
- emerge_cmd + ("-p", "dev-libs/B"),
- emerge_cmd + ("-p", "--newrepo", "dev-libs/B"),
- emerge_cmd
- + (
- "-B",
- "dev-libs/B",
- ),
- emerge_cmd
- + (
- "--oneshot",
- "--usepkg",
- "dev-libs/B",
- ),
- # trigger clean prior to pkg_pretend as in bug #390711
- ebuild_cmd + (test_ebuild, "unpack"),
- emerge_cmd
- + (
- "--oneshot",
- "dev-libs/A",
- ),
- emerge_cmd
- + (
- "--noreplace",
- "dev-libs/A",
- ),
- emerge_cmd
- + (
- "--config",
- "dev-libs/A",
- ),
- emerge_cmd + ("--info", "dev-libs/A", "dev-libs/B"),
- emerge_cmd + ("--pretend", "--depclean", "--verbose", "dev-libs/B"),
- emerge_cmd
- + (
- "--pretend",
- "--depclean",
- ),
- emerge_cmd + ("--depclean",),
- quickpkg_cmd
- + (
- "--include-config",
- "y",
- "dev-libs/A",
- ),
- # Test bug #523684, where a file renamed or removed by the
- # admin forces replacement files to be merged with config
- # protection.
- lambda: self.assertEqual(
- 0,
- len(
- list(
- find_updated_config_files(
- eroot, shlex_split(settings["CONFIG_PROTECT"])
- )
+async def _async_test_simple(playground, metadata_xml_files, loop):
+ debug = playground.debug
+ settings = playground.settings
+ eprefix = settings["EPREFIX"]
+ eroot = settings["EROOT"]
+ trees = playground.trees
+ portdb = trees[eroot]["porttree"].dbapi
+ test_repo_location = settings.repositories["test_repo"].location
+ var_cache_edb = os.path.join(eprefix, "var", "cache", "edb")
+ cachedir = os.path.join(var_cache_edb, "dep")
+ cachedir_pregen = os.path.join(test_repo_location, "metadata", "md5-cache")
+
+ portage_python = portage._python_interpreter
+ dispatch_conf_cmd = (
+ portage_python,
+ "-b",
+ "-Wd",
+ os.path.join(cnf_sbindir, "dispatch-conf"),
+ )
+ ebuild_cmd = (portage_python, "-b", "-Wd", os.path.join(cnf_bindir, "ebuild"))
+ egencache_cmd = (
+ portage_python,
+ "-b",
+ "-Wd",
+ os.path.join(cnf_bindir, "egencache"),
+ "--repo",
+ "test_repo",
+ "--repositories-configuration",
+ settings.repositories.config_string(),
+ )
+ emerge_cmd = (portage_python, "-b", "-Wd", os.path.join(cnf_bindir, "emerge"))
+ emaint_cmd = (portage_python, "-b", "-Wd", os.path.join(cnf_sbindir, "emaint"))
+ env_update_cmd = (
+ portage_python,
+ "-b",
+ "-Wd",
+ os.path.join(cnf_sbindir, "env-update"),
+ )
+ etc_update_cmd = (BASH_BINARY, os.path.join(cnf_sbindir, "etc-update"))
+ fixpackages_cmd = (
+ portage_python,
+ "-b",
+ "-Wd",
+ os.path.join(cnf_sbindir, "fixpackages"),
+ )
+ portageq_cmd = (
+ portage_python,
+ "-b",
+ "-Wd",
+ os.path.join(cnf_bindir, "portageq"),
+ )
+ quickpkg_cmd = (
+ portage_python,
+ "-b",
+ "-Wd",
+ os.path.join(cnf_bindir, "quickpkg"),
+ )
+ regenworld_cmd = (
+ portage_python,
+ "-b",
+ "-Wd",
+ os.path.join(cnf_sbindir, "regenworld"),
+ )
+
+ rm_binary = find_binary("rm")
+ assert rm_binary is not None, "rm command not found"
+ rm_cmd = (rm_binary,)
+
+ egencache_extra_args = []
+ if _have_python_xml():
+ egencache_extra_args.append("--update-use-local-desc")
+
+ test_ebuild = portdb.findname("dev-libs/A-1")
+ assert test_ebuild is not None
+
+ cross_prefix = os.path.join(eprefix, "cross_prefix")
+ cross_root = os.path.join(eprefix, "cross_root")
+ cross_eroot = os.path.join(cross_root, eprefix.lstrip(os.sep))
+
+ binhost_dir = os.path.join(eprefix, "binhost")
+ binhost_address = "127.0.0.1"
+ binhost_remote_path = "/binhost"
+ binhost_server = AsyncHTTPServer(
+ binhost_address, BinhostContentMap(binhost_remote_path, binhost_dir), loop
+ ).__enter__()
+ binhost_uri = "http://{address}:{port}{path}".format(
+ address=binhost_address,
+ port=binhost_server.server_port,
+ path=binhost_remote_path,
+ )
+
+ binpkg_format = settings.get("BINPKG_FORMAT", SUPPORTED_GENTOO_BINPKG_FORMATS[0])
+ assert binpkg_format in ("xpak", "gpkg")
+ if binpkg_format == "xpak":
+ foo_filename = "foo-0-1.xpak"
+ elif binpkg_format == "gpkg":
+ foo_filename = "foo-0-1.gpkg.tar"
+
+ test_commands = ()
+
+ if hasattr(argparse.ArgumentParser, "parse_intermixed_args"):
+ test_commands += (emerge_cmd + ("--oneshot", "dev-libs/A", "-v", "dev-libs/A"),)
+
+ test_commands += (
+ emerge_cmd
+ + (
+ "--usepkgonly",
+ "--root",
+ cross_root,
+ "--quickpkg-direct=y",
+ "--quickpkg-direct-root",
+ "/",
+ "dev-libs/A",
+ ),
+ emerge_cmd
+ + (
+ "--usepkgonly",
+ "--quickpkg-direct=y",
+ "--quickpkg-direct-root",
+ cross_root,
+ "dev-libs/A",
+ ),
+ env_update_cmd,
+ portageq_cmd
+ + (
+ "envvar",
+ "-v",
+ "CONFIG_PROTECT",
+ "EROOT",
+ "PORTAGE_CONFIGROOT",
+ "PORTAGE_TMPDIR",
+ "USERLAND",
+ ),
+ etc_update_cmd,
+ dispatch_conf_cmd,
+ emerge_cmd + ("--version",),
+ emerge_cmd + ("--info",),
+ emerge_cmd + ("--info", "--verbose"),
+ emerge_cmd + ("--list-sets",),
+ emerge_cmd + ("--check-news",),
+ rm_cmd + ("-rf", cachedir),
+ rm_cmd + ("-rf", cachedir_pregen),
+ emerge_cmd + ("--regen",),
+ rm_cmd + ("-rf", cachedir),
+ ({"FEATURES": "metadata-transfer"},) + emerge_cmd + ("--regen",),
+ rm_cmd + ("-rf", cachedir),
+ ({"FEATURES": "metadata-transfer"},) + emerge_cmd + ("--regen",),
+ rm_cmd + ("-rf", cachedir),
+ egencache_cmd + ("--update",) + tuple(egencache_extra_args),
+ ({"FEATURES": "metadata-transfer"},) + emerge_cmd + ("--metadata",),
+ rm_cmd + ("-rf", cachedir),
+ ({"FEATURES": "metadata-transfer"},) + emerge_cmd + ("--metadata",),
+ emerge_cmd + ("--metadata",),
+ rm_cmd + ("-rf", cachedir),
+ emerge_cmd + ("--oneshot", "virtual/foo"),
+ lambda: self.assertFalse(
+ os.path.exists(os.path.join(pkgdir, "virtual", "foo", foo_filename))
+ ),
+ ({"FEATURES": "unmerge-backup"},) + emerge_cmd + ("--unmerge", "virtual/foo"),
+ lambda: self.assertTrue(
+ os.path.exists(os.path.join(pkgdir, "virtual", "foo", foo_filename))
+ ),
+ emerge_cmd + ("--pretend", "dev-libs/A"),
+ ebuild_cmd + (test_ebuild, "manifest", "clean", "package", "merge"),
+ emerge_cmd + ("--pretend", "--tree", "--complete-graph", "dev-libs/A"),
+ emerge_cmd + ("-p", "dev-libs/B"),
+ emerge_cmd + ("-p", "--newrepo", "dev-libs/B"),
+ emerge_cmd
+ + (
+ "-B",
+ "dev-libs/B",
+ ),
+ emerge_cmd
+ + (
+ "--oneshot",
+ "--usepkg",
+ "dev-libs/B",
+ ),
+ # trigger clean prior to pkg_pretend as in bug #390711
+ ebuild_cmd + (test_ebuild, "unpack"),
+ emerge_cmd
+ + (
+ "--oneshot",
+ "dev-libs/A",
+ ),
+ emerge_cmd
+ + (
+ "--noreplace",
+ "dev-libs/A",
+ ),
+ emerge_cmd
+ + (
+ "--config",
+ "dev-libs/A",
+ ),
+ emerge_cmd + ("--info", "dev-libs/A", "dev-libs/B"),
+ emerge_cmd + ("--pretend", "--depclean", "--verbose", "dev-libs/B"),
+ emerge_cmd
+ + (
+ "--pretend",
+ "--depclean",
+ ),
+ emerge_cmd + ("--depclean",),
+ quickpkg_cmd
+ + (
+ "--include-config",
+ "y",
+ "dev-libs/A",
+ ),
+ # Test bug #523684, where a file renamed or removed by the
+ # admin forces replacement files to be merged with config
+ # protection.
+ lambda: self.assertEqual(
+ 0,
+ len(
+ list(
+ find_updated_config_files(
+ eroot, shlex_split(settings["CONFIG_PROTECT"])
)
- ),
+ )
),
- lambda: os.unlink(os.path.join(eprefix, "etc", "A-0")),
- emerge_cmd + ("--usepkgonly", "dev-libs/A"),
- lambda: self.assertEqual(
- 1,
- len(
- list(
- find_updated_config_files(
- eroot, shlex_split(settings["CONFIG_PROTECT"])
- )
+ ),
+ lambda: os.unlink(os.path.join(eprefix, "etc", "A-0")),
+ emerge_cmd + ("--usepkgonly", "dev-libs/A"),
+ lambda: self.assertEqual(
+ 1,
+ len(
+ list(
+ find_updated_config_files(
+ eroot, shlex_split(settings["CONFIG_PROTECT"])
)
- ),
- ),
- emaint_cmd + ("--check", "all"),
- emaint_cmd + ("--fix", "all"),
- fixpackages_cmd,
- regenworld_cmd,
- portageq_cmd + ("match", eroot, "dev-libs/A"),
- portageq_cmd + ("best_visible", eroot, "dev-libs/A"),
- portageq_cmd + ("best_visible", eroot, "binary", "dev-libs/A"),
- portageq_cmd + ("contents", eroot, "dev-libs/A-1"),
- portageq_cmd
- + ("metadata", eroot, "ebuild", "dev-libs/A-1", "EAPI", "IUSE", "RDEPEND"),
- portageq_cmd
- + ("metadata", eroot, "binary", "dev-libs/A-1", "EAPI", "USE", "RDEPEND"),
- portageq_cmd
- + (
- "metadata",
- eroot,
- "installed",
- "dev-libs/A-1",
- "EAPI",
- "USE",
- "RDEPEND",
+ )
),
- portageq_cmd + ("owners", eroot, eroot + "usr"),
- emerge_cmd + ("-p", eroot + "usr"),
- emerge_cmd + ("-p", "--unmerge", "-q", eroot + "usr"),
- emerge_cmd + ("--unmerge", "--quiet", "dev-libs/A"),
- emerge_cmd + ("-C", "--quiet", "dev-libs/B"),
- # If EMERGE_DEFAULT_OPTS contains --autounmask=n, then --autounmask
- # must be specified with --autounmask-continue.
- ({"EMERGE_DEFAULT_OPTS": "--autounmask=n"},)
+ ),
+ emaint_cmd + ("--check", "all"),
+ emaint_cmd + ("--fix", "all"),
+ fixpackages_cmd,
+ regenworld_cmd,
+ portageq_cmd + ("match", eroot, "dev-libs/A"),
+ portageq_cmd + ("best_visible", eroot, "dev-libs/A"),
+ portageq_cmd + ("best_visible", eroot, "binary", "dev-libs/A"),
+ portageq_cmd + ("contents", eroot, "dev-libs/A-1"),
+ portageq_cmd
+ + ("metadata", eroot, "ebuild", "dev-libs/A-1", "EAPI", "IUSE", "RDEPEND"),
+ portageq_cmd
+ + ("metadata", eroot, "binary", "dev-libs/A-1", "EAPI", "USE", "RDEPEND"),
+ portageq_cmd
+ + (
+ "metadata",
+ eroot,
+ "installed",
+ "dev-libs/A-1",
+ "EAPI",
+ "USE",
+ "RDEPEND",
+ ),
+ portageq_cmd + ("owners", eroot, eroot + "usr"),
+ emerge_cmd + ("-p", eroot + "usr"),
+ emerge_cmd + ("-p", "--unmerge", "-q", eroot + "usr"),
+ emerge_cmd + ("--unmerge", "--quiet", "dev-libs/A"),
+ emerge_cmd + ("-C", "--quiet", "dev-libs/B"),
+ # If EMERGE_DEFAULT_OPTS contains --autounmask=n, then --autounmask
+ # must be specified with --autounmask-continue.
+ ({"EMERGE_DEFAULT_OPTS": "--autounmask=n"},)
+ + emerge_cmd
+ + (
+ "--autounmask",
+ "--autounmask-continue",
+ "dev-libs/C",
+ ),
+ # Verify that the above --autounmask-continue command caused
+ # USE=flag to be applied correctly to dev-libs/D.
+ portageq_cmd + ("match", eroot, "dev-libs/D[flag]"),
+ # Test cross-prefix usage, including chpathtool for binpkgs.
+ # EAPI 7
+ ({"EPREFIX": cross_prefix},) + emerge_cmd + ("dev-libs/C",),
+ ({"EPREFIX": cross_prefix},)
+ + portageq_cmd
+ + ("has_version", cross_prefix, "dev-libs/C"),
+ ({"EPREFIX": cross_prefix},)
+ + portageq_cmd
+ + ("has_version", cross_prefix, "dev-libs/D"),
+ ({"ROOT": cross_root},) + emerge_cmd + ("dev-libs/D",),
+ portageq_cmd + ("has_version", cross_eroot, "dev-libs/D"),
+ # EAPI 5
+ ({"EPREFIX": cross_prefix},) + emerge_cmd + ("--usepkgonly", "dev-libs/A"),
+ ({"EPREFIX": cross_prefix},)
+ + portageq_cmd
+ + ("has_version", cross_prefix, "dev-libs/A"),
+ ({"EPREFIX": cross_prefix},)
+ + portageq_cmd
+ + ("has_version", cross_prefix, "dev-libs/B"),
+ ({"EPREFIX": cross_prefix},) + emerge_cmd + ("-C", "--quiet", "dev-libs/B"),
+ ({"EPREFIX": cross_prefix},) + emerge_cmd + ("-C", "--quiet", "dev-libs/A"),
+ ({"EPREFIX": cross_prefix},) + emerge_cmd + ("dev-libs/A",),
+ ({"EPREFIX": cross_prefix},)
+ + portageq_cmd
+ + ("has_version", cross_prefix, "dev-libs/A"),
+ ({"EPREFIX": cross_prefix},)
+ + portageq_cmd
+ + ("has_version", cross_prefix, "dev-libs/B"),
+ # Test ROOT support
+ ({"ROOT": cross_root},) + emerge_cmd + ("dev-libs/B",),
+ portageq_cmd + ("has_version", cross_eroot, "dev-libs/B"),
+ )
+
+ # Test binhost support if FETCHCOMMAND is available.
+ binrepos_conf_file = os.path.join(os.sep, eprefix, BINREPOS_CONF_FILE)
+ with open(binrepos_conf_file, "w") as f:
+ f.write("[test-binhost]\n")
+ f.write(f"sync-uri = {binhost_uri}\n")
+ fetchcommand = portage.util.shlex_split(playground.settings["FETCHCOMMAND"])
+ fetch_bin = portage.process.find_binary(fetchcommand[0])
+ if fetch_bin is not None:
+ test_commands = test_commands + (
+ lambda: os.rename(pkgdir, binhost_dir),
+ emerge_cmd + ("-e", "--getbinpkgonly", "dev-libs/A"),
+ lambda: shutil.rmtree(pkgdir),
+ lambda: os.rename(binhost_dir, pkgdir),
+ # Remove binrepos.conf and test PORTAGE_BINHOST.
+ lambda: os.unlink(binrepos_conf_file),
+ lambda: os.rename(pkgdir, binhost_dir),
+ ({"PORTAGE_BINHOST": binhost_uri},)
+ emerge_cmd
- + (
- "--autounmask",
- "--autounmask-continue",
- "dev-libs/C",
- ),
- # Verify that the above --autounmask-continue command caused
- # USE=flag to be applied correctly to dev-libs/D.
- portageq_cmd + ("match", eroot, "dev-libs/D[flag]"),
- # Test cross-prefix usage, including chpathtool for binpkgs.
- # EAPI 7
- ({"EPREFIX": cross_prefix},) + emerge_cmd + ("dev-libs/C",),
- ({"EPREFIX": cross_prefix},)
- + portageq_cmd
- + ("has_version", cross_prefix, "dev-libs/C"),
- ({"EPREFIX": cross_prefix},)
- + portageq_cmd
- + ("has_version", cross_prefix, "dev-libs/D"),
- ({"ROOT": cross_root},) + emerge_cmd + ("dev-libs/D",),
- portageq_cmd + ("has_version", cross_eroot, "dev-libs/D"),
- # EAPI 5
- ({"EPREFIX": cross_prefix},) + emerge_cmd + ("--usepkgonly", "dev-libs/A"),
- ({"EPREFIX": cross_prefix},)
- + portageq_cmd
- + ("has_version", cross_prefix, "dev-libs/A"),
- ({"EPREFIX": cross_prefix},)
- + portageq_cmd
- + ("has_version", cross_prefix, "dev-libs/B"),
- ({"EPREFIX": cross_prefix},) + emerge_cmd + ("-C", "--quiet", "dev-libs/B"),
- ({"EPREFIX": cross_prefix},) + emerge_cmd + ("-C", "--quiet", "dev-libs/A"),
- ({"EPREFIX": cross_prefix},) + emerge_cmd + ("dev-libs/A",),
- ({"EPREFIX": cross_prefix},)
- + portageq_cmd
- + ("has_version", cross_prefix, "dev-libs/A"),
- ({"EPREFIX": cross_prefix},)
- + portageq_cmd
- + ("has_version", cross_prefix, "dev-libs/B"),
- # Test ROOT support
- ({"ROOT": cross_root},) + emerge_cmd + ("dev-libs/B",),
- portageq_cmd + ("has_version", cross_eroot, "dev-libs/B"),
+ + ("-fe", "--getbinpkgonly", "dev-libs/A"),
+ lambda: shutil.rmtree(pkgdir),
+ lambda: os.rename(binhost_dir, pkgdir),
)
- # Test binhost support if FETCHCOMMAND is available.
- binrepos_conf_file = os.path.join(os.sep, eprefix, BINREPOS_CONF_FILE)
- with open(binrepos_conf_file, "w") as f:
- f.write("[test-binhost]\n")
- f.write(f"sync-uri = {binhost_uri}\n")
- fetchcommand = portage.util.shlex_split(playground.settings["FETCHCOMMAND"])
- fetch_bin = portage.process.find_binary(fetchcommand[0])
- if fetch_bin is not None:
- test_commands = test_commands + (
- lambda: os.rename(pkgdir, binhost_dir),
- emerge_cmd + ("-e", "--getbinpkgonly", "dev-libs/A"),
- lambda: shutil.rmtree(pkgdir),
- lambda: os.rename(binhost_dir, pkgdir),
- # Remove binrepos.conf and test PORTAGE_BINHOST.
- lambda: os.unlink(binrepos_conf_file),
- lambda: os.rename(pkgdir, binhost_dir),
- ({"PORTAGE_BINHOST": binhost_uri},)
- + emerge_cmd
- + ("-fe", "--getbinpkgonly", "dev-libs/A"),
- lambda: shutil.rmtree(pkgdir),
- lambda: os.rename(binhost_dir, pkgdir),
- )
-
- distdir = playground.distdir
- pkgdir = playground.pkgdir
- fake_bin = os.path.join(eprefix, "bin")
- portage_tmpdir = os.path.join(eprefix, "var", "tmp", "portage")
- profile_path = settings.profile_path
- user_config_dir = os.path.join(os.sep, eprefix, USER_CONFIG_PATH)
-
- path = os.environ.get("PATH")
- if path is not None and not path.strip():
- path = None
- if path is None:
- path = ""
+ distdir = playground.distdir
+ pkgdir = playground.pkgdir
+ fake_bin = os.path.join(eprefix, "bin")
+ portage_tmpdir = os.path.join(eprefix, "var", "tmp", "portage")
+ profile_path = settings.profile_path
+ user_config_dir = os.path.join(os.sep, eprefix, USER_CONFIG_PATH)
+
+ path = os.environ.get("PATH")
+ if path is not None and not path.strip():
+ path = None
+ if path is None:
+ path = ""
+ else:
+ path = ":" + path
+ path = fake_bin + path
+
+ pythonpath = os.environ.get("PYTHONPATH")
+ if pythonpath is not None and not pythonpath.strip():
+ pythonpath = None
+ if pythonpath is not None and pythonpath.split(":")[0] == PORTAGE_PYM_PATH:
+ pass
+ else:
+ if pythonpath is None:
+ pythonpath = ""
else:
- path = ":" + path
- path = fake_bin + path
-
- pythonpath = os.environ.get("PYTHONPATH")
- if pythonpath is not None and not pythonpath.strip():
- pythonpath = None
- if pythonpath is not None and pythonpath.split(":")[0] == PORTAGE_PYM_PATH:
- pass
- else:
- if pythonpath is None:
- pythonpath = ""
- else:
- pythonpath = ":" + pythonpath
- pythonpath = PORTAGE_PYM_PATH + pythonpath
-
- env = {
- "PORTAGE_OVERRIDE_EPREFIX": eprefix,
- "CLEAN_DELAY": "0",
- "DISTDIR": distdir,
- "EMERGE_WARNING_DELAY": "0",
- "INFODIR": "",
- "INFOPATH": "",
- "PATH": path,
- "PKGDIR": pkgdir,
- "PORTAGE_INST_GID": str(os.getgid()), # str(portage.data.portage_gid),
- "PORTAGE_INST_UID": str(os.getuid()), # str(portage.data.portage_uid),
- "PORTAGE_PYTHON": portage_python,
- "PORTAGE_REPOSITORIES": settings.repositories.config_string(),
- "PORTAGE_TMPDIR": portage_tmpdir,
- "PORTAGE_LOGDIR": portage_tmpdir,
- "PYTHONDONTWRITEBYTECODE": os.environ.get("PYTHONDONTWRITEBYTECODE", ""),
- "PYTHONPATH": pythonpath,
- "__PORTAGE_TEST_PATH_OVERRIDE": fake_bin,
- }
-
- if "__PORTAGE_TEST_HARDLINK_LOCKS" in os.environ:
- env["__PORTAGE_TEST_HARDLINK_LOCKS"] = os.environ[
- "__PORTAGE_TEST_HARDLINK_LOCKS"
- ]
-
- updates_dir = os.path.join(test_repo_location, "profiles", "updates")
- dirs = [
- cachedir,
- cachedir_pregen,
- cross_eroot,
- cross_prefix,
- distdir,
- fake_bin,
- portage_tmpdir,
- updates_dir,
- user_config_dir,
- var_cache_edb,
+ pythonpath = ":" + pythonpath
+ pythonpath = PORTAGE_PYM_PATH + pythonpath
+
+ env = {
+ "PORTAGE_OVERRIDE_EPREFIX": eprefix,
+ "CLEAN_DELAY": "0",
+ "DISTDIR": distdir,
+ "EMERGE_WARNING_DELAY": "0",
+ "INFODIR": "",
+ "INFOPATH": "",
+ "PATH": path,
+ "PKGDIR": pkgdir,
+ "PORTAGE_INST_GID": str(os.getgid()), # str(portage.data.portage_gid),
+ "PORTAGE_INST_UID": str(os.getuid()), # str(portage.data.portage_uid),
+ "PORTAGE_PYTHON": portage_python,
+ "PORTAGE_REPOSITORIES": settings.repositories.config_string(),
+ "PORTAGE_TMPDIR": portage_tmpdir,
+ "PORTAGE_LOGDIR": portage_tmpdir,
+ "PYTHONDONTWRITEBYTECODE": os.environ.get("PYTHONDONTWRITEBYTECODE", ""),
+ "PYTHONPATH": pythonpath,
+ "__PORTAGE_TEST_PATH_OVERRIDE": fake_bin,
+ }
+
+ if "__PORTAGE_TEST_HARDLINK_LOCKS" in os.environ:
+ env["__PORTAGE_TEST_HARDLINK_LOCKS"] = os.environ[
+ "__PORTAGE_TEST_HARDLINK_LOCKS"
]
- etc_symlinks = ("dispatch-conf.conf", "etc-update.conf")
- # 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)
- true_symlinks = ["find", "prepstrip", "sed", "scanelf"]
- true_binary = find_binary("true")
- self.assertEqual(true_binary is None, False, "true command not found")
- try:
- for d in dirs:
- ensure_dirs(d)
- for x in true_symlinks:
- os.symlink(true_binary, os.path.join(fake_bin, x))
- for x in etc_symlinks:
- os.symlink(
- os.path.join(str(self.cnf_etc_path), x),
- os.path.join(eprefix, "etc", x),
- )
- with open(os.path.join(var_cache_edb, "counter"), "wb") as f:
- f.write(b"100")
- # non-empty system set keeps --depclean quiet
- with open(os.path.join(profile_path, "packages"), "w") as f:
- f.write("*dev-libs/token-system-pkg")
- for cp, xml_data in metadata_xml_files:
- with open(
- os.path.join(test_repo_location, cp, "metadata.xml"), "w"
- ) as f:
- f.write(playground.metadata_xml_template % xml_data)
+
+ updates_dir = os.path.join(test_repo_location, "profiles", "updates")
+ dirs = [
+ cachedir,
+ cachedir_pregen,
+ cross_eroot,
+ cross_prefix,
+ distdir,
+ fake_bin,
+ portage_tmpdir,
+ updates_dir,
+ user_config_dir,
+ var_cache_edb,
+ ]
+ etc_symlinks = ("dispatch-conf.conf", "etc-update.conf")
+ # 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)
+ true_symlinks = ["find", "prepstrip", "sed", "scanelf"]
+ true_binary = find_binary("true")
+ assert true_binary is not None, "true command not found"
+ try:
+ for d in dirs:
+ ensure_dirs(d)
+ for x in true_symlinks:
+ os.symlink(true_binary, os.path.join(fake_bin, x))
+ for x in etc_symlinks:
+ os.symlink(os.path.join(cnf_etc_path, x), os.path.join(eprefix, "etc", x))
+ with open(os.path.join(var_cache_edb, "counter"), "wb") as f:
+ f.write(b"100")
+ # non-empty system set keeps --depclean quiet
+ with open(os.path.join(profile_path, "packages"), "w") as f:
+ f.write("*dev-libs/token-system-pkg")
+ for cp, xml_data in metadata_xml_files:
+ with open(os.path.join(test_repo_location, cp, "metadata.xml"), "w") as f:
+ f.write(playground.metadata_xml_template % xml_data)
with open(os.path.join(updates_dir, "1Q-2010"), "w") as f:
f.write(
"""
@@ -699,42 +678,41 @@ move dev-util/git dev-vcs/git
"""
)
- if debug:
- # The subprocess inherits both stdout and stderr, for
- # debugging purposes.
- stdout = None
+ if debug:
+ # The subprocess inherits both stdout and stderr, for
+ # debugging purposes.
+ stdout = None
+ else:
+ # The subprocess inherits stderr so that any warnings
+ # triggered by python -Wd will be visible.
+ stdout = subprocess.PIPE
+
+ for idx, args in enumerate(test_commands):
+ if hasattr(args, "__call__"):
+ args()
+ continue
+
+ if isinstance(args[0], dict):
+ local_env = env.copy()
+ local_env.update(args[0])
+ args = args[1:]
else:
- # The subprocess inherits stderr so that any warnings
- # triggered by python -Wd will be visible.
- stdout = subprocess.PIPE
-
- for args in test_commands:
- if hasattr(args, "__call__"):
- args()
- continue
-
- if isinstance(args[0], dict):
- local_env = env.copy()
- local_env.update(args[0])
- args = args[1:]
- else:
- local_env = env
-
- proc = await asyncio.create_subprocess_exec(
- *args, env=local_env, stderr=None, stdout=stdout
- )
+ local_env = env
- if debug:
- await proc.wait()
- else:
- output, _err = await proc.communicate()
- await proc.wait()
- if proc.returncode != os.EX_OK:
- portage.writemsg(output)
+ # with self.subTest(cmd=args, i=idx):
+ proc = await asyncio.create_subprocess_exec(
+ *args, env=local_env, stderr=None, stdout=stdout
+ )
- self.assertEqual(
- os.EX_OK, proc.returncode, f"emerge failed with args {args}"
- )
- finally:
- binhost_server.__exit__(None, None, None)
- playground.cleanup()
+ if debug:
+ await proc.wait()
+ else:
+ output, _err = await proc.communicate()
+ await proc.wait()
+ if proc.returncode != os.EX_OK:
+ portage.writemsg(output)
+
+ assert os.EX_OK == proc.returncode, f"emerge failed with args {args}"
+ finally:
+ binhost_server.__exit__(None, None, None)
+ playground.cleanup()
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/emerge/
@ 2023-10-30 3:14 Sam James
0 siblings, 0 replies; 38+ messages in thread
From: Sam James @ 2023-10-30 3:14 UTC (permalink / raw
To: gentoo-commits
commit: 273644d1ee78da50473c7677850eee117ce0983e
Author: David Palao <david.palao <AT> gmail <DOT> com>
AuthorDate: Fri Jul 7 15:32:10 2023 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Oct 30 03:14:23 2023 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=273644d1
tests/emerge: test_simple.py, conftest.py: Add docstrings
Add docstrings. They contain some brief documentation about the tests,
the fixture with the commands and how to select those tests with pytest.
Also the main test function was renamed:
test_simple_emerge -> test_portage_baseline
Signed-off-by: David Palao <david.palao <AT> gmail.com>
Signed-off-by: Sam James <sam <AT> gentoo.org>
lib/portage/tests/emerge/conftest.py | 6 ++++++
lib/portage/tests/emerge/test_simple.py | 20 +++++++++++++++++++-
2 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/lib/portage/tests/emerge/conftest.py b/lib/portage/tests/emerge/conftest.py
index 9cb4691f56..656ee85726 100644
--- a/lib/portage/tests/emerge/conftest.py
+++ b/lib/portage/tests/emerge/conftest.py
@@ -388,6 +388,12 @@ def binhost(playground, async_loop):
@pytest.fixture()
def simple_command(playground, binhost, request):
+ """A fixture that provides the commands to perform a baseline
+ functional test of portage.
+
+ To add a new command, define it in the local ``test_commands`` and
+ add its key to the ``_SIMPLE_COMMAND_SEQUENCE``.
+ """
settings = playground.settings
eprefix = settings["EPREFIX"]
eroot = settings["EROOT"]
diff --git a/lib/portage/tests/emerge/test_simple.py b/lib/portage/tests/emerge/test_simple.py
index 12a16f2d93..b13add9122 100644
--- a/lib/portage/tests/emerge/test_simple.py
+++ b/lib/portage/tests/emerge/test_simple.py
@@ -1,6 +1,24 @@
# Copyright 2011-2021, 2023 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
+"""This module defines a baseline for portage's functionality.
+
+Multiple portage commands are executed in a sequence in a playground
+(see the ``simple_command`` fixture in ``conftest.py``).
+
+All the commands are triggered from the ``test_portage_baseline`` test.
+That test is marked with::
+
+ @pytest.mark.ft
+
+so that it can selected with that marker, i.e.::
+
+ pytest -m ft
+
+``ft`` stands for *functional test*, since that's what it is, a
+functional or end-to-end test.
+"""
+
import subprocess
import pytest
@@ -39,7 +57,7 @@ move dev-util/git dev-vcs/git
@pytest.mark.ft
-def test_simple_emerge(async_loop, playground, binhost, simple_command):
+def test_portage_baseline(async_loop, playground, binhost, simple_command):
async_loop.run_until_complete(
asyncio.ensure_future(
_async_test_simple(
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/emerge/
@ 2023-10-30 3:14 Sam James
0 siblings, 0 replies; 38+ messages in thread
From: Sam James @ 2023-10-30 3:14 UTC (permalink / raw
To: gentoo-commits
commit: e324f300247f4181362325d46a7232f0bbaf561e
Author: David Palao <david.palao <AT> gmail <DOT> com>
AuthorDate: Tue Oct 10 01:36:02 2023 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Oct 30 03:14:25 2023 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=e324f300
tests: Adapt to UTF-8 changes
Adapt to UTF-8 changes in 4f5f6f571e52af6d2703db760bad4e0ad7439d5a.
Signed-off-by: David Palao <david.palao <AT> gmail.com>
Signed-off-by: Sam James <sam <AT> gentoo.org>
lib/portage/tests/emerge/conftest.py | 22 +-
lib/portage/tests/emerge/test_baseline.py | 4 +-
lib/portage/tests/emerge/test_simple.py | 740 ++++++++++++++++++++++++++++++
3 files changed, 754 insertions(+), 12 deletions(-)
diff --git a/lib/portage/tests/emerge/conftest.py b/lib/portage/tests/emerge/conftest.py
index aaa603f731..c534f5e9d3 100644
--- a/lib/portage/tests/emerge/conftest.py
+++ b/lib/portage/tests/emerge/conftest.py
@@ -267,7 +267,7 @@ class PortageCommandSequence:
class Emerge(PortageCommand):
name = "emerge"
- command = (PORTAGE_PYTHON, "-b", "-Wd", os.path.join(cnf_bindir, name))
+ command = (PORTAGE_PYTHON, "-b", "-Wd", os.path.join(str(cnf_bindir), name))
class Noop(PortageCommand):
@@ -276,7 +276,7 @@ class Noop(PortageCommand):
class EnvUpdate(PortageCommand):
name = "env-update"
- command = (PORTAGE_PYTHON, "-b", "-Wd", os.path.join(cnf_sbindir, name))
+ command = (PORTAGE_PYTHON, "-b", "-Wd", os.path.join(str(cnf_sbindir), name))
class DispatchConf(PortageCommand):
@@ -285,13 +285,13 @@ class DispatchConf(PortageCommand):
PORTAGE_PYTHON,
"-b",
"-Wd",
- os.path.join(cnf_sbindir, name),
+ os.path.join(str(cnf_sbindir), name),
)
class Ebuild(PortageCommand):
name = "ebuild"
- command = (PORTAGE_PYTHON, "-b", "-Wd", os.path.join(cnf_bindir, name))
+ command = (PORTAGE_PYTHON, "-b", "-Wd", os.path.join(str(cnf_bindir), name))
class Egencache(PortageCommand):
@@ -300,18 +300,18 @@ class Egencache(PortageCommand):
PORTAGE_PYTHON,
"-b",
"-Wd",
- os.path.join(cnf_bindir, name),
+ os.path.join(str(cnf_bindir), name),
)
class Emaint(PortageCommand):
name = "emaint"
- command = (PORTAGE_PYTHON, "-b", "-Wd", os.path.join(cnf_sbindir, name))
+ command = (PORTAGE_PYTHON, "-b", "-Wd", os.path.join(str(cnf_sbindir), name))
class EtcUpdate(PortageCommand):
name = "etc-update"
- command = (BASH_BINARY, os.path.join(cnf_sbindir, name))
+ command = (BASH_BINARY, os.path.join(str(cnf_sbindir), name))
class Fixpackages(PortageCommand):
@@ -320,7 +320,7 @@ class Fixpackages(PortageCommand):
PORTAGE_PYTHON,
"-b",
"-Wd",
- os.path.join(cnf_sbindir, name),
+ os.path.join(str(cnf_sbindir), name),
)
@@ -330,7 +330,7 @@ class Portageq(PortageCommand):
PORTAGE_PYTHON,
"-b",
"-Wd",
- os.path.join(cnf_bindir, name),
+ os.path.join(str(cnf_bindir), name),
)
@@ -340,7 +340,7 @@ class Quickpkg(PortageCommand):
PORTAGE_PYTHON,
"-b",
"-Wd",
- os.path.join(cnf_bindir, name),
+ os.path.join(str(cnf_bindir), name),
)
@@ -350,7 +350,7 @@ class Regenworld(PortageCommand):
PORTAGE_PYTHON,
"-b",
"-Wd",
- os.path.join(cnf_sbindir, name),
+ os.path.join(str(cnf_sbindir), name),
)
diff --git a/lib/portage/tests/emerge/test_baseline.py b/lib/portage/tests/emerge/test_baseline.py
index 55722d900e..8f44528949 100644
--- a/lib/portage/tests/emerge/test_baseline.py
+++ b/lib/portage/tests/emerge/test_baseline.py
@@ -173,7 +173,9 @@ async def _async_test_baseline(playground, binhost, commands):
pass
for x in etc_symlinks:
try:
- os.symlink(os.path.join(cnf_etc_path, x), os.path.join(eprefix, "etc", x))
+ os.symlink(
+ os.path.join(str(cnf_etc_path), x), os.path.join(eprefix, "etc", x)
+ )
except FileExistsError:
pass
with open(os.path.join(var_cache_edb, "counter"), "wb") as f:
diff --git a/lib/portage/tests/emerge/test_simple.py b/lib/portage/tests/emerge/test_simple.py
new file mode 100644
index 0000000000..1cc6457ef1
--- /dev/null
+++ b/lib/portage/tests/emerge/test_simple.py
@@ -0,0 +1,740 @@
+# Copyright 2011-2021, 2023 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+import argparse
+import subprocess
+import sys
+
+import portage
+from portage import shutil, os
+from portage.const import (
+ BASH_BINARY,
+ BINREPOS_CONF_FILE,
+ PORTAGE_PYM_PATH,
+ USER_CONFIG_PATH,
+ SUPPORTED_GENTOO_BINPKG_FORMATS,
+)
+from portage.cache.mappings import Mapping
+from portage.process import find_binary
+from portage.tests import TestCase
+from portage.tests.resolver.ResolverPlayground import ResolverPlayground
+from portage.tests.util.test_socks5 import AsyncHTTPServer
+from portage.util import ensure_dirs, find_updated_config_files, shlex_split
+from portage.util.futures import asyncio
+from portage.output import colorize
+
+
+class BinhostContentMap(Mapping):
+ def __init__(self, remote_path, local_path):
+ self._remote_path = remote_path
+ self._local_path = local_path
+
+ def __getitem__(self, request_path):
+ safe_path = os.path.normpath(request_path)
+ if not safe_path.startswith(self._remote_path + "/"):
+ raise KeyError(request_path)
+ local_path = os.path.join(
+ self._local_path, safe_path[len(self._remote_path) + 1 :]
+ )
+ try:
+ with open(local_path, "rb") as f:
+ return f.read()
+ except OSError:
+ raise KeyError(request_path)
+
+
+class SimpleEmergeTestCase(TestCase):
+ def _have_python_xml(self):
+ try:
+ __import__("xml.etree.ElementTree")
+ __import__("xml.parsers.expat").parsers.expat.ExpatError
+ except (AttributeError, ImportError):
+ return False
+ return True
+
+ def testSimple(self):
+ debug = False
+
+ install_something = """
+S="${WORKDIR}"
+
+pkg_pretend() {
+ einfo "called pkg_pretend for $CATEGORY/$PF"
+}
+
+src_install() {
+ einfo "installing something..."
+ insinto /usr/lib/${P}
+ echo "blah blah blah" > "${T}"/regular-file
+ doins "${T}"/regular-file
+ dosym regular-file /usr/lib/${P}/symlink || die
+
+ # Test CONFIG_PROTECT
+ insinto /etc
+ newins "${T}"/regular-file ${PN}-${SLOT%/*}
+
+ # Test code for bug #381629, using a copyright symbol encoded with latin-1.
+ # We use $(printf "\\xa9") rather than $'\\xa9', since printf apparently
+ # works in any case, while $'\\xa9' transforms to \\xef\\xbf\\xbd under
+ # some conditions. TODO: Find out why it transforms to \\xef\\xbf\\xbd when
+ # running tests for Python 3.2 (even though it's bash that is ultimately
+ # responsible for performing the transformation).
+ local latin_1_dir=/usr/lib/${P}/latin-1-$(printf "\\xa9")-directory
+ insinto "${latin_1_dir}"
+ echo "blah blah blah" > "${T}"/latin-1-$(printf "\\xa9")-regular-file || die
+ doins "${T}"/latin-1-$(printf "\\xa9")-regular-file
+ dosym latin-1-$(printf "\\xa9")-regular-file ${latin_1_dir}/latin-1-$(printf "\\xa9")-symlink || die
+
+ call_has_and_best_version
+}
+
+pkg_config() {
+ einfo "called pkg_config for $CATEGORY/$PF"
+}
+
+pkg_info() {
+ einfo "called pkg_info for $CATEGORY/$PF"
+}
+
+pkg_preinst() {
+ if ! ___eapi_best_version_and_has_version_support_-b_-d_-r; then
+ # The BROOT variable is unset during pkg_* phases for EAPI 7,
+ # therefore best/has_version -b is expected to fail if we attempt
+ # to call it for EAPI 7 here.
+ call_has_and_best_version
+ fi
+}
+
+call_has_and_best_version() {
+ local root_arg
+ if ___eapi_best_version_and_has_version_support_-b_-d_-r; then
+ root_arg="-b"
+ else
+ root_arg="--host-root"
+ fi
+ einfo "called ${EBUILD_PHASE_FUNC} for $CATEGORY/$PF"
+ einfo "EPREFIX=${EPREFIX}"
+ einfo "PORTAGE_OVERRIDE_EPREFIX=${PORTAGE_OVERRIDE_EPREFIX}"
+ einfo "ROOT=${ROOT}"
+ einfo "EROOT=${EROOT}"
+ einfo "SYSROOT=${SYSROOT}"
+ einfo "ESYSROOT=${ESYSROOT}"
+ einfo "BROOT=${BROOT}"
+ # Test that has_version and best_version work correctly with
+ # prefix (involves internal ROOT -> EROOT calculation in order
+ # to support ROOT override via the environment with EAPIs 3
+ # and later which support prefix).
+ if has_version $CATEGORY/$PN:$SLOT ; then
+ einfo "has_version detects an installed instance of $CATEGORY/$PN:$SLOT"
+ einfo "best_version reports that the installed instance is $(best_version $CATEGORY/$PN:$SLOT)"
+ else
+ einfo "has_version does not detect an installed instance of $CATEGORY/$PN:$SLOT"
+ fi
+ if [[ ${EPREFIX} != ${PORTAGE_OVERRIDE_EPREFIX} ]] ; then
+ if has_version ${root_arg} $CATEGORY/$PN:$SLOT ; then
+ einfo "has_version ${root_arg} detects an installed instance of $CATEGORY/$PN:$SLOT"
+ einfo "best_version ${root_arg} reports that the installed instance is $(best_version ${root_arg} $CATEGORY/$PN:$SLOT)"
+ else
+ einfo "has_version ${root_arg} does not detect an installed instance of $CATEGORY/$PN:$SLOT"
+ fi
+ fi
+}
+
+"""
+
+ ebuilds = {
+ "dev-libs/A-1": {
+ "EAPI": "5",
+ "IUSE": "+flag",
+ "KEYWORDS": "x86",
+ "LICENSE": "GPL-2",
+ "MISC_CONTENT": install_something,
+ "RDEPEND": "flag? ( dev-libs/B[flag] )",
+ },
+ "dev-libs/B-1": {
+ "EAPI": "5",
+ "IUSE": "+flag",
+ "KEYWORDS": "x86",
+ "LICENSE": "GPL-2",
+ "MISC_CONTENT": install_something,
+ },
+ "dev-libs/C-1": {
+ "EAPI": "7",
+ "KEYWORDS": "~x86",
+ "RDEPEND": "dev-libs/D[flag]",
+ "MISC_CONTENT": install_something,
+ },
+ "dev-libs/D-1": {
+ "EAPI": "7",
+ "KEYWORDS": "~x86",
+ "IUSE": "flag",
+ "MISC_CONTENT": install_something,
+ },
+ "virtual/foo-0": {
+ "EAPI": "5",
+ "KEYWORDS": "x86",
+ "LICENSE": "GPL-2",
+ },
+ }
+
+ installed = {
+ "dev-libs/A-1": {
+ "EAPI": "5",
+ "IUSE": "+flag",
+ "KEYWORDS": "x86",
+ "LICENSE": "GPL-2",
+ "RDEPEND": "flag? ( dev-libs/B[flag] )",
+ "USE": "flag",
+ },
+ "dev-libs/B-1": {
+ "EAPI": "5",
+ "IUSE": "+flag",
+ "KEYWORDS": "x86",
+ "LICENSE": "GPL-2",
+ "USE": "flag",
+ },
+ "dev-libs/depclean-me-1": {
+ "EAPI": "5",
+ "IUSE": "",
+ "KEYWORDS": "x86",
+ "LICENSE": "GPL-2",
+ "USE": "",
+ },
+ "app-misc/depclean-me-1": {
+ "EAPI": "5",
+ "IUSE": "",
+ "KEYWORDS": "x86",
+ "LICENSE": "GPL-2",
+ "RDEPEND": "dev-libs/depclean-me",
+ "USE": "",
+ },
+ }
+
+ metadata_xml_files = (
+ (
+ "dev-libs/A",
+ {
+ "flags": "<flag name='flag'>Description of how USE='flag' affects this package</flag>",
+ },
+ ),
+ (
+ "dev-libs/B",
+ {
+ "flags": "<flag name='flag'>Description of how USE='flag' affects this package</flag>",
+ },
+ ),
+ )
+
+ for binpkg_format in SUPPORTED_GENTOO_BINPKG_FORMATS:
+ with self.subTest(binpkg_format=binpkg_format):
+ print(colorize("HILITE", binpkg_format), end=" ... ")
+ sys.stdout.flush()
+ playground = ResolverPlayground(
+ ebuilds=ebuilds,
+ installed=installed,
+ debug=debug,
+ user_config={
+ "make.conf": (f'BINPKG_FORMAT="{binpkg_format}"',),
+ },
+ )
+
+ loop = asyncio._wrap_loop()
+ loop.run_until_complete(
+ asyncio.ensure_future(
+ self._async_test_simple(
+ playground, metadata_xml_files, loop=loop
+ ),
+ loop=loop,
+ )
+ )
+
+ async def _async_test_simple(self, playground, metadata_xml_files, loop):
+ debug = playground.debug
+ settings = playground.settings
+ eprefix = settings["EPREFIX"]
+ eroot = settings["EROOT"]
+ trees = playground.trees
+ portdb = trees[eroot]["porttree"].dbapi
+ test_repo_location = settings.repositories["test_repo"].location
+ var_cache_edb = os.path.join(eprefix, "var", "cache", "edb")
+ cachedir = os.path.join(var_cache_edb, "dep")
+ cachedir_pregen = os.path.join(test_repo_location, "metadata", "md5-cache")
+
+ portage_python = portage._python_interpreter
+ dispatch_conf_cmd = (
+ portage_python,
+ "-b",
+ "-Wd",
+ os.path.join(str(self.sbindir), "dispatch-conf"),
+ )
+ ebuild_cmd = (
+ portage_python,
+ "-b",
+ "-Wd",
+ os.path.join(str(self.bindir), "ebuild"),
+ )
+ egencache_cmd = (
+ portage_python,
+ "-b",
+ "-Wd",
+ os.path.join(str(self.bindir), "egencache"),
+ "--repo",
+ "test_repo",
+ "--repositories-configuration",
+ settings.repositories.config_string(),
+ )
+ emerge_cmd = (
+ portage_python,
+ "-b",
+ "-Wd",
+ os.path.join(str(self.bindir), "emerge"),
+ )
+ emaint_cmd = (
+ portage_python,
+ "-b",
+ "-Wd",
+ os.path.join(str(self.sbindir), "emaint"),
+ )
+ env_update_cmd = (
+ portage_python,
+ "-b",
+ "-Wd",
+ os.path.join(str(self.sbindir), "env-update"),
+ )
+ etc_update_cmd = (BASH_BINARY, os.path.join(str(self.sbindir), "etc-update"))
+ fixpackages_cmd = (
+ portage_python,
+ "-b",
+ "-Wd",
+ os.path.join(str(self.sbindir), "fixpackages"),
+ )
+ portageq_cmd = (
+ portage_python,
+ "-b",
+ "-Wd",
+ os.path.join(str(self.bindir), "portageq"),
+ )
+ quickpkg_cmd = (
+ portage_python,
+ "-b",
+ "-Wd",
+ os.path.join(str(self.bindir), "quickpkg"),
+ )
+ regenworld_cmd = (
+ portage_python,
+ "-b",
+ "-Wd",
+ os.path.join(str(self.sbindir), "regenworld"),
+ )
+
+ rm_binary = find_binary("rm")
+ self.assertEqual(rm_binary is None, False, "rm command not found")
+ rm_cmd = (rm_binary,)
+
+ egencache_extra_args = []
+ if self._have_python_xml():
+ egencache_extra_args.append("--update-use-local-desc")
+
+ test_ebuild = portdb.findname("dev-libs/A-1")
+ self.assertFalse(test_ebuild is None)
+
+ cross_prefix = os.path.join(eprefix, "cross_prefix")
+ cross_root = os.path.join(eprefix, "cross_root")
+ cross_eroot = os.path.join(cross_root, eprefix.lstrip(os.sep))
+
+ binhost_dir = os.path.join(eprefix, "binhost")
+ binhost_address = "127.0.0.1"
+ binhost_remote_path = "/binhost"
+ binhost_server = AsyncHTTPServer(
+ binhost_address, BinhostContentMap(binhost_remote_path, binhost_dir), loop
+ ).__enter__()
+ binhost_uri = "http://{address}:{port}{path}".format(
+ address=binhost_address,
+ port=binhost_server.server_port,
+ path=binhost_remote_path,
+ )
+
+ binpkg_format = settings.get(
+ "BINPKG_FORMAT", SUPPORTED_GENTOO_BINPKG_FORMATS[0]
+ )
+ self.assertIn(binpkg_format, ("xpak", "gpkg"))
+ if binpkg_format == "xpak":
+ foo_filename = "foo-0-1.xpak"
+ elif binpkg_format == "gpkg":
+ foo_filename = "foo-0-1.gpkg.tar"
+
+ test_commands = ()
+
+ if hasattr(argparse.ArgumentParser, "parse_intermixed_args"):
+ test_commands += (
+ emerge_cmd + ("--oneshot", "dev-libs/A", "-v", "dev-libs/A"),
+ )
+
+ test_commands += (
+ emerge_cmd
+ + (
+ "--usepkgonly",
+ "--root",
+ cross_root,
+ "--quickpkg-direct=y",
+ "--quickpkg-direct-root",
+ "/",
+ "dev-libs/A",
+ ),
+ emerge_cmd
+ + (
+ "--usepkgonly",
+ "--quickpkg-direct=y",
+ "--quickpkg-direct-root",
+ cross_root,
+ "dev-libs/A",
+ ),
+ env_update_cmd,
+ portageq_cmd
+ + (
+ "envvar",
+ "-v",
+ "CONFIG_PROTECT",
+ "EROOT",
+ "PORTAGE_CONFIGROOT",
+ "PORTAGE_TMPDIR",
+ "USERLAND",
+ ),
+ etc_update_cmd,
+ dispatch_conf_cmd,
+ emerge_cmd + ("--version",),
+ emerge_cmd + ("--info",),
+ emerge_cmd + ("--info", "--verbose"),
+ emerge_cmd + ("--list-sets",),
+ emerge_cmd + ("--check-news",),
+ rm_cmd + ("-rf", cachedir),
+ rm_cmd + ("-rf", cachedir_pregen),
+ emerge_cmd + ("--regen",),
+ rm_cmd + ("-rf", cachedir),
+ ({"FEATURES": "metadata-transfer"},) + emerge_cmd + ("--regen",),
+ rm_cmd + ("-rf", cachedir),
+ ({"FEATURES": "metadata-transfer"},) + emerge_cmd + ("--regen",),
+ rm_cmd + ("-rf", cachedir),
+ egencache_cmd + ("--update",) + tuple(egencache_extra_args),
+ ({"FEATURES": "metadata-transfer"},) + emerge_cmd + ("--metadata",),
+ rm_cmd + ("-rf", cachedir),
+ ({"FEATURES": "metadata-transfer"},) + emerge_cmd + ("--metadata",),
+ emerge_cmd + ("--metadata",),
+ rm_cmd + ("-rf", cachedir),
+ emerge_cmd + ("--oneshot", "virtual/foo"),
+ lambda: self.assertFalse(
+ os.path.exists(os.path.join(pkgdir, "virtual", "foo", foo_filename))
+ ),
+ ({"FEATURES": "unmerge-backup"},)
+ + emerge_cmd
+ + ("--unmerge", "virtual/foo"),
+ lambda: self.assertTrue(
+ os.path.exists(os.path.join(pkgdir, "virtual", "foo", foo_filename))
+ ),
+ emerge_cmd + ("--pretend", "dev-libs/A"),
+ ebuild_cmd + (test_ebuild, "manifest", "clean", "package", "merge"),
+ emerge_cmd + ("--pretend", "--tree", "--complete-graph", "dev-libs/A"),
+ emerge_cmd + ("-p", "dev-libs/B"),
+ emerge_cmd + ("-p", "--newrepo", "dev-libs/B"),
+ emerge_cmd
+ + (
+ "-B",
+ "dev-libs/B",
+ ),
+ emerge_cmd
+ + (
+ "--oneshot",
+ "--usepkg",
+ "dev-libs/B",
+ ),
+ # trigger clean prior to pkg_pretend as in bug #390711
+ ebuild_cmd + (test_ebuild, "unpack"),
+ emerge_cmd
+ + (
+ "--oneshot",
+ "dev-libs/A",
+ ),
+ emerge_cmd
+ + (
+ "--noreplace",
+ "dev-libs/A",
+ ),
+ emerge_cmd
+ + (
+ "--config",
+ "dev-libs/A",
+ ),
+ emerge_cmd + ("--info", "dev-libs/A", "dev-libs/B"),
+ emerge_cmd + ("--pretend", "--depclean", "--verbose", "dev-libs/B"),
+ emerge_cmd
+ + (
+ "--pretend",
+ "--depclean",
+ ),
+ emerge_cmd + ("--depclean",),
+ quickpkg_cmd
+ + (
+ "--include-config",
+ "y",
+ "dev-libs/A",
+ ),
+ # Test bug #523684, where a file renamed or removed by the
+ # admin forces replacement files to be merged with config
+ # protection.
+ lambda: self.assertEqual(
+ 0,
+ len(
+ list(
+ find_updated_config_files(
+ eroot, shlex_split(settings["CONFIG_PROTECT"])
+ )
+ )
+ ),
+ ),
+ lambda: os.unlink(os.path.join(eprefix, "etc", "A-0")),
+ emerge_cmd + ("--usepkgonly", "dev-libs/A"),
+ lambda: self.assertEqual(
+ 1,
+ len(
+ list(
+ find_updated_config_files(
+ eroot, shlex_split(settings["CONFIG_PROTECT"])
+ )
+ )
+ ),
+ ),
+ emaint_cmd + ("--check", "all"),
+ emaint_cmd + ("--fix", "all"),
+ fixpackages_cmd,
+ regenworld_cmd,
+ portageq_cmd + ("match", eroot, "dev-libs/A"),
+ portageq_cmd + ("best_visible", eroot, "dev-libs/A"),
+ portageq_cmd + ("best_visible", eroot, "binary", "dev-libs/A"),
+ portageq_cmd + ("contents", eroot, "dev-libs/A-1"),
+ portageq_cmd
+ + ("metadata", eroot, "ebuild", "dev-libs/A-1", "EAPI", "IUSE", "RDEPEND"),
+ portageq_cmd
+ + ("metadata", eroot, "binary", "dev-libs/A-1", "EAPI", "USE", "RDEPEND"),
+ portageq_cmd
+ + (
+ "metadata",
+ eroot,
+ "installed",
+ "dev-libs/A-1",
+ "EAPI",
+ "USE",
+ "RDEPEND",
+ ),
+ portageq_cmd + ("owners", eroot, eroot + "usr"),
+ emerge_cmd + ("-p", eroot + "usr"),
+ emerge_cmd + ("-p", "--unmerge", "-q", eroot + "usr"),
+ emerge_cmd + ("--unmerge", "--quiet", "dev-libs/A"),
+ emerge_cmd + ("-C", "--quiet", "dev-libs/B"),
+ # If EMERGE_DEFAULT_OPTS contains --autounmask=n, then --autounmask
+ # must be specified with --autounmask-continue.
+ ({"EMERGE_DEFAULT_OPTS": "--autounmask=n"},)
+ + emerge_cmd
+ + (
+ "--autounmask",
+ "--autounmask-continue",
+ "dev-libs/C",
+ ),
+ # Verify that the above --autounmask-continue command caused
+ # USE=flag to be applied correctly to dev-libs/D.
+ portageq_cmd + ("match", eroot, "dev-libs/D[flag]"),
+ # Test cross-prefix usage, including chpathtool for binpkgs.
+ # EAPI 7
+ ({"EPREFIX": cross_prefix},) + emerge_cmd + ("dev-libs/C",),
+ ({"EPREFIX": cross_prefix},)
+ + portageq_cmd
+ + ("has_version", cross_prefix, "dev-libs/C"),
+ ({"EPREFIX": cross_prefix},)
+ + portageq_cmd
+ + ("has_version", cross_prefix, "dev-libs/D"),
+ ({"ROOT": cross_root},) + emerge_cmd + ("dev-libs/D",),
+ portageq_cmd + ("has_version", cross_eroot, "dev-libs/D"),
+ # EAPI 5
+ ({"EPREFIX": cross_prefix},) + emerge_cmd + ("--usepkgonly", "dev-libs/A"),
+ ({"EPREFIX": cross_prefix},)
+ + portageq_cmd
+ + ("has_version", cross_prefix, "dev-libs/A"),
+ ({"EPREFIX": cross_prefix},)
+ + portageq_cmd
+ + ("has_version", cross_prefix, "dev-libs/B"),
+ ({"EPREFIX": cross_prefix},) + emerge_cmd + ("-C", "--quiet", "dev-libs/B"),
+ ({"EPREFIX": cross_prefix},) + emerge_cmd + ("-C", "--quiet", "dev-libs/A"),
+ ({"EPREFIX": cross_prefix},) + emerge_cmd + ("dev-libs/A",),
+ ({"EPREFIX": cross_prefix},)
+ + portageq_cmd
+ + ("has_version", cross_prefix, "dev-libs/A"),
+ ({"EPREFIX": cross_prefix},)
+ + portageq_cmd
+ + ("has_version", cross_prefix, "dev-libs/B"),
+ # Test ROOT support
+ ({"ROOT": cross_root},) + emerge_cmd + ("dev-libs/B",),
+ portageq_cmd + ("has_version", cross_eroot, "dev-libs/B"),
+ )
+
+ # Test binhost support if FETCHCOMMAND is available.
+ binrepos_conf_file = os.path.join(os.sep, eprefix, BINREPOS_CONF_FILE)
+ with open(binrepos_conf_file, "w") as f:
+ f.write("[test-binhost]\n")
+ f.write(f"sync-uri = {binhost_uri}\n")
+ fetchcommand = portage.util.shlex_split(playground.settings["FETCHCOMMAND"])
+ fetch_bin = portage.process.find_binary(fetchcommand[0])
+ if fetch_bin is not None:
+ test_commands = test_commands + (
+ lambda: os.rename(pkgdir, binhost_dir),
+ emerge_cmd + ("-e", "--getbinpkgonly", "dev-libs/A"),
+ lambda: shutil.rmtree(pkgdir),
+ lambda: os.rename(binhost_dir, pkgdir),
+ # Remove binrepos.conf and test PORTAGE_BINHOST.
+ lambda: os.unlink(binrepos_conf_file),
+ lambda: os.rename(pkgdir, binhost_dir),
+ ({"PORTAGE_BINHOST": binhost_uri},)
+ + emerge_cmd
+ + ("-fe", "--getbinpkgonly", "dev-libs/A"),
+ lambda: shutil.rmtree(pkgdir),
+ lambda: os.rename(binhost_dir, pkgdir),
+ )
+
+ distdir = playground.distdir
+ pkgdir = playground.pkgdir
+ fake_bin = os.path.join(eprefix, "bin")
+ portage_tmpdir = os.path.join(eprefix, "var", "tmp", "portage")
+ profile_path = settings.profile_path
+ user_config_dir = os.path.join(os.sep, eprefix, USER_CONFIG_PATH)
+
+ path = os.environ.get("PATH")
+ if path is not None and not path.strip():
+ path = None
+ if path is None:
+ path = ""
+ else:
+ path = ":" + path
+ path = fake_bin + path
+
+ pythonpath = os.environ.get("PYTHONPATH")
+ if pythonpath is not None and not pythonpath.strip():
+ pythonpath = None
+ if pythonpath is not None and pythonpath.split(":")[0] == PORTAGE_PYM_PATH:
+ pass
+ else:
+ if pythonpath is None:
+ pythonpath = ""
+ else:
+ pythonpath = ":" + pythonpath
+ pythonpath = PORTAGE_PYM_PATH + pythonpath
+
+ env = {
+ "PORTAGE_OVERRIDE_EPREFIX": eprefix,
+ "CLEAN_DELAY": "0",
+ "DISTDIR": distdir,
+ "EMERGE_WARNING_DELAY": "0",
+ "INFODIR": "",
+ "INFOPATH": "",
+ "PATH": path,
+ "PKGDIR": pkgdir,
+ "PORTAGE_INST_GID": str(os.getgid()), # str(portage.data.portage_gid),
+ "PORTAGE_INST_UID": str(os.getuid()), # str(portage.data.portage_uid),
+ "PORTAGE_PYTHON": portage_python,
+ "PORTAGE_REPOSITORIES": settings.repositories.config_string(),
+ "PORTAGE_TMPDIR": portage_tmpdir,
+ "PORTAGE_LOGDIR": portage_tmpdir,
+ "PYTHONDONTWRITEBYTECODE": os.environ.get("PYTHONDONTWRITEBYTECODE", ""),
+ "PYTHONPATH": pythonpath,
+ "__PORTAGE_TEST_PATH_OVERRIDE": fake_bin,
+ }
+
+ if "__PORTAGE_TEST_HARDLINK_LOCKS" in os.environ:
+ env["__PORTAGE_TEST_HARDLINK_LOCKS"] = os.environ[
+ "__PORTAGE_TEST_HARDLINK_LOCKS"
+ ]
+
+ updates_dir = os.path.join(test_repo_location, "profiles", "updates")
+ dirs = [
+ cachedir,
+ cachedir_pregen,
+ cross_eroot,
+ cross_prefix,
+ distdir,
+ fake_bin,
+ portage_tmpdir,
+ updates_dir,
+ user_config_dir,
+ var_cache_edb,
+ ]
+ etc_symlinks = ("dispatch-conf.conf", "etc-update.conf")
+ # 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)
+ true_symlinks = ["find", "prepstrip", "sed", "scanelf"]
+ true_binary = find_binary("true")
+ self.assertEqual(true_binary is None, False, "true command not found")
+ try:
+ for d in dirs:
+ ensure_dirs(d)
+ for x in true_symlinks:
+ os.symlink(true_binary, os.path.join(fake_bin, x))
+ for x in etc_symlinks:
+ os.symlink(
+ os.path.join(str(self.cnf_etc_path), x),
+ os.path.join(eprefix, "etc", x),
+ )
+ with open(os.path.join(var_cache_edb, "counter"), "wb") as f:
+ f.write(b"100")
+ # non-empty system set keeps --depclean quiet
+ with open(os.path.join(profile_path, "packages"), "w") as f:
+ f.write("*dev-libs/token-system-pkg")
+ for cp, xml_data in metadata_xml_files:
+ with open(
+ os.path.join(test_repo_location, cp, "metadata.xml"), "w"
+ ) as f:
+ f.write(playground.metadata_xml_template % xml_data)
+ with open(os.path.join(updates_dir, "1Q-2010"), "w") as f:
+ f.write(
+ """
+slotmove =app-doc/pms-3 2 3
+move dev-util/git dev-vcs/git
+"""
+ )
+
+ if debug:
+ # The subprocess inherits both stdout and stderr, for
+ # debugging purposes.
+ stdout = None
+ else:
+ # The subprocess inherits stderr so that any warnings
+ # triggered by python -Wd will be visible.
+ stdout = subprocess.PIPE
+
+ for args in test_commands:
+ if hasattr(args, "__call__"):
+ args()
+ continue
+
+ if isinstance(args[0], dict):
+ local_env = env.copy()
+ local_env.update(args[0])
+ args = args[1:]
+ else:
+ local_env = env
+
+ proc = await asyncio.create_subprocess_exec(
+ *args, env=local_env, stderr=None, stdout=stdout
+ )
+
+ if debug:
+ await proc.wait()
+ else:
+ output, _err = await proc.communicate()
+ await proc.wait()
+ if proc.returncode != os.EX_OK:
+ portage.writemsg(output)
+
+ self.assertEqual(
+ os.EX_OK, proc.returncode, f"emerge failed with args {args}"
+ )
+ finally:
+ binhost_server.__exit__(None, None, None)
+ playground.cleanup()
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/emerge/
@ 2023-10-30 3:14 Sam James
0 siblings, 0 replies; 38+ messages in thread
From: Sam James @ 2023-10-30 3:14 UTC (permalink / raw
To: gentoo-commits
commit: b6a5a31808f2f5548e3699184bd20d110ae77ee1
Author: David Palao <david.palao <AT> gmail <DOT> com>
AuthorDate: Fri Sep 29 15:26:46 2023 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Oct 30 03:14:24 2023 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=b6a5a318
tests/emerge: test_simple.py, conftest.py: Refactor
Refactor.
Removed some dead code.
Signed-off-by: David Palao <david.palao <AT> gmail.com>
Signed-off-by: Sam James <sam <AT> gentoo.org>
lib/portage/tests/emerge/conftest.py | 458 +-------------------------------
lib/portage/tests/emerge/test_simple.py | 139 +---------
2 files changed, 13 insertions(+), 584 deletions(-)
diff --git a/lib/portage/tests/emerge/conftest.py b/lib/portage/tests/emerge/conftest.py
index 5bf535cdcf..43fde441fd 100644
--- a/lib/portage/tests/emerge/conftest.py
+++ b/lib/portage/tests/emerge/conftest.py
@@ -178,7 +178,7 @@ _INSTALLED_EBUILDS = {
},
}
-_SIMPLE_COMMAND_FETCHCOMMAND_SEQUENCE = [
+_BASELINE_COMMAND_FETCHCOMMAND_SEQUENCE = [
# "mv {pkgdir} {binhost_dir}",
"emerge -eG dev-libs/A",
# "rm -R {pkgdir}",
@@ -190,7 +190,7 @@ _SIMPLE_COMMAND_FETCHCOMMAND_SEQUENCE = [
# "mv {binhost_dir} {pkgdir}",
]
-_SIMPLE_COMMAND_SEQUENCE = [
+_BASELINE_COMMAND_SEQUENCE = [
"emerge -1 dev-libs/A -v dev-libs/B",
"emerge --root --quickpkg-direct-root",
"emerge --quickpkg-direct-root",
@@ -277,14 +277,14 @@ _SIMPLE_COMMAND_SEQUENCE = [
"EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/B",
"ROOT={cross_root} emerge dev-libs/B",
"portageq has_version {cross_eroot} dev-libs/B",
-] + _SIMPLE_COMMAND_FETCHCOMMAND_SEQUENCE
+] + _BASELINE_COMMAND_FETCHCOMMAND_SEQUENCE
PORTAGE_PYTHON = portage._python_interpreter
NOOP = lambda: ...
class PortageCommand:
- """A class that represents a simple test case command,
+ """A class that represents a baseline test case command,
including handling of environment and one-use arguments.
"""
@@ -429,15 +429,10 @@ class Regenworld(PortageCommand):
)
-class Rm(PortageCommand):
- name = "rm"
- command = (find_binary(name),)
-
-
def pytest_generate_tests(metafunc):
if "baseline_command" in metafunc.fixturenames:
metafunc.parametrize(
- "baseline_command", _SIMPLE_COMMAND_SEQUENCE, indirect=True
+ "baseline_command", _BASELINE_COMMAND_SEQUENCE, indirect=True
)
@@ -523,414 +518,6 @@ def binhost(playground, async_loop):
binhost_server.__exit__(None, None, None)
-@pytest.fixture()
-def _generate_all_simple_commands(
- playground,
- binhost,
- emerge,
- env_update,
- portageq,
- etc_update,
- dispatch_conf,
- ebuild,
- egencache,
- emaint,
- fixpackages,
- quickpkg,
- regenworld,
-):
- """This fixture generates all the commands that
- ``test_portage_baseline`` will use.
-
- But, don't use this fixture directly, instead, use the
- ``simple_command`` fixture. That improves performance a bit due to
- pytest caching.
-
- .. note::
-
- To add a new command, define it in the local ``test_commands``
- dict, if not yet defined, and add its key at the correct position
- in the ``_SIMPLE_COMMAND_SEQUENCE`` list.
- """
- settings = playground.settings
- eprefix = settings["EPREFIX"]
- eroot = settings["EROOT"]
- trees = playground.trees
- pkgdir = playground.pkgdir
- portdb = trees[eroot]["porttree"].dbapi
- test_repo_location = settings.repositories["test_repo"].location
- var_cache_edb = os.path.join(eprefix, "var", "cache", "edb")
- cachedir = os.path.join(var_cache_edb, "dep")
- cachedir_pregen = os.path.join(test_repo_location, "metadata", "md5-cache")
-
- rm_binary = find_binary("rm")
- assert rm_binary is not None, "rm command not found"
- rm_cmd = (rm_binary,)
-
- egencache_extra_args = []
- if _have_python_xml():
- egencache_extra_args.append("--update-use-local-desc")
-
- test_ebuild = portdb.findname("dev-libs/A-1")
- assert test_ebuild is not None
-
- cross_prefix = os.path.join(eprefix, "cross_prefix")
- cross_root = os.path.join(eprefix, "cross_root")
- cross_eroot = os.path.join(cross_root, eprefix.lstrip(os.sep))
-
- binpkg_format = settings.get("BINPKG_FORMAT", SUPPORTED_GENTOO_BINPKG_FORMATS[0])
- assert binpkg_format in ("xpak", "gpkg")
- if binpkg_format == "xpak":
- foo_filename = "foo-0-1.xpak"
- elif binpkg_format == "gpkg":
- foo_filename = "foo-0-1.gpkg.tar"
-
- test_commands = {}
-
- if hasattr(argparse.ArgumentParser, "parse_intermixed_args"):
- parse_intermixed_command = emerge + (
- "--oneshot",
- "dev-libs/A",
- "-v",
- "dev-libs/A",
- )
- else:
- parse_intermixed_command = NOOP
- test_commands["emerge -1 dev-libs/A -v dev-libs/B"] = parse_intermixed_command
-
- test_commands["emerge --root --quickpkg-direct-root"] = emerge + (
- "--usepkgonly",
- "--root",
- cross_root,
- "--quickpkg-direct=y",
- "--quickpkg-direct-root",
- "/",
- "dev-libs/A",
- )
- test_commands["emerge --quickpkg-direct-root"] = emerge + (
- "--usepkgonly",
- "--quickpkg-direct=y",
- "--quickpkg-direct-root",
- cross_root,
- "dev-libs/A",
- )
- test_commands["env-update"] = env_update
- test_commands["portageq envvar"] = portageq + (
- "envvar",
- "-v",
- "CONFIG_PROTECT",
- "EROOT",
- "PORTAGE_CONFIGROOT",
- "PORTAGE_TMPDIR",
- "USERLAND",
- )
- test_commands["etc-update"] = etc_update
- test_commands["dispatch-conf"] = dispatch_conf
- test_commands["emerge --version"] = emerge + ("--version",)
- test_commands["emerge --info"] = emerge + ("--info",)
- test_commands["emerge --info --verbose"] = emerge + ("--info", "--verbose")
- test_commands["emerge --list-sets"] = emerge + ("--list-sets",)
- test_commands["emerge --check-news"] = emerge + ("--check-news",)
- test_commands["rm -rf {cachedir}"] = rm_cmd + ("-rf", cachedir)
- test_commands["rm -rf {cachedir_pregen}"] = rm_cmd + ("-rf", cachedir_pregen)
- test_commands["emerge --regen"] = emerge + ("--regen",)
- test_commands["FEATURES=metadata-transfer emerge --regen"] = (
- ({"FEATURES": "metadata-transfer"},) + emerge + ("--regen",)
- )
- test_commands["egencache --update"] = (
- egencache + ("--update",) + tuple(egencache_extra_args)
- )
- test_commands["FEATURES=metadata-transfer emerge --metadata"] = (
- ({"FEATURES": "metadata-transfer"},) + emerge + ("--metadata",)
- )
- test_commands["emerge --metadata"] = emerge + ("--metadata",)
-
- test_commands["emerge --oneshot virtual/foo"] = emerge + (
- "--oneshot",
- "virtual/foo",
- )
- test_commands["foo pkg missing"] = lambda: _check_foo_file(
- pkgdir, foo_filename, must_exist=False
- )
-
- test_commands["FEATURES=unmerge-backup emerge --unmerge virtual/foo"] = (
- ({"FEATURES": "unmerge-backup"},) + emerge + ("--unmerge", "virtual/foo")
- )
- test_commands["foo pkg exists"] = lambda: _check_foo_file(
- pkgdir, foo_filename, must_exist=True
- )
-
- test_commands["emerge --pretend dev-libs/A"] = emerge + (
- "--pretend",
- "dev-libs/A",
- )
-
- test_commands["ebuild dev-libs/A-1 manifest clean package merge"] = ebuild + (
- test_ebuild,
- "manifest",
- "clean",
- "package",
- "merge",
- )
- test_commands["emerge --pretend --tree --complete-graph dev-libs/A"] = emerge + (
- "--pretend",
- "--tree",
- "--complete-graph",
- "dev-libs/A",
- )
- test_commands["emerge -p dev-libs/B"] = emerge + ("-p", "dev-libs/B")
- test_commands["emerge -p --newrepo dev-libs/B"] = emerge + (
- "-p",
- "--newrepo",
- "dev-libs/B",
- )
- test_commands["emerge -B dev-libs/B"] = emerge + ("-B", "dev-libs/B")
- test_commands["emerge -1k dev-libs/B"] = emerge + (
- "--oneshot",
- "--usepkg",
- "dev-libs/B",
- )
- # trigger clean prior to pkg_pretend as in bug #390711
- test_commands["ebuild dev-libs/A-1 unpack"] = ebuild + (test_ebuild, "unpack")
- test_commands["emerge -1 dev-libs/A"] = emerge + ("--oneshot", "dev-libs/A")
- test_commands["emerge -n dev-libs/A"] = emerge + ("--noreplace", "dev-libs/A")
- test_commands["emerge --config dev-libs/A"] = emerge + (
- "--config",
- "dev-libs/A",
- )
- test_commands["emerge --info dev-libs/A dev-libs/B"] = emerge + (
- "--info",
- "dev-libs/A",
- "dev-libs/B",
- )
- test_commands["emerge -pcv dev-libs/B"] = emerge + (
- "--pretend",
- "--depclean",
- "--verbose",
- "dev-libs/B",
- )
- test_commands["emerge -pc"] = emerge + ("--pretend", "--depclean")
- test_commands["emerge -c"] = emerge + ("--depclean",)
- test_commands["quickpkg --include-config y dev-libs/A"] = quickpkg + (
- "--include-config",
- "y",
- "dev-libs/A",
- )
- # Test bug #523684, where a file renamed or removed by the
- # admin forces replacement files to be merged with config
- # protection.
- test_commands["no protected files"] = lambda: _check_number_of_protected_files(
- 0, eroot, settings["CONFIG_PROTECT"]
- )
- # Another "it is not a test command" case; actually setup:
- test_commands["rm /etc/A-0"] = lambda: os.unlink(
- os.path.join(eprefix, "etc", "A-0")
- )
- test_commands["emerge -K dev-libs/A"] = emerge + ("--usepkgonly", "dev-libs/A")
- test_commands["one protected file"] = lambda: _check_number_of_protected_files(
- 1, eroot, settings["CONFIG_PROTECT"]
- )
-
- test_commands["emaint --check all"] = emaint + ("--check", "all")
- test_commands["emaint --fix all"] = emaint + ("--fix", "all")
- test_commands["fixpackages"] = fixpackages
- test_commands["regenworld"] = regenworld
- test_commands["portageq match {eroot} dev-libs/A"] = portageq + (
- "match",
- eroot,
- "dev-libs/A",
- )
- test_commands["portageq best_visible {eroot} dev-libs/A"] = portageq + (
- "best_visible",
- eroot,
- "dev-libs/A",
- )
- test_commands["portageq best_visible {eroot} binary dev-libs/A"] = portageq + (
- "best_visible",
- eroot,
- "binary",
- "dev-libs/A",
- )
- test_commands["portageq contents {eroot} dev-libs/A-1"] = portageq + (
- "contents",
- eroot,
- "dev-libs/A-1",
- )
- test_commands[
- "portageq metadata {eroot} ebuild dev-libs/A-1 EAPI IUSE RDEPEND"
- ] = portageq + (
- "metadata",
- eroot,
- "ebuild",
- "dev-libs/A-1",
- "EAPI",
- "IUSE",
- "RDEPEND",
- )
- test_commands[
- "portageq metadata {eroot} binary dev-libs/A-1 EAPI USE RDEPEND"
- ] = portageq + (
- "metadata",
- eroot,
- "binary",
- "dev-libs/A-1",
- "EAPI",
- "USE",
- "RDEPEND",
- )
- test_commands[
- "portageq metadata {eroot} installed dev-libs/A-1 EAPI USE RDEPEND"
- ] = portageq + (
- "metadata",
- eroot,
- "installed",
- "dev-libs/A-1",
- "EAPI",
- "USE",
- "RDEPEND",
- )
- test_commands["portageq owners {eroot} {eroot}usr"] = portageq + (
- "owners",
- eroot,
- eroot + "usr",
- )
- test_commands["emerge -p {eroot}usr"] = emerge + ("-p", eroot + "usr")
- test_commands["emerge -pCq {eroot}usr"] = emerge + (
- "-p",
- "--unmerge",
- "-q",
- eroot + "usr",
- )
- test_commands["emerge -Cq dev-libs/A"] = emerge + (
- "--unmerge",
- "--quiet",
- "dev-libs/A",
- )
- test_commands["emerge -Cq dev-libs/B"] = emerge + (
- "-C",
- "--quiet",
- "dev-libs/B",
- )
-
- # autounmask:
- # If EMERGE_DEFAULT_OPTS contains --autounmask=n, then --autounmask
- # must be specified with --autounmask-continue.
- test_commands[
- "EMERGE_DEFAULT_OPTS=--autounmask=n "
- "emerge --autounmask --autounmask-continue dev-libs/C"
- ] = (
- ({"EMERGE_DEFAULT_OPTS": "--autounmask=n"},)
- + emerge
- + ("--autounmask", "--autounmask-continue", "dev-libs/C")
- )
- # Verify that the above --autounmask-continue command caused
- # USE=flag to be applied correctly to dev-libs/D.
- test_commands["portageq match {eroot} dev-libs/D[flag]"] = portageq + (
- "match",
- eroot,
- "dev-libs/D[flag]",
- )
- # Test cross-prefix usage, including chpathtool for binpkgs.
- # EAPI 7
- test_commands["EPREFIX={cross_prefix} emerge dev-libs/C"] = (
- ({"EPREFIX": cross_prefix},) + emerge + ("dev-libs/C",)
- )
- test_commands[
- "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/C"
- ] = (
- ({"EPREFIX": cross_prefix},)
- + portageq
- + ("has_version", cross_prefix, "dev-libs/C")
- )
- test_commands[
- "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/D"
- ] = (
- ({"EPREFIX": cross_prefix},)
- + portageq
- + ("has_version", cross_prefix, "dev-libs/D")
- )
- test_commands["ROOT={cross_root} emerge dev-libs/D"] = (
- ({"ROOT": cross_root},) + emerge + ("dev-libs/D",)
- )
- test_commands["portageq has_version {cross_eroot} dev-libs/D"] = portageq + (
- "has_version",
- cross_eroot,
- "dev-libs/D",
- )
- # EAPI 5
- test_commands["EPREFIX={cross_prefix} emerge -K dev-libs/A"] = (
- ({"EPREFIX": cross_prefix},) + emerge + ("--usepkgonly", "dev-libs/A")
- )
- test_commands[
- "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/A"
- ] = (
- ({"EPREFIX": cross_prefix},)
- + portageq
- + ("has_version", cross_prefix, "dev-libs/A")
- )
- test_commands[
- "EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/B"
- ] = (
- ({"EPREFIX": cross_prefix},)
- + portageq
- + ("has_version", cross_prefix, "dev-libs/B")
- )
- test_commands["EPREFIX={cross_prefix} emerge -Cq dev-libs/B"] = (
- ({"EPREFIX": cross_prefix},) + emerge + ("-C", "--quiet", "dev-libs/B")
- )
- test_commands["EPREFIX={cross_prefix} emerge -Cq dev-libs/A"] = (
- ({"EPREFIX": cross_prefix},) + emerge + ("-C", "--quiet", "dev-libs/A")
- )
- test_commands["EPREFIX={cross_prefix} emerge dev-libs/A"] = (
- ({"EPREFIX": cross_prefix},) + emerge + ("dev-libs/A",)
- )
-
- # Test ROOT support
- test_commands["ROOT={cross_root} emerge dev-libs/B"] = (
- ({"ROOT": cross_root},) + emerge + ("dev-libs/B",)
- )
- test_commands["portageq has_version {cross_eroot} dev-libs/B"] = portageq + (
- "has_version",
- cross_eroot,
- "dev-libs/B",
- )
-
- # Test binhost support if FETCHCOMMAND is available.
- binrepos_conf_file = os.path.join(os.sep, eprefix, BINREPOS_CONF_FILE)
- binhost_uri = binhost["uri"]
- binhost_dir = binhost["dir"]
- with open(binrepos_conf_file, "w") as f:
- f.write("[test-binhost]\n")
- f.write(f"sync-uri = {binhost_uri}\n")
- fetchcommand = portage.util.shlex_split(settings["FETCHCOMMAND"])
- fetch_bin = portage.process.find_binary(fetchcommand[0])
- if fetch_bin is None:
- for command_name in _SIMPLE_COMMAND_FETCHCOMMAND_SEQUENCE:
- test_commands[command_name] = NOOP
- else:
- test_commands["mv {pkgdir} {binhost_dir}"] = lambda: os.rename(
- pkgdir, binhost_dir
- )
- test_commands["emerge -eG dev-libs/A"] = emerge + (
- "-e",
- "--getbinpkgonly",
- "dev-libs/A",
- )
- test_commands["rm -R {pkgdir}"] = lambda: shutil.rmtree(pkgdir)
- test_commands["mv {binhost_dir} {pkgdir}"] = lambda: os.rename(
- binhost_dir, pkgdir
- )
- # Remove binrepos.conf and test PORTAGE_BINHOST.
- test_commands["rm {binrepos_conf_file}"] = lambda: os.unlink(binrepos_conf_file)
- test_commands["PORTAGE_BINHOST={binhost_uri} emerge -feG dev-libs/A"] = (
- ({"PORTAGE_BINHOST": binhost_uri},)
- + emerge
- + ("-fe", "--getbinpkgonly", "dev-libs/A")
- )
-
- yield test_commands
-
-
@pytest.fixture()
def _generate_all_baseline_commands(playground, binhost):
"""This fixture generates all the commands that
@@ -944,7 +531,7 @@ def _generate_all_baseline_commands(playground, binhost):
To add a new command, define it in the local ``test_commands``
dict, if not yet defined, and add its key at the correct position
- in the ``_SIMPLE_COMMAND_SEQUENCE`` list.
+ in the ``_BASELINE_COMMAND_SEQUENCE`` list.
"""
settings = playground.settings
eprefix = settings["EPREFIX"]
@@ -1027,9 +614,6 @@ def _generate_all_baseline_commands(playground, binhost):
test_commands["emerge --list-sets"] = Emerge("--list-sets")
test_commands["emerge --check-news"] = Emerge("--check-news")
- # test_commands["rm -rf {cachedir}"] = Rm("-rf", cachedir)
- # test_commands["rm -rf {cachedir_pregen}"] = Rm("-rf", cachedir_pregen)
-
def _rm_cachedir():
shutil.rmtree(cachedir)
@@ -1140,6 +724,10 @@ def _generate_all_baseline_commands(playground, binhost):
test_commands["emerge -c"] = Emerge(
"--depclean",
)
+
+ # Test bug #523684, where a file renamed or removed by the
+ # admin forces replacement files to be merged with config
+ # protection.
test_commands["quickpkg --include-config y dev-libs/A"] = Quickpkg(
"--include-config",
"y",
@@ -1148,13 +736,6 @@ def _generate_all_baseline_commands(playground, binhost):
0, eroot, settings["CONFIG_PROTECT"]
),
)
- # Test bug #523684, where a file renamed or removed by the
- # admin forces replacement files to be merged with config
- # protection.
-
- # test_commands["no protected files"] = lambda: _check_number_of_protected_files(
- # 0, eroot, settings["CONFIG_PROTECT"]
- # )
# Another "it is not a test command" case; actually setup:
# test_commands["rm /etc/A-0"] = lambda: os.unlink(
@@ -1169,10 +750,6 @@ def _generate_all_baseline_commands(playground, binhost):
),
)
- # test_commands["one protected file"] = lambda: _check_number_of_protected_files(
- # 1, eroot, settings["CONFIG_PROTECT"]
- # )
-
test_commands["emaint --check all"] = Emaint("--check", "all")
test_commands["emaint --fix all"] = Emaint("--fix", "all")
test_commands["fixpackages"] = Fixpackages()
@@ -1351,7 +928,7 @@ def _generate_all_baseline_commands(playground, binhost):
fetchcommand = portage.util.shlex_split(settings["FETCHCOMMAND"])
fetch_bin = portage.process.find_binary(fetchcommand[0])
if fetch_bin is None:
- for command_name in _SIMPLE_COMMAND_FETCHCOMMAND_SEQUENCE:
+ for command_name in _BASELINE_COMMAND_FETCHCOMMAND_SEQUENCE:
test_commands[command_name] = Noop()
else:
# test_commands["mv {pkgdir} {binhost_dir}"] = lambda: os.rename(
@@ -1386,22 +963,11 @@ def _generate_all_baseline_commands(playground, binhost):
yield test_commands
-@pytest.fixture()
-def simple_command(request, _generate_all_simple_commands):
- """A fixture that provides the commands to perform a baseline
- functional test of portage. It uses another fixture, namely
- ``_generate_all_simple_commands``.
- Pytest caches the fixtures and there is a little performance
- improvement if the commands are generated only once..
- """
- return _generate_all_simple_commands[request.param]
-
-
@pytest.fixture()
def baseline_command(request, _generate_all_baseline_commands):
"""A fixture that provides the commands to perform a baseline
functional test of portage. It uses another fixture, namely
- ``_generate_all_simple_commands``.
+ ``_generate_all_baseline_commands``.
Pytest caches the fixtures and there is a little performance
improvement if the commands are generated only once..
"""
diff --git a/lib/portage/tests/emerge/test_simple.py b/lib/portage/tests/emerge/test_simple.py
index d287aaa159..b23e10ddfd 100644
--- a/lib/portage/tests/emerge/test_simple.py
+++ b/lib/portage/tests/emerge/test_simple.py
@@ -60,24 +60,17 @@ move dev-util/git dev-vcs/git
def test_portage_baseline(async_loop, playground, binhost, baseline_command):
async_loop.run_until_complete(
asyncio.ensure_future(
- # _async_test_baseline(
- # playground,
- # binhost,
- # simple_command,
- # ),
_async_test_simple(
playground,
binhost,
- # simple_command,
baseline_command,
- loop=async_loop,
),
loop=async_loop,
)
)
-async def _async_test_simple(playground, binhost, commands, loop):
+async def _async_test_simple(playground, binhost, commands):
debug = playground.debug
settings = playground.settings
trees = playground.trees
@@ -199,27 +192,14 @@ async def _async_test_simple(playground, binhost, commands, loop):
# triggered by python -Wd will be visible.
stdout = subprocess.PIPE
- # # command.prepare()
- # if hasattr(command, "__call__"):
- # command()
- # return
for command in commands:
if command:
command.base_environment = env
- # if isinstance(command[0], dict):
- # local_env = env.copy()
- # local_env.update(command[0])
- # command = command[1:]
- # else:
- # local_env = env
- # with self.subTest(cmd=command, i=idx):
proc = await asyncio.create_subprocess_exec(
*command(), env=command.env, stderr=None, stdout=stdout
)
- # command.cleanup()
-
if debug:
await proc.wait()
else:
@@ -234,120 +214,3 @@ async def _async_test_simple(playground, binhost, commands, loop):
os.EX_OK == proc.returncode
), f"'{real_command}' failed with args '{args}'"
command.check_command_result()
-
-
-async def _async_test_baseline(playground, binhost, baseline_command):
- debug = playground.debug
- settings = playground.settings
- trees = playground.trees
- eprefix = settings["EPREFIX"]
-
- # test_commands = make_test_commands(settings, trees, binhost["uri"])
-
- test_repo_location = settings.repositories["test_repo"].location
- var_cache_edb = os.path.join(eprefix, "var", "cache", "edb")
- cachedir = os.path.join(var_cache_edb, "dep")
- cachedir_pregen = os.path.join(test_repo_location, "metadata", "md5-cache")
-
- cross_prefix = os.path.join(eprefix, "cross_prefix")
- cross_root = os.path.join(eprefix, "cross_root")
- cross_eroot = os.path.join(cross_root, eprefix.lstrip(os.sep))
-
- distdir = playground.distdir
- pkgdir = playground.pkgdir
- fake_bin = os.path.join(eprefix, "bin")
- portage_tmpdir = os.path.join(eprefix, "var", "tmp", "portage")
- profile_path = settings.profile_path
- user_config_dir = os.path.join(os.sep, eprefix, USER_CONFIG_PATH)
-
- path = os.environ.get("PATH")
- if path is not None and not path.strip():
- path = None
- if path is None:
- path = ""
- else:
- path = ":" + path
- path = fake_bin + path
-
- pythonpath = os.environ.get("PYTHONPATH")
- if pythonpath is not None and not pythonpath.strip():
- pythonpath = None
- if pythonpath is not None and pythonpath.split(":")[0] == PORTAGE_PYM_PATH:
- pass
- else:
- if pythonpath is None:
- pythonpath = ""
- else:
- pythonpath = ":" + pythonpath
- pythonpath = PORTAGE_PYM_PATH + pythonpath
-
- env = {
- "PORTAGE_OVERRIDE_EPREFIX": eprefix,
- "CLEAN_DELAY": "0",
- "DISTDIR": distdir,
- "EMERGE_WARNING_DELAY": "0",
- "INFODIR": "",
- "INFOPATH": "",
- "PATH": path,
- "PKGDIR": pkgdir,
- "PORTAGE_INST_GID": str(os.getgid()), # str(portage.data.portage_gid),
- "PORTAGE_INST_UID": str(os.getuid()), # str(portage.data.portage_uid),
- "PORTAGE_PYTHON": portage._python_interpreter,
- "PORTAGE_REPOSITORIES": settings.repositories.config_string(),
- "PORTAGE_TMPDIR": portage_tmpdir,
- "PORTAGE_LOGDIR": portage_tmpdir,
- "PYTHONDONTWRITEBYTECODE": os.environ.get("PYTHONDONTWRITEBYTECODE", ""),
- "PYTHONPATH": pythonpath,
- "__PORTAGE_TEST_PATH_OVERRIDE": fake_bin,
- }
-
- if "__PORTAGE_TEST_HARDLINK_LOCKS" in os.environ:
- env["__PORTAGE_TEST_HARDLINK_LOCKS"] = os.environ[
- "__PORTAGE_TEST_HARDLINK_LOCKS"
- ]
-
- updates_dir = os.path.join(test_repo_location, "profiles", "updates")
- dirs = [
- cachedir,
- cachedir_pregen,
- cross_eroot,
- cross_prefix,
- distdir,
- fake_bin,
- portage_tmpdir,
- updates_dir,
- user_config_dir,
- var_cache_edb,
- ]
- etc_symlinks = ("dispatch-conf.conf", "etc-update.conf")
- # 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)
- true_symlinks = ["find", "prepstrip", "sed", "scanelf"]
- true_binary = find_binary("true")
- assert true_binary is not None, "true command not found"
-
- for d in dirs:
- ensure_dirs(d)
- for x in true_symlinks:
- try:
- os.symlink(true_binary, os.path.join(fake_bin, x))
- except FileExistsError:
- pass
- for x in etc_symlinks:
- try:
- os.symlink(os.path.join(cnf_etc_path, x), os.path.join(eprefix, "etc", x))
- except FileExistsError:
- pass
- with open(os.path.join(var_cache_edb, "counter"), "wb") as f:
- f.write(b"100")
- # non-empty system set keeps --depclean quiet
- with open(os.path.join(profile_path, "packages"), "w") as f:
- f.write("*dev-libs/token-system-pkg")
- for cp, xml_data in _METADATA_XML_FILES:
- with open(os.path.join(test_repo_location, cp, "metadata.xml"), "w") as f:
- f.write(playground.metadata_xml_template % xml_data)
- with open(os.path.join(updates_dir, "1Q-2010"), "w") as f:
- f.write(_1Q_2010_UPDATE)
-
- baseline_command(environment=env)
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/emerge/
@ 2023-10-30 3:14 Sam James
0 siblings, 0 replies; 38+ messages in thread
From: Sam James @ 2023-10-30 3:14 UTC (permalink / raw
To: gentoo-commits
commit: 8fa355bbdea7526b29d659381e79128e8b9101e1
Author: David Palao <david.palao <AT> gmail <DOT> com>
AuthorDate: Fri Sep 15 15:36:08 2023 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Oct 30 03:14:24 2023 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=8fa355bb
tests/emerge: test_simple.py, conftest.py: Refactor
Refactor.
Portage commands converted into fixtures. Now the commands are
simply tuples of strings. I pretend them to become instances of
a Command class that can encapsulate the context of each command
more cleanly.
Signed-off-by: David Palao <david.palao <AT> gmail.com>
Signed-off-by: Sam James <sam <AT> gentoo.org>
lib/portage/tests/emerge/conftest.py | 291 +++++++++++++++++++++--------------
1 file changed, 174 insertions(+), 117 deletions(-)
diff --git a/lib/portage/tests/emerge/conftest.py b/lib/portage/tests/emerge/conftest.py
index 07895501d4..ce339d3afc 100644
--- a/lib/portage/tests/emerge/conftest.py
+++ b/lib/portage/tests/emerge/conftest.py
@@ -278,6 +278,7 @@ _SIMPLE_COMMAND_SEQUENCE = [
"portageq has_version {cross_eroot} dev-libs/B",
] + _SIMPLE_COMMAND_FETCHCOMMAND_SEQUENCE
+PORTAGE_PYTHON = portage._python_interpreter
NOOP = lambda: ...
@@ -387,83 +388,139 @@ def binhost(playground, async_loop):
@pytest.fixture()
-def _generate_all_simple_commands(playground, binhost):
- """This fixture generates all the commands that
- ``test_portage_baseline`` will use.
+def emerge():
+ yield (PORTAGE_PYTHON, "-b", "-Wd", os.path.join(cnf_bindir, "emerge"))
- But, don't use this fixture directly, instead, use the
- ``simple_command`` fixture. That improves performance a bit due to
- pytest caching.
- .. note::
-
- To add a new command, define it in the local ``test_commands``
- dict, if not yet defined, and add its key at the correct position
- in the ``_SIMPLE_COMMAND_SEQUENCE`` list.
- """
- settings = playground.settings
- eprefix = settings["EPREFIX"]
- eroot = settings["EROOT"]
- trees = playground.trees
- pkgdir = playground.pkgdir
- portdb = trees[eroot]["porttree"].dbapi
- test_repo_location = settings.repositories["test_repo"].location
- var_cache_edb = os.path.join(eprefix, "var", "cache", "edb")
- cachedir = os.path.join(var_cache_edb, "dep")
- cachedir_pregen = os.path.join(test_repo_location, "metadata", "md5-cache")
-
- portage_python = portage._python_interpreter
- dispatch_conf_cmd = (
- portage_python,
+@pytest.fixture()
+def dispatch_conf():
+ yield (
+ PORTAGE_PYTHON,
"-b",
"-Wd",
os.path.join(cnf_sbindir, "dispatch-conf"),
)
- ebuild_cmd = (portage_python, "-b", "-Wd", os.path.join(cnf_bindir, "ebuild"))
- egencache_cmd = (
- portage_python,
+
+
+@pytest.fixture()
+def ebuild():
+ yield (PORTAGE_PYTHON, "-b", "-Wd", os.path.join(cnf_bindir, "ebuild"))
+
+
+@pytest.fixture()
+def egencache(playground):
+ yield (
+ PORTAGE_PYTHON,
"-b",
"-Wd",
os.path.join(cnf_bindir, "egencache"),
"--repo",
"test_repo",
"--repositories-configuration",
- settings.repositories.config_string(),
+ playground.settings.repositories.config_string(),
)
- emerge_cmd = (portage_python, "-b", "-Wd", os.path.join(cnf_bindir, "emerge"))
- emaint_cmd = (portage_python, "-b", "-Wd", os.path.join(cnf_sbindir, "emaint"))
- env_update_cmd = (
- portage_python,
+
+
+@pytest.fixture()
+def emaint():
+ yield (PORTAGE_PYTHON, "-b", "-Wd", os.path.join(cnf_sbindir, "emaint"))
+
+
+@pytest.fixture()
+def env_update():
+ yield (
+ PORTAGE_PYTHON,
"-b",
"-Wd",
os.path.join(cnf_sbindir, "env-update"),
)
- etc_update_cmd = (BASH_BINARY, os.path.join(cnf_sbindir, "etc-update"))
- fixpackages_cmd = (
- portage_python,
+
+
+@pytest.fixture()
+def etc_update():
+ yield (BASH_BINARY, os.path.join(cnf_sbindir, "etc-update"))
+
+
+@pytest.fixture()
+def fixpackages():
+ yield (
+ PORTAGE_PYTHON,
"-b",
"-Wd",
os.path.join(cnf_sbindir, "fixpackages"),
)
- portageq_cmd = (
- portage_python,
+
+
+@pytest.fixture()
+def portageq():
+ yield (
+ PORTAGE_PYTHON,
"-b",
"-Wd",
os.path.join(cnf_bindir, "portageq"),
)
- quickpkg_cmd = (
- portage_python,
+
+
+@pytest.fixture()
+def quickpkg():
+ yield (
+ PORTAGE_PYTHON,
"-b",
"-Wd",
os.path.join(cnf_bindir, "quickpkg"),
)
- regenworld_cmd = (
- portage_python,
+
+
+@pytest.fixture()
+def regenworld():
+ yield (
+ PORTAGE_PYTHON,
"-b",
"-Wd",
os.path.join(cnf_sbindir, "regenworld"),
)
+
+@pytest.fixture()
+def _generate_all_simple_commands(
+ playground,
+ binhost,
+ emerge,
+ env_update,
+ portageq,
+ etc_update,
+ dispatch_conf,
+ ebuild,
+ egencache,
+ emaint,
+ fixpackages,
+ quickpkg,
+ regenworld,
+):
+ """This fixture generates all the commands that
+ ``test_portage_baseline`` will use.
+
+ But, don't use this fixture directly, instead, use the
+ ``simple_command`` fixture. That improves performance a bit due to
+ pytest caching.
+
+ .. note::
+
+ To add a new command, define it in the local ``test_commands``
+ dict, if not yet defined, and add its key at the correct position
+ in the ``_SIMPLE_COMMAND_SEQUENCE`` list.
+ """
+ settings = playground.settings
+ eprefix = settings["EPREFIX"]
+ eroot = settings["EROOT"]
+ trees = playground.trees
+ pkgdir = playground.pkgdir
+ portdb = trees[eroot]["porttree"].dbapi
+ test_repo_location = settings.repositories["test_repo"].location
+ var_cache_edb = os.path.join(eprefix, "var", "cache", "edb")
+ cachedir = os.path.join(var_cache_edb, "dep")
+ cachedir_pregen = os.path.join(test_repo_location, "metadata", "md5-cache")
+
rm_binary = find_binary("rm")
assert rm_binary is not None, "rm command not found"
rm_cmd = (rm_binary,)
@@ -489,7 +546,7 @@ def _generate_all_simple_commands(playground, binhost):
test_commands = {}
if hasattr(argparse.ArgumentParser, "parse_intermixed_args"):
- parse_intermixed_command = emerge_cmd + (
+ parse_intermixed_command = emerge + (
"--oneshot",
"dev-libs/A",
"-v",
@@ -499,7 +556,7 @@ def _generate_all_simple_commands(playground, binhost):
parse_intermixed_command = NOOP
test_commands["emerge -1 dev-libs/A -v dev-libs/B"] = parse_intermixed_command
- test_commands["emerge --root --quickpkg-direct-root"] = emerge_cmd + (
+ test_commands["emerge --root --quickpkg-direct-root"] = emerge + (
"--usepkgonly",
"--root",
cross_root,
@@ -508,15 +565,15 @@ def _generate_all_simple_commands(playground, binhost):
"/",
"dev-libs/A",
)
- test_commands["emerge --quickpkg-direct-root"] = emerge_cmd + (
+ test_commands["emerge --quickpkg-direct-root"] = emerge + (
"--usepkgonly",
"--quickpkg-direct=y",
"--quickpkg-direct-root",
cross_root,
"dev-libs/A",
)
- test_commands["env-update"] = env_update_cmd
- test_commands["portageq envvar"] = portageq_cmd + (
+ test_commands["env-update"] = env_update
+ test_commands["portageq envvar"] = portageq + (
"envvar",
"-v",
"CONFIG_PROTECT",
@@ -525,28 +582,28 @@ def _generate_all_simple_commands(playground, binhost):
"PORTAGE_TMPDIR",
"USERLAND",
)
- test_commands["etc-update"] = etc_update_cmd
- test_commands["dispatch-conf"] = dispatch_conf_cmd
- test_commands["emerge --version"] = emerge_cmd + ("--version",)
- test_commands["emerge --info"] = emerge_cmd + ("--info",)
- test_commands["emerge --info --verbose"] = emerge_cmd + ("--info", "--verbose")
- test_commands["emerge --list-sets"] = emerge_cmd + ("--list-sets",)
- test_commands["emerge --check-news"] = emerge_cmd + ("--check-news",)
+ test_commands["etc-update"] = etc_update
+ test_commands["dispatch-conf"] = dispatch_conf
+ test_commands["emerge --version"] = emerge + ("--version",)
+ test_commands["emerge --info"] = emerge + ("--info",)
+ test_commands["emerge --info --verbose"] = emerge + ("--info", "--verbose")
+ test_commands["emerge --list-sets"] = emerge + ("--list-sets",)
+ test_commands["emerge --check-news"] = emerge + ("--check-news",)
test_commands["rm -rf {cachedir}"] = rm_cmd + ("-rf", cachedir)
test_commands["rm -rf {cachedir_pregen}"] = rm_cmd + ("-rf", cachedir_pregen)
- test_commands["emerge --regen"] = emerge_cmd + ("--regen",)
+ test_commands["emerge --regen"] = emerge + ("--regen",)
test_commands["FEATURES=metadata-transfer emerge --regen"] = (
- ({"FEATURES": "metadata-transfer"},) + emerge_cmd + ("--regen",)
+ ({"FEATURES": "metadata-transfer"},) + emerge + ("--regen",)
)
test_commands["egencache --update"] = (
- egencache_cmd + ("--update",) + tuple(egencache_extra_args)
+ egencache + ("--update",) + tuple(egencache_extra_args)
)
test_commands["FEATURES=metadata-transfer emerge --metadata"] = (
- ({"FEATURES": "metadata-transfer"},) + emerge_cmd + ("--metadata",)
+ ({"FEATURES": "metadata-transfer"},) + emerge + ("--metadata",)
)
- test_commands["emerge --metadata"] = emerge_cmd + ("--metadata",)
+ test_commands["emerge --metadata"] = emerge + ("--metadata",)
- test_commands["emerge --oneshot virtual/foo"] = emerge_cmd + (
+ test_commands["emerge --oneshot virtual/foo"] = emerge + (
"--oneshot",
"virtual/foo",
)
@@ -555,64 +612,64 @@ def _generate_all_simple_commands(playground, binhost):
)
test_commands["FEATURES=unmerge-backup emerge --unmerge virtual/foo"] = (
- ({"FEATURES": "unmerge-backup"},) + emerge_cmd + ("--unmerge", "virtual/foo")
+ ({"FEATURES": "unmerge-backup"},) + emerge + ("--unmerge", "virtual/foo")
)
test_commands["foo pkg exists"] = lambda: _check_foo_file(
pkgdir, foo_filename, must_exist=True
)
- test_commands["emerge --pretend dev-libs/A"] = emerge_cmd + (
+ test_commands["emerge --pretend dev-libs/A"] = emerge + (
"--pretend",
"dev-libs/A",
)
- test_commands["ebuild dev-libs/A-1 manifest clean package merge"] = ebuild_cmd + (
+ test_commands["ebuild dev-libs/A-1 manifest clean package merge"] = ebuild + (
test_ebuild,
"manifest",
"clean",
"package",
"merge",
)
- test_commands[
- "emerge --pretend --tree --complete-graph dev-libs/A"
- ] = emerge_cmd + ("--pretend", "--tree", "--complete-graph", "dev-libs/A")
- test_commands["emerge -p dev-libs/B"] = emerge_cmd + ("-p", "dev-libs/B")
- test_commands["emerge -p --newrepo dev-libs/B"] = emerge_cmd + (
+ test_commands["emerge --pretend --tree --complete-graph dev-libs/A"] = emerge + (
+ "--pretend",
+ "--tree",
+ "--complete-graph",
+ "dev-libs/A",
+ )
+ test_commands["emerge -p dev-libs/B"] = emerge + ("-p", "dev-libs/B")
+ test_commands["emerge -p --newrepo dev-libs/B"] = emerge + (
"-p",
"--newrepo",
"dev-libs/B",
)
- test_commands["emerge -B dev-libs/B"] = emerge_cmd + (
- "-B",
- "dev-libs/B",
- )
- test_commands["emerge -1k dev-libs/B"] = emerge_cmd + (
+ test_commands["emerge -B dev-libs/B"] = emerge + ("-B", "dev-libs/B")
+ test_commands["emerge -1k dev-libs/B"] = emerge + (
"--oneshot",
"--usepkg",
"dev-libs/B",
)
# trigger clean prior to pkg_pretend as in bug #390711
- test_commands["ebuild dev-libs/A-1 unpack"] = ebuild_cmd + (test_ebuild, "unpack")
- test_commands["emerge -1 dev-libs/A"] = emerge_cmd + ("--oneshot", "dev-libs/A")
- test_commands["emerge -n dev-libs/A"] = emerge_cmd + ("--noreplace", "dev-libs/A")
- test_commands["emerge --config dev-libs/A"] = emerge_cmd + (
+ test_commands["ebuild dev-libs/A-1 unpack"] = ebuild + (test_ebuild, "unpack")
+ test_commands["emerge -1 dev-libs/A"] = emerge + ("--oneshot", "dev-libs/A")
+ test_commands["emerge -n dev-libs/A"] = emerge + ("--noreplace", "dev-libs/A")
+ test_commands["emerge --config dev-libs/A"] = emerge + (
"--config",
"dev-libs/A",
)
- test_commands["emerge --info dev-libs/A dev-libs/B"] = emerge_cmd + (
+ test_commands["emerge --info dev-libs/A dev-libs/B"] = emerge + (
"--info",
"dev-libs/A",
"dev-libs/B",
)
- test_commands["emerge -pcv dev-libs/B"] = emerge_cmd + (
+ test_commands["emerge -pcv dev-libs/B"] = emerge + (
"--pretend",
"--depclean",
"--verbose",
"dev-libs/B",
)
- test_commands["emerge -pc"] = emerge_cmd + ("--pretend", "--depclean")
- test_commands["emerge -c"] = emerge_cmd + ("--depclean",)
- test_commands["quickpkg --include-config y dev-libs/A"] = quickpkg_cmd + (
+ test_commands["emerge -pc"] = emerge + ("--pretend", "--depclean")
+ test_commands["emerge -c"] = emerge + ("--depclean",)
+ test_commands["quickpkg --include-config y dev-libs/A"] = quickpkg + (
"--include-config",
"y",
"dev-libs/A",
@@ -627,39 +684,39 @@ def _generate_all_simple_commands(playground, binhost):
test_commands["rm /etc/A-0"] = lambda: os.unlink(
os.path.join(eprefix, "etc", "A-0")
)
- test_commands["emerge -K dev-libs/A"] = emerge_cmd + ("--usepkgonly", "dev-libs/A")
+ test_commands["emerge -K dev-libs/A"] = emerge + ("--usepkgonly", "dev-libs/A")
test_commands["one protected file"] = lambda: _check_number_of_protected_files(
1, eroot, settings["CONFIG_PROTECT"]
)
- test_commands["emaint --check all"] = emaint_cmd + ("--check", "all")
- test_commands["emaint --fix all"] = emaint_cmd + ("--fix", "all")
- test_commands["fixpackages"] = fixpackages_cmd
- test_commands["regenworld"] = regenworld_cmd
- test_commands["portageq match {eroot} dev-libs/A"] = portageq_cmd + (
+ test_commands["emaint --check all"] = emaint + ("--check", "all")
+ test_commands["emaint --fix all"] = emaint + ("--fix", "all")
+ test_commands["fixpackages"] = fixpackages
+ test_commands["regenworld"] = regenworld
+ test_commands["portageq match {eroot} dev-libs/A"] = portageq + (
"match",
eroot,
"dev-libs/A",
)
- test_commands["portageq best_visible {eroot} dev-libs/A"] = portageq_cmd + (
+ test_commands["portageq best_visible {eroot} dev-libs/A"] = portageq + (
"best_visible",
eroot,
"dev-libs/A",
)
- test_commands["portageq best_visible {eroot} binary dev-libs/A"] = portageq_cmd + (
+ test_commands["portageq best_visible {eroot} binary dev-libs/A"] = portageq + (
"best_visible",
eroot,
"binary",
"dev-libs/A",
)
- test_commands["portageq contents {eroot} dev-libs/A-1"] = portageq_cmd + (
+ test_commands["portageq contents {eroot} dev-libs/A-1"] = portageq + (
"contents",
eroot,
"dev-libs/A-1",
)
test_commands[
"portageq metadata {eroot} ebuild dev-libs/A-1 EAPI IUSE RDEPEND"
- ] = portageq_cmd + (
+ ] = portageq + (
"metadata",
eroot,
"ebuild",
@@ -670,7 +727,7 @@ def _generate_all_simple_commands(playground, binhost):
)
test_commands[
"portageq metadata {eroot} binary dev-libs/A-1 EAPI USE RDEPEND"
- ] = portageq_cmd + (
+ ] = portageq + (
"metadata",
eroot,
"binary",
@@ -681,7 +738,7 @@ def _generate_all_simple_commands(playground, binhost):
)
test_commands[
"portageq metadata {eroot} installed dev-libs/A-1 EAPI USE RDEPEND"
- ] = portageq_cmd + (
+ ] = portageq + (
"metadata",
eroot,
"installed",
@@ -690,24 +747,24 @@ def _generate_all_simple_commands(playground, binhost):
"USE",
"RDEPEND",
)
- test_commands["portageq owners {eroot} {eroot}usr"] = portageq_cmd + (
+ test_commands["portageq owners {eroot} {eroot}usr"] = portageq + (
"owners",
eroot,
eroot + "usr",
)
- test_commands["emerge -p {eroot}usr"] = emerge_cmd + ("-p", eroot + "usr")
- test_commands["emerge -pCq {eroot}usr"] = emerge_cmd + (
+ test_commands["emerge -p {eroot}usr"] = emerge + ("-p", eroot + "usr")
+ test_commands["emerge -pCq {eroot}usr"] = emerge + (
"-p",
"--unmerge",
"-q",
eroot + "usr",
)
- test_commands["emerge -Cq dev-libs/A"] = emerge_cmd + (
+ test_commands["emerge -Cq dev-libs/A"] = emerge + (
"--unmerge",
"--quiet",
"dev-libs/A",
)
- test_commands["emerge -Cq dev-libs/B"] = emerge_cmd + (
+ test_commands["emerge -Cq dev-libs/B"] = emerge + (
"-C",
"--quiet",
"dev-libs/B",
@@ -721,12 +778,12 @@ def _generate_all_simple_commands(playground, binhost):
"emerge --autounmask --autounmask-continue dev-libs/C"
] = (
({"EMERGE_DEFAULT_OPTS": "--autounmask=n"},)
- + emerge_cmd
+ + emerge
+ ("--autounmask", "--autounmask-continue", "dev-libs/C")
)
# Verify that the above --autounmask-continue command caused
# USE=flag to be applied correctly to dev-libs/D.
- test_commands["portageq match {eroot} dev-libs/D[flag]"] = portageq_cmd + (
+ test_commands["portageq match {eroot} dev-libs/D[flag]"] = portageq + (
"match",
eroot,
"dev-libs/D[flag]",
@@ -734,63 +791,63 @@ def _generate_all_simple_commands(playground, binhost):
# Test cross-prefix usage, including chpathtool for binpkgs.
# EAPI 7
test_commands["EPREFIX={cross_prefix} emerge dev-libs/C"] = (
- ({"EPREFIX": cross_prefix},) + emerge_cmd + ("dev-libs/C",)
+ ({"EPREFIX": cross_prefix},) + emerge + ("dev-libs/C",)
)
test_commands[
"EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/C"
] = (
({"EPREFIX": cross_prefix},)
- + portageq_cmd
+ + portageq
+ ("has_version", cross_prefix, "dev-libs/C")
)
test_commands[
"EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/D"
] = (
({"EPREFIX": cross_prefix},)
- + portageq_cmd
+ + portageq
+ ("has_version", cross_prefix, "dev-libs/D")
)
test_commands["ROOT={cross_root} emerge dev-libs/D"] = (
- ({"ROOT": cross_root},) + emerge_cmd + ("dev-libs/D",)
+ ({"ROOT": cross_root},) + emerge + ("dev-libs/D",)
)
- test_commands["portageq has_version {cross_eroot} dev-libs/D"] = portageq_cmd + (
+ test_commands["portageq has_version {cross_eroot} dev-libs/D"] = portageq + (
"has_version",
cross_eroot,
"dev-libs/D",
)
# EAPI 5
test_commands["EPREFIX={cross_prefix} emerge -K dev-libs/A"] = (
- ({"EPREFIX": cross_prefix},) + emerge_cmd + ("--usepkgonly", "dev-libs/A")
+ ({"EPREFIX": cross_prefix},) + emerge + ("--usepkgonly", "dev-libs/A")
)
test_commands[
"EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/A"
] = (
({"EPREFIX": cross_prefix},)
- + portageq_cmd
+ + portageq
+ ("has_version", cross_prefix, "dev-libs/A")
)
test_commands[
"EPREFIX={cross_prefix} portageq has_version {cross_prefix} dev-libs/B"
] = (
({"EPREFIX": cross_prefix},)
- + portageq_cmd
+ + portageq
+ ("has_version", cross_prefix, "dev-libs/B")
)
test_commands["EPREFIX={cross_prefix} emerge -Cq dev-libs/B"] = (
- ({"EPREFIX": cross_prefix},) + emerge_cmd + ("-C", "--quiet", "dev-libs/B")
+ ({"EPREFIX": cross_prefix},) + emerge + ("-C", "--quiet", "dev-libs/B")
)
test_commands["EPREFIX={cross_prefix} emerge -Cq dev-libs/A"] = (
- ({"EPREFIX": cross_prefix},) + emerge_cmd + ("-C", "--quiet", "dev-libs/A")
+ ({"EPREFIX": cross_prefix},) + emerge + ("-C", "--quiet", "dev-libs/A")
)
test_commands["EPREFIX={cross_prefix} emerge dev-libs/A"] = (
- ({"EPREFIX": cross_prefix},) + emerge_cmd + ("dev-libs/A",)
+ ({"EPREFIX": cross_prefix},) + emerge + ("dev-libs/A",)
)
# Test ROOT support
test_commands["ROOT={cross_root} emerge dev-libs/B"] = (
- ({"ROOT": cross_root},) + emerge_cmd + ("dev-libs/B",)
+ ({"ROOT": cross_root},) + emerge + ("dev-libs/B",)
)
- test_commands["portageq has_version {cross_eroot} dev-libs/B"] = portageq_cmd + (
+ test_commands["portageq has_version {cross_eroot} dev-libs/B"] = portageq + (
"has_version",
cross_eroot,
"dev-libs/B",
@@ -812,7 +869,7 @@ def _generate_all_simple_commands(playground, binhost):
test_commands["mv {pkgdir} {binhost_dir}"] = lambda: os.rename(
pkgdir, binhost_dir
)
- test_commands["emerge -eG dev-libs/A"] = emerge_cmd + (
+ test_commands["emerge -eG dev-libs/A"] = emerge + (
"-e",
"--getbinpkgonly",
"dev-libs/A",
@@ -825,7 +882,7 @@ def _generate_all_simple_commands(playground, binhost):
test_commands["rm {binrepos_conf_file}"] = lambda: os.unlink(binrepos_conf_file)
test_commands["PORTAGE_BINHOST={binhost_uri} emerge -feG dev-libs/A"] = (
({"PORTAGE_BINHOST": binhost_uri},)
- + emerge_cmd
+ + emerge
+ ("-fe", "--getbinpkgonly", "dev-libs/A")
)
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/emerge/
@ 2023-10-30 3:14 Sam James
0 siblings, 0 replies; 38+ messages in thread
From: Sam James @ 2023-10-30 3:14 UTC (permalink / raw
To: gentoo-commits
commit: a9c81ffe93fdd24cf148e119de7d8ad14007b18b
Author: David Palao <david.palao <AT> gmail <DOT> com>
AuthorDate: Mon Oct 16 15:34:04 2023 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Oct 30 03:14:25 2023 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=a9c81ffe
tests/emerge/test_simple.py: remove it.
It has been renamed to test_baseline.py
Signed-off-by: David Palao <david.palao <AT> gmail.com>
Signed-off-by: Sam James <sam <AT> gentoo.org>
lib/portage/tests/emerge/test_simple.py | 727 --------------------------------
1 file changed, 727 deletions(-)
diff --git a/lib/portage/tests/emerge/test_simple.py b/lib/portage/tests/emerge/test_simple.py
deleted file mode 100644
index f452a84c6b..0000000000
--- a/lib/portage/tests/emerge/test_simple.py
+++ /dev/null
@@ -1,727 +0,0 @@
-# Copyright 2011-2021, 2023 Gentoo Authors
-# Distributed under the terms of the GNU General Public License v2
-
-import argparse
-import subprocess
-import sys
-
-import pytest
-
-import portage
-from portage import shutil, os
-from portage.const import (
- BASH_BINARY,
- BINREPOS_CONF_FILE,
- PORTAGE_PYM_PATH,
- USER_CONFIG_PATH,
- SUPPORTED_GENTOO_BINPKG_FORMATS,
-)
-from portage.cache.mappings import Mapping
-from portage.process import find_binary
-from portage.tests import cnf_bindir, cnf_sbindir, cnf_etc_path
-from portage.tests.resolver.ResolverPlayground import ResolverPlayground
-from portage.tests.util.test_socks5 import AsyncHTTPServer
-from portage.util import ensure_dirs, find_updated_config_files, shlex_split
-from portage.util.futures import asyncio
-from portage.output import colorize
-
-
-class BinhostContentMap(Mapping):
- def __init__(self, remote_path, local_path):
- self._remote_path = remote_path
- self._local_path = local_path
-
-
-@pytest.mark.ft
-def test_simple_emerge(async_loop, playground, binhost, simple_command):
- async_loop.run_until_complete(
- asyncio.ensure_future(
- _async_test_simple(
- playground,
- binhost,
- simple_command,
- _METADATA_XML_FILES,
- loop=async_loop,
- ),
- loop=async_loop,
- )
- try:
- with open(local_path, "rb") as f:
- return f.read()
- except OSError:
- raise KeyError(request_path)
-
-
-class SimpleEmergeTestCase(TestCase):
- def _have_python_xml(self):
- try:
- __import__("xml.etree.ElementTree")
- __import__("xml.parsers.expat").parsers.expat.ExpatError
- except (AttributeError, ImportError):
- return False
- return True
-
- def testSimple(self):
- debug = False
-
- install_something = """
-S="${WORKDIR}"
-
-pkg_pretend() {
- einfo "called pkg_pretend for $CATEGORY/$PF"
-}
-
-src_install() {
- einfo "installing something..."
- insinto /usr/lib/${P}
- echo "blah blah blah" > "${T}"/regular-file
- doins "${T}"/regular-file
- dosym regular-file /usr/lib/${P}/symlink || die
-
- # Test CONFIG_PROTECT
- insinto /etc
- newins "${T}"/regular-file ${PN}-${SLOT%/*}
-
- # Test code for bug #381629, using a copyright symbol encoded with latin-1.
- # We use $(printf "\\xa9") rather than $'\\xa9', since printf apparently
- # works in any case, while $'\\xa9' transforms to \\xef\\xbf\\xbd under
- # some conditions. TODO: Find out why it transforms to \\xef\\xbf\\xbd when
- # running tests for Python 3.2 (even though it's bash that is ultimately
- # responsible for performing the transformation).
- local latin_1_dir=/usr/lib/${P}/latin-1-$(printf "\\xa9")-directory
- insinto "${latin_1_dir}"
- echo "blah blah blah" > "${T}"/latin-1-$(printf "\\xa9")-regular-file || die
- doins "${T}"/latin-1-$(printf "\\xa9")-regular-file
- dosym latin-1-$(printf "\\xa9")-regular-file ${latin_1_dir}/latin-1-$(printf "\\xa9")-symlink || die
-
- call_has_and_best_version
-}
-
-pkg_config() {
- einfo "called pkg_config for $CATEGORY/$PF"
-}
-
-pkg_info() {
- einfo "called pkg_info for $CATEGORY/$PF"
-}
-
-pkg_preinst() {
- if ! ___eapi_best_version_and_has_version_support_-b_-d_-r; then
- # The BROOT variable is unset during pkg_* phases for EAPI 7,
- # therefore best/has_version -b is expected to fail if we attempt
- # to call it for EAPI 7 here.
- call_has_and_best_version
- fi
-}
-
-call_has_and_best_version() {
- local root_arg
- if ___eapi_best_version_and_has_version_support_-b_-d_-r; then
- root_arg="-b"
- else
- root_arg="--host-root"
- fi
- einfo "called ${EBUILD_PHASE_FUNC} for $CATEGORY/$PF"
- einfo "EPREFIX=${EPREFIX}"
- einfo "PORTAGE_OVERRIDE_EPREFIX=${PORTAGE_OVERRIDE_EPREFIX}"
- einfo "ROOT=${ROOT}"
- einfo "EROOT=${EROOT}"
- einfo "SYSROOT=${SYSROOT}"
- einfo "ESYSROOT=${ESYSROOT}"
- einfo "BROOT=${BROOT}"
- # Test that has_version and best_version work correctly with
- # prefix (involves internal ROOT -> EROOT calculation in order
- # to support ROOT override via the environment with EAPIs 3
- # and later which support prefix).
- if has_version $CATEGORY/$PN:$SLOT ; then
- einfo "has_version detects an installed instance of $CATEGORY/$PN:$SLOT"
- einfo "best_version reports that the installed instance is $(best_version $CATEGORY/$PN:$SLOT)"
- else
- einfo "has_version does not detect an installed instance of $CATEGORY/$PN:$SLOT"
- fi
- if [[ ${EPREFIX} != ${PORTAGE_OVERRIDE_EPREFIX} ]] ; then
- if has_version ${root_arg} $CATEGORY/$PN:$SLOT ; then
- einfo "has_version ${root_arg} detects an installed instance of $CATEGORY/$PN:$SLOT"
- einfo "best_version ${root_arg} reports that the installed instance is $(best_version ${root_arg} $CATEGORY/$PN:$SLOT)"
- else
- einfo "has_version ${root_arg} does not detect an installed instance of $CATEGORY/$PN:$SLOT"
- fi
- fi
-}
-
-"""
-
- _AVAILABLE_EBUILDS = {
- "dev-libs/A-1": {
- "EAPI": "5",
- "IUSE": "+flag",
- "KEYWORDS": "x86",
- "LICENSE": "GPL-2",
- "MISC_CONTENT": _INSTALL_SOMETHING,
- "RDEPEND": "flag? ( dev-libs/B[flag] )",
- },
- "dev-libs/B-1": {
- "EAPI": "5",
- "IUSE": "+flag",
- "KEYWORDS": "x86",
- "LICENSE": "GPL-2",
- "MISC_CONTENT": _INSTALL_SOMETHING,
- },
- "dev-libs/C-1": {
- "EAPI": "7",
- "KEYWORDS": "~x86",
- "RDEPEND": "dev-libs/D[flag]",
- "MISC_CONTENT": _INSTALL_SOMETHING,
- },
- "dev-libs/D-1": {
- "EAPI": "7",
- "KEYWORDS": "~x86",
- "IUSE": "flag",
- "MISC_CONTENT": _INSTALL_SOMETHING,
- },
- "virtual/foo-0": {
- "EAPI": "5",
- "KEYWORDS": "x86",
- "LICENSE": "GPL-2",
- },
- }
-
- installed = {
- "dev-libs/A-1": {
- "EAPI": "5",
- "IUSE": "+flag",
- "KEYWORDS": "x86",
- "LICENSE": "GPL-2",
- "RDEPEND": "flag? ( dev-libs/B[flag] )",
- "USE": "flag",
- },
- "dev-libs/B-1": {
- "EAPI": "5",
- "IUSE": "+flag",
- "KEYWORDS": "x86",
- "LICENSE": "GPL-2",
- "USE": "flag",
- },
- "dev-libs/depclean-me-1": {
- "EAPI": "5",
- "IUSE": "",
- "KEYWORDS": "x86",
- "LICENSE": "GPL-2",
- "USE": "",
- },
- "app-misc/depclean-me-1": {
- "EAPI": "5",
- "IUSE": "",
- "KEYWORDS": "x86",
- "LICENSE": "GPL-2",
- "RDEPEND": "dev-libs/depclean-me",
- "USE": "",
- },
- }
-
- metadata_xml_files = (
- (
- "dev-libs/A",
- {
- "flags": "<flag name='flag'>Description of how USE='flag' affects this package</flag>",
- },
- ),
- (
- "dev-libs/B",
- {
- "flags": "<flag name='flag'>Description of how USE='flag' affects this package</flag>",
- },
- ),
- )
- try:
- with open(local_path, "rb") as f:
- return f.read()
- except OSError:
- raise KeyError(request_path)
-
-
-def test_simple_emerge():
- debug = False
-
- for binpkg_format in SUPPORTED_GENTOO_BINPKG_FORMATS:
- playground = ResolverPlayground(
- ebuilds=_AVAILABLE_EBUILDS,
- installed=_INSTALLED_EBUILDS,
- debug=debug,
- user_config={
- "make.conf": (f'BINPKG_FORMAT="{binpkg_format}"',),
- },
- )
-
- loop = asyncio._wrap_loop()
- loop.run_until_complete(
- asyncio.ensure_future(
- _async_test_simple(playground, _METADATA_XML_FILES, loop=loop),
- loop=loop,
- )
- )
-
-
-async def _async_test_simple(playground, metadata_xml_files, loop):
- debug = playground.debug
- settings = playground.settings
- eprefix = settings["EPREFIX"]
- eroot = settings["EROOT"]
- trees = playground.trees
- portdb = trees[eroot]["porttree"].dbapi
- test_repo_location = settings.repositories["test_repo"].location
- var_cache_edb = os.path.join(eprefix, "var", "cache", "edb")
- cachedir = os.path.join(var_cache_edb, "dep")
- cachedir_pregen = os.path.join(test_repo_location, "metadata", "md5-cache")
-
- portage_python = portage._python_interpreter
- dispatch_conf_cmd = (
- portage_python,
- "-b",
- "-Wd",
- os.path.join(cnf_sbindir, "dispatch-conf"),
- )
- ebuild_cmd = (portage_python, "-b", "-Wd", os.path.join(cnf_bindir, "ebuild"))
- egencache_cmd = (
- portage_python,
- "-b",
- "-Wd",
- os.path.join(cnf_bindir, "egencache"),
- "--repo",
- "test_repo",
- "--repositories-configuration",
- settings.repositories.config_string(),
- )
- emerge_cmd = (portage_python, "-b", "-Wd", os.path.join(cnf_bindir, "emerge"))
- emaint_cmd = (portage_python, "-b", "-Wd", os.path.join(cnf_sbindir, "emaint"))
- env_update_cmd = (
- portage_python,
- "-b",
- "-Wd",
- os.path.join(cnf_sbindir, "env-update"),
- )
- etc_update_cmd = (BASH_BINARY, os.path.join(cnf_sbindir, "etc-update"))
- fixpackages_cmd = (
- portage_python,
- "-b",
- "-Wd",
- os.path.join(cnf_sbindir, "fixpackages"),
- )
- portageq_cmd = (
- portage_python,
- "-b",
- "-Wd",
- os.path.join(cnf_bindir, "portageq"),
- )
- quickpkg_cmd = (
- portage_python,
- "-b",
- "-Wd",
- os.path.join(cnf_bindir, "quickpkg"),
- )
- regenworld_cmd = (
- portage_python,
- "-b",
- "-Wd",
- os.path.join(cnf_sbindir, "regenworld"),
- )
-
- rm_binary = find_binary("rm")
- assert rm_binary is not None, "rm command not found"
- rm_cmd = (rm_binary,)
-
- egencache_extra_args = []
- if _have_python_xml():
- egencache_extra_args.append("--update-use-local-desc")
-
- test_ebuild = portdb.findname("dev-libs/A-1")
- assert test_ebuild is not None
-
- cross_prefix = os.path.join(eprefix, "cross_prefix")
- cross_root = os.path.join(eprefix, "cross_root")
- cross_eroot = os.path.join(cross_root, eprefix.lstrip(os.sep))
-
- binhost_dir = os.path.join(eprefix, "binhost")
- binhost_address = "127.0.0.1"
- binhost_remote_path = "/binhost"
- binhost_server = AsyncHTTPServer(
- binhost_address, BinhostContentMap(binhost_remote_path, binhost_dir), loop
- ).__enter__()
- binhost_uri = "http://{address}:{port}{path}".format(
- address=binhost_address,
- port=binhost_server.server_port,
- path=binhost_remote_path,
- )
-
- binpkg_format = settings.get("BINPKG_FORMAT", SUPPORTED_GENTOO_BINPKG_FORMATS[0])
- assert binpkg_format in ("xpak", "gpkg")
- if binpkg_format == "xpak":
- foo_filename = "foo-0-1.xpak"
- elif binpkg_format == "gpkg":
- foo_filename = "foo-0-1.gpkg.tar"
-
- test_commands = ()
-
- if hasattr(argparse.ArgumentParser, "parse_intermixed_args"):
- test_commands += (emerge_cmd + ("--oneshot", "dev-libs/A", "-v", "dev-libs/A"),)
-
- test_commands += (
- emerge_cmd
- + (
- "--usepkgonly",
- "--root",
- cross_root,
- "--quickpkg-direct=y",
- "--quickpkg-direct-root",
- "/",
- "dev-libs/A",
- ),
- emerge_cmd
- + (
- "--usepkgonly",
- "--quickpkg-direct=y",
- "--quickpkg-direct-root",
- cross_root,
- "dev-libs/A",
- ),
- env_update_cmd,
- portageq_cmd
- + (
- "envvar",
- "-v",
- "CONFIG_PROTECT",
- "EROOT",
- "PORTAGE_CONFIGROOT",
- "PORTAGE_TMPDIR",
- "USERLAND",
- ),
- etc_update_cmd,
- dispatch_conf_cmd,
- emerge_cmd + ("--version",),
- emerge_cmd + ("--info",),
- emerge_cmd + ("--info", "--verbose"),
- emerge_cmd + ("--list-sets",),
- emerge_cmd + ("--check-news",),
- rm_cmd + ("-rf", cachedir),
- rm_cmd + ("-rf", cachedir_pregen),
- emerge_cmd + ("--regen",),
- rm_cmd + ("-rf", cachedir),
- ({"FEATURES": "metadata-transfer"},) + emerge_cmd + ("--regen",),
- rm_cmd + ("-rf", cachedir),
- ({"FEATURES": "metadata-transfer"},) + emerge_cmd + ("--regen",),
- rm_cmd + ("-rf", cachedir),
- egencache_cmd + ("--update",) + tuple(egencache_extra_args),
- ({"FEATURES": "metadata-transfer"},) + emerge_cmd + ("--metadata",),
- rm_cmd + ("-rf", cachedir),
- ({"FEATURES": "metadata-transfer"},) + emerge_cmd + ("--metadata",),
- emerge_cmd + ("--metadata",),
- rm_cmd + ("-rf", cachedir),
- emerge_cmd + ("--oneshot", "virtual/foo"),
- lambda: self.assertFalse(
- os.path.exists(os.path.join(pkgdir, "virtual", "foo", foo_filename))
- ),
- ({"FEATURES": "unmerge-backup"},) + emerge_cmd + ("--unmerge", "virtual/foo"),
- lambda: self.assertTrue(
- os.path.exists(os.path.join(pkgdir, "virtual", "foo", foo_filename))
- ),
- emerge_cmd + ("--pretend", "dev-libs/A"),
- ebuild_cmd + (test_ebuild, "manifest", "clean", "package", "merge"),
- emerge_cmd + ("--pretend", "--tree", "--complete-graph", "dev-libs/A"),
- emerge_cmd + ("-p", "dev-libs/B"),
- emerge_cmd + ("-p", "--newrepo", "dev-libs/B"),
- emerge_cmd
- + (
- "-B",
- "dev-libs/B",
- ),
- emerge_cmd
- + (
- "--oneshot",
- "--usepkg",
- "dev-libs/B",
- ),
- # trigger clean prior to pkg_pretend as in bug #390711
- ebuild_cmd + (test_ebuild, "unpack"),
- emerge_cmd
- + (
- "--oneshot",
- "dev-libs/A",
- ),
- emerge_cmd
- + (
- "--noreplace",
- "dev-libs/A",
- ),
- emerge_cmd
- + (
- "--config",
- "dev-libs/A",
- ),
- emerge_cmd + ("--info", "dev-libs/A", "dev-libs/B"),
- emerge_cmd + ("--pretend", "--depclean", "--verbose", "dev-libs/B"),
- emerge_cmd
- + (
- "--pretend",
- "--depclean",
- ),
- emerge_cmd + ("--depclean",),
- quickpkg_cmd
- + (
- "--include-config",
- "y",
- "dev-libs/A",
- ),
- # Test bug #523684, where a file renamed or removed by the
- # admin forces replacement files to be merged with config
- # protection.
- lambda: self.assertEqual(
- 0,
- len(
- list(
- find_updated_config_files(
- eroot, shlex_split(settings["CONFIG_PROTECT"])
- )
- )
- ),
- ),
- lambda: os.unlink(os.path.join(eprefix, "etc", "A-0")),
- emerge_cmd + ("--usepkgonly", "dev-libs/A"),
- lambda: self.assertEqual(
- 1,
- len(
- list(
- find_updated_config_files(
- eroot, shlex_split(settings["CONFIG_PROTECT"])
- )
- )
- ),
- ),
- emaint_cmd + ("--check", "all"),
- emaint_cmd + ("--fix", "all"),
- fixpackages_cmd,
- regenworld_cmd,
- portageq_cmd + ("match", eroot, "dev-libs/A"),
- portageq_cmd + ("best_visible", eroot, "dev-libs/A"),
- portageq_cmd + ("best_visible", eroot, "binary", "dev-libs/A"),
- portageq_cmd + ("contents", eroot, "dev-libs/A-1"),
- portageq_cmd
- + ("metadata", eroot, "ebuild", "dev-libs/A-1", "EAPI", "IUSE", "RDEPEND"),
- portageq_cmd
- + ("metadata", eroot, "binary", "dev-libs/A-1", "EAPI", "USE", "RDEPEND"),
- portageq_cmd
- + (
- "metadata",
- eroot,
- "installed",
- "dev-libs/A-1",
- "EAPI",
- "USE",
- "RDEPEND",
- ),
- portageq_cmd + ("owners", eroot, eroot + "usr"),
- emerge_cmd + ("-p", eroot + "usr"),
- emerge_cmd + ("-p", "--unmerge", "-q", eroot + "usr"),
- emerge_cmd + ("--unmerge", "--quiet", "dev-libs/A"),
- emerge_cmd + ("-C", "--quiet", "dev-libs/B"),
- # If EMERGE_DEFAULT_OPTS contains --autounmask=n, then --autounmask
- # must be specified with --autounmask-continue.
- ({"EMERGE_DEFAULT_OPTS": "--autounmask=n"},)
- + emerge_cmd
- + (
- "--autounmask",
- "--autounmask-continue",
- "dev-libs/C",
- ),
- # Verify that the above --autounmask-continue command caused
- # USE=flag to be applied correctly to dev-libs/D.
- portageq_cmd + ("match", eroot, "dev-libs/D[flag]"),
- # Test cross-prefix usage, including chpathtool for binpkgs.
- # EAPI 7
- ({"EPREFIX": cross_prefix},) + emerge_cmd + ("dev-libs/C",),
- ({"EPREFIX": cross_prefix},)
- + portageq_cmd
- + ("has_version", cross_prefix, "dev-libs/C"),
- ({"EPREFIX": cross_prefix},)
- + portageq_cmd
- + ("has_version", cross_prefix, "dev-libs/D"),
- ({"ROOT": cross_root},) + emerge_cmd + ("dev-libs/D",),
- portageq_cmd + ("has_version", cross_eroot, "dev-libs/D"),
- # EAPI 5
- ({"EPREFIX": cross_prefix},) + emerge_cmd + ("--usepkgonly", "dev-libs/A"),
- ({"EPREFIX": cross_prefix},)
- + portageq_cmd
- + ("has_version", cross_prefix, "dev-libs/A"),
- ({"EPREFIX": cross_prefix},)
- + portageq_cmd
- + ("has_version", cross_prefix, "dev-libs/B"),
- ({"EPREFIX": cross_prefix},) + emerge_cmd + ("-C", "--quiet", "dev-libs/B"),
- ({"EPREFIX": cross_prefix},) + emerge_cmd + ("-C", "--quiet", "dev-libs/A"),
- ({"EPREFIX": cross_prefix},) + emerge_cmd + ("dev-libs/A",),
- ({"EPREFIX": cross_prefix},)
- + portageq_cmd
- + ("has_version", cross_prefix, "dev-libs/A"),
- ({"EPREFIX": cross_prefix},)
- + portageq_cmd
- + ("has_version", cross_prefix, "dev-libs/B"),
- # Test ROOT support
- ({"ROOT": cross_root},) + emerge_cmd + ("dev-libs/B",),
- portageq_cmd + ("has_version", cross_eroot, "dev-libs/B"),
- )
-
- # Test binhost support if FETCHCOMMAND is available.
- binrepos_conf_file = os.path.join(os.sep, eprefix, BINREPOS_CONF_FILE)
- with open(binrepos_conf_file, "w") as f:
- f.write("[test-binhost]\n")
- f.write(f"sync-uri = {binhost_uri}\n")
- fetchcommand = portage.util.shlex_split(playground.settings["FETCHCOMMAND"])
- fetch_bin = portage.process.find_binary(fetchcommand[0])
- if fetch_bin is not None:
- test_commands = test_commands + (
- lambda: os.rename(pkgdir, binhost_dir),
- emerge_cmd + ("-e", "--getbinpkgonly", "dev-libs/A"),
- lambda: shutil.rmtree(pkgdir),
- lambda: os.rename(binhost_dir, pkgdir),
- # Remove binrepos.conf and test PORTAGE_BINHOST.
- lambda: os.unlink(binrepos_conf_file),
- lambda: os.rename(pkgdir, binhost_dir),
- ({"PORTAGE_BINHOST": binhost_uri},)
- + emerge_cmd
- + ("-fe", "--getbinpkgonly", "dev-libs/A"),
- lambda: shutil.rmtree(pkgdir),
- lambda: os.rename(binhost_dir, pkgdir),
- )
-
- distdir = playground.distdir
- pkgdir = playground.pkgdir
- fake_bin = os.path.join(eprefix, "bin")
- portage_tmpdir = os.path.join(eprefix, "var", "tmp", "portage")
- profile_path = settings.profile_path
- user_config_dir = os.path.join(os.sep, eprefix, USER_CONFIG_PATH)
-
- path = os.environ.get("PATH")
- if path is not None and not path.strip():
- path = None
- if path is None:
- path = ""
- else:
- path = ":" + path
- path = fake_bin + path
-
- pythonpath = os.environ.get("PYTHONPATH")
- if pythonpath is not None and not pythonpath.strip():
- pythonpath = None
- if pythonpath is not None and pythonpath.split(":")[0] == PORTAGE_PYM_PATH:
- pass
- else:
- if pythonpath is None:
- pythonpath = ""
- else:
- pythonpath = ":" + pythonpath
- pythonpath = PORTAGE_PYM_PATH + pythonpath
-
- env = {
- "PORTAGE_OVERRIDE_EPREFIX": eprefix,
- "CLEAN_DELAY": "0",
- "DISTDIR": distdir,
- "EMERGE_WARNING_DELAY": "0",
- "INFODIR": "",
- "INFOPATH": "",
- "PATH": path,
- "PKGDIR": pkgdir,
- "PORTAGE_INST_GID": str(os.getgid()), # str(portage.data.portage_gid),
- "PORTAGE_INST_UID": str(os.getuid()), # str(portage.data.portage_uid),
- "PORTAGE_PYTHON": portage_python,
- "PORTAGE_REPOSITORIES": settings.repositories.config_string(),
- "PORTAGE_TMPDIR": portage_tmpdir,
- "PORTAGE_LOGDIR": portage_tmpdir,
- "PYTHONDONTWRITEBYTECODE": os.environ.get("PYTHONDONTWRITEBYTECODE", ""),
- "PYTHONPATH": pythonpath,
- "__PORTAGE_TEST_PATH_OVERRIDE": fake_bin,
- }
-
- if "__PORTAGE_TEST_HARDLINK_LOCKS" in os.environ:
- env["__PORTAGE_TEST_HARDLINK_LOCKS"] = os.environ[
- "__PORTAGE_TEST_HARDLINK_LOCKS"
- ]
-
- updates_dir = os.path.join(test_repo_location, "profiles", "updates")
- dirs = [
- cachedir,
- cachedir_pregen,
- cross_eroot,
- cross_prefix,
- distdir,
- fake_bin,
- portage_tmpdir,
- updates_dir,
- user_config_dir,
- var_cache_edb,
- ]
- etc_symlinks = ("dispatch-conf.conf", "etc-update.conf")
- # 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)
- true_symlinks = ["find", "prepstrip", "sed", "scanelf"]
- true_binary = find_binary("true")
- assert true_binary is not None, "true command not found"
- try:
- for d in dirs:
- ensure_dirs(d)
- for x in true_symlinks:
- os.symlink(true_binary, os.path.join(fake_bin, x))
- for x in etc_symlinks:
- os.symlink(os.path.join(cnf_etc_path, x), os.path.join(eprefix, "etc", x))
- with open(os.path.join(var_cache_edb, "counter"), "wb") as f:
- f.write(b"100")
- # non-empty system set keeps --depclean quiet
- with open(os.path.join(profile_path, "packages"), "w") as f:
- f.write("*dev-libs/token-system-pkg")
- for cp, xml_data in metadata_xml_files:
- with open(os.path.join(test_repo_location, cp, "metadata.xml"), "w") as f:
- f.write(playground.metadata_xml_template % xml_data)
- with open(os.path.join(updates_dir, "1Q-2010"), "w") as f:
- f.write(
- """
-slotmove =app-doc/pms-3 2 3
-move dev-util/git dev-vcs/git
-"""
- )
-
- if debug:
- # The subprocess inherits both stdout and stderr, for
- # debugging purposes.
- stdout = None
- else:
- # The subprocess inherits stderr so that any warnings
- # triggered by python -Wd will be visible.
- stdout = subprocess.PIPE
-
- for idx, args in enumerate(test_commands):
- if hasattr(args, "__call__"):
- args()
- continue
-
- if isinstance(args[0], dict):
- local_env = env.copy()
- local_env.update(args[0])
- args = args[1:]
- else:
- local_env = env
-
- # with self.subTest(cmd=args, i=idx):
- proc = await asyncio.create_subprocess_exec(
- *args, env=local_env, stderr=None, stdout=stdout
- )
-
- if debug:
- await proc.wait()
- else:
- output, _err = await proc.communicate()
- await proc.wait()
- if proc.returncode != os.EX_OK:
- portage.writemsg(output)
-
- assert os.EX_OK == proc.returncode, f"emerge failed with args {args}"
- finally:
- binhost_server.__exit__(None, None, None)
- playground.cleanup()
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/emerge/
@ 2023-10-30 3:14 Sam James
0 siblings, 0 replies; 38+ messages in thread
From: Sam James @ 2023-10-30 3:14 UTC (permalink / raw
To: gentoo-commits
commit: a807ee1838d44b704401c3b0ff4424ad817b0335
Author: David Palao <david.palao <AT> gmail <DOT> com>
AuthorDate: Thu Oct 26 14:15:27 2023 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Oct 30 03:14:25 2023 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=a807ee18
tests/emerge/meson.build: replace test_simple with test_baseline
...since the file had been renamed.
Signed-off-by: David Palao <david.palao <AT> gmail.com>
Closes: https://github.com/gentoo/portage/pull/1146
Signed-off-by: Sam James <sam <AT> gentoo.org>
lib/portage/tests/emerge/meson.build | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/portage/tests/emerge/meson.build b/lib/portage/tests/emerge/meson.build
index 3c45cd380b..b42945123c 100644
--- a/lib/portage/tests/emerge/meson.build
+++ b/lib/portage/tests/emerge/meson.build
@@ -5,7 +5,7 @@ py.install_sources(
'test_emerge_blocker_file_collision.py',
'test_emerge_slot_abi.py',
'test_global_updates.py',
- 'test_simple.py',
+ 'test_baseline.py',
'__init__.py',
'__test__.py',
],
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/emerge/
@ 2024-01-03 19:59 Sam James
0 siblings, 0 replies; 38+ messages in thread
From: Sam James @ 2024-01-03 19:59 UTC (permalink / raw
To: gentoo-commits
commit: 14ec6c259ca5bd7439ede37216bbb0d160e909e9
Author: Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Wed Jan 3 04:22:24 2024 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Wed Jan 3 19:59:51 2024 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=14ec6c25
tests: add getbinpkg file:// sync testcase for BUILD_ID
We do a bit of a strange dance here where we:
1) create a binpkg;
2) shift the PKGDIR so that it becomes a "remote" one for use with file:///;
3) try to merge the binpkg but defer checking the exit status;
4) check if the downloaded filename was unnecessarily incremented (-2). if it is,
fail.
5) check the deferred exit status from 3) so that we fail if the merge failed
for another reason (e.g. failed injection).
Bug: https://bugs.gentoo.org/921208
Signed-off-by: Sam James <sam <AT> gentoo.org>
lib/portage/tests/emerge/meson.build | 1 +
lib/portage/tests/emerge/test_binpkg_fetch.py | 226 ++++++++++++++++++++++++++
2 files changed, 227 insertions(+)
diff --git a/lib/portage/tests/emerge/meson.build b/lib/portage/tests/emerge/meson.build
index 0d34cbecf7..0e0a419740 100644
--- a/lib/portage/tests/emerge/meson.build
+++ b/lib/portage/tests/emerge/meson.build
@@ -1,6 +1,7 @@
py.install_sources(
[
'test_actions.py',
+ 'test_binpkg_fetch.py',
'test_config_protect.py',
'test_emerge_blocker_file_collision.py',
'test_emerge_slot_abi.py',
diff --git a/lib/portage/tests/emerge/test_binpkg_fetch.py b/lib/portage/tests/emerge/test_binpkg_fetch.py
new file mode 100644
index 0000000000..731711bad8
--- /dev/null
+++ b/lib/portage/tests/emerge/test_binpkg_fetch.py
@@ -0,0 +1,226 @@
+# Copyright 2024 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+import shutil
+import subprocess
+import sys
+import tempfile
+
+import portage
+from portage import _unicode_decode, os
+from portage.const import (
+ PORTAGE_PYM_PATH,
+ USER_CONFIG_PATH,
+)
+from portage.process import find_binary
+from portage.tests import TestCase
+from portage.tests.resolver.ResolverPlayground import ResolverPlayground
+from portage.util import ensure_dirs
+
+
+class BinpkgFetchtestCase(TestCase):
+ def testLocalFilePkgSyncUpdate(self):
+ """
+ Check handling of local file:// sync-uri and unnecessary BUILD_ID
+ increments (bug #921208).
+ """
+ debug = False
+
+ ebuilds = {
+ "dev-libs/A-1::local": {
+ "EAPI": "7",
+ "SLOT": "0",
+ },
+ }
+
+ playground = ResolverPlayground(ebuilds=ebuilds, debug=debug)
+ settings = playground.settings
+ eprefix = settings["EPREFIX"]
+ eroot = settings["EROOT"]
+ trees = playground.trees
+ bindb = trees[eroot]["bintree"].dbapi
+ var_cache_edb = os.path.join(eprefix, "var", "cache", "edb")
+ user_config_dir = os.path.join(eprefix, USER_CONFIG_PATH)
+
+ portage_python = portage._python_interpreter
+ emerge_cmd = (
+ portage_python,
+ "-b",
+ "-Wd",
+ os.path.join(str(self.bindir), "emerge"),
+ )
+
+ tmppkgdir = tempfile.TemporaryDirectory()
+ tmppkgdir_suffix = os.path.join(tmppkgdir.name, "binpkg")
+
+ test_commands = (
+ # Create a trivial binpkg first.
+ emerge_cmd
+ + (
+ "--oneshot",
+ "--verbose",
+ "--buildpkg",
+ "dev-libs/A",
+ ),
+ # Copy to a new PKGDIR which we'll use as PORTAGE_BINHOST then delete the old PKGDIR.
+ (
+ (
+ lambda: shutil.copytree(bindb.bintree.pkgdir, tmppkgdir_suffix)
+ or True,
+ )
+ ),
+ (
+ (
+ lambda: os.unlink(
+ os.path.join(
+ bindb.bintree.pkgdir, "dev-libs", "A", "A-1-1.gpkg.tar"
+ )
+ )
+ or True,
+ )
+ ),
+ )
+ test_commands_nonfatal = (
+ # This should succeed if we've correctly saved it as A-1-1.gpkg.tar, not
+ # A-1-2.gpkg.tar, and then also try to unpack the right filename, but
+ # we defer checking the exit code to get a better error if the binpkg
+ # was downloaded with the wrong filename.
+ emerge_cmd
+ + (
+ "--oneshot",
+ "--verbose",
+ "--getbinpkgonly",
+ "dev-libs/A",
+ ),
+ )
+ test_commands_final = (
+ # Check whether the downloaded binpkg in PKGDIR has the correct
+ # filename (-1) or an unnecessarily-incremented one (-2).
+ (
+ lambda: os.path.exists(
+ os.path.join(
+ bindb.bintree.pkgdir, "dev-libs", "A", "A-1-1.gpkg.tar"
+ )
+ ),
+ ),
+ )
+
+ fake_bin = os.path.join(eprefix, "bin")
+ portage_tmpdir = os.path.join(eprefix, "var", "tmp", "portage")
+
+ path = settings.get("PATH")
+ if path is not None and not path.strip():
+ path = None
+ if path is None:
+ path = ""
+ else:
+ path = ":" + path
+ path = fake_bin + path
+
+ pythonpath = os.environ.get("PYTHONPATH")
+ if pythonpath is not None and not pythonpath.strip():
+ pythonpath = None
+ if pythonpath is not None and pythonpath.split(":")[0] == PORTAGE_PYM_PATH:
+ pass
+ else:
+ if pythonpath is None:
+ pythonpath = ""
+ else:
+ pythonpath = ":" + pythonpath
+ pythonpath = PORTAGE_PYM_PATH + pythonpath
+
+ env = {
+ "PORTAGE_OVERRIDE_EPREFIX": eprefix,
+ "PATH": path,
+ "PORTAGE_PYTHON": portage_python,
+ "PORTAGE_REPOSITORIES": settings.repositories.config_string(),
+ "PYTHONDONTWRITEBYTECODE": os.environ.get("PYTHONDONTWRITEBYTECODE", ""),
+ "PYTHONPATH": pythonpath,
+ "PORTAGE_INST_GID": str(os.getgid()),
+ "PORTAGE_INST_UID": str(os.getuid()),
+ "FEATURES": "-pkgdir-index-trusted",
+ }
+
+ dirs = [
+ playground.distdir,
+ fake_bin,
+ portage_tmpdir,
+ user_config_dir,
+ var_cache_edb,
+ ]
+
+ true_symlinks = ["chown", "chgrp"]
+
+ needed_binaries = {
+ "true": (find_binary("true"), True),
+ }
+
+ def run_commands(test_commands, require_success=True):
+ all_successful = True
+
+ for i, args in enumerate(test_commands):
+ if hasattr(args[0], "__call__"):
+ if require_success:
+ self.assertTrue(args[0](), f"callable at index {i} failed")
+ continue
+
+ if isinstance(args[0], dict):
+ local_env = env.copy()
+ local_env.update(args[0])
+ args = args[1:]
+ else:
+ local_env = env
+
+ local_env["PORTAGE_BINHOST"] = f"file:///{tmppkgdir_suffix}"
+ proc = subprocess.Popen(args, env=local_env, stdout=stdout)
+
+ if debug:
+ proc.wait()
+ else:
+ output = proc.stdout.readlines()
+ proc.wait()
+ proc.stdout.close()
+ if proc.returncode != os.EX_OK:
+ for line in output:
+ sys.stderr.write(_unicode_decode(line))
+
+ if all_successful and proc.returncode != os.EX_OK:
+ all_successful = False
+
+ if require_success:
+ self.assertEqual(
+ os.EX_OK, proc.returncode, f"emerge failed with args {args}"
+ )
+
+ return all_successful
+
+ try:
+ for d in dirs:
+ ensure_dirs(d)
+ for x in true_symlinks:
+ os.symlink(needed_binaries["true"][0], os.path.join(fake_bin, x))
+
+ with open(os.path.join(var_cache_edb, "counter"), "wb") as f:
+ f.write(b"100")
+
+ if debug:
+ # The subprocess inherits both stdout and stderr, for
+ # debugging purposes.
+ stdout = None
+ else:
+ # The subprocess inherits stderr so that any warnings
+ # triggered by python -Wd will be visible.
+ stdout = subprocess.PIPE
+
+ run_commands(test_commands)
+ deferred_success = run_commands(test_commands_nonfatal, False)
+ run_commands(test_commands_final)
+
+ # Check the return value of test_commands_nonfatal later on so
+ # we can get a better error message from test_commands_final
+ # if possible.
+ self.assertTrue(deferred_success, f"{test_commands_nonfatal} failed")
+ finally:
+ playground.debug = False
+ playground.cleanup()
+ tmppkgdir.cleanup()
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/emerge/
@ 2024-02-24 3:36 Zac Medico
0 siblings, 0 replies; 38+ messages in thread
From: Zac Medico @ 2024-02-24 3:36 UTC (permalink / raw
To: gentoo-commits
commit: 01d06eb1d9dc8c4b16cbc9a6567ed0c07df5901a
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sat Feb 24 02:45:58 2024 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sat Feb 24 03:28:24 2024 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=01d06eb1
Fix python 3.9 CI jobs since 92ff02b9189f
Use emerge -e to fix this error we've seen since
92ff02b9189f for python 3.9 CI jobs:
https://github.com/gentoo/portage/actions/runs/8014796128/job/21893963019
test_portage_baseline[binhost emerge-gpkg] - AssertionError: 'emerge' failed with args '('-e', '--getbinpkgonly', 'dev-libs/A')'
emerge: there are no binary packages to satisfy "dev-libs/B[flag]".
(dependency required by "dev-libs/A-1::test_repo" [binary])
(dependency required by "dev-libs/A" [argument])
Fixes: 92ff02b9189f ("emerge: Skip installed packages with emptytree in depgraph selection")
Bug: https://bugs.gentoo.org/651018
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
lib/portage/tests/emerge/conftest.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/portage/tests/emerge/conftest.py b/lib/portage/tests/emerge/conftest.py
index d9aec7041e..580d1e09ab 100644
--- a/lib/portage/tests/emerge/conftest.py
+++ b/lib/portage/tests/emerge/conftest.py
@@ -805,7 +805,7 @@ def _generate_all_baseline_commands(playground, binhost):
test_commands["binhost emerge"] = Noop()
else:
# The next emerge has been added to split this test from the rest:
- make_package = Emerge("--buildpkg", "dev-libs/A")
+ make_package = Emerge("-e", "--buildpkg", "dev-libs/A")
getbinpkgonly = Emerge(
"-e",
"--getbinpkgonly",
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/emerge/
@ 2024-02-25 8:25 Sam James
0 siblings, 0 replies; 38+ messages in thread
From: Sam James @ 2024-02-25 8:25 UTC (permalink / raw
To: gentoo-commits
commit: 8a2f1d14788d107ec54dc53c9ef1cf00ee310d51
Author: Gábor Oszkár Dénes <gaboroszkar <AT> protonmail <DOT> com>
AuthorDate: Sat Feb 24 20:48:05 2024 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sun Feb 25 08:25:06 2024 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=8a2f1d14
test_baseline: Improve robustness with cleanup
The baseline tests need to cleanup the ResolverPlayground
after each testcase, with each different parametrization.
This is ensured by making the scope of the playground
fixture the function instead of the module. With module
the cleanup only happens before/after the switch from/to
xpak and gpkg.
Signed-off-by: Gábor Oszkár Dénes <gaboroszkar <AT> protonmail.com>
Closes: https://github.com/gentoo/portage/pull/1281
Signed-off-by: Sam James <sam <AT> gentoo.org>
lib/portage/tests/emerge/conftest.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/portage/tests/emerge/conftest.py b/lib/portage/tests/emerge/conftest.py
index 580d1e09ab..356e09879c 100644
--- a/lib/portage/tests/emerge/conftest.py
+++ b/lib/portage/tests/emerge/conftest.py
@@ -406,7 +406,7 @@ def async_loop():
yield asyncio._wrap_loop()
-@pytest.fixture(params=SUPPORTED_GENTOO_BINPKG_FORMATS, scope="module")
+@pytest.fixture(params=SUPPORTED_GENTOO_BINPKG_FORMATS, scope="function")
def playground(request, tmp_path_factory):
"""Fixture that provides instances of ``ResolverPlayground``
each one with one supported value for ``BINPKG_FORMAT``."""
^ permalink raw reply related [flat|nested] 38+ messages in thread
end of thread, other threads:[~2024-02-25 8:25 UTC | newest]
Thread overview: 38+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-30 3:14 [gentoo-commits] proj/portage:master commit in: lib/portage/tests/emerge/ Sam James
-- strict thread matches above, loose matches on Subject: below --
2024-02-25 8:25 Sam James
2024-02-24 3:36 Zac Medico
2024-01-03 19:59 Sam James
2023-10-30 3:14 Sam James
2023-10-30 3:14 Sam James
2023-10-30 3:14 Sam James
2023-10-30 3:14 Sam James
2023-10-30 3:14 Sam James
2023-10-30 3:14 Sam James
2023-10-30 3:14 Sam James
2023-10-30 3:14 Sam James
2023-10-30 3:14 Sam James
2023-10-30 3:14 Sam James
2023-10-30 3:14 Sam James
2023-10-30 3:14 Sam James
2023-10-30 3:14 Sam James
2023-10-30 3:14 Sam James
2023-10-30 3:14 Sam James
2023-10-30 3:14 Sam James
2023-10-30 3:14 Sam James
2023-10-30 3:14 Sam James
2023-10-30 3:14 Sam James
2023-10-30 3:14 Sam James
2023-10-30 3:14 Sam James
2023-10-30 3:14 Sam James
2023-10-30 3:14 Sam James
2023-10-30 3:14 Sam James
2023-05-26 15:45 Sam James
2023-05-26 15:45 Sam James
2022-09-25 19:12 Mike Gilbert
2021-01-18 12:20 Zac Medico
2020-10-17 9:21 Zac Medico
2020-10-12 18:03 Zac Medico
2020-08-03 23:28 Zac Medico
2020-08-03 19:30 Zac Medico
2020-03-08 22:29 Zac Medico
2020-03-08 7:33 Zac Medico
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox