-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
150 lines (113 loc) · 5.94 KB
/
test.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
147
148
149
150
import unittest
import pandas as pd
import os.path
from functions.extract_data import getData
from functions.transform_data import transformNewYorkTimesData
from functions.transform_data import transformJohnHopkinsData
from functions.transform_data import transformJoinData
my_path = os.path.abspath(os.path.dirname(__file__))
nytTestDataPath = os.path.join(my_path, "test_files/NYT-test-data.csv")
jhpTestDataPath = os.path.join(my_path, "test_files/JPH-test-data.csv")
class TestCalc(unittest.TestCase):
def setUp(self):
self.nytdata = nytTestDataPath
self.jphdata = jhpTestDataPath
def tearDown(self):
pass
################## TEST GETDATA ##################
## New York Times Data ##
# NYT Data Test: Check if headers match
def test_csv_read_data_headers(self):
result = getData(self.nytdata)
result_headers = list(result.columns)
result_df = ['date', 'cases', 'deaths']
self.assertEqual(result_headers, result_df)
# NYT Data Test: Check if Date can be read properly
def test_csv_nyt_date_data(self):
result = getData(self.nytdata)
result_date = result.date.iloc[0]
self.assertEqual(result_date, '2020-12-11')
## John Hopkins Data ##
# JHP Data Test: Check if headers match
def test_jhp_csv_read_data_headers(self):
result = getData(self.jphdata)
result_headers = list(result.columns)
result_df = ['Date', 'Country/Region', 'Province/State', 'Lat', 'Long', 'Confirmed', 'Recovered', 'Deaths']
self.assertEqual(result_headers, result_df)
# JHP Data Test: Check if Date can be read properly
def test_csv_jph_date_data(self):
result = getData(self.jphdata)
result_date = result.Date.iloc[0]
self.assertEqual(result_date, '2020-07-10')
################## TEST TRANSFORM MODULE DATA ##################
## New York Times Data ##
# TRANSFORM NYT DATA TEST: check if headers match
def test_nytdata_headers(self):
result = transformNewYorkTimesData(getData(self.nytdata))
result_headers = list(result.columns)
result_df = ['datetime', 'cases', 'deaths']
self.assertEqual(result_headers, result_df)
# TRANSFORM NYT DATA TEST: Check if date has been converted to datetime
def test_nytdata(self):
result = transformNewYorkTimesData(getData(self.nytdata))
result_date = str(result.datetime.iloc[1])
self.assertEqual(result_date, '2020-12-12 00:00:00')
# TRANSFORM NYT DATA TEST: Check if Cases and Deaths Field are Int and greater or equal to 0
def test_nytdata_int(self):
result = transformNewYorkTimesData(getData(self.nytdata))
result_cases_int = result.cases.iloc[0]
result_deaths_int = result.deaths.iloc[1]
self.assertGreaterEqual(result_cases_int, 0)
self.assertGreaterEqual(result_deaths_int, 0)
## John Hopkins Data ##
# TRANSFORM JPH DATA TEST: check if headers match
def test_jphdata_headers(self):
result = transformJohnHopkinsData(getData(self.jphdata))
result_headers = list(result.columns)
result_df = ['datetime', 'Recovered']
self.assertEqual(result_headers, result_df)
# TRANSFORM NYT DATA TEST: Check if date has been converted to datetime
def test_jphdata(self):
result = transformJohnHopkinsData(getData(self.jphdata))
result_date = str(result.datetime.iloc[1])
self.assertEqual(result_date, '2020-07-10 00:00:00')
# TRANSFORM NYT DATA TEST: Check if Cases and Deaths Field are Int and greater or equal to 0
def test_jphdata_int(self):
result = transformJohnHopkinsData(getData(self.jphdata))
result_recovered_int = result.Recovered.iloc[0]
self.assertGreaterEqual(result_recovered_int, 0)
## JOINED DATA OF BOTH NEW YORK TIME AND JOHN HOPKINS ##
# JOINED DATA TEST: check if headers match
def test_joindataset_headers(self):
newYorkDataExtraction = getData(self.nytdata)
johnHopkinsDataExtraction = getData(self.jphdata)
NYTData = transformNewYorkTimesData(newYorkDataExtraction)
JPHData = transformJohnHopkinsData(johnHopkinsDataExtraction)
result = transformJoinData(NYTData, JPHData)
result_headers = list(result.columns)
expected_headers = ['datetime', 'cases', 'deaths', 'Recovered']
self.assertEqual(result_headers, expected_headers)
# JOINED DATA TEST: Check if date has been converted to datetime
def test_joindataset_date(self):
newYorkDataExtraction = getData(self.nytdata)
johnHopkinsDataExtraction = getData(self.jphdata)
NYTData = transformNewYorkTimesData(newYorkDataExtraction)
JPHData = transformJohnHopkinsData(johnHopkinsDataExtraction)
result = transformJoinData(NYTData, JPHData)
result_date = str(result.datetime.iloc[0])
self.assertEqual(result_date, '2020-08-12 00:00:00')
# JOINED DATA TEST: Check if Cases and Deaths Field are Int and greater or equal to 0
def test_joindataset_int(self):
newYorkDataExtraction = getData(self.nytdata)
johnHopkinsDataExtraction = getData(self.jphdata)
NYTData = transformNewYorkTimesData(newYorkDataExtraction)
JPHData = transformJohnHopkinsData(johnHopkinsDataExtraction)
result = transformJoinData(NYTData, JPHData)
result_cases_int = result.cases.iloc[0]
result_deaths_int = result.deaths.iloc[0]
result_Recocered_int = result.Recovered.iloc[0]
self.assertGreaterEqual(result_cases_int, 0)
self.assertGreaterEqual(result_deaths_int, 0)
self.assertGreaterEqual(result_Recocered_int, 0)
if __name__ == '__main__':
unittest.main()