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