summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pym/portage/tests/resolver/ResolverPlayground.py77
-rw-r--r--pym/portage/tests/resolver/test_depclean.py113
2 files changed, 168 insertions, 22 deletions
diff --git a/pym/portage/tests/resolver/ResolverPlayground.py b/pym/portage/tests/resolver/ResolverPlayground.py
index 1983b9e6e..0b950059f 100644
--- a/pym/portage/tests/resolver/ResolverPlayground.py
+++ b/pym/portage/tests/resolver/ResolverPlayground.py
@@ -15,6 +15,8 @@ from portage.package.ebuild.config import config
from portage._sets import load_default_config
from portage.versions import catsplit
+import _emerge
+from _emerge.actions import calc_depclean
from _emerge.Blocker import Blocker
from _emerge.create_depgraph_params import create_depgraph_params
from _emerge.depgraph import backtrack_depgraph
@@ -315,12 +317,23 @@ class ResolverPlayground(object):
if not self.debug:
portage.util.noiselimit = -2
- params = create_depgraph_params(options, action)
- success, depgraph, favorites = backtrack_depgraph(
- self.settings, self.trees, options, params, action, atoms, None)
- depgraph.display_problems()
- result = ResolverPlaygroundResult(atoms, success, depgraph, favorites)
+ _emerge.emergelog._disable = True
+
+ if options.get("--depclean"):
+ rval, cleanlist, ordered, req_pkg_count = \
+ calc_depclean(self.settings, self.trees, None,
+ options, "depclean", atoms, None)
+ result = ResolverPlaygroundDepcleanResult( \
+ atoms, rval, cleanlist, ordered, req_pkg_count)
+ else:
+ params = create_depgraph_params(options, action)
+ success, depgraph, favorites = backtrack_depgraph(
+ self.settings, self.trees, options, params, action, atoms, None)
+ depgraph.display_problems()
+ result = ResolverPlaygroundResult(atoms, success, depgraph, favorites)
+
portage.util.noiselimit = 0
+ _emerge.emergelog._disable = False
return result
@@ -344,15 +357,6 @@ class ResolverPlayground(object):
class ResolverPlaygroundTestCase(object):
def __init__(self, request, **kwargs):
- self.checks = {
- "success": None,
- "mergelist": None,
- "use_changes": None,
- "unstable_keywords": None,
- "slot_collision_solutions": None,
- "circular_dependency_solutions": None,
- }
-
self.all_permutations = kwargs.pop("all_permutations", False)
self.ignore_mergelist_order = kwargs.pop("ignore_mergelist_order", False)
@@ -365,17 +369,23 @@ class ResolverPlaygroundTestCase(object):
self.action = kwargs.pop("action", None)
self.test_success = True
self.fail_msg = None
-
- for key, value in kwargs.items():
- if not key in self.checks:
- raise KeyError("Not an avaiable check: '%s'" % key)
- self.checks[key] = value
-
+ self._checks = kwargs.copy()
+
def compare_with_result(self, result):
+ checks = dict.fromkeys(result.checks)
+ for key, value in self._checks.items():
+ if not key in checks:
+ raise KeyError("Not an avaiable check: '%s'" % key)
+ checks[key] = value
+
fail_msgs = []
- for key, value in self.checks.items():
+ for key, value in checks.items():
got = getattr(result, key)
expected = value
+
+ if key in result.optional_checks and expected is None:
+ continue
+
if key == "mergelist" and self.ignore_mergelist_order and got is not None :
got = set(got)
expected = set(expected)
@@ -392,6 +402,14 @@ class ResolverPlaygroundTestCase(object):
return True
class ResolverPlaygroundResult(object):
+
+ checks = (
+ "success", "mergelist", "use_changes", "unstable_keywords", "slot_collision_solutions",
+ "circular_dependency_solutions",
+ )
+ optional_checks = (
+ )
+
def __init__(self, atoms, success, mydepgraph, favorites):
self.atoms = atoms
self.success = success
@@ -443,4 +461,19 @@ class ResolverPlaygroundResult(object):
handler = self.depgraph._dynamic_config._circular_dependency_handler
sol = handler.solutions
self.circular_dependency_solutions = dict( zip([x.cpv for x in sol.keys()], sol.values()) )
-
+
+class ResolverPlaygroundDepcleanResult(object):
+
+ checks = (
+ "success", "cleanlist", "ordered", "req_pkg_count",
+ )
+ optional_checks = (
+ "ordered", "req_pkg_count",
+ )
+
+ def __init__(self, atoms, rval, cleanlist, ordered, req_pkg_count):
+ self.atoms = atoms
+ self.success = rval == 0
+ self.cleanlist = cleanlist
+ self.ordered = ordered
+ self.req_pkg_count = req_pkg_count
diff --git a/pym/portage/tests/resolver/test_depclean.py b/pym/portage/tests/resolver/test_depclean.py
new file mode 100644
index 000000000..9e8e43bfc
--- /dev/null
+++ b/pym/portage/tests/resolver/test_depclean.py
@@ -0,0 +1,113 @@
+# Copyright 2010 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+from portage.tests import TestCase
+from portage.tests.resolver.ResolverPlayground import ResolverPlayground, ResolverPlaygroundTestCase
+
+class SimpleDepcleanTestCase(TestCase):
+
+ def testSimpleDepclean(self):
+ ebuilds = {
+ "dev-libs/A-1": {},
+ "dev-libs/B-1": {},
+ }
+ installed = {
+ "dev-libs/A-1": {},
+ "dev-libs/B-1": {},
+ }
+
+ world = (
+ "dev-libs/A",
+ )
+
+ test_cases = (
+ ResolverPlaygroundTestCase(
+ [],
+ options = {"--depclean": True},
+ success = True,
+ cleanlist = ["dev-libs/B-1"]),
+ )
+
+ playground = ResolverPlayground(ebuilds=ebuilds, installed=installed, world=world)
+ try:
+ for test_case in test_cases:
+ playground.run_TestCase(test_case)
+ self.assertEqual(test_case.test_success, True, test_case.fail_msg)
+ finally:
+ playground.cleanup()
+
+class DepcleanWithDepsTestCase(TestCase):
+
+ def testDepcleanWithDeps(self):
+ ebuilds = {
+ "dev-libs/A-1": { "DEPEND": "dev-libs/C" },
+ "dev-libs/B-1": { "DEPEND": "dev-libs/D" },
+ "dev-libs/C-1": {},
+ "dev-libs/D-1": {},
+ }
+ installed = {
+ "dev-libs/A-1": { "DEPEND": "dev-libs/C" },
+ "dev-libs/B-1": { "DEPEND": "dev-libs/D" },
+ "dev-libs/C-1": {},
+ "dev-libs/D-1": {},
+ }
+
+ world = (
+ "dev-libs/A",
+ )
+
+ test_cases = (
+ ResolverPlaygroundTestCase(
+ [],
+ options = {"--depclean": True},
+ success = True,
+ cleanlist = ["dev-libs/B-1", "dev-libs/D-1"]),
+ )
+
+ playground = ResolverPlayground(ebuilds=ebuilds, installed=installed, world=world)
+ try:
+ for test_case in test_cases:
+ playground.run_TestCase(test_case)
+ self.assertEqual(test_case.test_success, True, test_case.fail_msg)
+ finally:
+ playground.cleanup()
+
+
+class DepcleanWithInstalledMaskedTestCase(TestCase):
+
+ def testDepcleanWithInstalledMasked(self):
+ """
+ Test case for bug 332719.
+ emerge --declean ignores that B is masked by license and removes C.
+ The next emerge -uDN world doesn't take B and installs C again.
+ """
+ ebuilds = {
+ "dev-libs/A-1": { "DEPEND": "|| ( dev-libs/B dev-libs/C )" },
+ "dev-libs/B-1": { "LICENSE": "TEST" },
+ "dev-libs/C-1": {},
+ }
+ installed = {
+ "dev-libs/A-1": { "DEPEND": "|| ( dev-libs/B dev-libs/C )" },
+ "dev-libs/B-1": { "LICENSE": "TEST" },
+ "dev-libs/C-1": {},
+ }
+
+ world = (
+ "dev-libs/A",
+ )
+
+ test_cases = (
+ ResolverPlaygroundTestCase(
+ [],
+ options = {"--depclean": True},
+ success = True,
+ cleanlist = ["dev-libs/C-1"]),
+ )
+
+ playground = ResolverPlayground(ebuilds=ebuilds, installed=installed, world=world)
+ try:
+ for test_case in test_cases:
+ playground.run_TestCase(test_case)
+ self.assertEqual(test_case.test_success, True, test_case.fail_msg)
+ finally:
+ playground.cleanup()