45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
"""Общие фикстуры pytest."""
|
||
|
||
from __future__ import annotations
|
||
|
||
import pytest
|
||
|
||
from voice_dictation.core.paths import AppPaths
|
||
|
||
|
||
@pytest.fixture()
|
||
def tmp_paths(tmp_path: pytest.TempPathFactory) -> AppPaths:
|
||
"""AppPaths с временными директориями в pytest tmp_path.
|
||
|
||
Args:
|
||
tmp_path: Встроенная фикстура pytest.
|
||
|
||
Returns:
|
||
AppPaths с путями в tmp_path.
|
||
"""
|
||
root = tmp_path # type: ignore[arg-type]
|
||
paths = AppPaths(
|
||
root=root,
|
||
config_file=root / "config.json",
|
||
usage_db=root / "usage.db",
|
||
dictionary_file=root / "dictionary.txt",
|
||
custom_sounds_dir=root / "sounds",
|
||
log_file=root / "app.log",
|
||
pid_file=root / "dictate.pid",
|
||
tmp_dir=root / "tmp",
|
||
)
|
||
paths.ensure_exists()
|
||
return paths
|
||
|
||
|
||
@pytest.fixture(autouse=True)
|
||
def offline_unit_environment(monkeypatch):
|
||
"""Unit checks never depend on exchange-rate services or network access."""
|
||
import socket
|
||
from decimal import Decimal
|
||
|
||
def reject_connection(*args, **kwargs):
|
||
raise AssertionError("Unit tests must use an explicit network fake")
|
||
|
||
monkeypatch.setattr(socket, "create_connection", reject_connection)
|
||
monkeypatch.setattr("voice_dictation.core.fx.get_rate", lambda: Decimal("100"))
|