-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
56 lines (41 loc) · 1.41 KB
/
tests.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
import time
import unittest
import fscraper as fs
from fscraper.exceptions import (
CodeNotFound,
DelistedCode
)
class TestMethods(unittest.TestCase):
def tearDown(self):
time.sleep(1)
def test_yf_normal(self):
code = '7203.T'
yf=fs.YahooFinanceScraper(code=code)
df = yf.get_stock_price()
self.assertIsNotNone(df)
def test_nonexist_code(self):
"""Test delisted code in Yahoo !Finance"""
code = '8369.T' # Delisted code
yf = fs.YahooFinanceScraper(code=code)
with self.assertRaises(CodeNotFound):
yf.get_stock_price2(start='2023-12-15')
def test_reuter_news(self):
keyword = 'トヨタ自動車'
news = fs.ReutersScraper.get_news(keyword, 5)
self.assertEqual(len(news), 5)
def test_minkabu_news_list(self):
ms = fs.MinkabuScraper('7203.T')
queries = ms.query_news()
time.sleep(2)
news_list = ms.get_news_list(queries[:3])
self.assertEqual(len(news_list), 3)
def test_yfscraper_report(self):
yf = fs.YahooFinanceScraper('7203.T')
df = yf.get_financials('balancesheet', 'annual')
self.assertGreater(len(df), 0)
def test_minutes_price(self):
with self.assertRaises(DelistedCode):
kt = fs.KabutanScraper('2412.T')
kt.get_stock_price_by_minutes()
if __name__ == '__main__':
unittest.main()