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' def fake_download_to_path(**kwargs: object) -> Path: del kwargs return expected_path monkeypatch.setattr(cli, 'download_to_path', fake_download_to_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: del kwargs raise InvalidSessionError('session error') monkeypatch.setattr(cli, 'download_to_path', raise_error) with pytest.raises(SystemExit) as exc_info: cli.main(['https://youtube.com/shorts/example', 'cookies.txt']) assert exc_info.value.code == 1