diff --git a/package/MDAnalysis/auxiliary/XVG.py b/package/MDAnalysis/auxiliary/XVG.py index befe94c7ee7..4bf2c083c21 100644 --- a/package/MDAnalysis/auxiliary/XVG.py +++ b/package/MDAnalysis/auxiliary/XVG.py @@ -68,7 +68,6 @@ """ from __future__ import absolute_import -from six.moves import range from six import raise_from import numbers @@ -77,6 +76,7 @@ from . import base from ..lib.util import anyopen + def uncomment(lines): """ Remove comments from lines in an .xvg file diff --git a/testsuite/MDAnalysisTests/auxiliary/base.py b/testsuite/MDAnalysisTests/auxiliary/base.py index 61395a98f58..93445f7f105 100644 --- a/testsuite/MDAnalysisTests/auxiliary/base.py +++ b/testsuite/MDAnalysisTests/auxiliary/base.py @@ -227,6 +227,11 @@ def test_time_selector(self, ref): for i, val in enumerate(reader): assert val.time == ref.select_time_ref[i], "time for step {} does not match".format(i) + def test_time_non_constant_dt(self, reader): + reader.constant_dt = False + with pytest.raises(ValueError, match="If dt is not constant, must have a valid time selector"): + reader.time + def test_time_selector_manual(self, ref): reader = ref.reader(ref.testdata, time_selector = ref.time_selector) @@ -367,7 +372,7 @@ def test_step_to_frame_out_of_bounds(self, reader, ref): def test_step_to_frame_no_time_diff(self, reader, ref): ts = mda.coordinates.base.Timestep(0, dt=ref.dt) - + for idx in range(reader.n_steps): assert reader.step_to_frame(idx, ts) == idx @@ -385,6 +390,19 @@ def test_step_to_frame_time_diff(self, reader, ref): assert frame == idx np.testing.assert_almost_equal(time_diff, idx * 0.1) + def test_go_to_step_fail(self, reader): + + with pytest.raises(ValueError, match="Step index [0-9]* is not valid for auxiliary"): + reader._go_to_step(reader.n_steps) + + @pytest.mark.parametrize("constant", [True, False]) + def test_set_constant_dt(self, reader, constant): + + reader.constant_dt = constant + + assert reader.constant_dt == constant + + def assert_auxstep_equal(A, B): if not isinstance(A, mda.auxiliary.base.AuxStep): raise AssertionError('A is not of type AuxStep') diff --git a/testsuite/MDAnalysisTests/auxiliary/test_core.py b/testsuite/MDAnalysisTests/auxiliary/test_core.py new file mode 100644 index 00000000000..9a624be1c6f --- /dev/null +++ b/testsuite/MDAnalysisTests/auxiliary/test_core.py @@ -0,0 +1,43 @@ +# -*- Mode: python; tab-width: 4; indent-tabs-mode:nil; coding:utf-8 -*- +# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 fileencoding=utf-8 +# +# MDAnalysis --- https://www.mdanalysis.org +# Copyright (c) 2006-2017 The MDAnalysis Development Team and contributors +# (see the file AUTHORS for the full list of names) +# +# Released under the GNU Public Licence, v2 or any higher version +# +# Please cite your use of MDAnalysis in published work: +# +# R. J. Gowers, M. Linke, J. Barnoud, T. J. E. Reddy, M. N. Melo, S. L. Seyler, +# D. L. Dotson, J. Domanski, S. Buchoux, I. M. Kenney, and O. Beckstein. +# MDAnalysis: A Python package for the rapid analysis of molecular dynamics +# simulations. In S. Benthall and S. Rostrup editors, Proceedings of the 15th +# Python in Science Conference, pages 102-109, Austin, TX, 2016. SciPy. +# doi: 10.25080/majora-629e541a-00e +# +# N. Michaud-Agrawal, E. J. Denning, T. B. Woolf, and O. Beckstein. +# MDAnalysis: A Toolkit for the Analysis of Molecular Dynamics Simulations. +# J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787 +# + +from __future__ import absolute_import + +import MDAnalysis as mda + +import pytest + + +def test_get_auxreader_for_none(): + with pytest.raises(ValueError, match="Must provide either auxdata or format"): + mda.auxiliary.core.get_auxreader_for() + + +def test_get_auxreader_for_wrong_auxdata(): + with pytest.raises(ValueError, match="Unknown auxiliary data format for auxdata:"): + mda.auxiliary.core.get_auxreader_for(auxdata="test.none") + + +def test_get_auxreader_for_wrong_format(): + with pytest.raises(ValueError, match="Unknown auxiliary data format"): + mda.auxiliary.core.get_auxreader_for(format="none") diff --git a/testsuite/MDAnalysisTests/auxiliary/test_xvg.py b/testsuite/MDAnalysisTests/auxiliary/test_xvg.py index 2b4791c0744..a7ecf3a7531 100644 --- a/testsuite/MDAnalysisTests/auxiliary/test_xvg.py +++ b/testsuite/MDAnalysisTests/auxiliary/test_xvg.py @@ -33,6 +33,7 @@ from MDAnalysisTests.datafiles import AUX_XVG, XVG_BAD_NCOL, XVG_BZ2 from MDAnalysisTests.auxiliary.base import (BaseAuxReaderTest, BaseAuxReference) +from MDAnalysis.auxiliary.XVG import XVGStep class XVGReference(BaseAuxReference): @@ -52,6 +53,29 @@ def __init__(self): self.select_data_ref = [self.format_data([2*i, 2**i]) for i in range(self.n_steps)] +class TestXVGStep(): + + @staticmethod + @pytest.fixture() + def step(): + return XVGStep() + + def test_select_time_none(self, step): + + st = step._select_time(None) + + assert st is None + + def test_select_time_invalid_index(self, step): + with pytest.raises(ValueError, match="Time selector must be single index"): + step._select_time([0]) + + def test_select_data_none(self, step): + + st = step._select_data(None) + + assert st is None + class TestXVGReader(BaseAuxReaderTest): @staticmethod @pytest.fixture()