2011-04-26 19:19:59 +02:00
|
|
|
import os.path
|
2010-02-24 11:24:55 +01:00
|
|
|
import textwrap
|
2011-03-23 00:13:04 +01:00
|
|
|
from pip.backwardcompat import urllib
|
2011-01-04 06:05:10 +01:00
|
|
|
from pip.req import Requirements
|
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
|
|
|
|
2011-05-04 09:44:02 +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
|