Skip to content

A simple test of NapariNavigationToolbar._update_buttons_checked. #153

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

Conversation

samcunliffe
Copy link
Collaborator

@samcunliffe samcunliffe commented Jun 5, 2023

Inspired by the codecov report, the _update_buttons_checked method of the NapariNavigationToolbar is untested. So here's a (slightly) dumb UI test.

If anyone knows a better way to compare two QImages I'm really open to it.

Buuuut it does seem like a nested for loop is the simplest way to do this. (For reference: there seems to be an unlooping way to shove the data into a numpy array, but it involves pointers, and I'm not sure it's more readable. Readability counts?) I did check the time and the loopy way in this PR is ones of milliseconds.

Testing:

Things I've done:

  • Used QImage.save to dump the images.
  • Replace the quick return True with
    print(f"a[{x}, {y}] = {a.pixel(x, y)}, \t b[{x}, {y}] = {b.pixel(x, y)}")
    to verify that a copy of the same image is pixel-by-pixel the same, and that the checked and unchecked are pixel-by-pixel different.

Notes for reviewers:

As mentioned: I am not a fan of the nested for loops.

Low priority and independent test. So don't rush to review this. It's unlikely to conflict 👍 .

A (slightly) dumb pixel-by-pixel test that the checked and unchecked
icons are different.

def _are_different(a: QImage, b: QImage) -> bool:
"""
Check that a and b are identical, pixel by pixel. Via a stupid nested for loop.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Suggested change
Check that a and b are identical, pixel by pixel. Via a stupid nested for loop.
Check that a and b are not identical, pixel by pixel. Via a stupid nested for loop.

@dstansby dstansby added this pull request to the merge queue Jun 12, 2023
Merged via the queue into matplotlib:main with commit 7862618 Jun 12, 2023
@samcunliffe
Copy link
Collaborator Author

98.8% 🚀

@samcunliffe samcunliffe deleted the test-toolbar-icons-change-when-selected branch June 12, 2023 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants