Make DoebuildSpawnTestCase instantiate a minimal Package instance, and
authorZac Medico <zmedico@gentoo.org>
Sun, 15 Aug 2010 17:56:49 +0000 (10:56 -0700)
committerZac Medico <zmedico@gentoo.org>
Sun, 15 Aug 2010 17:56:49 +0000 (10:56 -0700)
fix code to tolerate missing metadata values in various places.

pym/_emerge/Package.py
pym/portage/package/ebuild/config.py
pym/portage/tests/ebuild/test_doebuild_spawn.py

index 1671c4ef777f459367f6bb48794ee75489d30383..f504216e2eebb53d25d2d088461a4436f84205cd 100644 (file)
@@ -52,7 +52,7 @@ class Package(Task):
                        not eapi_has_iuse_defaults(self.metadata["EAPI"]):
                        self._invalid_metadata('IUSE.invalid',
                                "IUSE contains defaults, but EAPI doesn't allow them")
-               if self.metadata["REQUIRED_USE"] and \
+               if self.metadata.get("REQUIRED_USE") and \
                        not eapi_has_required_use(self.metadata["EAPI"]):
                        self._invalid_metadata('REQUIRED_USE.invalid',
                                "REQUIRED_USE set, but EAPI doesn't allow it")
index 9089ffb4504eea1210a25f72c585ab3c9c1c809c..cdfbdc28a4f8e1061c31af7580123f1bf010209a 100644 (file)
@@ -1767,7 +1767,8 @@ class config(object):
        def _getKeywords(self, cpv, metadata):
                cp = cpv_getkey(cpv)
                pkg = "%s:%s" % (cpv, metadata["SLOT"])
-               keywords = [[x for x in metadata["KEYWORDS"].split() if x != "-*"]]
+               keywords = [[x for x in metadata.get("KEYWORDS", "").split() \
+                       if x != "-*"]]
                for pkeywords_dict in self._pkeywords_list:
                        cpdict = pkeywords_dict.get(cp)
                        if cpdict:
@@ -2006,7 +2007,8 @@ class config(object):
                                for x in pproperties_list:
                                        accept_properties.extend(x)
 
-               properties = set(use_reduce(metadata["PROPERTIES"], matchall=1, flat=True))
+               properties_str = metadata.get("PROPERTIES", "")
+               properties = set(use_reduce(properties_str, matchall=1, flat=True))
                properties.discard('||')
 
                acceptable_properties = set()
@@ -2020,7 +2022,6 @@ class config(object):
                        else:
                                acceptable_properties.add(x)
 
-               properties_str = metadata["PROPERTIES"]
                if "?" in properties_str:
                        use = metadata["USE"].split()
                else:
index f93fa8758b79b3a5f718529a2695a4cba3404d11..615062709923bde9f8460d20655e0c46eadee424 100644 (file)
@@ -9,6 +9,7 @@ from portage.package.ebuild.config import config
 from portage.package.ebuild.doebuild import spawn as doebuild_spawn
 from portage.tests import TestCase
 from portage.tests.resolver.ResolverPlayground import ResolverPlayground
+from _emerge.Package import Package
 
 class DoebuildSpawnTestCase(TestCase):
        """
@@ -32,7 +33,11 @@ class DoebuildSpawnTestCase(TestCase):
                                'RDEPEND'   : '>=app-shells/bash-3.2_p17 >=dev-lang/python-2.6',
                                'SLOT'      : '0',
                        }
-                       settings.setcpv(cpv, mydb=metadata)
+                       root_config = playground.trees[playground.root]['root_config']
+                       pkg = Package(built=False, cpv=cpv, installed=False,
+                               metadata=metadata, root_config=root_config,
+                               type_name='ebuild')
+                       settings.setcpv(pkg)
                        settings['PORTAGE_PYTHON'] = sys.executable
                        settings['PORTAGE_BUILDDIR'] = os.path.join(
                                settings['PORTAGE_TMPDIR'], cpv)