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