41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
from __future__ import annotations
|
||
|
||
import re
|
||
|
||
_NEGATIVE_TEST_RE = re.compile(r"\b(?:не|без|кроме)\b[^.?!]{0,28}\bтест", re.IGNORECASE)
|
||
_NEGATIVE_TEST_MARKERS = ("не про тест", "без тест", "кроме тест", "про прод код", "только прод", "production code")
|
||
_POSITIVE_TEST_MARKERS = (
|
||
"тест",
|
||
"tests",
|
||
"pytest",
|
||
"unit test",
|
||
"unit tests",
|
||
"тестиру",
|
||
)
|
||
_TEST_TERMS = {"тест", "тесты", "test", "tests", "pytest", "unit", "unit test", "юнит-тест", "юниттест"}
|
||
|
||
|
||
def is_negative_test_request(text: str) -> bool:
|
||
lowered = (text or "").lower()
|
||
if _NEGATIVE_TEST_RE.search(lowered):
|
||
return True
|
||
return any(marker in lowered for marker in _NEGATIVE_TEST_MARKERS)
|
||
|
||
|
||
def has_test_focus(text: str) -> bool:
|
||
lowered = (text or "").lower()
|
||
if is_negative_test_request(lowered):
|
||
return False
|
||
return any(marker in lowered for marker in _POSITIVE_TEST_MARKERS)
|
||
|
||
|
||
def is_test_related_token(value: str) -> bool:
|
||
lowered = (value or "").lower().strip()
|
||
if not lowered:
|
||
return False
|
||
if lowered in _TEST_TERMS:
|
||
return True
|
||
if lowered.startswith("test"):
|
||
return True
|
||
return lowered.startswith("тест")
|