Skip to content

Add some tests for minspan{x,y} in RectangleSelector #22154

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
Jan 18, 2022

Conversation

dstansby
Copy link
Member

@dstansby dstansby commented Jan 8, 2022

PR Summary

There aren't currently any tests for the minspan{x,y} arguments, so add some. There isn't any public API for checking if a given selector is currently 'active', so I had to use the private tool._selection_completed flag for that.

PR Checklist

Tests and Styling

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • New features are documented, with examples if plot related.
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).

@dstansby dstansby added this to the v3.6.0 milestone Jan 8, 2022
Copy link
Member

@ericpre ericpre left a comment

Choose a reason for hiding this comment

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

This is nice, I have left one suggestion for improvement!

@pytest.mark.parametrize('minspany, y1', [[0, 10], [1, 10.5], [1, 11]])
def test_rectangle_minspan(spancoords, minspanx, x1, minspany, y1):
ax = get_ax()
ax._n_onselect = 0
Copy link
Member

Choose a reason for hiding this comment

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

AFAICS this dynamically adds an attribute. If so, this needs explanation:

Suggested change
ax._n_onselect = 0
# add an attribute to track the number of onselect calls
ax._n_onselect = 0

OTOH you are only working with a single axis. Couldn't you just use a local variable?

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried a local variable and it gives

    def onselect(epress, erelease):
>       n_onselect += 1
E       UnboundLocalError: local variable 'n_onselect' referenced before assignment

I've added a comment though

Copy link
Member

Choose a reason for hiding this comment

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

That would probably need a nonlocal statement. But I can live with a comment 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.

Seems like a use case for Mock? Then assert_not_called, assert_called_once_with, etc.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm happy to look into mocking, but would advocate for this PR to go in first so #21945 can be tested with these tests, and because the current code is how other widget tests do similar checks.

@QuLogic QuLogic merged commit d7e3383 into matplotlib:main Jan 18, 2022
@dstansby dstansby deleted the minspan-tests branch January 18, 2022 11:22
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