Files
yt-shorts-downloader/tests/test_runtime.py
T
ВяткинАртём d7cbd876ea
CI / Quality Checks (push) Failing after 12s
CI / Test Suite (push) Successful in 10s
Refactor code style and improve documentation
- 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.
2026-05-27 17:24:30 +03:00

54 lines
1.6 KiB
Python

from __future__ import annotations
from pathlib import Path
import pytest
from yt_shorts_downloader.core 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')
def fake_which(_executable: str) -> None:
return None
monkeypatch.setattr(runtime, 'which', fake_which)
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