Skip to content

Commit 7b3f389

Browse files
strengthen zero-width dash regression tests
1 parent 0fe9994 commit 7b3f389

3 files changed

Lines changed: 31 additions & 12 deletions

File tree

lib/matplotlib/tests/test_axes.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8081,12 +8081,6 @@ def test_twinning_default_axes_class():
80818081
assert type(twiny) is Axes
80828082

80838083

8084-
@check_figures_equal()
8085-
def test_zero_linewidth(fig_test, fig_ref):
8086-
fig_test.subplots().plot([0, 1], [0, 1], ls='--', lw=0)
8087-
fig_ref.subplots().plot([0, 1], [0, 1], ls='-', lw=0)
8088-
8089-
80908084
@mpl.style.context('mpl20')
80918085
@check_figures_equal()
80928086
def test_stairs_fill_zero_linewidth(fig_test, fig_ref):

lib/matplotlib/tests/test_lines.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import itertools
66
import platform
77
from types import SimpleNamespace
8+
import unittest.mock
89

910
from cycler import cycler
1011
import numpy as np
@@ -92,6 +93,21 @@ def test_valid_linestyles():
9293
line.set_linestyle('aardvark')
9394

9495

96+
@mpl.style.context('mpl20')
97+
def test_zero_linewidth_dashed_uses_solid_gc_dashes():
98+
fig, ax = plt.subplots()
99+
line, = ax.plot([0, 1], [0, 1], ls='--', lw=0)
100+
renderer = fig.canvas.get_renderer()
101+
with unittest.mock.patch(
102+
"matplotlib.backend_bases.GraphicsContextBase.set_dashes",
103+
autospec=True,
104+
wraps=matplotlib.backend_bases.GraphicsContextBase.set_dashes,
105+
) as set_dashes:
106+
line.draw(renderer)
107+
108+
assert set_dashes.call_args_list[-1].args[1:] == (0, None)
109+
110+
95111
@image_comparison(['drawstyle_variants.png'], remove_text=True,
96112
tol=0 if platform.machine() == 'x86_64' else 0.03)
97113
def test_drawstyle_variants():

lib/matplotlib/tests/test_patches.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Tests specific to the patches module.
33
"""
44
import platform
5+
import unittest.mock
56

67
import numpy as np
78
from numpy.testing import assert_almost_equal, assert_array_equal
@@ -907,12 +908,20 @@ def test_default_linestyle():
907908
assert patch.get_linestyle() == 'solid'
908909

909910

910-
@check_figures_equal()
911-
def test_patch_zero_linewidth_dashed_draw(fig_test, fig_ref):
912-
fig_test.subplots().add_patch(
913-
Rectangle((0, 0), 1, 1, fill=False, linewidth=0, linestyle='--'))
914-
fig_ref.subplots().add_patch(
915-
Rectangle((0, 0), 1, 1, fill=False, linewidth=0, linestyle='-'))
911+
@mpl.style.context('mpl20')
912+
def test_patch_zero_linewidth_dashed_uses_solid_gc_dashes():
913+
_, ax = plt.subplots()
914+
rect = Rectangle((0, 0), 1, 1, fill=False, linewidth=0, linestyle='--')
915+
ax.add_patch(rect)
916+
renderer = ax.figure.canvas.get_renderer()
917+
with unittest.mock.patch(
918+
"matplotlib.backend_bases.GraphicsContextBase.set_dashes",
919+
autospec=True,
920+
wraps=mpl.backend_bases.GraphicsContextBase.set_dashes,
921+
) as set_dashes:
922+
rect.draw(renderer)
923+
924+
assert set_dashes.call_args_list[-1].args[1:] == (0, None)
916925

917926

918927
def test_default_capstyle():

0 commit comments

Comments
 (0)