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 testExit(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 testHelpBlank(self): |
27
|
|
|
input_list = ['', 'exit', 'y'] |
28
|
|
|
output_checks = ['help : Display the help information', |
29
|
|
|
'exit : Close the program'] |
30
|
|
|
sctu.savu_config_runner(input_list, output_checks) |
31
|
|
|
|
32
|
|
|
def testHelpCommand(self): |
33
|
|
|
input_list = ['help', 'exit', 'y'] |
34
|
|
|
output_checks = ['help : Display the help information', |
35
|
|
|
'exit : Close the program'] |
36
|
|
|
sctu.savu_config_runner(input_list, output_checks) |
37
|
|
|
|
38
|
|
|
def testAdd(self): |
39
|
|
|
input_list = ['add NxtomoLoader', |
40
|
|
|
'exit', |
41
|
|
|
'y'] |
42
|
|
|
output_checks = ['Exception'] |
43
|
|
|
sctu.savu_config_runner(input_list, output_checks, |
44
|
|
|
error_str=True) |
45
|
|
|
|
46
|
|
|
def testAddMod(self): |
47
|
|
|
input_list = ['add NxtomoLoader', |
48
|
|
|
'disp', |
49
|
|
|
'mod 1.3 Test text', |
50
|
|
|
'exit', |
51
|
|
|
'y'] |
52
|
|
|
output_checks = ['Exception'] |
53
|
|
|
sctu.savu_config_runner(input_list, output_checks, |
54
|
|
|
error_str=True) |
55
|
|
|
|
56
|
|
|
def testAddMod_2(self): |
57
|
|
|
input_list = ['add NxtomoLoader', |
58
|
|
|
'add AstraReconCpu', |
59
|
|
|
'mod 1.4 FBP', |
60
|
|
|
'exit', |
61
|
|
|
'y'] |
62
|
|
|
output_checks = ['Exception'] |
63
|
|
|
sctu.savu_config_runner(input_list, output_checks, |
64
|
|
|
error_str=True) |
65
|
|
|
|
66
|
|
|
def testAddMod_3(self): |
67
|
|
|
# Exception due to invalid parameter number |
68
|
|
|
input_list = ['add NxtomoLoader', |
69
|
|
|
'add AstraReconCpu', |
70
|
|
|
'mod 1.45 FBP', |
71
|
|
|
'exit', |
72
|
|
|
'y'] |
73
|
|
|
output_checks = ['Exception'] |
74
|
|
|
sctu.savu_config_runner(input_list, output_checks, |
75
|
|
|
error_str=True) |
76
|
|
|
|
77
|
|
|
def testAddDupl(self): |
78
|
|
|
# Exception due to invalid plugin number |
79
|
|
|
input_list = ['add NxtomoLoader', |
80
|
|
|
'add AstraReconCpu', |
81
|
|
|
'dupl 3', |
82
|
|
|
'exit', |
83
|
|
|
'y'] |
84
|
|
|
output_checks = ['ValueError'] |
85
|
|
|
sctu.savu_config_runner(input_list, output_checks) |
86
|
|
|
|
87
|
|
|
def testAddDupl_1(self): |
88
|
|
|
input_list = ['add NxtomoLoader', |
89
|
|
|
'add AstraReconCpu', |
90
|
|
|
'dupl 1', |
91
|
|
|
'exit', |
92
|
|
|
'y'] |
93
|
|
|
output_checks = ['Exception', 'Error'] |
94
|
|
|
sctu.savu_config_runner(input_list, output_checks, |
95
|
|
|
error_str=True) |
96
|
|
|
|
97
|
|
|
def testReplace(self): |
98
|
|
|
# Exception due to invalid plugin number |
99
|
|
|
input_list = ['add NxtomoLoader', |
100
|
|
|
'add AstraReconCpu', |
101
|
|
|
'replace 2 TomopyRecon', |
102
|
|
|
'exit', |
103
|
|
|
'y'] |
104
|
|
|
output_checks = ['ValueError'] |
105
|
|
|
sctu.savu_config_runner(input_list, output_checks, |
106
|
|
|
error_str=True) |
107
|
|
|
|
108
|
|
|
def testReplace_1(self): |
109
|
|
|
input_list = ['add NxtomoLoader', |
110
|
|
|
'add AstraReconCpu', |
111
|
|
|
'replace 1 SavuNexusLoader', |
112
|
|
|
'exit', |
113
|
|
|
'y'] |
114
|
|
|
output_checks = ['Exception', 'Error'] |
115
|
|
|
sctu.savu_config_runner(input_list, output_checks, |
116
|
|
|
error_str=True) |
117
|
|
|
|
118
|
|
|
def testReplace_2(self): |
119
|
|
|
input_list = ['add NxtomoLoader', |
120
|
|
|
'add AstraReconCpu', |
121
|
|
|
'replace 1 IncorrectString', |
122
|
|
|
'exit', |
123
|
|
|
'y'] |
124
|
|
|
output_checks = ['Unknown plugin'] |
125
|
|
|
sctu.savu_config_runner(input_list, output_checks) |
126
|
|
|
|
127
|
|
|
def testrunconfig(self): |
128
|
|
|
result = subprocess.run(['savu_config', '-h'], stdout=subprocess.PIPE) |
129
|
|
|
str_stdout=str(result.stdout) |
130
|
|
|
if "Create" not in str_stdout: |
131
|
|
|
# Savu_config has failed to load |
132
|
|
|
assert False |
133
|
|
|
|
134
|
|
|
|
135
|
|
|
if __name__ == "__main__": |
136
|
|
|
unittest.main() |
137
|
|
|
|