Trees | Indices | Help |
|
---|
|
1 ############################################################################### 2 # # 3 # Copyright (C) 2007-2008,2014 Edward d'Auvergne # 4 # # 5 # This file is part of the program relax (http://www.nmr-relax.com). # 6 # # 7 # This program is free software: you can redistribute it and/or modify # 8 # it under the terms of the GNU General Public License as published by # 9 # the Free Software Foundation, either version 3 of the License, or # 10 # (at your option) 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 General Public License for more details. # 16 # # 17 # You should have received a copy of the GNU General Public License # 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. # 19 # # 20 ############################################################################### 21 22 # relax module imports. 23 from data_store import Relax_data_store; ds = Relax_data_store() 24 from pipe_control import pipes 25 from pipe_control.reset import reset 26 from lib.errors import RelaxError, RelaxNoPipeError, RelaxPipeError 27 from test_suite.unit_tests.base_classes import UnitTestCase 28 2931 """Unit tests for the functions of the 'pipe_control.pipes' module.""" 3224134 """Set up for all the data pipe unit tests.""" 35 36 # Add a data pipe to the data store. 37 ds.add(pipe_name='orig', pipe_type='mf') 38 39 # Add a single object to the 'orig' data pipe. 40 ds['orig'].x = 1 41 42 # Add a single object to the single spin system of the 'orig' data pipe. 43 ds['orig'].mol[0].res[0].spin[0].num = 1 44 45 # Add an empty data pipe (for the 'eliminate_unused_pipes' test). 46 ds.add(pipe_name='empty', pipe_type='mf') 47 48 # Set the current pipe to the 'orig' data pipe. 49 pipes.switch('orig')50 5153 """Test the copying of a data pipe. 54 55 The function tested is pipe_control.pipes.copy(). 56 """ 57 58 # Copy the 'orig' data pipe to the 'new' data pipe. 59 pipes.copy('orig', 'new') 60 61 # Test that the new data pipe exists. 62 self.assertTrue('new' in ds) 63 64 # Test that the new data pipe has the object 'x' and that its value is 1. 65 self.assertEqual(ds['new'].x, 1) 66 67 # Change the value of x. 68 ds['new'].x = 2 69 70 # Test that the two values are different. 71 self.assertTrue(ds['orig'].x != ds['new'].x) 72 73 # Test that the new data pipe has the object 'mol[0].res[0].spin[0].num' and that its value is 1. 74 self.assertEqual(ds['new'].mol[0].res[0].spin[0].num, 1) 75 76 # Change the spin system number. 77 ds['new'].mol[0].res[0].spin[0].num = 2 78 79 # Test that the original spin system number hasn't changed. 80 self.assertEqual(ds['orig'].mol[0].res[0].spin[0].num, 1)81 8284 """Test the copying of current data pipe. 85 86 The function tested is pipe_control.pipes.copy(). 87 """ 88 89 # Copy the 'orig' data pipe to the 'new' data pipe. 90 pipes.copy(pipe_to='new') 91 92 # Test that the new data pipe exists. 93 self.assertTrue('new' in ds) 94 95 # Test that the new data pipe has the object 'x' and that its value is 1. 96 self.assertEqual(ds['new'].x, 1) 97 98 # Change the value of x. 99 ds['new'].x = 2 100 101 # Test that the two values are different. 102 self.assertTrue(ds['orig'].x != ds['new'].x) 103 104 # Test that the new data pipe has the object 'mol[0].res[0].spin[0].num' and that its value is 1. 105 self.assertEqual(ds['new'].mol[0].res[0].spin[0].num, 1) 106 107 # Change the spin system number. 108 ds['new'].mol[0].res[0].spin[0].num = 2 109 110 # Test that the original spin system number hasn't changed. 111 self.assertEqual(ds['orig'].mol[0].res[0].spin[0].num, 1)112 113115 """Test the failure of the copying of data pipes when the data pipe to copy to already exists. 116 117 The function tested is pipe_control.pipes.copy() 118 """ 119 120 # Assert that a RelaxPipeError occurs when the data pipe to copy data to already exists. 121 self.assertRaises(RelaxPipeError, pipes.copy, 'orig', 'empty')122 123125 """Test the creation of a data pipe. 126 127 The function used is pipe_control.pipes.create(). 128 """ 129 130 # Create a new model-free data pipe. 131 name = 'new' 132 pipes.create(name, 'mf') 133 134 # Test that the data pipe exists. 135 self.assertTrue(name in ds) 136 137 # Test that the current pipe is the new pipe. 138 self.assertEqual(pipes.cdp_name(), name)139 140142 """Test the failure of the creation of a data pipe (by supplying an incorrect pipe type). 143 144 The function used is pipe_control.pipes.create(). 145 """ 146 147 # Assert that a RelaxError occurs when the pipe type is invalid. 148 self.assertRaises(RelaxError, pipes.create, 'new', 'x')149 150152 """Get the current data pipe. 153 154 The function used is pipe_control.pipes.cdp_name(). 155 """ 156 157 # Test the current pipe. 158 self.assertEqual(pipes.cdp_name(), 'orig')159 160162 """Test the deletion of a data pipe. 163 164 The function tested is pipe_control.pipes.delete() 165 """ 166 167 # Set the current pipe to the 'orig' data pipe. 168 name = 'orig' 169 pipes.switch(name) 170 171 # Delete the 'orig' data pipe. 172 pipes.delete(name) 173 174 # Test that the data pipe no longer exists. 175 self.assertTrue(name not in ds) 176 177 # Test that the current pipe is None (as the current pipe was deleted). 178 self.assertEqual(pipes.cdp_name(), None)179 180182 """Test the failure of the deletion of a data pipe (by suppling a non-existant data pipe). 183 184 The function tested is pipe_control.pipes.delete() 185 """ 186 187 # Assert that a RelaxNoPipeError occurs when the data pipe does not exist. 188 self.assertRaises(RelaxNoPipeError, pipes.delete, 'x')189 190192 """Test the switching of the current data pipe. 193 194 The function tested is pipe_control.pipes.switch(). 195 """ 196 197 # Switch to the 'orig' data pipe. 198 pipes.switch('orig') 199 200 # Test the current data pipe. 201 self.assertEqual(pipes.cdp_name(), 'orig') 202 203 # Switch to the 'empty' data pipe. 204 pipes.switch('empty') 205 206 # Test the current data pipe. 207 self.assertEqual(pipes.cdp_name(), 'empty')208 209211 """Test the failure of switching to a non-existant data pipe. 212 213 The function used is pipe_control.pipes.switch(). 214 """ 215 216 # Assert that a RelaxNoPipeError occurs when the pipe type is invalid. 217 self.assertRaises(RelaxNoPipeError, pipes.switch, 'x')218 219221 """The throwing of RelaxNoPipeError when the pipe does not exist. 222 223 The function tested is pipe_control.pipes.check_pipe(). 224 """ 225 226 # The following should do nothing as the pipes exist. 227 pipes.check_pipe() 228 pipes.check_pipe('orig') 229 pipes.check_pipe('empty') 230 231 # Assert that a RelaxNoPipeError occurs when the pipe doesn't exist. 232 self.assertRaises(RelaxNoPipeError, pipes.check_pipe, 'x') 233 234 # Reset relax. 235 reset() 236 237 # Now none of the following pipes exist, hence errors should be thrown. 238 self.assertRaises(RelaxNoPipeError, pipes.check_pipe) 239 self.assertRaises(RelaxNoPipeError, pipes.check_pipe, 'orig') 240 self.assertRaises(RelaxNoPipeError, pipes.check_pipe, 'empty')
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Sat Jun 8 10:44:46 2024 | http://epydoc.sourceforge.net |