mailr3229 - in /1.3: generic_fns/selection.py test_suite/unit_tests/generic_fns/test_selection.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on March 19, 2007 - 06:24:
Author: bugman
Date: Mon Mar 19 06:24:23 2007
New Revision: 3229

URL: http://svn.gna.org/viewcvs/relax?rev=3229&view=rev
Log:
Wrote the generic_fns.selection.tokenise() function and 28 unit tests 
covering the function!

The unit tests attempt to cover all proper and improper combinations of the 
selection string.

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=3229&r1=3228&r2=3229&view=diff
==============================================================================
--- 1.3/generic_fns/selection.py (original)
+++ 1.3/generic_fns/selection.py Mon Mar 19 06:24:23 2007
@@ -22,7 +22,7 @@
 
 # Python module imports.
 from os import F_OK, access
-from re import compile, match
+from re import compile, match, split
 
 # relax module imports.
 from data import Data as relax_data_store
@@ -510,4 +510,94 @@
 
 
 def tokenise(selection):
-    return None, None, None
+    """Split the input selection string returning the mol_token, res_token, 
and spin_token strings.
+
+    The mol_token is identified as the text from the '#' to either the ':' 
or '@' characters or the
+    end of the string.
+
+    The res_token is identified as the text from the ':' to either the '@' 
character or the end of
+    the string.
+
+    The spin_token is identified as the text from the '@' to the end of the 
string.
+
+    @param selection:   The selection identifier.
+    @type selection:    str
+    @return:            The mol_token, res_token, and spin_token.
+    @rtype:             3-tuple of str or None
+    """
+
+    # No selection.
+    if selection == None:
+        return None, None, None
+
+
+    # Atoms.
+    ########
+
+    # Split by '@'.
+    atom_split = split('@', selection)
+
+    # Test that only one '@' character was supplied.
+    if len(atom_split) > 2:
+        raise RelaxError, "Only one '@' character is allowed within the 
selection identifier string."
+
+    # No atom identifier.
+    if len(atom_split) == 1:
+        spin_token = None
+    else:
+        # Test for out of order identifiers.
+        if ':' in atom_split[1]:
+            raise RelaxError, "The atom identifier '@' must come after the 
residue identifier ':'."
+        elif '#' in atom_split[1]:
+            raise RelaxError, "The atom identifier '@' must come after the 
molecule identifier '#'."
+
+        # The token.
+        spin_token = atom_split[1]
+
+
+    # Residues.
+    ###########
+
+    # Split by ':'.
+    res_split = split(':', atom_split[0])
+
+    # Test that only one ':' character was supplied.
+    if len(res_split) > 2:
+        raise RelaxError, "Only one ':' character is allowed within the 
selection identifier string."
+
+    # No residue identifier.
+    if len(res_split) == 1:
+        res_token = None
+    else:
+        # Test for out of order identifiers.
+        if '#' in res_split[1]:
+            raise RelaxError, "The residue identifier ':' must come after 
the molecule identifier '#'."
+
+        # The token.
+        res_token = res_split[1]
+
+
+
+    # Molecules.
+    ############
+
+    # Split by '#'.
+    mol_split = split('#', res_split[0])
+
+    # Test that only one '#' character was supplied.
+    if len(mol_split) > 2:
+        raise RelaxError, "Only one '#' character is allowed within the 
selection identifier string."
+
+    # No molecule identifier.
+    if len(mol_split) == 1:
+        mol_token = None
+    else:
+        mol_token = mol_split[1]
+
+
+    # Improper selection string.
+    if mol_token == None and res_token == None and spin_token == None:
+        raise RelaxError, "The selection string " + `selection` + " is 
invalid."
+
+    # Return the three tokens.
+    return mol_token, res_token, spin_token

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=3229&r1=3228&r2=3229&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 Mon Mar 19 
06:24:23 2007
@@ -26,6 +26,7 @@
 # relax module imports.
 from data import Data as relax_data_store
 from generic_fns import selection
+from relax_errors import RelaxError
 
 
 class Test_selection(TestCase):
@@ -204,3 +205,297 @@
 
             # Increment i.
             i = i + 1
+
+
+    def test_tokenise1(self):
+        """Test the generic_fns.selection.tokenise() function on the string 
'@1'."""
+
+        # Tokenise.
+        mol_token, res_token, spin_token = selection.tokenise('@1')
+
+        # Check the tokens.
+        self.assertEqual(mol_token, None)
+        self.assertEqual(res_token, None)
+        self.assertEqual(spin_token, '1')
+
+
+    def test_tokenise2(self):
+        """Test the generic_fns.selection.tokenise() function on the string 
':-4'."""
+
+        # Tokenise.
+        mol_token, res_token, spin_token = selection.tokenise(':-4')
+
+        # Check the tokens.
+        self.assertEqual(mol_token, None)
+        self.assertEqual(res_token, '-4')
+        self.assertEqual(spin_token, None)
+
+
+    def test_tokenise3(self):
+        """Test the generic_fns.selection.tokenise() function on the string 
'#CaM'."""
+
+        # Tokenise.
+        mol_token, res_token, spin_token = selection.tokenise('#CaM')
+
+        # Check the tokens.
+        self.assertEqual(mol_token, 'CaM')
+        self.assertEqual(res_token, None)
+        self.assertEqual(spin_token, None)
+
+
+    def test_tokenise4(self):
+        """Test the generic_fns.selection.tokenise() function on the string 
':G@N3'."""
+
+        # Tokenise.
+        mol_token, res_token, spin_token = selection.tokenise(':G@N3')
+
+        # Check the tokens.
+        self.assertEqual(mol_token, None)
+        self.assertEqual(res_token, 'G')
+        self.assertEqual(spin_token, 'N3')
+
+
+    def test_tokenise5(self):
+        """Test the generic_fns.selection.tokenise() function on the string 
'#OMP@NH'."""
+
+        # Tokenise.
+        mol_token, res_token, spin_token = selection.tokenise('#OMP@NH')
+
+        # Check the tokens.
+        self.assertEqual(mol_token, 'OMP')
+        self.assertEqual(res_token, None)
+        self.assertEqual(spin_token, 'NH')
+
+
+    def test_tokenise6(self):
+        """Test the generic_fns.selection.tokenise() function on the string 
'#Lyso:20-50'."""
+
+        # Tokenise.
+        mol_token, res_token, spin_token = selection.tokenise('#Lyso:20-50')
+
+        # Check the tokens.
+        self.assertEqual(mol_token, 'Lyso')
+        self.assertEqual(res_token, '20-50')
+        self.assertEqual(spin_token, None)
+
+
+    def test_tokenise7(self):
+        """Test the generic_fns.selection.tokenise() function on the string 
'#Ap4Aase:*@N,CA'."""
+
+        # Tokenise.
+        mol_token, res_token, spin_token = 
selection.tokenise('#Ap4Aase:*@N,CA')
+
+        # Check the tokens.
+        self.assertEqual(mol_token, 'Ap4Aase')
+        self.assertEqual(res_token, '*')
+        self.assertEqual(spin_token, 'N,CA')
+
+
+    def test_tokenise_dup_atom_id_fail1(self):
+        """Test failure of the generic_fns.selection.tokenise() function on 
the string '@N@1'.
+
+        This tests for a duplicated atom identifier.
+        """
+
+        # Tokenise an invalid string.
+        self.assertRaises(RelaxError, selection.tokenise, '@N@1')
+
+
+    def test_tokenise_dup_atom_id_fail2(self):
+        """Test failure of the generic_fns.selection.tokenise() function on 
the string ':*@N@1'.
+
+        This tests for a duplicated atom identifier.
+        """
+
+        # Tokenise an invalid string.
+        self.assertRaises(RelaxError, selection.tokenise, ':*@N@1')
+
+
+    def test_tokenise_dup_atom_id_fail3(self):
+        """Test failure of the generic_fns.selection.tokenise() function on 
the string '@N:*@1'.
+
+        This tests for a duplicated atom identifier.
+        """
+
+        # Tokenise an invalid string.
+        self.assertRaises(RelaxError, selection.tokenise, '@N:*@1')
+
+
+    def test_tokenise_dup_res_id_fail1(self):
+        """Test failure of the generic_fns.selection.tokenise() function on 
the string ':1:2'.
+
+        This tests for a duplicated residue identifier.
+        """
+
+        # Tokenise an invalid string.
+        self.assertRaises(RelaxError, selection.tokenise, ':1:2')
+
+
+    def test_tokenise_dup_res_id_fail2(self):
+        """Test failure of the generic_fns.selection.tokenise() function on 
the string '#None:1:Ala'.
+
+        This tests for a duplicated residue identifier.
+        """
+
+        # Tokenise an invalid string.
+        self.assertRaises(RelaxError, selection.tokenise, '#None:1:Ala')
+
+
+    def test_tokenise_dup_res_id_fail3(self):
+        """Test failure of the generic_fns.selection.tokenise() function on 
the string ':1:Ala@N'.
+
+        This tests for a duplicated residue identifier.
+        """
+
+        # Tokenise an invalid string.
+        self.assertRaises(RelaxError, selection.tokenise, ':1:Ala@N')
+
+
+    def test_tokenise_dup_mol_id_fail1(self):
+        """Test failure of the generic_fns.selection.tokenise() function on 
the string '#A#B'.
+
+        This tests for a duplicated molecule identifier.
+        """
+
+        # Tokenise an invalid string.
+        self.assertRaises(RelaxError, selection.tokenise, '#A#B')
+
+
+    def test_tokenise_dup_mol_id_fail2(self):
+        """Test failure of the generic_fns.selection.tokenise() function on 
the string '#A#B:Leu'.
+
+        This tests for a duplicated molecule identifier.
+        """
+
+        # Tokenise an invalid string.
+        self.assertRaises(RelaxError, selection.tokenise, '#A#B:Leu')
+
+
+    def test_tokenise_dup_mol_id_fail3(self):
+        """Test failure of the generic_fns.selection.tokenise() function on 
the string '#A#C@CA'.
+
+        This tests for a duplicated molecule identifier.
+        """
+
+        # Tokenise an invalid string.
+        self.assertRaises(RelaxError, selection.tokenise, '#A#C@CA')
+
+
+    def test_tokenise_out_of_order_atom_id_fail1(self):
+        """Test failure of the generic_fns.selection.tokenise() function on 
the string '@CA#A'.
+
+        This tests for an out of order '@' identifier.
+        """
+
+        # Tokenise an invalid string.
+        self.assertRaises(RelaxError, selection.tokenise, '@CA#A')
+
+
+    def test_tokenise_out_of_order_atom_id_fail2(self):
+        """Test failure of the generic_fns.selection.tokenise() function on 
the string '@CA:Pro'.
+
+        This tests for an out of order '@' identifier.
+        """
+
+        # Tokenise an invalid string.
+        self.assertRaises(RelaxError, selection.tokenise, '@CA:Pro')
+
+
+    def test_tokenise_out_of_order_atom_id_fail3(self):
+        """Test failure of the generic_fns.selection.tokenise() function on 
the string '@CA#Z:Pro'.
+
+        This tests for an out of order '@' identifier.
+        """
+
+        # Tokenise an invalid string.
+        self.assertRaises(RelaxError, selection.tokenise, '@CA#Z:Pro')
+
+
+    def test_tokenise_out_of_order_res_id_fail1(self):
+        """Test failure of the generic_fns.selection.tokenise() function on 
the string '@CA:Pro'.
+
+        This tests for an out of order ':' identifier.
+        """
+
+        # Tokenise an invalid string.
+        self.assertRaises(RelaxError, selection.tokenise, '@CA:Pro')
+
+
+    def test_tokenise_out_of_order_res_id_fail2(self):
+        """Test failure of the generic_fns.selection.tokenise() function on 
the string ':Glu#X'.
+
+        This tests for an out of order ':' identifier.
+        """
+
+        # Tokenise an invalid string.
+        self.assertRaises(RelaxError, selection.tokenise, ':Glu#X')
+
+
+    def test_tokenise_out_of_order_res_id_fail3(self):
+        """Test failure of the generic_fns.selection.tokenise() function on 
the string '#1@12423:Glu'.
+
+        This tests for an out of order ':' identifier.
+        """
+
+        # Tokenise an invalid string.
+        self.assertRaises(RelaxError, selection.tokenise, ':Glu#X')
+
+
+    def test_tokenise_out_of_order_mol_id_fail1(self):
+        """Test failure of the generic_fns.selection.tokenise() function on 
the string ':1-160#A'.
+
+        This tests for an out of order '#' identifier.
+        """
+
+        # Tokenise an invalid string.
+        self.assertRaises(RelaxError, selection.tokenise, ':1-160#A')
+
+
+    def test_tokenise_out_of_order_mol_id_fail2(self):
+        """Test failure of the generic_fns.selection.tokenise() function on 
the string '@N,CA#A'.
+
+        This tests for an out of order '#' identifier.
+        """
+
+        # Tokenise an invalid string.
+        self.assertRaises(RelaxError, selection.tokenise, '@N,CA#A')
+
+
+    def test_tokenise_out_of_order_mol_id_fail3(self):
+        """Test failure of the generic_fns.selection.tokenise() function on 
the string '@N:-10#Zip'.
+
+        This tests for an out of order '#' identifier.
+        """
+
+        # Tokenise an invalid string.
+        self.assertRaises(RelaxError, selection.tokenise, '@N:-10#Zip')
+
+
+    def test_tokenise_bad_string_fail1(self):
+        """Test failure of the generic_fns.selection.tokenise() function on 
the string '13'.
+
+        This tests for an improper selection string.
+        """
+
+        # Tokenise an invalid string.
+        self.assertRaises(RelaxError, selection.tokenise, '13')
+
+
+    def test_tokenise_bad_string_fail2(self):
+        """Test failure of the generic_fns.selection.tokenise() function on 
the string 'XXX'.
+
+        This tests for an improper selection string.
+        """
+
+        # Tokenise an invalid string.
+        self.assertRaises(RelaxError, selection.tokenise, 'XXX')
+
+
+    def test_tokenise_bad_string_fail3(self):
+        """Test failure of the generic_fns.selection.tokenise() function on 
the string ''.
+
+        This tests for an improper selection string.
+        """
+
+        # Tokenise an invalid string.
+        self.assertRaises(RelaxError, selection.tokenise, '')




Related Messages


Powered by MHonArc, Updated Mon Mar 19 06:40:17 2007