8000 Shorten usage of `@image_comparison`. · matplotlib/matplotlib@8108d33 · GitHub
[go: up one dir, main page]

Skip to content
  • Commit 8108d33

    Browse files
    committed
    Shorten usage of @image_comparison.
    ``` @image_comparison(baseline_images=["foo"], extensions=["png"]) ``` is quite a mouthful. Shorten it to ``` @image_comparison(["foo.png"]) ``` instead (in the common cases when either only one extension or all extensions are tested). The only interesting change is in `decorators.py`; the rest is just regexps and manual changes.
    1 parent d062859 commit 8108d33

    Some content is hidden

    Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

    50 files changed

    +616
    -943
    lines changed

    lib/matplotlib/testing/decorators.py

    Lines changed: 22 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -366,6 +366,10 @@ def image_comparison(baseline_images, extensions=None, tol=0,
    366366
    367367
    If *None*, defaults to all supported extensions: png, pdf, and svg.
    368368
    369+
    When testing a single extension, it can be directly included in the
    370+
    names passed to *baseline_images*. In that case, *extensions* must not
    371+
    be set.
    372+
    369373
    In order to keep the size of the test suite from ballooning, we only
    370374
    include the ``svg`` or ``pdf`` outputs if the test is explicitly
    371375
    exercising a feature dependent on that backend (see also the
    @@ -393,10 +397,26 @@ def image_comparison(baseline_images, extensions=None, tol=0,
    393397
    Optional name for the base style to apply to the image test. The test
    394398
    itself can also apply additional styles if desired. Defaults to the
    395399
    '_classic_test' style.
    396-
    397400
    """
    401+
    402+
    if baseline_images is not None:
    403+
    # List of non-empty filename extensions.
    404+
    baseline_exts = [*filter(None, {Path(baseline).suffix[1:]
    405+
    for baseline in baseline_images})]
    406+
    if baseline_exts:
    407+
    if extensions is not None:
    408+
    raise ValueError(
    409+
    "When including extensions directly in 'baseline_images', "
    410+
    "'extensions' cannot be set as well")
    411+
    if len(baseline_exts) > 1:
    412+
    raise ValueError(
    413+
    "When including extensions directly in 'baseline_images', "
    414+
    "all baselines must share the same suffix")
    415+
    extensions = baseline_exts
    416+
    baseline_images = [ # Chop suffix out from baseline_images.
    417+
    Path(baseline).stem for baseline in baseline_images]
    398418
    if extensions is None:
    399-
    # default extensions to test
    419+
    # Default extensions to test, if not set via baseline_images.
    400420
    extensions = ['png', 'pdf', 'svg']
    401421

    402422
    if savefig_kwarg is None:

    lib/matplotlib/tests/test_agg.py

    Lines changed: 1 addition & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -78,8 +78,7 @@ def test_long_path():
    7878
    fig.savefig(buff, format='png')
    7979

    8080

    81-
    @image_comparison(baseline_images=['agg_filter'],
    82-
    extensions=['png'], remove_text=True)
    81+
    @image_comparison(['agg_filter.png'], remove_text=True)
    8382
    def test_agg_filter():
    8483
    def smooth1d(x, window_len):
    8584
    s = np.r_[2*x[0] - x[window_len:1:-1],

    lib/matplotlib/tests/test_arrow_patches.py

    Lines changed: 7 additions & 13 deletions
    Original file line numberDiff line numberDiff line change
    @@ -11,7 +11,7 @@ def draw_arrow(ax, t, r):
    1111
    fc="b", ec='k'))
    1212

    1313

    14-
    @image_comparison(baseline_images=['fancyarrow_test_image'])
    14+
    @image_comparison(['fancyarrow_test_image'])
    1515
    def test_fancyarrow():
    1616
    # Added 0 to test division by zero error described in issue 3930
    1717
    r = [0.4, 0.3, 0.2, 0.1, 0]
    @@ -28,7 +28,7 @@ def test_fancyarrow():
    2828
    ax.tick_params(labelleft=False, labelbottom=False)
    2929

    3030

    31-
    @image_comparison(baseline_images=['boxarrow_test_image'], extensions=['png'])
    31+
    @image_comparison(['boxarrow_test_image.png'])
    3232
    def test_boxarrow():
    3333

    3434
    styles = mpatches.BoxStyle.get_styles()
    @@ -67,8 +67,7 @@ def __prepare_fancyarrow_dpi_cor_test():
    6767
    return fig2
    6868

    6969

    70-
    @image_comparison(baseline_images=['fancyarrow_dpi_cor_100dpi'],
    71-
    remove_text=True, extensions=['png'],
    70+
    @image_comparison(['fancyarrow_dpi_cor_100dpi.png'], remove_text=True,
    7271
    tol={'aarch64': 0.02}.get(platform.machine(), 0.0),
    7372
    savefig_kwarg=dict(dpi=100))
    7473
    def test_fancyarrow_dpi_cor_100dpi():
    @@ -83,8 +82,7 @@ def test_fancyarrow_dpi_cor_100dpi():
    8382
    __prepare_fancyarrow_dpi_cor_test()
    8483

    8584

    86-
    @image_comparison(baseline_images=['fancyarrow_dpi_cor_200dpi'],
    87-
    remove_text=True, extensions=['png'],
    85+
    @image_comparison(['fancyarrow_dpi_cor_200dpi.png'], remove_text=True,
    8886
    tol={'aarch64': 0.02}.get(platform.machine(), 0.0),
    8987
    savefig_kwarg=dict(dpi=200))
    9088
    def test_fancyarrow_dpi_cor_200dpi():
    @@ -96,9 +94,7 @@ def test_fancyarrow_dpi_cor_200dpi():
    9694
    __prepare_fancyarrow_dpi_cor_test()
    9795

    9896

    99-
    @image_comparison(baseline_images=['fancyarrow_dash'],
    100-
    remove_text=True, extensions=['png'],
    101-
    style='default')
    97+
    @image_comparison(['fancyarrow_dash.png'], remove_text=True, style='default')
    10298
    def test_fancyarrow_dash():
    10399
    from matplotlib.patches import FancyArrowPatch
    104100
    fig, ax = plt.subplots()
    @@ -122,8 +118,7 @@ def test_fancyarrow_dash():
    122118
    ax.add_patch(e2)
    123119

    124120

    125-
    @image_comparison(baseline_images=['arrow_styles'], extensions=['png'],
    126-
    style='mpl20', remove_text=True)
    121+
    @image_comparison(['arrow_styles.png'], style='mpl20', remove_text=True)
    127122
    def test_arrow_styles():
    128123
    styles = mpatches.ArrowStyle.get_styles()
    129124

    @@ -139,8 +134,7 @@ def test_arrow_styles():
    139134
    ax.add_patch(patch)
    140135

    141136

    142-
    @image_comparison(baseline_images=['connection_styles'], extensions=['png'],
    143-
    style='mpl20', remove_text=True)
    137+
    @image_comparison(['connection_styles.png'], style='mpl20', remove_text=True)
    144138
    def test_connection_styles():
    145139
    styles = mpatches.ConnectionStyle.get_styles()
    146140

    lib/matplotlib/tests/test_artist.py

    Lines changed: 3 additions & 5 deletions
    < 7BE0 td data-grid-cell-id="diff-b0287ae4c229762a1d0ef7500f7a6245aee06a09a56f64bb8ad521afb3ba9140-148-147-2" data-line-anchor="diff-b0287ae4c229762a1d0ef7500f7a6245aee06a09a56f64bb8ad521afb3ba9140R147" data-selected="false" role="gridcell" style="background-color:var(--bgColor-default);padding-right:24px" tabindex="-1" valign="top" class="focusable-grid-cell diff-text-cell right-side-diff-cell left-side">
    fig, ax = plt.subplots(1, 1)
    Original file line numberDiff line numberDiff line change
    @@ -94,7 +94,7 @@ def test_collection_transform_of_none():
    9494
    assert isinstance(c._transOffset, mtransforms.IdentityTransform)
    9595

    9696

    97-
    @image_comparison(baseline_images=["clip_path_clipping"], remove_text=True)
    97+
    @image_comparison(["clip_path_clipping"], remove_text=True)
    9898
    def test_clipping():
    9999
    exterior = mpath.Path.unit_rectangle().deepcopy()
    100100
    exterior.vertices *= 4
    @@ -142,8 +142,7 @@ def test_cull_markers():
    142142
    assert len(svg.getvalue()) < 20000
    143143

    144144

    145-
    @image_comparison(baseline_images=['hatching'], remove_text=True,
    146-
    style='default')
    145+
    @image_comparison(['hatching'], remove_text=True, style='default')
    147146
    def test_hatching():
    148147
    149148

    @@ -200,8 +199,7 @@ def test_remove():
    200199
    assert ax.stale
    201200

    202201

    203-
    @image_comparison(baseline_images=["default_edges"], remove_text=True,
    204-
    extensions=['png'], style='default')
    202+
    @image_comparison(["default_edges.png"], remove_text=True, style='default')
    205203
    def test_default_edges():
    206204
    fig, [[ax1, ax2], [ax3, ax4]] = plt.subplots(2, 2)
    207205

    0 commit comments

    Comments
     (0)
    0