summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pym/portage/tests/resolver/ResolverPlayground.py84
-rw-r--r--pym/portage/tests/resolver/test_autounmask.py144
-rw-r--r--pym/portage/tests/resolver/test_eapi.py84
-rw-r--r--pym/portage/tests/resolver/test_simple.py28
4 files changed, 219 insertions, 121 deletions
diff --git a/pym/portage/tests/resolver/ResolverPlayground.py b/pym/portage/tests/resolver/ResolverPlayground.py
index fd916a71b..46ae837f6 100644
--- a/pym/portage/tests/resolver/ResolverPlayground.py
+++ b/pym/portage/tests/resolver/ResolverPlayground.py
@@ -1,7 +1,7 @@
# Copyright 2010 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-from itertools import chain
+from itertools import chain, permutations
import shutil
import tempfile
import portage
@@ -183,30 +183,88 @@ class ResolverPlayground(object):
return settings, trees
- def run(self, myfiles, myopts={}, myaction=None):
- myopts["--pretend"] = True
- myopts["--quiet"] = True
- myopts["--root"] = self.root
- myopts["--config-root"] = self.root
- myopts["--root-deps"] = "rdeps"
+ def run(self, atoms, options={}, action=None):
+ options = options.copy()
+ options["--pretend"] = True
+ options["--quiet"] = True
+ options["--root"] = self.root
+ options["--config-root"] = self.root
+ options["--root-deps"] = "rdeps"
# Add a fake _test_ option that can be used for
# conditional test code.
- myopts["_test_"] = True
+ options["_test_"] = True
portage.util.noiselimit = -2
- myparams = create_depgraph_params(myopts, myaction)
- success, mydepgraph, favorites = backtrack_depgraph(
- self.settings, self.trees, myopts, myparams, myaction, myfiles, None)
- result = ResolverPlaygroundResult(success, mydepgraph, favorites)
+ params = create_depgraph_params(options, action)
+ success, depgraph, favorites = backtrack_depgraph(
+ self.settings, self.trees, options, params, action, atoms, None)
+ result = ResolverPlaygroundResult(atoms, success, depgraph, favorites)
portage.util.noiselimit = 0
return result
+ def run_TestCase(self, test_case):
+ if not isinstance(test_case, ResolverPlaygroundTestCase):
+ raise TypeError("ResolverPlayground needs a ResolverPlaygroundTestCase")
+ for atoms in test_case.requests:
+ result = self.run(atoms, test_case.options, test_case.action)
+ if not test_case.compare_with_result(result):
+ return
+
def cleanup(self):
shutil.rmtree(self.root)
+class ResolverPlaygroundTestCase(object):
+
+ def __init__(self, request, **kwargs):
+ self.checks = {
+ "success": None,
+ "mergelist": None,
+ "use_changes": None,
+ "unstable_keywords": None
+ }
+
+ self.all_permutations = kwargs.pop("all_permutations", False)
+ self.ignore_mergelist_order = kwargs.pop("ignore_mergelist_order", False)
+
+ if self.all_permutations:
+ self.requests = list(permutations(request))
+ else:
+ self.requests = [request]
+
+ self.options = kwargs.pop("options", {})
+ 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
+
+ def compare_with_result(self, result):
+ fail_msgs = []
+ for key, value in self.checks.items():
+ got = getattr(result, key)
+ expected = value
+ if key == "mergelist" and self.ignore_mergelist_order and value is not None :
+ got = set(got)
+ expected = set(expected)
+ elif key == "unstable_keywords" and expected is not None:
+ expected = set(expected)
+
+ if got != expected:
+ fail_msgs.append("atoms: (" + ", ".join(result.atoms) + "), key: " + \
+ key + ", expected: " + str(expected) + ", got: " + str(got))
+ if fail_msgs:
+ self.test_success = False
+ self.fail_msg = "\n".join(fail_msgs)
+ return False
+ return True
+
class ResolverPlaygroundResult(object):
- def __init__(self, success, mydepgraph, favorites):
+ def __init__(self, atoms, success, mydepgraph, favorites):
+ self.atoms = atoms
self.success = success
self.depgraph = mydepgraph
self.favorites = favorites
diff --git a/pym/portage/tests/resolver/test_autounmask.py b/pym/portage/tests/resolver/test_autounmask.py
index d528f9077..bb7ff0ad7 100644
--- a/pym/portage/tests/resolver/test_autounmask.py
+++ b/pym/portage/tests/resolver/test_autounmask.py
@@ -2,7 +2,7 @@
# 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.tests.resolver.ResolverPlayground import ResolverPlayground, ResolverPlaygroundTestCase
class AutounmaskTestCase(TestCase):
@@ -37,80 +37,116 @@ class AutounmaskTestCase(TestCase):
"sci-libs/P-1": { },
}
- requests = (
+ test_cases = (
#Test USE changes.
#The simple case.
- (["dev-libs/A:1"], {"--autounmask": "n"}, None, False, None, None, None),
- (["dev-libs/A:1"], {"--autounmask": True}, None, False, \
- ["dev-libs/C-1", "dev-libs/B-1", "dev-libs/A-1"], { "dev-libs/B-1": {"foo": True} }, None),
+ ResolverPlaygroundTestCase(
+ ["dev-libs/A:1"],
+ options = {"--autounmask": "n"},
+ success = False),
+ ResolverPlaygroundTestCase(
+ ["dev-libs/A:1"],
+ options = {"--autounmask": True},
+ success = False,
+ mergelist = ["dev-libs/C-1", "dev-libs/B-1", "dev-libs/A-1"],
+ use_changes = { "dev-libs/B-1": {"foo": True} } ),
#Make sure we restart if needed.
- (["dev-libs/B", "dev-libs/A:1"], {"--autounmask": True}, None, False, \
- ["dev-libs/C-1", "dev-libs/B-1", "dev-libs/A-1"], { "dev-libs/B-1": {"foo": True} }, None),
- (["dev-libs/A:1", "dev-libs/B"], {"--autounmask": True}, None, False, \
- ["dev-libs/C-1", "dev-libs/B-1", "dev-libs/A-1"], { "dev-libs/B-1": {"foo": True} }, None),
- (["dev-libs/A:1", "dev-libs/A:2"], {"--autounmask": True}, None, False, \
- ["dev-libs/D-1", "dev-libs/C-1", "dev-libs/B-1", "dev-libs/A-1", "dev-libs/A-2"], \
- { "dev-libs/B-1": {"foo": True, "bar": True} }, None),
- (["dev-libs/B", "dev-libs/A:1", "dev-libs/A:2"], {"--autounmask": True}, None, False, \
- ["dev-libs/D-1", "dev-libs/C-1", "dev-libs/B-1", "dev-libs/A-1", "dev-libs/A-2"], \
- { "dev-libs/B-1": {"foo": True, "bar": True} }, None),
- (["dev-libs/A:1", "dev-libs/B", "dev-libs/A:2"], {"--autounmask": True}, None, False, \
- ["dev-libs/D-1", "dev-libs/C-1", "dev-libs/B-1", "dev-libs/A-1", "dev-libs/A-2"], \
- { "dev-libs/B-1": {"foo": True, "bar": True} }, None),
- (["dev-libs/A:1", "dev-libs/A:2", "dev-libs/B"], {"--autounmask": True}, None, False, \
- ["dev-libs/D-1", "dev-libs/C-1", "dev-libs/B-1", "dev-libs/A-1", "dev-libs/A-2"], \
- { "dev-libs/B-1": {"foo": True, "bar": True} }, None),
+ ResolverPlaygroundTestCase(
+ ["dev-libs/A:1", "dev-libs/B"],
+ options = {"--autounmask": True},
+ all_permutations = True,
+ success = False,
+ mergelist = ["dev-libs/C-1", "dev-libs/B-1", "dev-libs/A-1"],
+ use_changes = { "dev-libs/B-1": {"foo": True} } ),
+ ResolverPlaygroundTestCase(
+ ["dev-libs/A:1", "dev-libs/A:2", "dev-libs/B"],
+ options = {"--autounmask": True},
+ all_permutations = True,
+ success = False,
+ mergelist = ["dev-libs/D-1", "dev-libs/C-1", "dev-libs/B-1", "dev-libs/A-1", "dev-libs/A-2"],
+ ignore_mergelist_order = True,
+ use_changes = { "dev-libs/B-1": {"foo": True, "bar": True} } ),
#Test keywording.
#The simple case.
- (["app-misc/Z"], {"--autounmask": "n"}, None, False, None, None, None),
- (["app-misc/Z"], {"--autounmask": True}, None, False, \
- ["app-misc/Y-1", "app-misc/Z-1"], None, ["app-misc/Y-1", "app-misc/Z-1"]),
+ ResolverPlaygroundTestCase(
+ ["app-misc/Z"],
+ options = {"--autounmask": "n"},
+ success = False),
+ ResolverPlaygroundTestCase(
+ ["app-misc/Z"],
+ options = {"--autounmask": True},
+ success = False,
+ mergelist = ["app-misc/Y-1", "app-misc/Z-1"],
+ unstable_keywords = ["app-misc/Y-1", "app-misc/Z-1"]),
#Make sure that the backtracking for slot conflicts handles our mess.
- (["=app-misc/V-1", "app-misc/W"], {"--autounmask": True}, None, False, \
- ["app-misc/W-2", "app-misc/V-1"], None, ["app-misc/W-2", "app-misc/V-1"]),
- (["app-misc/W", "=app-misc/V-1"], {"--autounmask": True}, None, False, \
- ["app-misc/W-2", "app-misc/V-1"], None, ["app-misc/W-2", "app-misc/V-1"]),
+ ResolverPlaygroundTestCase(
+ ["=app-misc/V-1", "app-misc/W"],
+ options = {"--autounmask": True},
+ all_permutations = True,
+ success = False,
+ mergelist = ["app-misc/W-2", "app-misc/V-1"],
+ unstable_keywords = ["app-misc/W-2", "app-misc/V-1"]),
#Mixed testing
#Make sure we don't change use for something in a || dep if there is another choice
#that needs no change.
-
- (["=sci-libs/K-1"], {"--autounmask": True}, None, True, \
- ["sci-libs/P-1", "sci-libs/K-1"], None, None),
- (["=sci-libs/K-2"], {"--autounmask": True}, None, True, \
- ["sci-libs/P-1", "sci-libs/K-2"], None, None),
- (["=sci-libs/K-3"], {"--autounmask": True}, None, True, \
- ["sci-libs/P-1", "sci-libs/K-3"], None, None),
- (["=sci-libs/K-4"], {"--autounmask": True}, None, True, \
- ["sci-libs/P-1", "sci-libs/K-4"], None, None),
- (["=sci-libs/K-5"], {"--autounmask": True}, None, True, \
- ["sci-libs/P-1", "sci-libs/K-5"], None, None),
- (["=sci-libs/K-6"], {"--autounmask": True}, None, True, \
- ["sci-libs/P-1", "sci-libs/K-6"], None, None),
+
+ ResolverPlaygroundTestCase(
+ ["=sci-libs/K-1"],
+ options = {"--autounmask": True},
+ success = True,
+ mergelist = ["sci-libs/P-1", "sci-libs/K-1"]),
+ ResolverPlaygroundTestCase(
+ ["=sci-libs/K-2"],
+ options = {"--autounmask": True},
+ success = True,
+ mergelist = ["sci-libs/P-1", "sci-libs/K-2"]),
+ ResolverPlaygroundTestCase(
+ ["=sci-libs/K-3"],
+ options = {"--autounmask": True},
+ success = True,
+ mergelist = ["sci-libs/P-1", "sci-libs/K-3"]),
+ ResolverPlaygroundTestCase(
+ ["=sci-libs/K-4"],
+ options = {"--autounmask": True},
+ success = True,
+ mergelist = ["sci-libs/P-1", "sci-libs/K-4"]),
+ ResolverPlaygroundTestCase(
+ ["=sci-libs/K-5"],
+ options = {"--autounmask": True},
+ success = True,
+ mergelist = ["sci-libs/P-1", "sci-libs/K-5"]),
+ ResolverPlaygroundTestCase(
+ ["=sci-libs/K-6"],
+ options = {"--autounmask": True},
+ success = True,
+ mergelist = ["sci-libs/P-1", "sci-libs/K-6"]),
#Make sure we prefer use changes over keyword changes.
- (["=sci-libs/K-7"], {"--autounmask": True}, None, False, \
- ["sci-libs/L-1", "sci-libs/K-7"], { "sci-libs/L-1": { "bar": True } }, None),
- (["=sci-libs/K-8"], {"--autounmask": True}, None, False, \
- ["sci-libs/L-1", "sci-libs/K-8"], { "sci-libs/L-1": { "bar": True } }, None),
+ ResolverPlaygroundTestCase(
+ ["=sci-libs/K-7"],
+ options = {"--autounmask": True},
+ success = False,
+ mergelist = ["sci-libs/L-1", "sci-libs/K-7"],
+ use_changes = { "sci-libs/L-1": { "bar": True } }),
+ ResolverPlaygroundTestCase(
+ ["=sci-libs/K-8"],
+ options = {"--autounmask": True},
+ success = False,
+ mergelist = ["sci-libs/L-1", "sci-libs/K-8"],
+ use_changes = { "sci-libs/L-1": { "bar": True } }),
)
playground = ResolverPlayground(ebuilds=ebuilds)
try:
- for atoms, options, action, expected_result, expected_mergelist, \
- expected_use_changes, expected_unstable_keywords in requests:
- result = playground.run(atoms, options, action)
- if expected_unstable_keywords is not None:
- expected_unstable_keywords = set(expected_unstable_keywords)
- self.assertEqual(
- (result.success, result.mergelist, result.use_changes, result.unstable_keywords),
- (expected_result, expected_mergelist, expected_use_changes, expected_unstable_keywords)
- )
+ 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()
diff --git a/pym/portage/tests/resolver/test_eapi.py b/pym/portage/tests/resolver/test_eapi.py
index 94cdd4a99..dec1008fb 100644
--- a/pym/portage/tests/resolver/test_eapi.py
+++ b/pym/portage/tests/resolver/test_eapi.py
@@ -2,7 +2,7 @@
# 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.tests.resolver.ResolverPlayground import ResolverPlayground, ResolverPlaygroundTestCase
class EAPITestCase(TestCase):
@@ -53,50 +53,48 @@ class EAPITestCase(TestCase):
"dev-libs/B-1": {"EAPI": 1, "IUSE": "+foo"},
}
- requests = (
- (["=dev-libs/A-1.0"], {}, None, False, None),
- (["=dev-libs/A-1.1"], {}, None, True, ["dev-libs/A-1.1"]),
- (["=dev-libs/A-1.2"], {}, None, True, ["dev-libs/A-1.2"]),
- (["=dev-libs/A-1.3"], {}, None, True, ["dev-libs/A-1.3"]),
- #~ (["=dev-libs/A-1.4"], {}, None, True, ["dev-libs/A-1.4"]),
-
- (["=dev-libs/A-2.0"], {}, None, False, None),
- (["=dev-libs/A-2.1"], {}, None, True, ["dev-libs/B-1", "dev-libs/A-2.1"]),
- (["=dev-libs/A-2.2"], {}, None, True, ["dev-libs/B-1", "dev-libs/A-2.2"]),
- (["=dev-libs/A-2.3"], {}, None, True, ["dev-libs/B-1", "dev-libs/A-2.3"]),
- #~ (["=dev-libs/A-2.4"], {}, None, True, ["dev-libs/B-1", "dev-libs/A-2.4"]),
-
- (["=dev-libs/A-3.0"], {}, None, False, None),
- (["=dev-libs/A-3.1"], {}, None, False, None),
- (["=dev-libs/A-3.2"], {}, None, True, ["dev-libs/B-1", "dev-libs/A-3.2"]),
- (["=dev-libs/A-3.3"], {}, None, True, ["dev-libs/B-1", "dev-libs/A-3.3"]),
- #~ (["=dev-libs/A-3.4"], {}, None, True, ["dev-libs/B-1", "dev-libs/A-3.4"]),
-
- (["=dev-libs/A-4.0"], {}, None, False, None),
- (["=dev-libs/A-4.1"], {}, None, False, None),
- (["=dev-libs/A-4.2"], {}, None, True, ["dev-libs/A-4.2"]),
- (["=dev-libs/A-4.3"], {}, None, True, ["dev-libs/A-4.3"]),
- #~ (["=dev-libs/A-4.4"], {}, None, True, ["dev-libs/A-4.4"]),
-
- #~ (["=dev-libs/A-5.0"], {}, None, False, None),
- #~ (["=dev-libs/A-5.1"], {}, None, False, None),
- #~ (["=dev-libs/A-5.2"], {}, None, False, None),
- #~ (["=dev-libs/A-5.3"], {}, None, False, None),
- #~ (["=dev-libs/A-5.4"], {}, None, True, ["dev-libs/B-1", "dev-libs/A-5.4"]),
-
- #~ (["=dev-libs/A-6.0"], {}, None, False, None),
- #~ (["=dev-libs/A-6.1"], {}, None, False, None),
- #~ (["=dev-libs/A-6.2"], {}, None, False, None),
- #~ (["=dev-libs/A-6.3"], {}, None, False, None),
- #~ (["=dev-libs/A-6.4"], {}, None, True, ["dev-libs/B-1", "dev-libs/A-6.4"]),
- )
+ test_cases = (
+ ResolverPlaygroundTestCase(["=dev-libs/A-1.0"], success = False),
+ ResolverPlaygroundTestCase(["=dev-libs/A-1.1"], success = True, mergelist = ["dev-libs/A-1.1"]),
+ ResolverPlaygroundTestCase(["=dev-libs/A-1.2"], success = True, mergelist = ["dev-libs/A-1.2"]),
+ ResolverPlaygroundTestCase(["=dev-libs/A-1.3"], success = True, mergelist = ["dev-libs/A-1.3"]),
+ #~ ResolverPlaygroundTestCase(["=dev-libs/A-1.4"], success = True, mergelist = ["dev-libs/A-1.4"]),
+
+ ResolverPlaygroundTestCase(["=dev-libs/A-2.0"], success = False),
+ ResolverPlaygroundTestCase(["=dev-libs/A-2.1"], success = True, mergelist = ["dev-libs/B-1", "dev-libs/A-2.1"]),
+ ResolverPlaygroundTestCase(["=dev-libs/A-2.2"], success = True, mergelist = ["dev-libs/B-1", "dev-libs/A-2.2"]),
+ ResolverPlaygroundTestCase(["=dev-libs/A-2.3"], success = True, mergelist = ["dev-libs/B-1", "dev-libs/A-2.3"]),
+ #~ ResolverPlaygroundTestCase(["=dev-libs/A-2.4"], success = True, mergelist = ["dev-libs/B-1", "dev-libs/A-2.4"]),
+
+ ResolverPlaygroundTestCase(["=dev-libs/A-3.0"], success = False),
+ ResolverPlaygroundTestCase(["=dev-libs/A-3.1"], success = False),
+ ResolverPlaygroundTestCase(["=dev-libs/A-3.2"], success = True, mergelist = ["dev-libs/B-1", "dev-libs/A-3.2"]),
+ ResolverPlaygroundTestCase(["=dev-libs/A-3.3"], success = True, mergelist = ["dev-libs/B-1", "dev-libs/A-3.3"]),
+ #~ ResolverPlaygroundTestCase(["=dev-libs/A-3.4"], success = True, mergelist = ["dev-libs/B-1", "dev-libs/A-3.4"]),
+
+ ResolverPlaygroundTestCase(["=dev-libs/A-4.0"], success = False),
+ ResolverPlaygroundTestCase(["=dev-libs/A-4.1"], success = False),
+ ResolverPlaygroundTestCase(["=dev-libs/A-4.2"], success = True, mergelist = ["dev-libs/A-4.2"]),
+ ResolverPlaygroundTestCase(["=dev-libs/A-4.3"], success = True, mergelist = ["dev-libs/A-4.3"]),
+ #~ ResolverPlaygroundTestCase(["=dev-libs/A-4.4"], success = True, mergelist = ["dev-libs/A-4.4"]),
+
+ #~ ResolverPlaygroundTestCase(["=dev-libs/A-5.0"], success = False),
+ #~ ResolverPlaygroundTestCase(["=dev-libs/A-5.1"], success = False),
+ #~ ResolverPlaygroundTestCase(["=dev-libs/A-5.2"], success = False),
+ #~ ResolverPlaygroundTestCase(["=dev-libs/A-5.3"], success = False),
+ #~ ResolverPlaygroundTestCase(["=dev-libs/A-5.4"], success = True, mergelist = ["dev-libs/B-1", "dev-libs/A-5.4"]),
+
+ #~ ResolverPlaygroundTestCase(["=dev-libs/A-6.0"], success = False),
+ #~ ResolverPlaygroundTestCase(["=dev-libs/A-6.1"], success = False),
+ #~ ResolverPlaygroundTestCase(["=dev-libs/A-6.2"], success = False),
+ #~ ResolverPlaygroundTestCase(["=dev-libs/A-6.3"], success = False),
+ #~ ResolverPlaygroundTestCase(["=dev-libs/A-6.4"], success = True, mergelist = ["dev-libs/B-1", "dev-libs/A-6.4"]),
+ )
playground = ResolverPlayground(ebuilds=ebuilds)
try:
- for atoms, options, action, \
- expected_result, expected_mergelist in requests:
- result = playground.run(atoms, options, action)
- self.assertEqual((result.success, result.mergelist),
- (expected_result, expected_mergelist))
+ 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()
diff --git a/pym/portage/tests/resolver/test_simple.py b/pym/portage/tests/resolver/test_simple.py
index ef19abe1b..8665098a8 100644
--- a/pym/portage/tests/resolver/test_simple.py
+++ b/pym/portage/tests/resolver/test_simple.py
@@ -2,7 +2,7 @@
# 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.tests.resolver.ResolverPlayground import ResolverPlayground, ResolverPlaygroundTestCase
class SimpleResolverTestCase(TestCase):
@@ -16,19 +16,25 @@ class SimpleResolverTestCase(TestCase):
"dev-libs/B-1.1": {},
}
- requests = (
- (["dev-libs/A"], {}, None, True, ["dev-libs/A-1"]),
- (["=dev-libs/A-2"], {}, None, False, None),
- (["dev-libs/B"], {"--noreplace": True}, None, True, []),
- (["dev-libs/B"], {"--update": True}, None, True, ["dev-libs/B-1.2"]),
+ test_cases = (
+ ResolverPlaygroundTestCase(["dev-libs/A"], success = True, mergelist = ["dev-libs/A-1"]),
+ ResolverPlaygroundTestCase(["=dev-libs/A-2"], success = False),
+ ResolverPlaygroundTestCase(
+ ["dev-libs/B"],
+ options = {"--noreplace": True},
+ success = True,
+ mergelist = []),
+ ResolverPlaygroundTestCase(
+ ["dev-libs/B"],
+ options = {"--update": True},
+ success = True,
+ mergelist = ["dev-libs/B-1.2"]),
)
playground = ResolverPlayground(ebuilds=ebuilds, installed=installed)
try:
- for atoms, options, action, \
- expected_result, expected_mergelist in requests:
- result = playground.run(atoms, options, action)
- self.assertEqual((result.success, result.mergelist),
- (expected_result, expected_mergelist))
+ 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()