-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_get_historical_data.py
44 lines (34 loc) · 1.52 KB
/
test_get_historical_data.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
import tempfile
from unittest import TestCase
import get_historical_data
class Test(TestCase):
def test_get_fed_history(self):
history = get_historical_data.get_fed_history()
for year, h in zip(range(1983, 2021), history):
self.assertEqual(year, int(h[0]))
for one in h:
self.assertTrue(int(one) > 0)
def test_get_2019_data(self):
data = get_historical_data.get_2019_data()
self.assertEqual(int(data[7]), int(data[1]) + int(data[3]) + int(data[5]))
self.assertEqual(int(data[8]), int(data[2]) + int(data[4]) + int(data[6]))
def test_get_2020_data(self):
data = get_historical_data.get_2020_data()
self.assertEqual(int(data[7]), int(data[1]) + int(data[3]) + int(data[5]))
self.assertEqual(int(data[8]), int(data[2]) + int(data[4]) + int(data[6]))
def test_run(self):
with tempfile.NamedTemporaryFile() as f:
destination = f.name
get_historical_data.run(destination)
compare_to = get_historical_data.output_file_name
with open(compare_to) as f:
expected = f.read()
with open(destination) as f:
actual = f.read()
self.assertEqual(expected, actual)
def test_get_source_data(self):
data = get_historical_data._get_source_data()
self.assertEqual(32, len(data))
self.assertEqual("1987", data[0][0])
self.assertEqual("2018", data[31][0])
self.assertEqual("1,975,086", data[31][8])