Gentoo Archives: gentoo-portage-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-portage-dev@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: [gentoo-portage-dev] [PATCH 4/6] tests: Fix running on installed copy of Portage
Date: Thu, 21 Aug 2014 20:20:24
Message-Id: 1408652384-1954-5-git-send-email-mgorny@gentoo.org
In Reply to: [gentoo-portage-dev] [PATCHES] setup.py install for Portage by "Michał Górny"
1 ---
2 pym/portage/tests/__init__.py | 20 ++++++++++++++++++
3 pym/portage/tests/dbapi/test_portdb_cache.py | 5 ++---
4 pym/portage/tests/emerge/test_emerge_slot_abi.py | 7 +++----
5 pym/portage/tests/emerge/test_simple.py | 26 ++++++++++++------------
6 pym/portage/tests/lint/test_compile_modules.py | 10 +++++----
7 pym/portage/tests/lint/test_import_modules.py | 8 ++++++--
8 pym/portage/tests/repoman/test_simple.py | 8 +++++---
9 pym/portage/tests/resolver/ResolverPlayground.py | 8 +++++---
10 pym/portage/tests/util/test_getconfig.py | 5 ++---
11 9 files changed, 62 insertions(+), 35 deletions(-)
12
13 diff --git a/pym/portage/tests/__init__.py b/pym/portage/tests/__init__.py
14 index 697b800..708dd59 100644
15 --- a/pym/portage/tests/__init__.py
16 +++ b/pym/portage/tests/__init__.py
17 @@ -25,8 +25,24 @@ import portage
18 from portage import os
19 from portage import _encodings
20 from portage import _unicode_decode
21 +from portage.const import (EPREFIX, GLOBAL_CONFIG_PATH, PORTAGE_BASE_PATH,
22 + PORTAGE_BIN_PATH)
23 from portage.util._argparse import ArgumentParser
24
25 +
26 +if portage._not_installed:
27 + cnf_path = os.path.join(PORTAGE_BASE_PATH, 'cnf')
28 + cnf_etc_path = cnf_path
29 + cnf_bindir = PORTAGE_BIN_PATH
30 + cnf_sbindir = cnf_bindir
31 +else:
32 + cnf_path = os.path.join(EPREFIX or '/', GLOBAL_CONFIG_PATH)
33 + cnf_etc_path = os.path.join(EPREFIX or '/', 'etc')
34 + cnf_eprefix = EPREFIX
35 + cnf_bindir = os.path.join(EPREFIX or '/', 'usr', 'bin')
36 + cnf_sbindir = os.path.join(EPREFIX or '/', 'usr', 'sbin')
37 +
38 +
39 def main():
40 suite = unittest.TestSuite()
41 basedir = os.path.dirname(os.path.realpath(__file__))
42 @@ -178,6 +194,10 @@ class TestCase(unittest.TestCase):
43 unittest.TestCase.__init__(self, *pargs, **kwargs)
44 self.todo = False
45 self.portage_skip = None
46 + self.cnf_path = cnf_path
47 + self.cnf_etc_path = cnf_etc_path
48 + self.bindir = cnf_bindir
49 + self.sbindir = cnf_sbindir
50
51 def defaultTestResult(self):
52 return TextTestResult()
53 diff --git a/pym/portage/tests/dbapi/test_portdb_cache.py b/pym/portage/tests/dbapi/test_portdb_cache.py
54 index 94af96e..25e65f6 100644
55 --- a/pym/portage/tests/dbapi/test_portdb_cache.py
56 +++ b/pym/portage/tests/dbapi/test_portdb_cache.py
57 @@ -8,8 +8,7 @@ import textwrap
58 import portage
59 from portage import os
60 from portage import _unicode_decode
61 -from portage.const import (BASH_BINARY, PORTAGE_BIN_PATH,
62 - PORTAGE_PYM_PATH, USER_CONFIG_PATH)
63 +from portage.const import (BASH_BINARY, PORTAGE_PYM_PATH, USER_CONFIG_PATH)
64 from portage.tests import TestCase
65 from portage.tests.resolver.ResolverPlayground import ResolverPlayground
66 from portage.util import ensure_dirs
67 @@ -38,7 +37,7 @@ class PortdbCacheTestCase(TestCase):
68
69 portage_python = portage._python_interpreter
70 egencache_cmd = (portage_python, "-b", "-Wd",
71 - os.path.join(PORTAGE_BIN_PATH, "egencache"),
72 + os.path.join(self.bindir, "egencache"),
73 "--repo", "test_repo",
74 "--repositories-configuration", settings.repositories.config_string())
75 python_cmd = (portage_python, "-b", "-Wd", "-c")
76 diff --git a/pym/portage/tests/emerge/test_emerge_slot_abi.py b/pym/portage/tests/emerge/test_emerge_slot_abi.py
77 index fd7ec0e..d1f2d92 100644
78 --- a/pym/portage/tests/emerge/test_emerge_slot_abi.py
79 +++ b/pym/portage/tests/emerge/test_emerge_slot_abi.py
80 @@ -7,8 +7,7 @@ import sys
81 import portage
82 from portage import os
83 from portage import _unicode_decode
84 -from portage.const import (BASH_BINARY, PORTAGE_BIN_PATH,
85 - PORTAGE_PYM_PATH, USER_CONFIG_PATH)
86 +from portage.const import (BASH_BINARY, PORTAGE_PYM_PATH, USER_CONFIG_PATH)
87 from portage.process import find_binary
88 from portage.tests import TestCase
89 from portage.tests.resolver.ResolverPlayground import ResolverPlayground
90 @@ -70,9 +69,9 @@ class SlotAbiEmergeTestCase(TestCase):
91
92 portage_python = portage._python_interpreter
93 ebuild_cmd = (portage_python, "-b", "-Wd",
94 - os.path.join(PORTAGE_BIN_PATH, "ebuild"))
95 + os.path.join(self.bindir, "ebuild"))
96 emerge_cmd = (portage_python, "-b", "-Wd",
97 - os.path.join(PORTAGE_BIN_PATH, "emerge"))
98 + os.path.join(self.bindir, "emerge"))
99
100 test_ebuild = portdb.findname("dev-libs/dbus-glib-0.98")
101 self.assertFalse(test_ebuild is None)
102 diff --git a/pym/portage/tests/emerge/test_simple.py b/pym/portage/tests/emerge/test_simple.py
103 index bf0af8b..9c1b1bf 100644
104 --- a/pym/portage/tests/emerge/test_simple.py
105 +++ b/pym/portage/tests/emerge/test_simple.py
106 @@ -8,7 +8,7 @@ import portage
107 from portage import os
108 from portage import _unicode_decode
109 from portage.const import (BASH_BINARY, PORTAGE_BASE_PATH,
110 - PORTAGE_BIN_PATH, PORTAGE_PYM_PATH, USER_CONFIG_PATH)
111 + PORTAGE_PYM_PATH, USER_CONFIG_PATH)
112 from portage.process import find_binary
113 from portage.tests import TestCase
114 from portage.tests.resolver.ResolverPlayground import ResolverPlayground
115 @@ -175,29 +175,29 @@ pkg_preinst() {
116
117 portage_python = portage._python_interpreter
118 dispatch_conf_cmd = (portage_python, "-b", "-Wd",
119 - os.path.join(PORTAGE_BIN_PATH, "dispatch-conf"))
120 + os.path.join(self.sbindir, "dispatch-conf"))
121 ebuild_cmd = (portage_python, "-b", "-Wd",
122 - os.path.join(PORTAGE_BIN_PATH, "ebuild"))
123 + os.path.join(self.bindir, "ebuild"))
124 egencache_cmd = (portage_python, "-b", "-Wd",
125 - os.path.join(PORTAGE_BIN_PATH, "egencache"),
126 + os.path.join(self.bindir, "egencache"),
127 "--repo", "test_repo",
128 "--repositories-configuration", settings.repositories.config_string())
129 emerge_cmd = (portage_python, "-b", "-Wd",
130 - os.path.join(PORTAGE_BIN_PATH, "emerge"))
131 + os.path.join(self.bindir, "emerge"))
132 emaint_cmd = (portage_python, "-b", "-Wd",
133 - os.path.join(PORTAGE_BIN_PATH, "emaint"))
134 + os.path.join(self.sbindir, "emaint"))
135 env_update_cmd = (portage_python, "-b", "-Wd",
136 - os.path.join(PORTAGE_BIN_PATH, "env-update"))
137 + os.path.join(self.sbindir, "env-update"))
138 etc_update_cmd = (BASH_BINARY,
139 - os.path.join(PORTAGE_BIN_PATH, "etc-update"))
140 + os.path.join(self.sbindir, "etc-update"))
141 fixpackages_cmd = (portage_python, "-b", "-Wd",
142 - os.path.join(PORTAGE_BIN_PATH, "fixpackages"))
143 + os.path.join(self.sbindir, "fixpackages"))
144 portageq_cmd = (portage_python, "-b", "-Wd",
145 - os.path.join(PORTAGE_BIN_PATH, "portageq"))
146 + os.path.join(self.bindir, "portageq"))
147 quickpkg_cmd = (portage_python, "-b", "-Wd",
148 - os.path.join(PORTAGE_BIN_PATH, "quickpkg"))
149 + os.path.join(self.bindir, "quickpkg"))
150 regenworld_cmd = (portage_python, "-b", "-Wd",
151 - os.path.join(PORTAGE_BIN_PATH, "regenworld"))
152 + os.path.join(self.sbindir, "regenworld"))
153
154 rm_binary = find_binary("rm")
155 self.assertEqual(rm_binary is None, False,
156 @@ -368,7 +368,7 @@ pkg_preinst() {
157 for x in true_symlinks:
158 os.symlink(true_binary, os.path.join(fake_bin, x))
159 for x in etc_symlinks:
160 - os.symlink(os.path.join(PORTAGE_BASE_PATH, "cnf", x),
161 + os.symlink(os.path.join(self.cnf_etc_path, x),
162 os.path.join(eprefix, "etc", x))
163 with open(os.path.join(var_cache_edb, "counter"), 'wb') as f:
164 f.write(b"100")
165 diff --git a/pym/portage/tests/lint/test_compile_modules.py b/pym/portage/tests/lint/test_compile_modules.py
166 index ce7e3fb..4826cad 100644
167 --- a/pym/portage/tests/lint/test_compile_modules.py
168 +++ b/pym/portage/tests/lint/test_compile_modules.py
169 @@ -5,7 +5,7 @@ import errno
170 import itertools
171 import stat
172
173 -from portage.const import PORTAGE_BIN_PATH, PORTAGE_PYM_PATH
174 +from portage.const import PORTAGE_BIN_PATH, PORTAGE_PYM_PATH, PORTAGE_PYM_PACKAGES
175 from portage.tests import TestCase
176 from portage import os
177 from portage import _encodings
178 @@ -14,9 +14,11 @@ from portage import _unicode_decode, _unicode_encode
179 class CompileModulesTestCase(TestCase):
180
181 def testCompileModules(self):
182 - for parent, _dirs, files in itertools.chain(
183 - os.walk(PORTAGE_BIN_PATH),
184 - os.walk(PORTAGE_PYM_PATH)):
185 + iters = [os.walk(os.path.join(PORTAGE_PYM_PATH, x))
186 + for x in PORTAGE_PYM_PACKAGES]
187 + iters.append(os.walk(PORTAGE_BIN_PATH))
188 +
189 + for parent, _dirs, files in itertools.chain(*iters):
190 parent = _unicode_decode(parent,
191 encoding=_encodings['fs'], errors='strict')
192 for x in files:
193 diff --git a/pym/portage/tests/lint/test_import_modules.py b/pym/portage/tests/lint/test_import_modules.py
194 index 34261f4..fcdcb3b 100644
195 --- a/pym/portage/tests/lint/test_import_modules.py
196 +++ b/pym/portage/tests/lint/test_import_modules.py
197 @@ -1,7 +1,9 @@
198 # Copyright 2011-2012 Gentoo Foundation
199 # Distributed under the terms of the GNU General Public License v2
200
201 -from portage.const import PORTAGE_PYM_PATH
202 +from itertools import chain
203 +
204 +from portage.const import PORTAGE_PYM_PATH, PORTAGE_PYM_PACKAGES
205 from portage.tests import TestCase
206 from portage import os
207 from portage import _encodings
208 @@ -13,7 +15,9 @@ class ImportModulesTestCase(TestCase):
209 expected_failures = frozenset((
210 ))
211
212 - for mod in self._iter_modules(PORTAGE_PYM_PATH):
213 + iters = (self._iter_modules(os.path.join(PORTAGE_PYM_PATH, x))
214 + for x in PORTAGE_PYM_PACKAGES)
215 + for mod in chain(*iters):
216 try:
217 __import__(mod)
218 except ImportError as e:
219 diff --git a/pym/portage/tests/repoman/test_simple.py b/pym/portage/tests/repoman/test_simple.py
220 index 69eb36d..5dbb767 100644
221 --- a/pym/portage/tests/repoman/test_simple.py
222 +++ b/pym/portage/tests/repoman/test_simple.py
223 @@ -9,7 +9,7 @@ import portage
224 from portage import os
225 from portage import shutil
226 from portage import _unicode_decode
227 -from portage.const import PORTAGE_BASE_PATH, PORTAGE_BIN_PATH, PORTAGE_PYM_PATH
228 +from portage.const import PORTAGE_BASE_PATH, PORTAGE_PYM_PATH
229 from portage.process import find_binary
230 from portage.tests import TestCase
231 from portage.tests.resolver.ResolverPlayground import ResolverPlayground
232 @@ -171,7 +171,7 @@ class SimpleRepomanTestCase(TestCase):
233 license_dir = os.path.join(test_repo_location, "licenses")
234
235 repoman_cmd = (portage._python_interpreter, "-b", "-Wd",
236 - os.path.join(PORTAGE_BIN_PATH, "repoman"))
237 + os.path.join(self.bindir, "repoman"))
238
239 git_binary = find_binary("git")
240 git_cmd = (git_binary,)
241 @@ -274,7 +274,9 @@ class SimpleRepomanTestCase(TestCase):
242 os.symlink(test_repo_location, test_repo_symlink)
243 # repoman checks metadata.dtd for recent CTIME, so copy the file in
244 # order to ensure that the CTIME is current
245 - shutil.copyfile(metadata_dtd, os.path.join(distdir, "metadata.dtd"))
246 + # NOTE: if we don't have the file around, let repoman try to fetch it.
247 + if os.path.exists(metadata_dtd):
248 + shutil.copyfile(metadata_dtd, os.path.join(distdir, "metadata.dtd"))
249
250 if debug:
251 # The subprocess inherits both stdout and stderr, for
252 diff --git a/pym/portage/tests/resolver/ResolverPlayground.py b/pym/portage/tests/resolver/ResolverPlayground.py
253 index 077e271..675e23f 100644
254 --- a/pym/portage/tests/resolver/ResolverPlayground.py
255 +++ b/pym/portage/tests/resolver/ResolverPlayground.py
256 @@ -15,6 +15,7 @@ from portage.package.ebuild.config import config
257 from portage.package.ebuild.digestgen import digestgen
258 from portage._sets import load_default_config
259 from portage._sets.base import InternalPackageSet
260 +from portage.tests import cnf_path
261 from portage.util import ensure_dirs, normalize_path
262 from portage.versions import catsplit
263
264 @@ -65,6 +66,7 @@ class ResolverPlayground(object):
265 If a metadata key is missing, it gets a default value.
266 profile: settings defined by the profile.
267 """
268 +
269 self.debug = debug
270 self.eprefix = normalize_path(tempfile.mkdtemp())
271 portage.const.EPREFIX = self.eprefix.rstrip(os.sep)
272 @@ -414,7 +416,7 @@ class ResolverPlayground(object):
273 make_globals_path = os.path.join(self.eroot,
274 GLOBAL_CONFIG_PATH.lstrip(os.sep), "make.globals")
275 ensure_dirs(os.path.dirname(make_globals_path))
276 - os.symlink(os.path.join(PORTAGE_BASE_PATH, "cnf", "make.globals"),
277 + os.symlink(os.path.join(cnf_path, "make.globals"),
278 make_globals_path)
279
280 #Create /usr/share/portage/config/sets/portage.conf
281 @@ -425,8 +427,8 @@ class ResolverPlayground(object):
282 except os.error:
283 pass
284
285 - provided_sets_portage_conf = \
286 - os.path.join(PORTAGE_BASE_PATH, "cnf/sets/portage.conf")
287 + provided_sets_portage_conf = (
288 + os.path.join(cnf_path, "sets", "portage.conf"))
289 os.symlink(provided_sets_portage_conf, os.path.join(default_sets_conf_dir, "portage.conf"))
290
291 set_config_dir = os.path.join(user_config_dir, "sets")
292 diff --git a/pym/portage/tests/util/test_getconfig.py b/pym/portage/tests/util/test_getconfig.py
293 index e5fd60f..16f415c 100644
294 --- a/pym/portage/tests/util/test_getconfig.py
295 +++ b/pym/portage/tests/util/test_getconfig.py
296 @@ -3,6 +3,7 @@
297
298 import tempfile
299
300 +import portage
301 from portage import os
302 from portage import shutil
303 from portage import _unicode_encode
304 @@ -26,9 +27,7 @@ class GetConfigTestCase(TestCase):
305 }
306
307 def testGetConfig(self):
308 -
309 - make_globals_file = os.path.join(PORTAGE_BASE_PATH,
310 - 'cnf', 'make.globals')
311 + make_globals_file = os.path.join(self.cnf_path, "make.globals")
312 d = getconfig(make_globals_file)
313 for k, v in self._cases.items():
314 self.assertEqual(d[k], v)
315 --
316 2.0.4

Replies