[gentoo-commits] proj/portage:master commit in: lib/portage/tests/dbapi/

2024-02-26 Thread Zac Medico
commit: e9bdb7342b3048ab3236bff9d94ce733bb877d8e
Author: Zac Medico  gentoo  org>
AuthorDate: Tue Feb 27 04:02:28 2024 +
Commit: Zac Medico  gentoo  org>
CommitDate: Tue Feb 27 04:03:07 2024 +
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  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()



[gentoo-commits] proj/portage:master commit in: lib/portage/tests/dbapi/, lib/portage/tests/resolver/

2024-02-21 Thread Zac Medico
commit: 0dedea99ac13e0e75a83a78890ed73bced1b950b
Author: Zac Medico  gentoo  org>
AuthorDate: Tue Feb 13 04:21:26 2024 +
Commit: Zac Medico  gentoo  org>
CommitDate: Wed Feb 21 15:27:31 2024 +
URL:https://gitweb.gentoo.org/proj/portage.git/commit/?id=0dedea99

ResolverPlayground: Use egencache to create manifests

Make the ResolverPlayground _create_ebuild_manifests method
call egencache --jobs, which reliably triggers the KeyError
from bug 924319 for multiple tests:

lib/portage/tests/bin/test_doins.py::DoIns::testDoInsFallback Exception in 
callback EbuildMetadataPhase._async_start_done()
handle: )>
Traceback (most recent call last):
  File "/usr/lib/python3.12/asyncio/events.py", line 88, in _run
self._context.run(self._callback, *self._args)
  File "lib/_emerge/EbuildMetadataPhase.py", line 154, in _async_start_done
future.cancelled() or future.result()
  ^^^
  File "lib/_emerge/EbuildMetadataPhase.py", line 130, in _async_start
