File: test_default_backend.py

package info (click to toggle)
pytest-mpl 0.17.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,132 kB
  • sloc: python: 2,514; javascript: 179; makefile: 16
file content (35 lines) | stat: -rw-r--r-- 995 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import pytest


@pytest.mark.parametrize(
    "ini, cli, kwarg, expected",
    [
        ("backend1", None, None, "backend1"),
        ("backend1", "backend2", None, "backend2"),
        ("backend1", "backend2", "backend3", "backend3"),
    ],
)
def test_config(pytester, ini, cli, kwarg, expected):
    ini = f"mpl-default-backend = {ini}" if ini else ""
    pytester.makeini(
        f"""
        [pytest]
        {ini}
        """
    )
    kwarg = f"backend='{kwarg}'" if kwarg else ""
    pytester.makepyfile(
        f"""
        import matplotlib.pyplot as plt
        import pytest
        @pytest.mark.mpl_image_compare({kwarg})
        def test_mpl():
            fig, ax = plt.subplots()
            ax.plot([1, 2, 3])
            return fig
        """
    )
    cli = f"--mpl-default-backend={cli}" if cli else ""
    result = pytester.runpytest("--mpl", cli)
    result.assert_outcomes(failed=1)
    result.stdout.re_match_lines([f".*(ModuleNotFound|Value)Error: .*{expected}.*"])