Files
deb-python-oslo.config/tests/unit/test_setup.py
Bhuvan Arumugam 2e1371a132 Tests to cover various mailmap formats.
Bug: 994957

Mailmap might include entries in different format:
   Full Name <email@foo.com> Full Name <email@bar.com>
   Firstname <email@foo.com> Firstname <email@bar.com>
   <email@foo.com> <email@bar.com>

This commit adds a test case to parse these entries.

* tests/unit/test_setup.py
  Remove unused imports.
  Import os and setup methods to verify.

  SetupTest: Define unique test case name.
  setUp(): New method to define temporary mailmap file.
  tearDown(): New method to remove the temporary mailmap file.
  test_mailmap_with_fullname(): New method to test mailmap entry
  with fullname.
  test_mailmap_with_firstname(): New method to test mailmap entry
  with first name only.
  test_mailmap_with_noname(): New method to test mailmap entry with
  just email addresses.

Change-Id: Icc018d4b2692ce7a7de757f02d1dd49241c30a6c
2012-05-12 07:16:59 -07:00

58 lines
2.1 KiB
Python

# 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 tempfile import mkstemp
from openstack.common.setup import canonicalize_emails
from openstack.common.setup import parse_mailmap
class SetupTest(unittest.TestCase):
def setUp(self):
(fd, self.mailmap) = mkstemp(prefix='openstack', suffix='.mailmap')
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)