Добавить основную функциональность загрузки YouTube Shorts с использованием файла сессии и обработкой ошибок
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from yt_shorts_downloader import runtime
|
||||
|
||||
|
||||
def test_find_supported_js_runtimes_prefers_deno(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
monkeypatch.setattr(
|
||||
runtime,
|
||||
"which",
|
||||
lambda executable: "/usr/bin/deno" if executable == "deno" else None,
|
||||
)
|
||||
|
||||
runtimes = runtime.find_supported_js_runtimes()
|
||||
|
||||
assert runtimes == {"deno": {"path": "/usr/bin/deno"}}
|
||||
|
||||
|
||||
def test_find_supported_js_runtimes_uses_best_supported_node(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
first_node = tmp_path / ".nvm" / "versions" / "node" / "v22.1.0" / "bin" / "node"
|
||||
second_node = tmp_path / ".nvm" / "versions" / "node" / "v22.9.0" / "bin" / "node"
|
||||
second_node.parent.mkdir(parents=True)
|
||||
first_node.parent.mkdir(parents=True)
|
||||
first_node.write_text("", encoding="utf-8")
|
||||
second_node.write_text("", encoding="utf-8")
|
||||
|
||||
monkeypatch.setattr(runtime, "which", lambda executable: None)
|
||||
monkeypatch.setattr(Path, "home", lambda: tmp_path)
|
||||
monkeypatch.setattr(
|
||||
runtime,
|
||||
"_probe_executable_version",
|
||||
lambda executable: (22, 9, 0)
|
||||
if executable.endswith("v22.9.0/bin/node")
|
||||
else (22, 1, 0),
|
||||
)
|
||||
|
||||
runtimes = runtime.find_supported_js_runtimes()
|
||||
|
||||
assert runtimes == {"node": {"path": str(second_node.resolve())}}
|
||||
|
||||
|
||||
def test_parse_semver_handles_prefixed_versions() -> None:
|
||||
assert runtime._parse_semver("v22.12.1") == (22, 12, 1)
|
||||
assert runtime._parse_semver("node") is None
|
||||
Reference in New Issue
Block a user