Author: bugman Date: Tue Nov 20 10:00:10 2007 New Revision: 3609 URL: http://svn.gna.org/viewcvs/relax?rev=3609&view=rev Log: Created, by copying, a base class for testing both the generic_fns and prompt molecule modules. Added: 1.3/test_suite/unit_tests/molecule_testing_base.py - copied, changed from r3608, 1.3/test_suite/unit_tests/generic_fns/test_molecule.py Copied: 1.3/test_suite/unit_tests/molecule_testing_base.py (from r3608, 1.3/test_suite/unit_tests/generic_fns/test_molecule.py) URL: http://svn.gna.org/viewcvs/relax/1.3/test_suite/unit_tests/molecule_testing_base.py?p2=1.3/test_suite/unit_tests/molecule_testing_base.py&p1=1.3/test_suite/unit_tests/generic_fns/test_molecule.py&r1=3608&r2=3609&rev=3609&view=diff ============================================================================== --- 1.3/test_suite/unit_tests/generic_fns/test_molecule.py (original) +++ 1.3/test_suite/unit_tests/molecule_testing_base.py Tue Nov 20 10:00:10 2007 @@ -20,9 +20,6 @@ # # ############################################################################### -# Python module imports. -from unittest import TestCase - # relax module imports. from data import Data as relax_data_store from generic_fns import molecule, residue @@ -30,8 +27,12 @@ -class Test_molecule(TestCase): - """Unit tests for the functions of the 'generic_fns.molecule' module.""" +class Molecule_base_class: + """Base class for the tests of both the 'prompt.molecule' and 'generic_fns.molecule' modules. + + This base class also contains many shared unit tests. + """ + def setUp(self): """Set up for all the molecule unit tests.""" @@ -79,18 +80,18 @@ def test_copy_between_pipes(self): """Test the copying of the molecule data between different data pipes. - The function used is generic_fns.molecule.copy(). + The function tested is both generic_fns.molecule.copy() and prompt.molecule.copy(). """ # Create the first molecule and residue and add some data to its spin container. - molecule.create('Old mol') + self.molecule_fns.create('Old mol') residue.create(1, 'Ala') relax_data_store['orig'].mol[0].res[0].spin[0].num = 111 relax_data_store['orig'].mol[0].res[0].spin[0].x = 1 # Copy the molecule to the second data pipe. - molecule.copy(mol_from='#Old mol', pipe_to='test') - molecule.copy(pipe_from='orig', mol_from='#Old mol', pipe_to='test', mol_to='#New mol') + self.molecule_fns.copy(mol_from='#Old mol', pipe_to='test') + self.molecule_fns.copy(pipe_from='orig', mol_from='#Old mol', pipe_to='test', mol_to='#New mol') # Change the first molecule's data. relax_data_store['orig'].mol[0].res[0].spin[0].num = 222 @@ -121,41 +122,41 @@ def test_copy_between_pipes_fail_no_pipe(self): """Test the failure of copying of the molecule data between different data pipes. - The function used is generic_fns.molecule.copy(). + The function tested is both generic_fns.molecule.copy() and prompt.molecule.copy(). """ # Create the first molecule and residue and add some data to its spin container. - molecule.create('Old mol') + self.molecule_fns.create('Old mol') residue.create(1, 'Ala') relax_data_store['orig'].mol[0].res[0].spin[0].num = 111 relax_data_store['orig'].mol[0].res[0].spin[0].x = 1 # Copy the molecule to the second data pipe. - self.assertRaises(RelaxNoPipeError, molecule.copy, mol_from='#Old mol', pipe_to='test2') + self.assertRaises(RelaxNoPipeError, self.molecule_fns.copy, mol_from='#Old mol', pipe_to='test2') def test_copy_within_pipe(self): """Test the copying of the molecule data within a single data pipe. - The function used is generic_fns.molecule.copy(). + The function tested is both generic_fns.molecule.copy() and prompt.molecule.copy(). """ # Create the first molecule and residue and add some data to its spin container. - molecule.create('Old mol') + self.molecule_fns.create('Old mol') residue.create(1, 'Ala') relax_data_store['orig'].mol[0].res[0].spin[0].num = 111 relax_data_store['orig'].mol[0].res[0].spin[0].x = 1 # Copy the molecule a few times. - molecule.copy(mol_from='#Old mol', mol_to='#2') - molecule.copy(mol_from='#Old mol', pipe_to='orig', mol_to='#3') + self.molecule_fns.copy(mol_from='#Old mol', mol_to='#2') + self.molecule_fns.copy(mol_from='#Old mol', pipe_to='orig', mol_to='#3') # Change the first molecule's data. relax_data_store['orig'].mol[0].res[0].spin[0].num = 222 relax_data_store['orig'].mol[0].res[0].spin[0].x = 2 # Copy the molecule once more. - molecule.copy(mol_from='#Old mol', mol_to='#4') + self.molecule_fns.copy(mol_from='#Old mol', mol_to='#4') # Test the original molecule. self.assertEqual(relax_data_store['orig'].mol[0].name, 'Old mol') @@ -189,30 +190,30 @@ def test_copy_within_pipe_fail(self): """Test the failure of the copying of the molecule data within a molecule. - The function used is generic_fns.molecule.copy(). + The function tested is both generic_fns.molecule.copy() and prompt.molecule.copy(). """ # Create a few molecules. - molecule.create('GST') - molecule.create('GB1') + self.molecule_fns.create('GST') + self.molecule_fns.create('GB1') # Copy a non-existent molecule (MBP). - self.assertRaises(RelaxError, molecule.copy, mol_from='#MBP', mol_to='#IL4') + self.assertRaises(RelaxError, self.molecule_fns.copy, mol_from='#MBP', mol_to='#IL4') # Copy a molecule to one which already exists. - self.assertRaises(RelaxError, molecule.copy, mol_from='#GST', mol_to='#GB1') + self.assertRaises(RelaxError, self.molecule_fns.copy, mol_from='#GST', mol_to='#GB1') def test_creation(self): """Test the creation of a molecule data structure. - The function used is generic_fns.molecule.create(). + The function tested is both generic_fns.molecule.create() and prompt.molecule.create(). """ # Create a few new molecules. - molecule.create('Ap4Aase') - molecule.create('ATP') - molecule.create(mol_name='MgF4') + self.molecule_fns.create('Ap4Aase') + self.molecule_fns.create('ATP') + self.molecule_fns.create(mol_name='MgF4') # Test that the molecule names are correct. self.assertEqual(relax_data_store['orig'].mol[0].name, 'Ap4Aase') @@ -223,27 +224,27 @@ def test_creation_fail(self): """Test the failure of molecule creation by supplying two molecules with the same name. - The function used is generic_fns.molecule.create(). + The function tested is both generic_fns.molecule.create() and prompt.molecule.create(). """ # Create the first molecule. - molecule.create('CaM') + self.molecule_fns.create('CaM') # Assert that a RelaxError occurs when the next added molecule has the same name as the first. - self.assertRaises(RelaxError, molecule.create, 'CaM') + self.assertRaises(RelaxError, self.molecule_fns.create, 'CaM') def test_delete(self): """Test molecule deletion. - The function used is generic_fns.molecule.delete(). + The function tested is both generic_fns.molecule.delete() and prompt.molecule.delete(). """ # Set up some data. self.setup_data() # Delete the first molecule. - molecule.delete(mol_id='#Old mol') + self.molecule_fns.delete(mol_id='#Old mol') # Test that the first molecule is now 'New mol'. self.assertEqual(relax_data_store['orig'].mol[0].name, 'New mol') @@ -260,15 +261,15 @@ def test_delete_all(self): """Test the deletion of all molecules. - The function used is generic_fns.molecule.delete(). + The function tested is both generic_fns.molecule.delete() and prompt.molecule.delete(). """ # Set up some data. self.setup_data() # Delete all molecules. - molecule.delete(mol_id='#Old mol') - molecule.delete(mol_id='#New mol') + self.molecule_fns.delete(mol_id='#Old mol') + self.molecule_fns.delete(mol_id='#New mol') # Test that the first molecule defaults back to the empty container. self.assertEqual(relax_data_store['orig'].mol[0].name, None) @@ -281,56 +282,56 @@ def test_delete_fail(self): """Test the failure of molecule deletion when a residue or spin id is supplied. - The function used is generic_fns.molecule.delete(). + The function tested is both generic_fns.molecule.delete() and prompt.molecule.delete(). """ # Supply a spin id. - self.assertRaises(RelaxSpinSelectDisallowError, molecule.delete, mol_id='@2') + self.assertRaises(RelaxSpinSelectDisallowError, self.molecule_fns.delete, mol_id='@2') # Supply a residue id. - self.assertRaises(RelaxResSelectDisallowError, molecule.delete, mol_id=':1') + self.assertRaises(RelaxResSelectDisallowError, self.molecule_fns.delete, mol_id=':1') def test_display(self): """Test the display of molecular information. - The function used is generic_fns.molecule.display(). + The function tested is both generic_fns.molecule.display() and prompt.molecule.display(). """ # Set up some data. self.setup_data() # The following should all work without error. - molecule.display() - molecule.display('#Old mol') - molecule.display(mol_id='#New mol') + self.molecule_fns.display() + self.molecule_fns.display('#Old mol') + self.molecule_fns.display(mol_id='#New mol') def test_display_fail(self): """Test the failure of the display of molecule information. - The function used is generic_fns.molecule.display(). + The function tested is both generic_fns.molecule.display() and prompt.molecule.display(). """ # Set up some data. self.setup_data() # The following should fail. - self.assertRaises(RelaxSpinSelectDisallowError, molecule.display, '@N') - self.assertRaises(RelaxResSelectDisallowError, molecule.display, ':1') + self.assertRaises(RelaxSpinSelectDisallowError, self.molecule_fns.display, '@N') + self.assertRaises(RelaxResSelectDisallowError, self.molecule_fns.display, ':1') def test_rename(self): """Test the renaming of a molecule. - The function tested is generic_fns.molecule.rename(). + The function tested is both generic_fns.molecule.rename() and prompt.molecule.rename(). """ # Set up some data. self.setup_data() # Rename the molecule. - molecule.rename(mol_id='#New mol', new_name='K') + self.molecule_fns.rename(mol_id='#New mol', new_name='K') # Test that the molecule has been renamed. self.assertEqual(relax_data_store['orig'].mol[1].name, 'K') @@ -339,24 +340,24 @@ def test_rename_fail(self): """Test the failure of renaming a molecule when a residue or spin id is given. - The function tested is generic_fns.molecule.rename(). + The function tested is both generic_fns.molecule.rename() and prompt.molecule.rename(). """ # Try renaming using a spin id. - self.assertRaises(RelaxSpinSelectDisallowError, molecule.rename, mol_id='@111', new_name='K') + self.assertRaises(RelaxSpinSelectDisallowError, self.molecule_fns.rename, mol_id='@111', new_name='K') # Try renaming using a residue id. - self.assertRaises(RelaxResSelectDisallowError, molecule.rename, mol_id=':1', new_name='K') + self.assertRaises(RelaxResSelectDisallowError, self.molecule_fns.rename, mol_id=':1', new_name='K') def test_rename_many_fail(self): """Test the failure of the renaming of multiple molecules to the same name. - The function used is generic_fns.molecule.rename(). + The function tested is both generic_fns.molecule.rename() and prompt.molecule.rename(). """ # Set up some data. self.setup_data() # Test for the failure. - self.assertRaises(RelaxError, molecule.rename, mol_id='#Old mol,New mol', new_name='K') + self.assertRaises(RelaxError, self.molecule_fns.rename, mol_id='#Old mol,New mol', new_name='K')