Skip to content

Commit 2324ae4

Browse files
committed
Add unit tests for pip commands not using cwd
1 parent eb865b4 commit 2324ae4

File tree

6 files changed

+184
-14
lines changed

6 files changed

+184
-14
lines changed

news/9E2A89E1-F932-4159-9E69-8AEA7DFD6432.trivial

Whitespace-only changes.

tests/functional/test_check.py

+53
Original file line numberDiff line numberDiff line change
@@ -239,3 +239,56 @@ def test_basic_check_broken_metadata(script):
239239

240240
assert 'Error parsing requirements' in result.stderr
241241
assert result.returncode == 1
242+
243+
244+
def test_check_skip_work_dir_pkg(script):
245+
"""
246+
Test that check should not include package
247+
present in working directory
248+
"""
249+
250+
# Create a test package with dependency missing
251+
# and create .egg-info dir
252+
pkg_path = create_test_package_with_setup(
253+
script, name='simple', version='1.0',
254+
install_requires=['missing==0.1'])
255+
256+
script.run('python', 'setup.py', 'egg_info',
257+
expect_stderr=True, cwd=pkg_path)
258+
259+
# Check should not complain about broken requirements
260+
# when run from package directory
261+
result = script.pip('check')
262+
expected_lines = (
263+
"No broken requirements found.",
264+
)
265+
assert matches_expected_lines(result.stdout, expected_lines)
266+
assert result.returncode == 0
267+
268+
269+
def test_check_include_work_dir_pkg(script):
270+
"""
271+
Test that check should include package in working directory
272+
if working directory is added in PYTHONPATH
273+
"""
274+
275+
# Create a test package with dependency missing
276+
# and create .egg-info dir
277+
pkg_path = create_test_package_with_setup(
278+
script, name='simple', version='1.0',
279+
install_requires=['missing==0.1'])
280+
281+
script.run('python', 'setup.py', 'egg_info',
282+
expect_stderr=True, cwd=pkg_path)
283+
284+
# Add PYTHONPATH env variable
285+
script.environ.update({'PYTHONPATH': pkg_path})
286+
287+
# Check should mention about missing requirement simple
288+
# when run from package directory
289+
result = script.pip('check', expect_error=True)
290+
expected_lines = (
291+
"simple 1.0 requires missing, which is not installed.",
292+
)
293+
assert matches_expected_lines(result.stdout, expected_lines)
294+
assert result.returncode == 1

tests/functional/test_freeze.py

+39-6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
_create_test_package_with_srcdir,
1212
_git_commit,
1313
_vcs_add,
14+
create_test_package_with_setup,
1415
need_bzr,
1516
need_mercurial,
1617
need_svn,
@@ -818,9 +819,41 @@ def test_freeze_path_multiple(tmpdir, script, data):
818819
_check_output(result.stdout, expected)
819820

820821

821-
def test_freeze_direct_url_archive(script, shared_data, with_wheel):
822-
req = "simple @ " + path_to_url(shared_data.packages / "simple-2.0.tar.gz")
823-
assert req.startswith("simple @ file://")
824-
script.pip("install", req)
825-
result = script.pip("freeze")
826-
assert req in result.stdout
822+
def test_freeze_skip_work_dir_pkg(script):
823+
"""
824+
Test that freeze should not include package
825+
present in working directory
826+
"""
827+
828+
# Create a test package and create .egg-info dir
829+
pkg_path = create_test_package_with_setup(
830+
script, name='simple', version='1.0')
831+
script.run('python', 'setup.py', 'egg_info',
832+
expect_stderr=True, cwd=pkg_path)
833+
834+
# Freeze should not include package simple when run from package directory
835+
result = script.pip('freeze', 'simple', cwd=pkg_path)
836+
_check_output(result.stdout, '')
837+
838+
839+
def test_freeze_include_work_dir_pkg(script):
840+
"""
841+
Test that freeze should include package in working directory
842+
if working directory is added in PYTHONPATH
843+
"""
844+
845+
# Create a test package and create .egg-info dir
846+
pkg_path = create_test_package_with_setup(
847+
script, name='simple', version='1.0')
848+
script.run('python', 'setup.py', 'egg_info',
849+
expect_stderr=True, cwd=pkg_path)
850+
851+
# Add PYTHONPATH env variable
852+
script.environ.update({'PYTHONPATH': pkg_path})
853+
854+
# Freeze should include package simple when run from package directory
855+
result = script.pip('freeze', 'simple', cwd=pkg_path)
856+
expected = textwrap.dedent("""\
857+
simple==1.0
858+
<BLANKLINE>""")
859+
_check_output(result.stdout, expected)

tests/functional/test_install.py

