-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_cr_nlp.py
31 lines (23 loc) · 1.05 KB
/
test_cr_nlp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import pytest
from cr_nlp import tokenize_text, analyze_sentiment, analyze_sentiment_vader, stem_words
# Assuming your_module_name is the name of the Python file containing your code.
def test_tokenize_text():
text = "Hello, world! This is a test sentence."
tokens = tokenize_text(text)
assert isinstance(tokens, list)
assert "hello" in tokens # checking tokenization lowercasing in 'bert-base-uncased'
def test_analyze_sentiment():
sentence = "I love this product!"
result = analyze_sentiment(sentence)
assert isinstance(result, dict)
assert 'label' in result
assert result['label'] in ['POSITIVE', 'NEGATIVE']
def test_analyze_sentiment_vader():
text = "I really hate this weather!"
result = analyze_sentiment_vader(text)
assert isinstance(result, dict)
assert 'neg' in result and result['neg'] > 0 # Expecting a negative sentiment
def test_stem_words():
words = ["running", "jumps", "easily"]
stemmed_words = stem_words(words)
assert stemmed_words == ['run', 'jump', 'easili'] # Expected stemmed forms