-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
136 lines (117 loc) · 5.07 KB
/
tests.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
import inspect, traceback
from database_handler import DatabaseHandler
from database_selector import DatabaseSelector
""" This file can be used to run tests of main functionnalities, main methods
of DatabaseHandler and DatabaseSelector. Each function is named from the name
of the method to test or when necessary with a more explicit name of what
it really does, each name is prefixed by test_* """
def test_import_db_meteo():
try:
db_handler = DatabaseHandler()
db_handler.connect()
db_handler.init_import('test_meteo_import_db',
'./data/meteo_data.csv', True)
db_handler.process_csv_file()
db_handler.disconnect()
return 0
except Exception as e:
traceback.print_exc()
raise RuntimeError(f"Error occurred during {inspect.currentframe().f_code.co_name}") from e
def test_import_db_helio_results():
try:
db_handler = DatabaseHandler()
db_handler.init_import('test_helio_data_import', './data/test_helio.csv', False)
db_handler.connect()
db_handler.process_csv_file()
db_handler.disconnect()
return 0
except Exception as e:
traceback.print_exc()
raise RuntimeError(f"Error occurred during {inspect.currentframe().f_code.co_name}") from e
def test_aggregate_to_helio_step():
try:
manager = DatabaseSelector()
manager.connect()
manager.init_import('test_meteo_import_db','','')
manager.aggregate_values_to_helio_step(subtable_name='test_aggregate_to_step')
manager.disconnect()
return 0
except Exception as e:
raise RuntimeError(f"Error occurred during {inspect.currentframe().f_code.co_name}:{e}") from e
def test_insert_variable():
try:
manager = DatabaseSelector()
manager.connect()
# test for inserting new variables to the table
manager.init_import('test_meteo_import_db','','')
manager.insert_variables_from_python_formula(['Temperature',
'wind_speed',
'rel_humidity'])
manager.disconnect()
return 0
except Exception as e:
traceback.print_exc()
raise RuntimeError(f"Error occurred during {inspect.currentframe().f_code.co_name}") from e
def test_select_interval():
# test for the creation of subtables with selected values
try:
manager = DatabaseSelector()
manager.connect()
available_tables = manager.get_available_tables()
manager.table_name = 'test_meteo_import_db'
new_table_name = 'test_select_interval'
fields = manager.get_fields_in_table(manager.table_name)
column_name = 'Date'
start = '2023-12-01'
end = '2024-06-30'
manager.select_interval(start, end, column_name,
new_table_name)
manager.disconnect()
return 0
except Exception as e:
traceback.print_exc()
raise RuntimeError(f"Error occurred during {inspect.currentframe().f_code.co_name}") from e
def test_select_scope():
# test for the creation of subtables with selected values
try:
manager = DatabaseSelector()
manager.connect()
available_tables = manager.get_available_tables()
manager.table_name = 'test_helio_data_import'
new_table_name = 'test_select_scope'
fields = manager.get_fields_in_table(manager.table_name)
column_name = 'mpp'
scope = 'mpp-25-4'
manager.select_scope(column_name,scope,
new_table_name,)
manager.disconnect()
return 0
except Exception as e:
traceback.print_exc()
raise RuntimeError(f"Error occurred during {inspect.currentframe().f_code.co_name}") from e
def test_json_generator():
try:
pass
except Exception as e:
traceback.print_exc()
raise RuntimeError(f"Error occurred during {inspect.currentframe().f_code.co_name}") from e
def tests():
functions_to_test = [test_import_db_meteo,test_import_db_helio_results, test_insert_variable,
test_select_scope,test_select_interval,
test_aggregate_to_helio_step]
for i,func in enumerate(functions_to_test):
try:
print(f"{len(func.__name__)*'='}===============")
print(f"TEST {i} {func.__name__} running")
print(f"{len(func.__name__)*'='}===============")
result = func()
print(f"{len(func.__name__)*'o'}oooooooooooooooooooooooooooooooooooo")
print(f"{func.__name__} executed successfully. exit code:", result)
print(f"{len(func.__name__)*'o'}oooooooooooooooooooooooooooooooooooo")
except Exception as e:
print("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
print(f"Error occurred in Test {i} function:", func.__name__)
print("Error message:", e)
print("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
if __name__ == '__main__':
tests()