aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Harring <ferringb@gmail.com>2023-11-20 18:31:36 -0800
committerArthur Zamarin <arthurzam@gentoo.org>2023-12-03 07:18:35 +0200
commit323148b8c9b43d631ac0a18bf3a6beac43d807d2 (patch)
treefc174b09d0322f3ebcfe25bdf9d174e0a62f719d
parentpquery: Fix --environment-re support . (diff)
downloadpkgcore-323148b8c9b43d631ac0a18bf3a6beac43d807d2.tar.gz
pkgcore-323148b8c9b43d631ac0a18bf3a6beac43d807d2.tar.bz2
pkgcore-323148b8c9b43d631ac0a18bf3a6beac43d807d2.zip
cleanup: Replace fake_pkg with common mock
Signed-off-by: Brian Harring <ferringb@gmail.com> Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
-rw-r--r--src/pkgcore/test/misc.py9
-rw-r--r--tests/scripts/test_pmaint.py17
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"