-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TST: Skipif decorator for matplotlib #18190
- Loading branch information
Showing
14 changed files
with
111 additions
and
29 deletions.
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
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
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
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
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
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
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
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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
""" | ||
This module provides decorator functions which can be applied to test objects | ||
in order to skip those objects when certain conditions occur. A sample use case | ||
is to detect if the platform is missing ``matplotlib``. If so, any test objects | ||
which require ``matplotlib`` and marked with ``skip_if_no_mpl`` will be skipped | ||
by ``pytest`` during the execution of the test suite. | ||
The decorators can be applied to classes: | ||
@skip_if_some_reason | ||
class Foo(): | ||
... | ||
Or individual functions: | ||
@skip_if_some_reason | ||
def test_foo(): | ||
... | ||
For more information, refer to the ``pytest`` documentation on ``skipif``. | ||
""" | ||
|
||
import pytest | ||
|
||
|
||
def safe_import(mod_name, min_version=None): | ||
""" | ||
Parameters: | ||
----------- | ||
mod_name : str | ||
Name of the module to be imported | ||
min_version : str, default None | ||
Minimum required version of the specified mod_name | ||
Returns: | ||
-------- | ||
object | ||
The imported module if successful, or False | ||
""" | ||
try: | ||
mod = __import__(mod_name) | ||
except ImportError: | ||
return False | ||
|
||
if not min_version: | ||
return mod | ||
else: | ||
import sys | ||
version = getattr(sys.modules[mod_name], '__version__') | ||
if version: | ||
from distutils.version import LooseVersion | ||
if LooseVersion(version) >= LooseVersion(min_version): | ||
return mod | ||
|
||
return False | ||
|
||
|
||
def _skip_if_no_mpl(): | ||
mod = safe_import("matplotlib") | ||
if mod: | ||
mod.use("Agg", warn=False) | ||
else: | ||
return True | ||
|
||
|
||
skip_if_no_mpl = pytest.mark.skipif(_skip_if_no_mpl(), | ||
reason="Missing matplotlib dependency") |
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