- Реестр режимов постобработки вместо бинарного summary_mode: Чистая диктовка, Чистовик (без паразитов), Summary, Переводчик RU→EN, Промпт для LLM, Буллеты, Деловое письмо - Кастомные стили: свои промпты в настройках (таб «Стили») - Новая иконка приложения (микрофон + VД) - Прослушка звуков в настройках (кнопки ▶) - ffmpeg как опциональная докачка (кнопка в настройках), WAV-fallback без него - Версия 0.2.0 + changelog в «О программе» - Фикс: сохранение настроек через dataclasses.replace (не теряет поля) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
76 lines
2.4 KiB
Python
76 lines
2.4 KiB
Python
"""Тесты для UsageDB."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import UTC, datetime, timedelta
|
|
from decimal import Decimal
|
|
|
|
from voice_dictation.core.models import UsageRecord
|
|
from voice_dictation.core.paths import AppPaths
|
|
from voice_dictation.core.usage_db import UsageDB
|
|
|
|
|
|
def _record(when: datetime, duration: float = 5.0, cost: str = "0.001") -> UsageRecord:
|
|
return UsageRecord(
|
|
id=None,
|
|
created_at=when,
|
|
duration_sec=duration,
|
|
cost_usd=Decimal(cost),
|
|
model="gpt-4o-mini-transcribe",
|
|
text_preview="hello",
|
|
)
|
|
|
|
|
|
def test_insert_assigns_id(tmp_paths: AppPaths) -> None:
|
|
db = UsageDB(tmp_paths.usage_db)
|
|
record = db.insert(_record(datetime.now(UTC)))
|
|
assert record.id is not None
|
|
assert record.id >= 1
|
|
|
|
|
|
def test_today_total_aggregates(tmp_paths: AppPaths) -> None:
|
|
db = UsageDB(tmp_paths.usage_db)
|
|
now = datetime.now(UTC)
|
|
db.insert(_record(now, duration=10.0, cost="0.001"))
|
|
db.insert(_record(now, duration=20.0, cost="0.002"))
|
|
db.insert(_record(now - timedelta(days=2), duration=999.0, cost="0.5"))
|
|
|
|
today = db.today_total(tz=UTC)
|
|
assert today.count == 2
|
|
assert today.total_duration_sec == 30.0
|
|
assert today.total_cost_usd == Decimal("0.003000")
|
|
|
|
|
|
def test_recent_returns_newest_first(tmp_paths: AppPaths) -> None:
|
|
db = UsageDB(tmp_paths.usage_db)
|
|
base = datetime.now(UTC)
|
|
for i in range(5):
|
|
db.insert(_record(base + timedelta(seconds=i)))
|
|
|
|
recent = db.recent(limit=3)
|
|
assert len(recent) == 3
|
|
assert recent[0].id is not None
|
|
assert recent[0].id > recent[1].id > recent[2].id
|
|
|
|
|
|
def test_all_time_includes_old_records(tmp_paths: AppPaths) -> None:
|
|
db = UsageDB(tmp_paths.usage_db)
|
|
db.insert(_record(datetime.now(UTC) - timedelta(days=400), duration=60.0, cost="0.01"))
|
|
db.insert(_record(datetime.now(UTC), duration=30.0, cost="0.005"))
|
|
|
|
total = db.all_time()
|
|
assert total.count == 2
|
|
assert total.total_duration_sec == 90.0
|
|
assert total.total_cost_usd == Decimal("0.015000")
|
|
|
|
|
|
def test_month_stats_filters_correctly(tmp_paths: AppPaths) -> None:
|
|
db = UsageDB(tmp_paths.usage_db)
|
|
in_month = datetime(2026, 4, 15, 12, 0, tzinfo=UTC)
|
|
other_month = datetime(2026, 3, 15, 12, 0, tzinfo=UTC)
|
|
db.insert(_record(in_month, duration=10.0))
|
|
db.insert(_record(other_month, duration=999.0))
|
|
|
|
stats = db.month_stats(2026, 4, tz=UTC)
|
|
assert stats.count == 1
|
|
assert stats.total_duration_sec == 10.0
|