test_merge_order: test 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/circ-post-runtime-a-1": {
15                                 "PDEPEND": "app-misc/circ-post-runtime-b",
16                         },
17                         "app-misc/circ-post-runtime-b-1": {
18                                 "RDEPEND": "app-misc/circ-post-runtime-a",
19                         },
20                         "app-misc/circ-runtime-a-1": {
21                                 "RDEPEND": "app-misc/circ-runtime-b",
22                         },
23                         "app-misc/circ-runtime-b-1": {
24                                 "RDEPEND": "app-misc/circ-runtime-a",
25                         },
26                         "app-misc/installed-blocker-a-1" : {
27                                 "DEPEND" : "!app-misc/blocker-buildtime-a",
28                                 "RDEPEND" : "!app-misc/blocker-runtime-a",
29                         },
30                         "app-misc/some-app-a-1": {
31                                 "RDEPEND": "app-misc/circ-runtime-a app-misc/circ-runtime-b",
32                         },
33                         "app-misc/some-app-b-1": {
34                                 "RDEPEND": "app-misc/circ-post-runtime-a app-misc/circ-post-runtime-b",
35                         },
36                 }
37
38                 installed = {
39                         "app-misc/installed-blocker-a-1" : {
40                                 "DEPEND" : "!app-misc/blocker-buildtime-a",
41                                 "RDEPEND" : "!app-misc/blocker-runtime-a",
42                         }
43                 }
44
45                 test_cases = (
46                         ResolverPlaygroundTestCase(
47                                 ["app-misc/some-app-a"],
48                                 success = True,
49                                 ambigous_merge_order = True,
50                                 mergelist = [("app-misc/circ-runtime-a-1", "app-misc/circ-runtime-b-1"), "app-misc/some-app-a-1"]),
51                         ResolverPlaygroundTestCase(
52                                 ["app-misc/some-app-a"],
53                                 success = True,
54                                 ambigous_merge_order = True,
55                                 mergelist = [("app-misc/circ-runtime-b-1", "app-misc/circ-runtime-a-1"), "app-misc/some-app-a-1"]),
56                         # Test optimal merge order for a circular dep that is
57                         # RDEPEND in one direction and PDEPEND in the other.
58                         ResolverPlaygroundTestCase(
59                                 ["app-misc/some-app-b"],
60                                 success = True,
61                                 mergelist = ["app-misc/circ-post-runtime-a-1", "app-misc/circ-post-runtime-b-1", "app-misc/some-app-b-1"]),
62                         # installed package has buildtime-only blocker
63                         # that should be ignored
64                         ResolverPlaygroundTestCase(
65                                 ["app-misc/blocker-buildtime-a"],
66                                 success = True,
67                                 mergelist = ["app-misc/blocker-buildtime-a-1"]),
68                         # installed package has runtime blocker that
69                         # should cause it to be uninstalled
70                         # TODO: distinguish between install/uninstall tasks in mergelist
71                         ResolverPlaygroundTestCase(
72                                 ["app-misc/blocker-runtime-a"],
73                                 success = True,
74                                 mergelist = ["app-misc/blocker-runtime-a-1", "app-misc/installed-blocker-a-1", "!app-misc/blocker-runtime-a"]),
75                 )
76
77                 playground = ResolverPlayground(ebuilds=ebuilds, installed=installed)
78                 try:
79                         for test_case in test_cases:
80                                 playground.run_TestCase(test_case)
81                                 self.assertEqual(test_case.test_success, True, test_case.fail_msg)
82                 finally:
83                         playground.cleanup()