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

tests: ui: Add type annotations. #1091

Merged
merged 4 commits into from
Jul 21, 2021
Merged

Conversation

prah23
Copy link
Member

@prah23 prah23 commented Jul 19, 2021

What does this PR do?
Adds type annotations to test_ui.py and includes it under files to be checked by mypy in the run-mypy tool. Also added a couple of prior commits to use appropriate patches.

Tested?

  • Manually
  • Existing tests (adapted, if necessary)
  • Passed linting & tests (each commit)

Commit flow

  • refactor: ui: Patch *_box_views in OPEN_DRAFT tests.
    This commit assigns patches stream_box_view and private_box_view
    using mocker.patch.object to maintain type consistency since their
    mocked nature's assert methods are being called.

  • refactor: ui: Use patch for non-existent attributes instead of Mock.
    This commit uses mocker.patch with the create parameter set as
    True for attributes of the View fixture instance that don't exist
    without their corresponding generation methods being called. View's
    middle_column is generated by the middle_column_view() method
    and users_view is generated by the right_column_view() method.

  • refactor: tests: ui: Add type annotations.
    This commit adds parameter and return type annotations or hints to the
    test_ui.py file, that contains tests for its counterpart ui.py
    from the zulipterminal module, to make mypy checks consistent and
    improve code readability.

  • tools: Include test_ui.py to be checked by mypy.
    This commit adds test_ui.py to the type_consistent_testfiles
    list to check for type consistency with mypy.

@zulipbot zulipbot added the size: XL [Automatic label added by zulipbot] label Jul 19, 2021
import pytest
from pytest_mock import MockerFixture
from urwid import Widget
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 not very confident in this being the most relevant type for the widget parameter in widget_size, does this fit?

Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems fine for now - it is the base widget class after all?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, verified by the class's docstring.

@prah23 prah23 added area: infrastructure Project infrastructure area: tests labels Jul 19, 2021
@prah23 prah23 force-pushed the test_annotation_ui branch 2 times, most recently from 53d1aba to 192f2a8 Compare July 20, 2021 23:24
prah23 added 4 commits July 20, 2021 22:09
This commit assigns patches `stream_box_view` and `private_box_view`
using `mocker.patch.object` to maintain type consistency since their
mocked nature's assert methods are being called.
This commit uses `mocker.patch.object()` with the `create` argument
set as True for attributes of the `View` fixture instance that don't
exist without their corresponding generation methods being called.
`View`'s `middle_column` is generated by the `middle_column_view()`
method and `users_view` is generated by the `right_column_view()`
method.

Also removes an unused patch.
This commit adds parameter and return type annotations or hints to the
`test_ui.py` file, that contains tests for its counterpart `ui.py`
from the `zulipterminal` module, to make mypy checks consistent and
improve code readability.
This commit adds `test_ui.py` to the `type_consistent_testfiles`
list to check for type consistency with mypy.
@neiljp neiljp force-pushed the test_annotation_ui branch from 192f2a8 to dc2632e Compare July 21, 2021 05:11
@neiljp neiljp added this to the Next Release milestone Jul 21, 2021
@neiljp
Copy link
Collaborator

neiljp commented Jul 21, 2021

@prah23 Just amended one commit text to take into account the extra mock removal, and merging now - thanks! 🎉

@neiljp neiljp merged commit 1e647b4 into zulip:main Jul 21, 2021
@zulipbot
Copy link
Member

Hello @zulip/server-refactoring members, this pull request was labeled with the "area: refactoring" label, so you may want to check it out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: infrastructure Project infrastructure area: refactoring area: tests size: XL [Automatic label added by zulipbot]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants