51 lines
1.7 KiB
Python
51 lines
1.7 KiB
Python
"""Regression tests for duplicate crisis indicators cleanup (#123)."""
|
|
|
|
import os
|
|
import re
|
|
import sys
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
from crisis.detect import detect_crisis
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
DETECT_FILE = ROOT / "crisis" / "detect.py"
|
|
|
|
|
|
class TestCrisisIndicatorDedup(unittest.TestCase):
|
|
def _extract_indicator_list(self, name: str) -> set[str]:
|
|
text = DETECT_FILE.read_text(encoding="utf-8")
|
|
match = re.search(rf"{name}\s*=\s*\[(.*?)\n\]", text, re.S)
|
|
self.assertIsNotNone(match, f"{name} list missing")
|
|
return {
|
|
line.strip().rstrip(",")
|
|
for line in match.group(1).splitlines()
|
|
if line.strip().startswith('r"')
|
|
}
|
|
|
|
def test_high_and_medium_indicator_lists_do_not_overlap(self):
|
|
high = self._extract_indicator_list("HIGH_INDICATORS")
|
|
medium = self._extract_indicator_list("MEDIUM_INDICATORS")
|
|
overlap = high & medium
|
|
self.assertEqual(set(), overlap, f"duplicate cross-tier patterns found: {sorted(overlap)}")
|
|
|
|
def test_removed_duplicates_still_classify_at_high_tier(self):
|
|
cases = {
|
|
"I feel hopeless": "HIGH",
|
|
"I feel trapped": "HIGH",
|
|
"I feel desperate": "HIGH",
|
|
"I have no future ahead": "HIGH",
|
|
"I have given up on myself": "HIGH",
|
|
}
|
|
for text, expected in cases.items():
|
|
with self.subTest(text=text):
|
|
result = detect_crisis(text)
|
|
self.assertEqual(expected, result.level)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|