|
12 | 12 | import matplotlib.pyplot as plt
|
13 | 13 | from matplotlib.tests import assert_str_equal
|
14 | 14 | from matplotlib.testing.decorators import cleanup, knownfailureif
|
| 15 | +import matplotlib.colors as mcolors |
15 | 16 | from nose.tools import assert_true, assert_raises, assert_equal
|
16 | 17 | from nose.plugins.skip import SkipTest
|
17 | 18 | import nose
|
@@ -183,21 +184,46 @@ def test_Bug_2543_newer_python():
|
183 | 184 |
|
184 | 185 |
|
185 | 186 | @cleanup
|
186 |
| -def test_legend_facecolor(): |
187 |
| - with mpl.rc_context({'legend.facecolor': 'r'}): |
| 187 | +def _legend_rcparam_helper(param_dict, target, get_func): |
| 188 | + with mpl.rc_context(param_dict): |
188 | 189 | _, ax = plt.subplots()
|
189 | 190 | ax.plot(range(3), label='test')
|
190 | 191 | leg = ax.legend()
|
191 |
| - assert_equal(leg.legendPatch.get_facecolor(), (1, 0, 0, 1)) |
| 192 | + assert_equal(getattr(leg.legendPatch, get_func)(), target) |
| 193 | + |
| 194 | + |
| 195 | +def test_legend_facecolor(): |
| 196 | + get_func = 'get_facecolor' |
| 197 | + rcparam = 'legend.facecolor' |
| 198 | + test_values = [({rcparam: 'r'}, |
| 199 | + mcolors.colorConverter.to_rgba('r')), |
| 200 | + ({rcparam: 'inherit', |
| 201 | + 'axes.facecolor': 'r' |
| 202 | + }, |
| 203 | + mcolors.colorConverter.to_rgba('r')), |
| 204 | + ({rcparam: 'g', |
| 205 | + 'axes.facecolor': 'r'}, |
| 206 | + mcolors.colorConverter.to_rgba('g')) |
| 207 | + ] |
| 208 | + for rc_dict, target in test_values: |
| 209 | + yield _legend_rcparam_helper, rc_dict, target, get_func |
192 | 210 |
|
193 | 211 |
|
194 |
| -@cleanup |
195 | 212 | def test_legend_edgecolor():
|
196 |
| - with mpl.rc_context({'legend.edgecolor': 'r'}): |
197 |
| - _, ax = plt.subplots() |
198 |
| - ax.plot(range(3), label='test') |
199 |
| - leg = ax.legend() |
200 |
| - assert_equal(leg.legendPatch.get_edgecolor(), (1, 0, 0, 1)) |
| 213 | + get_func = 'get_edgecolor' |
| 214 | + rcparam = 'legend.edgecolor' |
| 215 | + test_values = [({rcparam: 'r'}, |
| 216 | + mcolors.colorConverter.to_rgba('r')), |
| 217 | + ({rcparam: 'inherit', |
| 218 | + 'axes.edgecolor': 'r' |
| 219 | + }, |
| 220 | + mcolors.colorConverter.to_rgba('r')), |
| 221 | + ({rcparam: 'g', |
| 222 | + 'axes.facecolor': 'r'}, |
| 223 | + mcolors.colorConverter.to_rgba('g')) |
| 224 | + ] |
| 225 | + for rc_dict, target in test_values: |
| 226 | + yield _legend_rcparam_helper, rc_dict, target, get_func |
201 | 227 |
|
202 | 228 |
|
203 | 229 | def test_Issue_1713():
|
|
0 commit comments