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

Run black on tests/functional/test_install_user.py #10322

Closed
wants to merge 1 commit into from
Closed
Changes from all 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
143 changes: 74 additions & 69 deletions tests/functional/test_install_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,75 +17,80 @@ def _patch_dist_in_site_packages(virtualenv):
# error: Monkey patch `pip._internal.req.req_install.dist_in_site_packages`
# and `pip._internal.utils.misc.dist_in_site_packages`
# so it's possible to install a conflicting distribution in the user site.
virtualenv.sitecustomize = textwrap.dedent("""
virtualenv.sitecustomize = textwrap.dedent(
"""
def dist_in_site_packages(dist):
return False

from pip._internal.req import req_install
from pip._internal.utils import misc
req_install.dist_in_site_packages = dist_in_site_packages
misc.dist_in_site_packages = dist_in_site_packages
""")
"""
)


class Tests_UserSite:

@pytest.mark.network
@pytest.mark.incompatible_with_test_venv
def test_reset_env_system_site_packages_usersite(self, script):
"""
Check user site works as expected.
"""
script.pip('install', '--user', 'INITools==0.2')
script.pip("install", "--user", "INITools==0.2")
result = script.run(
'python', '-c',
"python",
"-c",
"import pkg_resources; print(pkg_resources.get_distribution"
"('initools').project_name)",
)
project_name = result.stdout.strip()
assert 'INITools' == project_name, project_name
assert "INITools" == project_name, project_name

@pytest.mark.xfail
@pytest.mark.network
@need_svn
@pytest.mark.incompatible_with_test_venv
def test_install_subversion_usersite_editable_with_distribute(
self, script, tmpdir):
def test_install_subversion_usersite_editable_with_distribute(self, script, tmpdir):
"""
Test installing current directory ('.') into usersite after installing
distribute
"""
result = script.pip(
'install', '--user', '-e',
'{checkout}#egg=initools'.format(
"install",
"--user",
"-e",
"{checkout}#egg=initools".format(
checkout=local_checkout(
'svn+http://svn.colorstudy.com/INITools', tmpdir)
)
"svn+http://svn.colorstudy.com/INITools", tmpdir
)
),
)
result.assert_installed('INITools', use_user_site=True)
result.assert_installed("INITools", use_user_site=True)

@pytest.mark.incompatible_with_test_venv
def test_install_from_current_directory_into_usersite(
self, script, data, with_wheel):
self, script, data, with_wheel
):
"""
Test installing current directory ('.') into usersite
"""
run_from = data.packages.joinpath("FSPkg")
result = script.pip(
'install', '-vvv', '--user', curdir,
"install",
"-vvv",
"--user",
curdir,
cwd=run_from,
)

fspkg_folder = script.user_site / 'fspkg'
fspkg_folder = script.user_site / "fspkg"
result.did_create(fspkg_folder)

dist_info_folder = (
script.user_site / 'FSPkg-0.1.dev0.dist-info'
)
dist_info_folder = script.user_site / "FSPkg-0.1.dev0.dist-info"
result.did_create(dist_info_folder)

