forked from vedangj044/News_stock_prediction
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_components.py
75 lines (52 loc) · 2.16 KB
/
test_components.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import unittest
from predictor import predict1
from model import Sentiment
from nltk import NaiveBayesClassifier
from extractTicker import stock_graph
from news_scraper import scraper
from AltException import InvalidQuery, InvalidTicker
class newsScraperTestcase(unittest.TestCase):
def setUp(self):
self.scr = scraper("Tesla")
def test_news_scraper(self):
self.assertTrue(len(self.scr.results)>0)
def test_news_count(self):
self.assertTrue(self.scr.count>0)
def test_get_title(self):
self.assertIsInstance(self.scr.get_title(), str)
def test_empty_scaper(self):
self.assertRaises(AssertionError, lambda: scraper(""))
def test_invalid_scraper(self):
self.assertRaises(InvalidQuery, lambda: scraper("icneidisneafebf"))
class predictorTestCase(unittest.TestCase):
def setUp(self):
self.pred = predict1("Tesla")
def test_predictor(self):
self.assertTrue(self.pred.final_pred)
def test_empty_predictor(self):
self.assertRaises(AssertionError, lambda: predict1(""))
def test_invalid_predictor(self):
self.assertRaises(InvalidQuery, lambda: predict1("iaenflaisuef"))
class modelTestCase(unittest.TestCase):
def test_model_train(self):
self.model = Sentiment().train_data()
self.assertIsInstance(self.model, NaiveBayesClassifier)
class extractTicketTestCase(unittest.TestCase):
def setUp(self):
self.sg = stock_graph("Tesla", [0.08733508525853388, 0.41467300402115265, 0.8421720201029591, 2.1635118971243883])
def test_ticker(self):
self.assertEqual(self.sg.ticker, "TSLA")
def test_current_value(self):
self.assertTrue(self.sg.current_price_value)
def test_graph(self):
self.assertIsInstance(self.sg.graph(), dict)
def test_empty_graph(self):
self.assertRaises(AssertionError, lambda: stock_graph("", []))
def test_invalid_graph(self):
self.assertRaises(InvalidTicker, lambda: stock_graph("guocoland",
[0.08733508525853388,
0.41467300402115265,
0.8421720201029591,
2.1635118971243883]))
if __name__ == "__main__":
unittest.main() # pragma: no cover