voice-dictation/tests/unit/test_dictionary.py
Claude Zhenya b96b49f1d5 v0.2.0: режимы обработки, кастомные стили, новая иконка, прослушка звуков
- Реестр режимов постобработки вместо бинарного 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>
2026-06-23 22:48:38 +03:00

69 lines
2.8 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.

"""Тесты словаря подсказок."""
from __future__ import annotations
from voice_dictation.core.dictionary import Dictionary
from voice_dictation.core.paths import AppPaths
def test_load_empty_if_file_missing(tmp_paths: AppPaths) -> None:
"""Загрузка несуществующего файла возвращает пустой список."""
d = Dictionary(tmp_paths.dictionary_file)
assert d.load() == []
def test_load_words(tmp_paths: AppPaths) -> None:
"""Загрузка слов из файла."""
tmp_paths.dictionary_file.write_text("FastAPI\nSQLAlchemy\n")
d = Dictionary(tmp_paths.dictionary_file)
assert d.load() == ["FastAPI", "SQLAlchemy"]
def test_load_ignores_comments(tmp_paths: AppPaths) -> None:
"""Строки с # игнорируются."""
tmp_paths.dictionary_file.write_text("# Комментарий\nFastAPI\n# Ещё один\nPydantic\n")
d = Dictionary(tmp_paths.dictionary_file)
assert d.load() == ["FastAPI", "Pydantic"]
def test_load_ignores_empty_lines(tmp_paths: AppPaths) -> None:
"""Пустые строки игнорируются."""
tmp_paths.dictionary_file.write_text("FastAPI\n\n\nPydantic\n")
d = Dictionary(tmp_paths.dictionary_file)
assert d.load() == ["FastAPI", "Pydantic"]
def test_build_prompt_empty_dict(tmp_paths: AppPaths) -> None:
"""Пустой словарь → пустая строка prompt."""
d = Dictionary(tmp_paths.dictionary_file)
assert d.build_prompt() == ""
def test_build_prompt_basic(tmp_paths: AppPaths) -> None:
"""Базовая сборка prompt из слов."""
tmp_paths.dictionary_file.write_text("FastAPI\nPydantic\n")
d = Dictionary(tmp_paths.dictionary_file)
prompt = d.build_prompt()
assert "FastAPI" in prompt
assert "Pydantic" in prompt
def test_build_prompt_respects_limit(tmp_paths: AppPaths) -> None:
"""build_prompt не превышает max_chars."""
# Создаём словарь с многими длинными словами
words = [f"LongTechnicalTermNumber{i:03d}" for i in range(100)]
tmp_paths.dictionary_file.write_text("\n".join(words))
d = Dictionary(tmp_paths.dictionary_file)
prompt = d.build_prompt(max_chars=100)
assert len(prompt) <= 100
def test_build_prompt_takes_from_end(tmp_paths: AppPaths) -> None:
"""При переполнении берутся слова с конца (более специфичные)."""
# Создаём файл где последнее слово точно влезет
tmp_paths.dictionary_file.write_text(
"a" * 90 + "\nLastWord\n" # первое слово не влезет в 50 символов
)
d = Dictionary(tmp_paths.dictionary_file)
prompt = d.build_prompt(max_chars=50)
assert "LastWord" in prompt