Spaces:
Sleeping
Sleeping
| import pytest | |
| from app.services.emotion import EmotionService | |
| def emotion_service(): | |
| return EmotionService() | |
| async def test_positive_sentiment(emotion_service): | |
| text = "I am so happy and blessed today" | |
| result = await emotion_service.analyze_tone(text) | |
| assert result["sentiment"] == "positive" | |
| assert result["pos_count"] >= 2 | |
| assert result["neg_count"] == 0 | |
| async def test_negative_sentiment(emotion_service): | |
| text = "I am sad and angry about this" | |
| result = await emotion_service.analyze_tone(text) | |
| assert result["sentiment"] == "negative" | |
| assert result["neg_count"] >= 2 | |
| async def test_neutral_sentiment(emotion_service): | |
| text = "I walked to the store" | |
| result = await emotion_service.analyze_tone(text) | |
| assert result["sentiment"] == "neutral" | |
| async def test_distress_detection_keywords(emotion_service): | |
| text = "I feel hopeless and want to end it all" | |
| analysis = await emotion_service.analyze_tone(text) | |
| is_distress = emotion_service.is_distress_high(text, analysis) | |
| assert is_distress is True | |
| async def test_distress_detection_intensity(emotion_service): | |
| # A sentence with almost entirely negative words to trigger high intensity | |
| text = "pain grief suffering hurt broken sad depressed" | |
| analysis = await emotion_service.analyze_tone(text) | |
| assert analysis["intensity"] > 0.8 | |
| is_distress = emotion_service.is_distress_high(text, analysis) | |
| assert is_distress is True | |