From fd7df12e3dba97760c1eb2a3d8bd782bbf633a24 Mon Sep 17 00:00:00 2001 From: Bhuvan Arumugam Date: Sun, 6 May 2012 15:35:58 -0700 Subject: 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 Bar YY Foo Bar 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 --- keystone/openstack/common/setup.py | 3 +- tests/test_setup.py | 56 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 tests/test_setup.py 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 Foo Bar \n") + self.assertEqual({'' : ''}, + parse_mailmap(self.mailmap)) + + def test_mailmap_with_firstname(self): + with open(self.mailmap, 'w') as mm_fh: + mm_fh.write("Foo Foo \n") + self.assertEqual({'' : ''}, + parse_mailmap(self.mailmap)) + + def test_mailmap_with_noname(self): + with open(self.mailmap, 'w') as mm_fh: + mm_fh.write(" \n") + self.assertEqual({'' : ''}, + parse_mailmap(self.mailmap)) + + def tearDown(self): + if os.path.exists(self.mailmap): + os.remove(self.mailmap) -- cgit