Skip to content

Commit

Permalink
✅ Add test for get_package_report in cli
Browse files Browse the repository at this point in the history
  • Loading branch information
ddelange committed Aug 9, 2023
1 parent cc4f9d5 commit 7f2edf5
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pipgrip.pipper
from pipgrip.cli import flatten, main
from pipgrip.pipper import PIP_VERSION, _download_wheel
from pipgrip.pipper import PIP_VERSION, _download_wheel, _extract_metadata

self_wheel = _download_wheel(".", None, None, None, "./tests/assets")

Expand Down Expand Up @@ -56,6 +56,13 @@ def mock_download_wheel(package, *args, **kwargs):
return wheelhouse[package]


def mock_get_package_report(package, *args, **kwargs):
wheel_fname = mock_download_wheel(package)
wheel_metadata = _extract_metadata(wheel_fname)
report = {"install": [{"metadata": wheel_metadata}]}
return report


def mock_get_available_versions(package, *args, **kwargs):
versions = {
"setuptools": ["44.0.0"],
Expand Down Expand Up @@ -93,7 +100,7 @@ def mock_stream_bash_command(*args, **kwargs):
return "I passed"


def invoke_patched(func, arguments, monkeypatch, **kwargs):
def invoke_patched(func, arguments, monkeypatch, use_report=False, **kwargs):
def default_environment():
return {
"implementation_name": "cpython",
Expand All @@ -116,9 +123,21 @@ def default_environment():
)
monkeypatch.setattr(
pipgrip.pipper,
"PIP_VERSION",
[22, 0], # to circumvent _get_package_report
"_get_package_report",
mock_get_package_report,
)
if use_report:
monkeypatch.setattr(
pipgrip.pipper,
"PIP_VERSION",
[22, 2],
)
else:
monkeypatch.setattr(
pipgrip.pipper,
"PIP_VERSION",
[22, 1], # to circumvent _get_package_report
)
monkeypatch.setattr(
pipgrip.pipper,
"_get_available_versions",
Expand Down Expand Up @@ -358,6 +377,14 @@ def test_solutions(arguments, expected, monkeypatch):
expected
), "Unexpected output:\n{}".format(result.output.strip())

result = invoke_patched(main, arguments, monkeypatch, use_report=True)

if result.exit_code:
raise result.exception
assert set(result.output.strip().split("\n")) == set(
expected
), "Unexpected output:\n{}".format(result.output.strip())


@pytest.mark.parametrize(
"arguments",
Expand Down

0 comments on commit 7f2edf5

Please sign in to comment.