retval = portage.doebuild(
 ^
  File "lib/portage/package/ebuild/doebuild.py", line 1030, in doebuild
doebuild_environment(
  File "lib/portage/package/ebuild/doebuild.py", line 519, in 
doebuild_environment
eapi = mysettings.configdict["pkg"]["EAPI"]
   
  File "lib/portage/util/__init__.py", line 1684, in __getitem__
return UserDict.__getitem__(self, item_key)
   
  File "lib/portage/cache/mappings.py", line 175, in __getitem__
return self.data[key]
   ~^
KeyError: 'EAPI'

Bug: https://bugs.gentoo.org/924319
Signed-off-by: Zac Medico  gentoo.org>

 lib/portage/tests/dbapi/test_portdb_cache.py |  4 ++-
 lib/portage/tests/resolver/ResolverPlayground.py | 38 +---
 2 files changed, 23 insertions(+), 19 deletions(-)

diff --git a/lib/portage/tests/dbapi/test_portdb_cache.py 
b/lib/portage/tests/dbapi/test_portdb_cache.py
index c7c6913b49..c24a4f2098 100644
--- a/lib/portage/tests/dbapi/test_portdb_cache.py
+++ b/lib/portage/tests/dbapi/test_portdb_cache.py
@@ -1,6 +1,7 @@
-# Copyright 2012-2023 Gentoo Authors
+# Copyright 2012-2024 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
+import shutil
 import subprocess
 import sys
 import textwrap
@@ -63,6 +64,7 @@ class PortdbCacheTestCase(TestCase):
 python_cmd = (portage_python, "-b", "-Wd", "-c")
 
 test_commands = (
+(lambda: shutil.rmtree(md5_cache_dir) or True,),
 (lambda: not os.path.exists(pms_cache_dir),),
 (lambda: not os.path.exists(md5_cache_dir),),
 python_cmd

diff --git a/lib/portage/tests/resolver/ResolverPlayground.py 
b/lib/portage/tests/resolver/ResolverPlayground.py
index 2d26012873..75c86b615c 100644
--- a/lib/portage/tests/resolver/ResolverPlayground.py
+++ b/lib/portage/tests/resolver/ResolverPlayground.py
@@ -3,6 +3,7 @@
 
 import bz2
 import fnmatch
+import subprocess
 import tempfile
 import portage
 
@@ -18,8 +19,6 @@ from portage.const import (
 from portage.process import find_binary
 from portage.dep import Atom, _repo_separator
 from portage.dbapi.bintree import binarytree
-from portage.package.ebuild.config import config
-from portage.package.ebuild.digestgen import digestgen
 from portage._sets import load_default_config
 from portage._sets.base import InternalPackageSet
 from portage.tests import cnf_path
@@ -323,22 +322,25 @@ class ResolverPlayground:
 f.write(misc_content)
 
 def _create_ebuild_manifests(self, ebuilds):
-tmpsettings = config(clone=self.settings)
-tmpsettings["PORTAGE_QUIET"] = "1"
-for cpv in ebuilds:
-a = Atom("=" + cpv, allow_repo=True)
-repo = a.repo
-if repo is None:
-repo = "test_repo"
-
-repo_dir = self._get_repo_dir(repo)
-ebuild_dir = os.path.join(repo_dir, a.cp)
-ebuild_path = os.path.join(ebuild_dir, a.cpv.split("/")[1] + 
".ebuild")
-
-portdb = self.trees[self.eroot]["porttree"].dbapi
-tmpsettings["O"] = ebuild_dir
-if not digestgen(mysettings=tmpsettings, myportdb=portdb):
-raise AssertionError(f"digest creation failed for 
{ebuild_path}")
+for repo_name in self._repositories:
+if repo_name == "DEFAULT":
+continue
+egencache_cmd = [
+"egencache",
+f"--repo={repo_name}",
+"--update",
+"--update-manifests",
+"--sign-manifests=n",
+"--strict-manifests=n",
+
f"--repositories-configuration={self.settings['PORTAGE_REPOSITORIES']}",
+f"--jobs={portage.util.cpuinfo.get_cpu_count()}",
+]
+result = subprocess.run(
+egencache_cmd,
+ 

[gentoo-commits] proj/portage:master commit in: lib/portage/tests/dbapi/

2024-02-09 Thread Zac Medico
commit: fc6cace9fddfa3a2c5567e35156b2ee7ef39dce1
Author: Zac Medico  gentoo  org>
AuthorDate: Fri Feb  9 21:03:55 2024 +
Commit: Zac Medico  gentoo  org>
CommitDate: Fri Feb  9 21:08:32 2024 +
URL:https://gitweb.gentoo.org/proj/portage.git/commit/?id=fc6cace9

AuxdbTestCase: Add missing playground cleanup

Signed-off-by: Zac Medico  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



[gentoo-commits] proj/portage:master commit in: lib/portage/tests/dbapi/

2023-11-10 Thread Sam James
commit: 00ce1c2e21575c6154ce22d0fcf676e2654c56b3
Author: Sam James  gentoo  org>
AuthorDate: Sat Nov 11 03:29:17 2023 +
Commit: Sam James  gentoo  org>
CommitDate: Sat Nov 11 07:23:08 2023 +
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  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()



[gentoo-commits] proj/portage:master commit in: lib/portage/tests/dbapi/

2023-10-24 Thread Zac Medico
commit: d7e64317e3a0d789e17dfea7b451c6b3b6cdb3c0
Author: Zac Medico  gentoo  org>
AuthorDate: Tue Oct 24 23:52:46 2023 +
Commit: Zac Medico  gentoo  org>
CommitDate: Tue Oct 24 23:56:15 2023 +
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  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]["

[gentoo-commits] proj/portage:master commit in: lib/portage/tests/dbapi/, lib/portage/dbapi/, /

2023-08-20 Thread Sam James
commit: 71daef3ac877329a0479a72ba333a9c801a36bf3
Author: Siddhanth Rathod  gmail  com>
AuthorDate: Thu Mar 23 16:28:14 2023 +
Commit: Sam James  gentoo  org>
CommitDate: Mon Aug 21 05:15:05 2023 +
URL:https://gitweb.gentoo.org/proj/portage.git/commit/?id=71daef3a

bintree: Add invalid_paths member to API

Add object invalid_paths for new eclean feature to deal with invalid binpkgs.

This is needed for gentoolkit's eclean to handle cleaning up invalid binpkgs.

gentoolkit side PR: https://github.com/gentoo/gentoolkit/pull/28
Bug: https://bugs.gentoo.org/900224
Signed-off-by: Siddhanth Rathod  gmail.com>
Closes: https://github.com/gentoo/portage/pull/1016
Signed-off-by: Sam James  gentoo.org>

 NEWS| 7 +++
 lib/portage/dbapi/bintree.py| 4 
 lib/portage/tests/dbapi/test_bintree.py | 1 +
 3 files changed, 12 insertions(+)

diff --git a/NEWS b/NEWS
index a59af3818b..d770e0b7e9 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,10 @@
+portage-3.0.52 (UNRELEASED)
+--
+
+Features:
+* bintree: Add new API member (invalid_paths) to allow gentoolkit to later
+  clean up invalid binpkgs (bug #900224).
+
 portage-3.0.51 (2023-08-20)
 --
 

diff --git a/lib/portage/dbapi/bintree.py b/lib/portage/dbapi/bintree.py
index 5f58c548d6..af2113bd84 100644
--- a/lib/portage/dbapi/bintree.py
+++ b/lib/portage/dbapi/bintree.py
@@ -485,6 +485,7 @@ class binarytree:
 self._remotepkgs = None  # remote metadata indexed by cpv
 self._additional_pkgs = {}
 self.invalids = []
+self.invalid_paths: dict[str, list[str]] = {}
 self.settings = settings
 self._pkg_paths = {}
 self._populating = False
@@ -1017,12 +1018,14 @@ class binarytree:
 noiselevel=-1,
 )
 self.invalids.append(myfile[:-5])
+self.invalid_paths[myfile] = [full_path]
 continue
 
 try:
 binpkg_format = get_binpkg_format(myfile)
 except InvalidBinaryPackageFormat:
 self.invalids.append(myfile[:-5])
+self.invalid_paths[myfile[:-5]] = [full_path]
 continue
 
 if gpkg_only:
@@ -1089,6 +1092,7 @@ class binarytree:
 for line in textwrap.wrap("".join(msg), 72):
 writemsg(f"!!! {line}\n", noiselevel=-1)
 self.invalids.append(mypkg)
+self.invalid_paths[mypkg] = [full_path]
 continue
 
 multi_instance = False

diff --git a/lib/portage/tests/dbapi/test_bintree.py 
b/lib/portage/tests/dbapi/test_bintree.py
index 383d5585e7..60785b4e59 100644
--- a/lib/portage/tests/dbapi/test_bintree.py
+++ b/lib/portage/tests/dbapi/test_bintree.py
@@ -46,6 +46,7 @@ class BinarytreeTestCase(TestCase):
 "_remotepkgs",
 "_additional_pkgs",
 "invalids",
+"invalid_paths",
 "settings",
 "_pkg_paths",
 "_populating",



[gentoo-commits] proj/portage:master commit in: lib/portage/tests/dbapi/

2023-08-01 Thread Sam James
commit: 058613d54790fc164b2a2df266b96a60047a7d13
Author: James Le Cuirot  gentoo  org>
AuthorDate: Sun Jul 30 21:34:29 2023 +
Commit: Sam James  gentoo  org>
CommitDate: Wed Aug  2 06:31:20 2023 +
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  gentoo.org>
Closes: https://github.com/gentoo/portage/pull/1071
Signed-off-by: Sam James  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",

[gentoo-commits] proj/portage:master commit in: lib/portage/tests/dbapi/

2023-02-19 Thread Sam James
commit: 22406d51ccaa743da4fd4c45e0fbaca09ffb1eba
Author: Sam James  gentoo  org>
AuthorDate: Sat Feb 18 12:42:09 2023 +
Commit: Sam James  gentoo  org>
CommitDate: Sun Feb 19 19:19:44 2023 +
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  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)}"),



[gentoo-commits] proj/portage:master commit in: lib/portage/tests/dbapi/, lib/portage/dbapi/

2022-09-25 Thread Mike Gilbert
commit: a52b27e86680331abdc12f48ea50bc7d1080445f
Author: David Palao  gmail  com>
AuthorDate: Fri Sep  9 18:35:17 2022 +
Commit: Mike Gilbert  gentoo  org>
CommitDate: Sun Sep 25 19:07:52 2022 +
URL:https://gitweb.gentoo.org/proj/portage.git/commit/?id=a52b27e8

chore(style): some minor stylistic issues

* replaced printf-style string with f-string, and
* code passed through pylint and black

Signed-off-by: David Palao  gmail.com>
Signed-off-by: Mike Gilbert  gentoo.org>

 lib/portage/dbapi/bintree.py|  6 +--
 lib/portage/tests/dbapi/test_bintree.py | 68 +
 2 files changed, 47 insertions(+), 27 deletions(-)

diff --git a/lib/portage/dbapi/bintree.py b/lib/portage/dbapi/bintree.py
index 28b3c481b..cea9378d5 100644
--- a/lib/portage/dbapi/bintree.py
+++ b/lib/portage/dbapi/bintree.py
@@ -866,9 +866,9 @@ class binarytree:
 if not self._binrepos_conf:
 writemsg(
 _(
-"!!! %s is missing (or PORTAGE_BINHOST is unset), 
but use is requested.\n"
-)
-% (config_path,),
+f"!!! {config_path} is missing (or PORTAGE_BINHOST 
is unset), "
+"but use is requested.\n"
+),
 noiselevel=-1,
 )
 else:

diff --git a/lib/portage/tests/dbapi/test_bintree.py 
b/lib/portage/tests/dbapi/test_bintree.py
index d0bfa306e..881d8ff48 100644
--- a/lib/portage/tests/dbapi/test_bintree.py
+++ b/lib/portage/tests/dbapi/test_bintree.py
@@ -30,25 +30,44 @@ class BinarytreeTestCase(TestCase):
 # 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",
+"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)
+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)
+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)
@@ -57,8 +76,7 @@ class BinarytreeTestCase(TestCase):
 getattr(multi_instance_bt, "_allocate_filename")
 
 @patch("portage.dbapi.bintree.binarytree._populate_local")
