Refactor code style and improve documentation
CI / Quality Checks (push) Failing after 12s
CI / Test Suite (push) Successful in 10s

- 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.
This commit is contained in:
ВяткинАртём
2026-05-27 17:24:30 +03:00
parent 1c3228e039
commit d7cbd876ea
23 changed files with 214 additions and 203 deletions
+19 -21
View File
@@ -14,50 +14,48 @@ def _build_valid_session_validation(path: Path) -> SessionValidation:
def test_download_returns_binary_mp4(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
expected_content = b"mp4-binary-content"
expected_content = b'mp4-binary-content'
def fake_validate_session_file(path: Path) -> SessionValidation:
return _build_valid_session_validation(path)
def fake_download_video(*, url: str, output_dir: Path, session_path: Path) -> Path:
del url, session_path
downloaded_file = output_dir / "video.mp4"
downloaded_file = output_dir / 'video.mp4'
downloaded_file.write_bytes(expected_content)
return downloaded_file
monkeypatch.setattr(api, "validate_session_file", fake_validate_session_file)
monkeypatch.setattr(api, "download_video", fake_download_video)
monkeypatch.setattr(api, 'validate_session_file', fake_validate_session_file)
monkeypatch.setattr(api, 'download_video', fake_download_video)
downloaded_video = api.download(
"https://youtube.com/shorts/example",
session_path="cookies.txt",
'https://youtube.com/shorts/example',
session_path='cookies.txt',
)
assert downloaded_video == DownloadedVideo(
filename="video.mp4",
filename='video.mp4',
content=expected_content,
)
def test_download_to_path_returns_path_from_downloader(
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
) -> None:
expected_path = tmp_path / "video.mp4"
def test_download_to_path_returns_path_from_downloader(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
expected_path = tmp_path / 'video.mp4'
def fake_validate_session_file(path: Path) -> SessionValidation:
return _build_valid_session_validation(path)
def fake_download_video(*, url: str, output_dir: Path, session_path: Path) -> Path:
del url, session_path
expected_path.write_bytes(b"mp4")
expected_path.write_bytes(b'mp4')
return output_dir / expected_path.name
monkeypatch.setattr(api, "validate_session_file", fake_validate_session_file)
monkeypatch.setattr(api, "download_video", fake_download_video)
monkeypatch.setattr(api, 'validate_session_file', fake_validate_session_file)
monkeypatch.setattr(api, 'download_video', fake_download_video)
downloaded_path = api.download_to_path(
"https://youtube.com/shorts/example",
session_path="cookies.txt",
'https://youtube.com/shorts/example',
session_path='cookies.txt',
output_dir=tmp_path,
)
@@ -66,15 +64,15 @@ def test_download_to_path_returns_path_from_downloader(
def test_download_rejects_invalid_url() -> None:
with pytest.raises(InvalidUrlError):
api.download("https://example.com/watch?v=1", session_path="cookies.txt")
api.download('https://example.com/watch?v=1', session_path='cookies.txt')
def test_download_rejects_invalid_session(monkeypatch: pytest.MonkeyPatch) -> None:
def fake_validate_session_file(path: Path) -> SessionValidation:
del path
return SessionValidation(False, False, False, False, "bad session")
return SessionValidation(False, False, False, False, 'bad session')
monkeypatch.setattr(api, "validate_session_file", fake_validate_session_file)
monkeypatch.setattr(api, 'validate_session_file', fake_validate_session_file)
with pytest.raises(InvalidSessionError, match="bad session"):
api.download("https://youtube.com/shorts/example", session_path="cookies.txt")
with pytest.raises(InvalidSessionError, match='bad session'):
api.download('https://youtube.com/shorts/example', session_path='cookies.txt')