RATapi 0.0.0.dev0__cp39-cp39-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. RATapi/__init__.py +8 -0
  2. RATapi/classlist.py +387 -0
  3. RATapi/controls.py +143 -0
  4. RATapi/eventManager.dll +0 -0
  5. RATapi/events.py +70 -0
  6. RATapi/examples/__init__.py +0 -0
  7. RATapi/examples/absorption/__init__.py +0 -0
  8. RATapi/examples/absorption/absorption.py +148 -0
  9. RATapi/examples/absorption/volume_thiol_bilayer.py +138 -0
  10. RATapi/examples/data/D2O_spin_down.dat +100 -0
  11. RATapi/examples/data/D2O_spin_up.dat +101 -0
  12. RATapi/examples/data/DSPC_D2O.dat +82 -0
  13. RATapi/examples/data/DSPC_SMW.dat +82 -0
  14. RATapi/examples/data/H2O_spin_down.dat +102 -0
  15. RATapi/examples/data/H2O_spin_up.dat +102 -0
  16. RATapi/examples/data/__init__.py +0 -0
  17. RATapi/examples/data/c_PLP0016596.dat +146 -0
  18. RATapi/examples/data/c_PLP0016601.dat +97 -0
  19. RATapi/examples/data/c_PLP0016607.dat +104 -0
  20. RATapi/examples/domains/__init__.py +0 -0
  21. RATapi/examples/domains/alloy_domains.py +26 -0
  22. RATapi/examples/domains/domains_XY_model.py +70 -0
  23. RATapi/examples/domains/domains_custom_XY.py +69 -0
  24. RATapi/examples/domains/domains_custom_layers.py +46 -0
  25. RATapi/examples/domains/domains_standard_layers.py +75 -0
  26. RATapi/examples/languages/__init__.py +0 -0
  27. RATapi/examples/languages/custom_bilayer.py +66 -0
  28. RATapi/examples/languages/run_custom_file_languages.py +41 -0
  29. RATapi/examples/languages/setup_problem.py +130 -0
  30. RATapi/examples/non_polarised/DSPC_custom_XY.py +140 -0
  31. RATapi/examples/non_polarised/DSPC_custom_layers.py +121 -0
  32. RATapi/examples/non_polarised/DSPC_standard_layers.py +358 -0
  33. RATapi/examples/non_polarised/__init__.py +0 -0
  34. RATapi/examples/non_polarised/custom_XY_DSPC.py +137 -0
  35. RATapi/examples/non_polarised/custom_bilayer_DSPC.py +85 -0
  36. RATapi/inputs.py +471 -0
  37. RATapi/models.py +288 -0
  38. RATapi/outputs.py +218 -0
  39. RATapi/project.py +659 -0
  40. RATapi/rat_core.cp39-win_amd64.pyd +0 -0
  41. RATapi/run.py +35 -0
  42. RATapi/utils/__init__.py +0 -0
  43. RATapi/utils/custom_errors.py +42 -0
  44. RATapi/utils/enums.py +101 -0
  45. RATapi/utils/plotting.py +211 -0
  46. RATapi/wrappers.py +115 -0
  47. RATapi-0.0.0.dev0.dist-info/METADATA +57 -0
  48. RATapi-0.0.0.dev0.dist-info/RECORD +64 -0
  49. RATapi-0.0.0.dev0.dist-info/WHEEL +5 -0
  50. RATapi-0.0.0.dev0.dist-info/top_level.txt +2 -0
  51. tests/__init__.py +0 -0
  52. tests/conftest.py +4728 -0
  53. tests/test_classlist.py +882 -0
  54. tests/test_controls.py +863 -0
  55. tests/test_custom_errors.py +49 -0
  56. tests/test_events.py +61 -0
  57. tests/test_inputs.py +908 -0
  58. tests/test_models.py +308 -0
  59. tests/test_outputs.py +31 -0
  60. tests/test_plotting.py +167 -0
  61. tests/test_project.py +1387 -0
  62. tests/test_run.py +570 -0
  63. tests/test_wrappers.py +57 -0
  64. tests/utils.py +171 -0
