-
Notifications
You must be signed in to change notification settings - Fork 667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TST: Added scipy import warning unit test to test_distances.py. #1141
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2882cd4
TST: Added scipy import warning unit test to test_distances.py.
tylerjereddy dbf6520
TST: Added block_import to MDAnalysisTests.util (#1143)
richardjgowers 9585220
TST: Attempted fix of relative imports in PR#1141.
tylerjereddy 207efff
TST: updated test_distances.py to use new block_import decorator.
tylerjereddy 7f2ab69
TST: TestImportWarnings now clears analysis.distances from sys.module…
tylerjereddy 20d0124
TST: TestImportWarnings now checks for the exception raised if scipy …
tylerjereddy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ | |
|
||
from numpy.testing import TestCase, assert_equal, dec | ||
import numpy as np | ||
import warnings | ||
|
||
|
||
class TestContactMatrix(TestCase): | ||
|
@@ -186,3 +187,22 @@ def test_between_simple_case_indices_only(self): | |
self.ag2, | ||
self.distance).indices) | ||
assert_equal(actual, self.expected) | ||
|
||
class TestImportWarnings(TestCase): | ||
|
||
def test_no_exception_scipy_module_level(self): | ||
# a module level ImportError should never be raised, even if | ||
# scipy is absent ; only silent success or a warning | ||
# see unit testing for warnings: | ||
# http://stackoverflow.com/a/3892301 | ||
|
||
if module_not_found('scipy'): | ||
with warnings.catch_warnings(record=True) as w: | ||
warnings.simplefilter("always") | ||
import MDAnalysis.analysis.distances | ||
assert issubclass(w[-1].category, ImportWarning) | ||
else: # no warning if scipy is present | ||
with warnings.catch_warnings(record=True) as w: | ||
warnings.simplefilter("always") | ||
import MDAnalysis.analysis.distances | ||
assert w == [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do like checking that we don't warn when not necessary though! |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can wrap this with the PR I put up, so it always issue a warning. Then split the
else:
branch of this if into a separate test that only runs when the scipy module is present.