Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8f9ce77

Browse files
henryhu123DennisTismenko
authored andcommitted
Fix test cases based on feedback
1 parent db133b0 commit 8f9ce77

File tree

1 file changed

+42
-57
lines changed

1 file changed

+42
-57
lines changed

lib/matplotlib/tests/test_axes.py

Lines changed: 42 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -3992,72 +3992,57 @@ def test_hlines():
39923992
ax5.set_ylim(0, 15)
39933993

39943994

3995-
def generate_hlines_with_colors_inputs():
3996-
colors = cycler('colors', [['red', 'green', 'blue', 'purple', 'orange']])
3997-
base_y = cycler(
3998-
'y', [[1, 2, 3, np.nan, 5], np.ma.masked_equal([1, 2, 3, 4, 5], 4)])
3999-
base_max = cycler('xmax', [np.ones(5)])
4000-
base_min = cycler('xmin', [0])
4001-
base_line_width = cycler('linewidth', [5])
4002-
original = base_y * base_min * base_max * colors * base_line_width
3995+
def generate_lines_with_colors_inputs():
3996+
colors = ['red', 'green', 'blue', 'purple', 'orange']
3997+
xy_nan = [1, 2, 3, np.nan, 5]
3998+
xy_mask = np.ma.masked_equal([1, 2, 3, 4, 5], 4)
3999+
lines_nan = [{'base_xy': xy_nan,
4000+
'base_max': np.ones(5),
4001+
'base_min': [0],
4002+
'linewidth': 5,
4003+
'colors': colors}]
4004+
lines_mask = [{'base_xy': xy_mask,
4005+
'base_max': np.ones(5),
4006+
'base_min': [0],
4007+
'linewidth': 5,
4008+
'colors': colors}]
4009+
4010+
return [*lines_nan, *lines_mask]
4011+
4012+
4013+
@pytest.mark.parametrize('kwargs', generate_lines_with_colors_inputs())
4014+
@check_figures_equal(extensions=["png"])
4015+
def test_vlines_with_colors(fig_test, fig_ref, kwargs):
4016+
kwargs['x'] = kwargs.pop('base_xy')
4017+
kwargs['ymin'] = kwargs.pop('base_min')
4018+
kwargs['ymax'] = kwargs.pop('base_max')
4019+
fig_test.subplots().vlines(**kwargs)
40034020

40044021
expect = {
4005-
'y': [1, 2, 3, 5],
4006-
'xmin': 0, 'xmax': [1, 2, 3, 5],
4007-
'colors': ['red', 'green', 'blue', 'orange']}
4008-
4009-
result = []
4010-
4011-
for i in original:
4012-
result.append({'original': i, 'expect': expect})
4022+
'x': [1, 2, 3, 5],
4023+
'ymin': [0],
4024+
'ymax': np.ones(4),
4025+
'colors': ['red', 'green', 'blue', 'orange'],
4026+
'linewidth': 5}
4027+
fig_ref.subplots().vlines(**expect)
40134028

4014-
return result
40154029

4016-
4017-
@pytest.mark.parametrize('kwargs', generate_hlines_with_colors_inputs())
4030+
@pytest.mark.parametrize('kwargs', generate_lines_with_colors_inputs())
40184031
@check_figures_equal(extensions=["png"])
40194032
def test_hlines_with_colors(fig_test, fig_ref, kwargs):
4020-
fig_test, ax0 = plt.subplots()
4021-
test = kwargs.pop('original')
4022-
ax0.hlines(**test)
4023-
4024-
fig_ref, ax1 = plt.subplots()
4025-
ref = kwargs.pop('expect')
4026-
ax1.hlines(**ref)
4027-
4028-
4029-
def generate_vlines_with_colors_inputs():
4030-
colors = cycler('colors', [['red', 'green', 'blue', 'purple', 'orange']])
4031-
base_x = cycler(
4032-
'x', [[1, 2, 3, np.nan, 5], np.ma.masked_equal([1, 2, 3, 4, 5], 4)])
4033-
base_max = cycler('ymax', [np.ones(5)])
4034-
base_min = cycler('ymin', [0])
4035-
base_line_width = cycler('linewidth', [5])
4036-
original = base_x * base_min * base_max * colors * base_line_width
4033+
kwargs['y'] = kwargs.pop('base_xy')
4034+
kwargs['xmin'] = kwargs.pop('base_min')
4035+
kwargs['xmax'] = kwargs.pop('base_max')
4036+
fig_test.subplots().hlines(**kwargs)
40374037

40384038
expect = {
4039-
'x': [1, 2, 3, 5],
4040-
'ymin': 0,
4041-
'ymax': [1, 2, 3, 5],
4042-
'colors': ['red', 'green', 'blue', 'orange']}
4043-
4044-
result = []
4045-
for i in original:
4046-
result.append({'original': i, 'expect': expect})
4047-
4048-
return result
4049-
4050-
4051-
@pytest.mark.parametrize('kwargs', generate_vlines_with_colors_inputs())
4052-
@check_figures_equal(extensions=["png"])
4053-
def test_vlines_with_colors(fig_test, fig_ref, kwargs):
4054-
fig_test, ax0 = plt.subplots()
4055-
test = kwargs.pop('original')
4056-
ax0.vlines(**test)
4039+
'y': [1, 2, 3, 5],
4040+
'xmin': [0],
4041+
'xmax': np.ones(4),
4042+
'colors': ['red', 'green', 'blue', 'orange'],
4043+
'linewidth': 5}
40574044

4058-
fig_ref, ax1 = plt.subplots()
4059-
ref = kwargs.pop('expect')
4060-
ax1.vlines(**ref)
4045+
fig_ref.subplots().hlines(**expect)
40614046

40624047

40634048
@image_comparison(['step_linestyle', 'step_linestyle'], remove_text=True)

0 commit comments

Comments
 (0)