fix desktop version
This commit is contained in:
45
ai-moderation/tests/test_profanity.py
Normal file
45
ai-moderation/tests/test_profanity.py
Normal file
@@ -0,0 +1,45 @@
|
||||
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
|
||||
Reference in New Issue
Block a user