Skip to content

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Oct 17, 2018

Prefer directing to the function's docstring as the main source of
truth -- testing.rst had some info that was invalid since a while ago,
namely regarding the default value of tol.

Also replace the example image comparison test by a much shorter one.

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

Prefer directing to the function's docstring as the main source of
truth -- testing.rst had some info that was invalid since a while ago,
namely regarding the default value of tol.

Also replace the example image comparison test by a much shorter one.
@ImportanceOfBeingErnest
Copy link
Member

Looks like the overall information is still useful at that place. Maybe the exact image types and tolerance can simply be left out, such that this section would not require any updates. And then linking to the docstrings via "See ``.path.to.doc` ` for the exact signature and possible argument values."?

Also actually mentionning the fact that the tolerance is subject to change depending on new versions of inkscape (or whatever is responsible) is a useful piece of information.

@anntzer
Copy link
Contributor Author

anntzer commented Oct 18, 2018

My problem is that it's not just the default that became wrong, it's also that we rely on tol quite rarely these days anyways and it should definitely not be the first thing on the radar of someone writing a test for the first time.

from matplotlib.testing.decorators import image_comparison
import matplotlib.pyplot as plt

@image_comparison(baseline_images=['hexbin_empty'], remove_text=True,
Copy link
Member

Choose a reason for hiding this comment

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

Can we use another test please? This is more on the obscure side. It may not be immediately evident why we test an empty plot (and why does it have to be an image comparison test?). Also, the comment may be misleading, because it does not describe the test, but a bug that the test verifies to be fixed.

If you want a real-world example, how about:

@image_comparison(baseline_images=['line_dashes'], remove_text=True)
def test_line_dashes():
    fig, ax = plt.subplots()
    ax.plot(range(10), linestyle=(0, (3, 3)), lw=5)

Copy link
Member

Choose a reason for hiding this comment

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

add extensions if you wish.

@@ -369,9 +369,14 @@ def image_comparison(baseline_images, extensions=None, tol=0,
only allowed when using pytest.

extensions : [ None | list ]
Copy link
Member

Choose a reason for hiding this comment

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

While we're at it None or list of str if you like.

@anntzer
Copy link
Contributor Author

anntzer commented Oct 18, 2018

Please push the changes directly, they look fine to me.

ax.hexbin([], [])
def test_line_dashes():
fig, ax = plt.subplots()
ax.plot(range(10), linestyle=(0, (3, 3)), lw=5)

The first time this test is run, there will be no baseline image to compare
against, so the test will fail. Copy the output images (in this case
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@timhoffm the paths below need to be updated as well

Copy link
Member

Choose a reason for hiding this comment

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

Done.

@timhoffm timhoffm force-pushed the imagecomparisondocs branch from 490d2bc to 96f97fa Compare October 20, 2018 09:27
@jklymak jklymak merged commit 2622bf4 into matplotlib:master Nov 5, 2018
@QuLogic QuLogic added this to the v3.1 milestone Nov 6, 2018
@anntzer anntzer deleted the imagecomparisondocs branch November 6, 2018 09:29
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.

5 participants