# 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 sys from tempfile import mkstemp import fixtures from openstack.common.setup import * from tests import utils class EmailTestCase(utils.BaseTestCase): def test_str_dict_replace(self): string = 'Johnnie T. Hozer' mapping = {'T.': 'The'} self.assertEqual('Johnnie The Hozer', canonicalize_emails(string, mapping)) class MailmapTestCase(utils.BaseTestCase): def setUp(self): super(MailmapTestCase, self).setUp() self.useFixture(fixtures.NestedTempfile()) (fd, self.mailmap) = mkstemp(prefix='openstack', suffix='.setup') 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)) class ParseRequirementsTest(utils.BaseTestCase): def setUp(self): super(ParseRequirementsTest, self).setUp() self.useFixture(fixtures.NestedTempfile()) (fd, self.tmp_file) = mkstemp(prefix='openstack', suffix='.setup') def test_parse_requirements_normal(self): with open(self.tmp_file, 'w') as fh: fh.write("foo\nbar") self.assertEqual(['foo', 'bar'], parse_requirements([self.tmp_file])) def test_parse_requirements_with_git_egg_url(self): with open(self.tmp_file, 'w') as fh: fh.write("-e git://foo.com/zipball#egg=bar") self.assertEqual(['bar'], parse_requirements([self.tmp_file])) def test_parse_requirements_with_http_egg_url(self): with open(self.tmp_file, 'w') as fh: fh.write("https://foo.com/zipball#egg=bar") self.assertEqual(['bar'], parse_requirements([self.tmp_file])) def test_parse_requirements_removes_index_lines(self): with open(self.tmp_file, 'w') as fh: fh.write("-f foobar") self.assertEqual([], parse_requirements([self.tmp_file])) def test_parse_requirements_removes_argparse(self): with open(self.tmp_file, 'w') as fh: fh.write("argparse") if sys.version_info >= (2, 7): self.assertEqual([], parse_requirements([self.tmp_file]))