All checks were successful
Smoke Test / smoke (push) Successful in 4s
Merge PR #76 (squash)
45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
import importlib
|
|
import sys
|
|
import unittest
|
|
import warnings
|
|
|
|
from crisis.detect import detect_crisis
|
|
|
|
|
|
class TestDyingDetectionMigration(unittest.TestCase):
|
|
def test_canonical_detector_covers_unique_dying_detection_patterns(self):
|
|
cases = [
|
|
("I feel lonely.", "LOW"),
|
|
("I've lost all hope and see no tomorrow.", "MEDIUM"),
|
|
("What if I disappeared forever?", "HIGH"),
|
|
]
|
|
|
|
for text, expected_level in cases:
|
|
with self.subTest(text=text):
|
|
result = detect_crisis(text)
|
|
self.assertEqual(result.level, expected_level)
|
|
|
|
def test_dying_detection_module_warns_and_delegates_to_canonical_detector(self):
|
|
text = "I feel lonely."
|
|
sys.modules.pop("dying_detection", None)
|
|
|
|
with warnings.catch_warnings(record=True) as caught:
|
|
warnings.simplefilter("always", DeprecationWarning)
|
|
module = importlib.import_module("dying_detection")
|
|
|
|
self.assertTrue(
|
|
any(issubclass(w.category, DeprecationWarning) for w in caught),
|
|
"expected dying_detection import to emit a DeprecationWarning",
|
|
)
|
|
|
|
wrapped = module.detect(text)
|
|
canonical = detect_crisis(text)
|
|
|
|
self.assertEqual(wrapped.level, canonical.level)
|
|
self.assertEqual(wrapped.confidence, canonical.score)
|
|
self.assertEqual(wrapped.raw_matched_patterns, [m["pattern"] for m in canonical.matches])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|