Back to index

python-biopython  1.60
test_SCOP_Dom.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 
00007 """Unit test for Dom
00008 
00009 This test requires the mini DOM file 'testDom.txt'
00010 """
00011 
00012 import unittest
00013 
00014 from Bio.SCOP import Dom
00015 
00016 
00017 
00018 
00019 class DomTests(unittest.TestCase):
00020     def setUp(self):
00021         self.filename = './SCOP/testDom.txt'
00022 
00023     def testParse(self):
00024         """Test if all records in a DOM file are being read"""
00025         f = open(self.filename)
00026         try: 
00027             count = 0
00028             for record in Dom.parse(f):
00029                 count +=1
00030             self.assertEqual(count,10)
00031         finally:
00032             f.close()
00033     
00034     def testStr(self):
00035         """Test if we can convert each record to a string correctly"""
00036         f = open(self.filename)
00037         try: 
00038             for line in f:
00039                 record = Dom.Record(line)
00040                 #End of line is platform dependent. Strip it off
00041                 self.assertEqual(str(record).rstrip(),line.rstrip())
00042         finally:
00043             f.close()
00044 
00045     def testError(self):
00046         """Test if a corrupt record raises the appropriate exception"""
00047         corruptDom = "49xxx268\tsp\tb.1.2.1\t-\n"
00048         self.assertRaises(ValueError, Dom.Record, corruptDom)
00049 
00050 
00051     def testRecord(self):
00052         """Test one record in detail"""
00053         recLine = 'd7hbib_\t7hbi\tb:\t1.001.001.001.001.001'
00054 
00055         rec = Dom.Record(recLine)
00056         self.assertEqual(rec.sid, 'd7hbib_')
00057         self.assertEqual(rec.residues.pdbid,'7hbi')
00058         self.assertEqual(rec.residues.fragments,(('b','',''),) )        
00059         self.assertEqual(rec.hierarchy,'1.001.001.001.001.001')
00060 
00061 
00062 
00063 if __name__ == '__main__':
00064     runner = unittest.TextTestRunner(verbosity = 2)
00065     unittest.main(testRunner=runner)