voice-dictation/tests/conftest.py

45 lines
1.3 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""Общие фикстуры 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"))