-def test_populate_without_updates_repos_nor_getbinspkgs(
-self, ppopulate_local):
+def test_populate_without_updates_repos_nor_getbinspkgs(self, 
ppopulate_local):
 bt = binarytree(pkgdir="/tmp", settings=MagicMock())
 ppopulate_local.return_value = {}
 bt.populate()
@@ -67,8 +85,7 @@ class BinarytreeTestCase(TestCase):
 self.assertTrue(bt.populated)
 
 @patch("portage.dbapi.bintree.binarytree._populate_local")
-def test_populate_calls_twice_populate_local_if_updates(
-self, ppopulate_loca

[gentoo-commits] proj/portage:master commit in: lib/portage/tests/dbapi/

2022-09-25 Thread Mike Gilbert
commit: 98292b4077c0b75d7424955e0affa64beb86a2b7
Author: David Palao  gmail  com>
AuthorDate: Fri Sep 23 13:41:02 2022 +
Commit: Mike Gilbert  gentoo  org>
CommitDate: Sun Sep 25 19:07:49 2022 +
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  gmail.com>
Signed-off-by: Mike Gilbert  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 0..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")



[gentoo-commits] proj/portage:master commit in: lib/portage/tests/dbapi/

2022-09-25 Thread Mike Gilbert
commit: 419f5ae0d9f0ca55279f1ad60a7dc83d8da777d6
Author: David Palao  gmail  com>
AuthorDate: Fri Sep  9 17:12:17 2022 +
Commit: Mike Gilbert  gentoo  org>
CommitDate: Sun Sep 25 19:07:52 2022 +
URL:https://gitweb.gentoo.org/proj/portage.git/commit/?id=419f5ae0

test(bintree): added UTs for binarytree.populate

Signed-off-by: David Palao  gmail.com>
Signed-off-by: Mike Gilbert  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
+)



