Trees | Indices | Help |
|
---|
|
1 ############################################################################### 2 # # 3 # Copyright (C) 2007-2011 Edward d'Auvergne # 4 # # 5 # This file is part of the program relax. # 6 # # 7 # relax 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 2 of the License, or # 10 # (at your option) any later version. # 11 # # 12 # relax 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 relax; if not, write to the Free Software # 19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # 20 # # 21 ############################################################################### 22 23 # relax module imports. 24 from data import Relax_data_store; ds = Relax_data_store() 25 from generic_fns import pipes 26 from generic_fns.reset import reset 27 from relax_errors import RelaxError, RelaxNoPipeError, RelaxPipeError 28 from test_suite.unit_tests.base_classes import UnitTestCase 29 3032 """Unit tests for the functions of the 'generic_fns.pipes' module.""" 3324235 """Set up for all the data pipe unit tests.""" 36 37 # Add a data pipe to the data store. 38 ds.add(pipe_name='orig', pipe_type='mf') 39 40 # Add a single object to the 'orig' data pipe. 41 ds['orig'].x = 1 42 43 # Add a single object to the single spin system of the 'orig' data pipe. 44 ds['orig'].mol[0].res[0].spin[0].num = 1 45 46 # Add an empty data pipe (for the 'eliminate_unused_pipes' test). 47 ds.add(pipe_name='empty', pipe_type='mf') 48 49 # Set the current pipe to the 'orig' data pipe. 50 pipes.switch('orig')51 5254 """Test the copying of a data pipe. 55 56 The function tested is generic_fns.pipes.copy(). 57 """ 58 59 # Copy the 'orig' data pipe to the 'new' data pipe. 60 pipes.copy('orig', 'new') 61 62 # Test that the new data pipe exists. 63 self.assert_('new' in ds) 64 65 # Test that the new data pipe has the object 'x' and that its value is 1. 66 self.assertEqual(ds['new'].x, 1) 67 68 # Change the value of x. 69 ds['new'].x = 2 70 71 # Test that the two values are different. 72 self.assert_(ds['orig'].x != ds['new'].x) 73 74 # Test that the new data pipe has the object 'mol[0].res[0].spin[0].num' and that its value is 1. 75 self.assertEqual(ds['new'].mol[0].res[0].spin[0].num, 1) 76 77 # Change the spin system number. 78 ds['new'].mol[0].res[0].spin[0].num = 2 79 80 # Test that the original spin system number hasn't changed. 81 self.assertEqual(ds['orig'].mol[0].res[0].spin[0].num, 1)82 8385 """Test the copying of current data pipe. 86 87 The function tested is generic_fns.pipes.copy(). 88 """ 89 90 # Copy the 'orig' data pipe to the 'new' data pipe. 91 pipes.copy(pipe_to='new') 92 93 # Test that the new data pipe exists. 94 self.assert_('new' in ds) 95 96 # Test that the new data pipe has the object 'x' and that its value is 1. 97 self.assertEqual(ds['new'].x, 1) 98 99 # Change the value of x. 100 ds['new'].x = 2 101 102 # Test that the two values are different. 103 self.assert_(ds['orig'].x != ds['new'].x) 104 105 # Test that the new data pipe has the object 'mol[0].res[0].spin[0].num' and that its value is 1. 106 self.assertEqual(ds['new'].mol[0].res[0].spin[0].num, 1) 107 108 # Change the spin system number. 109 ds['new'].mol[0].res[0].spin[0].num = 2 110 111 # Test that the original spin system number hasn't changed. 112 self.assertEqual(ds['orig'].mol[0].res[0].spin[0].num, 1)113 114116 """Test the failure of the copying of data pipes when the data pipe to copy to already exists. 117 118 The function tested is generic_fns.pipes.copy() 119 """ 120 121 # Assert that a RelaxPipeError occurs when the data pipe to copy data to already exists. 122 self.assertRaises(RelaxPipeError, pipes.copy, 'orig', 'empty')123 124126 """Test the creation of a data pipe. 127 128 The function used is generic_fns.pipes.create(). 129 """ 130 131 # Create a new model-free data pipe. 132 name = 'new' 133 pipes.create(name, 'mf') 134 135 # Test that the data pipe exists. 136 self.assert_(name in ds) 137 138 # Test that the current pipe is the new pipe. 139 self.assertEqual(pipes.cdp_name(), name)140 141143 """Test the failure of the creation of a data pipe (by supplying an incorrect pipe type). 144 145 The function used is generic_fns.pipes.create(). 146 """ 147 148 # Assert that a RelaxError occurs when the pipe type is invalid. 149 self.assertRaises(RelaxError, pipes.create, 'new', 'x')150 151153 """Get the current data pipe. 154 155 The function used is generic_fns.pipes.cdp_name(). 156 """ 157 158 # Test the current pipe. 159 self.assertEqual(pipes.cdp_name(), 'orig')160 161163 """Test the deletion of a data pipe. 164 165 The function tested is generic_fns.pipes.delete() 166 """ 167 168 # Set the current pipe to the 'orig' data pipe. 169 name = 'orig' 170 pipes.switch(name) 171 172 # Delete the 'orig' data pipe. 173 pipes.delete(name) 174 175 # Test that the data pipe no longer exists. 176 self.assert_(name not in ds) 177 178 # Test that the current pipe is None (as the current pipe was deleted). 179 self.assertEqual(pipes.cdp_name(), None)180 181183 """Test the failure of the deletion of a data pipe (by suppling a non-existant data pipe). 184 185 The function tested is generic_fns.pipes.delete() 186 """ 187 188 # Assert that a RelaxNoPipeError occurs when the data pipe does not exist. 189 self.assertRaises(RelaxNoPipeError, pipes.delete, 'x')190 191193 """Test the switching of the current data pipe. 194 195 The function tested is generic_fns.pipes.switch(). 196 """ 197 198 # Switch to the 'orig' data pipe. 199 pipes.switch('orig') 200 201 # Test the current data pipe. 202 self.assertEqual(pipes.cdp_name(), 'orig') 203 204 # Switch to the 'empty' data pipe. 205 pipes.switch('empty') 206 207 # Test the current data pipe. 208 self.assertEqual(pipes.cdp_name(), 'empty')209 210212 """Test the failure of switching to a non-existant data pipe. 213 214 The function used is generic_fns.pipes.switch(). 215 """ 216 217 # Assert that a RelaxNoPipeError occurs when the pipe type is invalid. 218 self.assertRaises(RelaxNoPipeError, pipes.switch, 'x')219 220222 """The throwing of RelaxNoPipeError when the pipe does not exist. 223 224 The function tested is generic_fns.pipes.test(). 225 """ 226 227 # The following should do nothing as the pipes exist. 228 pipes.test() 229 pipes.test('orig') 230 pipes.test('empty') 231 232 # Assert that a RelaxNoPipeError occurs when the pipe doesn't exist. 233 self.assertRaises(RelaxNoPipeError, pipes.test, 'x') 234 235 # Reset relax. 236 reset() 237 238 # Now none of the following pipes exist, hence errors should be thrown. 239 self.assertRaises(RelaxNoPipeError, pipes.test) 240 self.assertRaises(RelaxNoPipeError, pipes.test, 'orig') 241 self.assertRaises(RelaxNoPipeError, pipes.test, 'empty')
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Wed Apr 10 13:32:58 2013 | http://epydoc.sourceforge.net |