Skip to content

Commit

Permalink
Bump up auxiliary coverage (#2570)
Browse files Browse the repository at this point in the history
* contributes to  #597
* bump auxreader core coverage
* add more test on failures
* test XVGStep failures
* remove unused module
  • Loading branch information
orbeckst authored Mar 5, 2020
1 parent 9d602ec commit 0b20ae8
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package/MDAnalysis/auxiliary/XVG.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
"""
from __future__ import absolute_import

from six.moves import range
from six import raise_from

import numbers
Expand All @@ -77,6 +76,7 @@
from . import base
from ..lib.util import anyopen


def uncomment(lines):
""" Remove comments from lines in an .xvg file
Expand Down
20 changes: 19 additions & 1 deletion testsuite/MDAnalysisTests/auxiliary/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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')
Expand Down
43 changes: 43 additions & 0 deletions testsuite/MDAnalysisTests/auxiliary/test_core.py
Original file line number Diff line number Diff line change
@@ -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")
24 changes: 24 additions & 0 deletions testsuite/MDAnalysisTests/auxiliary/test_xvg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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()
Expand Down

0 comments on commit 0b20ae8

Please sign in to comment.