|
1
|
|
|
# Copyright 2014 Diamond Light Source Ltd. |
|
2
|
|
|
# |
|
3
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); |
|
4
|
|
|
# you may not use this file except in compliance with the License. |
|
5
|
|
|
# You may obtain a copy of the License at |
|
6
|
|
|
# |
|
7
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0 |
|
8
|
|
|
# |
|
9
|
|
|
# Unless required by applicable law or agreed to in writing, software |
|
10
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, |
|
11
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
12
|
|
|
# See the License for the specific language governing permissions and |
|
13
|
|
|
# limitations under the License. |
|
14
|
|
|
|
|
15
|
|
|
""" |
|
16
|
|
|
.. module:: savu_mod_test |
|
17
|
|
|
:platform: Unix |
|
18
|
|
|
:synopsis: A command line tool for editing process lists |
|
19
|
|
|
|
|
20
|
|
|
.. moduleauthor:: Jessica Verschoyle <[email protected]> |
|
21
|
|
|
|
|
22
|
|
|
""" |
|
23
|
|
|
|
|
24
|
|
|
import unittest |
|
25
|
|
|
|
|
26
|
|
|
import savu.test.test_utils as tu |
|
27
|
|
|
import scripts.savu_mod.savu_mod as sm |
|
28
|
|
|
|
|
29
|
|
|
class SavuModTest(unittest.TestCase): |
|
30
|
|
|
def setUp(self): |
|
31
|
|
|
self.parser = sm.arg_parser(doc=True) |
|
32
|
|
|
# Required arguments below: |
|
33
|
|
|
# plugin number/name |
|
34
|
|
|
# parameter number/name |
|
35
|
|
|
# (optional) plugin index |
|
36
|
|
|
# new parameter value |
|
37
|
|
|
# process list file path |
|
38
|
|
|
|
|
39
|
|
|
def test_invalid_directory(self): |
|
40
|
|
|
parsed = self.parser.parse_args( |
|
41
|
|
|
[ |
|
42
|
|
|
"1", |
|
43
|
|
|
"5", |
|
44
|
|
|
"0.3", |
|
45
|
|
|
tu.get_test_process_path("savu_mod/tomo_false.savu"), |
|
46
|
|
|
] |
|
47
|
|
|
) |
|
48
|
|
|
with self.assertRaises(ValueError): |
|
49
|
|
|
content, content_modified = sm.modify_content(parsed) |
|
50
|
|
|
|
|
51
|
|
|
def test_valid_directory(self): |
|
52
|
|
|
parsed = self.parser.parse_args( |
|
53
|
|
|
[ |
|
54
|
|
|
"1", |
|
55
|
|
|
"5", |
|
56
|
|
|
"0.3", |
|
57
|
|
|
tu.get_test_process_path( |
|
58
|
|
|
"savu_mod/tomo_savu_mod_example.savu" |
|
59
|
|
|
), |
|
60
|
|
|
] |
|
61
|
|
|
) |
|
62
|
|
|
content, content_modified = sm.modify_content(parsed) |
|
63
|
|
|
|
|
64
|
|
|
def test_valid_parameter(self): |
|
65
|
|
|
parsed = self.parser.parse_args( |
|
66
|
|
|
[ |
|
67
|
|
|
"1", |
|
68
|
|
|
"5", |
|
69
|
|
|
"0.3", |
|
70
|
|
|
tu.get_test_process_path( |
|
71
|
|
|
"savu_mod/tomo_savu_mod_example.savu" |
|
72
|
|
|
), |
|
73
|
|
|
] |
|
74
|
|
|
) |
|
75
|
|
|
content, content_modified = sm.modify_content(parsed) |
|
76
|
|
|
|
|
77
|
|
|
def test_valid_parameter_1(self): |
|
78
|
|
|
parsed = self.parser.parse_args( |
|
79
|
|
|
[ |
|
80
|
|
|
"2", |
|
81
|
|
|
"3", |
|
82
|
|
|
"0.3", |
|
83
|
|
|
tu.get_test_process_path( |
|
84
|
|
|
"savu_mod/tomo_savu_mod_example.savu" |
|
85
|
|
|
), |
|
86
|
|
|
] |
|
87
|
|
|
) |
|
88
|
|
|
content, content_modified = sm.modify_content(parsed) |
|
89
|
|
|
|
|
90
|
|
|
def test_invalid_parameter(self): |
|
91
|
|
|
parsed = self.parser.parse_args( |
|
92
|
|
|
[ |
|
93
|
|
|
"1", |
|
94
|
|
|
"95", |
|
95
|
|
|
"0.3", |
|
96
|
|
|
tu.get_test_process_path( |
|
97
|
|
|
"savu_mod/tomo_savu_mod_example.savu" |
|
98
|
|
|
), |
|
99
|
|
|
] |
|
100
|
|
|
) |
|
101
|
|
|
with self.assertRaises(ValueError): |
|
102
|
|
|
content, content_modified = sm.modify_content(parsed) |
|
103
|
|
|
|
|
104
|
|
|
def test_plugin_and_index(self): |
|
105
|
|
|
# If a plugin number is used, then the index becomes irrelevant. |
|
106
|
|
|
# Is an error message needed? |
|
107
|
|
|
parsed = self.parser.parse_args( |
|
108
|
|
|
[ |
|
109
|
|
|
"2", |
|
110
|
|
|
"5", |
|
111
|
|
|
"4", |
|
112
|
|
|
"0.3", |
|
113
|
|
|
tu.get_test_process_path( |
|
114
|
|
|
"savu_mod/tomo_savu_mod_example.savu" |
|
115
|
|
|
), |
|
116
|
|
|
] |
|
117
|
|
|
) |
|
118
|
|
|
content, content_modified = sm.modify_content(parsed) |
|
119
|
|
|
|
|
120
|
|
|
def test_plugin_name_and_index(self): |
|
121
|
|
|
# If a plugin name is used, then the index can fail |
|
122
|
|
|
parsed = self.parser.parse_args( |
|
123
|
|
|
[ |
|
124
|
|
|
"FresnelFilter", |
|
125
|
|
|
"2", |
|
126
|
|
|
"4", |
|
127
|
|
|
"0.3", |
|
128
|
|
|
tu.get_test_process_path( |
|
129
|
|
|
"savu_mod/tomo_savu_mod_example.savu" |
|
130
|
|
|
), |
|
131
|
|
|
] |
|
132
|
|
|
) |
|
133
|
|
|
with self.assertRaises(IndexError): |
|
134
|
|
|
content, content_modified = sm.modify_content(parsed) |
|
135
|
|
|
|
|
136
|
|
|
def test_plugin_name_and_index_1(self): |
|
137
|
|
|
# Use a plugin name |
|
138
|
|
|
parsed = self.parser.parse_args( |
|
139
|
|
|
[ |
|
140
|
|
|
"FresnelFilter", |
|
141
|
|
|
"1", |
|
142
|
|
|
"4", |
|
143
|
|
|
"0.3", |
|
144
|
|
|
tu.get_test_process_path( |
|
145
|
|
|
"savu_mod/tomo_savu_mod_example.savu" |
|
146
|
|
|
), |
|
147
|
|
|
] |
|
148
|
|
|
) |
|
149
|
|
|
content, content_modified = sm.modify_content(parsed) |
|
150
|
|
|
|
|
151
|
|
|
def test_invalid_plugin(self): |
|
152
|
|
|
parsed = self.parser.parse_args( |
|
153
|
|
|
[ |
|
154
|
|
|
"19", |
|
155
|
|
|
"5", |
|
156
|
|
|
"0.3", |
|
157
|
|
|
tu.get_test_process_path( |
|
158
|
|
|
"savu_mod/tomo_savu_mod_example.savu" |
|
159
|
|
|
), |
|
160
|
|
|
] |
|
161
|
|
|
) |
|
162
|
|
|
with self.assertRaises(ValueError): |
|
163
|
|
|
content, content_modified = sm.modify_content(parsed) |
|
164
|
|
|
|
|
165
|
|
|
def test_valid_plugin(self): |
|
166
|
|
|
parsed = self.parser.parse_args( |
|
167
|
|
|
[ |
|
168
|
|
|
"1", |
|
169
|
|
|
"5", |
|
170
|
|
|
"0.3", |
|
171
|
|
|
tu.get_test_process_path( |
|
172
|
|
|
"savu_mod/tomo_savu_mod_example.savu" |
|
173
|
|
|
), |
|
174
|
|
|
] |
|
175
|
|
|
) |
|
176
|
|
|
content, content_modified = sm.modify_content(parsed) |
|
177
|
|
|
|
|
178
|
|
|
def test_invalid_value(self): |
|
179
|
|
|
parsed = self.parser.parse_args( |
|
180
|
|
|
[ |
|
181
|
|
|
"1", |
|
182
|
|
|
"5", |
|
183
|
|
|
'[?""/=+]', |
|
184
|
|
|
tu.get_test_process_path( |
|
185
|
|
|
"savu_mod/tomo_savu_mod_example.savu" |
|
186
|
|
|
), |
|
187
|
|
|
] |
|
188
|
|
|
) |
|
189
|
|
|
content, content_modified = sm.modify_content(parsed) |
|
190
|
|
|
self.assertFalse(content_modified) |
|
191
|
|
|
|
|
192
|
|
|
def test_valid_value(self): |
|
193
|
|
|
parsed = self.parser.parse_args( |
|
194
|
|
|
[ |
|
195
|
|
|
"1", |
|
196
|
|
|
"5", |
|
197
|
|
|
"0.3", |
|
198
|
|
|
tu.get_test_process_path( |
|
199
|
|
|
"savu_mod/tomo_savu_mod_example.savu" |
|
200
|
|
|
), |
|
201
|
|
|
] |
|
202
|
|
|
) |
|
203
|
|
|
content, content_modified = sm.modify_content(parsed) |
|
204
|
|
|
|