Skip to content

Commit

Permalink
Finalizing MDAnalysis#2537
Browse files Browse the repository at this point in the history
- [DOC] add sphinx deprecated paragraph to density/BFactor2RMSF docstring
- [TEST] decrease precision in assert_almost_equal test_density/test_density_from_PDB
- [TEST] Bring back TestGridImport class in test_density
  • Loading branch information
wvdtoorn committed Mar 12, 2020
1 parent 1154532 commit a0a5393
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
3 changes: 3 additions & 0 deletions package/MDAnalysis/analysis/density.py
Original file line number Diff line number Diff line change
Expand Up @@ -1264,6 +1264,9 @@ def Bfactor2RMSF(B):
----------
.. [Willis1975] BTM Willis and AW Pryor. *Thermal vibrations in crystallography*. Cambridge Univ. Press, 1975
.. deprecated:: 1.0.0
"""
return np.sqrt(3. * B / 8.) / np.pi

Expand Down
29 changes: 28 additions & 1 deletion testsuite/MDAnalysisTests/analysis/test_density.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
from MDAnalysis.analysis import density

from MDAnalysisTests.datafiles import TPR, XTC, GRO, PDB_full
from unittest.mock import Mock, patch
from MDAnalysisTests.util import block_import


class TestDensity(object):
Expand Down Expand Up @@ -452,9 +454,34 @@ def test_density_from_PDB(self, sigma, ref_shape, ref_gridsum):

assert isinstance(D, density.Density)
assert_equal(D.grid.shape, ref_shape)
assert_almost_equal(D.grid.sum(), ref_gridsum, decimal=6)
assert_almost_equal(D.grid.sum(), ref_gridsum, decimal=5)

def test_has_DeprecationWarning(self):
with pytest.warns(DeprecationWarning,
match="will be removed in release 2.0.0"):
density.density_from_PDB(PDB_full, delta=5.0, sigma=2)

class TestGridImport(object):

@block_import('gridData')
def test_absence_griddata(self):
sys.modules.pop('MDAnalysis.analysis.density', None)
# if gridData package is missing an ImportError should be raised
# at the module level of MDAnalysis.analysis.density
with pytest.raises(ImportError):
import MDAnalysis.analysis.density

def test_presence_griddata(self):
sys.modules.pop('MDAnalysis.analysis.density', None)
# no ImportError exception is raised when gridData is properly
# imported by MDAnalysis.analysis.density

# mock gridData in case there are testing scenarios where
# it is not available
mock = Mock()
with patch.dict('sys.modules', {'gridData':mock}):
try:
import MDAnalysis.analysis.density
except ImportError:
pytest.fail(msg='''MDAnalysis.analysis.density should not raise
an ImportError if gridData is available.''')

0 comments on commit a0a5393

Please sign in to comment.