Files
post-moderation/ai-moderation/tests/test_profanity.py
2026-10-23 00:12:34 +03:00

46 lines
1.6 KiB
Python
Raw 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.

import time
import pytest
from app.core.dependencies import get_profanity_detector
@pytest.fixture(scope="module")
def detector():
return get_profanity_detector()
@pytest.mark.parametrize("text", [
"Потерял кошелёк в парке, нашедшему вознаграждение",
"Найдена собака, рыжая, с ошейником",
"Потерялись ключи с брелоком, 3 шт., район 6 мкр",
"Буфера у машины помяты, опущенный козырёк",
"Lost black wallet near the station",
"",
])
def test_clean_texts(detector, text):
assert detector.detect(text) == []
@pytest.mark.parametrize("text", [
"бля",
"БЛЯ, где мой телефон",
"иди нахуй",
"6ля", # цифра вместо буквы, есть в словаре
"fuck", # транслит/латиница из словаря
"xуй", # латинская x вместо кириллической х
"бля123", # мусор после слова
"бляха-муха", # слово через дефис из словаря
"ёбаный", # ё/е
])
def test_profanity_detected(detector, text):
assert detector.detect(text), text
def test_long_text_is_fast(detector):
# Раньше каждое слово сравнивалось со всеми ~7 тыс. словами словаря
text = "обычный текст объявления о находке " * 140
start = time.perf_counter()
assert detector.detect(text[:5000]) == []
assert time.perf_counter() - start < 1.0