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

Convert this test off pip-shims, it became flakey recently. #5226

Merged
merged 2 commits into from
Aug 6, 2022
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions news/5226.trivial.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Modernize the test ``test_convert_deps_to_pip`` to not use ``pip-shims`` and the code it calls to not use ``vistir``.
5 changes: 2 additions & 3 deletions pipenv/utils/dependencies.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
from contextlib import contextmanager
from tempfile import NamedTemporaryFile
from typing import Mapping, Sequence

from pipenv.patched.pip._vendor.packaging.markers import Marker
Expand Down Expand Up @@ -273,9 +274,7 @@ def convert_deps_to_pip(
return dependencies

# Write requirements.txt to tmp directory.
from pipenv.vendor.vistir.path import create_tracked_tempfile

f = create_tracked_tempfile(suffix="-requirements.txt", delete=False)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You always get bonus points for removing usage of vistir :-)

f = NamedTemporaryFile(suffix="-requirements.txt", delete=False)
f.write("\n".join(dependencies).encode("utf-8"))
f.close()
return f.name
Expand Down
21 changes: 6 additions & 15 deletions tests/unit/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from unittest import mock

import pytest

Expand Down Expand Up @@ -83,13 +84,11 @@ def mock_unpack(link, source_dir, download_dir, only_download=False, session=Non
@pytest.mark.utils
@pytest.mark.parametrize("deps, expected", DEP_PIP_PAIRS)
@pytest.mark.needs_internet
def test_convert_deps_to_pip(monkeypatch, deps, expected):
with monkeypatch.context() as m:
from pipenv.vendor import pip_shims
m.setattr(pip_shims.shims, "unpack_url", mock_unpack)
if expected.startswith("Django"):
expected = expected.lower()
assert dependencies.convert_deps_to_pip(deps, r=False) == [expected]
@mock.patch("pipenv.patched.pip._internal.operations.prepare.unpack_url", mock_unpack)
def test_convert_deps_to_pip(deps, expected):
if expected.startswith("Django"):
expected = expected.lower()
assert dependencies.convert_deps_to_pip(deps, r=False) == [expected]


@pytest.mark.utils
Expand Down Expand Up @@ -134,14 +133,6 @@ def test_convert_deps_to_pip_one_way(deps, expected):
assert dependencies.convert_deps_to_pip(deps, r=False) == [expected.lower()]


@pytest.mark.skipif(isinstance("", str), reason="don't need to test if unicode is str")
@pytest.mark.utils
def test_convert_deps_to_pip_unicode():
deps = {"django": "==1.10"}
deps = dependencies.convert_deps_to_pip(deps, r=False)
assert deps[0] == "django==1.10"


@pytest.mark.parametrize("line,result", [
("-i https://example.com/simple/", ("https://example.com/simple/", None, None, [])),
("--extra-index-url=https://example.com/simple/", (None, "https://example.com/simple/", None, [])),
Expand Down