42 lines
1.2 KiB
Python
42 lines
1.2 KiB
Python
"""Tests for installing runtime packages via pipenv."""
|
|
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from new_python.scaffold import ScaffoldError, install_packages
|
|
|
|
|
|
def test_install_packages_invokes_pipenv_install(stub_cmd, calls, tmp_path: Path):
|
|
"""Package values reach one pipenv call with the exact install arguments."""
|
|
record = stub_cmd("pipenv")
|
|
project = tmp_path / "demo-project"
|
|
project.mkdir()
|
|
|
|
install_packages(["mutagen", "requests"], project)
|
|
|
|
assert calls(record) == [["install", "mutagen", "requests"]]
|
|
|
|
|
|
def test_install_packages_skips_invocation_when_empty(stub_cmd, tmp_path: Path):
|
|
"""An empty package list never invokes pipenv."""
|
|
record = stub_cmd("pipenv")
|
|
project = tmp_path / "demo-project"
|
|
project.mkdir()
|
|
|
|
install_packages([], project)
|
|
|
|
assert not record.exists()
|
|
|
|
|
|
def test_install_packages_wraps_pipenv_failure(stub_cmd, tmp_path: Path):
|
|
"""A failing pipenv refuses as ScaffoldError naming the command."""
|
|
stub_cmd("pipenv", exit_code=1)
|
|
project = tmp_path / "demo-project"
|
|
project.mkdir()
|
|
|
|
with pytest.raises(ScaffoldError) as exc:
|
|
install_packages(["mutagen"], project)
|
|
|
|
assert "pipenv install" in str(exc.value)
|