|
2 | 2 |
|
3 | 3 | import matplotlib.colors as mcolors |
4 | 4 | from matplotlib.lines import _get_dash_pattern |
5 | | -from matplotlib._style_helpers import style_generator |
| 5 | +from matplotlib._style_helpers import iterate_styles |
6 | 6 |
|
7 | 7 |
|
8 | 8 | @pytest.mark.parametrize('key, value', [('facecolor', ["b", "g", "r"]), |
9 | 9 | ('edgecolor', ["b", "g", "r"]), |
10 | 10 | ('hatch', ["/", "\\", "."]), |
11 | 11 | ('linestyle', ["-", "--", ":"]), |
12 | 12 | ('linewidth', [1, 1.5, 2])]) |
13 | | -def test_style_generator_list(key, value): |
| 13 | +def test_iterate_styles_list(key, value): |
14 | 14 | kw = {'foo': 12, key: value} |
15 | | - new_kw, gen = style_generator(kw) |
16 | | - |
17 | | - assert new_kw == {'foo': 12} |
| 15 | + gen_kw = iterate_styles(kw) |
18 | 16 |
|
19 | 17 | for v in value * 2: # Result should repeat |
20 | | - style_dict = next(gen) |
21 | | - assert len(style_dict) == 1 |
| 18 | + kw_dict = next(gen_kw) |
| 19 | + assert len(kw_dict) == 2 |
| 20 | + assert kw_dict['foo'] == 12 |
22 | 21 | if key.endswith('color'): |
23 | | - assert mcolors.same_color(v, style_dict[key]) |
| 22 | + assert mcolors.same_color(v, kw_dict[key]) |
24 | 23 | elif key == 'linestyle': |
25 | | - assert _get_dash_pattern(v) == style_dict[key] |
| 24 | + assert _get_dash_pattern(v) == kw_dict[key] |
26 | 25 | else: |
27 | | - assert v == style_dict[key] |
| 26 | + assert v == kw_dict[key] |
28 | 27 |
|
29 | 28 |
|
30 | 29 | @pytest.mark.parametrize('key, value', [('facecolor', "b"), |
31 | 30 | ('edgecolor', "b"), |
32 | 31 | ('hatch', "/"), |
33 | 32 | ('linestyle', "-"), |
34 | 33 | ('linewidth', 1)]) |
35 | | -def test_style_generator_single(key, value): |
| 34 | +def test_iterate_styles_single(key, value): |
36 | 35 | kw = {'foo': 12, key: value} |
37 | | - new_kw, gen = style_generator(kw) |
| 36 | + gen_kw = iterate_styles(kw) |
38 | 37 |
|
39 | | - assert new_kw == {'foo': 12} |
40 | 38 | for _ in range(2): # Result should repeat |
41 | | - style_dict = next(gen) |
| 39 | + kw_dict = next(gen_kw) |
| 40 | + assert len(kw_dict) == 2 |
| 41 | + assert kw_dict['foo'] == 12 |
42 | 42 | if key.endswith('color'): |
43 | | - assert mcolors.same_color(value, style_dict[key]) |
44 | | - elif key == 'linestyle': |
45 | | - assert _get_dash_pattern(value) == style_dict[key] |
| 43 | + assert mcolors.same_color(value, kw_dict[key]) |
46 | 44 | else: |
47 | | - assert value == style_dict[key] |
| 45 | + assert value == kw_dict[key] |
48 | 46 |
|
49 | 47 |
|
50 | 48 | @pytest.mark.parametrize('key', ['facecolor', 'hatch', 'linestyle']) |
51 | | -def test_style_generator_empty(key): |
| 49 | +def test_iterate_styles_empty(key): |
52 | 50 | kw = {key: []} |
| 51 | + gen_kw = iterate_styles(kw) |
53 | 52 | with pytest.raises(TypeError, match=f'{key} must not be an empty sequence'): |
54 | | - style_generator(kw) |
| 53 | + next(gen_kw) |
55 | 54 |
|
56 | 55 |
|
57 | | -def test_style_generator_sequence_type_styles(): |
| 56 | +def test_iterate_styles_sequence_type_styles(): |
58 | 57 | kw = {'facecolor': ('r', 0.5), |
59 | 58 | 'edgecolor': [0.5, 0.5, 0.5], |
60 | 59 | 'linestyle': (0, (1, 1))} |
61 | 60 |
|
62 | | - _, gen = style_generator(kw) |
| 61 | + gen_kw = iterate_styles(kw) |
63 | 62 | for _ in range(2): # Result should repeat |
64 | | - style_dict = next(gen) |
65 | | - mcolors.same_color(kw['facecolor'], style_dict['facecolor']) |
66 | | - mcolors.same_color(kw['edgecolor'], style_dict['edgecolor']) |
67 | | - kw['linestyle'] == style_dict['linestyle'] |
| 63 | + kw_dict = next(gen_kw) |
| 64 | + mcolors.same_color(kw['facecolor'], kw_dict['facecolor']) |
| 65 | + mcolors.same_color(kw['edgecolor'], kw_dict['edgecolor']) |
| 66 | + kw['linestyle'] == kw_dict['linestyle'] |
68 | 67 |
|
69 | 68 |
|
70 | | -def test_style_generator_none(): |
| 69 | +def test_iterate_styles_none(): |
71 | 70 | kw = {'facecolor': 'none', |
72 | 71 | 'edgecolor': 'none'} |
73 | | - _, gen = style_generator(kw) |
| 72 | + gen_kw = iterate_styles(kw) |
74 | 73 | for _ in range(2): # Result should repeat |
75 | | - style_dict = next(gen) |
76 | | - assert style_dict['facecolor'] == 'none' |
77 | | - assert style_dict['edgecolor'] == 'none' |
| 74 | + kw_dict = next(gen_kw) |
| 75 | + assert kw_dict['facecolor'] == 'none' |
| 76 | + assert kw_dict['edgecolor'] == 'none' |
0 commit comments