Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit tests for pip commands not using cwd #7987

Merged
merged 5 commits into from
Apr 10, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
53 changes: 53 additions & 0 deletions tests/functional/test_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
deveshks marked this conversation as resolved.
Show resolved Hide resolved
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
deveshks marked this conversation as resolved.
Show resolved Hide resolved
script.environ.update({'PYTHONPATH': pkg_path})

# Check should mention about missing requirement simple
# when run from package directory
deveshks marked this conversation as resolved.
Show resolved Hide resolved
result = script.pip('check', expect_error=True)
deveshks marked this conversation as resolved.
Show resolved Hide resolved
expected_lines = (
"simple 1.0 requires missing, which is not installed.",
)
assert matches_expected_lines(result.stdout, expected_lines)
assert result.returncode == 1
42 changes: 36 additions & 6 deletions tests/functional/test_freeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
_create_test_package_with_srcdir,
_git_commit,
_vcs_add,
create_test_package_with_setup,
need_bzr,
need_mercurial,
need_svn,
Expand Down Expand Up @@ -818,9 +819,38 @@ def test_freeze_path_multiple(tmpdir, script, data):
_check_output(result.stdout, expected)


def test_freeze_direct_url_archive(script, shared_data, with_wheel):
req = "simple @ " + path_to_url(shared_data.packages / "simple-2.0.tar.gz")
assert req.startswith("simple @ file://")
script.pip("install", req)
result = script.pip("freeze")
assert req in result.stdout
deveshks marked this conversation as resolved.
Show resolved Hide resolved
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==1.0' not in result.stdout
deveshks marked this conversation as resolved.
Show resolved Hide resolved


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
deveshks marked this conversation as resolved.
Show resolved Hide resolved
result = script.pip('freeze', cwd=pkg_path)
assert 'simple==1.0' in result.stdout
48 changes: 48 additions & 0 deletions tests/functional/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -1821,3 +1821,51 @@ 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 'Successfully installed simple' in result.stdout
sbidoul marked this conversation as resolved.
Show resolved Hide resolved


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
deveshks marked this conversation as resolved.
Show resolved Hide resolved
script.pip('uninstall', 'simple', '-y')

# Add PYTHONPATH env variable
script.environ.update({'PYTHONPATH': pkg_path})

# Uninstalling the package and installing it again will fail
deveshks marked this conversation as resolved.
Show resolved Hide resolved
result = script.pip('install', '--find-links',
data.find_links, 'simple',
expect_stderr=True, cwd=pkg_path)
assert 'Requirement already satisfied: simple' in result.stdout
13 changes: 5 additions & 8 deletions tests/functional/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand Down
39 changes: 39 additions & 0 deletions tests/functional/test_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

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):
Expand Down Expand Up @@ -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)

# 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