Package test_suite :: Package unit_tests :: Package _pipe_control :: Module test_value
[hide private]
[frames] | no frames]

Source Code for Module test_suite.unit_tests._pipe_control.test_value

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2007-2013 Edward d'Auvergne                                   # 
  4  # Copyright (C) 2014 Troels E. Linnet                                         # 
  5  #                                                                             # 
  6  # This file is part of the program relax (http://www.nmr-relax.com).          # 
  7  #                                                                             # 
  8  # This program is free software: you can redistribute it and/or modify        # 
  9  # it under the terms of the GNU General Public License as published by        # 
 10  # the Free Software Foundation, either version 3 of the License, or           # 
 11  # (at your option) any later version.                                         # 
 12  #                                                                             # 
 13  # This program is distributed in the hope that it will be useful,             # 
 14  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 15  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 16  # GNU General Public License for more details.                                # 
 17  #                                                                             # 
 18  # You should have received a copy of the GNU General Public License           # 
 19  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
 20  #                                                                             # 
 21  ############################################################################### 
 22   
 23  # Python module imports. 
 24  from unittest import TestCase 
 25   
 26  # relax module imports. 
 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   
33 -class Test_value(Value_base_class, TestCase):
34 """Unit tests for the functions of the 'pipe_control.value' module.""" 35 36 # Place the pipe_control.value module into the class namespace. 37 value_fns = value 38 39
40 - def test_partition_params1(self):
41 """First test of the pipe_control.value.partition_params() function.""" 42 43 # Set the current data pipe to 'mf'. 44 pipes.switch('mf') 45 46 # The parameters and values. 47 param = ['s2'] 48 val = [0.8] 49 50 # Partition. 51 spin_params, spin_values, other_params, other_values = value.partition_params(val, param) 52 53 # Tests. 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
60 - def test_partition_params2(self):
61 """Second test of the pipe_control.value.partition_params() function.""" 62 63 # Set the current data pipe to 'mf'. 64 pipes.switch('mf') 65 66 # The parameters and values. 67 param = ['Dx'] 68 val = [1e7] 69 70 # Partition. 71 spin_params, spin_values, other_params, other_values = value.partition_params(val, param) 72 73 # Tests. 74 self.assertEqual(spin_params, []) 75 self.assertEqual(spin_values, []) 76 self.assertEqual(other_params, ['Dx']) 77 self.assertEqual(other_values, [1e7])
78 79
80 - def test_partition_params3(self):
81 """Third test of the pipe_control.value.partition_params() function.""" 82 83 # Set the current data pipe to 'mf'. 84 pipes.switch('mf') 85 86 # The parameters and values. 87 param = ['Dx', 's2'] 88 val = [1e7, 0.8] 89 90 # Partition. 91 spin_params, spin_values, other_params, other_values = value.partition_params(val, param) 92 93 # Tests. 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
100 - def test_partition_params4(self):
101 """Forth test of the pipe_control.value.partition_params() function.""" 102 103 # Set the current data pipe to 'mf'. 104 pipes.switch('mf') 105 106 # The parameters and values. 107 param = ['Dx', 's2', 'csa'] 108 val = [1e7, 0.8, -160e-6] 109 110 # Partition. 111 spin_params, spin_values, other_params, other_values = value.partition_params(val, param) 112 113 # Tests. 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
120 - def test_partition_params5(self):
121 """Fifth test of the pipe_control.value.partition_params() function.""" 122 123 # Set the current data pipe to 'mf'. 124 pipes.switch('mf') 125 126 # The parameters and values. 127 param = ['Dpar', 's2', 'Dper', 'csa', 'theta'] 128 val = [1e7, 0.8, 2e7, -160e-6, 0.13] 129 130 # Partition. 131 spin_params, spin_values, other_params, other_values = value.partition_params(val, param) 132 133 # Tests. 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
140 - def test_partition_params6(self):
141 """Sixth test of the pipe_control.value.partition_params() function.""" 142 143 # Set the current data pipe to 'mf'. 144 pipes.switch('mf') 145 146 # The parameters and values. 147 param = [] 148 val = [] 149 150 # Partition. 151 spin_params, spin_values, other_params, other_values = value.partition_params(val, param) 152 153 # Tests. 154 self.assertEqual(spin_params, []) 155 self.assertEqual(spin_values, []) 156 self.assertEqual(other_params, []) 157 self.assertEqual(other_values, [])
158 159
160 - def test_value_set_r1_rit(self):
161 """Test of the pipe_control.value.set() function.""" 162 163 # Set the current data pipe to 'mf'. 164 pipes.switch('relax_disp') 165 166 # Set variables. 167 exp_type = 'R1rho' 168 frq = 800.1 * 1E6 169 170 # Set an experiment type to the pipe. 171 set_exp_type(spectrum_id='test', exp_type=exp_type) 172 173 # Set a frequency to loop through. 174 spectrometer.set_frequency(id='test', frq=frq, units='Hz') 175 176 # Generate dic key. 177 r20_key = generate_r20_key(exp_type=exp_type, frq=frq) 178 179 # Set first similar to r2. 180 value.set(val=None, param='r2') 181 self.assertEqual(cdp.mol[0].res[0].spin[0].r2[r20_key], 10.0) 182 183 # Then set for r1. 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