Merge pull request #7987 from deveshks/add-tests-for-pip-cmds-ignoring-cwd

Add unit tests for pip commands not using cwd
This commit is contained in:
Pradyun Gedam 2020-04-10 14:29:06 +05:30 committed by GitHub
commit 9360793a6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 185 additions and 8 deletions

View File

@ -239,3 +239,56 @@ def test_basic_check_broken_metadata(script):
assert 'Error parsing requirements' in result.stderr
assert result.returncode == 1
def test_check_skip_work_dir_pkg(script):
"""
Test that check should not include package
present in working directory
"""
# Create a test package with dependency missing
# and create .egg-info dir
pkg_path = create_test_package_with_setup(
script, name='simple', version='1.0',
install_requires=['missing==0.1'])
script.run('python', 'setup.py', 'egg_info',
expect_stderr=True, cwd=pkg_path)
# Check should not complain about broken requirements
# when run from package directory
result = script.pip('check', cwd=pkg_path)
expected_lines = (
"No broken requirements found.",
)
assert matches_expected_lines(result.stdout, expected_lines)
assert result.returncode == 0
def test_check_include_work_dir_pkg(script):
"""
Test that check should include package in working directory
if working directory is added in PYTHONPATH
"""
# Create a test package with dependency missing
# and create .egg-info dir
pkg_path = create_test_package_with_setup(
script, name='simple', version='1.0',
install_requires=['missing==0.1'])
script.run('python', 'setup.py', 'egg_info',
expect_stderr=True, cwd=pkg_path)
script.environ.update({'PYTHONPATH': pkg_path})
# Check should mention about missing requirement simple
# when run from package directory, when package directory
# is in PYTHONPATH
result = script.pip('check', expect_error=True, cwd=pkg_path)
expected_lines = (
"simple 1.0 requires missing, which is not installed.",
)
assert matches_expected_lines(result.stdout, expected_lines)
assert result.returncode == 1

View File

@ -11,6 +11,7 @@ from tests.lib import (
_create_test_package_with_srcdir,
_git_commit,
_vcs_add,
create_test_package_with_setup,
need_bzr,
need_mercurial,
need_svn,
@ -824,3 +825,40 @@ def test_freeze_direct_url_archive(script, shared_data, with_wheel):
script.pip("install", req)
result = script.pip("freeze")
assert req in result.stdout
def test_freeze_skip_work_dir_pkg(script):
"""
Test that freeze should not include package
present in working directory
"""
# Create a test package and create .egg-info dir
pkg_path = create_test_package_with_setup(
script, name='simple', version='1.0')
script.run('python', 'setup.py', 'egg_info',
expect_stderr=True, cwd=pkg_path)
# Freeze should not include package simple when run from package directory
result = script.pip('freeze', cwd=pkg_path)
assert 'simple' not in result.stdout
def test_freeze_include_work_dir_pkg(script):
"""
Test that freeze should include package in working directory
if working directory is added in PYTHONPATH
"""
# Create a test package and create .egg-info dir
pkg_path = create_test_package_with_setup(
script, name='simple', version='1.0')
script.run('python', 'setup.py', 'egg_info',
expect_stderr=True, cwd=pkg_path)
script.environ.update({'PYTHONPATH': pkg_path})
# Freeze should include package simple when run from package directory,
# when package directory is in PYTHONPATH
result = script.pip('freeze', cwd=pkg_path)
assert 'simple==1.0' in result.stdout

View File

@ -1846,3 +1846,53 @@ def test_install_sends_client_cert(install_args, script, cert_factory, data):
environ, _ = call_args.args
assert "SSL_CLIENT_CERT" in environ
assert environ["SSL_CLIENT_CERT"]
def test_install_skip_work_dir_pkg(script, data):
"""
Test that install of a package in working directory
should pass on the second attempt after an install
and an uninstall
"""
# Create a test package and install it
pkg_path = create_test_package_with_setup(
script, name='simple', version='1.0')
script.pip('install', '-e', '.',
expect_stderr=True, cwd=pkg_path)
# Uninstalling the package and installing it again will succeed
script.pip('uninstall', 'simple', '-y')
result = script.pip('install', '--find-links',
data.find_links, 'simple',
expect_stderr=True, cwd=pkg_path)
assert 'Requirement already satisfied: simple' not in result.stdout
assert 'Successfully installed simple' in result.stdout
def test_install_include_work_dir_pkg(script, data):
"""
Test that install of a package in working directory
should fail on the second attempt after an install
if working directory is added in PYTHONPATH
"""
# Create a test package and install it
pkg_path = create_test_package_with_setup(
script, name='simple', version='1.0')
script.pip('install', '-e', '.',
expect_stderr=True, cwd=pkg_path)
# Uninstall will fail with given warning
script.pip('uninstall', 'simple', '-y')
script.environ.update({'PYTHONPATH': pkg_path})
# Uninstalling the package and installing it again will fail,
# when package directory is in PYTHONPATH
result = script.pip('install', '--find-links',
data.find_links, 'simple',
expect_stderr=True, cwd=pkg_path)
assert 'Requirement already satisfied: simple' in result.stdout

View File

@ -552,9 +552,8 @@ def test_list_skip_work_dir_pkg(script):
"""
# Create a test package and create .egg-info dir
pkg_path = create_test_package_with_setup(script,
name='simple',
version='1.0')
pkg_path = create_test_package_with_setup(
script, name='simple', version='1.0')
script.run('python', 'setup.py', 'egg_info',
expect_stderr=True, cwd=pkg_path)
@ -567,14 +566,12 @@ def test_list_skip_work_dir_pkg(script):
def test_list_include_work_dir_pkg(script):
"""
Test that list should include package in working directory
if working directory is added in sys.path
if working directory is added in PYTHONPATH
"""
# Create a test package and create .egg-info dir
pkg_path = create_test_package_with_setup(script,
name='simple',
version='1.0')
pkg_path = create_test_package_with_setup(
script, name='simple', version='1.0')
script.run('python', 'setup.py', 'egg_info',
expect_stderr=True, cwd=pkg_path)

View File

@ -5,6 +5,7 @@ import pytest
from pip import __version__
from pip._internal.commands.show import search_packages_info
from tests.lib import create_test_package_with_setup
def test_basic_show(script):
@ -259,3 +260,41 @@ def test_show_required_by_packages_requiring_capitalized(script, data):
assert 'Name: Requires-Capitalized' in lines
assert 'Required-by: requires-requires-capitalized' in lines
def test_show_skip_work_dir_pkg(script):
"""
Test that show should not include package
present in working directory
"""
# Create a test package and create .egg-info dir
pkg_path = create_test_package_with_setup(
script, name='simple', version='1.0')
script.run('python', 'setup.py', 'egg_info',
expect_stderr=True, cwd=pkg_path)
# Show should not include package simple when run from package directory
result = script.pip('show', 'simple', expect_error=True, cwd=pkg_path)
assert 'WARNING: Package(s) not found: simple' in result.stderr
def test_show_include_work_dir_pkg(script):
"""
Test that show should include package in working directory
if working directory is added in PYTHONPATH
"""
# Create a test package and create .egg-info dir
pkg_path = create_test_package_with_setup(
script, name='simple', version='1.0')
script.run('python', 'setup.py', 'egg_info',
expect_stderr=True, cwd=pkg_path)
script.environ.update({'PYTHONPATH': pkg_path})
# Show should include package simple when run from package directory,
# when package directory is in PYTHONPATH
result = script.pip('show', 'simple', cwd=pkg_path)
lines = result.stdout.splitlines()
assert 'Name: simple' in lines