-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for sentiment.py (#25)
- Add `add_sentiment_to_dataframe` method to SentimentAnalysis class - Remove unused 'get_sentiment_multiple' method, which assumed an outdated comment data format - Add fixture for creating a comment data frame - Add tests for sentiment.py - Modify workflow to install requirements.txt in src/ directory - Install required `nltk` packages - Suppress noisy output from `nltk.download()`
- Loading branch information
1 parent
f2a7d91
commit 034e291
Showing
5 changed files
with
86 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
""" | ||
Tests for the SentimentAnalysis class. | ||
""" | ||
import pytest | ||
|
||
# Astro modules | ||
from src.data_collection.sentiment import SentimentAnalysis | ||
|
||
positive_string = 'This is amazing!' | ||
negative_string = 'This is terrible!' | ||
neutral_string = 'The color is blue' | ||
nonsense_string = 'asdf gra asdg vrs sdg' | ||
empty_string = '' | ||
|
||
|
||
def verify_sentiment(sentiment): | ||
assert sentiment <= 1.0 and sentiment >= 0.0 | ||
|
||
|
||
class TestSentimentAnalysis: | ||
|
||
def test_add_sentiment_to_dataframe(self, logger, comment_dataframe): | ||
sa = SentimentAnalysis(logger) | ||
|
||
sa.add_sentiment_to_dataframe(comment_dataframe) | ||
|
||
for index, row in comment_dataframe.iterrows(): | ||
verify_sentiment(row['PSentiment']) | ||
verify_sentiment(row['NSentiment']) | ||
|
||
@pytest.mark.parametrize('text', | ||
[positive_string, | ||
negative_string, | ||
neutral_string, | ||
nonsense_string, | ||
empty_string]) | ||
def test_get_sentiment(self, logger, text): | ||
sa = SentimentAnalysis(logger) | ||
|
||
sentiment = sa.get_sentiment(text) | ||
|
||
# verify that some sentiment data is returned | ||
verify_sentiment(sentiment[0]) | ||
verify_sentiment(sentiment[1]) | ||
verify_sentiment(sentiment[2]) |