Запрос на слияние 'task' (#1) из task в master
This commit is contained in:
1 parent
3c4e8e6cee
commit
e3f6084527
19 files changed
+725
-115
No files matched your search
@@ -0,0 +1,105 @@
|
||||
"""Юнит-тесты для препроцессоров текста."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from src.prepare.base_prepare import PreProcessor
|
||||
from src.prepare.min_words import DEFAULT_MIN_WORDS, MinWordsPreProcessor
|
||||
|
||||
# --- PreProcessor ABC ---
|
||||
|
||||
|
||||
def test_preprocessor_is_abstract():
|
||||
with pytest.raises(TypeError):
|
||||
PreProcessor() # type: ignore[abstract]
|
||||
|
||||
|
||||
# --- MinWordsPreProcessor ---
|
||||
|
||||
|
||||
async def test_min_words_passes_long_enough_text():
|
||||
processor = MinWordsPreProcessor(min_words=20)
|
||||
text = " ".join(f"word{i}" for i in range(20))
|
||||
|
||||
result = await processor.prepare(text, {})
|
||||
|
||||
assert result == text
|
||||
|
||||
|
||||
async def test_min_words_skips_empty_text():
|
||||
processor = MinWordsPreProcessor()
|
||||
|
||||
result = await processor.prepare("", {})
|
||||
|
||||
assert result is None
|
||||
|
||||
|
||||
async def test_min_words_skips_whitespace_only():
|
||||
processor = MinWordsPreProcessor()
|
||||
|
||||
result = await processor.prepare(" \n\t ", {})
|
||||
|
||||
assert result is None
|
||||
|
||||
|
||||
async def test_min_words_skips_short_text():
|
||||
processor = MinWordsPreProcessor(min_words=20)
|
||||
text = "one two three four five"
|
||||
|
||||
result = await processor.prepare(text, {})
|
||||
|
||||
assert result is None
|
||||
|
||||
|
||||
async def test_min_words_boundary_exact_min():
|
||||
processor = MinWordsPreProcessor(min_words=20)
|
||||
text = " ".join(f"word{i}" for i in range(20))
|
||||
|
||||
result = await processor.prepare(text, {})
|
||||
|
||||
assert result == text
|
||||
|
||||
|
||||
async def test_min_words_boundary_one_less():
|
||||
processor = MinWordsPreProcessor(min_words=20)
|
||||
text = " ".join(f"word{i}" for i in range(19))
|
||||
|
||||
result = await processor.prepare(text, {})
|
||||
|
||||
assert result is None
|
||||
|
||||
|
||||
async def test_min_words_default_min_words():
|
||||
processor = MinWordsPreProcessor()
|
||||
text = " ".join(f"word{i}" for i in range(DEFAULT_MIN_WORDS))
|
||||
|
||||
result = await processor.prepare(text, {})
|
||||
|
||||
assert result == text
|
||||
|
||||
|
||||
async def test_min_words_custom_threshold():
|
||||
processor = MinWordsPreProcessor(min_words=3)
|
||||
|
||||
assert await processor.prepare("a b c", {}) == "a b c"
|
||||
assert await processor.prepare("a b", {}) is None
|
||||
|
||||
|
||||
async def test_min_words_ignores_metadata():
|
||||
processor = MinWordsPreProcessor(min_words=5)
|
||||
text = "one two three four five"
|
||||
|
||||
result = await processor.prepare(text, {"source": "kafka", "document_id": "doc-1"})
|
||||
|
||||
assert result == text
|
||||
|
||||
|
||||
def test_min_words_invalid_threshold_zero():
|
||||
with pytest.raises(ValueError, match="min_words должен быть положительным"):
|
||||
MinWordsPreProcessor(min_words=0)
|
||||
|
||||
|
||||
def test_min_words_invalid_threshold_negative():
|
||||
with pytest.raises(ValueError, match="min_words должен быть положительным"):
|
||||
MinWordsPreProcessor(min_words=-1)
|
||||
Reference in new issue
Block a user