Files
yt-shorts-downloader/tests/test_cli.py
T

44 lines
1.1 KiB
Python

from __future__ import annotations
from pathlib import Path
import pytest
from yt_shorts_downloader import cli
from yt_shorts_downloader.exceptions import InvalidSessionError
def test_cli_prints_downloaded_path(
monkeypatch: pytest.MonkeyPatch,
capsys: pytest.CaptureFixture[str],
tmp_path: Path,
) -> None:
expected_path = tmp_path / "video.mp4"
monkeypatch.setattr(cli, "download", lambda **kwargs: expected_path)
exit_code = cli.main(
[
"https://youtube.com/shorts/example",
"cookies.txt",
"--output-dir",
str(tmp_path),
]
)
captured = capsys.readouterr()
assert exit_code == 0
assert captured.out.strip() == str(expected_path)
def test_cli_exits_with_error(monkeypatch: pytest.MonkeyPatch) -> None:
def raise_error(**kwargs: object) -> Path:
raise InvalidSessionError("session error")
monkeypatch.setattr(cli, "download", raise_error)
with pytest.raises(SystemExit) as exc_info:
cli.main(["https://youtube.com/shorts/example", "cookies.txt"])
assert exc_info.value.code == 1