-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
46 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from contextlib import contextmanager | ||
|
||
import matplotlib | ||
import pytest | ||
|
||
from . import figure_context | ||
|
||
|
||
def get_renderer(f): | ||
|
||
if hasattr(f.canvas, "get_renderer"): | ||
return f.canvas.get_renderer() | ||
elif hasattr(f, "_get_renderer"): | ||
return f._get_renderer() | ||
|
||
backend = matplotlib.get_backend() | ||
|
||
raise AttributeError( | ||
f"Could not find a renderer for the '{backend}' backend. Please raise an issue" | ||
) | ||
|
||
|
||
@contextmanager | ||
def restore_backend(): | ||
|
||
backend = matplotlib.get_backend() | ||
|
||
try: | ||
yield | ||
except Exception: | ||
matplotlib.use(backend) | ||
|
||
|
||
@pytest.mark.parametrize("backend", matplotlib.rcsetup.all_backends) | ||
def test_get_renderer(backend): | ||
|
||
with restore_backend(): | ||
try: | ||
matplotlib.use(backend) | ||
except ImportError: | ||
pytest.skip(backend) | ||
|
||
with figure_context() as f: | ||
get_renderer(f) |