[gentoo-commits] proj/portage:master commit in: lib/portage/tests/dbapi/

2021-01-18 Thread Zac Medico
commit: be3613e562203d1d8fd7ad6001aa7db43480b2fe
Author: Zac Medico  gentoo  org>
AuthorDate: Mon Jan 18 11:31:18 2021 +
Commit: Zac Medico  gentoo  org>
CommitDate: Mon Jan 18 11:32:12 2021 +
URL:https://gitweb.gentoo.org/proj/portage.git/commit/?id=be3613e5

AuxdbTestCase: Use async and await syntax

Signed-off-by: Zac Medico  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



[gentoo-commits] proj/portage:master commit in: lib/portage/tests/dbapi/, lib/portage/cache/

2020-08-08 Thread Zac Medico
commit: d4f212def0dcba58e8a146daf8da7b481491de39
Author: Zac Medico  gentoo  org>
AuthorDate: Sat Aug  8 01:00:50 2020 +
Commit: Zac Medico  gentoo  org>
CommitDate: Sun Aug  9 02:41:43 2020 +
URL:https://gitweb.gentoo.org/proj/portage.git/commit/?id=d4f212de

sqlite: fork safety (bug 736334)

Use a separate connection instance for each pid, since
it is not safe to use a connection created in a parent
process.

See: https://www.sqlite.org/howtocorrupt.html
Bug: https://bugs.gentoo.org/736334
Signed-off-by: Zac Medico  gentoo.org>

 lib/portage/cache/sqlite.py   |  9 +
 lib/portage/tests/dbapi/test_auxdb.py | 38 ++-
 2 files changed, 38 insertions(+), 9 deletions(-)

diff --git a/lib/portage/cache/sqlite.py b/lib/portage/cache/sqlite.py
index 0395dd516..36a4f049e 100644
--- a/lib/portage/cache/sqlite.py
+++ b/lib/portage/cache/sqlite.py
@@ -4,6 +4,7 @@
 import collections
 import re
 
+import portage
 from portage.cache import fs_template
 from portage.cache import cache_errors
 from portage import os
@@ -25,7 +26,7 @@ class database(fs_template.FsBased):
cache_bytes = 1024 * 1024 * 10
 
_connection_info_entry = 
collections.namedtuple('_connection_info_entry',
-   ('connection', 'cursor'))
+   ('connection', 'cursor', 'pid'))
 
def __init__(self, *args, **config):
super(database, self).__init__(*args, **config)
@@ -71,13 +72,13 @@ class database(fs_template.FsBased):
 
@property
def _db_cursor(self):
-   if self._db_connection_info is None:
+   if self._db_connection_info is None or 
self._db_connection_info.pid != portage.getpid():
self._db_init_connection()
return self._db_connection_info.cursor
 
@property
def _db_connection(self):
-   if self._db_connection_info is None:
+   if self._db_connection_info is None or 
self._db_connection_info.pid != portage.getpid():
self._db_init_connection()
return self._db_connection_info.connection
 
@@ -94,7 +95,7 @@ class database(fs_template.FsBased):
connection = self._db_module.connect(
database=_unicode_decode(self._dbpath), 
**connection_kwargs)
cursor = connection.cursor()
-   self._db_connection_info = 
self._connection_info_entry(connection, cursor)
+   self._db_connection_info = 
self._connection_info_entry(connection, cursor, portage.getpid())
self._db_cursor.execute("PRAGMA encoding = %s" % 
self._db_escape_string("UTF-8"))
if not self.readonly and not 
self._ensure_access(self._dbpath):
raise 
cache_errors.InitializationError(self.__class__, "can't ensure perms on %s" % 
self._dbpath)

diff --git a/lib/portage/tests/dbapi/test_auxdb.py 
b/lib/portage/tests/dbapi/test_auxdb.py
index 5c79357d7..907c289fb 100644
--- a/lib/portage/tests/dbapi/test_auxdb.py
+++ b/lib/portage/tests/dbapi/test_auxdb.py
@@ -4,7 +4,8 @@
 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
+from portage.util.futures.compat_coroutine import coroutine, coroutine_return
+from portage.util.futures.executor.fork import ForkExecutor
 
 
 class AuxdbTestCase(TestCase):
@@ -14,13 +15,13 @@ class AuxdbTestCase(TestCase):
from portage.cache.anydbm import database
except ImportError:
self.skipTest('dbm import failed')
-   self._test_mod('portage.cache.anydbm.database')
+   self._test_mod('portage.cache.anydbm.database', multiproc=False)
 
def test_flat_hash_md5(self):
self._test_mod('portage.cache.flat_hash.md5_database')
 
def test_volatile(self):
-   self._test_mod('portage.cache.volatile.database')
+   self._test_mod('portage.cache.volatile.database', 
multiproc=False)
 
def test_sqite(self):
try:
@@ -29,7 +30,7 @@ class AuxdbTestCase(TestCase):
self.skipTest('sqlite3 import failed')
self._test_mod('portage.cache.sqlite.database')
 
-   def _test_mod(self, auxdbmodule):
+   def _test_mod(self, auxdbmodule, multiproc=True):
ebuilds = {
"cat/A-1": {
"EAPI": "7",
@@ -61,8 +62,33 @@ class AuxdbTestCase(TestCase):
 
portdb = playground.trees[playground.eroot]["porttree"].dbapi
 
+   def test_func():
+   return 
asyncio._wrap_loop().run_until_complete(self._test_mod_async(
+   ebuilds, ebuil

[gentoo-commits] proj/portage:master commit in: lib/portage/tests/dbapi/, lib/portage/cache/

2020-05-02 Thread Zac Medico
commit: 687dbcb0ab2f7d254bdc53b1332b3d480b2de581
Author: Zac Medico  gentoo  org>
AuthorDate: Sat May  2 20:51:15 2020 +
Commit: Zac Medico  gentoo  org>
CommitDate: Sat May  2 21:04:37 2020 +
URL:https://gitweb.gentoo.org/proj/portage.git/commit/?id=687dbcb0

anydbm: avoid interference between cleanse_keys and _eclasses_

Fix this AuxdbTestCase failure for anydbm:

test_anydbm (portage.tests.dbapi.test_auxdb.AuxdbTestCase) ... Exception in 
callback None()
handle: 
Traceback (most recent call last):
  File "/usr/lib64/python3.6/asyncio/events.py", line 145, in _run
self._callback(*self._args)
  File "lib/_emerge/EbuildMetadataPhase.py", line 143, in _output_handler
self._async_waitpid()
  File "lib/_emerge/SubProcess.py", line 60, in _async_waitpid
add_child_handler(self.pid, self._async_waitpid_cb)
  File "/usr/lib64/python3.6/asyncio/unix_events.py", line 873, in 
add_child_handler
self._do_waitpid(pid)
  File "/usr/lib64/python3.6/asyncio/unix_events.py", line 919, in _do_waitpid
callback(pid, returncode, *args)
  File "lib/_emerge/EbuildMetadataPhase.py", line 207, in _async_waitpid_cb
self.repo_path, metadata, self.ebuild_hash)
  File "lib/portage/dbapi/porttree.py", line 545, in _write_cache
cache[cpv] = metadata
  File "lib/portage/cache/template.py", line 146, in __setitem__
d["_eclasses_"] = self._internal_eclasses(d["_eclasses_"],
  File "lib/portage/cache/mappings.py", line 213, in __getitem__
raise KeyError(key)
KeyError: '_eclasses_'

Signed-off-by: Zac Medico  gentoo.org>

 lib/portage/cache/template.py | 2 +-
 lib/portage/tests/dbapi/test_auxdb.py | 7 +++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/lib/portage/cache/template.py b/lib/portage/cache/template.py
index 8662d859f..6b4878347 100644
--- a/lib/portage/cache/template.py
+++ b/lib/portage/cache/template.py
@@ -133,7 +133,7 @@ class database(object):
d = None
if self.cleanse_keys:
d=ProtectedDict(values)
-   for k, v in list(d.items()):
+   for k, v in list(item for item in d.items() if item[0] 
!= "_eclasses_"):
if not v:
del d[k]
if "_eclasses_" in values:

diff --git a/lib/portage/tests/dbapi/test_auxdb.py 
b/lib/portage/tests/dbapi/test_auxdb.py
index 73fc2b2c3..cfcabc8bb 100644
--- a/lib/portage/tests/dbapi/test_auxdb.py
+++ b/lib/portage/tests/dbapi/test_auxdb.py
@@ -11,6 +11,13 @@ from portage.util.futures.compat_coroutine import coroutine
 
 class AuxdbTestCase(TestCase):
 
+   def test_anydbm(self):
+   try:
+   from portage.cache.anydbm import database
+   except ImportError:
+   self.skipTest('dbm import failed')
+   self._test_mod('portage.cache.anydbm.database')
+
def test_flat_hash_md5(self):
self._test_mod('portage.cache.flat_hash.md5_database')
 



[gentoo-commits] proj/portage:master commit in: lib/portage/tests/dbapi/, lib/portage/tests/resolver/

2020-01-21 Thread Zac Medico
commit: 410818d2c733bd5961d51191083b423ef53761b1
Author: Zac Medico  gentoo  org>
AuthorDate: Tue Jan 21 08:04:33 2020 +
Commit: Zac Medico  gentoo  org>
CommitDate: Tue Jan 21 08:06:41 2020 +
URL:https://gitweb.gentoo.org/proj/portage.git/commit/?id=410818d2

Test /etc/portage/modules portdbapi.auxdbmodule settings

Signed-off-by: Zac Medico  gentoo.org>

 lib/portage/tests/dbapi/test_auxdb.py| 50 
 lib/portage/tests/resolver/ResolverPlayground.py |  2 +-
 2 files changed, 51 insertions(+), 1 deletion(-)

diff --git a/lib/portage/tests/dbapi/test_auxdb.py 
b/lib/portage/tests/dbapi/test_auxdb.py
new file mode 100644
index 0..73fc2b2c3
--- /dev/null
+++ b/lib/portage/tests/dbapi/test_auxdb.py
@@ -0,0 +1,50 @@
+# Copyright 2020 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+from __future__ import unicode_literals
+
+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
+
+
+class AuxdbTestCase(TestCase):
+
+   def test_flat_hash_md5(self):
+   self._test_mod('portage.cache.flat_hash.md5_database')
+
+   def test_volatile(self):
+   self._test_mod('portage.cache.volatile.database')
+
+   def test_sqite(self):
+   try:
+   import sqlite3
+   except ImportError:
+   self.skipTest('sqlite3 import failed')
+   self._test_mod('portage.cache.sqlite.database')
+
+   def _test_mod(self, auxdbmodule):
+   ebuilds = {
+   "cat/A-1": {
+   "EAPI": "7"
+   },
+   "cat/B-1": {
+   "EAPI": "7"
+   },
+   }
+
+   playground = ResolverPlayground(ebuilds=ebuilds,
+   user_config={'modules': ('portdbapi.auxdbmodule = %s' % 
auxdbmodule,)})
+
+   portdb = playground.trees[playground.eroot]["porttree"].dbapi
+
+   loop = asyncio._wrap_loop()
+   loop.run_until_complete(self._test_mod_async(ebuilds, portdb))
+
+   @coroutine
+   def _test_mod_async(self, ebuilds, portdb):
+
+   for cpv, metadata in ebuilds.items():
+   eapi, = yield portdb.async_aux_get(cpv, ['EAPI'])
+   self.assertEqual(eapi, metadata['EAPI'])

diff --git a/lib/portage/tests/resolver/ResolverPlayground.py 
b/lib/portage/tests/resolver/ResolverPlayground.py
index cc3056ab4..d7fbe4390 100644
--- a/lib/portage/tests/resolver/ResolverPlayground.py
+++ b/lib/portage/tests/resolver/ResolverPlayground.py
@@ -44,7 +44,7 @@ class ResolverPlayground(object):
its work.
"""
 
-   config_files = frozenset(("eapi", "layout.conf", "make.conf", 
"package.accept_keywords",
+   config_files = frozenset(("eapi", "layout.conf", "make.conf", 
"modules", "package.accept_keywords",
"package.keywords", "package.license", "package.mask", 
"package.properties",
"package.provided", "packages",
"package.unmask", "package.use", "package.use.aliases", 
"package.use.stable.mask",