File: test_generate_summary.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 (65 lines) | stat: -rw-r--r-- 1,810 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import json

import pytest
from helpers import pytester_path


@pytest.mark.parametrize(
    "ini, cli, expected",
    [
        ("json", None, {"json"}),
        ("json", "html", {"html"}),
        ("basic-html", "json", {"json"}),
        (None, "json,basic-html,html", {"json", "basic-html", "html"}),
    ],
)
def test_config(pytester, ini, cli, expected):
    path = pytester_path(pytester)
    ini = f"mpl-generate-summary = {ini}" if ini else ""
    pytester.makeini(
        f"""
        [pytest]
        mpl-results-path = {path}
        {ini}
        """
    )
    pytester.makepyfile(
        """
        import matplotlib.pyplot as plt
        import pytest
        @pytest.mark.mpl_image_compare
        def test_mpl():
            fig, ax = plt.subplots()
            ax.plot([1, 2, 3])
            return fig
        """
    )
    cli = f"--mpl-generate-summary={cli}" if cli else ""
    result = pytester.runpytest("--mpl", cli)
    result.assert_outcomes(failed=1)

    json_summary = path / "results.json"
    if "json" in expected:
        with open(json_summary) as fp:
            results = json.load(fp)
            assert "test_config.test_mpl" in results
    else:
        assert not json_summary.exists()

    html_summary = path / "fig_comparison.html"
    if "html" in expected:
        with open(html_summary) as fp:
            raw = fp.read()
        assert "bootstrap" in raw
        assert "test_config.test_mpl" in raw
    else:
        assert not html_summary.exists()

    basic_html_summary = path / "fig_comparison_basic.html"
    if "basic-html" in expected:
        with open(basic_html_summary) as fp:
            raw = fp.read()
        assert "bootstrap" not in raw
        assert "test_config.test_mpl" in raw
    else:
        assert not basic_html_summary.exists()