From 1c7c671f130265084db676b700b90372797a992b Mon Sep 17 00:00:00 2001 From: Max Linke Date: Fri, 30 Dec 2016 21:55:03 +0100 Subject: [PATCH] add deprecation tests --- .../MDAnalysisTests/analysis/test_align.py | 34 +++++++++++++++++-- .../MDAnalysisTests/analysis/test_rms.py | 24 ++++++++++--- 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/testsuite/MDAnalysisTests/analysis/test_align.py b/testsuite/MDAnalysisTests/analysis/test_align.py index d73add0393b..a6d4f5a0b9a 100644 --- a/testsuite/MDAnalysisTests/analysis/test_align.py +++ b/testsuite/MDAnalysisTests/analysis/test_align.py @@ -20,6 +20,8 @@ # J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787 # from __future__ import absolute_import, print_function +import warnings +import os.path import MDAnalysis import MDAnalysis.analysis.align as align @@ -33,11 +35,13 @@ import numpy as np from nose.plugins.attrib import attr -import os.path - from MDAnalysisTests.datafiles import PSF, DCD, FASTA from MDAnalysisTests import executable_not_found, parser_not_found, tempdir +# I want to catch all warnings in the tests. If this is not set at the start it +# could cause test that check for warnings to fail. +warnings.simplefilter('always') + class TestRotationMatrix(object): def __init__(self): @@ -119,6 +123,17 @@ def test_rmsd(self): center=True, superposition=True) assert_almost_equal(rmsd[1], rmsd_sup_weight, 6) + def test_rmsd_deprecated(self): + last_atoms_weight = self.universe.atoms.masses + A = self.universe.trajectory[0] + B = self.reference.trajectory[-1] + with warnings.catch_warnings(record=True) as warn: + warnings.simplefilter('always') + rmsd = align.alignto(self.universe, self.reference, mass_weighted=True) + assert_equal(len(warn), 1) + rmsd_sup_weight = rms.rmsd(A, B, weights=last_atoms_weight, + center=True, superposition=True) + assert_almost_equal(rmsd[1], rmsd_sup_weight, 6) @dec.slow @attr('issue') @@ -187,6 +202,21 @@ def test_AlignTraj_weighted(self): self._assert_rmsd(fitted, -1, 6.929083032629219, weights=self.universe.atoms.masses) + def test_AlignTraj_weigts_deprecated(self): + with warnings.catch_warnings(record=True) as warn: + warnings.simplefilter('always') + x = align.AlignTraj(self.universe, self.reference, + filename=self.outfile, mass_weighted=True).run() + assert_equal(len(warn), 1) + fitted = MDAnalysis.Universe(PSF, self.outfile) + assert_almost_equal(x.rmsd[0], 0, decimal=3) + assert_almost_equal(x.rmsd[-1], 6.9033, decimal=3) + + self._assert_rmsd(fitted, 0, 0.0, + weights=self.universe.atoms.masses) + self._assert_rmsd(fitted, -1, 6.929083032629219, + weights=self.universe.atoms.masses) + def test_AlignTraj_partial_fit(self): # fitting on a partial selection should still write the whole topology align.AlignTraj(self.universe, self.reference, select='resid 1-20', diff --git a/testsuite/MDAnalysisTests/analysis/test_rms.py b/testsuite/MDAnalysisTests/analysis/test_rms.py index 49ea4dc9670..2c09135c1d3 100644 --- a/testsuite/MDAnalysisTests/analysis/test_rms.py +++ b/testsuite/MDAnalysisTests/analysis/test_rms.py @@ -20,9 +20,12 @@ # J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787 # from __future__ import print_function - from six.moves import range +import warnings +import os +import sys + import MDAnalysis import MDAnalysis as mda from MDAnalysis.analysis import rms, align @@ -33,13 +36,14 @@ import numpy as np -import os -import sys - from MDAnalysis.exceptions import SelectionError, NoDataError from MDAnalysisTests.datafiles import GRO, XTC, rmsfArray, PSF, DCD from MDAnalysisTests import tempdir, parser_not_found +# I want to catch all warnings in the tests. If this is not set at the start it +# could cause test that check for warnings to fail. +warnings.simplefilter('always') + class Testrmsd(object): def __init__(self): @@ -191,6 +195,18 @@ def test_mass_weighted_and_save(self): err_msg="error: rmsd profile should match " + "test values") + def test_mass_weighted_and_save_deprecated(self): + with warnings.catch_warnings(record=True) as warn: + warnings.simplefilter('always') + RMSD = MDAnalysis.analysis.rms.RMSD(self.universe, select='name CA', + step=49, mass_weighted=True).run() + assert(len(warn), 1) + RMSD.save(self.outfile) + saved = np.loadtxt(self.outfile) + assert_array_almost_equal(RMSD.rmsd, saved, 4, + err_msg="error: rmsd profile should match " + + "test values") + def test_rmsd_group_selections(self): RMSD = MDAnalysis.analysis.rms.RMSD(self.universe, groupselections=