2011-04-26 19:19:59 +02:00
|
|
|
import os.path
|
2010-02-24 11:24:55 +01:00
|
|
|
import textwrap
|
2012-04-01 23:41:57 +02:00
|
|
|
from nose.tools import assert_equal, assert_raises
|
|
|
|
from mock import patch
|
2012-06-03 17:16:31 +02:00
|
|
|
from pip.backwardcompat import urllib
|
2012-04-01 23:41:57 +02:00
|
|
|
from pip.req import Requirements, parse_editable
|
2011-04-26 19:19:59 +02:00
|
|
|
from tests.test_pip import reset_env, run_pip, write_file, pyversion, here, path_to_url
|
2011-03-15 20:49:48 +01:00
|
|
|
from tests.local_repos import local_checkout
|
2011-03-23 00:13:04 +01:00
|
|
|
from tests.path import Path
|
2010-06-03 04:25:26 +02:00
|
|
|
|
2011-05-04 09:44:02 +02:00
|
|
|
|
2010-02-25 00:16:43 +01:00
|
|
|
def test_requirements_file():
|
|
|
|
"""
|
|
|
|
Test installing from a requirements file.
|
2010-06-03 04:25:26 +02:00
|
|
|
|
2010-02-25 00:16:43 +01:00
|
|
|
"""
|
2011-03-19 01:31:36 +01:00
|
|
|
other_lib_name, other_lib_version = 'anyjson', '0.3'
|
2010-04-14 00:24:22 +02:00
|
|
|
env = reset_env()
|
2010-02-25 00:16:43 +01:00
|
|
|
write_file('initools-req.txt', textwrap.dedent("""\
|
2010-02-24 11:24:55 +01:00
|
|
|
INITools==0.2
|
|
|
|
# and something else to test out:
|
2011-03-15 20:49:48 +01:00
|
|
|
%s<=%s
|
|
|
|
""" % (other_lib_name, other_lib_version)))
|
2010-04-15 00:00:01 +02:00
|
|
|
result = run_pip('install', '-r', env.scratch_path / 'initools-req.txt')
|
2010-05-02 20:11:45 +02:00
|
|
|
assert env.site_packages/'INITools-0.2-py%s.egg-info' % pyversion in result.files_created
|
|
|
|
assert env.site_packages/'initools' in result.files_created
|
2011-03-15 20:49:48 +01:00
|
|
|
assert result.files_created[env.site_packages/other_lib_name].dir
|
|
|
|
fn = '%s-%s-py%s.egg-info' % (other_lib_name, other_lib_version, pyversion)
|
|
|
|
assert result.files_created[env.site_packages/fn].dir
|
2010-02-24 11:24:55 +01:00
|
|
|
|
2012-05-14 05:13:50 +02:00
|
|
|
|
2012-03-13 23:38:47 +01:00
|
|
|
def test_schema_check_in_requirements_file():
|
|
|
|
"""
|
|
|
|
Test installing from a requirements file with an invalid vcs schema..
|
|
|
|
|
|
|
|
"""
|
|
|
|
env = reset_env()
|
|
|
|
write_file('file-egg-req.txt', textwrap.dedent("""\
|
|
|
|
git://github.com/alex/django-fixture-generator.git#egg=fixture_generator
|
|
|
|
"""))
|
|
|
|
assert_raises(AssertionError, run_pip, 'install', '-vvv', '-r', env.scratch_path / 'file-egg-req.txt')
|
2011-05-04 09:44:02 +02:00
|
|
|
|
2012-05-14 05:13:50 +02:00
|
|
|
|
2011-03-23 00:13:04 +01:00
|
|
|
def test_relative_requirements_file():
|
|
|
|
"""
|
|
|
|
Test installing from a requirements file with a relative path with an egg= definition..
|
|
|
|
|
|
|
|
"""
|
2011-04-26 19:19:59 +02:00
|
|
|
url = path_to_url(os.path.join(here, 'packages', '..', 'packages', 'FSPkg')) + '#egg=FSPkg'
|
2011-03-23 00:13:04 +01:00
|
|
|
env = reset_env()
|
|
|
|
write_file('file-egg-req.txt', textwrap.dedent("""\
|
|
|
|
%s
|
|
|
|
""" % url))
|
|
|
|
result = run_pip('install', '-vvv', '-r', env.scratch_path / 'file-egg-req.txt')
|
|
|
|
assert (env.site_packages/'FSPkg-0.1dev-py%s.egg-info' % pyversion) in result.files_created, str(result)
|
|
|
|
assert (env.site_packages/'fspkg') in result.files_created, str(result.stdout)
|
2010-06-03 04:25:26 +02:00
|
|
|
|
2011-05-04 09:44:02 +02:00
|
|
|
|
2010-02-25 00:16:43 +01:00
|
|
|
def test_multiple_requirements_files():
|
|
|
|
"""
|
|
|
|
Test installing from multiple nested requirements files.
|
2010-06-03 04:25:26 +02:00
|
|
|
|
2010-02-25 00:16:43 +01:00
|
|
|
"""
|
2011-03-19 01:31:36 +01:00
|
|
|
other_lib_name, other_lib_version = 'anyjson', '0.3'
|
2010-04-14 00:24:22 +02:00
|
|
|
env = reset_env()
|
2010-02-25 00:16:43 +01:00
|
|
|
write_file('initools-req.txt', textwrap.dedent("""\
|
2010-07-02 03:44:26 +02:00
|
|
|
-e %s@10#egg=INITools-dev
|
2011-03-19 17:52:48 +01:00
|
|
|
-r %s-req.txt""" % (local_checkout('svn+http://svn.colorstudy.com/INITools/trunk'),
|
2011-03-15 20:49:48 +01:00
|
|
|
other_lib_name)))
|
|
|
|
write_file('%s-req.txt' % other_lib_name, textwrap.dedent("""\
|
|
|
|
%s<=%s
|
|
|
|
""" % (other_lib_name, other_lib_version)))
|
2010-04-15 00:00:01 +02:00
|
|
|
result = run_pip('install', '-r', env.scratch_path / 'initools-req.txt')
|
2011-03-15 20:49:48 +01:00
|
|
|
assert result.files_created[env.site_packages/other_lib_name].dir
|
|
|
|
fn = '%s-%s-py%s.egg-info' % (other_lib_name, other_lib_version, pyversion)
|
|
|
|
assert result.files_created[env.site_packages/fn].dir
|
2010-05-02 20:11:45 +02:00
|
|
|
assert env.venv/'src'/'initools' in result.files_created
|
2010-02-24 11:24:55 +01:00
|
|
|
|
2011-01-04 06:05:10 +01:00
|
|
|
|
|
|
|
def test_respect_order_in_requirements_file():
|
|
|
|
env = reset_env()
|
|
|
|
write_file('frameworks-req.txt', textwrap.dedent("""\
|
2011-03-15 04:18:48 +01:00
|
|
|
bidict
|
2011-01-04 06:05:10 +01:00
|
|
|
ordereddict
|
2012-02-06 20:27:51 +01:00
|
|
|
initools
|
2011-01-04 06:05:10 +01:00
|
|
|
"""))
|
|
|
|
result = run_pip('install', '-r', env.scratch_path / 'frameworks-req.txt')
|
|
|
|
downloaded = [line for line in result.stdout.split('\n')
|
|
|
|
if 'Downloading/unpacking' in line]
|
2011-03-19 01:31:36 +01:00
|
|
|
|
2011-03-15 04:18:48 +01:00
|
|
|
assert 'bidict' in downloaded[0], 'First download should ' \
|
2011-03-19 01:31:36 +01:00
|
|
|
'be "bidict" but was "%s"' % downloaded[0]
|
2011-01-04 06:05:10 +01:00
|
|
|
assert 'ordereddict' in downloaded[1], 'Second download should ' \
|
|
|
|
'be "ordereddict" but was "%s"' % downloaded[1]
|
2012-02-06 20:27:51 +01:00
|
|
|
assert 'initools' in downloaded[2], 'Third download should ' \
|
|
|
|
'be "initools" but was "%s"' % downloaded[2]
|
2011-01-04 06:05:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_requirements_data_structure_keeps_order():
|
|
|
|
requirements = Requirements()
|
|
|
|
requirements['pip'] = 'pip'
|
|
|
|
requirements['nose'] = 'nose'
|
|
|
|
requirements['coverage'] = 'coverage'
|
|
|
|
|
2011-03-15 20:49:48 +01:00
|
|
|
assert ['pip', 'nose', 'coverage'] == list(requirements.values())
|
|
|
|
assert ['pip', 'nose', 'coverage'] == list(requirements.keys())
|
2011-01-04 06:05:10 +01:00
|
|
|
|
2011-05-04 09:44:02 +02:00
|
|
|
|
2011-01-04 06:05:10 +01:00
|
|
|
def test_requirements_data_structure_implements__repr__():
|
|
|
|
requirements = Requirements()
|
|
|
|
requirements['pip'] = 'pip'
|
|
|
|
requirements['nose'] = 'nose'
|
|
|
|
|
|
|
|
assert "Requirements({'pip': 'pip', 'nose': 'nose'})" == repr(requirements)
|
|
|
|
|
2011-05-04 09:44:02 +02:00
|
|
|
|
2011-01-04 06:05:10 +01:00
|
|
|
def test_requirements_data_structure_implements__contains__():
|
|
|
|
requirements = Requirements()
|
|
|
|
requirements['pip'] = 'pip'
|
|
|
|
|
|
|
|
assert 'pip' in requirements
|
|
|
|
assert 'nose' not in requirements
|
2012-04-01 23:41:57 +02:00
|
|
|
|
2012-06-06 14:29:24 +02:00
|
|
|
@patch('pip.req.os.getcwd')
|
2012-04-01 23:41:57 +02:00
|
|
|
@patch('pip.req.os.path.exists')
|
|
|
|
@patch('pip.req.os.path.isdir')
|
2012-06-06 14:29:24 +02:00
|
|
|
def test_parse_editable_local(isdir_mock, exists_mock, getcwd_mock):
|
2012-04-01 23:41:57 +02:00
|
|
|
exists_mock.return_value = isdir_mock.return_value = True
|
2012-06-06 14:29:24 +02:00
|
|
|
getcwd_mock.return_value = "/some/path"
|
2012-04-01 23:41:57 +02:00
|
|
|
assert_equal(
|
|
|
|
parse_editable('.', 'git'),
|
2012-06-06 14:29:24 +02:00
|
|
|
(None, 'file:///some/path', None)
|
2012-04-01 23:41:57 +02:00
|
|
|
)
|
|
|
|
assert_equal(
|
|
|
|
parse_editable('foo', 'git'),
|
2012-06-06 14:29:24 +02:00
|
|
|
(None, 'file://' + os.path.join("/some/path", 'foo'), None)
|
2012-04-01 23:41:57 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
|
|
|
)
|
|
|
|
|
2012-06-06 14:29:24 +02:00
|
|
|
@patch('pip.req.os.getcwd')
|
2012-04-01 23:41:57 +02:00
|
|
|
@patch('pip.req.os.path.exists')
|
|
|
|
@patch('pip.req.os.path.isdir')
|
2012-06-06 14:29:24 +02:00
|
|
|
def test_parse_editable_local_extras(isdir_mock, exists_mock, getcwd_mock):
|
2012-04-01 23:41:57 +02:00
|
|
|
exists_mock.return_value = isdir_mock.return_value = True
|
2012-06-06 14:29:24 +02:00
|
|
|
getcwd_mock.return_value = "/some/path"
|
2012-04-01 23:41:57 +02:00
|
|
|
assert_equal(
|
|
|
|
parse_editable('.[extras]', 'git'),
|
2012-06-06 14:29:24 +02:00
|
|
|
(None, 'file://' + "/some/path", ('extras',))
|
2012-04-01 23:41:57 +02:00
|
|
|
)
|
|
|
|
assert_equal(
|
|
|
|
parse_editable('foo[bar,baz]', 'git'),
|
2012-06-06 14:29:24 +02:00
|
|
|
(None, 'file://' + os.path.join("/some/path", 'foo'), ('bar', 'baz'))
|
2012-04-01 23:41:57 +02:00
|
|
|
)
|
2012-05-24 11:04:16 +02:00
|
|
|
|
|
|
|
def test_install_local_editable_with_extras():
|
|
|
|
env = reset_env()
|
|
|
|
to_install = os.path.abspath(os.path.join(here, 'packages', 'LocalExtras'))
|
|
|
|
res = run_pip('install', '-e', to_install + '[bar]', expect_error=False)
|
|
|
|
assert env.site_packages/'easy-install.pth' in res.files_updated
|
|
|
|
assert env.site_packages/'LocalExtras.egg-link' in res.files_created
|
|
|
|
assert env.site_packages/'fspkg' in res.files_created
|