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

Source Code for Module test_suite.unit_tests._pipe_control.test_pipes

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2007-2013 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   
 29   
30 -class Test_pipes(UnitTestCase):
31 """Unit tests for the functions of the 'pipe_control.pipes' module.""" 32
33 - def setUp(self):
34 """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 51
52 - def test_copy(self):
53 """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.assert_('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.assert_(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 82
83 - def test_copy_current(self):
84 """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.assert_('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.assert_(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 113
114 - def test_copy_fail(self):
115 """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 123
124 - def test_creation(self):
125 """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.assert_(name in ds) 136 137 # Test that the current pipe is the new pipe. 138 self.assertEqual(pipes.cdp_name(), name)
139 140
141 - def test_creation_fail(self):
142 """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 150
151 - def test_current(self):
152 """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 160
161 - def test_deletion(self):
162 """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.assert_(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 180
181 - def test_deletion_fail(self):
182 """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 190
191 - def test_switch(self):
192 """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 209
210 - def test_switch_fail(self):
211 """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 219
220 - def test_test(self):
221 """The throwing of RelaxNoPipeError when the pipe does not exist. 222 223 The function tested is pipe_control.pipes.test(). 224 """ 225 226 # The following should do nothing as the pipes exist. 227 pipes.test() 228 pipes.test('orig') 229 pipes.test('empty') 230 231 # Assert that a RelaxNoPipeError occurs when the pipe doesn't exist. 232 self.assertRaises(RelaxNoPipeError, pipes.test, '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.test) 239 self.assertRaises(RelaxNoPipeError, pipes.test, 'orig') 240 self.assertRaises(RelaxNoPipeError, pipes.test, 'empty')
241