mirror of
https://github.com/fhswf/aki_prj23_transparenzregister.git
synced 2025-06-21 23:23:55 +02:00
Moved the AI tests into the AI folder. (#315)
This commit is contained in:
78
tests/ai/sentiment_service_test.py
Normal file
78
tests/ai/sentiment_service_test.py
Normal file
@ -0,0 +1,78 @@
|
||||
"""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
|
Reference in New Issue
Block a user