From 6261e3e01253880cf94f05c659dc68fe1540e202 Mon Sep 17 00:00:00 2001 From: Jonathan Barnoud Date: Mon, 7 Dec 2015 18:52:34 +0100 Subject: [PATCH] Skip the tests that use scipy if scipy is missing Some tests requires scipy. Scipy is an optional dependency, so it can be missing leading to the tests to fail. This commit decorate the tests that need scipy with the dec.skipif decorator. This follows the guideline discussed in #124. --- .../MDAnalysisTests/analysis/test_distances.py | 17 +++++++++++++++-- .../MDAnalysisTests/analysis/test_leaflet.py | 7 +++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/testsuite/MDAnalysisTests/analysis/test_distances.py b/testsuite/MDAnalysisTests/analysis/test_distances.py index 238f9579aea..a5a98b44b1b 100644 --- a/testsuite/MDAnalysisTests/analysis/test_distances.py +++ b/testsuite/MDAnalysisTests/analysis/test_distances.py @@ -16,14 +16,27 @@ from __future__ import print_function import MDAnalysis -import MDAnalysis.analysis.distances +from MDAnalysisTests import module_not_found -from numpy.testing import TestCase, assert_equal +from numpy.testing import TestCase, assert_equal, dec import numpy as np +def scipy_missing(): + try: + import scipy + except ImportError: + return True + else: + return False + + class TestContactMatrix(TestCase): + + @dec.skipif(module_not_found('scipy'), + "Test skipped because scipy is not available.") def setUp(self): + import MDAnalysis.analysis.distances self.coord = np.array([[1, 1, 1], [5, 5, 5], [1.1, 1.1, 1.1], diff --git a/testsuite/MDAnalysisTests/analysis/test_leaflet.py b/testsuite/MDAnalysisTests/analysis/test_leaflet.py index 5e1ed5e8a99..939568acb4f 100644 --- a/testsuite/MDAnalysisTests/analysis/test_leaflet.py +++ b/testsuite/MDAnalysisTests/analysis/test_leaflet.py @@ -14,14 +14,16 @@ # J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787 # import MDAnalysis -from MDAnalysis.analysis.leaflet import LeafletFinder +from MDAnalysisTests import module_not_found -from numpy.testing import TestCase, assert_equal +from numpy.testing import TestCase, assert_equal, dec import numpy as np from MDAnalysisTests.datafiles import Martini_membrane_gro class TestLeafletFinder(TestCase): + @dec.skipif(module_not_found('scipy'), + "Test skipped because scipy is not available.") def setUp(self): self.universe = MDAnalysis.Universe(Martini_membrane_gro, Martini_membrane_gro) self.lipid_heads = self.universe.select_atoms("name PO4") @@ -30,6 +32,7 @@ def tearDown(self): del self.universe def test_leaflet_finder(self): + from MDAnalysis.analysis.leaflet import LeafletFinder lfls = LeafletFinder(self.universe, self.lipid_heads, pbc=True) top_heads, bottom_heads = lfls.groups() # Make top be... on top.