Skip to content

Commit

Permalink
splits BaseReaderTest into BaseReaderTest & MultiframeReaderTest
Browse files Browse the repository at this point in the history
  • Loading branch information
utkbansal committed Feb 4, 2017
1 parent 04f5526 commit f882a29
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 47 deletions.
85 changes: 46 additions & 39 deletions testsuite/MDAnalysisTests/coordinates/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from unittest import TestCase
from numpy.testing import (assert_equal, assert_raises, assert_almost_equal,
assert_array_almost_equal, raises, assert_allclose,
assert_)
assert_, dec)

import MDAnalysis as mda
from MDAnalysis.coordinates.base import Timestep
Expand Down Expand Up @@ -207,33 +207,6 @@ def test_double_close(self):
self.reader.close()
self.reader._reopen()

def test_reopen(self):
self.reader.close()
self.reader._reopen()
ts = self.reader.next()
assert_timestep_almost_equal(ts, self.ref.first_frame,
decimal=self.ref.prec)

def test_last_frame(self):
ts = self.reader[-1]
assert_timestep_almost_equal(ts, self.ref.last_frame,
decimal=self.ref.prec)

def test_next_gives_second_frame(self):
reader = self.ref.reader(self.ref.trajectory)
ts = reader.next()
assert_timestep_almost_equal(ts, self.ref.second_frame,
decimal=self.ref.prec)

@raises(IndexError)
def test_go_over_last_frame(self):
self.reader[self.ref.n_frames + 1]

def test_frame_jump(self):
ts = self.reader[self.ref.jump_to_frame.frame]
assert_timestep_almost_equal(ts, self.ref.jump_to_frame,
decimal=self.ref.prec)

def test_get_writer_1(self):
with tempdir.in_tempdir():
self.outfile = 'test-writer' + self.ref.ext
Expand Down Expand Up @@ -338,17 +311,7 @@ def test_iter_as_aux_cutoff(self):
assert_equal(num_frames, 0, "iter_as_aux should iterate over 0 frames,"
" not {}".format(num_frames))

def test_rename_aux(self):
self.reader.rename_aux('lowf', 'lowf_renamed')
# data should now be in aux namespace under new name
assert_equal(self.reader.ts.aux.lowf_renamed,
self.ref.aux_lowf_data[0])
# old name should be removed
assert_raises(AttributeError, getattr, self.reader.ts.aux, 'lowf')
# new name should be retained
next(self.reader)
assert_equal(self.reader.ts.aux.lowf_renamed,
self.ref.aux_lowf_data[1])


def test_reload_auxiliaries_from_description(self):
# get auxiliary desscriptions form existing reader
Expand All @@ -374,6 +337,50 @@ def test_stop_iter(self):
assert_equal(self.reader.frame, 0)


class MultiframeReaderTest(BaseReaderTest):

def test_last_frame(self):
ts = self.reader[-1]
assert_timestep_almost_equal(ts, self.ref.last_frame,
decimal=self.ref.prec)

@raises(IndexError)
def test_go_over_last_frame(self):
self.reader[self.ref.n_frames + 1]

def test_frame_jump(self):
ts = self.reader[self.ref.jump_to_frame.frame]
assert_timestep_almost_equal(ts, self.ref.jump_to_frame,
decimal=self.ref.prec)


def test_next_gives_second_frame(self):
reader = self.ref.reader(self.ref.trajectory)
ts = reader.next()
assert_timestep_almost_equal(ts, self.ref.second_frame,
decimal=self.ref.prec)

def test_reopen(self):
self.reader.close()
self.reader._reopen()
ts = self.reader.next()
assert_timestep_almost_equal(ts, self.ref.first_frame,
decimal=self.ref.prec)

def test_rename_aux(self):
self.reader.rename_aux('lowf', 'lowf_renamed')
# data should now be in aux namespace under new name
assert_equal(self.reader.ts.aux.lowf_renamed,
self.ref.aux_lowf_data[0])
# old name should be removed
assert_raises(AttributeError, getattr, self.reader.ts.aux, 'lowf')
# new name should be retained
next(self.reader)
assert_equal(self.reader.ts.aux.lowf_renamed,
self.ref.aux_lowf_data[1])



