Skip to content

Commit

Permalink
Close files when we're done with them
Browse files Browse the repository at this point in the history
  • Loading branch information
benmwebb committed Dec 13, 2023
1 parent 23f8635 commit f293608
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
3 changes: 2 additions & 1 deletion modules/cnmultifit/test/test_chimera_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def test_chimera_models_usage(self):

def test_chimera_models_run(self):
"""Test chimera_models module run"""
open('test.pdb', 'w').write("""
with open('test.pdb', 'w') as fh:
fh.write("""
ATOM 1 N ALA A 2 -27.425 4.153 -19.130 1.00 0.00 N
ATOM 2 CA ALA A 2 -18.390 4.442 -18.049 1.00 0.00 C
""")
Expand Down
3 changes: 2 additions & 1 deletion modules/cnmultifit/test/test_do_all_fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def test_do_all_fitting(self):
fin.close()
fout.close()
IMP.cnmultifit.do_all_fitting('trimer.param')
self.assertEqual(len(open('multifit.output').readlines()), 4)
with open('multifit.output') as fh:
self.assertEqual(len(fh.readlines()), 4)

m = IMP.Model()
ref = IMP.atom.read_pdb(self.get_input_file_name('trimer-ref.pdb'), m)
Expand Down
3 changes: 2 additions & 1 deletion modules/cnmultifit/test/test_param.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def test_param_run(self):
'--numsols', '42', '--',
'7', 'testmonomer.pdb', 'test.mrc', '8.0',
'4.0', '5.0', '-10.0', '-20.0', '-30.0'])
contents = open('test.params').read()
with open('test.params') as fh:
contents = fh.read()
self.assertIn('output = test.output', contents)
self.assertIn('intermediate = test.int', contents)
self.assertIn('model = test.model', contents)
Expand Down
9 changes: 6 additions & 3 deletions modules/cnmultifit/test/test_rmsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ def test_rmsd_run(self):
'multifit.param', self.get_input_file_name(
'multifit.output'),
self.get_input_file_name('mini-ref-complex.pdb')])
self.assertEqual(len(open('rmsd.output').readlines()), 10)
self.assertEqual(len(open('test.vec').read().split(' ')), 10)
with open('rmsd.output') as fh:
self.assertEqual(len(fh.readlines()), 10)
with open('test.vec') as fh:
self.assertEqual(len(fh.read().split(' ')), 10)
os.unlink('rmsd.output')
os.unlink('test.vec')

Expand All @@ -47,7 +49,8 @@ def test_rmsd_run(self):
'multifit.param', self.get_input_file_name(
'multifit.output'),
self.get_input_file_name('mini-ref-complex.pdb')])
self.assertEqual(len(open('rmsd.output').readlines()), 2)
with open('rmsd.output') as fh:
self.assertEqual(len(fh.readlines()), 2)
os.unlink('rmsd.output')
os.unlink('multifit.param')

Expand Down
3 changes: 2 additions & 1 deletion modules/cnmultifit/test/test_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def assert_surface_ok(leaves, outfile, density, rp):
self.assertEqual(outfile, 'test.pdb.ms')
self.assertEqual(density, 5.0)
self.assertEqual(rp, 3.0)
open('test.pdb', 'w').write("""
with open('test.pdb', 'w') as fh:
fh.write("""
ATOM 1 N ALA A 2 -27.425 4.153 -19.130 1.00 0.00 N
ATOM 2 CA ALA A 2 -18.390 4.442 -18.049 1.00 0.00 C
""")
Expand Down

0 comments on commit f293608

Please sign in to comment.