Skip to content

Commit

Permalink
add deprecation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kain88-de committed Dec 31, 2016
1 parent e1d0873 commit b893c8f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 6 deletions.
34 changes: 32 additions & 2 deletions testsuite/MDAnalysisTests/analysis/test_align.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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',
Expand Down
24 changes: 20 additions & 4 deletions testsuite/MDAnalysisTests/analysis/test_rms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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_equal(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=
Expand Down

0 comments on commit b893c8f

Please sign in to comment.