def test_install_user_venv_nositepkgs_fails(self, virtualenv,
script, data):
def test_install_user_venv_nositepkgs_fails(self, virtualenv, script, data):
"""
user install in virtualenv (with no system packages) fails with message
"""
Expand All @@ -94,7 +99,9 @@ def test_install_user_venv_nositepkgs_fails(self, virtualenv,
virtualenv.user_site_packages = False
run_from = data.packages.joinpath("FSPkg")
result = script.pip(
'install', '--user', curdir,
"install",
"--user",
curdir,
cwd=run_from,
expect_error=True,
)
Expand All @@ -110,20 +117,19 @@ def test_install_user_conflict_in_usersite(self, script):
Test user install with conflict in usersite updates usersite.
"""

script.pip('install', '--user', 'INITools==0.3', '--no-binary=:all:')
script.pip("install", "--user", "INITools==0.3", "--no-binary=:all:")

result2 = script.pip(
'install', '--user', 'INITools==0.1', '--no-binary=:all:')
result2 = script.pip("install", "--user", "INITools==0.1", "--no-binary=:all:")

# usersite has 0.1
# we still test for egg-info because no-binary implies setup.py install
egg_info_folder = (
script.user_site / f'INITools-0.1-py{pyversion}.egg-info'
)
egg_info_folder = script.user_site / f"INITools-0.1-py{pyversion}.egg-info"
initools_v3_file = (
# file only in 0.3
script.base_path / script.user_site / 'initools' /
'configparser.py'
script.base_path
/ script.user_site
/ "initools"
/ "configparser.py"
)
result2.did_create(egg_info_folder)
assert not isfile(initools_v3_file), initools_v3_file
Expand All @@ -137,26 +143,24 @@ def test_install_user_conflict_in_globalsite(self, virtualenv, script):
"""
_patch_dist_in_site_packages(virtualenv)

script.pip('install', 'INITools==0.2', '--no-binary=:all:')
script.pip("install", "INITools==0.2", "--no-binary=:all:")

result2 = script.pip(
'install', '--user', 'INITools==0.1', '--no-binary=:all:')
result2 = script.pip("install", "--user", "INITools==0.1", "--no-binary=:all:")

# usersite has 0.1
# we still test for egg-info because no-binary implies setup.py install
egg_info_folder = (
script.user_site / f'INITools-0.1-py{pyversion}.egg-info'
)
initools_folder = script.user_site / 'initools'
egg_info_folder = script.user_site / f"INITools-0.1-py{pyversion}.egg-info"
initools_folder = script.user_site / "initools"
result2.did_create(egg_info_folder)
result2.did_create(initools_folder)

# site still has 0.2 (can't look in result1; have to check)
egg_info_folder = (
script.base_path / script.site_packages /
f'INITools-0.2-py{pyversion}.egg-info'
script.base_path
/ script.site_packages
/ f"INITools-0.2-py{pyversion}.egg-info"
)
initools_folder = script.base_path / script.site_packages / 'initools'
initools_folder = script.base_path / script.site_packages / "initools"
assert isdir(egg_info_folder)
assert isdir(initools_folder)

Expand All @@ -169,91 +173,92 @@ def test_upgrade_user_conflict_in_globalsite(self, virtualenv, script):
"""
_patch_dist_in_site_packages(virtualenv)

script.pip('install', 'INITools==0.2', '--no-binary=:all:')
script.pip("install", "INITools==0.2", "--no-binary=:all:")
result2 = script.pip(
'install', '--user', '--upgrade', 'INITools', '--no-binary=:all:')
"install", "--user", "--upgrade", "INITools", "--no-binary=:all:"
)

# usersite has 0.3.1
# we still test for egg-info because no-binary implies setup.py install
egg_info_folder = (
script.user_site / f'INITools-0.3.1-py{pyversion}.egg-info'
)
initools_folder = script.user_site / 'initools'
egg_info_folder = script.user_site / f"INITools-0.3.1-py{pyversion}.egg-info"
initools_folder = script.user_site / "initools"
result2.did_create(egg_info_folder)
result2.did_create(initools_folder)

# site still has 0.2 (can't look in result1; have to check)
egg_info_folder = (
script.base_path / script.site_packages /
f'INITools-0.2-py{pyversion}.egg-info'
script.base_path
/ script.site_packages
/ f"INITools-0.2-py{pyversion}.egg-info"
)
initools_folder = script.base_path / script.site_packages / 'initools'
initools_folder = script.base_path / script.site_packages / "initools"
assert isdir(egg_info_folder), result2.stdout
assert isdir(initools_folder)

@pytest.mark.network
@pytest.mark.incompatible_with_test_venv
def test_install_user_conflict_in_globalsite_and_usersite(
self, virtualenv, script):
def test_install_user_conflict_in_globalsite_and_usersite(self, virtualenv, script):
"""
Test user install with conflict in globalsite and usersite ignores
global site and updates usersite.
"""
_patch_dist_in_site_packages(virtualenv)

script.pip('install', 'INITools==0.2', '--no-binary=:all:')
script.pip('install', '--user', 'INITools==0.3', '--no-binary=:all:')
script.pip("install", "INITools==0.2", "--no-binary=:all:")
script.pip("install", "--user", "INITools==0.3", "--no-binary=:all:")

result3 = script.pip(
'install', '--user', 'INITools==0.1', '--no-binary=:all:')
result3 = script.pip("install", "--user", "INITools==0.1", "--no-binary=:all:")

# usersite has 0.1
# we still test for egg-info because no-binary implies setup.py install
egg_info_folder = (
script.user_site / f'INITools-0.1-py{pyversion}.egg-info'
)
egg_info_folder = script.user_site / f"INITools-0.1-py{pyversion}.egg-info"
initools_v3_file = (
# file only in 0.3
script.base_path / script.user_site / 'initools' /
'configparser.py'
script.base_path
/ script.user_site
/ "initools"
/ "configparser.py"
)
result3.did_create(egg_info_folder)
assert not isfile(initools_v3_file), initools_v3_file

# site still has 0.2 (can't just look in result1; have to check)
egg_info_folder = (
script.base_path / script.site_packages /
f'INITools-0.2-py{pyversion}.egg-info'
script.base_path
/ script.site_packages
/ f"INITools-0.2-py{pyversion}.egg-info"
)
initools_folder = script.base_path / script.site_packages / 'initools'
initools_folder = script.base_path / script.site_packages / "initools"
assert isdir(egg_info_folder)
assert isdir(initools_folder)

@pytest.mark.network
@pytest.mark.incompatible_with_test_venv
def test_install_user_in_global_virtualenv_with_conflict_fails(
self, script):
def test_install_user_in_global_virtualenv_with_conflict_fails(self, script):
"""
Test user install in --system-site-packages virtualenv with conflict in
site fails.
"""

script.pip('install', 'INITools==0.2')
script.pip("install", "INITools==0.2")

result2 = script.pip(
'install', '--user', 'INITools==0.1',
"install",
"--user",
"INITools==0.1",
expect_error=True,
)
resultp = script.run(
'python', '-c',
"python",
"-c",
"import pkg_resources; print(pkg_resources.get_distribution"
"('initools').location)",
)
dist_location = resultp.stdout.strip()
assert (
"Will not install to the user site because it will lack sys.path "
"precedence to {name} in {location}".format(
name='INITools',
name="INITools",
location=dist_location,
)
in result2.stderr
Expand Down