* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/dbapi/
@ 2021-01-18 12:20 Zac Medico
0 siblings, 0 replies; 9+ messages in thread
From: Zac Medico @ 2021-01-18 12:20 UTC (permalink / raw
To: gentoo-commits
commit: be3613e562203d1d8fd7ad6001aa7db43480b2fe
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Mon Jan 18 11:31:18 2021 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Mon Jan 18 11:32:12 2021 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=be3613e5
AuxdbTestCase: Use async and await syntax
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
lib/portage/tests/dbapi/test_auxdb.py | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/lib/portage/tests/dbapi/test_auxdb.py b/lib/portage/tests/dbapi/test_auxdb.py
index 1029de70d..c8db65d34 100644
--- a/lib/portage/tests/dbapi/test_auxdb.py
+++ b/lib/portage/tests/dbapi/test_auxdb.py
@@ -1,10 +1,9 @@
-# Copyright 2020 Gentoo Authors
+# Copyright 2020-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
from portage.tests import TestCase
from portage.tests.resolver.ResolverPlayground import ResolverPlayground
from portage.util.futures import asyncio
-from portage.util.futures.compat_coroutine import coroutine, coroutine_return
from portage.util.futures.executor.fork import ForkExecutor
@@ -65,7 +64,7 @@ class AuxdbTestCase(TestCase):
def test_func():
loop = asyncio._wrap_loop()
return loop.run_until_complete(self._test_mod_async(
- ebuilds, ebuild_inherited, eclass_defined_phases, eclass_depend, portdb, loop=loop))
+ ebuilds, ebuild_inherited, eclass_defined_phases, eclass_depend, portdb))
self.assertTrue(test_func())
@@ -91,14 +90,13 @@ class AuxdbTestCase(TestCase):
self.assertEqual(auxdb[cpv]['RESTRICT'], 'test')
- @coroutine
- def _test_mod_async(self, ebuilds, ebuild_inherited, eclass_defined_phases, eclass_depend, portdb, loop=None):
+ async def _test_mod_async(self, ebuilds, ebuild_inherited, eclass_defined_phases, eclass_depend, portdb):
for cpv, metadata in ebuilds.items():
- defined_phases, depend, eapi, inherited = yield portdb.async_aux_get(cpv, ['DEFINED_PHASES', 'DEPEND', 'EAPI', 'INHERITED'], loop=loop)
+ defined_phases, depend, eapi, inherited = await portdb.async_aux_get(cpv, ['DEFINED_PHASES', 'DEPEND', 'EAPI', 'INHERITED'])
self.assertEqual(defined_phases, eclass_defined_phases)
self.assertEqual(depend, eclass_depend)
self.assertEqual(eapi, metadata['EAPI'])
self.assertEqual(frozenset(inherited.split()), ebuild_inherited)
- coroutine_return(True)
+ return True
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/dbapi/
@ 2022-09-25 19:12 Mike Gilbert
0 siblings, 0 replies; 9+ messages in thread
From: Mike Gilbert @ 2022-09-25 19:12 UTC (permalink / raw
To: gentoo-commits
commit: 98292b4077c0b75d7424955e0affa64beb86a2b7
Author: David Palao <david.palao <AT> gmail <DOT> com>
AuthorDate: Fri Sep 23 13:41:02 2022 +0000
Commit: Mike Gilbert <floppym <AT> gentoo <DOT> org>
CommitDate: Sun Sep 25 19:07:49 2022 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=98292b40
test(bintree): added some UTs for binarytree.__init__
Not very exhaustive, though, but they will help in future refactorings.
Signed-off-by: David Palao <david.palao <AT> gmail.com>
Signed-off-by: Mike Gilbert <floppym <AT> gentoo.org>
lib/portage/tests/dbapi/test_bintree.py | 54 +++++++++++++++++++++++++++++++++
1 file changed, 54 insertions(+)
diff --git a/lib/portage/tests/dbapi/test_bintree.py b/lib/portage/tests/dbapi/test_bintree.py
new file mode 100644
index 000000000..14b89dfc0
--- /dev/null
+++ b/lib/portage/tests/dbapi/test_bintree.py
@@ -0,0 +1,54 @@
+# Copyright 2020-2022 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+from unittest.mock import MagicMock
+
+from portage.tests import TestCase
+
+from portage.dbapi.bintree import binarytree
+
+
+class BinarytreeTestCase(TestCase):
+ def test_required_init_params(self):
+ with self.assertRaises(TypeError) as cm:
+ binarytree()
+ self.assertEqual(str(cm.exception), "pkgdir parameter is required")
+ with self.assertRaises(TypeError) as cm:
+ binarytree(pkgdir="/tmp")
+ self.assertEqual(str(cm.exception), "settings parameter is required")
+
+ def test_init_with_legacy_params_warns(self):
+ with self.assertWarns(DeprecationWarning):
+ binarytree(_unused=None, pkgdir="/tmp", settings=MagicMock())
+ with self.assertWarns(DeprecationWarning):
+ binarytree(virtual=None, pkgdir="/tmp", settings=MagicMock())
+
+ def test_instance_has_required_attrs(self):
+ # Quite smoky test. What would it be a better testing strategy?
+ # Not sure yet...
+ required_attrs_no_multi_instance = {
+ "pkgdir", "_multi_instance", "dbapi", "update_ents",
+ "move_slot_ent", "populated", "tree", "_binrepos_conf",
+ "_remote_has_index", "_remotepkgs", "_additional_pkgs",
+ "invalids", "settings", "_pkg_paths", "_populating",
+ "_all_directory", "_pkgindex_version", "_pkgindex_hashes",
+ "_pkgindex_file", "_pkgindex_keys", "_pkgindex_aux_keys",
+ "_pkgindex_use_evaluated_keys", "_pkgindex_header",
+ "_pkgindex_header_keys", "_pkgindex_default_pkg_data",
+ "_pkgindex_inherited_keys", "_pkgindex_default_header_data",
+ "_pkgindex_translated_keys", "_pkgindex_allowed_pkg_keys",
+ }
+ no_multi_instance_settings = MagicMock()
+ no_multi_instance_settings.features = ""
+ no_multi_instance_bt = binarytree(
+ pkgdir="/tmp", settings=no_multi_instance_settings)
+ multi_instance_settings = MagicMock()
+ multi_instance_settings.features = "binpkg-multi-instance"
+ multi_instance_bt = binarytree(
+ pkgdir="/tmp", settings=multi_instance_settings)
+ for attr in required_attrs_no_multi_instance:
+ getattr(no_multi_instance_bt, attr)
+ getattr(multi_instance_bt, attr)
+ # The next attribute is the difference between multi instance
+ # and no multi instance:
+ getattr(multi_instance_bt, "_allocate_filename")
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/dbapi/
@ 2022-09-25 19:12 Mike Gilbert
0 siblings, 0 replies; 9+ messages in thread
From: Mike Gilbert @ 2022-09-25 19:12 UTC (permalink / raw
To: gentoo-commits
commit: 419f5ae0d9f0ca55279f1ad60a7dc83d8da777d6
Author: David Palao <david.palao <AT> gmail <DOT> com>
AuthorDate: Fri Sep 9 17:12:17 2022 +0000
Commit: Mike Gilbert <floppym <AT> gentoo <DOT> org>
CommitDate: Sun Sep 25 19:07:52 2022 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=419f5ae0
test(bintree): added UTs for binarytree.populate
Signed-off-by: David Palao <david.palao <AT> gmail.com>
Signed-off-by: Mike Gilbert <floppym <AT> gentoo.org>
lib/portage/tests/dbapi/test_bintree.py | 68 ++++++++++++++++++++++++++++++++-
1 file changed, 66 insertions(+), 2 deletions(-)
diff --git a/lib/portage/tests/dbapi/test_bintree.py b/lib/portage/tests/dbapi/test_bintree.py
index 14b89dfc0..d0bfa306e 100644
--- a/lib/portage/tests/dbapi/test_bintree.py
+++ b/lib/portage/tests/dbapi/test_bintree.py
@@ -1,11 +1,14 @@
-# Copyright 2020-2022 Gentoo Authors
+# Copyright 2022 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
-from unittest.mock import MagicMock
+from unittest.mock import MagicMock, patch, call
+import os
from portage.tests import TestCase
from portage.dbapi.bintree import binarytree
+from portage.localization import _
+from portage.const import BINREPOS_CONF_FILE
class BinarytreeTestCase(TestCase):
@@ -52,3 +55,64 @@ class BinarytreeTestCase(TestCase):
# The next attribute is the difference between multi instance
# and no multi instance:
getattr(multi_instance_bt, "_allocate_filename")
+
+ @patch("portage.dbapi.bintree.binarytree._populate_local")
+ def test_populate_without_updates_repos_nor_getbinspkgs(
+ self, ppopulate_local):
+ bt = binarytree(pkgdir="/tmp", settings=MagicMock())
+ ppopulate_local.return_value = {}
+ bt.populate()
+ ppopulate_local.assert_called_once_with(reindex=True)
+ self.assertFalse(bt._populating)
+ self.assertTrue(bt.populated)
+
+ @patch("portage.dbapi.bintree.binarytree._populate_local")
+ def test_populate_calls_twice_populate_local_if_updates(
+ self, ppopulate_local):
+ bt = binarytree(pkgdir="/tmp", settings=MagicMock())
+ bt.populate()
+ self.assertIn(call(reindex=True), ppopulate_local.mock_calls)
+ self.assertIn(call(), ppopulate_local.mock_calls)
+ self.assertEqual(ppopulate_local.call_count, 2)
+
+ @patch("portage.dbapi.bintree.binarytree._populate_additional")
+ @patch("portage.dbapi.bintree.binarytree._populate_local")
+ def test_populate_with_repos(
+ self, ppopulate_local, ppopulate_additional):
+ repos = ("one", "two")
+ bt = binarytree(pkgdir="/tmp", settings=MagicMock())
+ bt.populate(add_repos=repos)
+ ppopulate_additional.assert_called_once_with(repos)
+
+ @patch("portage.dbapi.bintree.BinRepoConfigLoader")
+ @patch("portage.dbapi.bintree.binarytree._populate_remote")
+ @patch("portage.dbapi.bintree.binarytree._populate_local")
+ def test_populate_with_getbinpkgs(
+ self, ppopulate_local, ppopulate_remote, pBinRepoConfigLoader):
+ refresh = "something"
+ settings = MagicMock()
+ settings.__getitem__.return_value = "/some/path"
+ bt = binarytree(pkgdir="/tmp", settings=settings)
+ bt.populate(getbinpkgs=True, getbinpkg_refresh=refresh)
+ ppopulate_remote.assert_called_once_with(getbinpkg_refresh=refresh)
+
+ @patch("portage.dbapi.bintree.writemsg")
+ @patch("portage.dbapi.bintree.BinRepoConfigLoader")
+ @patch("portage.dbapi.bintree.binarytree._populate_remote")
+ @patch("portage.dbapi.bintree.binarytree._populate_local")
+ def test_populate_with_getbinpkgs_and_not_BinRepoConfigLoader(
+ self, ppopulate_local, ppopulate_remote, pBinRepoConfigLoader,
+ pwritemsg):
+ refresh = "something"
+ settings = MagicMock()
+ portage_root = "/some/path"
+ settings.__getitem__.return_value = portage_root
+ pBinRepoConfigLoader.return_value = None
+ conf_file = os.path.join(portage_root, BINREPOS_CONF_FILE)
+ bt = binarytree(pkgdir="/tmp", settings=settings)
+ bt.populate(getbinpkgs=True, getbinpkg_refresh=refresh)
+ ppopulate_remote.assert_not_called()
+ pwritemsg.assert_called_once_with(
+ _(f"!!! {conf_file} is missing (or PORTAGE_BINHOST is unset)"
+ ", but use is requested.\n"), noiselevel=-1
+ )
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/dbapi/
@ 2023-02-19 19:19 Sam James
0 siblings, 0 replies; 9+ messages in thread
From: Sam James @ 2023-02-19 19:19 UTC (permalink / raw
To: gentoo-commits
commit: 22406d51ccaa743da4fd4c45e0fbaca09ffb1eba
Author: Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Sat Feb 18 12:42:09 2023 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sun Feb 19 19:19:44 2023 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=22406d51
tests: dbapi: add basic metadata test (IDEPEND)
In f9f55b42f1602e79a5541afcace6b2a30af394e8, I fixed the generation of IDEPEND
metadata. It turns out we don't have suitable test coverage here.
Add a basic test to make sure that:
- IDEPEND survives cache generation and appears in the resultant cache;
- IDEPEND accumulates across inherits (which is what the actual bug was, in a sense).
This test fails with the fix for the bug (f9f55b42f1602e79a5541afcace6b2a30af394e8) reverted.
We need to be testing various bits of newer EAPIs more (not least to ensure
we don't forget to update one of the various parts of Portage when adding a new one)
but this is a start.
Bug: https://bugs.gentoo.org/870295
See: f9f55b42f1602e79a5541afcace6b2a30af394e8
Signed-off-by: Sam James <sam <AT> gentoo.org>
lib/portage/tests/dbapi/test_portdb_cache.py | 27 +++++++++++++++++++++++++--
1 file changed, 25 insertions(+), 2 deletions(-)
diff --git a/lib/portage/tests/dbapi/test_portdb_cache.py b/lib/portage/tests/dbapi/test_portdb_cache.py
index bda43643a..a55377b6b 100644
--- a/lib/portage/tests/dbapi/test_portdb_cache.py
+++ b/lib/portage/tests/dbapi/test_portdb_cache.py
@@ -1,4 +1,4 @@
-# Copyright 2012-2018 Gentoo Foundation
+# Copyright 2012-2023 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
import subprocess
@@ -23,9 +23,21 @@ class PortdbCacheTestCase(TestCase):
"dev-libs/A-2": {},
"sys-apps/B-1": {},
"sys-apps/B-2": {},
+ "sys-apps/C-1": {
+ "EAPI": 8,
+ "MISC_CONTENT": "inherit bar foo baz",
+ },
}
- playground = ResolverPlayground(ebuilds=ebuilds, debug=debug)
+ # The convoluted structure here is to test accumulation
+ # of IDEPEND across eclasses (bug #870295).
+ eclasses = {
+ "foo": ("inherit bar",),
+ "bar": ("IDEPEND=dev-libs/A",),
+ "baz": ("IDEPEND=",),
+ }
+
+ playground = ResolverPlayground(ebuilds=ebuilds, eclasses=eclasses, debug=debug)
settings = playground.settings
eprefix = settings["EPREFIX"]
test_repo_location = settings.repositories["test_repo"].location
@@ -161,6 +173,17 @@ class PortdbCacheTestCase(TestCase):
"""
),
),
+ (portage_python, "-b", "-Wd", "-Wi::DeprecationWarning", "-c")
+ + (
+ textwrap.dedent(
+ """
+ import os, sys, portage
+ location = portage.portdb.repositories['test_repo'].location
+ if not portage.portdb._pregen_auxdb[location]["sys-apps/C-1"]['IDEPEND']:
+ sys.exit(1)
+ """
+ ),
+ ),
# Test auto-detection and preference for md5-cache when both
# cache formats are available but layout.conf is absent.
(BASH_BINARY, "-c", f"rm {portage._shell_quote(layout_conf_path)}"),
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/dbapi/
@ 2023-08-02 6:31 Sam James
0 siblings, 0 replies; 9+ messages in thread
From: Sam James @ 2023-08-02 6:31 UTC (permalink / raw
To: gentoo-commits
commit: 058613d54790fc164b2a2df266b96a60047a7d13
Author: James Le Cuirot <chewi <AT> gentoo <DOT> org>
AuthorDate: Sun Jul 30 21:34:29 2023 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Wed Aug 2 06:31:20 2023 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=058613d5
Respect TMPDIR instead of hardcoding /tmp in test_bintree.py
It was breaking the Portage sandbox.
Signed-off-by: James Le Cuirot <chewi <AT> gentoo.org>
Closes: https://github.com/gentoo/portage/pull/1071
Signed-off-by: Sam James <sam <AT> gentoo.org>
lib/portage/tests/dbapi/test_bintree.py | 28 +++++++++++++++++-----------
1 file changed, 17 insertions(+), 11 deletions(-)
diff --git a/lib/portage/tests/dbapi/test_bintree.py b/lib/portage/tests/dbapi/test_bintree.py
index 4b4982a54..383d5585e 100644
--- a/lib/portage/tests/dbapi/test_bintree.py
+++ b/lib/portage/tests/dbapi/test_bintree.py
@@ -17,14 +17,18 @@ class BinarytreeTestCase(TestCase):
binarytree()
self.assertEqual(str(cm.exception), "pkgdir parameter is required")
with self.assertRaises(TypeError) as cm:
- binarytree(pkgdir="/tmp")
+ binarytree(pkgdir=os.getenv("TMPDIR", "/tmp"))
self.assertEqual(str(cm.exception), "settings parameter is required")
def test_init_with_legacy_params_warns(self):
with self.assertWarns(DeprecationWarning):
- binarytree(_unused=None, pkgdir="/tmp", settings=MagicMock())
+ binarytree(
+ _unused=None, pkgdir=os.getenv("TMPDIR", "/tmp"), settings=MagicMock()
+ )
with self.assertWarns(DeprecationWarning):
- binarytree(virtual=None, pkgdir="/tmp", settings=MagicMock())
+ binarytree(
+ virtual=None, pkgdir=os.getenv("TMPDIR", "/tmp"), settings=MagicMock()
+ )
def test_instance_has_required_attrs(self):
# Quite smoky test. What would it be a better testing strategy?
@@ -63,11 +67,13 @@ class BinarytreeTestCase(TestCase):
no_multi_instance_settings = MagicMock()
no_multi_instance_settings.features = ""
no_multi_instance_bt = binarytree(
- pkgdir="/tmp", settings=no_multi_instance_settings
+ pkgdir=os.getenv("TMPDIR", "/tmp"), settings=no_multi_instance_settings
)
multi_instance_settings = MagicMock()
multi_instance_settings.features = "binpkg-multi-instance"
- multi_instance_bt = binarytree(pkgdir="/tmp", settings=multi_instance_settings)
+ multi_instance_bt = binarytree(
+ pkgdir=os.getenv("TMPDIR", "/tmp"), settings=multi_instance_settings
+ )
for attr in required_attrs_no_multi_instance:
getattr(no_multi_instance_bt, attr)
getattr(multi_instance_bt, attr)
@@ -77,7 +83,7 @@ class BinarytreeTestCase(TestCase):
@patch("portage.dbapi.bintree.binarytree._populate_local")
def test_populate_without_updates_repos_nor_getbinspkgs(self, ppopulate_local):
- bt = binarytree(pkgdir="/tmp", settings=MagicMock())
+ bt = binarytree(pkgdir=os.getenv("TMPDIR", "/tmp"), settings=MagicMock())
ppopulate_local.return_value = {}
bt.populate()
ppopulate_local.assert_called_once_with(reindex=True)
@@ -86,7 +92,7 @@ class BinarytreeTestCase(TestCase):
@patch("portage.dbapi.bintree.binarytree._populate_local")
def test_populate_calls_twice_populate_local_if_updates(self, ppopulate_local):
- bt = binarytree(pkgdir="/tmp", settings=MagicMock())
+ bt = binarytree(pkgdir=os.getenv("TMPDIR", "/tmp"), settings=MagicMock())
bt.populate()
self.assertIn(call(reindex=True), ppopulate_local.mock_calls)
self.assertIn(call(), ppopulate_local.mock_calls)
@@ -96,7 +102,7 @@ class BinarytreeTestCase(TestCase):
@patch("portage.dbapi.bintree.binarytree._populate_local")
def test_populate_with_repos(self, ppopulate_local, ppopulate_additional):
repos = ("one", "two")
- bt = binarytree(pkgdir="/tmp", settings=MagicMock())
+ bt = binarytree(pkgdir=os.getenv("TMPDIR", "/tmp"), settings=MagicMock())
bt.populate(add_repos=repos)
ppopulate_additional.assert_called_once_with(repos)
@@ -109,7 +115,7 @@ class BinarytreeTestCase(TestCase):
refresh = "something"
settings = MagicMock()
settings.__getitem__.return_value = "/some/path"
- bt = binarytree(pkgdir="/tmp", settings=settings)
+ bt = binarytree(pkgdir=os.getenv("TMPDIR", "/tmp"), settings=settings)
bt.populate(getbinpkgs=True, getbinpkg_refresh=refresh)
ppopulate_remote.assert_called_once_with(getbinpkg_refresh=refresh)
@@ -126,7 +132,7 @@ class BinarytreeTestCase(TestCase):
settings.__getitem__.return_value = portage_root
pBinRepoConfigLoader.return_value = None
conf_file = os.path.join(portage_root, BINREPOS_CONF_FILE)
- bt = binarytree(pkgdir="/tmp", settings=settings)
+ bt = binarytree(pkgdir=os.getenv("TMPDIR", "/tmp"), settings=settings)
bt.populate(getbinpkgs=True, getbinpkg_refresh=refresh)
ppopulate_remote.assert_not_called()
pwritemsg.assert_called_once_with(
@@ -150,6 +156,6 @@ class BinarytreeTestCase(TestCase):
"""
settings = MagicMock()
settings.__getitem__.return_value = "/some/path"
- bt = binarytree(pkgdir="/tmp", settings=settings)
+ bt = binarytree(pkgdir=os.getenv("TMPDIR", "/tmp"), settings=settings)
bt.populate(getbinpkgs=True)
ppopulate_remote.assert_called_once_with(getbinpkg_refresh=False)
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/dbapi/
@ 2023-10-25 1:35 Zac Medico
0 siblings, 0 replies; 9+ messages in thread
From: Zac Medico @ 2023-10-25 1:35 UTC (permalink / raw
To: gentoo-commits
commit: d7e64317e3a0d789e17dfea7b451c6b3b6cdb3c0
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Tue Oct 24 23:52:46 2023 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Tue Oct 24 23:56:15 2023 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=d7e64317
test_auxdb: multiprocessing spawn compat
Use staticmethod and functools.partial to avoid unpicklable
local functions. Also, don't try to pickle anydbm or sqlite
modules since they currently are not picklable. Ultimately,
it might be a good idea to implement pickling for the sqlite
module.
Bug: https://bugs.gentoo.org/916245
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
lib/portage/tests/dbapi/test_auxdb.py | 103 ++++++++++++++++++++++------------
1 file changed, 66 insertions(+), 37 deletions(-)
diff --git a/lib/portage/tests/dbapi/test_auxdb.py b/lib/portage/tests/dbapi/test_auxdb.py
index f022e02adc..1bbf1bde35 100644
--- a/lib/portage/tests/dbapi/test_auxdb.py
+++ b/lib/portage/tests/dbapi/test_auxdb.py
@@ -1,6 +1,9 @@
-# Copyright 2020-2021 Gentoo Authors
+# Copyright 2020-2023 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
+import functools
+import multiprocessing
+
from portage.tests import TestCase
from portage.tests.resolver.ResolverPlayground import ResolverPlayground
from portage.util.futures import asyncio
@@ -13,7 +16,9 @@ class AuxdbTestCase(TestCase):
from portage.cache.anydbm import database
except ImportError:
self.skipTest("dbm import failed")
- self._test_mod("portage.cache.anydbm.database", multiproc=False)
+ self._test_mod(
+ "portage.cache.anydbm.database", multiproc=False, picklable=False
+ )
def test_flat_hash_md5(self):
self._test_mod("portage.cache.flat_hash.md5_database")
@@ -26,9 +31,9 @@ class AuxdbTestCase(TestCase):
import sqlite3
except ImportError:
self.skipTest("sqlite3 import failed")
- self._test_mod("portage.cache.sqlite.database")
+ self._test_mod("portage.cache.sqlite.database", picklable=False)
- def _test_mod(self, auxdbmodule, multiproc=True):
+ def _test_mod(self, auxdbmodule, multiproc=True, picklable=True):
ebuilds = {
"cat/A-1": {
"EAPI": "7",
@@ -60,55 +65,79 @@ class AuxdbTestCase(TestCase):
)
portdb = playground.trees[playground.eroot]["porttree"].dbapi
+ metadata_keys = ["DEFINED_PHASES", "DEPEND", "EAPI", "INHERITED"]
- def test_func():
- loop = asyncio._wrap_loop()
- return loop.run_until_complete(
- self._test_mod_async(
- ebuilds,
- ebuild_inherited,
- eclass_defined_phases,
- eclass_depend,
- portdb,
- )
- )
+ test_func = functools.partial(
+ self._run_test_mod_async, ebuilds, metadata_keys, portdb
+ )
- self.assertTrue(test_func())
+ results = test_func()
- loop = asyncio._wrap_loop()
- self.assertTrue(
- loop.run_until_complete(loop.run_in_executor(ForkExecutor(), test_func))
+ self._compare_results(
+ ebuilds, eclass_defined_phases, eclass_depend, ebuild_inherited, results
)
+ loop = asyncio._wrap_loop()
+ picklable_or_fork = picklable or multiprocessing.get_start_method == "fork"
+ if picklable_or_fork:
+ results = loop.run_until_complete(
+ loop.run_in_executor(ForkExecutor(), test_func)
+ )
+
+ self._compare_results(
+ ebuilds, eclass_defined_phases, eclass_depend, ebuild_inherited, results
+ )
+
auxdb = portdb.auxdb[portdb.getRepositoryPath("test_repo")]
cpv = next(iter(ebuilds))
- def modify_auxdb():
- metadata = auxdb[cpv]
- metadata["RESTRICT"] = "test"
- try:
- del metadata["_eclasses_"]
- except KeyError:
- pass
- auxdb[cpv] = metadata
+ modify_auxdb = functools.partial(self._modify_auxdb, auxdb, cpv)
- if multiproc:
+ if multiproc and picklable_or_fork:
loop.run_until_complete(loop.run_in_executor(ForkExecutor(), modify_auxdb))
else:
modify_auxdb()
self.assertEqual(auxdb[cpv]["RESTRICT"], "test")
- async def _test_mod_async(
- self, ebuilds, ebuild_inherited, eclass_defined_phases, eclass_depend, portdb
+ def _compare_results(
+ self, ebuilds, eclass_defined_phases, eclass_depend, ebuild_inherited, results
):
for cpv, metadata in ebuilds.items():
- defined_phases, depend, eapi, inherited = await portdb.async_aux_get(
- cpv, ["DEFINED_PHASES", "DEPEND", "EAPI", "INHERITED"]
+ self.assertEqual(results[cpv]["DEFINED_PHASES"], eclass_defined_phases)
+ self.assertEqual(results[cpv]["DEPEND"], eclass_depend)
+ self.assertEqual(results[cpv]["EAPI"], metadata["EAPI"])
+ self.assertEqual(
+ frozenset(results[cpv]["INHERITED"].split()), ebuild_inherited
)
- self.assertEqual(defined_phases, eclass_defined_phases)
- self.assertEqual(depend, eclass_depend)
- self.assertEqual(eapi, metadata["EAPI"])
- self.assertEqual(frozenset(inherited.split()), ebuild_inherited)
- return True
+ @staticmethod
+ def _run_test_mod_async(ebuilds, metadata_keys, portdb):
+ loop = asyncio._wrap_loop()
+ return loop.run_until_complete(
+ AuxdbTestCase._test_mod_async(
+ ebuilds,
+ metadata_keys,
+ portdb,
+ )
+ )
+
+ @staticmethod
+ async def _test_mod_async(ebuilds, metadata_keys, portdb):
+ results = {}
+ for cpv, metadata in ebuilds.items():
+ results[cpv] = dict(
+ zip(metadata_keys, await portdb.async_aux_get(cpv, metadata_keys))
+ )
+
+ return results
+
+ @staticmethod
+ def _modify_auxdb(auxdb, cpv):
+ metadata = auxdb[cpv]
+ metadata["RESTRICT"] = "test"
+ try:
+ del metadata["_eclasses_"]
+ except KeyError:
+ pass
+ auxdb[cpv] = metadata
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/dbapi/
@ 2023-11-11 7:23 Sam James
0 siblings, 0 replies; 9+ messages in thread
From: Sam James @ 2023-11-11 7:23 UTC (permalink / raw
To: gentoo-commits
commit: 00ce1c2e21575c6154ce22d0fcf676e2654c56b3
Author: Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Sat Nov 11 03:29:17 2023 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sat Nov 11 07:23:08 2023 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=00ce1c2e
tests: test_bintree: add test for trust helper --pretend issue
Followup to 6ae45739e208b7a9d59e0b6056be72a5791aae04.
Bug: https://bugs.gentoo.org/915842
Signed-off-by: Sam James <sam <AT> gentoo.org>
lib/portage/tests/dbapi/test_bintree.py | 45 +++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
diff --git a/lib/portage/tests/dbapi/test_bintree.py b/lib/portage/tests/dbapi/test_bintree.py
index 0aa411ad97..018f1cf9bd 100644
--- a/lib/portage/tests/dbapi/test_bintree.py
+++ b/lib/portage/tests/dbapi/test_bintree.py
@@ -3,6 +3,7 @@
from unittest.mock import MagicMock, patch, call
import os
+import tempfile
from portage.tests import TestCase
@@ -164,3 +165,47 @@ class BinarytreeTestCase(TestCase):
bt = binarytree(pkgdir=os.getenv("TMPDIR", "/tmp"), settings=settings)
bt.populate(getbinpkgs=True)
ppopulate_remote.assert_called_once_with(getbinpkg_refresh=False, pretend=False)
+
+ @patch("portage.dbapi.bintree.BinRepoConfigLoader")
+ @patch("portage.dbapi.bintree.binarytree._run_trust_helper")
+ def test_default_getbinpkg_refresh_in_populate_trusthelper(
+ self, run_trust_helper, pBinRepoConfigLoader
+ ):
+ """
+ Test for bug #915842.
+
+ Verify that we call the trust helper in non-pretend mode.
+ """
+ settings = MagicMock()
+ settings.features = ["binpkg-request-signature"]
+ settings.__getitem__.return_value = "/some/path"
+
+ d = tempfile.TemporaryDirectory()
+ try:
+ bt = binarytree(pkgdir=d.name, settings=settings)
+ bt.populate(getbinpkgs=True, pretend=False)
+ run_trust_helper.assert_called_once()
+ finally:
+ d.cleanup()
+
+ @patch("portage.dbapi.bintree.BinRepoConfigLoader")
+ @patch("portage.dbapi.bintree.binarytree._run_trust_helper")
+ def test_default_getbinpkg_refresh_in_populate_trusthelper_pretend(
+ self, run_trust_helper, pBinRepoConfigLoader
+ ):
+ """
+ Test for bug #915842.
+
+ Verify we do not call the trust helper in pretend mode.
+ """
+ settings = MagicMock()
+ settings.features = ["binpkg-request-signature"]
+ settings.__getitem__.return_value = "/some/path"
+
+ d = tempfile.TemporaryDirectory()
+ try:
+ bt = binarytree(pkgdir=d.name, settings=settings)
+ bt.populate(getbinpkgs=True, pretend=True)
+ run_trust_helper.assert_not_called()
+ finally:
+ d.cleanup()
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/dbapi/
@ 2024-02-09 21:09 Zac Medico
0 siblings, 0 replies; 9+ messages in thread
From: Zac Medico @ 2024-02-09 21:09 UTC (permalink / raw
To: gentoo-commits
commit: fc6cace9fddfa3a2c5567e35156b2ee7ef39dce1
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Fri Feb 9 21:03:55 2024 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Fri Feb 9 21:08:32 2024 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=fc6cace9
AuxdbTestCase: Add missing playground cleanup
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
lib/portage/tests/dbapi/test_auxdb.py | 67 ++++++++++++++++++++---------------
1 file changed, 38 insertions(+), 29 deletions(-)
diff --git a/lib/portage/tests/dbapi/test_auxdb.py b/lib/portage/tests/dbapi/test_auxdb.py
index c11eed73e8..0de0123a5f 100644
--- a/lib/portage/tests/dbapi/test_auxdb.py
+++ b/lib/portage/tests/dbapi/test_auxdb.py
@@ -1,4 +1,4 @@
-# Copyright 2020-2023 Gentoo Authors
+# Copyright 2020-2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
import functools
@@ -64,41 +64,50 @@ class AuxdbTestCase(TestCase):
user_config={"modules": (f"portdbapi.auxdbmodule = {auxdbmodule}",)},
)
- portdb = playground.trees[playground.eroot]["porttree"].dbapi
- metadata_keys = ["DEFINED_PHASES", "DEPEND", "EAPI", "INHERITED"]
-
- test_func = functools.partial(
- self._run_test_mod_async, ebuilds, metadata_keys, portdb
- )
-
- results = test_func()
-
- self._compare_results(
- ebuilds, eclass_defined_phases, eclass_depend, ebuild_inherited, results
- )
+ try:
+ portdb = playground.trees[playground.eroot]["porttree"].dbapi
+ metadata_keys = ["DEFINED_PHASES", "DEPEND", "EAPI", "INHERITED"]
- loop = asyncio._wrap_loop()
- picklable_or_fork = picklable or multiprocessing.get_start_method == "fork"
- if picklable_or_fork:
- results = loop.run_until_complete(
- loop.run_in_executor(ForkExecutor(), test_func)
+ test_func = functools.partial(
+ self._run_test_mod_async, ebuilds, metadata_keys, portdb
)
+ results = test_func()
+
self._compare_results(
ebuilds, eclass_defined_phases, eclass_depend, ebuild_inherited, results
)
- auxdb = portdb.auxdb[portdb.getRepositoryPath("test_repo")]
- cpv = next(iter(ebuilds))
-
- modify_auxdb = functools.partial(self._modify_auxdb, auxdb, cpv)
-
- if multiproc and picklable_or_fork:
- loop.run_until_complete(loop.run_in_executor(ForkExecutor(), modify_auxdb))
- else:
- modify_auxdb()
-
- self.assertEqual(auxdb[cpv]["RESTRICT"], "test")
+ loop = asyncio._wrap_loop()
+ picklable_or_fork = picklable or multiprocessing.get_start_method == "fork"
+ if picklable_or_fork:
+ results = loop.run_until_complete(
+ loop.run_in_executor(ForkExecutor(), test_func)
+ )
+
+ self._compare_results(
+ ebuilds,
+ eclass_defined_phases,
+ eclass_depend,
+ ebuild_inherited,
+ results,
+ )
+
+ auxdb = portdb.auxdb[portdb.getRepositoryPath("test_repo")]
+ cpv = next(iter(ebuilds))
+
+ modify_auxdb = functools.partial(self._modify_auxdb, auxdb, cpv)
+
+ if multiproc and picklable_or_fork:
+ loop.run_until_complete(
+ loop.run_in_executor(ForkExecutor(), modify_auxdb)
+ )
+ else:
+ modify_auxdb()
+
+ self.assertEqual(auxdb[cpv]["RESTRICT"], "test")
+ finally:
+ playground.cleanup()
def _compare_results(
self, ebuilds, eclass_defined_phases, eclass_depend, ebuild_inherited, results
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/dbapi/
@ 2024-02-27 4:18 Zac Medico
0 siblings, 0 replies; 9+ messages in thread
From: Zac Medico @ 2024-02-27 4:18 UTC (permalink / raw
To: gentoo-commits
commit: e9bdb7342b3048ab3236bff9d94ce733bb877d8e
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Tue Feb 27 04:02:28 2024 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Tue Feb 27 04:03:07 2024 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=e9bdb734
BinarytreeTestCase: Use temporary TMPDIR
Create a temporary TMPDIR which prevents test methods of this
class from leaving behind an empty /tmp/Packages file if TMPDIR
is initially unset.
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
lib/portage/tests/dbapi/test_bintree.py | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/lib/portage/tests/dbapi/test_bintree.py b/lib/portage/tests/dbapi/test_bintree.py
index 018f1cf9bd..91ac338a05 100644
--- a/lib/portage/tests/dbapi/test_bintree.py
+++ b/lib/portage/tests/dbapi/test_bintree.py
@@ -1,4 +1,4 @@
-# Copyright 2022 Gentoo Authors
+# Copyright 2022-2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
from unittest.mock import MagicMock, patch, call
@@ -13,6 +13,26 @@ from portage.const import BINREPOS_CONF_FILE
class BinarytreeTestCase(TestCase):
+ @classmethod
+ def setUpClass(cls):
+ """
+ Create a temporary TMPDIR which prevents test
+ methods of this class from leaving behind an empty
+ /tmp/Packages file if TMPDIR is initially unset.
+ """
+ cls._orig_tmpdir = os.environ.get("TMPDIR")
+ cls._tmpdir = tempfile.TemporaryDirectory()
+ os.environ["TMPDIR"] = cls._tmpdir.name
+
+ @classmethod
+ def tearDownClass(cls):
+ cls._tmpdir.cleanup()
+ if cls._orig_tmpdir is None:
+ os.environ.pop("TMPDIR", None)
+ else:
+ os.environ["TMPDIR"] = cls._orig_tmpdir
+ del cls._orig_tmpdir, cls._tmpdir
+
def test_required_init_params(self):
with self.assertRaises(TypeError) as cm:
binarytree()
^ permalink raw reply related [flat|nested] 9+ messages in thread
end of thread, other threads:[~2024-02-27 4:18 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-02 6:31 [gentoo-commits] proj/portage:master commit in: lib/portage/tests/dbapi/ Sam James
-- strict thread matches above, loose matches on Subject: below --
2024-02-27 4:18 Zac Medico
2024-02-09 21:09 Zac Medico
2023-11-11 7:23 Sam James
2023-10-25 1:35 Zac Medico
2023-02-19 19:19 Sam James
2022-09-25 19:12 Mike Gilbert
2022-09-25 19:12 Mike Gilbert
2021-01-18 12:20 Zac Medico
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox