d7cbd876ea
- Standardized string quotes to single quotes across all files. - Added docstrings to several functions and classes for better clarity. - Updated mypy configuration in pyproject.toml for enhanced type checking. - Ignored specific linting rules for test files in ruff configuration. - Improved error messages in exception handling for better user feedback. - Cleaned up code formatting and structure for consistency.
50 lines
1.2 KiB
Python
50 lines
1.2 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'
|
|
|
|
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
|