test_merge_order: test hard blocker resolution
[portage.git] / pym / portage / tests / resolver / test_merge_order.py
1 # Copyright 2011 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 from portage.tests import TestCase
5 from portage.tests.resolver.ResolverPlayground import (ResolverPlayground,
6         ResolverPlaygroundTestCase)
7
8 class MergeOrderTestCase(TestCase):
9
10         def testMergeOrder(self):
11                 ebuilds = {
12                         "app-misc/blocker-buildtime-a-1" : {},
13                         "app-misc/blocker-runtime-a-1" : {},
14                         "app-misc/blocker-runtime-hard-a-1" : {},
15                         "app-misc/circ-post-runtime-a-1": {
16                                 "PDEPEND": "app-misc/circ-post-runtime-b",
17                         },
18                         "app-misc/circ-post-runtime-b-1": {
19                                 "RDEPEND": "app-misc/circ-post-runtime-a",
20                         },
21                         "app-misc/circ-runtime-a-1": {
22                                 "RDEPEND": "app-misc/circ-runtime-b",
23                         },
24                         "app-misc/circ-runtime-b-1": {
25                                 "RDEPEND": "app-misc/circ-runtime-a",
26                         },
27                         "app-misc/installed-blocker-a-1" : {
28                                 "EAPI"   : "2",
29                                 "DEPEND" : "!app-misc/blocker-buildtime-a",
30                                 "RDEPEND" : "!app-misc/blocker-runtime-a !!app-misc/blocker-runtime-hard-a",
31                         },
32                         "app-misc/some-app-a-1": {
33                                 "RDEPEND": "app-misc/circ-runtime-a app-misc/circ-runtime-b",
34                         },
35                         "app-misc/some-app-b-1": {
36                                 "RDEPEND": "app-misc/circ-post-runtime-a app-misc/circ-post-runtime-b",
37                         },
38                 }
39
40                 installed = {
41                         "app-misc/installed-blocker-a-1" : {
42                                 "EAPI"   : "2",
43                                 "DEPEND" : "!app-misc/blocker-buildtime-a",
44                                 "RDEPEND" : "!app-misc/blocker-runtime-a !!app-misc/blocker-runtime-hard-a",
45                         },
46                 }
47
48                 test_cases = (
49                         ResolverPlaygroundTestCase(
50                                 ["app-misc/some-app-a"],
51                                 success = True,
52                                 ambigous_merge_order = True,
53                                 mergelist = [("app-misc/circ-runtime-a-1", "app-misc/circ-runtime-b-1"), "app-misc/some-app-a-1"]),
54                         ResolverPlaygroundTestCase(
55                                 ["app-misc/some-app-a"],
56                                 success = True,
57                                 ambigous_merge_order = True,
58                                 mergelist = [("app-misc/circ-runtime-b-1", "app-misc/circ-runtime-a-1"), "app-misc/some-app-a-1"]),
59                         # Test optimal merge order for a circular dep that is
60                         # RDEPEND in one direction and PDEPEND in the other.
61                         ResolverPlaygroundTestCase(
62                                 ["app-misc/some-app-b"],
63                                 success = True,
64                                 mergelist = ["app-misc/circ-post-runtime-a-1", "app-misc/circ-post-runtime-b-1", "app-misc/some-app-b-1"]),
65                         # installed package has buildtime-only blocker
66                         # that should be ignored
67                         ResolverPlaygroundTestCase(
68                                 ["app-misc/blocker-buildtime-a"],
69                                 success = True,
70                                 mergelist = ["app-misc/blocker-buildtime-a-1"]),
71                         # installed package has runtime blocker that
72                         # should cause it to be uninstalled
73                         # TODO: distinguish between install/uninstall tasks in mergelist
74                         ResolverPlaygroundTestCase(
75                                 ["app-misc/blocker-runtime-a"],
76                                 success = True,
77                                 mergelist = ["app-misc/blocker-runtime-a-1", "app-misc/installed-blocker-a-1", "!app-misc/blocker-runtime-a"]),
78                         # An installed package has a hard runtime blocker that
79                         # will not resolve automatically (unless the option
80                         # requested in bug 250286 is implemented).
81                         ResolverPlaygroundTestCase(
82                                 ["app-misc/blocker-runtime-hard-a"],
83                                 success = False,
84                                 mergelist = ['app-misc/blocker-runtime-hard-a-1', '!!app-misc/blocker-runtime-hard-a']),
85                 )
86
87                 playground = ResolverPlayground(ebuilds=ebuilds, installed=installed)
88                 try:
89                         for test_case in test_cases:
90                                 playground.run_TestCase(test_case)
91                                 self.assertEqual(test_case.test_success, True, test_case.fail_msg)
92                 finally:
93                         playground.cleanup()