summaryrefslogtreecommitdiff
path: root/tests/test_basic.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_basic.py')
-rw-r--r--tests/test_basic.py82
1 files changed, 46 insertions, 36 deletions
diff --git a/tests/test_basic.py b/tests/test_basic.py
index aa1129745..8bdce9772 100644
--- a/tests/test_basic.py
+++ b/tests/test_basic.py
@@ -7,7 +7,7 @@ from os.path import abspath, join, curdir, pardir
from nose import SkipTest
from nose.tools import assert_raises
-from mock import Mock, patch
+from mock import patch
from pip.util import rmtree, find_command
from pip.exceptions import BadCommand
@@ -17,6 +17,7 @@ from tests.test_pip import (here, reset_env, run_pip, pyversion, mkdir,
from tests.local_repos import local_checkout
from tests.path import Path
+
def test_correct_pip_version():
"""
Check we are running proper version of pip in run_pip.
@@ -223,10 +224,10 @@ def test_install_editable_from_git():
reset_env()
args = ['install']
args.extend(['-e',
- '%s#egg=django-feedutil' %
- local_checkout('git+http://github.com/jezdez/django-feedutil.git')])
+ '%s#egg=pip-test-package' %
+ local_checkout('git+http://github.com/pypa/pip-test-package.git')])
result = run_pip(*args, **{"expect_error": True})
- result.assert_installed('django-feedutil', with_files=['.git'])
+ result.assert_installed('pip-test-package', with_files=['.git'])
def test_install_editable_from_hg():
@@ -377,7 +378,7 @@ def test_install_subversion_usersite_editable_with_setuptools_fails():
# We don't try to use setuptools for 3.X.
elif sys.version_info >= (3,):
raise SkipTest()
- env = reset_env()
+ env = reset_env(use_distribute=False)
no_site_packages = env.lib_path/'no-global-site-packages.txt'
if os.path.isfile(no_site_packages):
no_site_packages.rm() # this re-enables user_site
@@ -388,6 +389,7 @@ def test_install_subversion_usersite_editable_with_setuptools_fails():
expect_error=True)
assert '--user --editable not supported with setuptools, use distribute' in result.stdout
+
def test_install_pardir():
"""
Test installing parent directory ('..').
@@ -419,6 +421,7 @@ def test_install_with_pax_header():
run_from = abspath(join(here, 'packages'))
run_pip('install', 'paxpkg.tar.bz2', cwd=run_from)
+
def test_install_using_install_option_and_editable():
"""
Test installing a tool using -e and --install-option
@@ -502,6 +505,7 @@ def test_install_folder_using_relative_path():
egg_folder = env.site_packages / 'mock-100.1-py%s.egg-info' % pyversion
assert egg_folder in result.files_created, str(result)
+
def test_install_package_which_contains_dev_in_name():
"""
Test installing package from pypi which contains 'dev' in name
@@ -513,6 +517,17 @@ def test_install_package_which_contains_dev_in_name():
assert devserver_folder in result.files_created, str(result.stdout)
assert egg_info_folder in result.files_created, str(result)
+
+def test_install_package_with_target():
+ """
+ Test installing a package using pip install --target
+ """
+ env = reset_env()
+ target_dir = env.scratch_path/'target'
+ result = run_pip('install', '-t', target_dir, "initools==0.1")
+ assert Path('scratch')/'target'/'initools' in result.files_created, str(result)
+
+
def test_find_command_folder_in_path():
"""
If a folder named e.g. 'git' is in PATH, and find_command is looking for
@@ -520,13 +535,16 @@ def test_find_command_folder_in_path():
looking.
"""
env = reset_env()
- mkdir('path_one'); path_one = env.scratch_path/'path_one'
+ mkdir('path_one')
+ path_one = env.scratch_path/'path_one'
mkdir(path_one/'foo')
- mkdir('path_two'); path_two = env.scratch_path/'path_two'
+ mkdir('path_two')
+ path_two = env.scratch_path/'path_two'
write_file(path_two/'foo', '# nothing')
found_path = find_command('foo', map(str, [path_one, path_two]))
assert found_path == path_two/'foo'
+
def test_does_not_find_command_because_there_is_no_path():
"""
Test calling `pip.utils.find_command` when there is no PATH env variable
@@ -534,16 +552,18 @@ def test_does_not_find_command_because_there_is_no_path():
environ_before = os.environ
os.environ = {}
try:
- try:
- find_command('anycommand')
- except BadCommand:
- e = sys.exc_info()[1]
- assert e.args == ("Cannot find command 'anycommand'",)
- else:
- raise AssertionError("`find_command` should raise `BadCommand`")
+ try:
+ find_command('anycommand')
+ except BadCommand:
+ e = sys.exc_info()[1]
+ assert e.args == ("Cannot find command 'anycommand'",)
+ else:
+ raise AssertionError("`find_command` should raise `BadCommand`")
finally:
os.environ = environ_before
+
+@patch('os.pathsep', ':')
@patch('pip.util.get_pathext')
@patch('os.path.isfile')
def test_find_command_trys_all_pathext(mock_isfile, getpath_mock):
@@ -552,22 +572,18 @@ def test_find_command_trys_all_pathext(mock_isfile, getpath_mock):
exist.
"""
mock_isfile.return_value = False
- # Patching os.pathsep failed on type checking
- old_sep = os.pathsep
- os.pathsep = ':'
getpath_mock.return_value = os.pathsep.join([".COM", ".EXE"])
- paths = [ os.path.join('path_one', f) for f in ['foo.com', 'foo.exe', 'foo'] ]
- expected = [ ((p,),) for p in paths ]
+ paths = [os.path.join('path_one', f) for f in ['foo.com', 'foo.exe', 'foo']]
+ expected = [((p,),) for p in paths]
+
+ assert_raises(BadCommand, find_command, 'foo', 'path_one')
+ assert mock_isfile.call_args_list == expected, "Actual: %s\nExpected %s" % (mock_isfile.call_args_list, expected)
+ assert getpath_mock.called, "Should call get_pathext"
- try:
- assert_raises(BadCommand, find_command, 'foo', 'path_one')
- assert mock_isfile.call_args_list == expected, "Actual: %s\nExpected %s" % (mock_isfile.call_args_list, expected)
- assert getpath_mock.called, "Should call get_pathext"
- finally:
- os.pathsep = old_sep
+@patch('os.pathsep', ':')
@patch('pip.util.get_pathext')
@patch('os.path.isfile')
def test_find_command_trys_supplied_pathext(mock_isfile, getpath_mock):
@@ -575,19 +591,13 @@ def test_find_command_trys_supplied_pathext(mock_isfile, getpath_mock):
If pathext supplied find_command should use all of its list of extensions to find file.
"""
mock_isfile.return_value = False
- # Patching os.pathsep failed on type checking
- old_sep = os.pathsep
- os.pathsep = ':'
getpath_mock.return_value = ".FOO"
pathext = os.pathsep.join([".RUN", ".CMD"])
- paths = [ os.path.join('path_one', f) for f in ['foo.run', 'foo.cmd', 'foo'] ]
- expected = [ ((p,),) for p in paths ]
+ paths = [os.path.join('path_one', f) for f in ['foo.run', 'foo.cmd', 'foo']]
+ expected = [((p,),) for p in paths]
- try:
- assert_raises(BadCommand, find_command, 'foo', 'path_one', pathext)
- assert mock_isfile.call_args_list == expected, "Actual: %s\nExpected %s" % (mock_isfile.call_args_list, expected)
- assert not getpath_mock.called, "Should not call get_pathext"
- finally:
- os.pathsep = old_sep
+ assert_raises(BadCommand, find_command, 'foo', 'path_one', pathext)
+ assert mock_isfile.call_args_list == expected, "Actual: %s\nExpected %s" % (mock_isfile.call_args_list, expected)
+ assert not getpath_mock.called, "Should not call get_pathext"