commit: 529b6985cb3f65d52d6f54bb251c446d317b6508 Author: Michał Górny <mgorny <AT> gentoo <DOT> org> AuthorDate: Sat Aug 9 10:17:59 2014 +0000 Commit: Brian Dolbec <brian.dolbec <AT> gmail <DOT> com> CommitDate: Thu Sep 11 23:44:25 2014 +0000 URL: http://sources.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=529b6985
tests: Fix running on installed copy of Portage --- pym/portage/tests/__init__.py | 20 ++++++++++++++++++ pym/portage/tests/dbapi/test_portdb_cache.py | 5 ++--- pym/portage/tests/emerge/test_emerge_slot_abi.py | 7 +++---- pym/portage/tests/emerge/test_simple.py | 26 ++++++++++++------------ pym/portage/tests/lint/test_compile_modules.py | 10 +++++---- pym/portage/tests/lint/test_import_modules.py | 8 ++++++-- pym/portage/tests/repoman/test_simple.py | 8 +++++--- pym/portage/tests/resolver/ResolverPlayground.py | 8 +++++--- pym/portage/tests/util/test_getconfig.py | 4 +--- 9 files changed, 61 insertions(+), 35 deletions(-) diff --git a/pym/portage/tests/__init__.py b/pym/portage/tests/__init__.py index 697b800..708dd59 100644 --- a/pym/portage/tests/__init__.py +++ b/pym/portage/tests/__init__.py @@ -25,8 +25,24 @@ import portage from portage import os from portage import _encodings from portage import _unicode_decode +from portage.const import (EPREFIX, GLOBAL_CONFIG_PATH, PORTAGE_BASE_PATH, + PORTAGE_BIN_PATH) from portage.util._argparse import ArgumentParser + +if portage._not_installed: + cnf_path = os.path.join(PORTAGE_BASE_PATH, 'cnf') + cnf_etc_path = cnf_path + cnf_bindir = PORTAGE_BIN_PATH + cnf_sbindir = cnf_bindir +else: + cnf_path = os.path.join(EPREFIX or '/', GLOBAL_CONFIG_PATH) + cnf_etc_path = os.path.join(EPREFIX or '/', 'etc') + cnf_eprefix = EPREFIX + cnf_bindir = os.path.join(EPREFIX or '/', 'usr', 'bin') + cnf_sbindir = os.path.join(EPREFIX or '/', 'usr', 'sbin') + + def main(): suite = unittest.TestSuite() basedir = os.path.dirname(os.path.realpath(__file__)) @@ -178,6 +194,10 @@ class TestCase(unittest.TestCase): unittest.TestCase.__init__(self, *pargs, **kwargs) self.todo = False self.portage_skip = None + self.cnf_path = cnf_path + self.cnf_etc_path = cnf_etc_path + self.bindir = cnf_bindir + self.sbindir = cnf_sbindir def defaultTestResult(self): return TextTestResult() diff --git a/pym/portage/tests/dbapi/test_portdb_cache.py b/pym/portage/tests/dbapi/test_portdb_cache.py index 3c77ed3..f08d0f8 100644 --- a/pym/portage/tests/dbapi/test_portdb_cache.py +++ b/pym/portage/tests/dbapi/test_portdb_cache.py @@ -8,8 +8,7 @@ import textwrap import portage from portage import os from portage import _unicode_decode -from portage.const import (BASH_BINARY, PORTAGE_BIN_PATH, - PORTAGE_PYM_PATH, USER_CONFIG_PATH) +from portage.const import (BASH_BINARY, PORTAGE_PYM_PATH, USER_CONFIG_PATH) from portage.tests import TestCase from portage.tests.resolver.ResolverPlayground import ResolverPlayground from portage.util import ensure_dirs @@ -38,7 +37,7 @@ class PortdbCacheTestCase(TestCase): portage_python = portage._python_interpreter egencache_cmd = (portage_python, "-b", "-Wd", - os.path.join(PORTAGE_BIN_PATH, "egencache"), + os.path.join(self.bindir, "egencache"), "--repo", "test_repo", "--repositories-configuration", settings.repositories.config_string()) python_cmd = (portage_python, "-b", "-Wd", "-c") diff --git a/pym/portage/tests/emerge/test_emerge_slot_abi.py b/pym/portage/tests/emerge/test_emerge_slot_abi.py index fd7ec0e..d1f2d92 100644 --- a/pym/portage/tests/emerge/test_emerge_slot_abi.py +++ b/pym/portage/tests/emerge/test_emerge_slot_abi.py @@ -7,8 +7,7 @@ import sys import portage from portage import os from portage import _unicode_decode -from portage.const import (BASH_BINARY, PORTAGE_BIN_PATH, - PORTAGE_PYM_PATH, USER_CONFIG_PATH) +from portage.const import (BASH_BINARY, PORTAGE_PYM_PATH, USER_CONFIG_PATH) from portage.process import find_binary from portage.tests import TestCase from portage.tests.resolver.ResolverPlayground import ResolverPlayground @@ -70,9 +69,9 @@ class SlotAbiEmergeTestCase(TestCase): portage_python = portage._python_interpreter ebuild_cmd = (portage_python, "-b", "-Wd", - os.path.join(PORTAGE_BIN_PATH, "ebuild")) + os.path.join(self.bindir, "ebuild")) emerge_cmd = (portage_python, "-b", "-Wd", - os.path.join(PORTAGE_BIN_PATH, "emerge")) + os.path.join(self.bindir, "emerge")) test_ebuild = portdb.findname("dev-libs/dbus-glib-0.98") self.assertFalse(test_ebuild is None) diff --git a/pym/portage/tests/emerge/test_simple.py b/pym/portage/tests/emerge/test_simple.py index bf0af8b..9c1b1bf 100644 --- a/pym/portage/tests/emerge/test_simple.py +++ b/pym/portage/tests/emerge/test_simple.py @@ -8,7 +8,7 @@ import portage from portage import os from portage import _unicode_decode from portage.const import (BASH_BINARY, PORTAGE_BASE_PATH, - PORTAGE_BIN_PATH, PORTAGE_PYM_PATH, USER_CONFIG_PATH) + PORTAGE_PYM_PATH, USER_CONFIG_PATH) from portage.process import find_binary from portage.tests import TestCase from portage.tests.resolver.ResolverPlayground import ResolverPlayground @@ -175,29 +175,29 @@ pkg_preinst() { portage_python = portage._python_interpreter dispatch_conf_cmd = (portage_python, "-b", "-Wd", - os.path.join(PORTAGE_BIN_PATH, "dispatch-conf")) + os.path.join(self.sbindir, "dispatch-conf")) ebuild_cmd = (portage_python, "-b", "-Wd", - os.path.join(PORTAGE_BIN_PATH, "ebuild")) + os.path.join(self.bindir, "ebuild")) egencache_cmd = (portage_python, "-b", "-Wd", - os.path.join(PORTAGE_BIN_PATH, "egencache"), + os.path.join(self.bindir, "egencache"), "--repo", "test_repo", "--repositories-configuration", settings.repositories.config_string()) emerge_cmd = (portage_python, "-b", "-Wd", - os.path.join(PORTAGE_BIN_PATH, "emerge")) + os.path.join(self.bindir, "emerge")) emaint_cmd = (portage_python, "-b", "-Wd", - os.path.join(PORTAGE_BIN_PATH, "emaint")) + os.path.join(self.sbindir, "emaint")) env_update_cmd = (portage_python, "-b", "-Wd", - os.path.join(PORTAGE_BIN_PATH, "env-update")) + os.path.join(self.sbindir, "env-update")) etc_update_cmd = (BASH_BINARY, - os.path.join(PORTAGE_BIN_PATH, "etc-update")) + os.path.join(self.sbindir, "etc-update")) fixpackages_cmd = (portage_python, "-b", "-Wd", - os.path.join(PORTAGE_BIN_PATH, "fixpackages")) + os.path.join(self.sbindir, "fixpackages")) portageq_cmd = (portage_python, "-b", "-Wd", - os.path.join(PORTAGE_BIN_PATH, "portageq")) + os.path.join(self.bindir, "portageq")) quickpkg_cmd = (portage_python, "-b", "-Wd", - os.path.join(PORTAGE_BIN_PATH, "quickpkg")) + os.path.join(self.bindir, "quickpkg")) regenworld_cmd = (portage_python, "-b", "-Wd", - os.path.join(PORTAGE_BIN_PATH, "regenworld")) + os.path.join(self.sbindir, "regenworld")) rm_binary = find_binary("rm") self.assertEqual(rm_binary is None, False, @@ -368,7 +368,7 @@ pkg_preinst() { for x in true_symlinks: os.symlink(true_binary, os.path.join(fake_bin, x)) for x in etc_symlinks: - os.symlink(os.path.join(PORTAGE_BASE_PATH, "cnf", x), + os.symlink(os.path.join(self.cnf_etc_path, x), os.path.join(eprefix, "etc", x)) with open(os.path.join(var_cache_edb, "counter"), 'wb') as f: f.write(b"100") diff --git a/pym/portage/tests/lint/test_compile_modules.py b/pym/portage/tests/lint/test_compile_modules.py index ce7e3fb..4826cad 100644 --- a/pym/portage/tests/lint/test_compile_modules.py +++ b/pym/portage/tests/lint/test_compile_modules.py @@ -5,7 +5,7 @@ import errno import itertools import stat -from portage.const import PORTAGE_BIN_PATH, PORTAGE_PYM_PATH +from portage.const import PORTAGE_BIN_PATH, PORTAGE_PYM_PATH, PORTAGE_PYM_PACKAGES from portage.tests import TestCase from portage import os from portage import _encodings @@ -14,9 +14,11 @@ from portage import _unicode_decode, _unicode_encode class CompileModulesTestCase(TestCase): def testCompileModules(self): - for parent, _dirs, files in itertools.chain( - os.walk(PORTAGE_BIN_PATH), - os.walk(PORTAGE_PYM_PATH)): + iters = [os.walk(os.path.join(PORTAGE_PYM_PATH, x)) + for x in PORTAGE_PYM_PACKAGES] + iters.append(os.walk(PORTAGE_BIN_PATH)) + + for parent, _dirs, files in itertools.chain(*iters): parent = _unicode_decode(parent, encoding=_encodings['fs'], errors='strict') for x in files: diff --git a/pym/portage/tests/lint/test_import_modules.py b/pym/portage/tests/lint/test_import_modules.py index 34261f4..fcdcb3b 100644 --- a/pym/portage/tests/lint/test_import_modules.py +++ b/pym/portage/tests/lint/test_import_modules.py @@ -1,7 +1,9 @@ # Copyright 2011-2012 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 -from portage.const import PORTAGE_PYM_PATH +from itertools import chain + +from portage.const import PORTAGE_PYM_PATH, PORTAGE_PYM_PACKAGES from portage.tests import TestCase from portage import os from portage import _encodings @@ -13,7 +15,9 @@ class ImportModulesTestCase(TestCase): expected_failures = frozenset(( )) - for mod in self._iter_modules(PORTAGE_PYM_PATH): + iters = (self._iter_modules(os.path.join(PORTAGE_PYM_PATH, x)) + for x in PORTAGE_PYM_PACKAGES) + for mod in chain(*iters): try: __import__(mod) except ImportError as e: diff --git a/pym/portage/tests/repoman/test_simple.py b/pym/portage/tests/repoman/test_simple.py index 69eb36d..5dbb767 100644 --- a/pym/portage/tests/repoman/test_simple.py +++ b/pym/portage/tests/repoman/test_simple.py @@ -9,7 +9,7 @@ import portage from portage import os from portage import shutil from portage import _unicode_decode -from portage.const import PORTAGE_BASE_PATH, PORTAGE_BIN_PATH, PORTAGE_PYM_PATH +from portage.const import PORTAGE_BASE_PATH, PORTAGE_PYM_PATH from portage.process import find_binary from portage.tests import TestCase from portage.tests.resolver.ResolverPlayground import ResolverPlayground @@ -171,7 +171,7 @@ class SimpleRepomanTestCase(TestCase): license_dir = os.path.join(test_repo_location, "licenses") repoman_cmd = (portage._python_interpreter, "-b", "-Wd", - os.path.join(PORTAGE_BIN_PATH, "repoman")) + os.path.join(self.bindir, "repoman")) git_binary = find_binary("git") git_cmd = (git_binary,) @@ -274,7 +274,9 @@ class SimpleRepomanTestCase(TestCase): os.symlink(test_repo_location, test_repo_symlink) # repoman checks metadata.dtd for recent CTIME, so copy the file in # order to ensure that the CTIME is current - shutil.copyfile(metadata_dtd, os.path.join(distdir, "metadata.dtd")) + # NOTE: if we don't have the file around, let repoman try to fetch it. + if os.path.exists(metadata_dtd): + shutil.copyfile(metadata_dtd, os.path.join(distdir, "metadata.dtd")) if debug: # The subprocess inherits both stdout and stderr, for diff --git a/pym/portage/tests/resolver/ResolverPlayground.py b/pym/portage/tests/resolver/ResolverPlayground.py index 3476aba..77a5b5c 100644 --- a/pym/portage/tests/resolver/ResolverPlayground.py +++ b/pym/portage/tests/resolver/ResolverPlayground.py @@ -15,6 +15,7 @@ from portage.package.ebuild.config import config from portage.package.ebuild.digestgen import digestgen from portage._sets import load_default_config from portage._sets.base import InternalPackageSet +from portage.tests import cnf_path from portage.util import ensure_dirs, normalize_path from portage.versions import catsplit @@ -65,6 +66,7 @@ class ResolverPlayground(object): If a metadata key is missing, it gets a default value. profile: settings defined by the profile. """ + self.debug = debug if eprefix is None: self.eprefix = normalize_path(tempfile.mkdtemp()) @@ -417,7 +419,7 @@ class ResolverPlayground(object): make_globals_path = os.path.join(self.eroot, GLOBAL_CONFIG_PATH.lstrip(os.sep), "make.globals") ensure_dirs(os.path.dirname(make_globals_path)) - os.symlink(os.path.join(PORTAGE_BASE_PATH, "cnf", "make.globals"), + os.symlink(os.path.join(cnf_path, "make.globals"), make_globals_path) #Create /usr/share/portage/config/sets/portage.conf @@ -428,8 +430,8 @@ class ResolverPlayground(object): except os.error: pass - provided_sets_portage_conf = \ - os.path.join(PORTAGE_BASE_PATH, "cnf/sets/portage.conf") + provided_sets_portage_conf = ( + os.path.join(cnf_path, "sets", "portage.conf")) os.symlink(provided_sets_portage_conf, os.path.join(default_sets_conf_dir, "portage.conf")) set_config_dir = os.path.join(user_config_dir, "sets") diff --git a/pym/portage/tests/util/test_getconfig.py b/pym/portage/tests/util/test_getconfig.py index e5fd60f..b72bd6a 100644 --- a/pym/portage/tests/util/test_getconfig.py +++ b/pym/portage/tests/util/test_getconfig.py @@ -26,9 +26,7 @@ class GetConfigTestCase(TestCase): } def testGetConfig(self): - - make_globals_file = os.path.join(PORTAGE_BASE_PATH, - 'cnf', 'make.globals') + make_globals_file = os.path.join(self.cnf_path, "make.globals") d = getconfig(make_globals_file) for k, v in self._cases.items(): self.assertEqual(d[k], v)