forked from ibpsa/project1-boptest
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_testcase2.py
174 lines (129 loc) · 5.7 KB
/
test_testcase2.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# -*- coding: utf-8 -*-
"""
This module runs tests for testcase 2. To run these tests, testcase 2 must
already be deployed.
"""
import unittest
import pandas as pd
import os
import utilities
import requests
from examples.python import testcase2
class ExampleSupervisoryPython(unittest.TestCase, utilities.partialChecks):
'''Tests the example test of a supervisory controller in Python.
'''
def setUp(self):
'''Setup for each test.
'''
pass
def test_run(self):
'''Runs the example and tests the kpi and trajectory results.
'''
# Run test
kpi,df_res,customizedkpis_result = testcase2.run()
# Check kpis
df = pd.DataFrame.from_dict(kpi, orient='index', columns=['value'])
df.index.name = 'keys'
ref_filepath = os.path.join(utilities.get_root_path(), 'testing', 'references', 'testcase2', 'kpis_python.csv')
self.compare_ref_values_df(df, ref_filepath)
# Check trajectories
# Set reference file path
ref_filepath = os.path.join(utilities.get_root_path(), 'testing', 'references', 'testcase2', 'results_python.csv')
self.compare_ref_timeseries_df(df_res,ref_filepath)
# Check customized kpi trajectories
df = pd.DataFrame()
for x in customizedkpis_result.keys():
if x != 'time':
df = pd.concat((df,pd.DataFrame(data=customizedkpis_result[x], index=customizedkpis_result['time'], columns=[x])), axis=1)
df.index.name = 'time'
# Set reference file path
ref_filepath = os.path.join(utilities.get_root_path(), 'testing', 'references', 'testcase2', 'customizedkpis.csv')
self.compare_ref_timeseries_df(df,ref_filepath)
class ExampleSupervisoryJulia(unittest.TestCase, utilities.partialChecks):
'''Tests the example test of a supervisory controller in Julia.
'''
def setUp(self):
'''Setup for each test.
'''
pass
def test_run(self):
'''Runs the example and tests the kpi and trajectory results.
'''
# Run test
kpi_path = os.path.join(utilities.get_root_path(), 'examples', 'julia', 'kpi_testcase2.csv')
res_path = os.path.join(utilities.get_root_path(), 'examples', 'julia', 'result_testcase2.csv')
# Check kpis
df = pd.read_csv(kpi_path).transpose()
# Check kpis
df.columns = ['value']
df.index.name = 'keys'
ref_filepath = os.path.join(utilities.get_root_path(), 'testing', 'references', 'testcase2', 'kpis_julia.csv')
self.compare_ref_values_df(df, ref_filepath)
# Check trajectories
df = pd.read_csv(res_path, index_col = 'time')
# Set reference file path
ref_filepath = os.path.join(utilities.get_root_path(), 'testing', 'references', 'testcase2', 'results_julia.csv')
# Test
self.compare_ref_timeseries_df(df,ref_filepath)
class ExampleSupervisoryJavaScript(unittest.TestCase, utilities.partialChecks):
'''Tests the example test of a supervisory controller in JavaScript.
'''
def setUp(self):
'''Setup for each test.
'''
pass
def test_run(self):
'''Runs the example and tests the kpi and trajectory results.
'''
# Run test
kpi_path = os.path.join(utilities.get_root_path(), 'examples', 'javascript', 'kpi_testcase2.csv')
res_path = os.path.join(utilities.get_root_path(), 'examples', 'javascript', 'result_testcase2.csv')
# Check kpis
df = pd.read_csv(kpi_path, index_col = 'keys')
ref_filepath = os.path.join(utilities.get_root_path(), 'testing', 'references', 'testcase2', 'kpis_javascript.csv')
self.compare_ref_values_df(df, ref_filepath)
# Check trajectories
df = pd.read_csv(res_path, index_col = 'time')
# Set reference file path
ref_filepath = os.path.join(utilities.get_root_path(), 'testing', 'references', 'testcase2', 'results_javascript.csv')
# Test
self.compare_ref_timeseries_df(df,ref_filepath)
class MinMax(unittest.TestCase):
'''Test the use of min/max attributes to truncate the controller input.
'''
def setUp(self):
'''Setup for each test.
'''
self.url = 'http:https://127.0.0.1:5000'
def test_min(self):
'''Tests that if input is below min, input is set to min.
'''
# Run test
requests.put('{0}/initialize'.format(self.url), data={'start_time':0, 'warmup_period':0})
y = requests.post('{0}/advance'.format(self.url), data={"oveTSetRooHea_activate":1,"oveTSetRooHea_u":273.15}).json()
# Check kpis
value = float(y['oveTSetRooHea_u'])
self.assertAlmostEqual(value, 273.15+10, places=3)
def test_max(self):
'''Tests that if input is above max, input is set to max.
'''
# Run test
requests.put('{0}/initialize'.format(self.url), data={'start_time':0, 'warmup_period':0})
y = requests.post('{0}/advance'.format(self.url), data={"oveTSetRooHea_activate":1,"oveTSetRooHea_u":310.15}).json()
# Check kpis
value = float(y['oveTSetRooHea_u'])
self.assertAlmostEqual(value, 273.15+35, places=3)
class API(unittest.TestCase, utilities.partialTestAPI):
'''Tests the api for testcase 2.
Actual test methods implemented in utilities.partialTestAPI. Set self
attributes defined there for particular testcase in setUp method here.
'''
def setUp(self):
'''Setup for testcase.
'''
self.name = 'testcase2'
self.url = 'http:https://127.0.0.1:5000'
self.step_ref = 3600.0
self.test_time_period = 'test_day'
if __name__ == '__main__':
utilities.run_tests(os.path.basename(__file__))