1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
# Copyright 2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
import subprocess
import sys
import portage
from portage import os
from portage import _unicode_decode
from portage.const import PORTAGE_BIN_PATH, PORTAGE_PYM_PATH
from portage.process import find_binary
from portage.tests import TestCase
from portage.tests.resolver.ResolverPlayground import ResolverPlayground
from portage.util import ensure_dirs
class SimpleEmergeTestCase(TestCase):
def testSimple(self):
ebuilds = {
"dev-libs/A-1": {
"EAPI" : "4",
"IUSE" : "+flag",
"KEYWORDS": "x86",
"LICENSE": "GPL-2",
"RDEPEND": "flag? ( dev-libs/B[flag] )",
},
"dev-libs/B-1": {
"EAPI" : "4",
"IUSE" : "+flag",
"KEYWORDS": "x86",
"LICENSE": "GPL-2",
},
}
installed = {
"dev-libs/A-1": {
"EAPI" : "4",
"IUSE" : "+flag",
"KEYWORDS": "x86",
"LICENSE": "GPL-2",
"RDEPEND": "flag? ( dev-libs/B[flag] )",
"USE": "flag",
},
"dev-libs/B-1": {
"EAPI" : "4",
"IUSE" : "+flag",
"KEYWORDS": "x86",
"LICENSE": "GPL-2",
"USE": "flag",
},
}
test_args = (
("--version",),
("--info",),
("--info", "--verbose"),
("--pretend", "dev-libs/A"),
("--pretend", "--tree", "--complete-graph", "dev-libs/A"),
("-p", "dev-libs/B"),
("--oneshot", "dev-libs/A",),
("--noreplace", "dev-libs/A",),
("--pretend", "--depclean", "--verbose", "dev-libs/B"),
("--pretend", "--depclean",),
("--depclean",),
("--unmerge", "--quiet", "dev-libs/A"),
("-C", "--quiet", "dev-libs/B"),
)
playground = ResolverPlayground(ebuilds=ebuilds, installed=installed)
settings = playground.settings
eprefix = settings["EPREFIX"]
distdir = os.path.join(eprefix, "distdir")
fake_bin = os.path.join(eprefix, "bin")
portage_tmpdir = os.path.join(eprefix, "var", "tmp", "portage")
portdir = settings["PORTDIR"]
profile_path = settings.profile_path
var_cache_edb = os.path.join(eprefix, "var", "cache", "edb")
path = os.environ.get("PATH")
if path is not None and not path.strip():
path = None
if path is None:
path = ""
else:
path = ":" + path
path = fake_bin + path
pythonpath = os.environ.get("PYTHONPATH")
if pythonpath is not None and not pythonpath.strip():
pythonpath = None
if pythonpath is not None and \
pythonpath.split(":")[0] == PORTAGE_PYM_PATH:
pass
else:
if pythonpath is None:
pythonpath = ""
else:
pythonpath = ":" + pythonpath
pythonpath = PORTAGE_PYM_PATH + pythonpath
env = {
"__PORTAGE_TEST_EPREFIX" : eprefix,
"DISTDIR" : distdir,
"INFODIR" : "",
"INFOPATH" : "",
"PATH" : path,
"PORTAGE_GRPNAME" : os.environ["PORTAGE_GRPNAME"],
"PORTAGE_TMPDIR" : portage_tmpdir,
"PORTAGE_USERNAME" : os.environ["PORTAGE_USERNAME"],
"PORTDIR" : portdir,
"PYTHONPATH" : pythonpath,
}
dirs = [distdir, fake_bin, portage_tmpdir, var_cache_edb]
true_symlinks = ["chown", "chgrp"]
true_binary = find_binary("true")
self.assertEqual(true_binary is None, False,
"true command not found")
try:
for d in dirs:
ensure_dirs(d)
for x in true_symlinks:
os.symlink(true_binary, os.path.join(fake_bin, x))
with open(os.path.join(var_cache_edb, "counter"), 'wb') as f:
f.write(b"100")
# non-empty system set keeps --depclean quiet
with open(os.path.join(profile_path, "packages"), 'w') as f:
f.write("*dev-libs/token-system-pkg")
for args in test_args:
proc = subprocess.Popen([portage._python_interpreter, "-Wd",
os.path.join(PORTAGE_BIN_PATH, "emerge")] + list(args),
env=env, stdout=subprocess.PIPE)
output = proc.stdout.readlines()
proc.wait()
proc.stdout.close()
if proc.returncode != os.EX_OK:
for line in output:
sys.stderr.write(_unicode_decode(line))
self.assertEqual(os.EX_OK, proc.returncode,
"emerge failed with args %s" % (args,))
finally:
playground.cleanup()
|