tests/emerge: test egencache
authorZac Medico <zmedico@gentoo.org>
Mon, 5 Sep 2011 22:35:02 +0000 (15:35 -0700)
committerZac Medico <zmedico@gentoo.org>
Mon, 5 Sep 2011 22:35:02 +0000 (15:35 -0700)
This tests --update in any case, and --update-use-local-desc only if
python xml support is detected.

bin/egencache
pym/portage/tests/emerge/test_simple.py

index 53ae565827964c40268b2a177caec3d013d829b4..bf29474ef50bcc6ac8770ccbe8477cb6f465c948 100755 (executable)
@@ -772,8 +772,6 @@ def egencache_main(args):
        parser, options, atoms = parse_args(args)
 
        config_root = options.config_root
-       if config_root is None:
-               config_root = '/'
 
        # The calling environment is ignored, so the program is
        # completely controlled by commandline arguments.
@@ -790,8 +788,10 @@ def egencache_main(args):
        if options.portdir is not None:
                env['PORTDIR'] = options.portdir
 
+       eprefix = os.environ.get("__PORTAGE_TEST_EPREFIX")
+
        settings = portage.config(config_root=config_root,
-               target_root='/', local_config=False, env=env)
+               local_config=False, env=env, _eprefix=eprefix)
 
        default_opts = None
        if not options.ignore_default_opts:
@@ -800,14 +800,11 @@ def egencache_main(args):
        if default_opts:
                parser, options, args = parse_args(default_opts + args)
 
-               if options.config_root is not None:
-                       config_root = options.config_root
-
                if options.cache_dir is not None:
                        env['PORTAGE_DEPCACHEDIR'] = options.cache_dir
 
                settings = portage.config(config_root=config_root,
-                       target_root='/', local_config=False, env=env)
+                       local_config=False, env=env, _eprefix=eprefix)
 
        if not options.update and not options.update_use_local_desc \
                        and not options.update_changelogs:
index 20cfa8f5961d107afb962add415503d75169cc5a..3f7a3bebe35e1c22d2b5e312cb5a1177a5b0f3a3 100644 (file)
@@ -7,7 +7,7 @@ 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.const import PORTAGE_BIN_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
@@ -15,6 +15,14 @@ from portage.util import ensure_dirs
 
 class SimpleEmergeTestCase(TestCase):
 
+       def _have_python_xml(self):
+               try:
+                       __import__("xml.etree.ElementTree")
+                       __import__("xml.parsers.expat").parsers.expat.ExpatError
+               except (AttributeError, ImportError):
+                       return False
+               return True
+
        def testSimple(self):
 
                debug = False
@@ -111,6 +119,8 @@ src_install() {
                )
 
                portage_python = portage._python_interpreter
+               egencache_cmd = (portage_python, "-Wd",
+                       os.path.join(PORTAGE_BIN_PATH, "egencache"))
                emerge_cmd = (portage_python, "-Wd",
                        os.path.join(PORTAGE_BIN_PATH, "emerge"))
                emaint_cmd = (portage_python, "-Wd",
@@ -118,7 +128,12 @@ src_install() {
                quickpkg_cmd = (portage_python, "-Wd",
                        os.path.join(PORTAGE_BIN_PATH, "quickpkg"))
 
+               egencache_extra_args = []
+               if self._have_python_xml():
+                       egencache_extra_args.append("--update-use-local-desc")
+
                test_commands = (
+                       egencache_cmd + ("--update",) + tuple(egencache_extra_args),
                        emerge_cmd + ("--version",),
                        emerge_cmd + ("--info",),
                        emerge_cmd + ("--info", "--verbose"),
@@ -149,8 +164,21 @@ src_install() {
                portage_tmpdir = os.path.join(eprefix, "var", "tmp", "portage")
                portdir = settings["PORTDIR"]
                profile_path = settings.profile_path
+               user_config_dir = os.path.join(os.sep, eprefix, USER_CONFIG_PATH)
                var_cache_edb = os.path.join(eprefix, "var", "cache", "edb")
 
+               features = []
+               features.append("metadata-transfer")
+               if not portage.process.sandbox_capable:
+                       features.append("-sandbox")
+
+               # Since egencache ignores settings from the calling environment,
+               # configure it via make.conf.
+               make_conf = (
+                       "FEATURES=\"%s\"\n" % (" ".join(features),),
+                       "PORTDIR=\"%s\"\n" % (portdir,),
+               )
+
                path =  os.environ.get("PATH")
                if path is not None and not path.strip():
                        path = None
@@ -188,17 +216,11 @@ src_install() {
                        "PORTAGE_PYTHON" : portage_python,
                        "PORTAGE_TMPDIR" : portage_tmpdir,
                        "PORTAGE_USERNAME" : os.environ["PORTAGE_USERNAME"],
-                       "PORTDIR" : portdir,
                        "PYTHONPATH" : pythonpath,
                }
 
-               features = []
-               if not portage.process.sandbox_capable:
-                       features.append("-sandbox")
-               if features:
-                       env["FEATURES"] = " ".join(features)
-
-               dirs = [distdir, fake_bin, portage_tmpdir, var_cache_edb]
+               dirs = [distdir, fake_bin, portage_tmpdir,
+                       user_config_dir, var_cache_edb]
                true_symlinks = ["chown", "chgrp"]
                true_binary = find_binary("true")
                self.assertEqual(true_binary is None, False,
@@ -206,6 +228,9 @@ src_install() {
                try:
                        for d in dirs:
                                ensure_dirs(d)
+                       with open(os.path.join(user_config_dir, "make.conf"), 'w') as f:
+                               for line in make_conf:
+                                       f.write(line)
                        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: