diff options
| author | Dan Prince <dprince@redhat.com> | 2012-06-20 12:39:51 -0400 |
|---|---|---|
| committer | Dan Prince <dprince@redhat.com> | 2012-06-20 12:43:32 -0400 |
| commit | c986a17be967fee897897cb8abc86b27d2426f75 (patch) | |
| tree | af21800c2a20a24e4edcb79472a817db440bb901 /tests | |
| parent | b76f83946ff9adbfbb482c9ec2fe623e679dde07 (diff) | |
Skip argparse when injecting requirements.
Also adds some unit tests parse_requirements.
Change-Id: I3d8625d4627c7933d73059a63f96e19f8d9647ab
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/unit/test_setup.py | 56 |
1 files changed, 48 insertions, 8 deletions
diff --git a/tests/unit/test_setup.py b/tests/unit/test_setup.py index 0ea0800..660388c 100644 --- a/tests/unit/test_setup.py +++ b/tests/unit/test_setup.py @@ -18,15 +18,12 @@ import os import unittest from tempfile import mkstemp +import sys -from openstack.common.setup import canonicalize_emails -from openstack.common.setup import parse_mailmap +from openstack.common.setup import * -class SetupTest(unittest.TestCase): - - def setUp(self): - (fd, self.mailmap) = mkstemp(prefix='openstack', suffix='.mailmap') +class EmailTestCase(unittest.TestCase): def test_str_dict_replace(self): string = 'Johnnie T. Hozer' @@ -34,6 +31,16 @@ class SetupTest(unittest.TestCase): self.assertEqual('Johnnie The Hozer', canonicalize_emails(string, mapping)) + +class MailmapTestCase(unittest.TestCase): + + def setUp(self): + (fd, self.mailmap) = mkstemp(prefix='openstack', suffix='.setup') + + def tearDown(self): + if os.path.exists(self.mailmap): + os.remove(self.mailmap) + 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") @@ -52,6 +59,39 @@ class SetupTest(unittest.TestCase): self.assertEqual({'<email@bar.com>': '<email@foo.com>'}, parse_mailmap(self.mailmap)) + +class ParseRequirementsTest(unittest.TestCase): + + def setUp(self): + (fd, self.tmp_file) = mkstemp(prefix='openstack', suffix='.setup') + def tearDown(self): - if os.path.exists(self.mailmap): - os.remove(self.mailmap) + if os.path.exists(self.tmp_file): + os.remove(self.tmp_file) + + 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])) |