class BaseWriterTest(object):
def __init__(self, reference):
self.ref = reference
Expand Down
2 changes: 2 additions & 0 deletions testsuite/MDAnalysisTests/coordinates/test_gro.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ def test_unitcell(self):
def test_volume(self):
# test_volume: reduce precision for Gromacs comparison to 0 decimals
# (A**3 <--> nm**3!)
print(self.ts.volume,
self.ref_volume)
assert_almost_equal(
self.ts.volume,
self.ref_volume,
Expand Down
3 changes: 2 additions & 1 deletion testsuite/MDAnalysisTests/coordinates/test_gro2.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from MDAnalysis.coordinates.GRO import GROReader, GROWriter
from MDAnalysisTests.coordinates.base import BaseReference, BaseReaderTest
from MDAnalysisTests.coordinates.base import BaseReference, BaseReaderTest, MultiframeReaderTest
from MDAnalysisTests.datafiles import COORDINATES_GRO
import numpy as np

Expand All @@ -12,6 +12,7 @@ def __init__(self):
self.reader = GROReader
self.writer = GROWriter
self.ext = 'gro'
self.n_frames = 1
# self.volume = 0
# self.dimensions = np.zeros(6)
# self.container_format = True
Expand Down
4 changes: 2 additions & 2 deletions testsuite/MDAnalysisTests/coordinates/test_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from MDAnalysis.coordinates.memory import MemoryReader
from MDAnalysisTests.datafiles import DCD, PSF
from MDAnalysisTests.coordinates.base import (BaseReference,
BaseReaderTest)
MultiframeReaderTest)
from MDAnalysis.coordinates.memory import Timestep
from numpy.testing import assert_equal, dec
from MDAnalysisTests import parser_not_found
Expand Down Expand Up @@ -59,7 +59,7 @@ def iter_ts(self, i):



class TestMemoryReader(BaseReaderTest):
class TestMemoryReader(MultiframeReaderTest):
def __init__(self):
reference = MemoryReference()
super(TestMemoryReader, self).__init__(reference)
Expand Down
6 changes: 3 additions & 3 deletions testsuite/MDAnalysisTests/coordinates/test_xdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

from MDAnalysisTests.datafiles import (COORDINATES_XTC, COORDINATES_TOPOLOGY,
COORDINATES_TRR)
from MDAnalysisTests.coordinates.base import (BaseReaderTest, BaseReference,
from MDAnalysisTests.coordinates.base import (MultiframeReaderTest, BaseReference,
BaseWriterTest,
assert_timestep_almost_equal)
from MDAnalysisTests import tempdir
Expand Down Expand Up @@ -619,7 +619,7 @@ def __init__(self):
self.changing_dimensions = True


class TestXTCReader_2(BaseReaderTest):
class TestXTCReader_2(MultiframeReaderTest):
def __init__(self, reference=None):
if reference is None:
reference = XTCReference()
Expand Down Expand Up @@ -679,7 +679,7 @@ def iter_ts(self, i):
return ts


class TestTRRReader_2(BaseReaderTest):
class TestTRRReader_2(MultiframeReaderTest):
def __init__(self, reference=None):
if reference is None:
reference = TRRReference()
Expand Down
4 changes: 2 additions & 2 deletions testsuite/MDAnalysisTests/coordinates/test_xyz.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from MDAnalysis.coordinates.XYZ import XYZWriter

from MDAnalysisTests.datafiles import COORDINATES_XYZ, COORDINATES_XYZ_BZ2
from MDAnalysisTests.coordinates.base import (BaseReaderTest, BaseReference,
from MDAnalysisTests.coordinates.base import (MultiframeReaderTest, BaseReference,
BaseWriterTest)
from MDAnalysisTests import tempdir, make_Universe

Expand All @@ -32,7 +32,7 @@ def __init__(self):
self.container_format = True


class TestXYZReader(BaseReaderTest):
class TestXYZReader(MultiframeReaderTest):
def __init__(self, reference=None):
if reference is None:
reference = XYZReference()
Expand Down

0 comments on commit f882a29

Please sign in to comment.