1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 from unittest import TestCase
25
26
27 from pipe_control import pipes, spectrometer, value
28 from specific_analyses.relax_disp.data import generate_r20_key, set_exp_type
29 from test_suite.unit_tests.value_testing_base import Value_base_class
30
31
32
34 """Unit tests for the functions of the 'pipe_control.value' module."""
35
36
37 value_fns = value
38
39
41 """First test of the pipe_control.value.partition_params() function."""
42
43
44 pipes.switch('mf')
45
46
47 param = ['s2']
48 val = [0.8]
49
50
51 spin_params, spin_values, other_params, other_values = value.partition_params(val, param)
52
53
54 self.assertEqual(spin_params, ['s2'])
55 self.assertEqual(spin_values, [0.8])
56 self.assertEqual(other_params, [])
57 self.assertEqual(other_values, [])
58
59
61 """Second test of the pipe_control.value.partition_params() function."""
62
63
64 pipes.switch('mf')
65
66
67 param = ['Dx']
68 val = [1e7]
69
70
71 spin_params, spin_values, other_params, other_values = value.partition_params(val, param)
72
73
74 self.assertEqual(spin_params, [])
75 self.assertEqual(spin_values, [])
76 self.assertEqual(other_params, ['Dx'])
77 self.assertEqual(other_values, [1e7])
78
79
81 """Third test of the pipe_control.value.partition_params() function."""
82
83
84 pipes.switch('mf')
85
86
87 param = ['Dx', 's2']
88 val = [1e7, 0.8]
89
90
91 spin_params, spin_values, other_params, other_values = value.partition_params(val, param)
92
93
94 self.assertEqual(spin_params, ['s2'])
95 self.assertEqual(spin_values, [0.8])
96 self.assertEqual(other_params, ['Dx'])
97 self.assertEqual(other_values, [1e7])
98
99
101 """Forth test of the pipe_control.value.partition_params() function."""
102
103
104 pipes.switch('mf')
105
106
107 param = ['Dx', 's2', 'csa']
108 val = [1e7, 0.8, -160e-6]
109
110
111 spin_params, spin_values, other_params, other_values = value.partition_params(val, param)
112
113
114 self.assertEqual(spin_params, ['s2', 'csa'])
115 self.assertEqual(spin_values, [0.8, -160e-6])
116 self.assertEqual(other_params, ['Dx'])
117 self.assertEqual(other_values, [1e7])
118
119
121 """Fifth test of the pipe_control.value.partition_params() function."""
122
123
124 pipes.switch('mf')
125
126
127 param = ['Dpar', 's2', 'Dper', 'csa', 'theta']
128 val = [1e7, 0.8, 2e7, -160e-6, 0.13]
129
130
131 spin_params, spin_values, other_params, other_values = value.partition_params(val, param)
132
133
134 self.assertEqual(spin_params, ['s2', 'csa'])
135 self.assertEqual(spin_values, [0.8, -160e-6])
136 self.assertEqual(other_params, ['Dpar', 'Dper', 'theta'])
137 self.assertEqual(other_values, [1e7, 2e7, 0.13])
138
139
141 """Sixth test of the pipe_control.value.partition_params() function."""
142
143
144 pipes.switch('mf')
145
146
147 param = []
148 val = []
149
150
151 spin_params, spin_values, other_params, other_values = value.partition_params(val, param)
152
153
154 self.assertEqual(spin_params, [])
155 self.assertEqual(spin_values, [])
156 self.assertEqual(other_params, [])
157 self.assertEqual(other_values, [])
158
159
161 """Test of the pipe_control.value.set() function."""
162
163
164 pipes.switch('relax_disp')
165
166
167 exp_type = 'R1rho'
168 frq = 800.1 * 1E6
169
170
171 set_exp_type(spectrum_id='test', exp_type=exp_type)
172
173
174 spectrometer.set_frequency(id='test', frq=frq, units='Hz')
175
176
177 r20_key = generate_r20_key(exp_type=exp_type, frq=frq)
178
179
180 value.set(val=None, param='r2')
181 self.assertEqual(cdp.mol[0].res[0].spin[0].r2[r20_key], 10.0)
182
183
184 value.set(val=None, param='r1')
185 print(cdp.mol[0].res[0].spin[0])
186 self.assertEqual(cdp.mol[0].res[0].spin[0].r1[r20_key], 2.0)
187