forked from ShayanArman/knotPortfolioTerminal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_ystockquote.py
146 lines (112 loc) · 5.19 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/env python
#
# Copyright (c) 2013, Corey Goldberg (cgoldberg@gmail.com)
#
# 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 pep8
import ystockquote
class Pep8ConformanceTestCase(unittest.TestCase):
"""Test that all code conforms to PEP8."""
def test_pep8_conformance(self):
self.pep8style = pep8.StyleGuide(show_source=True)
files = ('ystockquote.py', 'test_ystockquote.py')
self.pep8style.check_files(files)
self.assertEqual(self.pep8style.options.report.total_errors, 0)
class YStockQuoteTestCase(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_dict = ystockquote.get_historical_prices(
self.symbol, '2013-01-02', '2013-01-15')
self.assertIsInstance(prices_dict, dict)
self.assertEqual(len(prices_dict), 10)
self.assertEqual(sorted(prices_dict.keys())[0], '2013-01-02')
self.assertEqual(sorted(prices_dict.keys())[-1], '2013-01-15')
self.assertGreater(float(prices_dict['2013-01-02']['Open']), 0.0)
self.assertGreater(float(prices_dict['2013-01-02']['High']), 0.0)
self.assertGreater(float(prices_dict['2013-01-02']['Low']), 0.0)
self.assertGreater(float(prices_dict['2013-01-02']['Close']), 0.0)
self.assertGreater(float(prices_dict['2013-01-02']['Volume']), 0.0)
self.assertGreater(float(prices_dict['2013-01-02']['Adj Close']), 0.0)
self.assertGreater(float(prices_dict['2013-01-15']['Open']), 0.0)
self.assertGreater(float(prices_dict['2013-01-15']['High']), 0.0)
self.assertGreater(float(prices_dict['2013-01-15']['Low']), 0.0)
self.assertGreater(float(prices_dict['2013-01-15']['Close']), 0.0)
self.assertGreater(float(prices_dict['2013-01-15']['Volume']), 0.0)
self.assertGreater(float(prices_dict['2013-01-15']['Adj Close']), 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()