8000 Merge pull request #16950 from meeseeksmachine/auto-backport-of-pr-16… · matplotlib/matplotlib@0c6c184 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0c6c184

Browse files
authored
Merge pull request #16950 from meeseeksmachine/auto-backport-of-pr-16949-on-v3.2.x
Backport PR #16949 on branch v3.2.x (TST: Don't modify actual pyplot file for boilerplate test.)
2 parents bde95b2 + ffa1669 commit 0c6c184

File tree

2 files changed

+29
-25
lines changed

2 files changed

+29
-25
lines changed

lib/matplotlib/tests/test_pyplot.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,32 @@
99
from matplotlib import pyplot as plt
1010

1111

12-
def test_pyplot_up_to_date():
12+
def test_pyplot_up_to_date(tmpdir):
1313
gen_script = Path(mpl.__file__).parents[2] / "tools/boilerplate.py"
1414
if not gen_script.exists():
1515
pytest.skip("boilerplate.py not found")
1616
orig_contents = Path(plt.__file__).read_text()
17-
try:
18-
subprocess.run([sys.executable, str(gen_script)], check=True)
19-
new_contents = Path(plt.__file__).read_text()
20-
21-
if orig_contents != new_contents:
22-
diff_msg = '\n'.join(
23-
difflib.unified_diff(
24-
orig_contents.split('\n'), new_contents.split('\n'),
25-
fromfile='found pyplot.py',
26-
tofile='expected pyplot.py',
27-
n=0, lineterm=''))
28-
pytest.fail(
29-
"pyplot.py is not up-to-date. Please run "
30-
"'python tools/boilerplate.py' to update pyplot.py. "
31-
"This needs to be done from an environment where your "
32-
"current working copy is installed (e.g. 'pip install -e'd). "
33-
"Here is a diff of unex 8000 pected differences:\n%s" % diff_msg
34-
)
35-
finally:
36-
Path(plt.__file__).write_text(orig_contents)
17+
plt_file = tmpdir.join('pyplot.py')
18+
plt_file.write_text(orig_contents, 'utf-8')
19+
20+
subprocess.run([sys.executable, str(gen_script), str(plt_file)],
21+
check=True)
22+
new_contents = plt_file.read_text('utf-8')
23+
24+
if orig_contents != new_contents:
25+
diff_msg = '\n'.join(
26+
difflib.unified_diff(
27+
orig_contents.split('\n'), new_contents.split('\n'),
28+
fromfile='found pyplot.py',
29+
tofile='expected pyplot.py',
30+
n=0, lineterm=''))
31+
pytest.fail(
32+
"pyplot.py is not up-to-date. Please run "
33+
"'python tools/boilerplate.py' to update pyplot.py. "
34+
"This needs to be done from an environment where your "
35+
"current working copy is installed (e.g. 'pip install -e'd). "
36+
"Here is a diff of unexpected differences:\n%s" % diff_msg
37+
)
3738

3839

3940
def test_pyplot_box():

tools/boilerplate.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import inspect
1717
from inspect import Parameter
1818
from pathlib import Path
19+
import sys
1920
import textwrap
2021

2122
# This line imports the installed copy of matplotlib, and not the local copy.
@@ -327,9 +328,7 @@ def boilerplate_gen():
327328
yield '_setup_pyplot_info_docstrings()'
328329

329330

330-
def build_pyplot():
331-
pyplot_path = Path(__file__).parent / "../lib/matplotlib/pyplot.py"
332-
331+
def build_pyplot(pyplot_path):
333332
pyplot_orig = pyplot_path.read_text().splitlines(keepends=True)
334333
try:
335334
pyplot_orig = pyplot_orig[:pyplot_orig.index(PYPLOT_MAGIC_HEADER) + 1]
@@ -345,4 +344,8 @@ def build_pyplot():
345344

346345
if __name__ == '__main__':
347346
# Write the matplotlib.pyplot file.
348-
build_pyplot()
347+
if len(sys.argv) > 1:
348+
pyplot_path = Path(sys.argv[1])
349+
else:
350+
pyplot_path = Path(__file__).parent / "../lib/matplotlib/pyplot.py"
351+
build_pyplot(pyplot_path)

0 commit comments

Comments
 (0)
0