56 lines
2.1 KiB
Python
56 lines
2.1 KiB
Python
"""Statistics preserve unknown legacy values and literal file paths."""
|
||
|
||
from datetime import UTC, datetime
|
||
from decimal import Decimal
|
||
from pathlib import Path
|
||
from unittest.mock import Mock
|
||
|
||
import pytest
|
||
|
||
from voice_dictation.core.models import UsageRecord
|
||
from voice_dictation.ui import stats_helpers
|
||
|
||
|
||
def test_legacy_processing_is_unknown() -> None:
|
||
record = UsageRecord(None, datetime.now(UTC), 12.5, Decimal("0.1"), "model", "line1\nline2")
|
||
values = stats_helpers.record_values(record, UTC)
|
||
assert values[2:] == ("12.5 с", "—", "$0.1000", "line1 line2")
|
||
|
||
|
||
def test_zero_processing_is_known() -> None:
|
||
record = UsageRecord(
|
||
None, datetime.now(UTC), 1, Decimal(0), "local:model", "", processing_sec=0
|
||
)
|
||
assert stats_helpers.record_values(record, UTC)[3] == "0.0 с"
|
||
|
||
|
||
@pytest.mark.parametrize("platform, command", [("darwin", "open"), ("linux", "xdg-open")])
|
||
def test_directory_open_uses_literal_argument(
|
||
monkeypatch: pytest.MonkeyPatch, platform: str, command: str
|
||
) -> None:
|
||
launch = Mock()
|
||
monkeypatch.setattr(stats_helpers.sys, "platform", platform)
|
||
monkeypatch.setattr(stats_helpers.subprocess, "Popen", launch)
|
||
directory = Path("/tmp/audio folder;literal")
|
||
stats_helpers.open_directory(directory)
|
||
launch.assert_called_once_with([command, str(directory)])
|
||
|
||
|
||
def test_copy_uses_native_persistent_clipboard(monkeypatch: pytest.MonkeyPatch) -> None:
|
||
from voice_dictation.platform.macos.clipboard import MacClipboard
|
||
|
||
copy = Mock()
|
||
monkeypatch.setattr(stats_helpers.sys, "platform", "darwin")
|
||
monkeypatch.setattr(MacClipboard, "copy", copy)
|
||
stats_helpers.copy_saved_text("Полный текст")
|
||
copy.assert_called_once_with("Полный текст")
|
||
|
||
|
||
def test_cached_exchange_rate_never_fetches(monkeypatch: pytest.MonkeyPatch) -> None:
|
||
from voice_dictation.core import fx
|
||
|
||
request = Mock(side_effect=AssertionError("No network"))
|
||
monkeypatch.setattr(fx.httpx, "get", request)
|
||
monkeypatch.setattr(fx._singleton, "_rate", Decimal("90.50"))
|
||
assert fx.get_cached_rate() == Decimal("90.50")
|
||
request.assert_not_called()
|