2013-03-27 06:26:52 +01:00
|
|
|
import os
|
|
|
|
import shutil
|
2013-05-01 01:02:10 +02:00
|
|
|
import tempfile
|
2013-03-27 06:26:52 +01:00
|
|
|
|
2013-05-28 23:58:08 +02:00
|
|
|
from mock import Mock, patch
|
|
|
|
from nose.tools import assert_equal, assert_raises
|
2013-03-27 06:26:52 +01:00
|
|
|
from pip.exceptions import PreviousBuildDirError
|
|
|
|
from pip.index import PackageFinder
|
2013-05-01 00:30:15 +02:00
|
|
|
from pip.log import logger
|
2013-05-28 23:58:08 +02:00
|
|
|
from pip.req import (InstallRequirement, RequirementSet, parse_editable,
|
|
|
|
Requirements, parse_requirements)
|
2013-05-27 19:46:31 +02:00
|
|
|
from tests.lib import path_to_url, assert_raises_regexp, find_links
|
2013-03-27 06:26:52 +01:00
|
|
|
|
2013-05-01 01:02:10 +02:00
|
|
|
|
2013-03-27 06:26:52 +01:00
|
|
|
class TestRequirementSet(object):
|
|
|
|
"""RequirementSet tests"""
|
|
|
|
|
|
|
|
def setup(self):
|
2013-05-01 01:02:10 +02:00
|
|
|
logger.consumers = [(logger.NOTIFY, Mock())]
|
2013-03-27 06:26:52 +01:00
|
|
|
self.tempdir = tempfile.mkdtemp()
|
|
|
|
|
|
|
|
def teardown(self):
|
2013-05-01 00:30:15 +02:00
|
|
|
logger.consumers = []
|
2013-03-27 06:26:52 +01:00
|
|
|
shutil.rmtree(self.tempdir, ignore_errors=True)
|
|
|
|
|
2013-05-11 19:50:35 +02:00
|
|
|
def basic_reqset(self, skip_reqs={}):
|
2013-03-27 06:26:52 +01:00
|
|
|
return RequirementSet(
|
|
|
|
build_dir=os.path.join(self.tempdir, 'build'),
|
|
|
|
src_dir=os.path.join(self.tempdir, 'src'),
|
|
|
|
download_dir=None,
|
|
|
|
download_cache=os.path.join(self.tempdir, 'download_cache'),
|
2013-05-11 19:50:35 +02:00
|
|
|
skip_reqs=skip_reqs
|
2013-03-27 06:26:52 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_no_reuse_existing_build_dir(self):
|
|
|
|
"""Test prepare_files raise exception with previous build dir"""
|
|
|
|
|
|
|
|
build_dir = os.path.join(self.tempdir, 'build', 'simple')
|
|
|
|
os.makedirs(build_dir)
|
|
|
|
open(os.path.join(build_dir, "setup.py"), 'w')
|
|
|
|
reqset = self.basic_reqset()
|
|
|
|
req = InstallRequirement.from_line('simple')
|
|
|
|
reqset.add_requirement(req)
|
|
|
|
finder = PackageFinder([find_links], [])
|
|
|
|
assert_raises_regexp(
|
|
|
|
PreviousBuildDirError,
|
2013-05-01 00:30:15 +02:00
|
|
|
"pip can't proceed with [\s\S]*%s[\s\S]*%s" % (req, build_dir),
|
2013-03-27 06:26:52 +01:00
|
|
|
reqset.prepare_files,
|
|
|
|
finder
|
|
|
|
)
|
|
|
|
|
2013-05-11 19:50:35 +02:00
|
|
|
def test_skip_reqs(self):
|
|
|
|
"""Test the skip_reqs list works"""
|
|
|
|
|
|
|
|
reqset = self.basic_reqset(skip_reqs={'simple':''})
|
|
|
|
req = InstallRequirement.from_line('simple')
|
|
|
|
reqset.add_requirement(req)
|
|
|
|
assert not reqset.has_requirements
|
|
|
|
finder = PackageFinder([find_links], [])
|
|
|
|
reqset.prepare_files(finder)
|
|
|
|
assert not reqset.has_requirements
|
|
|
|
|
|
|
|
def test_add_requirement_returns_true_false(self):
|
|
|
|
"""Test add_requirement returns true of false"""
|
|
|
|
|
|
|
|
req = InstallRequirement.from_line('simple')
|
|
|
|
reqset = self.basic_reqset()
|
|
|
|
assert True == reqset.add_requirement(req)
|
|
|
|
reqset = self.basic_reqset(skip_reqs={'simple':''})
|
|
|
|
assert False == reqset.add_requirement(req)
|
2013-05-28 23:58:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_url_with_query():
|
|
|
|
"""InstallRequirement should strip the fragment, but not the query."""
|
|
|
|
url = 'http://foo.com/?p=bar.git;a=snapshot;h=v0.1;sf=tgz'
|
|
|
|
fragment = '#egg=bar'
|
|
|
|
req = InstallRequirement.from_line(url + fragment)
|
|
|
|
|
|
|
|
assert req.url == url, req.url
|
|
|
|
|
|
|
|
|
|
|
|
def test_requirements_data_structure_keeps_order():
|
|
|
|
requirements = Requirements()
|
|
|
|
requirements['pip'] = 'pip'
|
|
|
|
requirements['nose'] = 'nose'
|
|
|
|
requirements['coverage'] = 'coverage'
|
|
|
|
|
|
|
|
assert ['pip', 'nose', 'coverage'] == list(requirements.values())
|
|
|
|
assert ['pip', 'nose', 'coverage'] == list(requirements.keys())
|
|
|
|
|
|
|
|
|
|
|
|
def test_requirements_data_structure_implements__repr__():
|
|
|
|
requirements = Requirements()
|
|
|
|
requirements['pip'] = 'pip'
|
|
|
|
requirements['nose'] = 'nose'
|
|
|
|
|
|
|
|
assert "Requirements({'pip': 'pip', 'nose': 'nose'})" == repr(requirements)
|
|
|
|
|
|
|
|
|
|
|
|
def test_requirements_data_structure_implements__contains__():
|
|
|
|
requirements = Requirements()
|
|
|
|
requirements['pip'] = 'pip'
|
|
|
|
|
|
|
|
assert 'pip' in requirements
|
|
|
|
assert 'nose' not in requirements
|
|
|
|
|
|
|
|
@patch('os.path.normcase')
|
|
|
|
@patch('pip.req.os.getcwd')
|
|
|
|
@patch('pip.req.os.path.exists')
|
|
|
|
@patch('pip.req.os.path.isdir')
|
|
|
|
def test_parse_editable_local(isdir_mock, exists_mock, getcwd_mock, normcase_mock):
|
|
|
|
exists_mock.return_value = isdir_mock.return_value = True
|
|
|
|
# mocks needed to support path operations on windows tests
|
|
|
|
normcase_mock.return_value = getcwd_mock.return_value = "/some/path"
|
|
|
|
assert_equal(
|
|
|
|
parse_editable('.', 'git'),
|
|
|
|
(None, 'file:///some/path', None)
|
|
|
|
)
|
|
|
|
normcase_mock.return_value = "/some/path/foo"
|
|
|
|
assert_equal(
|
|
|
|
parse_editable('foo', 'git'),
|
|
|
|
(None, 'file:///some/path/foo', None)
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_parse_editable_default_vcs():
|
|
|
|
assert_equal(
|
|
|
|
parse_editable('https://foo#egg=foo', 'git'),
|
|
|
|
('foo', 'git+https://foo#egg=foo', None)
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_parse_editable_explicit_vcs():
|
|
|
|
assert_equal(
|
|
|
|
parse_editable('svn+https://foo#egg=foo', 'git'),
|
|
|
|
('foo', 'svn+https://foo#egg=foo', None)
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_parse_editable_vcs_extras():
|
|
|
|
assert_equal(
|
|
|
|
parse_editable('svn+https://foo#egg=foo[extras]', 'git'),
|
|
|
|
('foo[extras]', 'svn+https://foo#egg=foo[extras]', None)
|
|
|
|
)
|
|
|
|
|
|
|
|
@patch('os.path.normcase')
|
|
|
|
@patch('pip.req.os.getcwd')
|
|
|
|
@patch('pip.req.os.path.exists')
|
|
|
|
@patch('pip.req.os.path.isdir')
|
|
|
|
def test_parse_editable_local_extras(isdir_mock, exists_mock, getcwd_mock, normcase_mock):
|
|
|
|
exists_mock.return_value = isdir_mock.return_value = True
|
|
|
|
normcase_mock.return_value = getcwd_mock.return_value = "/some/path"
|
|
|
|
assert_equal(
|
|
|
|
parse_editable('.[extras]', 'git'),
|
|
|
|
(None, 'file://' + "/some/path", ('extras',))
|
|
|
|
)
|
|
|
|
normcase_mock.return_value = "/some/path/foo"
|
|
|
|
assert_equal(
|
|
|
|
parse_editable('foo[bar,baz]', 'git'),
|
|
|
|
(None, 'file:///some/path/foo', ('bar', 'baz'))
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_remote_reqs_parse():
|
|
|
|
"""
|
|
|
|
Test parsing a simple remote requirements file
|
|
|
|
"""
|
|
|
|
# this requirements file just contains a comment
|
|
|
|
# previously this has failed in py3 (https://github.com/pypa/pip/issues/760)
|
|
|
|
for req in parse_requirements('https://raw.github.com/pypa/pip-test-package/master/tests/req_just_comment.txt'):
|
|
|
|
pass
|