Skip argparse when injecting requirements.
Also adds some unit tests parse_requirements. Change-Id: I3d8625d4627c7933d73059a63f96e19f8d9647ab
This commit is contained in:
parent
b76f83946f
commit
c986a17be9
@ -22,6 +22,7 @@ Utilities with minimum-depends for use in setup.py
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
from setuptools.command import sdist
|
from setuptools.command import sdist
|
||||||
|
|
||||||
@ -76,6 +77,10 @@ def parse_requirements(requirements_files=['requirements.txt',
|
|||||||
# -f lines are for index locations, and don't get used here
|
# -f lines are for index locations, and don't get used here
|
||||||
elif re.match(r'\s*-f\s+', line):
|
elif re.match(r'\s*-f\s+', line):
|
||||||
pass
|
pass
|
||||||
|
# argparse is part of the standard library starting with 2.7
|
||||||
|
# adding it to the requirements list screws distro installs
|
||||||
|
elif line == 'argparse' and sys.version_info >= (2, 7):
|
||||||
|
pass
|
||||||
else:
|
else:
|
||||||
requirements.append(line)
|
requirements.append(line)
|
||||||
|
|
||||||
|
@ -18,15 +18,12 @@
|
|||||||
import os
|
import os
|
||||||
import unittest
|
import unittest
|
||||||
from tempfile import mkstemp
|
from tempfile import mkstemp
|
||||||
|
import sys
|
||||||
|
|
||||||
from openstack.common.setup import canonicalize_emails
|
from openstack.common.setup import *
|
||||||
from openstack.common.setup import parse_mailmap
|
|
||||||
|
|
||||||
|
|
||||||
class SetupTest(unittest.TestCase):
|
class EmailTestCase(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
(fd, self.mailmap) = mkstemp(prefix='openstack', suffix='.mailmap')
|
|
||||||
|
|
||||||
def test_str_dict_replace(self):
|
def test_str_dict_replace(self):
|
||||||
string = 'Johnnie T. Hozer'
|
string = 'Johnnie T. Hozer'
|
||||||
@ -34,6 +31,16 @@ class SetupTest(unittest.TestCase):
|
|||||||
self.assertEqual('Johnnie The Hozer',
|
self.assertEqual('Johnnie The Hozer',
|
||||||
canonicalize_emails(string, mapping))
|
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):
|
def test_mailmap_with_fullname(self):
|
||||||
with open(self.mailmap, 'w') as mm_fh:
|
with open(self.mailmap, 'w') as mm_fh:
|
||||||
mm_fh.write("Foo Bar <email@foo.com> Foo Bar <email@bar.com>\n")
|
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>'},
|
self.assertEqual({'<email@bar.com>': '<email@foo.com>'},
|
||||||
parse_mailmap(self.mailmap))
|
parse_mailmap(self.mailmap))
|
||||||
|
|
||||||
|
|
||||||
|
class ParseRequirementsTest(unittest.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
(fd, self.tmp_file) = mkstemp(prefix='openstack', suffix='.setup')
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
if os.path.exists(self.mailmap):
|
if os.path.exists(self.tmp_file):
|
||||||
os.remove(self.mailmap)
|
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]))
|
||||||
|
Loading…
Reference in New Issue
Block a user