Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix more unit tests which were not closing handles

  • Loading branch information...
commit b8a3ae74eaf3b3aa3cd3f27599c3836ba908857f 1 parent 89bf978
@peterjc peterjc authored
Showing with 24 additions and 9 deletions.
  1. +20 −9 Tests/test_Compass.py
  2. +4 −0 Tests/test_Enzyme.py
View
29 Tests/test_Compass.py
@@ -15,7 +15,9 @@ def setUp(self):
os.path.join(file_dir, "comtest3")]
def testCompassScanAndConsume(self):
- com_record = Compass.read(open(self.test_files[0]))
+ handle = open(self.test_files[0])
+ com_record = Compass.read(handle)
+ handle.close()
self.assertEqual("60456.blo.gz.aln", com_record.query)
self.assertEqual("60456.blo.gz.aln", com_record.hit)
@@ -35,20 +37,23 @@ def testCompassScanAndConsume(self):
self.assertEqual(float("0.00e+00"), com_record.evalue)
def testCompassParser(self):
- com_record = Compass.read(open(self.test_files[0]))
+ handle = open(self.test_files[0])
+ com_record = Compass.read(handle)
+ handle.close()
self.assertEqual("60456.blo.gz.aln", com_record.query)
def testCompassIteratorEasy(self):
- records = Compass.parse(open(self.test_files[0]))
-
+ handle = open(self.test_files[0])
+ records = Compass.parse(handle)
com_record = records.next()
self.assertEqual("60456.blo.gz.aln", com_record.query)
-
self.assertRaises(StopIteration, records.next)
+ handle.close()
def testCompassIteratorHard(self):
- records = Compass.parse(open(self.test_files[1]))
+ handle = open(self.test_files[1])
+ records = Compass.parse(handle)
com_record = records.next()
self.assertEqual("allscop//14982.blo.gz.aln", com_record.hit)
@@ -61,9 +66,12 @@ def testCompassIteratorHard(self):
com_record = records.next()
self.assertEqual("allscop//14984.blo.gz.aln", com_record.hit)
self.assertEqual(float('5.75e+02'), com_record.evalue)
+
+ handle.close()
def testAlignmentParsingOne(self):
- records = Compass.parse(open(self.test_files[1]))
+ handle = open(self.test_files[1])
+ records = Compass.parse(handle)
com_record = records.next()
self.assertEqual(178, com_record.query_start)
@@ -80,13 +88,16 @@ def testAlignmentParsingOne(self):
self.assertEqual("LQNFIDQLDNpddL", com_record.hit_aln)
self.assertEqual("+ ++++ + + +", com_record.positives)
+ handle.close()
+
def testAlignmentParsingTwo(self):
- records = Compass.parse(open(self.test_files[0]))
-
+ handle = open(self.test_files[0])
+ records = Compass.parse(handle)
com_record = records.next()
self.assertEqual(2, com_record.query_start)
self.assertEqual(2, com_record.hit_start)
self.assertEqual("LKERKL", com_record.hit_aln[-6:])
+ handle.close()
if __name__ == "__main__":
runner = unittest.TextTestRunner(verbosity = 2)
View
4 Tests/test_Enzyme.py
@@ -17,6 +17,7 @@ def test_lipoprotein(self):
filename = os.path.join( 'Enzymes', 'lipoprotein.txt')
handle = open(filename)
record = Enzyme.read(handle)
+ handle.close()
self.assertEqual(record["ID"], "3.1.1.34")
self.assertEqual(record["DE"], "Lipoprotein lipase.")
self.assertEqual(len(record["AN"]), 3)
@@ -44,6 +45,7 @@ def test_proline(self):
filename = os.path.join( 'Enzymes', 'proline.txt')
handle = open(filename)
record = Enzyme.read(handle)
+ handle.close()
self.assertEqual(record["ID"], "5.1.1.4")
self.assertEqual(record["DE"], "Proline racemase.")
self.assertEqual(record["CA"], "L-proline = D-proline.")
@@ -63,6 +65,7 @@ def test_valine(self):
filename = os.path.join( 'Enzymes', 'valine.txt')
handle = open(filename)
record = Enzyme.read(handle)
+ handle.close()
self.assertEqual(record["ID"], "4.1.1.14")
self.assertEqual(record["DE"], "Valine decarboxylase.")
self.assertEqual(record["CA"], "L-valine = 2-methylpropanamine + CO(2).")
@@ -75,6 +78,7 @@ def test_lactate(self):
filename = os.path.join( 'Enzymes', 'lactate.txt')
handle = open(filename)
record = Enzyme.read(handle)
+ handle.close()
self.assertEqual(record["ID"], "5.1.2.1")
self.assertEqual(record["DE"], "Lactate racemase.")
self.assertEqual(len(record["AN"]), 3)
Please sign in to comment.
Something went wrong with that request. Please try again.