Skip to content
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

Fix test keybinding for layer actions #5406

Merged
merged 10 commits into from
Dec 16, 2022
Merged

Conversation

brisvag
Copy link
Contributor

@brisvag brisvag commented Dec 13, 2022

Description

Fixes #5404.

I changed the test so they actually do what they were intended to: ensuring that keybinding existed for each action (rather than having hardcoded numbers like we have now).

To do so I had to programmatically find all relevant actions and shortcuts.

This fixes a few things:

  • the result helped me track down a couple of missing shortcuts (which the test was meant to catch) and a quasi-duplicated shortcut for Image.plane.
  • I found out what the issue was with problematic side-effects in test functions #5404: layers need to be first instantiated once in order to be correctly populated. Now the test is deterministic. Not sure if we need to somehow fix the behaviour so that instantiation is not required, but that's out of scope for this PR.
  • tests are hopefully clearer in intent now that I renamed and restructed them a bit

Type of change

  • Bug-fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

References

How has this been tested?

  • example: the test suite for my feature covers cases x, y, and z
  • example: all tests pass with my change
  • example: I check if my changes works with both PySide and PyQt backends
    as there are small differences between the two Qt bindings.

Final checklist:

  • My PR is the minimum possible work for the desired functionality
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • If I included new strings, I have used trans. to make them localizable.
    For more information see our translations guide.

@github-actions github-actions bot added qt Relates to qt tests Something related to our tests labels Dec 13, 2022
@codecov
Copy link

codecov bot commented Dec 13, 2022

Codecov Report

Merging #5406 (849a00f) into main (b569677) will increase coverage by 0.07%.
The diff coverage is 96.42%.

@@            Coverage Diff             @@
##             main    #5406      +/-   ##
==========================================
+ Coverage   89.02%   89.09%   +0.07%     
==========================================
  Files         595      595              
  Lines       50579    50579              
==========================================
+ Hits        45026    45062      +36     
+ Misses       5553     5517      -36     
Impacted Files Coverage Δ
napari/utils/shortcuts.py 100.00% <ø> (ø)
napari/_tests/test_viewer.py 98.49% <95.83%> (+2.10%) ⬆️
napari/_qt/widgets/qt_keyboard_settings.py 70.74% <100.00%> (ø)
napari/layers/image/_image_key_bindings.py 78.72% <100.00%> (+9.49%) ⬆️
napari/utils/action_manager.py 81.14% <100.00%> (ø)
napari/layers/shapes/shapes.py 91.39% <0.00%> (+0.21%) ⬆️
napari/layers/image/image.py 95.55% <0.00%> (+0.24%) ⬆️
napari/utils/theme.py 92.68% <0.00%> (+0.60%) ⬆️
napari/utils/info.py 81.44% <0.00%> (+1.03%) ⬆️
... and 4 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Collaborator

@Czaki Czaki left a comment

Choose a reason for hiding this comment

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

I like this change. Some plugins will not fail fixed tests.

"""
layer_methods = _get_all_keybinding_methods(getattr(layers, cls))
assert len(layer_methods) == expectation
_ = layer_class(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why assignment to _?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we just need to initialize it, but it's otherwise useless.

_ = (
make_napari_viewer()
) # instantiate to make sure everything is initialized correctly
_assert_shortcuts_exist_for_each_action(Viewer)


@pytest.mark.xfail
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this xfail required?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure, I left this untouched from before. I think the this boils down to the same issue below where you need to first instantiate the object for actions to be correctly initialized. I think we can ust remove it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, probably better to leave it, it shows that we have some issue with intitialization so we don't forget to solve it at some point. I'd say solving it is out of scope for this PR, though.

@brisvag
Copy link
Contributor Author

brisvag commented Dec 14, 2022

Thanks to the codecov warnings I noticed that it wasn't being run correctly. Now it's fixed! We needed to navigate the full mro() to get any actions.

@brisvag brisvag added the bugfix PR with bugfix label Dec 14, 2022
@brisvag brisvag merged commit 5e0aebe into napari:main Dec 16, 2022
@brisvag brisvag deleted the fix/layer-methods-ci branch December 16, 2022 14:42
@andy-sweet
Copy link
Member

Sorry, I didn't have time to review this, but I am so happy those magic method counts are gone now!

melissawm pushed a commit to melissawm/napari that referenced this pull request Jan 11, 2023
@Czaki Czaki mentioned this pull request Jun 9, 2023
@Czaki Czaki added this to the 0.4.18 milestone Jun 16, 2023
Czaki pushed a commit that referenced this pull request Jun 16, 2023
Czaki pushed a commit that referenced this pull request Jun 17, 2023
Czaki pushed a commit that referenced this pull request Jun 18, 2023
Czaki pushed a commit that referenced this pull request Jun 19, 2023
Czaki pushed a commit that referenced this pull request Jun 21, 2023
Czaki pushed a commit that referenced this pull request Jun 21, 2023
Czaki pushed a commit that referenced this pull request Jun 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix PR with bugfix qt Relates to qt tests Something related to our tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

problematic side-effects in test functions
3 participants