commit:     323148b8c9b43d631ac0a18bf3a6beac43d807d2
Author:     Brian Harring <ferringb <AT> gmail <DOT> com>
AuthorDate: Tue Nov 21 02:31:36 2023 +0000
Commit:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
CommitDate: Sun Dec  3 05:18:35 2023 +0000
URL:        
https://gitweb.gentoo.org/proj/pkgcore/pkgcore.git/commit/?id=323148b8

cleanup: Replace fake_pkg with common mock

Signed-off-by: Brian Harring <ferringb <AT> gmail.com>
Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org>

 src/pkgcore/test/misc.py     |  9 +++++++++
 tests/scripts/test_pmaint.py | 17 ++++++-----------
 2 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/src/pkgcore/test/misc.py b/src/pkgcore/test/misc.py
index 20c8e6fe3..3a0011765 100644
--- a/src/pkgcore/test/misc.py
+++ b/src/pkgcore/test/misc.py
@@ -109,6 +109,10 @@ class FakeEbuildRepo(FakeRepo):
 
 
 class FakePkg(FakePkgBase):
+    """
+    Object used to mock an ebuild instance for test usage.
+    """
+
     def __init__(
         self,
         cpv,
@@ -140,6 +144,11 @@ class FakePkg(FakePkgBase):
         if iuse is not None:
             object.__setattr__(self, "iuse", set(iuse))
 
+    @classmethod
+    def for_tree_usage(cls, cat: str, pkg: str, version: str, **kwargs):
+        """Helper function that can be used by repository classes"""
+        return cls(f"{cat}/{pkg}-{version}", **kwargs)
+
 
 # misc setup code for generating glsas for testing
 

diff --git a/tests/scripts/test_pmaint.py b/tests/scripts/test_pmaint.py
index 123421016..2cdb3009b 100644
--- a/tests/scripts/test_pmaint.py
+++ b/tests/scripts/test_pmaint.py
@@ -11,6 +11,7 @@ from pkgcore.operations.repo import install, operations, 
replace, uninstall
 from pkgcore.repository import syncable, util
 from pkgcore.scripts import pmaint
 from pkgcore.sync import base
+from pkgcore.test.misc import FakePkg
 from pkgcore.test.scripts.helpers import ArgParseMixin
 
 Options = AttrAccessible
@@ -39,7 +40,7 @@ class FakeRepo(util.SimpleTree):
         self.installed = []
         self.replaced = []
         self.uninstalled = []
-        super().__init__(data, pkg_klass=partial(fake_pkg, self), 
repo_id=repo_id)
+        super().__init__(data, pkg_klass=partial(FakePkg.for_tree_usage, 
repo=self), repo_id=repo_id)
         self.livefs = livefs
         self.frozen = frozen
 
@@ -161,12 +162,6 @@ class TestSync(ArgParseMixin):
         )
 
 
-class fake_pkg(CPV):
-    def __init__(self, repo, *a, **kw):
-        CPV.__init__(self, *a, **kw)
-        object.__setattr__(self, "repo", repo)
-
-
 def derive_op(name, op, *a, **kw):
     if isinstance(name, str):
         name = [name]
@@ -201,7 +196,7 @@ class TestCopy(ArgParseMixin):
             domain=make_domain(vdb={"sys-apps": {"portage": ["2.1", "2.3"]}}),
         )
         assert ret == 0, "expected non zero exit code"
-        assert list(map(str, config.target_repo.installed)) == [
+        assert [pkg.cpvstr for pkg in config.target_repo.installed] == [
             "sys-apps/portage-2.1",
             "sys-apps/portage-2.3",
         ]
@@ -218,7 +213,7 @@ class TestCopy(ArgParseMixin):
             domain=make_domain(binpkg=d, vdb=d),
         )
         assert ret == 0, "expected non zero exit code"
-        assert [list(map(str, x)) for x in config.target_repo.replaced] == [
+        assert [[x.cpvstr for x in pkg] for pkg in 
config.target_repo.replaced] == [
             ["sys-apps/portage-2.1", "sys-apps/portage-2.1"]
         ]
         assert (
@@ -235,7 +230,7 @@ class TestCopy(ArgParseMixin):
             domain=make_domain(vdb={"sys-apps": {"portage": ["2.1", "2.3"]}}),
         )
         assert ret == 0, "expected non zero exit code"
-        assert list(map(str, config.target_repo.installed)) == [
+        assert [pkg.cpvstr for pkg in config.target_repo.installed] == [
             "sys-apps/portage-2.1",
             "sys-apps/portage-2.3",
         ]
@@ -255,7 +250,7 @@ class TestCopy(ArgParseMixin):
             ),
         )
         assert ret == 0, "expected non zero exit code"
-        assert list(map(str, config.target_repo.installed)) == 
["sys-apps/portage-2.3"]
+        assert [pkg.cpvstr for pkg in config.target_repo.installed] == 
["sys-apps/portage-2.3"]
         assert (
             config.target_repo.uninstalled == config.target_repo.replaced
         ), "uninstalled should be the same as replaced; empty"

Reply via email to