1
|
|
|
|
2
|
|
|
""" |
3
|
|
|
.. module:: savu_config_test |
4
|
|
|
:platform: Unix |
5
|
|
|
:synopsis: unittest test for savu_config |
6
|
|
|
.. moduleauthor: Mark Basham |
7
|
|
|
|
8
|
|
|
""" |
9
|
|
|
|
10
|
|
|
import unittest |
11
|
|
|
from mock import patch |
12
|
|
|
from io import StringIO |
13
|
|
|
import subprocess |
14
|
|
|
|
15
|
|
|
from scripts.config_generator import savu_config |
16
|
|
|
|
17
|
|
|
import scripts.configurator_tests.savu_config_test_utils as sctu |
18
|
|
|
|
19
|
|
|
class SavuConfigTest(unittest.TestCase): |
20
|
|
|
|
21
|
|
|
def test_exit(self): |
22
|
|
|
input_list = ['exit', 'y'] |
23
|
|
|
output_checks = ['Thanks for using the application'] |
24
|
|
|
sctu.savu_config_runner(input_list, output_checks) |
25
|
|
|
|
26
|
|
|
def test_help_blank(self): |
27
|
|
|
input_list = ['', 'exit', 'y'] |
28
|
|
|
output_checks = ['Close the program'] |
29
|
|
|
sctu.savu_config_runner(input_list, output_checks) |
30
|
|
|
|
31
|
|
|
def test_help_command(self): |
32
|
|
|
input_list = ['help', 'exit', 'y'] |
33
|
|
|
output_checks = ['Display the help information'] |
34
|
|
|
sctu.savu_config_runner(input_list, output_checks) |
35
|
|
|
|
36
|
|
|
def test_add(self): |
37
|
|
|
input_list = ['add NxtomoLoader', |
38
|
|
|
'exit', |
39
|
|
|
'y'] |
40
|
|
|
output_checks = ['Exception'] |
41
|
|
|
sctu.savu_config_runner(input_list, output_checks, |
42
|
|
|
error_str=True) |
43
|
|
|
|
44
|
|
|
def test_add_mod(self): |
45
|
|
|
input_list = ['add NxtomoLoader', |
46
|
|
|
'disp', |
47
|
|
|
'mod 1.3 Test text', |
48
|
|
|
'exit', |
49
|
|
|
'y'] |
50
|
|
|
output_checks = ['Exception'] |
51
|
|
|
sctu.savu_config_runner(input_list, output_checks, |
52
|
|
|
error_str=True) |
53
|
|
|
|
54
|
|
|
def test_add_mod_2(self): |
55
|
|
|
input_list = ['add NxtomoLoader', |
56
|
|
|
'add AstraReconCpu', |
57
|
|
|
'mod 1.4 FBP', |
58
|
|
|
'exit', |
59
|
|
|
'y'] |
60
|
|
|
output_checks = ['Exception'] |
61
|
|
|
sctu.savu_config_runner(input_list, output_checks, |
62
|
|
|
error_str=True) |
63
|
|
|
|
64
|
|
|
def test_add_mod_3(self): |
65
|
|
|
# Exception due to invalid parameter number |
66
|
|
|
input_list = ['add NxtomoLoader', |
67
|
|
|
'add AstraReconCpu', |
68
|
|
|
'mod 1.45 FBP', |
69
|
|
|
'exit', |
70
|
|
|
'y'] |
71
|
|
|
output_checks = ['Exception'] |
72
|
|
|
sctu.savu_config_runner(input_list, output_checks, |
73
|
|
|
error_str=True) |
74
|
|
|
|
75
|
|
|
def test_add_dupl(self): |
76
|
|
|
# Exception due to invalid plugin number |
77
|
|
|
input_list = ['add NxtomoLoader', |
78
|
|
|
'add AstraReconCpu', |
79
|
|
|
'dupl 3', |
80
|
|
|
'exit', |
81
|
|
|
'y'] |
82
|
|
|
output_checks = ['ValueError'] |
83
|
|
|
sctu.savu_config_runner(input_list, output_checks) |
84
|
|
|
|
85
|
|
|
def test_add_dupl_1(self): |
86
|
|
|
input_list = ['add NxtomoLoader', |
87
|
|
|
'add AstraReconCpu', |
88
|
|
|
'dupl 1', |
89
|
|
|
'exit', |
90
|
|
|
'y'] |
91
|
|
|
output_checks = ['Exception', 'Error'] |
92
|
|
|
sctu.savu_config_runner(input_list, output_checks, |
93
|
|
|
error_str=True) |
94
|
|
|
|
95
|
|
|
def test_iterate_add_loop_success(self): |
96
|
|
|
start = 2 |
97
|
|
|
stop = 2 |
98
|
|
|
iterations = 5 |
99
|
|
|
input_list = [ |
100
|
|
|
'add TomoPhantomLoader', |
101
|
|
|
'add MedianFilter', |
102
|
|
|
f"iterate --set {start} {stop} {iterations}", |
103
|
|
|
'exit', |
104
|
|
|
'y' |
105
|
|
|
] |
106
|
|
|
output_str = f"The following loop has been added: start plugin index " \ |
107
|
|
|
f"{start}, end plugin index {stop}, iterations " \ |
108
|
|
|
f"{iterations}" |
109
|
|
|
output_checks = [output_str] |
110
|
|
|
sctu.savu_config_runner(input_list, output_checks) |
111
|
|
|
|
112
|
|
|
def test_iterate_add_loop_fail(self): |
113
|
|
|
start = 4 |
114
|
|
|
stop = 4 |
115
|
|
|
iterations = 5 |
116
|
|
|
input_list = [ |
117
|
|
|
'add TomoPhantomLoader', |
118
|
|
|
'add MedianFilter', |
119
|
|
|
f"iterate --set {start} {stop} {iterations}", |
120
|
|
|
'exit', |
121
|
|
|
'y' |
122
|
|
|
] |
123
|
|
|
output_str = 'The given plugin indices are not within the range of ' \ |
124
|
|
|
'existing plugin indices' |
125
|
|
|
output_checks = [output_str] |
126
|
|
|
sctu.savu_config_runner(input_list, output_checks) |
127
|
|
|
|
128
|
|
|
def test_iterate_remove_loop_success(self): |
129
|
|
|
start = 2 |
130
|
|
|
stop = 2 |
131
|
|
|
iterations = 5 |
132
|
|
|
input_list = [ |
133
|
|
|
'add TomoPhantomLoader', |
134
|
|
|
'add MedianFilter', |
135
|
|
|
f"iterate --set {start} {stop} {iterations}", |
136
|
|
|
'iterate --remove 1', |
137
|
|
|
'exit', |
138
|
|
|
'y' |
139
|
|
|
] |
140
|
|
|
output_str = f"The following loop has been removed: start plugin " \ |
141
|
|
|
f"index {start}, end plugin index {stop}, iterations " \ |
142
|
|
|
f"{iterations}" |
143
|
|
|
output_checks = [output_str] |
144
|
|
|
sctu.savu_config_runner(input_list, output_checks) |
145
|
|
|
|
146
|
|
|
def test_iterate_remove_loop_fail(self): |
147
|
|
|
input_list = [ |
148
|
|
|
'add TomoPhantomLoader', |
149
|
|
|
'add MedianFilter', |
150
|
|
|
'iterate --remove 1', |
151
|
|
|
'exit', |
152
|
|
|
'y' |
153
|
|
|
] |
154
|
|
|
output_str = "There doesn't exist an iterative loop with number 1" |
155
|
|
|
output_checks = [output_str] |
156
|
|
|
sctu.savu_config_runner(input_list, output_checks) |
157
|
|
|
|
158
|
|
|
def test_iterate_remove_all_loops_confirm(self): |
159
|
|
|
start = 2 |
160
|
|
|
stop = 2 |
161
|
|
|
iterations = 5 |
162
|
|
|
input_list = [ |
163
|
|
|
'add TomoPhantomLoader', |
164
|
|
|
'add MedianFilter', |
165
|
|
|
f"iterate --set {start} {stop} {iterations}", |
166
|
|
|
'iterate --remove', |
167
|
|
|
'y', |
168
|
|
|
'exit', |
169
|
|
|
'y' |
170
|
|
|
] |
171
|
|
|
output_str = 'All iterative loops have been removed' |
172
|
|
|
output_checks = [output_str] |
173
|
|
|
sctu.savu_config_runner(input_list, output_checks) |
174
|
|
|
|
175
|
|
|
def test_iterate_remove_all_loops_deny(self): |
176
|
|
|
start = 2 |
177
|
|
|
stop = 2 |
178
|
|
|
iterations = 5 |
179
|
|
|
input_list = [ |
180
|
|
|
'add TomoPhantomLoader', |
181
|
|
|
'add MedianFilter', |
182
|
|
|
f"iterate --set {start} {stop} {iterations}", |
183
|
|
|
'iterate --remove', |
184
|
|
|
'n', |
185
|
|
|
'exit', |
186
|
|
|
'y' |
187
|
|
|
] |
188
|
|
|
output_str = 'No iterative loops have been removed' |
189
|
|
|
output_checks = [output_str] |
190
|
|
|
sctu.savu_config_runner(input_list, output_checks) |
191
|
|
|
|
192
|
|
|
def test_rem(self): |
193
|
|
|
# Exception due to invalid plugin number |
194
|
|
|
input_list = ['add NxtomoLoader', |
195
|
|
|
'add AstraReconCpu', |
196
|
|
|
'rem 3', |
197
|
|
|
'exit', |
198
|
|
|
'y'] |
199
|
|
|
output_checks = ['ValueError'] |
200
|
|
|
sctu.savu_config_runner(input_list, output_checks) |
201
|
|
|
|
202
|
|
|
def test_rem_1(self): |
203
|
|
|
input_list = ['add NxtomoLoader', |
204
|
|
|
'add AstraReconCpu', |
205
|
|
|
'rem 2', |
206
|
|
|
'exit', |
207
|
|
|
'y'] |
208
|
|
|
output_checks = ['Exception'] |
209
|
|
|
sctu.savu_config_runner(input_list, output_checks, |
210
|
|
|
error_str=True) |
211
|
|
|
|
212
|
|
|
def test_rem_2(self): |
213
|
|
|
input_list = ['add NxtomoLoader', |
214
|
|
|
'add DarkFlatFieldCorrection', |
215
|
|
|
'add RingRemovalFitting', |
216
|
|
|
'add MedianFilter', |
217
|
|
|
'add MedianFilter', |
218
|
|
|
'add MedianFilter', |
219
|
|
|
'add MedianFilter' |
220
|
|
|
'add Pymca', |
221
|
|
|
'add AstraReconCpu', |
222
|
|
|
'add AstraReconCpu', |
223
|
|
|
'add AstraReconCpu', |
224
|
|
|
'add AstraReconCpu', |
225
|
|
|
'add AstraReconCpu', |
226
|
|
|
'add AstraReconCpu', |
227
|
|
|
'add AstraReconCpu', |
228
|
|
|
'add AstraReconCpu', |
229
|
|
|
'add AstraReconCpu', |
230
|
|
|
'rem 10 11 12', |
231
|
|
|
'exit', |
232
|
|
|
'y'] |
233
|
|
|
output_checks = ['Exception','Error'] |
234
|
|
|
sctu.savu_config_runner(input_list, output_checks, |
235
|
|
|
error_str=True) |
236
|
|
|
|
237
|
|
|
def test_rem_3(self): |
238
|
|
|
input_list = ['add NxtomoLoader', |
239
|
|
|
'add AstraReconCpu', |
240
|
|
|
'rem 2', |
241
|
|
|
'exit', |
242
|
|
|
'y'] |
243
|
|
|
output_checks = ['Exception'] |
244
|
|
|
sctu.savu_config_runner(input_list, output_checks, |
245
|
|
|
error_str=True) |
246
|
|
|
|
247
|
|
|
def test_replace(self): |
248
|
|
|
# Exception due to invalid plugin number |
249
|
|
|
input_list = ['add NxtomoLoader', |
250
|
|
|
'add AstraReconCpu', |
251
|
|
|
'replace 2 TomopyRecon', |
252
|
|
|
'exit', |
253
|
|
|
'y'] |
254
|
|
|
output_checks = ['ValueError'] |
255
|
|
|
sctu.savu_config_runner(input_list, output_checks, |
256
|
|
|
error_str=True) |
257
|
|
|
|
258
|
|
|
def test_replace_1(self): |
259
|
|
|
input_list = ['add NxtomoLoader', |
260
|
|
|
'add AstraReconCpu', |
261
|
|
|
'replace 1 SavuNexusLoader', |
262
|
|
|
'exit', |
263
|
|
|
'y'] |
264
|
|
|
output_checks = ['Exception', 'Error'] |
265
|
|
|
sctu.savu_config_runner(input_list, output_checks, |
266
|
|
|
error_str=True) |
267
|
|
|
|
268
|
|
|
def test_replace_2(self): |
269
|
|
|
input_list = ['add NxtomoLoader', |
270
|
|
|
'add AstraReconCpu', |
271
|
|
|
'replace 1 IncorrectString', |
272
|
|
|
'exit', |
273
|
|
|
'y'] |
274
|
|
|
output_checks = ['Unknown plugin'] |
275
|
|
|
sctu.savu_config_runner(input_list, output_checks) |
276
|
|
|
|
277
|
|
|
def test_run_config(self): |
278
|
|
|
result = subprocess.run(['savu_config', '-h'], stdout=subprocess.PIPE) |
279
|
|
|
str_stdout=str(result.stdout) |
280
|
|
|
if "Create" not in str_stdout: |
281
|
|
|
# Savu_config has failed to load |
282
|
|
|
assert False |
283
|
|
|
|
284
|
|
|
|
285
|
|
|
if __name__ == "__main__": |
286
|
|
|
unittest.main() |
287
|
|
|
|