-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathregression_test.py
More file actions
84 lines (74 loc) · 3.16 KB
/
regression_test.py
File metadata and controls
84 lines (74 loc) · 3.16 KB
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
#!/usr/bin/env python3
"""
Copyright (C) 2019 Centro de Computacao Cientifica e Software Livre
Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
This file is part of lde-api-regression-test.
lde-api-regression-test is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
lde-api-regression-test is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with lde-api-regression-test. If not, see <https://www.gnu.org/licenses/>.
"""
import sys
import pandas as pd
import numpy as np
import settings
from termcolor import colored,cprint
maxYear = 2019
class RegressionTest:
def __init__(self, route):
self.base_url = settings.BASE_URL
self.route_list = settings.BASE_ROUTE_LIST+settings.SIMCAQ_ROUTE_LIST
if len(route) > 0:
route = [route]
self.route_list = filter(lambda k: route[0] in k, self.route_list)
def save(self):
for route in self.route_list:
name = route[0]
arguments = ''
if len(route) > 1:
arguments = arguments.join(route[1:])
file_name = name+arguments
url = self.base_url+name+'?filter=min_year:1991,max_year:' + str(maxYear) + ','+arguments+'&format=csv'
url = url.replace(",&format","&format")
try:
api_csv = pd.read_csv(url,float_precision='round_trip', encoding="utf-8-sig") #get from api
file_name = file_name.replace("school/count","school_count")
file_name = file_name.replace("class_count/count","class_count_count")
api_csv.to_csv('route_result/'+file_name+'.csv', encoding="utf-8-sig") #save
cprint("Saved "+name+" with arguments: ["+arguments+"] URL: <"+url+">",'green')
except Exception as ex:
cprint(str(ex)+" Not saved, a problem ocurred at "+file_name+" "+url,'red')
def compare(self, verbose):
fail = 0
for route in self.route_list:
name = route[0]
arguments = ''
if len(route) > 1:
arguments = arguments.join(route[1:])
file_name = name+arguments
url = self.base_url+name+'?filter=min_year:1991,max_year:'+str(maxYear)+','+arguments+'&format=csv'
url = url.replace(",&format","&format")
try:
api_csv = pd.read_csv(url,float_precision='round_trip', encoding="utf-8-sig") #get from api
file_name = file_name.replace("school/count","school_count")
file_name = file_name.replace("class_count/count","class_count_count")
csv_route = pd.read_csv('route_result/'+file_name+'.csv', index_col=0, float_precision='round_trip', encoding="utf-8-sig") #get file
if csv_route.equals(api_csv): #comparing csv
cprint(file_name+' OK!','green')
else:
fail+=1
cprint(file_name+' FAIL!','red')
if verbose:
print(pd.concat([csv_route, api_csv]).drop_duplicates(keep=False))
except Exception as ex:
cprint(str(ex)+"\n"+file_name+' FAIL!','red')
fail+=1
cprint('TOTAL FAIL: '+str(fail),'red')
if (fail > 0):
exit(-1)