Commit dbfc3024 authored by Robert McGibbon's avatar Robert McGibbon
Browse files

Fix test checkpoint reporter close file before repoening

parent df071ec7
import os
import unittest import unittest
import tempfile import tempfile
import numpy as np import numpy as np
...@@ -18,7 +19,7 @@ class TestCheckpointReporter(unittest.TestCase): ...@@ -18,7 +19,7 @@ class TestCheckpointReporter(unittest.TestCase):
self.simulation.context.setPositions(pdb.positions) self.simulation.context.setPositions(pdb.positions)
def test_1(self): def test_1(self):
file = tempfile.NamedTemporaryFile() file = tempfile.NamedTemporaryFile(delete=False)
self.simulation.reporters.append(app.CheckpointReporter(file, 1)) self.simulation.reporters.append(app.CheckpointReporter(file, 1))
self.simulation.step(1) self.simulation.step(1)
...@@ -27,9 +28,10 @@ class TestCheckpointReporter(unittest.TestCase): ...@@ -27,9 +28,10 @@ class TestCheckpointReporter(unittest.TestCase):
# now set the positions into junk... # now set the positions into junk...
self.simulation.context.setPositions(np.random.random(positions.shape)) self.simulation.context.setPositions(np.random.random(positions.shape))
# then reload the right positions from the checkpoint # then reload the right positions from the checkpoint
file.close()
with open(file.name, 'rb') as f: with open(file.name, 'rb') as f:
self.simulation.context.loadCheckpoint(f.read()) self.simulation.context.loadCheckpoint(f.read())
file.close() os.unlink(file.name)
newPositions = self.simulation.context.getState(getPositions=True).getPositions(asNumpy=True)._value newPositions = self.simulation.context.getState(getPositions=True).getPositions(asNumpy=True)._value
np.testing.assert_array_equal(positions, newPositions) np.testing.assert_array_equal(positions, newPositions)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment