1+ import pytest
2+ from unittest .mock import patch
3+ from codecov .sentiment import SentimentAnalyzer
4+
5+
6+ @pytest .fixture
7+ def sentiment_analyzer ():
8+ return SentimentAnalyzer ()
9+
10+
11+ @patch ('codecov.sentiment.TextBlob' )
12+ def test_get_sentiment_positive (mock_textblob , sentiment_analyzer ):
13+ mock_textblob .return_value .sentiment .polarity = 0.5
14+ assert sentiment_analyzer .get_sentiment ("Great job!" ) == "positive"
15+
16+
17+ @patch ('codecov.sentiment.TextBlob' )
18+ def test_get_sentiment_negative (mock_textblob , sentiment_analyzer ):
19+ mock_textblob .return_value .sentiment .polarity = - 0.5
20+ assert sentiment_analyzer .get_sentiment ("Terrible experience." ) == "negative"
21+
22+
23+ @patch ('codecov.sentiment.TextBlob' )
24+ def test_get_sentiment_neutral (mock_textblob , sentiment_analyzer ):
25+ mock_textblob .return_value .sentiment .polarity = 0.0
26+ assert sentiment_analyzer .get_sentiment ("This is a neutral statement." ) == "neutral"
27+
28+
29+ @patch ('codecov.sentiment.TextBlob' )
30+ def test_get_polarity_score (mock_textblob , sentiment_analyzer ):
31+ mock_textblob .return_value .sentiment .polarity = 0.75
32+ assert sentiment_analyzer .get_polarity_score ("Excellent work!" ) == 0.75
33+
34+
35+ @patch ('codecov.sentiment.TextBlob' )
36+ def test_get_subjectivity_score (mock_textblob , sentiment_analyzer ):
37+ mock_textblob .return_value .sentiment .subjectivity = 0.6
38+ assert sentiment_analyzer .get_subjectivity_score ("I think this is amazing!" ) == 0.6
39+
40+
41+ @patch ('codecov.sentiment.TextBlob' )
42+ def test_is_neutral_true (mock_textblob , sentiment_analyzer ):
43+ mock_textblob .return_value .sentiment .polarity = 0.0
44+ assert sentiment_analyzer .is_neutral ("This is a fact." ) == True
45+
46+
47+ @patch ('codecov.sentiment.TextBlob' )
48+ def test_is_neutral_false (mock_textblob , sentiment_analyzer ):
49+ mock_textblob .return_value .sentiment .polarity = 0.5
50+ assert sentiment_analyzer .is_neutral ("This is great!" ) == False
51+
52+
53+ @patch ('codecov.sentiment.TextBlob' )
54+ def test_is_positive_true (mock_textblob , sentiment_analyzer ):
55+ mock_textblob .return_value .sentiment .polarity = 0.5
56+ assert sentiment_analyzer .is_positive ("This is wonderful!" ) == True
57+
58+
59+ @patch ('codecov.sentiment.TextBlob' )
60+ def test_is_positive_false (mock_textblob , sentiment_analyzer ):
61+ mock_textblob .return_value .sentiment .polarity = - 0.5
62+ assert sentiment_analyzer .is_positive ("This is awful." ) == False
63+
64+
65+ @patch ('codecov.sentiment.TextBlob' )
66+ def test_private_get_polarity (mock_textblob , sentiment_analyzer ):
67+ mock_textblob .return_value .sentiment .polarity = 0.8
68+ assert sentiment_analyzer ._get_polarity ("Amazing!" ) == 0.8
69+
70+
71+ @patch ('codecov.sentiment.TextBlob' )
72+ def test_private_get_subjectivity (mock_textblob , sentiment_analyzer ):
73+ mock_textblob .return_value .sentiment .subjectivity = 0.9
74+ assert sentiment_analyzer ._get_subjectivity ("I absolutely love this!" ) == 0.9
0 commit comments