File size: 1,583 Bytes
5e0532d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import pytest
from app.services.emotion import EmotionService

@pytest.fixture
def emotion_service():
    return EmotionService()

@pytest.mark.asyncio
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

@pytest.mark.asyncio
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

@pytest.mark.asyncio
async def test_neutral_sentiment(emotion_service):
    text = "I walked to the store"
    result = await emotion_service.analyze_tone(text)
    assert result["sentiment"] == "neutral"

@pytest.mark.asyncio
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

@pytest.mark.asyncio
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