Skip to content

Commit

Permalink
Automatically find latest version of pip for assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
jcuquemelle committed Sep 4, 2024
1 parent 56cd090 commit e6b0f73
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion tests/test_uploader.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import re
import subprocess
import sys
import contextlib
import json
Expand Down Expand Up @@ -441,6 +443,19 @@ def test__unique_filename(spec_file, expected):
assert expected == uploader._unique_filename(spec_file, packaging.PEX_PACKER)


def get_latest_pip_version() -> str:
p = subprocess.Popen("pip index versions pip", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
for line in p.stdout.readlines():
result = re.match(r"pip \((.+)\)", line.decode("utf-8"))
if result:
return result.group(1)
return None


def test_lateste_pip():
assert get_latest_pip_version() is not None


def test_format_pex_requirements():
with tempfile.TemporaryDirectory() as tempdir:
requirements = ["pipdeptree==2.0.0", "six==1.15.0"]
Expand All @@ -451,7 +466,8 @@ def test_format_pex_requirements():
pex_inherit_path="false")
pex_info = PexInfo.from_pex(f"{tempdir}/out.pex")
cleaned_requirements = uploader._format_pex_requirements(pex_info)
assert ['pip==24.2', 'pipdeptree==2.0.0', 'six==1.15.0'] == cleaned_requirements
assert [f'pip=={get_latest_pip_version()}',
'pipdeptree==2.0.0', 'six==1.15.0'] == cleaned_requirements


@pytest.mark.parametrize("req, expected", [
Expand Down

0 comments on commit e6b0f73

Please sign in to comment.