From a0a53934fe93d97ac05c66d08aae58bb86eae78e Mon Sep 17 00:00:00 2001 From: wvandertoorn Date: Thu, 12 Mar 2020 08:49:37 +0100 Subject: [PATCH] Finalizing #2537 - [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 --- package/MDAnalysis/analysis/density.py | 3 ++ .../MDAnalysisTests/analysis/test_density.py | 29 ++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/package/MDAnalysis/analysis/density.py b/package/MDAnalysis/analysis/density.py index d777783609c..7e6bde082e1 100644 --- a/package/MDAnalysis/analysis/density.py +++ b/package/MDAnalysis/analysis/density.py @@ -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 diff --git a/testsuite/MDAnalysisTests/analysis/test_density.py b/testsuite/MDAnalysisTests/analysis/test_density.py index 5e326ed04f9..f4d1381cffa 100644 --- a/testsuite/MDAnalysisTests/analysis/test_density.py +++ b/testsuite/MDAnalysisTests/analysis/test_density.py @@ -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): @@ -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.''')