Add CLI and bin entrypoint: quiet runs, refusals on stderr
This commit is contained in:
+7
-20
@@ -1,6 +1,5 @@
|
||||
"""Tests for installing runtime packages via pipenv."""
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
@@ -8,32 +7,20 @@ import pytest
|
||||
from new_python.scaffold import ScaffoldError, install_packages
|
||||
|
||||
|
||||
def _pipenv_stub(monkeypatch, tmp_path: Path, exit_code: int) -> Path:
|
||||
"""Put a fake pipenv on PATH that records args and exits *exit_code*."""
|
||||
bin_dir = tmp_path / "bin"
|
||||
bin_dir.mkdir()
|
||||
record = tmp_path / "pipenv-args.txt"
|
||||
stub = bin_dir / "pipenv"
|
||||
stub.write_text(f'#!/bin/sh\nprintf "%s\\n" "$@" > "{record}"\nexit {exit_code}\n')
|
||||
stub.chmod(0o755)
|
||||
monkeypatch.setenv("PATH", f"{bin_dir}:{os.environ['PATH']}")
|
||||
return record
|
||||
|
||||
|
||||
def test_install_packages_invokes_pipenv_install(monkeypatch, tmp_path: Path):
|
||||
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 = _pipenv_stub(monkeypatch, tmp_path, exit_code=0)
|
||||
record = stub_cmd("pipenv")
|
||||
project = tmp_path / "demo-project"
|
||||
project.mkdir()
|
||||
|
||||
install_packages(["mutagen", "requests"], project)
|
||||
|
||||
assert record.read_text().splitlines() == ["install", "mutagen", "requests"]
|
||||
assert calls(record) == [["install", "mutagen", "requests"]]
|
||||
|
||||
|
||||
def test_install_packages_skips_invocation_when_empty(monkeypatch, tmp_path: Path):
|
||||
def test_install_packages_skips_invocation_when_empty(stub_cmd, tmp_path: Path):
|
||||
"""An empty package list never invokes pipenv."""
|
||||
record = _pipenv_stub(monkeypatch, tmp_path, exit_code=0)
|
||||
record = stub_cmd("pipenv")
|
||||
project = tmp_path / "demo-project"
|
||||
project.mkdir()
|
||||
|
||||
@@ -42,9 +29,9 @@ def test_install_packages_skips_invocation_when_empty(monkeypatch, tmp_path: Pat
|
||||
assert not record.exists()
|
||||
|
||||
|
||||
def test_install_packages_wraps_pipenv_failure(monkeypatch, tmp_path: Path):
|
||||
def test_install_packages_wraps_pipenv_failure(stub_cmd, tmp_path: Path):
|
||||
"""A failing pipenv refuses as ScaffoldError naming the command."""
|
||||
_pipenv_stub(monkeypatch, tmp_path, exit_code=1)
|
||||
stub_cmd("pipenv", exit_code=1)
|
||||
project = tmp_path / "demo-project"
|
||||
project.mkdir()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user