From 2e1371a13205cd494dc4b9ade79ae20b607256b1 Mon Sep 17 00:00:00 2001 From: Bhuvan Arumugam Date: Sun, 6 May 2012 15:13:44 -0700 Subject: Tests to cover various mailmap formats. Bug: 994957 Mailmap might include entries in different format: Full Name Full Name Firstname Firstname 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 --- tests/unit/test_setup.py | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) (limited to 'tests/unit/test_setup.py') diff --git a/tests/unit/test_setup.py b/tests/unit/test_setup.py index 6a65b2d..fbfaebd 100644 --- a/tests/unit/test_setup.py +++ b/tests/unit/test_setup.py @@ -15,19 +15,43 @@ # License for the specific language governing permissions and limitations # under the License. +import os import unittest +from tempfile import mkstemp -import mock +from openstack.common.setup import canonicalize_emails +from openstack.common.setup import parse_mailmap -from openstack.common import exception -from openstack.common import utils -from openstack.common import setup +class SetupTest(unittest.TestCase): -class UtilsTest(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', - setup.canonicalize_emails(string, mapping)) + 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