-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathtest.py
308 lines (202 loc) · 6.66 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
import unittest
import sys
import click
import collections
import matplotlib
matplotlib.use('Agg')
from tests import *
verbose = 1
def create_test_suite_parameter(testcase, parameter=False):
"""
Create a suite containing all tests taken from the given
class, passing them a parameter.
"""
loader = unittest.TestLoader()
testnames = loader.getTestCaseNames(testcase)
suite = unittest.TestSuite()
for name in testnames:
suite.addTest(testcase(name, parameter=parameter))
return suite
def to_iterable(iterable):
if not isinstance(iterable, collections.Iterable):
iterable = [iterable]
return iterable
def create_test_suite(test_classes_to_run=[], parameter_test_cases=[], parameter=None):
loader = unittest.TestLoader()
test_classes_to_run = to_iterable(test_classes_to_run)
parameter_test_cases = to_iterable(parameter_test_cases)
suites_list = []
for test_class in test_classes_to_run:
suite = loader.loadTestsFromTestCase(test_class)
suites_list.append(suite)
for test_class in parameter_test_cases:
suite = create_test_suite_parameter(test_class, parameter=parameter)
suites_list.append(suite)
big_suite = unittest.TestSuite(suites_list)
return big_suite
def run(test_cases=[], parameter_test_cases=[], parameter=None):
global exit_status
suite = create_test_suite(test_cases, parameter_test_cases, parameter)
runner = unittest.TextTestRunner(verbosity=verbose)
results = runner.run(suite)
errors = len(results.errors)
failures = len(results.failures)
run = results.testsRun
print("------------------------------------------------------")
print("Test: run={} errors={} failures={}".format(run, errors, failures))
if not results.wasSuccessful():
sys.exit(1)
testing_spikes = [TestSpike, TestSpikes]
testing_features = [TestFeatures, TestGeneralSpikingFeatures, TestSpikingFeatures,
TestTestingFeatures, TestNetworkFeatures, TestGeneralNetworkFeatures,
TestEfelFeatures]
testing_base = [TestBase, TestParameterBase]
testing_data = [TestData, TestDataFeature]
testing_utils = [TestLogger, TestNoneToNan, TestLengths, TestContainsNoneOrNan,
TestIsRegular, TestSetNan]
# TODO: several tests crashes when several tests with Xvfb is run one after another
testing_models = [TestTestingModel0d, TestTestingModel1d, TestTestingModel2d,
TestModel, TestHodgkinHuxleyModel, TestCoffeeCupModel,
TestIzhikevichModel, TestNestModel, TestNeuronModel,
TestRunModel, TestParallel]
testing_parameters = [TestParameter, TestParameters]
testing_exact = testing_spikes + [TestUncertainty, TestPlotUncertainpy]
testing_all = testing_parameters + testing_models + testing_base\
+ testing_features + testing_data + [TestUncertaintyCalculations, TestDistribution]\
+ testing_utils
testing_complete = testing_all + [TestExamples]
testing_all_no_simulators = list(testing_all)
testing_all_no_simulators.remove(TestNestModel)
testing_all_no_simulators.remove(TestNeuronModel)
#chain=True
@click.group()
@click.option('--verbosity', default=1, help="Verbosity of test runner.")
def cli(verbosity):
global verbose
verbose = verbosity
@cli.command()
def distribution():
run(TestDistribution)
@cli.command()
@click.option('--exact', default=False, is_flag=True,
help="Test if the plot files are exactly equal.")
def spike(exact):
run(parameter_test_cases=TestSpike, parameter=exact)
@cli.command()
@click.option('--exact', default=False, is_flag=True,
help="Test if the plot files are exactly equal.")
def spikes(exact):
run(parameter_test_cases=TestSpikes, parameter=exact)
@cli.command()
@click.option('--exact', default=False, is_flag=True,
help="Test if the plot files are exactly equal.")
def all_spikes(exact):
run(parameter_test_cases=testing_spikes, parameter=exact)
@cli.command()
def features():
run(TestFeatures)
@cli.command()
def general_spiking_features():
run(TestGeneralSpikingFeatures)
@cli.command()
def spiking_features():
run(TestSpikingFeatures)
@cli.command()
def test_features():
run(TestTestingFeatures)
@cli.command()
def efel_features():
run(TestEfelFeatures)
@cli.command()
def network_features():
run(TestNetworkFeatures)
@cli.command()
def general_network_features():
run(TestGeneralNetworkFeatures)
@cli.command()
@click.option('--exact', default=False, is_flag=True,
help="Test if the plot files are exactly equal.")
def all_features(exact):
run(testing_features, testing_spikes, exact)
@cli.command()
def logger():
run(TestLogger)
@cli.command()
def utilities():
run(testing_utils)
@cli.command()
def uncertainty_calculations():
run(TestUncertaintyCalculations)
@cli.command()
def base():
run(TestBase)
@cli.command()
def parameter_base():
run(TestParameterBase)
@cli.command()
def all_bases():
run(testing_base)
@cli.command()
def parameter():
run(TestParameter)
@cli.command()
def parameters():
run(TestParameters)
@cli.command()
def all_parameters():
run(testing_parameters)
@cli.command()
def data_feature():
run(TestDataFeature)
@cli.command()
def data():
run(TestData)
@cli.command()
def all_data():
run(testing_data)
@cli.command()
def all_no_simulators():
run(testing_all_no_simulators)
@cli.command()
@click.option('--exact', default=False, is_flag=True,
help="Test if the plot files are exactly equal.")
def plotting(exact):
run(parameter_test_cases=TestPlotUncertainpy, parameter=exact)
@cli.command()
@click.option('--exact', default=False, is_flag=True,
help="Test if the plot files are exactly equal.")
def uncertainty(exact):
run(parameter_test_cases=TestUncertainty, parameter=exact)
@cli.command()
def parallel():
run(TestParallel)
@cli.command()
def run_model():
run(TestRunModel)
@cli.command()
def model():
run(TestModel)
@cli.command()
def nest_model():
run(TestNestModel)
@cli.command()
def neuron_model():
run(TestNeuronModel)
@cli.command()
def models():
run(testing_models)
@cli.command()
def examples():
run(TestExamples)
@cli.command()
@click.option('--exact', default=False, is_flag=True,
help="Test if the plot files are exactly equal.")
def all(exact):
run(testing_all, testing_exact, exact)
@cli.command()
@click.option('--exact', default=False, is_flag=True,
help="Test if the plot files are exactly equal.")
def complete(exact):
run(testing_complete, testing_exact, exact)
if __name__ == '__main__':
cli()