Permalink
Browse files

re.finditer never raises an AttributeError

  • Loading branch information...
1 parent 18f4f36 commit 49d5cb09ff2ac9b99d03ef956f0176c05dedb908 @mapleoin committed Jan 18, 2013
Showing with 68 additions and 15 deletions.
  1. +13 −14 git_tarballs
  2. +55 −1 test_git_tarballs.py
View
27 git_tarballs
@@ -86,24 +86,23 @@ def get_upstream_commit(changelog):
def parse_changelog(changelog):
- """Parse a git ChangeLog file returning an iterable of dicts
+ """Parse a git ChangeLog file
:changelog: string with the contents of the file
+ Returns an iterable of _sre.SRE_Match match objects from python's `re`
+
"""
- try:
- # FIXME: we can actually ignore Merge commits altogether.
- return re.finditer(r'^commit (?P<commit>.*?)$'
- '.*?'
- '^Author:\s+(?P<author>.*?)$'
- '.*?'
- '^Date:\s+(?P<date>.*?)$'
- '.*?'
- '\n\n\s+(?P<message>.*?)$'
- '(?:\n\n|\n.*?)',
- changelog, re.MULTILINE | re.DOTALL)
- except AttributeError:
- sys.exit("Could not parse ChangeLog file.")
+ # FIXME: we can actually ignore Merge commits altogether.
+ return re.finditer(r'^commit (?P<commit>.*?)$'
+ '.*?'
+ '^Author:\s+(?P<author>.*?)$'
+ '.*?'
+ '^Date:\s+(?P<date>.*?)$'
+ '.*?'
+ '\n\n\s+(?P<message>.*?)$'
+ '(?:\n\n|\n.*?)',
+ changelog, re.MULTILINE | re.DOTALL)
def get_commit_from_spec(package):
View
56 test_git_tarballs.py
@@ -22,8 +22,42 @@
ghb = imp.load_source('ghb', 'git_tarballs')
-class TestGitTarballs(unittest.TestCase):
+CHANGELOG = (
+ 'commit 921b7c514fb79bd4b8a023f34d22df4efe5406ad\n'
+ 'Merge: 9ae14c7 518bdb5\n'
+ 'Author: Jenkins <jenkins@review.openstack.org>\n'
+ 'Date: Thu Jan 17 12:14:24 2013 +0000\n'
+ '\n'
+ ' Merge "Expose a get_spice_console RPC API method"\n'
+ '\n'
+ 'commit 9ae14c7570bb9dfc4bf1ab8f8127cae3c9eb2641\n'
+ 'Merge: b76c5cf d597993\n'
+ 'Author: Jenkins <jenkins@review.openstack.org>\n'
+ 'Date: Thu Jan 17 11:59:39 2013 +0000\n'
+ '\n'
+ ' Merge "Add a get_spice_console method to nova.virt API"\n'
+ '\n'
+ 'commit eab051ec68bdc8792dddb63c9231ece11ab06037\n'
+ 'Author: Foo Barwington <barwing@ton.com>\n'
+ 'Date: Thu Jan 3 10:23:50 2013 +0000\n'
+ '\n'
+ ' Add nova-spicehtml5proxy helper\n'
+ ' \n'
+ ' Add nova-spicehtml5proxy which provides a websockets proxy,\n'
+ ' equivalent to nova-novncproxy\n'
+ ' \n'
+ ' Blueprint: libvirt-spice\n'
+ ' Change-Id: I48be78c97bb7dd6635fd4bba476ef22701418ba1\n'
+ ' Signed-off-by: Foo Barwington <barwing@ton.com>\n'
+ '\n'
+ ' bin/nova-spicehtml5proxy | 93 +++++++++++++++++++++++\n'
+ ' doc/source/conf.py | 2 +\n'
+ ' doc/source/man/nova-spicehtml5proxy.rst | 48 ++++++++++++++++\n'
+ ' setup.py | 1 +\n'
+ ' 4 files changed, 144 insertions(+)\n')
+
+class TestGitTarballs(unittest.TestCase):
def test_version_parse(self):
with mock_open(u"\nVersion: 2012.2.3+git.1355917214.0c8c2a3\n"):
self.assertEqual('0c8c2a3',
@@ -35,6 +69,26 @@ def test_version_parse_comment(self):
self.assertEqual('0c8c2a3',
ghb.get_commit_from_spec('example_pkg'))
+ def test_parse_changelog(self):
+ self.assertEqual(
+ [('921b7c514fb79bd4b8a023f34d22df4efe5406ad',
+ 'Jenkins <jenkins@review.openstack.org>',
+ 'Thu Jan 17 12:14:24 2013 +0000',
+ 'Merge "Expose a get_spice_console RPC API method"'),
+ ('9ae14c7570bb9dfc4bf1ab8f8127cae3c9eb2641',
+ 'Jenkins <jenkins@review.openstack.org>',
+ 'Thu Jan 17 11:59:39 2013 +0000',
+ 'Merge "Add a get_spice_console method to nova.virt API"'),
+ ('eab051ec68bdc8792dddb63c9231ece11ab06037',
+ 'Foo Barwington <barwing@ton.com>',
+ 'Thu Jan 3 10:23:50 2013 +0000',
+ 'Add nova-spicehtml5proxy helper')],
+ [c.groups() for c in ghb.parse_changelog(CHANGELOG)])
+
+ def test_parse_changelog_empty(self):
+ self.assertEqual([],
+ list(ghb.parse_changelog("bogus")))
+
class TestGitParseUpdateSpec(unittest.TestCase):
def test_normal(self):

0 comments on commit 49d5cb0

Please sign in to comment.