Back to index

python-biopython  1.60
test_SCOP_Hie.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 Hie"""
00008 
00009 import unittest
00010 
00011 from Bio.SCOP import Hie
00012 
00013 
00014 
00015 
00016 class HieTests(unittest.TestCase):
00017 
00018     def setUp(self):
00019         self.filename = './SCOP/dir.hie.scop.txt_test'
00020 
00021     def testParse(self):
00022         """Test if all records in a HIE file are being read"""
00023         f = open(self.filename)
00024         try: 
00025             count = 0
00026             for record in Hie.parse(f):
00027                 count +=1
00028             self.assertEqual(count, 21)
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 = Hie.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 = "4926sdfhjhfgyjdfyg"
00046         self.assertRaises(ValueError, Hie.Record, corruptRec)
00047 
00048 
00049 if __name__ == '__main__':
00050     runner = unittest.TextTestRunner(verbosity = 2)
00051     unittest.main(testRunner=runner)