Files
pipenv/tests/integration/test_uninstall.py
T
Matt Davis 9848862927 Convert test runner to use pypiserver package as standalone process (#5284)
* Check point progress on moving tests to pypiserver.

* Allow other indexes to mimic the pypi json API for package hashes.

* Fix these tests that run on lower python versions only.

* Try adding the pypiserver to the github actions to only run once.

* Expand the scope of fixtures for pypiserver.

* try to accomedate microsoft runner.

* Windows networking troubles.

* Remove running as a background job.

* Try to condtionally invoke different start pypi-server commands

* Try to condtionally invoke different start pypi-server commands

* Try to condtionally invoke different start pypi-server commands

* Try to condtionally invoke different start pypi-server commands

* Try to condtionally invoke different start pypi-server commands

* Try to condtionally invoke different start pypi-server commands

* Try to condtionally invoke different start pypi-server commands

* Try to introduce pypi as the root index because setuptools-scm is not in our pypi artifacts.

* see if the windows tests run faster (and the other tests) by supplying waitress.

* Only use waitress on windows because the others are fast on the default.  Fix requests pollution.

* Supply a suitable Pipfile instead for these two failing tests.

* More requests resolver cross test contamination cleanup.

* remove problematic tests because even on my version of python 3.8.12 this does not work due to AttributeError: 'HTMLParser' object has no attribute 'unescape'

* fix mirror install test.

* Fix Pipfile.

* Fix Pipfile for real

* Fix tests

* Cleanup test naming and more test enhancements.

* Save this optimization for a subsequent PR.

* Cleanup the TemporaryDirectory between tests.

* resolve merge conflict.

* Cleanup path initalization -- it hsould always be a TemporaryDirectory for tests that gets cleanedup.

* Cleanup path initalization -- it hsould always be a TemporaryDirectory for tests that gets cleanedup.

* tableflip on those requests tests that read the setup metadata in reqlib from other tests.

* Update developer documentation for running tests.

* add news fragment.

* Try gunicorn perfoormance for linux/mac

* Only use gunicorn on linux based on the results of last run.
2022-09-05 10:19:12 -04:00

197 lines
6.7 KiB
Python

import os
import shutil
import pytest
from pipenv.utils.shell import temp_environ
@pytest.mark.uninstall
@pytest.mark.install
def test_uninstall_requests(pipenv_instance_private_pypi):
# Uninstalling requests can fail even when uninstall Django below
# succeeds, if requests was de-vendored.
# See https://github.com/pypa/pipenv/issues/3644 for problems
# caused by devendoring
with pipenv_instance_private_pypi() as p:
c = p.pipenv("install requests")
assert c.returncode == 0
assert "requests" in p.pipfile["packages"]
c = p.pipenv("run python -m requests.help")
assert c.returncode == 0
c = p.pipenv("uninstall requests")
assert c.returncode == 0
assert "requests" not in p.pipfile["dev-packages"]
c = p.pipenv("run python -m requests.help")
assert c.returncode > 0
@pytest.mark.uninstall
def test_uninstall_django(pipenv_instance_private_pypi):
with pipenv_instance_private_pypi() as p:
c = p.pipenv("install Django")
assert c.returncode == 0
assert "django" in p.pipfile["packages"]
assert "django" in p.lockfile["default"]
assert "pytz" in p.lockfile["default"]
c = p.pipenv("run python -m django --version")
assert c.returncode == 0
c = p.pipenv("uninstall Django")
assert c.returncode == 0
assert "django" not in p.pipfile["dev-packages"]
assert "django" not in p.lockfile["develop"]
assert p.lockfile["develop"] == {}
c = p.pipenv("run python -m django --version")
assert c.returncode > 0
@pytest.mark.install
@pytest.mark.uninstall
def test_mirror_uninstall(pipenv_instance_private_pypi):
with temp_environ(), pipenv_instance_private_pypi(chdir=True) as p:
mirror_url = os.environ.pop(
"PIPENV_TEST_INDEX", "https://pypi.python.org/simple"
)
assert "pypi.org" not in mirror_url
c = p.pipenv(f"install Django --pypi-mirror {mirror_url}")
assert c.returncode == 0
assert "django" in p.pipfile["packages"]
assert "django" in p.lockfile["default"]
assert "pytz" in p.lockfile["default"]
# Ensure the --pypi-mirror parameter hasn't altered the Pipfile or Pipfile.lock sources
assert len(p.pipfile["source"]) == 1
assert len(p.lockfile["_meta"]["sources"]) == 1
assert "https://pypi.org/simple" == p.pipfile["source"][0]["url"]
assert "https://pypi.org/simple" == p.lockfile["_meta"]["sources"][0]["url"]
c = p.pipenv("run python -m django --version")
assert c.returncode == 0
c = p.pipenv(f"uninstall Django --pypi-mirror {mirror_url}")
assert c.returncode == 0
assert "django" not in p.pipfile["dev-packages"]
assert "django" not in p.lockfile["develop"]
assert p.lockfile["develop"] == {}
# Ensure the --pypi-mirror parameter hasn't altered the Pipfile or Pipfile.lock sources
assert len(p.pipfile["source"]) == 1
assert len(p.lockfile["_meta"]["sources"]) == 1
assert "https://pypi.org/simple" == p.pipfile["source"][0]["url"]
assert "https://pypi.org/simple" == p.lockfile["_meta"]["sources"][0]["url"]
c = p.pipenv("run python -m django --version")
assert c.returncode > 0
@pytest.mark.files
@pytest.mark.install
@pytest.mark.uninstall
def test_uninstall_all_local_files(pipenv_instance_private_pypi, testsroot):
file_name = "tablib-0.12.1.tar.gz"
# Not sure where travis/appveyor run tests from
source_path = os.path.abspath(os.path.join(testsroot, "pypi", "tablib", file_name))
with pipenv_instance_private_pypi(chdir=True) as p:
shutil.copy(source_path, os.path.join(p.path, file_name))
os.mkdir(os.path.join(p.path, "tablib"))
c = p.pipenv(f"install {file_name}")
assert c.returncode == 0
c = p.pipenv("uninstall --all")
assert c.returncode == 0
assert "tablib" in c.stdout
# Uninstall --all is not supposed to remove things from the pipfile
# Note that it didn't before, but that instead local filenames showed as hashes
assert "tablib" in p.pipfile["packages"]
@pytest.mark.install
@pytest.mark.uninstall
def test_uninstall_all_dev(pipenv_instance_private_pypi):
with pipenv_instance_private_pypi() as p:
c = p.pipenv("install --dev Django==1.11.13 six")
assert c.returncode == 0
c = p.pipenv("install tablib")
assert c.returncode == 0
assert "tablib" in p.pipfile["packages"]
assert "django" in p.pipfile["dev-packages"]
assert "six" in p.pipfile["dev-packages"]
assert "tablib" in p.lockfile["default"]
assert "django" in p.lockfile["develop"]
assert "six" in p.lockfile["develop"]
c = p.pipenv('run python -c "import django"')
assert c.returncode == 0
c = p.pipenv("uninstall --all-dev")
assert c.returncode == 0
assert p.pipfile["dev-packages"] == {}
assert "django" not in p.lockfile["develop"]
assert "six" not in p.lockfile["develop"]
assert "tablib" in p.pipfile["packages"]
assert "tablib" in p.lockfile["default"]
c = p.pipenv('run python -c "import django"')
assert c.returncode > 0
c = p.pipenv('run python -c "import tablib"')
assert c.returncode == 0
@pytest.mark.uninstall
def test_normalize_name_uninstall(pipenv_instance_private_pypi):
with pipenv_instance_private_pypi() as p:
with open(p.pipfile_path, "w") as f:
contents = """
# Pre comment
[packages]
Requests = "*"
python_DateUtil = "*"
"""
f.write(contents)
c = p.pipenv("install")
assert c.returncode == 0
c = p.pipenv("uninstall python_dateutil")
assert "Requests" in p.pipfile["packages"]
assert "python_DateUtil" not in p.pipfile["packages"]
with open(p.pipfile_path) as f:
contents = f.read()
assert "# Pre comment" in contents
@pytest.mark.install
@pytest.mark.uninstall
def test_uninstall_all_dev_with_shared_dependencies(pipenv_instance_pypi):
with pipenv_instance_pypi() as p:
c = p.pipenv("install pytest==4.6.11")
assert c.returncode == 0
c = p.pipenv("install --dev six")
assert c.returncode == 0
c = p.pipenv("uninstall --all-dev")
assert c.returncode == 0
assert "six" in p.lockfile["develop"]
@pytest.mark.uninstall
def test_uninstall_missing_parameters(pipenv_instance_pypi):
with pipenv_instance_pypi() as p:
c = p.pipenv("install dataclasses-json")
assert c.returncode == 0
c = p.pipenv("uninstall")
assert c.returncode != 0
assert "No package provided!" in c.stderr