Skip to content

Commit

Permalink
Pytest Style coordinates/test_mmtf.py (#1646)
Browse files Browse the repository at this point in the history
  • Loading branch information
utkbansal authored and richardjgowers committed Aug 25, 2017
1 parent b997234 commit e8de75d
Showing 1 changed file with 41 additions and 43 deletions.
84 changes: 41 additions & 43 deletions testsuite/MDAnalysisTests/coordinates/test_mmtf.py
Expand Up @@ -20,69 +20,67 @@
# J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787
#
from __future__ import division, absolute_import

import pytest
import numpy as np
from numpy.testing import (
assert_,
assert_array_almost_equal,
assert_almost_equal,
)

from MDAnalysisTests.datafiles import MMTF, MMTF_gz

from MDAnalysis.coordinates.MMTF import MMTFReader
from numpy.testing import TestCase

class TestMMTFReader(TestCase):
def setUp(self):
self.r = MMTFReader(MMTF)

def tearDown(self):
del self.r
class TestMMTFReader(object):
@pytest.fixture(scope='class')
def r(self):
return MMTFReader(MMTF)

def test_read_frame_size(self):
assert_(self.r.ts.n_atoms == 512)
def test_read_frame_size(self, r):
assert r.ts.n_atoms == 512

def test_read_positions(self):
assert_array_almost_equal(self.r.ts.positions[0],
np.array([-0.798, 12.632, 23.231]),
decimal=4)
assert_array_almost_equal(self.r.ts.positions[-1],
np.array([10.677, 15.517, 11.1]),
decimal=4)
def test_read_positions(self, r):
assert_almost_equal(r.ts.positions[0],
np.array([-0.798, 12.632, 23.231]),
decimal=4)
assert_almost_equal(r.ts.positions[-1],
np.array([10.677, 15.517, 11.1]),
decimal=4)

def test_velocities(self):
assert_(not self.r.ts.has_velocities)
def test_velocities(self, r):
assert not r.ts.has_velocities

def test_forces(self):
assert_(not self.r.ts.has_forces)
def test_forces(self, r):
assert not r.ts.has_forces

def test_len(self):
def test_len(self, r):
# should be single frame
assert_(len(self.r) == 1)
assert len(r) == 1

class TestMMTFReaderGZ(TestCase):
def setUp(self):
self.r = MMTFReader(MMTF_gz)

def tearDown(self):
del self.r
class TestMMTFReaderGZ(object):
@pytest.fixture(scope='class')
def r(self):
return MMTFReader(MMTF_gz)

def test_read_frame_size(self):
assert_(self.r.ts.n_atoms == 1140)
def test_read_frame_size(self, r):
assert r.ts.n_atoms == 1140

def test_read_positions(self):
assert_array_almost_equal(self.r.ts.positions[0],
np.array([38.428, 16.440, 28.841]),
decimal=4)
assert_array_almost_equal(self.r.ts.positions[-1],
np.array([36.684, 27.024, 20.468]),
decimal=4)
def test_read_positions(self, r):
assert_almost_equal(r.ts.positions[0],
np.array([38.428, 16.440, 28.841]),
decimal=4)
assert_almost_equal(r.ts.positions[-1],
np.array([36.684, 27.024, 20.468]),
decimal=4)

def test_velocities(self):
assert_(not self.r.ts.has_velocities)
def test_velocities(self, r):
assert not r.ts.has_velocities

def test_forces(self):
assert_(not self.r.ts.has_forces)
def test_forces(self, r):
assert not r.ts.has_forces

def test_len(self):
def test_len(self, r):
# should be single frame
assert_(len(self.r) == 1)
assert len(r) == 1

0 comments on commit e8de75d

Please sign in to comment.