Back to index

python-biopython  1.60
test_SCOP_Des.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 Des"""
00008 
00009 import unittest
00010 
00011 from Bio.SCOP import Des
00012 
00013 
00014 
00015 class DesTests(unittest.TestCase):
00016 
00017     def setUp(self):
00018         self.filename = './SCOP/dir.des.scop.txt_test'
00019 
00020     def testParse(self):
00021         """Test if all records in a DES file are being read"""
00022         f = open(self.filename)
00023         try: 
00024             count = 0
00025             records = Des.parse(f)
00026             for record in records:
00027                 count +=1
00028             self.assertEqual(count, 20)
00029         finally:
00030             f.close()
00031     
00032     def testStr(self):
00033         """Test if we can convert each record to a string correctly"""
00034         f = open(self.filename)
00035         try: 
00036             for line in f:
00037                 record = Des.Record(line)
00038                 #End of line is platform dependent. Strip it off
00039                 self.assertEqual(str(record).rstrip(), line.rstrip())
00040         finally:
00041             f.close()        
00042 
00043     def testError(self):
00044         """Test if a corrupt record raises the appropriate exception"""
00045         corruptRec = "49268\tsp\tb.1.2.1\t-\n"
00046         self.assertRaises(ValueError, Des.Record, corruptRec)
00047 
00048     def testRecord(self):
00049         """Test one record in detail"""
00050         recLine = '49268\tsp\tb.1.2.1\t-\tHuman (Homo sapiens)    \n'
00051         recFields = (49268,'sp','b.1.2.1','','Human (Homo sapiens)')
00052 
00053         record = Des.Record(recLine)
00054         self.assertEqual(record.sunid, recFields[0])
00055         self.assertEqual(record.nodetype, recFields[1])
00056         self.assertEqual(record.sccs, recFields[2])
00057         self.assertEqual(record.name, recFields[3])
00058         self.assertEqual(record.description, recFields[4])
00059 
00060 
00061 
00062 if __name__=='__main__':
00063     runner = unittest.TextTestRunner(verbosity = 2)
00064     unittest.main(testRunner=runner)