Commit b7088b74 authored by peastman's avatar peastman Committed by Robert McGibbon
Browse files

Python 2/3 compatibility in single code base, plus python 3 testing on travis.

parent 4c00b312
import unittest
import numpy as np
from simtk.openmm import app
import simtk.openmm as mm
from simtk import unit
try:
import numpy as np
NUMPY_IMPORT_FAILED = False
except ImportError:
NUMPY_IMPORT_FAILED = True
@unittest.skipIf(NUMPY_IMPORT_FAILED, 'Numpy is not installed')
class TestNumpyCompatibility(unittest.TestCase):
def setUp(self):
......@@ -80,6 +85,8 @@ class TestNumpyCompatibility(unittest.TestCase):
self.assertEqual(size, 10)
np.testing.assert_array_almost_equal(energy, np.asarray(energy_out))
@unittest.skipIf(NUMPY_IMPORT_FAILED, 'Numpy is not installed')
class TestNumpyUnits(unittest.TestCase):
def setUp(self):
......
import sys
import unittest
from simtk.openmm.app import *
from simtk.openmm import *
from simtk.unit import *
import simtk.openmm.app.element as elem
import cStringIO
if sys.version_info >= (3, 0):
from io import StringIO
else:
from cStringIO import StringIO
class TestPdbFile(unittest.TestCase):
"""Test the PDB file parser"""
......@@ -43,9 +48,9 @@ class TestPdbFile(unittest.TestCase):
def test_WriteFile(self):
"""Write a file, read it back, and make sure it matches the original."""
pdb1 = PDBFile('systems/triclinic.pdb')
output = cStringIO.StringIO()
output = StringIO()
PDBFile.writeFile(pdb1.topology, pdb1.positions, output)
input = cStringIO.StringIO(output.getvalue())
input = StringIO(output.getvalue())
pdb2 = PDBFile(input)
output.close();
input.close();
......
......@@ -70,6 +70,7 @@ class TestPdbxFile(unittest.TestCase):
# There should only be 10 frames (0 through 9)
self.assertRaises(IndexError, lambda: pdb.getPositions(frame=10))
self.assertIs(pdb.topology.getPeriodicBoxVectors(), None)
del sim
os.unlink('test.cif')
def assertAlmostEqualVec(self, vec1, vec2, *args, **kwargs):
......@@ -111,6 +112,7 @@ class TestPdbxFile(unittest.TestCase):
self.assertAlmostEqualVec(parm.topology.getPeriodicBoxVectors()[2],
pdb.topology.getPeriodicBoxVectors()[2],
places=5)
del sim
os.unlink('test.cif')
if __name__ == '__main__':
......
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