diff options
| author | Bhuvan Arumugam <bhuvan@apache.org> | 2012-05-06 15:35:58 -0700 |
|---|---|---|
| committer | Bhuvan Arumugam <bhuvan@apache.org> | 2012-05-06 15:39:33 -0700 |
| commit | fd7df12e3dba97760c1eb2a3d8bd782bbf633a24 (patch) | |
| tree | 2f74fe99187efec67f715ea9a0df8484f360a033 | |
| parent | a1c2dd19633dfe7d792bfec524104bcf683a5d77 (diff) | |
Truly handle mailmap entries for all combinations.
Bug: 994957
Mailmap might contain mapping with full name. This commit fixes
it to handle these combinations:
Foo ZZ <email@foo.com> Bar YY <email@bar.com>
Foo <email@foo.com> Bar <email@bar.com>
<email@foo.com> <email@bar.com>
This is inline with mailmap convention described here:
http://man.github.com/git/git-shortlog.html
* keystone/openstack/common/setup.py
parse_mailmap(): Pull out canonical and alias email addresses.
* keystone/tests/test_setup.py
New test script to cover various combinations in mailmap.
Change-Id: I471172aa012f37e499e86ffeb74c30ebcdb89b00
| -rw-r--r-- | keystone/openstack/common/setup.py | 3 | ||||
| -rw-r--r-- | tests/test_setup.py | 56 |
2 files changed, 58 insertions, 1 deletions
diff --git a/keystone/openstack/common/setup.py b/keystone/openstack/common/setup.py index 60c731a9..2c16b5b3 100644 --- a/keystone/openstack/common/setup.py +++ b/keystone/openstack/common/setup.py @@ -31,7 +31,8 @@ def parse_mailmap(mailmap='.mailmap'): for l in fp: l = l.strip() if not l.startswith('#') and ' ' in l: - canonical_email, alias = l.split(' ') + canonical_email, alias = [x for x in l.split(' ') \ + if x.startswith('<')] mapping[alias] = canonical_email return mapping diff --git a/tests/test_setup.py b/tests/test_setup.py new file mode 100644 index 00000000..0b9906dc --- /dev/null +++ b/tests/test_setup.py @@ -0,0 +1,56 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2011 OpenStack LLC. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import os +import unittest + +from keystone.openstack.common.setup import canonicalize_emails +from keystone.openstack.common.setup import parse_mailmap + + +class SetupTest(unittest.TestCase): + + def setUp(self): + self.mailmap = '.mailmap.test' + + def test_str_dict_replace(self): + string = 'Johnnie T. Hozer' + mapping = {'T.': 'The'} + self.assertEqual('Johnnie The Hozer', + canonicalize_emails(string, mapping)) + + def test_mailmap_with_fullname(self): + with open(self.mailmap, 'w') as mm_fh: + mm_fh.write("Foo Bar <email@foo.com> Foo Bar <email@bar.com>\n") + self.assertEqual({'<email@bar.com>' : '<email@foo.com>'}, + parse_mailmap(self.mailmap)) + + def test_mailmap_with_firstname(self): + with open(self.mailmap, 'w') as mm_fh: + mm_fh.write("Foo <email@foo.com> Foo <email@bar.com>\n") + self.assertEqual({'<email@bar.com>' : '<email@foo.com>'}, + parse_mailmap(self.mailmap)) + + def test_mailmap_with_noname(self): + with open(self.mailmap, 'w') as mm_fh: + mm_fh.write("<email@foo.com> <email@bar.com>\n") + self.assertEqual({'<email@bar.com>' : '<email@foo.com>'}, + parse_mailmap(self.mailmap)) + + def tearDown(self): + if os.path.exists(self.mailmap): + os.remove(self.mailmap) |
