Author: bugman Date: Sun Nov 4 13:19:36 2007 New Revision: 3396 URL: http://svn.gna.org/viewcvs/relax?rev=3396&view=rev Log: Added two unit tests for the generic_fns.selection.return_molecule() function. Also made the function fail properly when no data pipe exists. Modified: 1.3/generic_fns/selection.py 1.3/test_suite/unit_tests/generic_fns/test_selection.py Modified: 1.3/generic_fns/selection.py URL: http://svn.gna.org/viewcvs/relax/1.3/generic_fns/selection.py?rev=3396&r1=3395&r2=3396&view=diff ============================================================================== --- 1.3/generic_fns/selection.py (original) +++ 1.3/generic_fns/selection.py Sun Nov 4 13:19:36 2007 @@ -466,6 +466,10 @@ if pipe == None: pipe = relax_data_store.current_pipe + # Test that the data pipe exists. + if pipe not in relax_data_store.keys(): + raise RelaxNoRunError, pipe + # Parse the selection string. select_obj = Selection(selection) Modified: 1.3/test_suite/unit_tests/generic_fns/test_selection.py URL: http://svn.gna.org/viewcvs/relax/1.3/test_suite/unit_tests/generic_fns/test_selection.py?rev=3396&r1=3395&r2=3396&view=diff ============================================================================== --- 1.3/test_suite/unit_tests/generic_fns/test_selection.py (original) +++ 1.3/test_suite/unit_tests/generic_fns/test_selection.py Sun Nov 4 13:19:36 2007 @@ -306,6 +306,34 @@ self.assertEqual(i, 5) + def test_return_molecule(self): + """Test the function for returning the desired molecule data container. + + The function tested is generic_fns.selection.return_molecule(). + """ + + # Ask for a few molecules. + mol1 = selection.return_molecule('#Ap4Aase') + mol2 = selection.return_molecule(selection='#RNA', pipe='orig') + + # Test the data of molecule 1. + self.assertEqual(mol1.name, 'Ap4Aase') + + # Test the data of molecule 2. + self.assertEqual(mol2.name, 'RNA') + + + def test_return_molecule_pipe_fail(self): + """Test the failure of the function for returning the desired molecule data container. + + The function tested is generic_fns.selection.return_molecule(). + """ + + # Try to get a molecule from a missing data pipe. + self.assertRaises(RelaxNoRunError, selection.return_molecule, selection='#Ap4Aase', pipe='new') + self.assertRaises(RelaxNoRunError, selection.return_molecule, selection='#RNA', pipe='new') + + def test_return_residue(self): """Test the function for returning the desired residue data container.