-
Notifications
You must be signed in to change notification settings - Fork 33
/
test_regression.py
33 lines (25 loc) · 1001 Bytes
/
test_regression.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
30
31
32
33
# The idea of those tests is that we have some
# results obtained from the previous runs of the classifier
# and we make sure that they do not change from time to time
import json
import unittest
from senti_classifier import senti_classifier
class RegressionTests(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.reviews_file = "reviews.json"
cls.reviews_data = cls._read_reviews_data(cls.reviews_file)
@classmethod
def _read_reviews_data(cls, reviews_file):
data = {"reviews": []}
with open(reviews_file) as f:
data = json.load(f)
return data
def test_against_data(self):
for r in self.reviews_data['reviews']:
sentences = [s.strip() for s in r['text'].split(".")]
pos_score, neg_score = senti_classifier.polarity_scores(sentences)
self.assertEqual(pos_score, r['pos'])
self.assertEqual(neg_score, r['neg'])
if __name__ == '__main__':
unittest.main()