Author: bugman Date: Tue Mar 13 04:48:29 2007 New Revision: 3170 URL: http://svn.gna.org/viewcvs/relax?rev=3170&view=rev Log: Implemented the 'pipe.copy()' user function. The 'generic_fns.pipes.copy()' function and the three unit tests 'test_copy', 'test_copy_current', 'test_copy_fail' have been added. Modified: 1.3/generic_fns/pipes.py 1.3/prompt/pipe.py 1.3/test_suite/unit_tests/generic_fns/test_pipes.py Modified: 1.3/generic_fns/pipes.py URL: http://svn.gna.org/viewcvs/relax/1.3/generic_fns/pipes.py?rev=3170&r1=3169&r2=3170&view=diff ============================================================================== --- 1.3/generic_fns/pipes.py (original) +++ 1.3/generic_fns/pipes.py Tue Mar 13 04:48:29 2007 @@ -32,6 +32,30 @@ """Class containing the methods for manipulating data pipes.""" + + +def copy(pipe_from=None, pipe_to=None): + """Copy the contents of the source data pipe to a new target data pipe. + + If the 'pipe_from' argument is None then the current run is assumed as the source. The data + pipe corresponding to 'pipe_to' cannot exist. + + @param pipe_from: The name of the source data pipe to copy the data from. + @type pipe_from: str + @param pipe_to: The name of the target data pipe to copy the data to. + @type pipe_to: str + """ + + # Test if the pipe already exists. + if pipe_to in relax_data_store.keys(): + raise RelaxRunError, pipe_to + + # The current data pipe. + if pipe_from == None: + pipe_from = relax_data_store.current_pipe + + # Copy the data. + relax_data_store[pipe_to] = relax_data_store[pipe_from].__copy__() def create(pipe_name=None, pipe_type=None): Modified: 1.3/prompt/pipe.py URL: http://svn.gna.org/viewcvs/relax/1.3/prompt/pipe.py?rev=3170&r1=3169&r2=3170&view=diff ============================================================================== --- 1.3/prompt/pipe.py (original) +++ 1.3/prompt/pipe.py Tue Mar 13 04:48:29 2007 @@ -40,6 +40,57 @@ # Place relax in the class namespace. self.__relax__ = relax + + + def copy(self, pipe_from=None, pipe_to=None): + """Function for copying a data pipe. + + Keyword Arguments + ~~~~~~~~~~~~~~~~~ + + pipe_from: The name of the source data pipe to copy the data from. + + pipe_to: The name of the target data pipe to copy the data to. + + + Description + ~~~~~~~~~~~ + + This user function allows the contents of a data pipe to be copied. If the 'pipe_from' + keyword argument is set to None the current run is assumed. The data pipe corresponding to + 'pipe_to' must not yet exist. + + + Examples + ~~~~~~~~ + + To copy the contents of the 'm1' data pipe to the 'm2' data pipe, type: + + relax> pipe.copy('m1', 'm2') + relax> pipe.copy(pipe_from='m1', pipe_to='m2') + + If the current data pipe is 'm1', then the following command can be used: + + relax> pipe.copy(pipe_to='m2') + """ + + # Function intro text. + if self.__relax__.interpreter.intro: + text = sys.ps3 + "pipe.copy(" + text = text + "pipe_from=" + `pipe_from` + text = text + "pipe_to=" + `pipe_to` + ")" + print text + + # The source data pipe argument. + if pipe_from != None and type(pipe_from) != str: + raise RelaxNoneStrError, ('data pipe from', pipe_from) + + # The target data pipe argument. + if pipe_to != None and type(pipe_to) != str: + raise RelaxNoneStrError, ('data pipe to', pipe_to) + + # Execute the functional code. + pipes.copy(pipe_from=pipe_from, pipe_to=pipe_to) def create(self, pipe_name=None, pipe_type=None): Modified: 1.3/test_suite/unit_tests/generic_fns/test_pipes.py URL: http://svn.gna.org/viewcvs/relax/1.3/test_suite/unit_tests/generic_fns/test_pipes.py?rev=3170&r1=3169&r2=3170&view=diff ============================================================================== --- 1.3/test_suite/unit_tests/generic_fns/test_pipes.py (original) +++ 1.3/test_suite/unit_tests/generic_fns/test_pipes.py Tue Mar 13 04:48:29 2007 @@ -29,7 +29,7 @@ from data import Data from data.pipe_container import PipeContainer from generic_fns import pipes -from relax_errors import RelaxError, RelaxNoRunError +from relax_errors import RelaxError, RelaxNoRunError, RelaxRunError # The relax data storage object. @@ -56,11 +56,86 @@ relax_data_store['empty'] = PipeContainer() relax_data_store['empty'].pipe_type = 'mf' + # Set the current run to the 'orig' data pipe. + relax_data_store.current_pipe = 'orig' + def tearDown(self): """Reset the relax data storage object.""" relax_data_store.__reset__() + + + def test_copy(self): + """Test the copying of a data pipe. + + The function tested is generic_fns.pipes.copy(). + """ + + # Copy the 'orig' data pipe to the 'new' data pipe. + pipes.copy('orig', 'new') + + # Test that the new data pipe exists. + self.assert_(relax_data_store.has_key('new')) + + # Test that the new data pipe has the object 'x' and that its value is 1. + self.assertEqual(relax_data_store['new'].x, 1) + + # Change the value of x. + relax_data_store['new'].x = 2 + + # Test that the two values are different. + self.assert_(relax_data_store['orig'].x != relax_data_store['new'].x) + + # Test that the new data pipe has the object 'mol[0].res[0].spin[0].num' and that its value is 1. + self.assertEqual(relax_data_store['new'].mol[0].res[0].spin[0].num, 1) + + # Change the spin system number. + relax_data_store['new'].mol[0].res[0].spin[0].num = 2 + + # Test that the original spin system number hasn't changed. + self.assertEqual(relax_data_store['orig'].mol[0].res[0].spin[0].num, 1) + + + def test_copy_current(self): + """Test the copying of current data pipe. + + The function tested is generic_fns.pipes.copy(). + """ + + # Copy the 'orig' data pipe to the 'new' data pipe. + pipes.copy(pipe_to='new') + + # Test that the new data pipe exists. + self.assert_(relax_data_store.has_key('new')) + + # Test that the new data pipe has the object 'x' and that its value is 1. + self.assertEqual(relax_data_store['new'].x, 1) + + # Change the value of x. + relax_data_store['new'].x = 2 + + # Test that the two values are different. + self.assert_(relax_data_store['orig'].x != relax_data_store['new'].x) + + # Test that the new data pipe has the object 'mol[0].res[0].spin[0].num' and that its value is 1. + self.assertEqual(relax_data_store['new'].mol[0].res[0].spin[0].num, 1) + + # Change the spin system number. + relax_data_store['new'].mol[0].res[0].spin[0].num = 2 + + # Test that the original spin system number hasn't changed. + self.assertEqual(relax_data_store['orig'].mol[0].res[0].spin[0].num, 1) + + + def test_copy_fail(self): + """Test the failure of the copying of data pipes when the data pipe to copy to already exists. + + The function tested is generic_fns.pipes.copy() + """ + + # Assert that a RelaxRunError occurs when the data pipe to copy data to already exists. + self.assertRaises(RelaxRunError, pipes.copy, 'orig', 'empty') def test_creation(self):