Add checks for setup.cfg existence in project dictionary

This check is needed by new projects at their first commit
Without this fix the following initial commit for new project
failed:
https://review.openstack.org/#/c/201701/

The exception that it failed was originated in this method
with KeyError on the project['setup.cfg'] (see previous
jenkins logs on the above commit)

Log: http://logs.openstack.org/01/201701/6/check/gate-kuryr-requirements/e922983/console.html

Change-Id: I39db2918ea277b939f67d3c856f52bd53c226f27
This commit is contained in:
Gal Sagie 2015-07-15 09:19:53 +03:00
parent 724a83a30e
commit 97ddc985ab
2 changed files with 7 additions and 1 deletions

View File

@ -55,10 +55,12 @@ Verbose = collections.namedtuple('Verbose', ['message'])
def extras(project):
"""Return a dict of extra-name:content for the extras in setup.cfg."""
if 'setup.cfg' not in project:
return {}
c = configparser.SafeConfigParser()
c.readfp(io.StringIO(project['setup.cfg']))
if not c.has_section('extras'):
return dict()
return {}
return dict(c.items('extras'))

View File

@ -69,6 +69,10 @@ class TestProjectExtras(testtools.TestCase):
proj = {'setup.cfg': u"[metadata]\n"}
self.assertEqual({}, project.extras(proj))
def test_no_setup_cfg(self):
proj = {}
self.assertEqual({}, project.extras(proj))
class TestExtrasParsing(testtools.TestCase):