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 tempfile
import numpy as np
......@@ -18,7 +19,7 @@ class TestCheckpointReporter(unittest.TestCase):
self.simulation.context.setPositions(pdb.positions)
def test_1(self):
file = tempfile.NamedTemporaryFile()
file = tempfile.NamedTemporaryFile(delete=False)
self.simulation.reporters.append(app.CheckpointReporter(file, 1))
self.simulation.step(1)
......@@ -27,9 +28,10 @@ class TestCheckpointReporter(unittest.TestCase):
# now set the positions into junk...
self.simulation.context.setPositions(np.random.random(positions.shape))
# then reload the right positions from the checkpoint
file.close()
with open(file.name, 'rb') as f:
self.simulation.context.loadCheckpoint(f.read())
file.close()
os.unlink(file.name)
newPositions = self.simulation.context.getState(getPositions=True).getPositions(asNumpy=True)._value
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