forked from matplotlib/matplotlib
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_pyplot.py
More file actions
155 lines (124 loc) · 4 KB
/
Copy pathtest_pyplot.py
File metadata and controls
155 lines (124 loc) · 4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import difflib
import subprocess
import sys
from pathlib import Path
import pytest
import matplotlib as mpl
from matplotlib import pyplot as plt
from matplotlib.cbook import MatplotlibDeprecationWarning
def test_pyplot_up_to_date(tmpdir):
gen_script = Path(mpl.__file__).parents[2] / "tools/boilerplate.py"
if not gen_script.exists():
pytest.skip("boilerplate.py not found")
orig_contents = Path(plt.__file__).read_text()
plt_file = tmpdir.join('pyplot.py')
plt_file.write_text(orig_contents, 'utf-8')
subprocess.run([sys.executable, str(gen_script), str(plt_file)],
check=True)
new_contents = plt_file.read_text('utf-8')
if orig_contents != new_contents:
diff_msg = '\n'.join(
difflib.unified_diff(
orig_contents.split('\n'), new_contents.split('\n'),
fromfile='found pyplot.py',
tofile='expected pyplot.py',
n=0, lineterm=''))
pytest.fail(
"pyplot.py is not up-to-date. Please run "
"'python tools/boilerplate.py' to update pyplot.py. "
"This needs to be done from an environment where your "
"current working copy is installed (e.g. 'pip install -e'd). "
"Here is a diff of unexpected differences:\n%s" % diff_msg
)
def test_copy_docstring_and_deprecators(recwarn):
@mpl.cbook._rename_parameter("(version)", "old", "new")
@mpl.cbook._make_keyword_only("(version)", "kwo")
def func(new, kwo=None):
pass
@plt._copy_docstring_and_deprecators(func)
def wrapper_func(new, kwo=None):
pass
wrapper_func(None)
wrapper_func(new=None)
wrapper_func(None, kwo=None)
wrapper_func(new=None, kwo=None)
assert not recwarn
with pytest.warns(MatplotlibDeprecationWarning):
wrapper_func(old=None)
with pytest.warns(MatplotlibDeprecationWarning):
wrapper_func(None, None)
def test_pyplot_box():
fig, ax = plt.subplots()
plt.box(False)
assert not ax.get_frame_on()
plt.box(True)
assert ax.get_frame_on()
plt.box()
assert not ax.get_frame_on()
plt.box()
assert ax.get_frame_on()
def test_stackplot_smoke():
# Small smoke test for stackplot (see #12405)
plt.stackplot([1, 2, 3], [1, 2, 3])
def test_nrows_error():
with pytest.raises(TypeError):
plt.subplot(nrows=1)
with pytest.raises(TypeError):
plt.subplot(ncols=1)
def test_ioff():
plt.ion()
assert mpl.is_interactive()
with plt.ioff():
assert not mpl.is_interactive()
assert mpl.is_interactive()
plt.ioff()
assert not mpl.is_interactive()
with plt.ioff():
assert not mpl.is_interactive()
assert not mpl.is_interactive()
def test_ion():
plt.ioff()
assert not mpl.is_interactive()
with plt.ion():
assert mpl.is_interactive()
assert not mpl.is_interactive()
plt.ion()
assert mpl.is_interactive()
with plt.ion():
assert mpl.is_interactive()
assert mpl.is_interactive()
def test_nested_ion_ioff():
# initial state is interactive
plt.ion()
# mixed ioff/ion
with plt.ioff():
assert not mpl.is_interactive()
with plt.ion():
assert mpl.is_interactive()
assert not mpl.is_interactive()
assert mpl.is_interactive()
# redundant contexts
with plt.ioff():
with plt.ioff():
assert not mpl.is_interactive()
assert mpl.is_interactive()
with plt.ion():
plt.ioff()
assert mpl.is_interactive()
# initial state is not interactive
plt.ioff()
# mixed ioff/ion
with plt.ion():
assert mpl.is_interactive()
with plt.ioff():
assert not mpl.is_interactive()
assert mpl.is_interactive()
assert not mpl.is_interactive()
# redunant contexts
with plt.ion():
with plt.ion():
assert mpl.is_interactive()
assert not mpl.is_interactive()
with plt.ioff():
plt.ion()
assert not mpl.is_interactive()