aki_prj23_transparenzregister/tests/ai/sentiment_service_test.py

79 lines
2.8 KiB
Python

"""Tests for checking Sentiment Services."""
from aki_prj23_transparenzregister.ai.sentiment_service import (
SentimentAnalysisService,
)
def test_sentiment_service_with_spacy_pos() -> None:
"""Mock testing spaCy Sentiment Service with positive sentiment."""
# Init SentimentAnalysisService with spaCy
sentiment_service = SentimentAnalysisService(use_spacy=True)
# run the test
text = "Dies ist ein großartiger Test. Ich liebe es!"
sentiment, score = sentiment_service.sentiment_spacy(text)
assert sentiment == "positive"
assert score > 0
def test_sentiment_service_with_spacy_neg() -> None:
"""Mock testing spaCy Sentiment Service with negative sentiment."""
# Init SentimentAnalysisService with spaCy
sentiment_service = SentimentAnalysisService(use_spacy=True)
# run the test
text = "Dies ist ein wirklich schrecklicher Test. Ich hasse ihn!"
sentiment, score = sentiment_service.sentiment_spacy(text)
assert sentiment == "negative"
assert score > 0
def test_sentiment_service_with_spacy_neut() -> None:
"""Mock testing spaCy Sentiment Service with neutral sentiment."""
# Init SentimentAnalysisService with spaCy
sentiment_service = SentimentAnalysisService(use_spacy=True)
# run the test
text = "Dies ist ein Test."
sentiment, score = sentiment_service.sentiment_spacy(text)
assert sentiment == "neutral"
assert score >= 0
def test_sentiment_service_with_transformer_pos() -> None:
"""Mock testing Transformer Sentiment Service with positive Sentiment."""
# Init SentimentAnalysisService with Transformer
sentiment_service = SentimentAnalysisService(use_transformer=True)
# run the test
text = "Dies ist ein großartiger Test. Ich liebe es!"
sentiment, score = sentiment_service.sentiment_transformer(text)
assert sentiment == "positive"
assert score > 0
def test_sentiment_service_with_transformer_neg() -> None:
"""Mock testing Transformer Sentiment Service with negative Sentiment."""
# Init SentimentAnalysisService with Transformer
sentiment_service = SentimentAnalysisService(use_transformer=True)
# run the test
text = "Dies ist ein wirklich schrecklicher Test. Ich hasse ihn!"
sentiment, score = sentiment_service.sentiment_transformer(text)
assert sentiment == "negative"
assert score > 0
def test_sentiment_service_with_transformer_neut() -> None:
"""Mock testing Transformer Sentiment Service with neutral Sentiment."""
# Init SentimentAnalysisService with Transformer
sentiment_service = SentimentAnalysisService(use_transformer=True)
# run the test
text = "Das ist ein Text, ohne besondere Stimmung."
sentiment, score = sentiment_service.sentiment_transformer(text)
assert sentiment == "neutral"
assert score >= 0