2010-06-04 02:58:16 +02:00
|
|
|
import os
|
2010-02-24 11:24:55 +01:00
|
|
|
import tempfile
|
2010-02-24 11:24:55 +01:00
|
|
|
import textwrap
|
2013-08-21 11:16:07 +02:00
|
|
|
|
2010-06-03 04:25:26 +02:00
|
|
|
|
2013-08-22 06:40:46 +02:00
|
|
|
def test_options_from_env_vars(script):
|
2010-02-25 00:16:43 +01:00
|
|
|
"""
|
2010-02-24 11:24:55 +01:00
|
|
|
Test if ConfigOptionParser reads env vars (e.g. not using PyPI here)
|
2010-06-03 04:25:26 +02:00
|
|
|
|
2010-02-25 00:16:43 +01:00
|
|
|
"""
|
2013-08-22 06:40:46 +02:00
|
|
|
script.environ['PIP_NO_INDEX'] = '1'
|
2013-08-21 11:16:07 +02:00
|
|
|
result = script.pip('install', '-vvv', 'INITools', expect_error=True)
|
2010-02-24 11:24:55 +01:00
|
|
|
assert "Ignoring indexes:" in result.stdout, str(result)
|
2014-01-28 15:17:51 +01:00
|
|
|
assert (
|
|
|
|
"DistributionNotFound: No distributions at all found for INITools"
|
|
|
|
in result.stdout
|
|
|
|
)
|
2010-02-24 11:24:55 +01:00
|
|
|
|
2010-06-03 04:25:26 +02:00
|
|
|
|
2013-08-22 06:40:46 +02:00
|
|
|
def test_command_line_options_override_env_vars(script, virtualenv):
|
2010-02-25 00:16:43 +01:00
|
|
|
"""
|
|
|
|
Test that command line options override environmental variables.
|
2010-06-03 04:25:26 +02:00
|
|
|
|
2010-02-25 00:16:43 +01:00
|
|
|
"""
|
2013-08-22 06:40:46 +02:00
|
|
|
script.environ['PIP_INDEX_URL'] = 'http://b.pypi.python.org/simple/'
|
2013-08-21 11:16:07 +02:00
|
|
|
result = script.pip('install', '-vvv', 'INITools', expect_error=True)
|
2014-01-28 15:17:51 +01:00
|
|
|
assert (
|
|
|
|
"Getting page http://b.pypi.python.org/simple/INITools"
|
|
|
|
in result.stdout
|
|
|
|
)
|
2013-08-22 06:40:46 +02:00
|
|
|
virtualenv.clear()
|
2014-01-28 15:17:51 +01:00
|
|
|
result = script.pip(
|
|
|
|
'install', '-vvv', '--index-url', 'http://download.zope.org/ppix',
|
|
|
|
'INITools',
|
|
|
|
expect_error=True,
|
|
|
|
)
|
2011-04-01 00:55:44 +02:00
|
|
|
assert "b.pypi.python.org" not in result.stdout
|
2010-02-24 11:24:55 +01:00
|
|
|
assert "Getting page http://download.zope.org/ppix" in result.stdout
|
|
|
|
|
2010-06-03 04:25:26 +02:00
|
|
|
|
2013-08-22 06:40:46 +02:00
|
|
|
def test_env_vars_override_config_file(script, virtualenv):
|
2011-12-07 17:34:19 +01:00
|
|
|
"""
|
|
|
|
Test that environmental variables override settings in config files.
|
2011-12-12 10:02:14 +01:00
|
|
|
|
2011-12-07 17:34:19 +01:00
|
|
|
"""
|
|
|
|
fd, config_file = tempfile.mkstemp('-pip.cfg', 'test-')
|
|
|
|
try:
|
2013-08-22 06:40:46 +02:00
|
|
|
_test_env_vars_override_config_file(script, virtualenv, config_file)
|
2011-12-07 17:34:19 +01:00
|
|
|
finally:
|
|
|
|
# `os.close` is a workaround for a bug in subprocess
|
|
|
|
# http://bugs.python.org/issue3210
|
|
|
|
os.close(fd)
|
|
|
|
os.remove(config_file)
|
|
|
|
|
2012-01-30 07:26:12 +01:00
|
|
|
|
2013-08-22 06:40:46 +02:00
|
|
|
def _test_env_vars_override_config_file(script, virtualenv, config_file):
|
|
|
|
# set this to make pip load it
|
|
|
|
script.environ['PIP_CONFIG_FILE'] = config_file
|
2011-12-07 17:34:19 +01:00
|
|
|
# It's important that we test this particular config value ('no-index')
|
|
|
|
# because their is/was a bug which only shows up in cases in which
|
|
|
|
# 'config-item' and 'config_item' hash to the same value modulo the size
|
|
|
|
# of the config dictionary.
|
2014-02-24 22:52:23 +01:00
|
|
|
(script.scratch_path / config_file).write(textwrap.dedent("""\
|
2011-12-07 17:34:19 +01:00
|
|
|
[global]
|
|
|
|
no-index = 1
|
|
|
|
"""))
|
2013-08-21 11:16:07 +02:00
|
|
|
result = script.pip('install', '-vvv', 'INITools', expect_error=True)
|
2014-01-28 15:17:51 +01:00
|
|
|
assert (
|
|
|
|
"DistributionNotFound: No distributions at all found for INITools"
|
|
|
|
in result.stdout
|
|
|
|
)
|
2013-08-22 06:40:46 +02:00
|
|
|
script.environ['PIP_NO_INDEX'] = '0'
|
|
|
|
virtualenv.clear()
|
2013-08-21 11:16:07 +02:00
|
|
|
result = script.pip('install', '-vvv', 'INITools', expect_error=True)
|
2011-12-07 17:34:19 +01:00
|
|
|
assert "Successfully installed INITools" in result.stdout
|
|
|
|
|
2012-01-30 07:26:12 +01:00
|
|
|
|
2013-08-23 13:49:04 +02:00
|
|
|
def test_command_line_append_flags(script, virtualenv, data):
|
2010-02-25 00:16:43 +01:00
|
|
|
"""
|
2014-01-28 15:17:51 +01:00
|
|
|
Test command line flags that append to defaults set by environmental
|
|
|
|
variables.
|
2010-06-03 04:25:26 +02:00
|
|
|
|
2010-02-25 00:16:43 +01:00
|
|
|
"""
|
2013-08-22 06:40:46 +02:00
|
|
|
script.environ['PIP_FIND_LINKS'] = 'http://pypi.pinaxproject.com'
|
2013-08-21 11:16:07 +02:00
|
|
|
result = script.pip('install', '-vvv', 'INITools', expect_error=True)
|
2014-01-28 15:17:51 +01:00
|
|
|
assert (
|
|
|
|
"Analyzing links from page http://pypi.pinaxproject.com"
|
|
|
|
in result.stdout
|
|
|
|
)
|
2013-08-22 06:40:46 +02:00
|
|
|
virtualenv.clear()
|
2014-01-28 15:17:51 +01:00
|
|
|
result = script.pip(
|
|
|
|
'install', '-vvv', '--find-links', data.find_links, 'INITools',
|
|
|
|
expect_error=True,
|
|
|
|
)
|
|
|
|
assert (
|
|
|
|
"Analyzing links from page http://pypi.pinaxproject.com"
|
|
|
|
in result.stdout
|
|
|
|
)
|
2013-08-23 13:49:04 +02:00
|
|
|
assert "Skipping link %s" % data.find_links in result.stdout
|
2010-02-24 11:24:55 +01:00
|
|
|
|
2010-06-03 04:25:26 +02:00
|
|
|
|
2013-08-23 13:49:04 +02:00
|
|
|
def test_command_line_appends_correctly(script, data):
|
2010-08-13 14:49:18 +02:00
|
|
|
"""
|
2010-08-19 15:39:50 +02:00
|
|
|
Test multiple appending options set by environmental variables.
|
2010-08-13 14:49:18 +02:00
|
|
|
|
|
|
|
"""
|
2014-01-28 15:17:51 +01:00
|
|
|
script.environ['PIP_FIND_LINKS'] = (
|
|
|
|
'http://pypi.pinaxproject.com %s' % data.find_links
|
|
|
|
)
|
2013-08-21 11:16:07 +02:00
|
|
|
result = script.pip('install', '-vvv', 'INITools', expect_error=True)
|
2011-03-19 01:31:36 +01:00
|
|
|
|
2014-01-28 15:17:51 +01:00
|
|
|
assert (
|
|
|
|
"Analyzing links from page http://pypi.pinaxproject.com"
|
|
|
|
in result.stdout
|
|
|
|
), result.stdout
|
2013-08-23 13:49:04 +02:00
|
|
|
assert "Skipping link %s" % data.find_links in result.stdout
|
2010-08-13 14:49:18 +02:00
|
|
|
|
|
|
|
|
2013-08-22 06:40:46 +02:00
|
|
|
def test_config_file_override_stack(script, virtualenv):
|
2010-02-25 00:16:43 +01:00
|
|
|
"""
|
|
|
|
Test config files (global, overriding a global config with a
|
|
|
|
local, overriding all with a command line flag).
|
2010-06-03 04:25:26 +02:00
|
|
|
|
2010-02-25 00:16:43 +01:00
|
|
|
"""
|
2011-03-15 04:09:14 +01:00
|
|
|
fd, config_file = tempfile.mkstemp('-pip.cfg', 'test-')
|
2010-09-13 07:21:10 +02:00
|
|
|
try:
|
2013-08-22 06:40:46 +02:00
|
|
|
_test_config_file_override_stack(script, virtualenv, config_file)
|
2010-09-13 07:21:10 +02:00
|
|
|
finally:
|
2011-03-15 04:09:14 +01:00
|
|
|
# `os.close` is a workaround for a bug in subprocess
|
|
|
|
# http://bugs.python.org/issue3210
|
|
|
|
os.close(fd)
|
2010-09-13 07:21:10 +02:00
|
|
|
os.remove(config_file)
|
|
|
|
|
|
|
|
|
2013-08-22 06:40:46 +02:00
|
|
|
def _test_config_file_override_stack(script, virtualenv, config_file):
|
2014-01-28 15:17:51 +01:00
|
|
|
# set this to make pip load it
|
|
|
|
script.environ['PIP_CONFIG_FILE'] = config_file
|
2014-02-24 22:52:23 +01:00
|
|
|
(script.scratch_path / config_file).write(textwrap.dedent("""\
|
2010-02-24 11:24:55 +01:00
|
|
|
[global]
|
|
|
|
index-url = http://download.zope.org/ppix
|
2010-02-25 00:16:43 +01:00
|
|
|
"""))
|
2013-08-21 11:16:07 +02:00
|
|
|
result = script.pip('install', '-vvv', 'INITools', expect_error=True)
|
2014-01-28 15:17:51 +01:00
|
|
|
assert (
|
|
|
|
"Getting page http://download.zope.org/ppix/INITools" in result.stdout
|
|
|
|
)
|
2013-08-22 06:40:46 +02:00
|
|
|
virtualenv.clear()
|
2014-02-24 22:52:23 +01:00
|
|
|
(script.scratch_path / config_file).write(textwrap.dedent("""\
|
2010-02-24 11:24:55 +01:00
|
|
|
[global]
|
|
|
|
index-url = http://download.zope.org/ppix
|
|
|
|
[install]
|
|
|
|
index-url = http://pypi.appspot.com/
|
2010-02-25 00:16:43 +01:00
|
|
|
"""))
|
2013-08-21 11:16:07 +02:00
|
|
|
result = script.pip('install', '-vvv', 'INITools', expect_error=True)
|
2010-02-24 11:24:55 +01:00
|
|
|
assert "Getting page http://pypi.appspot.com/INITools" in result.stdout
|
2014-01-28 15:17:51 +01:00
|
|
|
result = script.pip(
|
|
|
|
'install', '-vvv', '--index-url', 'http://pypi.python.org/simple',
|
|
|
|
'INITools',
|
|
|
|
expect_error=True,
|
|
|
|
)
|
|
|
|
assert (
|
|
|
|
"Getting page http://download.zope.org/ppix/INITools"
|
|
|
|
not in result.stdout
|
|
|
|
)
|
2010-02-24 11:24:55 +01:00
|
|
|
assert "Getting page http://pypi.appspot.com/INITools" not in result.stdout
|
2014-01-28 15:17:51 +01:00
|
|
|
assert (
|
|
|
|
"Getting page http://pypi.python.org/simple/INITools" in result.stdout
|
|
|
|
)
|
2010-02-24 11:24:55 +01:00
|
|
|
|
2010-06-03 04:25:26 +02:00
|
|
|
|
2010-04-19 13:51:15 +02:00
|
|
|
def test_log_file_no_directory():
|
|
|
|
"""
|
|
|
|
Test opening a log file with no directory name.
|
2010-06-03 04:25:26 +02:00
|
|
|
|
2010-04-19 13:51:15 +02:00
|
|
|
"""
|
2010-04-27 02:05:58 +02:00
|
|
|
from pip.basecommand import open_logfile
|
2010-04-19 13:51:15 +02:00
|
|
|
fp = open_logfile('testpip.log')
|
|
|
|
fp.write('can write')
|
|
|
|
fp.close()
|
|
|
|
assert os.path.exists(fp.name)
|
|
|
|
os.remove(fp.name)
|
2013-12-04 14:04:54 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_options_from_venv_config(script, virtualenv):
|
|
|
|
"""
|
|
|
|
Test if ConfigOptionParser reads a virtualenv-local config file
|
|
|
|
|
|
|
|
"""
|
|
|
|
from pip.locations import default_config_basename
|
|
|
|
conf = "[global]\nno-index = true"
|
|
|
|
ini = virtualenv.location / default_config_basename
|
|
|
|
with open(ini, 'w') as f:
|
|
|
|
f.write(conf)
|
|
|
|
result = script.pip('install', '-vvv', 'INITools', expect_error=True)
|
|
|
|
assert "Ignoring indexes:" in result.stdout, str(result)
|
2014-01-28 15:17:51 +01:00
|
|
|
assert (
|
|
|
|
"DistributionNotFound: No distributions at all found for INITools"
|
|
|
|
in result.stdout
|
|
|
|
)
|