tests/test_run.py ADDED
@@ -0,0 +1,570 @@
1
+ """Test the run module using the example calculation from "DSPC_standard_layers.py".
2
+
3
+ We use the example for both a reflectivity calculation, and Bayesian analysis using the Dream algorithm.
4
+ """
5
+
6
+ from unittest import mock
7
+
8
+ import numpy as np
9
+ import pytest
10
+
11
+ import RATapi
12
+ import RATapi.outputs
13
+ import RATapi.rat_core
14
+ from RATapi.utils.enums import Calculations, Geometries, LayerModels, Procedures
15
+ from tests.utils import check_results_equal
16
+
17
+
18
+ @pytest.fixture
19
+ def input_project():
20
+ """A cut-down version of the input Project object for a reflectivity calculation set out in
21
+ "DSPC_standard_layers.py".
22
+ """
23
+ project = RATapi.Project(
24
+ name="original_dspc_bilayer",
25
+ calculation="non polarised",
26
+ model="standard layers",
27
+ geometry="substrate/liquid",
28
+ absorption=False,
29
+ )
30
+
31
+ # Set up the relevant parameters
32
+ project.parameters.append(
33
+ name="Oxide Thickness",
34
+ min=5.0,
35
+ value=19.54,
36
+ max=60.0,
37
+ fit=True,
38
+ prior_type="uniform",
39
+ mu=0.0,
40
+ sigma=np.inf,
41
+ )
42
+ project.parameters.append(
43
+ name="Oxide SLD",
44
+ min=3.39e-06,
45
+ value=3.39e-06,
46
+ max=3.41e-06,
47
+ fit=False,
48
+ prior_type="uniform",
49
+ mu=0.0,
50
+ sigma=np.inf,
51
+ )
52
+ project.parameters.append(
53
+ name="SAM Tails Thickness",
54
+ min=15.0,
55
+ value=22.66,
56
+ max=40.0,
57
+ fit=True,
58
+ prior_type="uniform",
59
+ mu=0.0,
60
+ sigma=np.inf,
61
+ )
62
+ project.parameters.append(
63
+ name="SAM Tails SLD",
64
+ min=-5e-07,
65
+ value=-4.01e-07,
66
+ max=-3e-07,
67
+ fit=False,
68
+ prior_type="uniform",
69
+ mu=0.0,
70
+ sigma=np.inf,
71
+ )
72
+ project.parameters.append(
73
+ name="SAM Tails Hydration",
74
+ min=1.0,
75
+ value=5.252,
76
+ max=50.0,
77
+ fit=True,
78
+ prior_type="uniform",
79
+ mu=0.0,
80
+ sigma=np.inf,
81
+ )
82
+ project.parameters.append(
83
+ name="SAM Roughness",
84
+ min=1.0,
85
+ value=5.64,
86
+ max=15.0,
87
+ fit=True,
88
+ prior_type="uniform",
89
+ mu=0.0,
90
+ sigma=np.inf,
91
+ )
92
+ project.parameters.append(
93
+ name="CW Thickness",
94
+ min=10.0,
95
+ value=17.12,
96
+ max=28.0,
97
+ fit=True,
98
+ prior_type="uniform",
99
+ mu=0.0,
100
+ sigma=np.inf,
101
+ )
102
+ project.parameters.append(
103
+ name="CW SLD",
104
+ min=0.0,
105
+ value=0.0,
106
+ max=1e-09,
107
+ fit=False,
108
+ prior_type="uniform",
109
+ mu=0.0,
110
+ sigma=np.inf,
111
+ )
112
+ project.parameters.append(
113
+ name="SAM Heads Thickness",
114
+ min=5.0,
115
+ value=8.56,
116
+ max=17.0,
117
+ fit=True,
118
+ prior_type="gaussian",
119
+ mu=10.0,
120
+ sigma=2.0,
121
+ )
122
+ project.parameters.append(
123
+ name="SAM Heads SLD",
124
+ min=1.0e-07,
125
+ value=1.75e-06,
126
+ max=2.0e-06,
127
+ fit=False,
128
+ prior_type="uniform",
129
+ mu=0.0,
130
+ sigma=np.inf,
131
+ )
132
+ project.parameters.append(
133
+ name="SAM Heads Hydration",
134
+ min=10.0,
135
+ value=45.45,
136
+ max=50.0,
137
+ fit=True,
138
+ prior_type="uniform",
139
+ mu=30.0,
140
+ sigma=3.0,
141
+ )
142
+ project.parameters.append(
143
+ name="Bilayer Heads Thickness",
144
+ min=7.0,
145
+ value=10.7,
146
+ max=17.0,
147
+ fit=True,
148
+ prior_type="gaussian",
149
+ mu=10.0,
150
+ sigma=2.0,
151
+ )
152
+ project.parameters.append(
153
+ name="Bilayer Heads SLD",
154
+ min=5.0e-07,
155
+ value=1.47e-06,
156
+ max=1.5e-06,
157
+ fit=False,
158
+ prior_type="uniform",
159
+ mu=0.0,
160
+ sigma=np.inf,
161
+ )
162
+ project.parameters.append(
163
+ name="Bilayer Roughness",
164
+ min=2.0,
165
+ value=6.014,
166
+ max=15.0,
167
+ fit=True,
168
+ prior_type="uniform",
169
+ mu=0.0,
170
+ sigma=np.inf,
171
+ )
172
+ project.parameters.append(
173
+ name="Bilayer Tails Thickness",
174
+ min=14.0,
175
+ value=17.82,
176
+ max=22.0,
177
+ fit=True,
178
+ prior_type="uniform",
179
+ mu=0.0,
180
+ sigma=np.inf,
181
+ )
182
+ project.parameters.append(
183
+ name="Bilayer Tails SLD",
184
+ min=-5.0e-07,
185
+ value=-4.61e-07,
186
+ max=0.0,
187
+ fit=False,
188
+ prior_type="uniform",
189
+ mu=0.0,
190
+ sigma=np.inf,
191
+ )
192
+ project.parameters.append(
193
+ name="Bilayer Tails Hydration",
194
+ min=10.0,
195
+ value=17.64,
196
+ max=50.0,
197
+ fit=True,
198
+ prior_type="uniform",
199
+ mu=0.0,
200
+ sigma=np.inf,
201
+ )
202
+ project.parameters.append(
203
+ name="Bilayer Heads Hydration",
204
+ min=10.0,
205
+ value=36.15,
206
+ max=50.0,
207
+ fit=True,
208
+ prior_type="gaussian",
209
+ mu=30.0,
210
+ sigma=3.0,
211
+ )
212
+ project.parameters.append(
213
+ name="CW Hydration",
214
+ min=99.9,
215
+ value=100.0,
216
+ max=100.0,
217
+ fit=False,
218
+ prior_type="uniform",
219
+ mu=0.0,
220
+ sigma=np.inf,
221
+ )
222
+ project.parameters.append(
223
+ name="Oxide Hydration",
224
+ min=0.0,
225
+ value=23.61,
226
+ max=60.0,
227
+ fit=True,
228
+ prior_type="uniform",
229
+ mu=0.0,
230
+ sigma=np.inf,
231
+ )
232
+
233
+ project.parameters.set_fields(0, max=10)
234
+
235
+ del project.bulk_in[0]
236
+ project.bulk_in.append(name="Silicon", min=2.0e-06, value=2.073e-06, max=2.1e-06, fit=False)
237
+
238
+ del project.bulk_out[0]
239
+ project.bulk_out.append(name="D2O", min=5.50e-06, value=5.98e-06, max=6.4e-06, fit=True)
240
+ project.bulk_out.append(name="SMW", min=1.0e-06, value=2.21e-06, max=4.99e-06, fit=True)
241
+
242
+ del project.scalefactors[0]
243
+ project.scalefactors.append(name="Scalefactor 1", min=0.05, value=0.10, max=0.2, fit=False)
244
+ project.scalefactors.append(name="Scalefactor 2", min=0.05, value=0.15, max=0.2, fit=False)
245
+
246
+ del project.backgrounds[0]
247
+ del project.background_parameters[0]
248
+ project.background_parameters.append(
249
+ name="Background parameter D2O",
250
+ min=5.0e-10,
251
+ value=2.23e-06,
252
+ max=7.0e-06,
253
+ fit=True,
254
+ )
255
+ project.background_parameters.append(
256
+ name="Background parameter SMW",
257
+ min=1.0e-10,
258
+ value=3.38e-06,
259
+ max=4.99e-06,
260
+ fit=True,
261
+ )
262
+
263
+ return project
264
+
265
+
266
+ @pytest.fixture
267
+ def reflectivity_calculation_problem():
268
+ """The output C++ ProblemDefinition object for a reflectivity calculation of the project set out in
269
+ "DSPC_standard_layers.py".
270
+ """
271
+ problem = RATapi.rat_core.ProblemDefinition()
272
+ problem.TF = Calculations.NonPolarised
273
+ problem.modelType = LayerModels.StandardLayers
274
+ problem.geometry = Geometries.SubstrateLiquid
275
+ problem.useImaginary = False
276
+ problem.params = np.array(
277
+ [
278
+ 3.000e00,
279
+ 1.954e01,
280
+ 3.390e-06,
281
+ 2.266e01,
282
+ -4.010e-07,
283
+ 5.252e00,
284
+ 5.640e00,
285
+ 1.712e01,
286
+ 0.000e00,
287
+ 8.560e00,
288
+ 1.750e-06,
289
+ 4.545e01,
290
+ 1.070e01,
291
+ 1.470e-06,
292
+ 6.014e00,
293
+ 1.782e01,
294
+ -4.610e-07,
295
+ 1.764e01,
296
+ 3.615e01,
297
+ 1.000e02,
298
+ 2.361e01,
299
+ ],
300
+ )
301
+ problem.bulkIn = np.array([2.073e-06])
302
+ problem.bulkOut = np.array([5.98e-06, 2.21e-06])
303
+ problem.qzshifts = np.array([0.0])
304
+ problem.scalefactors = np.array([0.1, 0.15])
305
+ problem.domainRatio = np.array([])
306
+ problem.backgroundParams = np.array([2.23e-06, 3.38e-06])
307
+ problem.resolutionParams = np.array([0.03])
308
+ problem.contrastBulkIns = np.array([1.0, 1.0])
309
+ problem.contrastBulkOuts = np.array([1.0, 2.0])
310
+ problem.contrastQzshifts = np.array([0.0, 0.0])
311
+ problem.contrastScalefactors = np.array([1.0, 2.0])
312
+ problem.contrastBackgroundParams = np.array([1.0, 2.0])
313
+ problem.contrastBackgroundActions = np.array([1.0, 1.0])
314
+ problem.contrastResolutionParams = np.array([1.0, 1.0])
315
+ problem.contrastCustomFiles = np.array([np.nan, np.nan])
316
+ problem.contrastDomainRatios = np.array([0.0, 0.0])
317
+ problem.resample = np.array([0.0, 0.0])
318
+ problem.dataPresent = np.array([1.0, 1.0])
319
+ problem.oilChiDataPresent = np.array([0.0, 0.0])
320
+ problem.numberOfContrasts = 2.0
321
+ problem.numberOfLayers = 6.0
322
+ problem.numberOfDomainContrasts = 0.0
323
+ problem.fitParams = np.array(
324
+ [
325
+ 3.000e00,
326
+ 1.954e01,
327
+ 2.266e01,
328
+ 5.252e00,
329
+ 5.640e00,
330
+ 1.712e01,
331
+ 8.560e00,
332
+ 4.545e01,
333
+ 1.070e01,
334
+ 6.014e00,
335
+ 1.782e01,
336
+ 1.764e01,
337
+ 3.615e01,
338
+ 2.361e01,
339
+ 2.230e-06,
340
+ 3.380e-06,
341
+ 5.980e-06,
342
+ 2.210e-06,
343
+ ],
344
+ )
345
+ problem.otherParams = np.array(
346
+ [
347
+ 3.390e-06,
348
+ -4.010e-07,
349
+ 0.000e00,
350
+ 1.750e-06,
351
+ 1.470e-06,
352
+ -4.610e-07,
353
+ 1.000e02,
354
+ 1.000e-01,
355
+ 1.500e-01,
356
+ 2.073e-06,
357
+ 3.000e-02,
358
+ ],
359
+ )
360
+ problem.fitLimits = np.array(
361
+ [
362
+ [1.00e00, 1.00e01],
363
+ [5.00e00, 6.00e01],
364
+ [1.50e01, 3.50e01],
365
+ [1.00e00, 5.00e01],
366
+ [1.00e00, 1.50e01],
367
+ [1.00e01, 2.80e01],
368
+ [5.00e00, 1.70e01],
369
+ [1.00e01, 5.00e01],
370
+ [7.00e00, 1.70e01],
371
+ [2.00e00, 1.50e01],
372
+ [1.40e01, 2.20e01],
373
+ [1.00e01, 5.00e01],
374
+ [1.00e01, 5.00e01],
375
+ [0.00e00, 6.00e01],
376
+ [5.00e-10, 7.00e-06],
377
+ [1.00e-10, 4.99e-06],
378
+ [5.50e-06, 6.40e-06],
379
+ [1.00e-06, 4.99e-06],
380
+ ],
381
+ )
382
+ problem.otherLimits = np.array(
383
+ [
384
+ [3.39e-06, 3.41e-06],
385
+ [-5.00e-07, -3.00e-07],
386
+ [0.00e00, 1.00e-09],
387
+ [1.00e-07, 2.00e-06],
388
+ [5.00e-07, 1.50e-06],
389
+ [-5.00e-07, 0.00e00],
390
+ [9.99e01, 1.00e02],
391
+ [5.00e-02, 2.00e-01],
392
+ [5.00e-02, 2.00e-01],
393
+ [2.00e-06, 2.10e-06],
394
+ [1.00e-02, 5.00e-02],
395
+ ],
396
+ )
397
+
398
+ return problem
399
+
400
+
401
+ @pytest.fixture
402
+ def dream_problem():
403
+ """The output C++ ProblemDefinition object for a Dream optimisation of the project set out in
404
+ "DSPC_standard_layers.py".
405
+
406
+ This optimisation used the parameters: nSamples=50000, nChains=10.
407
+ """
408
+ problem = RATapi.rat_core.ProblemDefinition()
409
+ problem.TF = Calculations.NonPolarised
410
+ problem.modelType = LayerModels.StandardLayers
411
+ problem.geometry = Geometries.SubstrateLiquid
412
+ problem.useImaginary = False
413
+ problem.params = np.array(
414
+ [
415
+ 6.19503045e00,
416
+ 1.84420960e01,
417
+ 3.39000000e-06,
418
+ 2.11039621e01,
419
+ -4.01000000e-07,
420
+ 8.75538121e00,
421
+ 3.72292994e00,
422
+ 1.84624551e01,
423
+ 0.00000000e00,
424
+ 1.02316734e01,
425
+ 1.75000000e-06,
426
+ 2.31156093e01,
427
+ 1.09906265e01,
428
+ 1.47000000e-06,
429
+ 5.71005361e00,
430
+ 1.67933822e01,
431
+ -4.61000000e-07,
432
+ 1.72009856e01,
433
+ 3.00260126e01,
434
+ 1.00000000e02,
435
+ 2.94448999e01,
436
+ ],
437
+ )
438
+ problem.bulkIn = np.array([2.073e-06])
439
+ problem.bulkOut = np.array([6.01489149e-06, 1.59371685e-06])
440
+ problem.qzshifts = np.array([0.0])
441
+ problem.scalefactors = np.array([0.1, 0.15])
442
+ problem.domainRatio = np.array([])
443
+ problem.backgroundParams = np.array([2.37113128e-06, 1.99006694e-06])
444
+ problem.resolutionParams = np.array([0.03])
445
+ problem.contrastBulkIns = np.array([1.0, 1.0])
446
+ problem.contrastBulkOuts = np.array([1.0, 2.0])
447
+ problem.contrastQzshifts = np.array([0.0, 0.0])
448
+ problem.contrastScalefactors = np.array([1.0, 2.0])
449
+ problem.contrastBackgroundParams = np.array([1.0, 2.0])
450
+ problem.contrastBackgroundActions = np.array([1.0, 1.0])
451
+ problem.contrastResolutionParams = np.array([1.0, 1.0])
452
+ problem.contrastCustomFiles = np.array([np.nan, np.nan])
453
+ problem.contrastDomainRatios = np.array([0.0, 0.0])
454
+ problem.resample = np.array([0.0, 0.0])
455
+ problem.dataPresent = np.array([1.0, 1.0])
456
+ problem.oilChiDataPresent = np.array([0.0, 0.0])
457
+ problem.numberOfContrasts = 2.0
458
+ problem.numberOfLayers = 6.0
459
+ problem.numberOfDomainContrasts = 0.0
460
+ problem.fitParams = np.array(
461
+ [
462
+ 6.19503045e00,
463
+ 1.84420960e01,
464
+ 2.11039621e01,
465
+ 8.75538121e00,
466
+ 3.72292994e00,
467
+ 1.84624551e01,
468
+ 1.02316734e01,
469
+ 2.31156093e01,
470
+ 1.09906265e01,
471
+ 5.71005361e00,
472
+ 1.67933822e01,
473
+ 1.72009856e01,
474
+ 3.00260126e01,
475
+ 2.94448999e01,
476
+ 2.37113128e-06,
477
+ 1.99006694e-06,
478
+ 6.01489149e-06,
479
+ 1.59371685e-06,
480
+ ],
481
+ )
482
+ problem.otherParams = np.array(
483
+ [
484
+ 3.390e-06,
485
+ -4.010e-07,
486
+ 0.000e00,
487
+ 1.750e-06,
488
+ 1.470e-06,
489
+ -4.610e-07,
490
+ 1.000e02,
491
+ 1.000e-01,
492
+ 1.500e-01,
493
+ 2.073e-06,
494
+ 3.000e-02,
495
+ 0.000e00,
496
+ ],
497
+ )
498
+ problem.fitLimits = np.array(
499
+ [
500
+ [1.00e00, 1.00e01],
501
+ [5.00e00, 6.00e01],
502
+ [1.50e01, 3.50e01],
503
+ [1.00e00, 5.00e01],
504
+ [1.00e00, 1.50e01],
505
+ [1.00e01, 2.80e01],
506
+ [5.00e00, 1.70e01],
507
+ [1.00e01, 5.00e01],
508
+ [7.00e00, 1.70e01],
509
+ [2.00e00, 1.50e01],
510
+ [1.40e01, 2.20e01],
511
+ [1.00e01, 5.00e01],
512
+ [1.00e01, 5.00e01],
513
+ [0.00e00, 6.00e01],
514
+ [5.00e-10, 7.00e-06],
515
+ [1.00e-10, 4.99e-06],
516
+ [5.50e-06, 6.40e-06],
517
+ [1.00e-06, 4.99e-06],
518
+ ],
519
+ )
520
+ problem.otherLimits = np.array(
521
+ [
522
+ [3.39e-06, 3.41e-06],
523
+ [-5.00e-07, -3.00e-07],
524
+ [0.00e00, 1.00e-09],
525
+ [1.00e-07, 2.00e-06],
526
+ [5.00e-07, 1.50e-06],
527
+ [-5.00e-07, 0.00e00],
528
+ [9.99e01, 1.00e02],
529
+ [5.00e-02, 2.00e-01],
530
+ [5.00e-02, 2.00e-01],
531
+ [2.00e-06, 2.10e-06],
532
+ [1.00e-02, 5.00e-02],
533
+ [0.00e00, 0.00e00],
534
+ ],
535
+ )
536
+
537
+ return problem
538
+
539
+
540
+ @pytest.mark.parametrize(
541
+ ["test_procedure", "test_output_problem", "test_output_results", "test_bayes", "test_results"],
542
+ [
543
+ (
544
+ Procedures.Calculate,
545
+ "reflectivity_calculation_problem",
546
+ "reflectivity_calculation_output_results",
547
+ None,
548
+ "reflectivity_calculation_results",
549
+ ),
550
+ (Procedures.Dream, "dream_problem", "dream_output_results", "dream_bayes", "dream_results"),
551
+ ],
552
+ )
553
+ def test_run(test_procedure, test_output_problem, test_output_results, test_bayes, test_results, request) -> None:
554
+ input_project = request.getfixturevalue("input_project")
555
+ test_output_problem = request.getfixturevalue(test_output_problem)
556
+ test_output_results = request.getfixturevalue(test_output_results)
557
+ if test_bayes:
558
+ test_bayes = request.getfixturevalue(test_bayes)
559
+
560
+ test_results = request.getfixturevalue(test_results)
561
+
562
+ with mock.patch.object(
563
+ RATapi.rat_core,
564
+ "RATMain",
565
+ mock.MagicMock(return_value=(test_output_problem, test_output_results, test_bayes)),
566
+ ):
567
+ # Use default project as we patch RATMain to give the desired outputs
568
+ project, results = RATapi.run(input_project, RATapi.Controls(procedure=test_procedure))
569
+
570
+ check_results_equal(test_results, results)
tests/test_wrappers.py ADDED
@@ -0,0 +1,57 @@
1
+ import pathlib
2
+ from unittest import mock
3
+
4
+ import pytest
5
+
6
+ import RATapi.wrappers
7
+
8
+
9
+ def test_matlab_wrapper() -> None:
10
+ with (
11
+ mock.patch.object(RATapi.wrappers.MatlabWrapper, "loader", None),
12
+ pytest.raises(ImportError),
13
+ ):
14
+ RATapi.wrappers.MatlabWrapper("demo.m")
15
+
16
+ mocked_matlab_future = mock.MagicMock()
17
+ mocked_engine = mock.MagicMock()
18
+ mocked_matlab_future.result.return_value = mocked_engine
19
+ with mock.patch.object(RATapi.wrappers.MatlabWrapper, "loader", mocked_matlab_future):
20
+ wrapper = RATapi.wrappers.MatlabWrapper("demo.m")
21
+ assert wrapper.function_name == "demo"
22
+ mocked_engine.cd.assert_called_once()
23
+ assert pathlib.Path(mocked_engine.cd.call_args[0][0]).samefile(".")
24
+
25
+ handle = wrapper.getHandle()
26
+
27
+ mocked_engine.demo.return_value = ([2], 5)
28
+ result = handle([1], [2], [3], 0)
29
+ assert result == ([2], 5)
30
+ assert wrapper.engine.demo.call_args[0] == ([1], [2], [3], 1)
31
+ mocked_engine.demo.assert_called_once()
32
+
33
+ mocked_engine.demo.return_value = ([3, 1], 7)
34
+ result = handle([4], [5], [6], 1, 1)
35
+ assert result == ([3, 1], 7)
36
+ assert wrapper.engine.demo.call_args[0] == ([4], [5], [6], 2, 2)
37
+ assert mocked_engine.demo.call_count == 2
38
+
39
+
40
+ def test_dylib_wrapper() -> None:
41
+ mocked_engine = mock.MagicMock()
42
+ with mock.patch("RATapi.wrappers.RATapi.rat_core.DylibEngine", mocked_engine):
43
+ wrapper = RATapi.wrappers.DylibWrapper("demo.dylib", "demo")
44
+ mocked_engine.assert_called_once_with("demo.dylib", "demo")
45
+
46
+ wrapper.engine.invoke.return_value = ([2], 5)
47
+ handle = wrapper.getHandle()
48
+ result = handle([1], [2], [3], 0)
49
+ assert result == ([2], 5)
50
+ assert wrapper.engine.invoke.call_args[0] == ([1], [2], [3], 0)
51
+ wrapper.engine.invoke.assert_called_once()
52
+
53
+ wrapper.engine.invoke.return_value = ([3, 1], 7)
54
+ result = handle([4], [5], [6], 1, 1)
55
+ assert result == ([3, 1], 7)
56
+ assert wrapper.engine.invoke.call_args[0] == ([4], [5], [6], 1, 1)
57
+ assert wrapper.engine.invoke.call_count == 2