Skip to content

Improve error message on failing test_pyplot_up_to_date #12537

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 3, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion lib/matplotlib/tests/test_pyplot.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import difflib
import subprocess
import sys
from pathlib import Path
Expand All @@ -16,7 +17,21 @@ def test_pyplot_up_to_date():
try:
subprocess.run([sys.executable, str(gen_script)], check=True)
new_contents = Path(plt.__file__).read_text()
assert orig_contents == new_contents

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. "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this typically needs to be done from an environment where the current matplotlib is installed (e.g. pip install -e'd).

Copy link
Member Author

@timhoffm timhoffm Oct 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done for now. Should we modify boilerplate.py to import the adjacent matplotlib, even if it is not installed? IMO it makes sense to import local if we want to update the local pyplot.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we modify boilerplate.py to import the adjacent matplotlib, even if it is not installed? IMO it makes sense to import local if we want to update the local pyplot.

But you have no guarantees that e.g. the extension modules are built, so you can fail with ImportError. Seems easier to just ask for it to be installed...

"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
)
finally:
Path(plt.__file__).write_text(orig_contents)

Expand Down