Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f4d42f7

Browse filesBrowse files
committed
TST: Don't modify actual pyplot file for boilerplate test.
This should prevent git/versioneer from thinking the working tree is dirty if some parallel test happens to run while this one is mid-write.
1 parent f10bcee commit f4d42f7
Copy full SHA for f4d42f7

File tree

Expand file treeCollapse file tree

2 files changed

+29
-25
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+29
-25
lines changed
Open diff view settings
Collapse file

‎lib/matplotlib/tests/test_pyplot.py‎

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_pyplot.py
+22-21Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,32 @@
1010
from matplotlib.cbook import MatplotlibDeprecationWarning
1111

1212

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

3940

4041
def test_copy_docstring_and_deprecators(recwarn):
Collapse file

‎tools/boilerplate.py‎

Copy file name to clipboardExpand all lines: tools/boilerplate.py
+7-4Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import inspect
1818
from inspect import Parameter
1919
from pathlib import Path
20+
import sys
2021
import textwrap
2122

2223
# This line imports the installed copy of matplotlib, and not the local copy.
@@ -337,9 +338,7 @@ def boilerplate_gen():
337338
yield '_setup_pyplot_info_docstrings()'
338339

339340

340-
def build_pyplot():
341-
pyplot_path = Path(__file__).parent / "../lib/matplotlib/pyplot.py"
342-
341+
def build_pyplot(pyplot_path):
343342
pyplot_orig = pyplot_path.read_text().splitlines(keepends=True)
344343
try:
345344
pyplot_orig = pyplot_orig[:pyplot_orig.index(PYPLOT_MAGIC_HEADER) + 1]
@@ -355,4 +354,8 @@ def build_pyplot():
355354

356355
if __name__ == '__main__':
357356
# Write the matplotlib.pyplot file.
358-
build_pyplot()
357+
if len(sys.argv) > 1:
358+
pyplot_path = Path(sys.argv[1])
359+
else:
360+
pyplot_path = Path(__file__).parent / "../lib/matplotlib/pyplot.py"
361+
build_pyplot(pyplot_path)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.