2023-07-15 15:16:38 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
import sys
|
2024-06-17 19:44:58 +00:00
|
|
|
from subprocess import CompletedProcess, check_call # noqa: S404
|
2024-04-13 15:55:38 +00:00
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
|
2024-06-17 19:44:58 +00:00
|
|
|
from pipdeptree.__main__ import main
|
|
|
|
|
2024-04-13 15:55:38 +00:00
|
|
|
if TYPE_CHECKING:
|
2024-06-17 19:44:58 +00:00
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
import pytest
|
2024-04-13 15:55:38 +00:00
|
|
|
from pytest_console_scripts import ScriptRunner
|
2024-06-17 19:44:58 +00:00
|
|
|
from pytest_mock import MockFixture
|
2023-07-15 15:16:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_main() -> None:
|
|
|
|
check_call([sys.executable, "-m", "pipdeptree", "--help"])
|
|
|
|
|
|
|
|
|
2024-04-13 15:55:38 +00:00
|
|
|
def test_console(script_runner: ScriptRunner) -> None:
|
2024-06-07 18:06:16 +00:00
|
|
|
result = script_runner.run(["pipdeptree", "--help"])
|
2024-04-13 15:55:38 +00:00
|
|
|
assert result.success
|
2024-06-17 19:44:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_main_log_resolved(tmp_path: Path, mocker: MockFixture, capsys: pytest.CaptureFixture[str]) -> None:
|
|
|
|
mocker.patch("sys.argv", ["", "--python", "auto"])
|
|
|
|
mocker.patch("pipdeptree.__main__.detect_active_interpreter", return_value=str(tmp_path))
|
|
|
|
mock_subprocess_run = mocker.patch("subprocess.run")
|
|
|
|
valid_sys_path = str([str(tmp_path)])
|
|
|
|
mock_subprocess_run.return_value = CompletedProcess(
|
|
|
|
args=["python", "-c", "import sys; print(sys.path)"],
|
|
|
|
returncode=0,
|
|
|
|
stdout=valid_sys_path,
|
|
|
|
stderr="",
|
|
|
|
)
|
|
|
|
|
|
|
|
main()
|
|
|
|
|
|
|
|
captured = capsys.readouterr()
|
|
|
|
assert captured.err.startswith(f"(resolved python: {tmp_path!s}")
|