mirror of
https://github.com/biopython/biopython.git
synced 2025-10-20 21:53:47 +08:00
use with in SCOP tests (#2705)
This commit is contained in:
@ -19,20 +19,16 @@ class ClaTests(unittest.TestCase):
|
||||
|
||||
def testParse(self):
|
||||
"""Test if all records in a CLA file are being read."""
|
||||
f = open(self.filename)
|
||||
try:
|
||||
count = 0
|
||||
count = 0
|
||||
with open(self.filename) as f:
|
||||
records = Cla.parse(f)
|
||||
for record in records:
|
||||
count += 1
|
||||
self.assertEqual(count, 14)
|
||||
finally:
|
||||
f.close()
|
||||
self.assertEqual(count, 14)
|
||||
|
||||
def testStr(self):
|
||||
"""Test if we can convert each record to a string correctly."""
|
||||
f = open(self.filename)
|
||||
try:
|
||||
with open(self.filename) as f:
|
||||
for line in f:
|
||||
record = Cla.Record(line)
|
||||
# The SCOP Classification file format which can be found at
|
||||
@ -51,8 +47,6 @@ class ClaTests(unittest.TestCase):
|
||||
len(expected_hierarchy))
|
||||
for key, actual_value in actual_hierarchy.items():
|
||||
self.assertEqual(actual_value, expected_hierarchy[key])
|
||||
finally:
|
||||
f.close()
|
||||
|
||||
def testError(self):
|
||||
"""Test if a corrupt record raises the appropriate exception."""
|
||||
|
@ -17,26 +17,20 @@ class DesTests(unittest.TestCase):
|
||||
|
||||
def testParse(self):
|
||||
"""Test if all records in a DES file are being read."""
|
||||
f = open(self.filename)
|
||||
try:
|
||||
count = 0
|
||||
count = 0
|
||||
with open(self.filename) as f:
|
||||
records = Des.parse(f)
|
||||
for record in records:
|
||||
count += 1
|
||||
self.assertEqual(count, 20)
|
||||
finally:
|
||||
f.close()
|
||||
self.assertEqual(count, 20)
|
||||
|
||||
def testStr(self):
|
||||
"""Test if we can convert each record to a string correctly."""
|
||||
f = open(self.filename)
|
||||
try:
|
||||
with open(self.filename) as f:
|
||||
for line in f:
|
||||
record = Des.Record(line)
|
||||
# End of line is platform dependent. Strip it off
|
||||
self.assertEqual(str(record).rstrip(), line.rstrip())
|
||||
finally:
|
||||
f.close()
|
||||
|
||||
def testError(self):
|
||||
"""Test if a corrupt record raises the appropriate exception."""
|
||||
|
@ -19,25 +19,19 @@ class DomTests(unittest.TestCase):
|
||||
|
||||
def testParse(self):
|
||||
"""Test if all records in a DOM file are being read."""
|
||||
f = open(self.filename)
|
||||
try:
|
||||
count = 0
|
||||
count = 0
|
||||
with open(self.filename) as f:
|
||||
for record in Dom.parse(f):
|
||||
count += 1
|
||||
self.assertEqual(count, 10)
|
||||
finally:
|
||||
f.close()
|
||||
self.assertEqual(count, 10)
|
||||
|
||||
def testStr(self):
|
||||
"""Test if we can convert each record to a string correctly."""
|
||||
f = open(self.filename)
|
||||
try:
|
||||
with open(self.filename) as f:
|
||||
for line in f:
|
||||
record = Dom.Record(line)
|
||||
# End of line is platform dependent. Strip it off
|
||||
self.assertEqual(str(record).rstrip(), line.rstrip())
|
||||
finally:
|
||||
f.close()
|
||||
|
||||
def testError(self):
|
||||
"""Test if a corrupt record raises the appropriate exception."""
|
||||
|
@ -17,25 +17,19 @@ class HieTests(unittest.TestCase):
|
||||
|
||||
def testParse(self):
|
||||
"""Test if all records in a HIE file are being read."""
|
||||
f = open(self.filename)
|
||||
try:
|
||||
count = 0
|
||||
count = 0
|
||||
with open(self.filename) as f:
|
||||
for record in Hie.parse(f):
|
||||
count += 1
|
||||
self.assertEqual(count, 21)
|
||||
finally:
|
||||
f.close()
|
||||
self.assertEqual(count, 21)
|
||||
|
||||
def testStr(self):
|
||||
"""Test if we can convert each record to a string correctly."""
|
||||
f = open(self.filename)
|
||||
try:
|
||||
with open(self.filename) as f:
|
||||
for line in f:
|
||||
record = Hie.Record(line)
|
||||
# End of line is platform dependent. Strip it off
|
||||
self.assertEqual(str(record).rstrip(), line.rstrip())
|
||||
finally:
|
||||
f.close()
|
||||
|
||||
def testError(self):
|
||||
"""Test if a corrupt record raises the appropriate exception."""
|
||||
|
@ -37,19 +37,12 @@ class ScopTests(unittest.TestCase):
|
||||
return True
|
||||
|
||||
def testParse(self):
|
||||
f = open("./SCOP/dir.cla.scop.txt_test")
|
||||
try:
|
||||
with open("./SCOP/dir.cla.scop.txt_test") as f:
|
||||
cla = f.read()
|
||||
f.close()
|
||||
|
||||
f = open("./SCOP/dir.des.scop.txt_test")
|
||||
with open("./SCOP/dir.des.scop.txt_test") as f:
|
||||
des = f.read()
|
||||
f.close()
|
||||
|
||||
f = open("./SCOP/dir.hie.scop.txt_test")
|
||||
with open("./SCOP/dir.hie.scop.txt_test") as f:
|
||||
hie = f.read()
|
||||
finally:
|
||||
f.close()
|
||||
|
||||
scop = Scop(StringIO(cla), StringIO(des), StringIO(hie))
|
||||
|
||||
|
Reference in New Issue
Block a user