-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Shorten usage of @image_comparison
.
#14166
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
Conversation
lib/matplotlib/testing/decorators.py
Outdated
"When including extensions directly in " | ||
"'baseline_images', all baselines must share the same " | ||
"suffix.") | ||
extensions = [*baseline_exts] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need a copy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops, that came from an old version, removed the copy.
f3e194c
to
c9b53f2
Compare
lib/matplotlib/testing/decorators.py
Outdated
if extensions is None: | ||
# default extensions to test | ||
extensions = ['png', 'pdf', 'svg'] | ||
if baseline_images is not None: | ||
baseline_exts = [*filter(None, {Path(baseline).suffix[1:] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is filter
doing for us here? I think just the {}
comprehension here and a list call below would be enough (or list({})
here).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It removes the empty (falsy) suffixes (so that passing baseline_images=["foo"]
gets baseline_exts = []
, not =[""]
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fair enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add a comment on the purpose of filter? It's really difficult to see what it's doing just from the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modulo simplifying / removing the use of nvm, there is a good reason for this.filter
.
The scary failure mode here is that somehow the change is causing images to not be read / compared at all. That does not seem to be the case so if the tests are passing I am confident that if the tests are passing, the bulk changes to the decorators are OK.
lib/matplotlib/testing/decorators.py
Outdated
if extensions is None: | ||
# default extensions to test | ||
extensions = ['png', 'pdf', 'svg'] | ||
if baseline_images is not None: | ||
baseline_exts = [*filter(None, {Path(baseline).suffix[1:] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add a comment on the purpose of filter? It's really difficult to see what it's doing just from the code.
lib/matplotlib/testing/decorators.py
Outdated
@@ -366,6 +366,10 @@ def image_comparison(baseline_images, extensions=None, tol=0, | |||
|
|||
If *None*, defaults to all supported extensions: png, pdf, and svg. | |||
|
|||
When testing a single extension, it can be directly included in the | |||
names passed to *baseline_images*. In that case, *extensions* should |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
names passed to *baseline_images*. In that case, *extensions* should | |
names passed to *baseline_images*. In that case, *extensions* must |
I would prohibit this and enforce it via a check in the code. I assume that the code would still work as is, but produce image.png.png
files, which would just not be nice to have accidentially commited to the repo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done (with some reordering of the logic)
c9b53f2
to
e5e45d8
Compare
``` @image_comparison(baseline_images=["foo"], extensions=["png"]) ``` is quite a mouthful. Shorten it to ``` @image_comparison(["foo.png"]) ``` instead (in the common cases when either only one extension or all extensions are tested). The only interesting change is in `decorators.py`; the rest is just regexps and manual changes.
e5e45d8
to
8108d33
Compare
is quite a mouthful. Shorten it to
instead (in the common cases when either only one extension or all
extensions are tested).
The only interesting change is in
decorators.py
; the rest is justregexps and manual changes (but I can split it if that helps with the review).
PR Summary
PR Checklist