Author: bugman Date: Tue Mar 13 04:45:47 2007 New Revision: 3166 URL: http://svn.gna.org/viewcvs/relax?rev=3166&view=rev Log: Created the pipe.switch() user function for switching between data pipes. Two unit tests were created for the new code - test_switch() and test_switch_fail(). 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=3166&r1=3165&r2=3166&view=diff ============================================================================== --- 1.3/generic_fns/pipes.py (original) +++ 1.3/generic_fns/pipes.py Tue Mar 13 04:45:47 2007 @@ -99,3 +99,18 @@ # Set the current data pipe to None if it is the deleted data pipe. if relax_data_store.current_pipe == pipe_name: relax_data_store.current_pipe = None + + +def switch(pipe_name=None): + """Switch the current data pipe to the given data pipe. + + @param pipe_name: The name of the data pipe to switch to. + @type pipe_name: str + """ + + # Test if the data pipe exists. + if not relax_data_store.has_key(pipe_name): + raise RelaxNoRunError, pipe_name + + # Switch the current data pipe. + relax_data_store.current_pipe = pipe_name Modified: 1.3/prompt/pipe.py URL: http://svn.gna.org/viewcvs/relax/1.3/prompt/pipe.py?rev=3166&r1=3165&r2=3166&view=diff ============================================================================== --- 1.3/prompt/pipe.py (original) +++ 1.3/prompt/pipe.py Tue Mar 13 04:45:47 2007 @@ -196,3 +196,41 @@ # Execute the functional code. self.__relax__.specific.hybrid.hybridise(hybrid=hybrid, pipes=pipes) + + + def switch(self, pipe_name=None): + """Function for switching between data pipes. + + Keyword Arguments + ~~~~~~~~~~~~~~~~~ + + pipe_name: The name of the data pipe. + + + Description + ~~~~~~~~~~~ + + This function will switch from the current data pipe to the given data pipe. + + + Examples + ~~~~~~~~ + + To switch to the 'ellipsoid' data pipe, type: + + relax> pipe.switch('ellipsoid') + relax> pipe.switch(pipe_name='ellipsoid') + """ + + # Function intro text. + if self.__relax__.interpreter.intro: + text = sys.ps3 + "pipe.switch(" + text = text + "pipe_name=" + `pipe_name` + ")" + print text + + # The data pipe name argument. + if pipe_name != None and type(pipe_name) != str: + raise RelaxNoneStrError, ('data pipe name', pipe_name) + + # Execute the functional code. + pipes.switch(pipe_name=pipe_name) 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=3166&r1=3165&r2=3166&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:45:47 2007 @@ -118,3 +118,32 @@ # Assert that a RelaxNoRunError occurs when the data pipe does not exist. self.assertRaises(RelaxNoRunError, pipes.delete, 'x') + + + def test_switch(self): + """Test the switching of the current data pipe. + + The function tested is generic_fns.pipes.switch(). + """ + + # Switch to the 'orig' data pipe. + pipes.switch('orig') + + # Test the current data pipe. + self.assertEqual(relax_data_store.current_pipe, 'orig') + + # Switch to the 'empty' data pipe. + pipes.switch('empty') + + # Test the current data pipe. + self.assertEqual(relax_data_store.current_pipe, 'empty') + + + def test_switch_fail(self): + """Test the failure of switching to a non-existant data pipe. + + The function used is generic_fns.pipes.switch(). + """ + + # Assert that a RelaxNoRunError occurs when the pipe type is invalid. + self.assertRaises(RelaxNoRunError, pipes.switch, 'x')