forked from cgoldberg/ystockquote
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_ystockquote.py
124 lines (94 loc) · 4.06 KB
/
test_ystockquote.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env python
#
# Copyright (c) 2013, Corey Goldberg ([email protected])
#
# license: GNU LGPL
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# Requires: Python 2.7/3.2+
import unittest
import ystockquote
class TestYStockQuote(unittest.TestCase):
def setUp(self):
self.symbol = 'GOOG'
def test_get_all(self):
all_info = ystockquote.get_all(self.symbol)
self.assertIsInstance(all_info, dict)
p = all_info['price']
self.assertIsInstance(p, str)
self.assertGreater(float(p), 0.0)
def test_get_historical_prices(self):
prices = ystockquote.get_historical_prices(self.symbol, '20130102', '20130115')
headers = ['Date', 'Open', 'High', 'Low', 'Close', 'Volume', 'Adj Close']
self.assertEqual(len(prices), 11)
self.assertEqual(prices[0], headers)
self.assertEqual(prices[1][0], '2013-01-15')
self.assertEqual(prices[-1][0], '2013-01-02')
self.assertGreater(float(prices[1][6]), 0.0)
self.assertGreater(float(prices[-1][6]), 0.0)
def test_get_price(self):
value = ystockquote.get_price(self.symbol)
self.assertIsInstance(value, str)
def test_get_change(self):
value = ystockquote.get_change(self.symbol)
self.assertIsInstance(value, str)
def test_get_volume(self):
value = ystockquote.get_volume(self.symbol)
self.assertIsInstance(value, str)
def test_get_avg_daily_volume(self):
value = ystockquote.get_avg_daily_volume(self.symbol)
self.assertIsInstance(value, str)
def test_get_stock_exchange(self):
value = ystockquote.get_stock_exchange(self.symbol)
self.assertIsInstance(value, str)
def test_get_market_cap(self):
value = ystockquote.get_market_cap(self.symbol)
self.assertIsInstance(value, str)
def test_get_book_value(self):
value = ystockquote.get_book_value(self.symbol)
self.assertIsInstance(value, str)
def test_get_ebitda(self):
value = ystockquote.get_ebitda(self.symbol)
self.assertIsInstance(value, str)
def test_get_dividend_per_share(self):
value = ystockquote.get_dividend_per_share(self.symbol)
self.assertIsInstance(value, str)
def test_get_dividend_yield(self):
value = ystockquote.get_dividend_yield(self.symbol)
self.assertIsInstance(value, str)
def test_get_earnings_per_share(self):
value = ystockquote.get_earnings_per_share(self.symbol)
self.assertIsInstance(value, str)
def test_get_52_week_high(self):
value = ystockquote.get_52_week_high(self.symbol)
self.assertIsInstance(value, str)
def test_get_52_week_low(self):
value = ystockquote.get_52_week_low(self.symbol)
self.assertIsInstance(value, str)
def test_get_50day_moving_avg(self):
value = ystockquote.get_50day_moving_avg(self.symbol)
self.assertIsInstance(value, str)
def test_get_200day_moving_avg(self):
value = ystockquote.get_200day_moving_avg(self.symbol)
self.assertIsInstance(value, str)
def test_get_price_earnings_ratio(self):
value = ystockquote.get_price_earnings_ratio(self.symbol)
self.assertIsInstance(value, str)
def test_get_price_earnings_growth_ratio(self):
value = ystockquote.get_price_earnings_growth_ratio(self.symbol)
self.assertIsInstance(value, str)
def test_get_price_sales_ratio(self):
value = ystockquote.get_price_sales_ratio(self.symbol)
self.assertIsInstance(value, str)
def test_get_price_book_ratio(self):
value = ystockquote.get_price_book_ratio(self.symbol)
self.assertIsInstance(value, str)
def test_get_short_ratio(self):
value = ystockquote.get_short_ratio(self.symbol)
self.assertIsInstance(value, str)
if __name__ == '__main__':
unittest.main()