Back to index

python-biopython  1.60
test_SCOP_Residues.py
Go to the documentation of this file.
00001 # Copyright 2001 by Gavin E. Crooks.  All rights reserved.
00002 # This code is part of the Biopython distribution and governed by its
00003 # license.  Please see the LICENSE file that should have been included
00004 # as part of this package.
00005 
00006 """Unit test for Residues"""
00007 
00008 import unittest
00009 from Bio.SCOP.Residues import *
00010 
00011 
00012 
00013 
00014 class ResiduesTests(unittest.TestCase):
00015     res = (
00016         ( "-",           () ),
00017         ( "A:",          (("A", "", ""),) ),
00018         ( "1:",          (("1", "", ""),) ),
00019         ( "1-100",       (("", "1", "100"),)  ),
00020         ( "B:1-101",     (("B",   "1" ,"101"),) ),
00021         ( "1:1a-100a",   (("1", "1a", "100a"),) ),
00022         ( "a:-100a--1a", (("a", "-100a", "-1a"),) ),
00023         ( "-1-100",      (("", "-1", "100"),) ),
00024         ( "-1-100",      (("", "-1", "100"),) ),
00025         ( "A:12-19,A:23-25", (("A","12","19"),("A","23","25")) ),
00026         ( "12-19,1:23-25", (("","12","19"),("1","23","25")) ),
00027         ( "0-1,1:-1a-25a,T:", (("","0","1"),("1","-1a","25a"),("T","","")) ),
00028         )
00029 
00030 
00031     def testParse(self):
00032         for loc in self.res:
00033             r = Residues(loc[0])
00034             self.assertEqual(r.fragments, loc[1])
00035 
00036     def testStr(self):
00037         for loc in self.res:
00038             r = Residues(loc[0])
00039             self.assertEqual(str(r), loc[0])
00040 
00041     def testAstralParse(self):
00042         """Test if we can parse residue subsets enclosed in brackets"""
00043         for loc in self.res:
00044             r = Residues("("+loc[0]+")")
00045             self.assertEqual(r.fragments, loc[1])
00046 
00047     def testPdbId(self):
00048         pdbid ="1ddf"
00049         for loc in self.res:
00050             r = Residues("\t 1ddf \t"+loc[0]+"\t\n\n\n")
00051             self.assertEqual(r.pdbid, pdbid)
00052             self.assertEqual(str(r), pdbid+" "+loc[0])
00053 
00054             r = Residues(pdbid+" "+loc[0])
00055             self.assertEqual(r.pdbid, pdbid)
00056             self.assertEqual(str(r), pdbid+" "+loc[0])
00057 
00058 
00059             r = Residues("104l A:112-113")
00060             self.assertEqual(r.pdbid, "104l")
00061             self.assertEqual(r.fragments, (('A', '112', '113'),))
00062 
00063             
00064     def testJustPdbId(self):
00065         r = Residues("1sds")
00066         self.assertEqual(r.pdbid, "1sds")
00067         self.assertFalse(r.fragments)
00068 
00069 
00070     def testParseError(self):
00071         self.assertRaises(ValueError, Residues, "09324923423hh./;,.389")
00072 
00073 
00074 
00075 if __name__=='__main__':
00076     runner = unittest.TextTestRunner(verbosity = 2)
00077     unittest.main(testRunner=runner)