1
1
Fork 0
mirror of https://github.com/pypa/pip synced 2023-12-13 21:30:23 +01:00

Add unit tests for pip commands not using cwd

This commit is contained in:
Devesh Kumar Singh 2020-04-05 23:17:03 +05:30
parent eb865b4e10
commit 2324ae422e
6 changed files with 184 additions and 14 deletions

View file

@ -239,3 +239,56 @@ def test_basic_check_broken_metadata(script):
assert 'Error parsing requirements' in result.stderr assert 'Error parsing requirements' in result.stderr
assert result.returncode == 1 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')
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)
# Add PYTHONPATH env variable
script.environ.update({'PYTHONPATH': pkg_path})
# Check should mention about missing requirement simple
# when run from package directory
result = script.pip('check', expect_error=True)
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, _create_test_package_with_srcdir,
_git_commit, _git_commit,
_vcs_add, _vcs_add,
create_test_package_with_setup,
need_bzr, need_bzr,
need_mercurial, need_mercurial,
need_svn, need_svn,
@ -818,9 +819,41 @@ def test_freeze_path_multiple(tmpdir, script, data):
_check_output(result.stdout, expected) _check_output(result.stdout, expected)
def test_freeze_direct_url_archive(script, shared_data, with_wheel): def test_freeze_skip_work_dir_pkg(script):
req = "simple @ " + path_to_url(shared_data.packages / "simple-2.0.tar.gz") """
assert req.startswith("simple @ file://") Test that freeze should not include package
script.pip("install", req) present in working directory
result = script.pip("freeze") """
assert req in result.stdout
# 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', 'simple', cwd=pkg_path)
_check_output(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)
# Add PYTHONPATH env variable
script.environ.update({'PYTHONPATH': pkg_path})
# Freeze should include package simple when run from package directory
result = script.pip('freeze', 'simple', cwd=pkg_path)
expected = textwrap.dedent("""\
simple==1.0
<BLANKLINE>""")
_check_output(result.stdout, expected)

View file

@ -1821,3 +1821,51 @@ def test_install_sends_client_cert(install_args, script, cert_factory, data):
environ, _ = call_args.args environ, _ = call_args.args
assert "SSL_CLIENT_CERT" in environ assert "SSL_CLIENT_CERT" in environ
assert environ["SSL_CLIENT_CERT"] 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 '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')
# Add PYTHONPATH env variable
script.environ.update({'PYTHONPATH': pkg_path})
# Uninstalling the package and installing it again will fail
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 # Create a test package and create .egg-info dir
pkg_path = create_test_package_with_setup(script, pkg_path = create_test_package_with_setup(
name='simple', script, name='simple', version='1.0')
version='1.0')
script.run('python', 'setup.py', 'egg_info', script.run('python', 'setup.py', 'egg_info',
expect_stderr=True, cwd=pkg_path) 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): def test_list_include_work_dir_pkg(script):
""" """
Test that list should include package in working directory 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 # Create a test package and create .egg-info dir
pkg_path = create_test_package_with_setup(script, pkg_path = create_test_package_with_setup(
name='simple', script, name='simple', version='1.0')
version='1.0')
script.run('python', 'setup.py', 'egg_info', script.run('python', 'setup.py', 'egg_info',
expect_stderr=True, cwd=pkg_path) expect_stderr=True, cwd=pkg_path)

View file

@ -5,6 +5,7 @@ import pytest
from pip import __version__ from pip import __version__
from pip._internal.commands.show import search_packages_info from pip._internal.commands.show import search_packages_info
from tests.lib import create_test_package_with_setup
def test_basic_show(script): 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 'Name: Requires-Capitalized' in lines
assert 'Required-by: requires-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', 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)
# Add PYTHONPATH env variable
script.environ.update({'PYTHONPATH': pkg_path})
# Show should include package simple when run from package directory
result = script.pip('show', 'simple', cwd=pkg_path)
lines = result.stdout.splitlines()
assert 'Name: simple' in lines