+48
Original file line numberDiff line numberDiff line change
@@ -1821,3 +1821,51 @@ def test_install_sends_client_cert(install_args, script, cert_factory, data):
18211821
environ, _ = call_args.args
18221822
assert "SSL_CLIENT_CERT" in environ
18231823
assert environ["SSL_CLIENT_CERT"]
1824+
1825+
1826+
def test_install_skip_work_dir_pkg(script, data):
1827+
"""
1828+
Test that install of a package in working directory
1829+
should pass on the second attempt after an install
1830+
and an uninstall
1831+
"""
1832+
1833+
# Create a test package and install it
1834+
pkg_path = create_test_package_with_setup(
1835+
script, name='simple', version='1.0')
1836+
script.pip('install', '-e', '.',
1837+
expect_stderr=True, cwd=pkg_path)
1838+
1839+
# Uninstalling the package and installing it again will succeed
1840+
script.pip('uninstall', 'simple', '-y')
1841+
1842+
result = script.pip('install', '--find-links',
1843+
data.find_links, 'simple',
1844+
expect_stderr=True, cwd=pkg_path)
1845+
assert 'Successfully installed simple' in result.stdout
1846+
1847+
1848+
def test_install_include_work_dir_pkg(script, data):
1849+
"""
1850+
Test that install of a package in working directory
1851+
should fail on the second attempt after an install
1852+
if working directory is added in PYTHONPATH
1853+
"""
1854+
1855+
# Create a test package and install it
1856+
pkg_path = create_test_package_with_setup(
1857+
script, name='simple', version='1.0')
1858+
script.pip('install', '-e', '.',
1859+
expect_stderr=True, cwd=pkg_path)
1860+
1861+
# Uninstall will fail with given warning
1862+
script.pip('uninstall', 'simple', '-y')
1863+
1864+
# Add PYTHONPATH env variable
1865+
script.environ.update({'PYTHONPATH': pkg_path})
1866+
1867+
# Uninstalling the package and installing it again will fail
1868+
result = script.pip('install', '--find-links',
1869+
data.find_links, 'simple',
1870+
expect_stderr=True, cwd=pkg_path)
1871+
assert 'Requirement already satisfied: simple' in result.stdout

tests/functional/test_list.py

+5-8
Original file line numberDiff line numberDiff line change
@@ -552,9 +552,8 @@ def test_list_skip_work_dir_pkg(script):
552552
"""
553553

554554
# Create a test package and create .egg-info dir
555-
pkg_path = create_test_package_with_setup(script,
556-
name='simple',
557-
version='1.0')
555+
pkg_path = create_test_package_with_setup(
556+
script, name='simple', version='1.0')
558557
script.run('python', 'setup.py', 'egg_info',
559558
expect_stderr=True, cwd=pkg_path)
560559

@@ -567,14 +566,12 @@ def test_list_skip_work_dir_pkg(script):
567566
def test_list_include_work_dir_pkg(script):
568567
"""
569568
Test that list should include package in working directory
570-
if working directory is added in sys.path
569+
if working directory is added in PYTHONPATH
571570
"""
572571

573572
# Create a test package and create .egg-info dir
574-
pkg_path = create_test_package_with_setup(script,
575-
name='simple',
576-
version='1.0')
577-
573+
pkg_path = create_test_package_with_setup(
574+
script, name='simple', version='1.0')
578575
script.run('python', 'setup.py', 'egg_info',
579576
expect_stderr=True, cwd=pkg_path)
580577

tests/functional/test_show.py

+39
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from pip import __version__
77
from pip._internal.commands.show import search_packages_info
8+
from tests.lib import create_test_package_with_setup
89

910

1011
def test_basic_show(script):
@@ -259,3 +260,41 @@ def test_show_required_by_packages_requiring_capitalized(script, data):
259260

260261
assert 'Name: Requires-Capitalized' in lines
261262
assert 'Required-by: requires-requires-capitalized' in lines
263+
264+
265+
def test_show_skip_work_dir_pkg(script):
266+
"""
267+
Test that show should not include package
268+
present in working directory
269+
"""
270+
271+
# Create a test package and create .egg-info dir
272+
pkg_path = create_test_package_with_setup(
273+
script, name='simple', version='1.0')
274+
script.run('python', 'setup.py', 'egg_info',
275+
expect_stderr=True, cwd=pkg_path)
276+
277+
# Show should not include package simple when run from package directory
278+
result = script.pip('show', 'simple', cwd=pkg_path)
279+
assert 'WARNING: Package(s) not found: simple' in result.stderr
280+
281+
282+
def test_show_include_work_dir_pkg(script):
283+
"""
284+
Test that show should include package in working directory
285+
if working directory is added in PYTHONPATH
286+
"""
287+
288+
# Create a test package and create .egg-info dir
289+
pkg_path = create_test_package_with_setup(
290+
script, name='simple', version='1.0')
291+
script.run('python', 'setup.py', 'egg_info',
292+
expect_stderr=True, cwd=pkg_path)
293+
294+
# Add PYTHONPATH env variable
295+
script.environ.update({'PYTHONPATH': pkg_path})
296+
297+
# Show should include package simple when run from package directory
298+
result = script.pip('show', 'simple', cwd=pkg_path)
299+
lines = result.stdout.splitlines()
300+
assert 'Name: simple' in lines

0 commit comments

Comments
 (0)