1 | #!/usr/bin/env python3 |
---|
2 | |
---|
3 | # pyOASIS - A Python wrapper for OASIS |
---|
4 | # Authors: Philippe Gambron, Rupert Ford |
---|
5 | # Copyright (C) 2019 UKRI - STFC |
---|
6 | |
---|
7 | # This program is free software: you can redistribute it and/or modify |
---|
8 | # it under the terms of the GNU Lesser General Public License as |
---|
9 | # published by the Free Software Foundation, either version 3 of the |
---|
10 | # License, or any later version. |
---|
11 | |
---|
12 | # This program is distributed in the hope that it will be useful, |
---|
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
15 | # GNU Lesser General Public License for more details. |
---|
16 | |
---|
17 | # A copy of the GNU Lesser General Public License, version 3, is supplied |
---|
18 | # with this program, in the file lgpl-3.0.txt. It is also available at |
---|
19 | # <https://www.gnu.org/licenses/lgpl-3.0.html>. |
---|
20 | |
---|
21 | |
---|
22 | import pytest |
---|
23 | import numpy |
---|
24 | import pyoasis |
---|
25 | from mpi4py import MPI |
---|
26 | |
---|
27 | |
---|
28 | # Functions for monkeypatching |
---|
29 | def returns_zero(*args): |
---|
30 | return 0 |
---|
31 | |
---|
32 | def returns_2_zeros(*args): |
---|
33 | return [0, 0] |
---|
34 | |
---|
35 | def returns_error(*args): |
---|
36 | return -1 |
---|
37 | |
---|
38 | def returns_2errors(*args): |
---|
39 | return [-1, -1] |
---|
40 | |
---|
41 | def returns_comm_handle_and_zero(*args): |
---|
42 | return [MPI.COMM_WORLD.py2f(), 0] |
---|
43 | |
---|
44 | def returns_comm_handle_and_error(*args): |
---|
45 | return [MPI.COMM_WORLD.py2f(), -1] |
---|
46 | |
---|
47 | def returns_comm_handle_and_2errors(*args): |
---|
48 | return [MPI.COMM_WORLD.py2f(), -1, -1] |
---|
49 | |
---|
50 | # Compoment class |
---|
51 | # Constructor |
---|
52 | |
---|
53 | # Wrong type for 1st argument |
---|
54 | def test_Component_constructor1(): |
---|
55 | with pytest.raises(pyoasis.PyOasisException): |
---|
56 | pyoasis.mod_oasis_method.init_comp = returns_2_zeros |
---|
57 | pyoasis.mod_oasis_method.terminate = returns_zero |
---|
58 | pyoasis.Component._n_components = 0 |
---|
59 | comp = pyoasis.Component(42, True) |
---|
60 | |
---|
61 | # Wrong type for 2nd argument |
---|
62 | def test_component_constructor2(): |
---|
63 | with pytest.raises(pyoasis.PyOasisException): |
---|
64 | pyoasis.mod_oasis_method.init_comp = returns_2_zeros |
---|
65 | pyoasis.mod_oasis_method.terminate = returns_zero |
---|
66 | pyoasis.Component._n_components = 0 |
---|
67 | comp = pyoasis.Component("name", 42) |
---|
68 | |
---|
69 | # Wrong type for 3rd argument |
---|
70 | def test_component_constructor3(): |
---|
71 | with pytest.raises(pyoasis.PyOasisException): |
---|
72 | pyoasis.mod_oasis_method.init_comp_with_comm = returns_2_zeros |
---|
73 | pyoasis.mod_oasis_method.terminate = returns_zero |
---|
74 | pyoasis.Component._n_components = 0 |
---|
75 | comp = pyoasis.Component("name", True, 42) |
---|
76 | |
---|
77 | # Empty name |
---|
78 | def test_component_constructor4(): |
---|
79 | with pytest.raises(pyoasis.PyOasisException): |
---|
80 | pyoasis.mod_oasis_method.init_comp = returns_2_zeros |
---|
81 | pyoasis.mod_oasis_method.terminate = returns_zero |
---|
82 | pyoasis.Component._n_components = 0 |
---|
83 | comp = pyoasis.Component("") |
---|
84 | |
---|
85 | # 2 components |
---|
86 | def test_component_constructor5(): |
---|
87 | with pytest.raises(pyoasis.PyOasisException): |
---|
88 | pyoasis.mod_oasis_method.init_comp = returns_2_zeros |
---|
89 | pyoasis.mod_oasis_method.terminate=returns_zero |
---|
90 | pyoasis.mod_oasis_auxiliary_routines.get_localcomm = returns_comm_handle_and_zero |
---|
91 | pyoasis.Component._n_components = 0 |
---|
92 | comp1 = pyoasis.Component("component1") |
---|
93 | comp2 = pyoasis.Component("component2") |
---|
94 | |
---|
95 | # Failure |
---|
96 | def test_component_constructor6(): |
---|
97 | with pytest.raises(pyoasis.OasisException): |
---|
98 | pyoasis.mod_oasis_method.init_comp = returns_2errors |
---|
99 | pyoasis.mod_oasis_method.terminate=returns_zero |
---|
100 | pyoasis.Component._n_components = 0 |
---|
101 | comp = pyoasis.Component("name") |
---|
102 | |
---|
103 | # get_localcomm failing in constructor |
---|
104 | def test_component_constructor7(): |
---|
105 | with pytest.raises(pyoasis.OasisException): |
---|
106 | pyoasis.mod_oasis_auxiliary_routines.get_localcomm = returns_comm_handle_and_error |
---|
107 | pyoasis.mod_oasis_method.init_comp = returns_2_zeros |
---|
108 | pyoasis.mod_oasis_method.terminate = returns_zero |
---|
109 | pyoasis.Component._n_components = 0 |
---|
110 | comp = pyoasis.Component("name") |
---|
111 | |
---|
112 | # name |
---|
113 | def test_component_name(): |
---|
114 | pyoasis.mod_oasis_auxiliary_routines.get_localcomm = returns_comm_handle_and_zero |
---|
115 | pyoasis.mod_oasis_method.init_comp = returns_2_zeros |
---|
116 | pyoasis.mod_oasis_method.terminate=returns_zero |
---|
117 | pyoasis.Component._n_components = 0 |
---|
118 | name = "name" |
---|
119 | comp = pyoasis.Component(name) |
---|
120 | assert(comp.name == name) |
---|
121 | |
---|
122 | # __del__ failing |
---|
123 | def test_destructor(): |
---|
124 | with pytest.raises(pyoasis.OasisException): |
---|
125 | pyoasis.mod_oasis_auxiliary_routines.get_localcomm = returns_comm_handle_and_zero |
---|
126 | pyoasis.mod_oasis_method.init_comp = returns_2errors |
---|
127 | pyoasis.mod_oasis_method.terminate = returns_error |
---|
128 | pyoasis.Component._n_components = 0 |
---|
129 | comp = pyoasis.Component("name") |
---|
130 | |
---|
131 | # create_couplcomm |
---|
132 | # Wrong argument type |
---|
133 | def test_component_create_couplcomm(): |
---|
134 | with pytest.raises(pyoasis.PyOasisException): |
---|
135 | pyoasis.mod_oasis_method.init_comp = returns_2_zeros |
---|
136 | pyoasis.mod_oasis_auxiliary_routines.get_localcomm = returns_comm_handle_and_zero |
---|
137 | pyoasis.mod_oasis_auxiliary_routines.create_couplcomm = returns_2_zeros |
---|
138 | pyoasis.mod_oasis_method.terminate = returns_zero |
---|
139 | pyoasis.Component._n_components = 0 |
---|
140 | comp = pyoasis.Component("name") |
---|
141 | couplcomm = comp.create_couplcomm("abc") |
---|
142 | |
---|
143 | # create_couplcomm |
---|
144 | # Failure |
---|
145 | def test_component_create_couplcomm3(): |
---|
146 | with pytest.raises(pyoasis.OasisException): |
---|
147 | pyoasis.mod_oasis_method.init_comp = returns_2_zeros |
---|
148 | pyoasis.mod_oasis_auxiliary_routines.create_couplcomm = returns_2errors |
---|
149 | pyoasis.mod_oasis_method.terminate = returns_zero |
---|
150 | pyoasis.Component._n_components = 0 |
---|
151 | comp = pyoasis.Component("name") |
---|
152 | couplcomm = comp.create_couplcomm(True) |
---|
153 | |
---|
154 | # set_couplcomm |
---|
155 | # Failure |
---|
156 | def test_component_set_couplcomm(): |
---|
157 | with pytest.raises(pyoasis.OasisException): |
---|
158 | pyoasis.mod_oasis_method.init_comp = returns_2_zeros |
---|
159 | pyoasis.mod_oasis_auxiliary_routines.create_couplcomm = returns_2errors |
---|
160 | pyoasis.mod_oasis_method.terminate = returns_zero |
---|
161 | pyoasis.pyoasis.mod_oasis_auxiliary_routines.set_couplcomm = returns_error |
---|
162 | pyoasis.Component._n_components = 0 |
---|
163 | comp = pyoasis.Component("name") |
---|
164 | comp.set_couplcomm(MPI.COMM_NULL) |
---|
165 | |
---|
166 | # get_intracomm |
---|
167 | # Failure |
---|
168 | def test_component_get_intracomm(): |
---|
169 | with pytest.raises(pyoasis.OasisException): |
---|
170 | pyoasis.mod_oasis_method.init_comp = returns_2_zeros |
---|
171 | pyoasis.mod_oasis_auxiliary_routines.create_couplcomm = returns_2errors |
---|
172 | pyoasis.mod_oasis_method.terminate = returns_zero |
---|
173 | pyoasis.mod_oasis_auxiliary_routines.get_intracomm = returns_2errors |
---|
174 | pyoasis.Component._n_components = 0 |
---|
175 | comp = pyoasis.Component("name") |
---|
176 | comp.get_intracomm("othercomponent") |
---|
177 | |
---|
178 | # get_intercomm |
---|
179 | # Failure |
---|
180 | def test_component_set_intercomm(): |
---|
181 | with pytest.raises(pyoasis.OasisException): |
---|
182 | pyoasis.mod_oasis_method.init_comp = returns_2_zeros |
---|
183 | pyoasis.mod_oasis_auxiliary_routines.create_couplcomm = returns_2errors |
---|
184 | pyoasis.mod_oasis_method.terminate = returns_zero |
---|
185 | pyoasis.mod_oasis_auxiliary_routines.get_intercomm = returns_2errors |
---|
186 | pyoasis.Component._n_components = 0 |
---|
187 | comp = pyoasis.Component("name") |
---|
188 | comp.get_intercomm("othercomponent") |
---|
189 | |
---|
190 | # get_multi_intracomm |
---|
191 | # Wrong call arguments (component name is not a strings list) |
---|
192 | def test_component_get_multi_intracomm1(): |
---|
193 | with pytest.raises(pyoasis.PyOasisException): |
---|
194 | pyoasis.mod_oasis_method.init_comp = returns_2_zeros |
---|
195 | pyoasis.mod_oasis_method.terminate = returns_zero |
---|
196 | pyoasis.Component._n_components = 0 |
---|
197 | comp = pyoasis.Component("name") |
---|
198 | comp.get_multi_intracomm(["othercomponent", 42]) |
---|
199 | |
---|
200 | # Wrong call arguments (component name is not a list) |
---|
201 | def test_component_get_multi_intracomm2(): |
---|
202 | with pytest.raises(pyoasis.PyOasisException): |
---|
203 | pyoasis.mod_oasis_method.init_comp = returns_2_zeros |
---|
204 | pyoasis.mod_oasis_method.terminate = returns_zero |
---|
205 | pyoasis.Component._n_components = 0 |
---|
206 | comp = pyoasis.Component("name") |
---|
207 | comp.get_multi_intracomm("othercomponent") |
---|
208 | |
---|
209 | # Failure |
---|
210 | def test_component_get_multi_intracomm3(): |
---|
211 | with pytest.raises(pyoasis.OasisException): |
---|
212 | pyoasis.mod_oasis_method.init_comp = returns_2_zeros |
---|
213 | pyoasis.mod_oasis_method.terminate = returns_zero |
---|
214 | pyoasis.mod_oasis_auxiliary_routines.get_multi_intracomm = returns_comm_handle_and_2errors |
---|
215 | pyoasis.Component._n_components = 0 |
---|
216 | comp = pyoasis.Component("name") |
---|
217 | comp.get_multi_intracomm(["othercomponent", "another"]) |
---|
218 | |
---|
219 | # Various functions |
---|
220 | def test_Component_various_functions(): |
---|
221 | pyoasis.mod_oasis_method.init_comp = returns_2_zeros |
---|
222 | pyoasis.mod_oasis_auxiliary_routines.create_couplcomm = returns_2_zeros |
---|
223 | pyoasis.mod_oasis_method.terminate = returns_zero |
---|
224 | pyoasis.Component._n_components = 0 |
---|
225 | comp = pyoasis.Component("name") |
---|
226 | assert comp._name == "name" |
---|
227 | assert comp.create_couplcomm(True) == 0 |
---|
228 | |
---|
229 | # enddef |
---|
230 | # failure |
---|
231 | def test_Component_enddef(): |
---|
232 | with pytest.raises(pyoasis.OasisException): |
---|
233 | pyoasis.mod_oasis_method.init_comp = returns_2_zeros |
---|
234 | pyoasis.mod_oasis_method.enddef = returns_error |
---|
235 | pyoasis.mod_oasis_method.terminate = returns_zero |
---|
236 | pyoasis.Component._n_components = 0 |
---|
237 | comp = pyoasis.Component("name") |
---|
238 | localcomm = comp.enddef() |
---|
239 | |
---|
240 | # __str__ |
---|
241 | def test_Component_str(): |
---|
242 | pyoasis.mod_oasis_method.init_comp = returns_2_zeros |
---|
243 | pyoasis.mod_oasis_method.terminate = returns_zero |
---|
244 | pyoasis.mod_oasis_method.terminate = returns_zero |
---|
245 | pyoasis.Component._n_components = 0 |
---|
246 | name = "name" |
---|
247 | comp = pyoasis.Component(name) |
---|
248 | line = str(comp) |
---|
249 | assert line.find(comp._name) >=0 |
---|
250 | assert line.find(str(comp._id)) >=0 |
---|
251 | |
---|
252 | |
---|
253 | # SerialPartition |
---|
254 | # Constructor |
---|
255 | |
---|
256 | # Wrong argument type |
---|
257 | def test_SerialPartition_constructor1(): |
---|
258 | with pytest.raises(pyoasis.PyOasisException): |
---|
259 | pyoasis.mod_oasis_part.def_partition = returns_2_zeros |
---|
260 | partition = pyoasis.SerialPartition("abc") |
---|
261 | |
---|
262 | # Wrong argument value |
---|
263 | def test_SerialPartition_constructor2(): |
---|
264 | with pytest.raises(pyoasis.PyOasisException): |
---|
265 | pyoasis.mod_oasis_part.def_partition = returns_2_zeros |
---|
266 | partition = pyoasis.SerialPartition(-1) |
---|
267 | |
---|
268 | # Failure |
---|
269 | def test_SerialPartition_constructor3(): |
---|
270 | with pytest.raises(pyoasis.OasisException): |
---|
271 | pyoasis.mod_oasis_part.def_partition = returns_2errors |
---|
272 | partition = pyoasis.SerialPartition(4) |
---|
273 | |
---|
274 | |
---|
275 | # __str__ |
---|
276 | def test_SerialPartition_str(): |
---|
277 | pyoasis.mod_oasis_method.init_comp = returns_2_zeros |
---|
278 | pyoasis.mod_oasis_part.def_partition = returns_2_zeros |
---|
279 | partition = pyoasis.SerialPartition(4) |
---|
280 | line = str(partition) |
---|
281 | assert line.find(str(partition._id)) >=0 |
---|
282 | |
---|
283 | |
---|
284 | # ApplePartition |
---|
285 | # Constructor |
---|
286 | |
---|
287 | # Wrong 1st argument type |
---|
288 | def test_ApplePartition_constructor1(): |
---|
289 | with pytest.raises(pyoasis.PyOasisException): |
---|
290 | pyoasis.mod_oasis_part.def_partition = returns_2_zeros |
---|
291 | partition = pyoasis.ApplePartition("abc", 4) |
---|
292 | |
---|
293 | # Wrong 2nd argument type |
---|
294 | def test_ApplePartition_constructor2(): |
---|
295 | with pytest.raises(pyoasis.PyOasisException): |
---|
296 | pyoasis.mod_oasis_part.def_partition = returns_2_zeros |
---|
297 | partition = pyoasis.ApplePartition(0, "abc") |
---|
298 | |
---|
299 | # Wrong 1st argument value |
---|
300 | def test_ApplePartition_constructor3(): |
---|
301 | with pytest.raises(pyoasis.PyOasisException): |
---|
302 | pyoasis.mod_oasis_part.def_partition = returns_2_zeros |
---|
303 | partition = pyoasis.ApplePartition(-1, 4) |
---|
304 | |
---|
305 | # Wrong 2nd argument value |
---|
306 | def test_ApplePartition_constructor4(): |
---|
307 | with pytest.raises(pyoasis.PyOasisException): |
---|
308 | pyoasis.mod_oasis_part.def_partition = returns_2_zeros |
---|
309 | partition = pyoasis.ApplePartition(0, -1) |
---|
310 | |
---|
311 | # Failure |
---|
312 | def test_ApplePartition_constructor5(): |
---|
313 | with pytest.raises(pyoasis.OasisException): |
---|
314 | pyoasis.mod_oasis_part.def_partition = returns_2errors |
---|
315 | partition = pyoasis.ApplePartition(0, 4) |
---|
316 | |
---|
317 | # __str__ |
---|
318 | def test_ApplePartition_str(): |
---|
319 | pyoasis.mod_oasis_method.init_comp = returns_2_zeros |
---|
320 | pyoasis.mod_oasis_part.def_partition = returns_2_zeros |
---|
321 | partition = pyoasis.ApplePartition(0, 4) |
---|
322 | line = str(partition) |
---|
323 | assert line.find(str(partition._id)) >=0 |
---|
324 | |
---|
325 | |
---|
326 | # BoxPartition |
---|
327 | # Constructor |
---|
328 | |
---|
329 | # Wrong 1st argument type |
---|
330 | def test_BoxPartition_constructor1(): |
---|
331 | with pytest.raises(pyoasis.PyOasisException): |
---|
332 | pyoasis.mod_oasis_part.def_partition = returns_2_zeros |
---|
333 | partition = pyoasis.BoxPartition("abc", 10, 10, 10) |
---|
334 | |
---|
335 | # Wrong 2nd argument type |
---|
336 | def test_BoxPartition_constructor2(): |
---|
337 | with pytest.raises(pyoasis.PyOasisException): |
---|
338 | pyoasis.mod_oasis_part.def_partition = returns_2_zeros |
---|
339 | partition = pyoasis.BoxPartition(0, "abc", 10, 10) |
---|
340 | |
---|
341 | # Wrong 3rd argument type |
---|
342 | def test_BoxPartition_constructor3(): |
---|
343 | with pytest.raises(pyoasis.PyOasisException): |
---|
344 | pyoasis.mod_oasis_part.def_partition = returns_2_zeros |
---|
345 | partition = pyoasis.BoxPartition(0, 10, "abc", 10) |
---|
346 | |
---|
347 | # Wrong 4th argument type |
---|
348 | def test_BoxPartition_constructor4(): |
---|
349 | with pytest.raises(pyoasis.PyOasisException): |
---|
350 | pyoasis.mod_oasis_part.def_partition = returns_2_zeros |
---|
351 | partition = pyoasis.BoxPartition(0, 10, 10, "abc") |
---|
352 | |
---|
353 | # Wrong 1st argument value |
---|
354 | def test_BoxPartition_constructor5(): |
---|
355 | with pytest.raises(pyoasis.PyOasisException): |
---|
356 | pyoasis.mod_oasis_part.def_partition = returns_2_zeros |
---|
357 | partition = pyoasis.BoxPartition(-1, 10, 10, 10) |
---|
358 | |
---|
359 | # Wrong 2nd argument value |
---|
360 | def test_BoxPartition_constructor6(): |
---|
361 | with pytest.raises(pyoasis.PyOasisException): |
---|
362 | pyoasis.mod_oasis_part.def_partition = returns_2_zeros |
---|
363 | partition = pyoasis.BoxPartition(0, -1, 10, 10) |
---|
364 | |
---|
365 | # Wrong 3rd argument value |
---|
366 | def test_BoxPartition_constructor7(): |
---|
367 | with pytest.raises(pyoasis.PyOasisException): |
---|
368 | pyoasis.mod_oasis_part.def_partition = returns_2_zeros |
---|
369 | partition = pyoasis.BoxPartition(0, 10, -1, 10) |
---|
370 | |
---|
371 | # Wrong 4th argument value |
---|
372 | def test_BoxPartition_constructor8(): |
---|
373 | with pytest.raises(pyoasis.PyOasisException): |
---|
374 | pyoasis.mod_oasis_part.def_partition = returns_2_zeros |
---|
375 | partition = pyoasis.BoxPartition(0, 10, 10, -1) |
---|
376 | |
---|
377 | # Failure |
---|
378 | def test_BoxPartition_constructor9(): |
---|
379 | with pytest.raises(pyoasis.OasisException): |
---|
380 | pyoasis.mod_oasis_part.def_partition = returns_2errors |
---|
381 | partition = pyoasis.BoxPartition(0, 10, 10, 10) |
---|
382 | |
---|
383 | |
---|
384 | # OrangePartition |
---|
385 | # Constructor |
---|
386 | |
---|
387 | # Wrong 1st argument type |
---|
388 | def test_OrangePartition_constructor1(): |
---|
389 | with pytest.raises(pyoasis.PyOasisException): |
---|
390 | pyoasis.mod_oasis_part.def_partition = returns_2_zeros |
---|
391 | partition = pyoasis.OrangePartition("abc", [2, 2]) |
---|
392 | |
---|
393 | # Wrong 1st argument type |
---|
394 | def test_OrangePartition_constructor2(): |
---|
395 | with pytest.raises(pyoasis.PyOasisException): |
---|
396 | pyoasis.mod_oasis_part.def_partition = returns_2_zeros |
---|
397 | partition = pyoasis.OrangePartition(["a", "b"], [2, 2]) |
---|
398 | |
---|
399 | # Wrong 2nd argument type |
---|
400 | def test_OrangePartition_constructor3(): |
---|
401 | with pytest.raises(pyoasis.PyOasisException): |
---|
402 | pyoasis.mod_oasis_part.def_partition = returns_2_zeros |
---|
403 | partition = pyoasis.OrangePartition([0, 0], "abc") |
---|
404 | |
---|
405 | # Wrong 2nd argument type |
---|
406 | def test_OrangePartition_constructor4(): |
---|
407 | with pytest.raises(pyoasis.PyOasisException): |
---|
408 | pyoasis.mod_oasis_part.def_partition = returns_2_zeros |
---|
409 | partition = pyoasis.OrangePartition([0, 2], ["a", "b"]) |
---|
410 | |
---|
411 | # Wrong 1st argument value |
---|
412 | def test_OrangePartition_constructor1(): |
---|
413 | with pytest.raises(pyoasis.PyOasisException): |
---|
414 | pyoasis.mod_oasis_part.def_partition = returns_2_zeros |
---|
415 | partition = pyoasis.OrangePartition([-1, 2], [2, 2]) |
---|
416 | |
---|
417 | # Wrong 2nd argument value |
---|
418 | def test_OrangePartition_constructor2(): |
---|
419 | with pytest.raises(pyoasis.PyOasisException): |
---|
420 | pyoasis.mod_oasis_part.def_partition = returns_2_zeros |
---|
421 | partition = pyoasis.OrangePartition([0, 2], [-1, 2]) |
---|
422 | |
---|
423 | # Inconsistent list sizes |
---|
424 | def test_OrangePartition_constructor3(): |
---|
425 | with pytest.raises(pyoasis.PyOasisException): |
---|
426 | pyoasis.mod_oasis_part.def_partition = returns_2_zeros |
---|
427 | partition = pyoasis.OrangePartition([0, 2, 4], [2, 2]) |
---|
428 | |
---|
429 | # Failure |
---|
430 | def test_OrangePartition_constructor4(): |
---|
431 | with pytest.raises(pyoasis.OasisException): |
---|
432 | pyoasis.mod_oasis_part.def_partition = returns_2errors |
---|
433 | partition = pyoasis.OrangePartition([0, 2], [2, 2]) |
---|
434 | |
---|
435 | |
---|
436 | # PointsPartition |
---|
437 | # Constructor |
---|
438 | |
---|
439 | # Wrong 1st argument type |
---|
440 | def test_PointsPartition_constructor1(): |
---|
441 | with pytest.raises(pyoasis.PyOasisException): |
---|
442 | pyoasis.mod_oasis_part.def_partition = returns_2_zeros |
---|
443 | partition = pyoasis.PointsPartition("abc") |
---|
444 | |
---|
445 | # Wrong 1st argument type |
---|
446 | def test_PointsPartition_constructor2(): |
---|
447 | with pytest.raises(pyoasis.PyOasisException): |
---|
448 | pyoasis.mod_oasis_part.def_partition = returns_2_zeros |
---|
449 | partition = pyoasis.PointsPartition(["abc", 7]) |
---|
450 | |
---|
451 | # Empty list |
---|
452 | def test_PointsPartition_constructor3(): |
---|
453 | with pytest.raises(pyoasis.PyOasisException): |
---|
454 | pyoasis.mod_oasis_part.def_partition = returns_2_zeros |
---|
455 | points = [] |
---|
456 | partition = pyoasis.PointsPartition(points) |
---|
457 | |
---|
458 | # Failure |
---|
459 | def test_PointsPartition_constructor4(): |
---|
460 | with pytest.raises(pyoasis.OasisException): |
---|
461 | pyoasis.mod_oasis_part.def_partition = returns_2errors |
---|
462 | partition = pyoasis.PointsPartition([0, 1]) |
---|
463 | |
---|
464 | |
---|
465 | # Var |
---|
466 | # Constructor |
---|
467 | |
---|
468 | # Wrong type 1st argument |
---|
469 | def test_Var_constructor1(): |
---|
470 | with pytest.raises(pyoasis.PyOasisException): |
---|
471 | pyoasis.mod_oasis_part.def_partition = returns_2_zeros |
---|
472 | pyoasis.mod_oasis_var.def_var = returns_2_zeros |
---|
473 | partition = pyoasis.SerialPartition(4) |
---|
474 | var = pyoasis.Var(42, partition, pyoasis.OasisParameters.OASIS_OUT, 1) |
---|
475 | |
---|
476 | # Wrong type 2nd argument |
---|
477 | def test_Var_constructor2(): |
---|
478 | with pytest.raises(pyoasis.PyOasisException): |
---|
479 | pyoasis.mod_oasis_part.def_partition = returns_2_zeros |
---|
480 | pyoasis.mod_oasis_var.def_var = returns_2_zeros |
---|
481 | partition = pyoasis.SerialPartition(4) |
---|
482 | var = pyoasis.Var("name", 42, pyoasis.OasisParameters.OASIS_OUT, 1) |
---|
483 | |
---|
484 | # Wrong type 3rd argument |
---|
485 | def test_Var_constructor3(): |
---|
486 | with pytest.raises(pyoasis.PyOasisException): |
---|
487 | pyoasis.mod_oasis_part.def_partition = returns_2_zeros |
---|
488 | pyoasis.mod_oasis_var.def_var = returns_2_zeros |
---|
489 | partition = pyoasis.SerialPartition(4) |
---|
490 | var = pyoasis.Var("name", partition, "abc", 1) |
---|
491 | |
---|
492 | # Wrong type 4th argument |
---|
493 | def test_Var_constructor4(): |
---|
494 | with pytest.raises(pyoasis.PyOasisException): |
---|
495 | pyoasis.mod_oasis_part.def_partition = returns_2_zeros |
---|
496 | pyoasis.mod_oasis_var.def_var = returns_2_zeros |
---|
497 | partition = pyoasis.SerialPartition(4) |
---|
498 | var = pyoasis.Var("name", partition, pyoasis.OasisParameters.OASIS_OUT, "abc") |
---|
499 | |
---|
500 | # Wrong value 1st argument |
---|
501 | def test_Var_constructor5(): |
---|
502 | with pytest.raises(pyoasis.PyOasisException): |
---|
503 | pyoasis.mod_oasis_part.def_partition = returns_2_zeros |
---|
504 | pyoasis.mod_oasis_var.def_var = returns_2_zeros |
---|
505 | partition = pyoasis.SerialPartition(4) |
---|
506 | var = pyoasis.Var("", partition, pyoasis.OasisParameters.OASIS_OUT, 1) |
---|
507 | |
---|
508 | # Wrong value 4th argument |
---|
509 | def test_Var_constructor6(): |
---|
510 | with pytest.raises(pyoasis.PyOasisException): |
---|
511 | pyoasis.mod_oasis_part.def_partition = returns_2_zeros |
---|
512 | pyoasis.mod_oasis_var.def_var = returns_2_zeros |
---|
513 | partition = pyoasis.SerialPartition(4) |
---|
514 | var = pyoasis.Var("name", partition, pyoasis.OasisParameters.OASIS_OUT, 0) |
---|
515 | |
---|
516 | # Failure |
---|
517 | def test_Var_constructor8(): |
---|
518 | with pytest.raises(pyoasis.OasisException): |
---|
519 | pyoasis.mod_oasis_part.def_partition = returns_2_zeros |
---|
520 | pyoasis.mod_oasis_var.def_var = returns_2errors |
---|
521 | partition = pyoasis.SerialPartition(4) |
---|
522 | var = pyoasis.Var("name", partition, pyoasis.OasisParameters.OASIS_OUT) |
---|
523 | |
---|
524 | # partition_id < 0 |
---|
525 | def test_Var_constructor9(): |
---|
526 | with pytest.raises(pyoasis.PyOasisException): |
---|
527 | pyoasis.mod_oasis_part.def_partition = returns_2_zeros |
---|
528 | pyoasis.mod_oasis_var.def_var = returns_2_zeros |
---|
529 | partition = pyoasis.SerialPartition(4) |
---|
530 | partition._id=-1 |
---|
531 | var = pyoasis.Var("name", partition, pyoasis.OasisParameters.OASIS_OUT) |
---|
532 | |
---|
533 | #name |
---|
534 | def test_Var_name(): |
---|
535 | pyoasis.mod_oasis_part.def_partition = returns_2_zeros |
---|
536 | pyoasis.mod_oasis_var.def_var = returns_2_zeros |
---|
537 | pyoasis.mod_oasis_getput_interface.put=returns_zero |
---|
538 | partition = pyoasis.SerialPartition(4) |
---|
539 | name = "name" |
---|
540 | var = pyoasis.Var(name, partition, pyoasis.OasisParameters.OASIS_OUT) |
---|
541 | assert(var.name == name) |
---|
542 | |
---|
543 | # put |
---|
544 | # Wrong type 1st argument |
---|
545 | def test_Var_put1(): |
---|
546 | with pytest.raises(pyoasis.PyOasisException): |
---|
547 | pyoasis.mod_oasis_part.def_partition = returns_2_zeros |
---|
548 | pyoasis.mod_oasis_var.def_var = returns_2_zeros |
---|
549 | pyoasis.mod_oasis_getput_interface.put=returns_zero |
---|
550 | partition = pyoasis.SerialPartition(4) |
---|
551 | var = pyoasis.Var("name", partition, pyoasis.OasisParameters.OASIS_OUT) |
---|
552 | field = pyoasis.asarray(range(4)) |
---|
553 | var.put("abc", field) |
---|
554 | |
---|
555 | # Wrong type 2nd argument |
---|
556 | def test_Var_put2(): |
---|
557 | with pytest.raises(pyoasis.PyOasisException): |
---|
558 | pyoasis.mod_oasis_part.def_partition = returns_2_zeros |
---|
559 | pyoasis.mod_oasis_var.def_var = returns_2_zeros |
---|
560 | pyoasis.mod_oasis_getput_interface.put=returns_zero |
---|
561 | partition = pyoasis.SerialPartition(4) |
---|
562 | var = pyoasis.Var("name", partition, pyoasis.OasisParameters.OASIS_OUT) |
---|
563 | field = pyoasis.asarray(range(4)) |
---|
564 | var.put(0, 42) |
---|
565 | |
---|
566 | # Field wrong side |
---|
567 | def test_Var_put4(): |
---|
568 | with pytest.raises(pyoasis.PyOasisException): |
---|
569 | pyoasis.mod_oasis_part.def_partition = returns_2_zeros |
---|
570 | pyoasis.mod_oasis_var.def_var = returns_2_zeros |
---|
571 | pyoasis.mod_oasis_getput_interface.put = returns_zero |
---|
572 | partition = pyoasis.SerialPartition(4) |
---|
573 | var = pyoasis.Var("name", partition, pyoasis.OasisParameters.OASIS_OUT) |
---|
574 | field = pyoasis.asarray(range(4), range(4)) |
---|
575 | var.put(0, field) |
---|
576 | |
---|
577 | # Failure |
---|
578 | def test_Var_put3(): |
---|
579 | with pytest.raises(pyoasis.OasisException): |
---|
580 | pyoasis.mod_oasis_part.def_partition = returns_2_zeros |
---|
581 | pyoasis.mod_oasis_var.def_var = returns_2_zeros |
---|
582 | pyoasis.mod_oasis_getput_interface.put = returns_error |
---|
583 | partition = pyoasis.SerialPartition(4) |
---|
584 | var = pyoasis.Var("name", partition, pyoasis.OasisParameters.OASIS_OUT) |
---|
585 | field = pyoasis.asarray(range(4)) |
---|
586 | var.put(0, field) |
---|
587 | |
---|
588 | # get |
---|
589 | # Wrong type 1st argument |
---|
590 | def test_Var_get1(): |
---|
591 | with pytest.raises(pyoasis.PyOasisException): |
---|
592 | pyoasis.mod_oasis_part.def_partition = returns_2_zeros |
---|
593 | pyoasis.mod_oasis_var.def_var = returns_2_zeros |
---|
594 | pyoasis.mod_oasis_getput_interface.get = returns_zero |
---|
595 | partition = pyoasis.SerialPartition(4) |
---|
596 | var = pyoasis.Var("name", partition, pyoasis.OasisParameters.OASIS_IN) |
---|
597 | field = pyoasis.asarray(numpy.zeros(4)) |
---|
598 | var.get("abc", field) |
---|
599 | |
---|
600 | # Wrong type 2nd argument |
---|
601 | def test_Var_get2(): |
---|
602 | with pytest.raises(pyoasis.PyOasisException): |
---|
603 | pyoasis.mod_oasis_part.def_partition = returns_2_zeros |
---|
604 | pyoasis.mod_oasis_var.def_var = returns_2_zeros |
---|
605 | pyoasis.mod_oasis_getput_interface.get = returns_zero |
---|
606 | partition = pyoasis.SerialPartition(4) |
---|
607 | var = pyoasis.Var("name", partition, pyoasis.OasisParameters.OASIS_IN) |
---|
608 | field = pyoasis.asarray(numpy.zeros(4)) |
---|
609 | var.get(0, 42) |
---|
610 | |
---|
611 | # Failure |
---|
612 | def test_Var_get3(): |
---|
613 | with pytest.raises(pyoasis.OasisException): |
---|
614 | pyoasis.mod_oasis_part.def_partition = returns_2_zeros |
---|
615 | pyoasis.mod_oasis_var.def_var = returns_2_zeros |
---|
616 | pyoasis.mod_oasis_getput_interface.get = returns_error |
---|
617 | partition = pyoasis.SerialPartition(4) |
---|
618 | var = pyoasis.Var("name", partition, pyoasis.OasisParameters.OASIS_IN) |
---|
619 | field = pyoasis.asarray(numpy.zeros(4)) |
---|
620 | var.get(0, field) |
---|
621 | |
---|
622 | # __str__ |
---|
623 | def test_SerialPartition_str(): |
---|
624 | pyoasis.mod_oasis_part.def_partition = returns_2_zeros |
---|
625 | pyoasis.mod_oasis_var.def_var = returns_2_zeros |
---|
626 | pyoasis.mod_oasis_getput_interface.get = returns_zero |
---|
627 | partition = pyoasis.SerialPartition(4) |
---|
628 | var = pyoasis.Var("name", partition, pyoasis.OasisParameters.OASIS_IN) |
---|
629 | line = str(var) |
---|
630 | assert line.find(var._name) >=0 |
---|
631 | assert line.find(str(var._id)) >=0 |
---|
632 | |
---|
633 | # cpl_freqs |
---|
634 | def test_Var_cpl_freqs(): |
---|
635 | with pytest.raises(pyoasis.OasisException): |
---|
636 | pyoasis.mod_oasis_part.def_partition = returns_2_zeros |
---|
637 | pyoasis.mod_oasis_var.def_var = returns_2_zeros |
---|
638 | pyoasis.mod_oasis_auxiliary_routines.get_freqs_array = returns_2errors |
---|
639 | partition = pyoasis.SerialPartition(4) |
---|
640 | var = pyoasis.Var("name", partition, pyoasis.OasisParameters.OASIS_IN) |
---|
641 | var.cpl_freqs |
---|
642 | |
---|
643 | |
---|
644 | # Grid |
---|
645 | # Constructor |
---|
646 | # Grid name empty |
---|
647 | def test_Grid_constructor(): |
---|
648 | with pytest.raises(pyoasis.PyOasisException): |
---|
649 | grid = pyoasis.Grid("", 2, 2, pyoasis.asarray([[1, 2], [3, 4]]), |
---|
650 | pyoasis.asarray([[1, 2], [3, 4]])) |
---|