From f882a29398ead62a49d4938ea27d3ca5ba4f2e5a Mon Sep 17 00:00:00 2001 From: Bansal Utkarsh Date: Sat, 4 Feb 2017 10:23:53 +0530 Subject: [PATCH] splits BaseReaderTest into BaseReaderTest & MultiframeReaderTest --- testsuite/MDAnalysisTests/coordinates/base.py | 85 ++++++++++--------- .../MDAnalysisTests/coordinates/test_gro.py | 2 + .../MDAnalysisTests/coordinates/test_gro2.py | 3 +- .../coordinates/test_memory.py | 4 +- .../MDAnalysisTests/coordinates/test_xdr.py | 6 +- .../MDAnalysisTests/coordinates/test_xyz.py | 4 +- 6 files changed, 57 insertions(+), 47 deletions(-) diff --git a/testsuite/MDAnalysisTests/coordinates/base.py b/testsuite/MDAnalysisTests/coordinates/base.py index 1f23f041f32..08de5d1f8e9 100644 --- a/testsuite/MDAnalysisTests/coordinates/base.py +++ b/testsuite/MDAnalysisTests/coordinates/base.py @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/testsuite/MDAnalysisTests/coordinates/test_gro.py b/testsuite/MDAnalysisTests/coordinates/test_gro.py index fbae2d2e046..29a45d66630 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_gro.py +++ b/testsuite/MDAnalysisTests/coordinates/test_gro.py @@ -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, diff --git a/testsuite/MDAnalysisTests/coordinates/test_gro2.py b/testsuite/MDAnalysisTests/coordinates/test_gro2.py index 6d242cd93b7..36a28de686c 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_gro2.py +++ b/testsuite/MDAnalysisTests/coordinates/test_gro2.py @@ -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 @@ -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 diff --git a/testsuite/MDAnalysisTests/coordinates/test_memory.py b/testsuite/MDAnalysisTests/coordinates/test_memory.py index a8fda097fcf..6b3a1a2cf16 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_memory.py +++ b/testsuite/MDAnalysisTests/coordinates/test_memory.py @@ -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 @@ -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) diff --git a/testsuite/MDAnalysisTests/coordinates/test_xdr.py b/testsuite/MDAnalysisTests/coordinates/test_xdr.py index 8a70d4a32f2..85c20eb2d5a 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_xdr.py +++ b/testsuite/MDAnalysisTests/coordinates/test_xdr.py @@ -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 @@ -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() @@ -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() diff --git a/testsuite/MDAnalysisTests/coordinates/test_xyz.py b/testsuite/MDAnalysisTests/coordinates/test_xyz.py index 2a577ab3ad7..df977361365 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_xyz.py +++ b/testsuite/MDAnalysisTests/coordinates/test_xyz.py @@ -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 @@ -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()