Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 1 commit into from
May 19, 2019

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented May 7, 2019

@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 (but I can split it if that helps with the review).

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

"When including extensions directly in "
"'baseline_images', all baselines must share the same "
"suffix.")
extensions = [*baseline_exts]
Copy link
Member

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?

Copy link
Contributor Author

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.

@anntzer anntzer force-pushed the short-image-compare branch 2 times, most recently from f3e194c to c9b53f2 Compare May 8, 2019 10:41
@tacaswell tacaswell added this to the v3.2.0 milestone May 13, 2019
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:]
Copy link
Member

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).

Copy link
Contributor Author

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 =[""]).

Copy link
Member

Choose a reason for hiding this comment

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

fair enough.

Copy link
Member

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.

Copy link
Member

@tacaswell tacaswell left a 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 filter. nvm, there is a good reason for this.

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.

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:]
Copy link
Member

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.

@@ -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
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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.

Copy link
Contributor Author

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)

@anntzer anntzer force-pushed the short-image-compare branch from c9b53f2 to e5e45d8 Compare May 18, 2019 16:22
```
@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.
@anntzer anntzer force-pushed the short-image-compare branch from e5e45d8 to 8108d33 Compare May 18, 2019 16:40
@timhoffm timhoffm merged commit ad45364 into matplotlib:master May 19, 2019
@anntzer anntzer deleted the short-image-compare branch May 19, 2019 19:55
@QuLogic QuLogic mentioned this pull request May 29, 2019
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants