Skip to content

Commit

Permalink
test get renderer fcn
Browse files Browse the repository at this point in the history
  • Loading branch information
mathause committed May 29, 2024
1 parent 3abb8d8 commit 275bd8e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest"]
os: ["ubuntu-latest", "macos-latest", "windows-latest"]
# Bookend python versions
python-version: ["3.9", "3.11", "3.12"]
steps:
Expand Down Expand Up @@ -52,7 +52,7 @@ jobs:
python -c "import mplotutils"
- name: Run tests
timeout-minutes: 5
run: python -u -m pytest
run: python -u -m pytest -vv
--cov=mplotutils
--cov-report=xml
--junitxml=test-results/${{ runner.os }}-${{ matrix.python-version }}.xml
Expand Down
44 changes: 44 additions & 0 deletions mplotutils/tests/test_get_renderer.py
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)

0 comments on commit 275bd8e

Please sign in to comment.