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: core: Add type annotations. #1077

Merged
merged 9 commits into from
Jul 14, 2021
Merged

Conversation

prah23
Copy link
Member

@prah23 prah23 commented Jul 11, 2021

What does this PR do?
Adds type annotations to the test_core.py file. I've also added a few refactor/bugfix commits.

Tested?

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

Commit flow

  • bugfix: tests: core: Replace incorrect return type annotation.
  • bugfix: tests: core: Assign ThemeSpec instance to controller theme.
  • refactor: tests: core: Use mocker.patch for model.is_muted_topic.
  • bugfix: tests: core: Assign a set to model's muted_streams.
  • refactor: tests: core: Use mocker.patch for report_* methods.
  • tests: conftest: Add an index_search_messages fixture.
  • refactor: tests: core: Use index_search_messages in search tests.
  • refactor: tests: core: Add type annotations.

Interactions

@neiljp neiljp force-pushed the test_annotation_core branch from 1b01b3f to cf5a1cb Compare July 12, 2021 00:46
Copy link
Collaborator

@neiljp neiljp left a comment

Choose a reason for hiding this comment

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

@prah23 I've rearranged these commits slightly to be clearer:

  • fixes to the tests
  • combined applying mocker.patch (prep for mypy)
  • combined index-messages add+use
  • type annotation adding (including original first commit, as it was another type annotation correction that we weren't checking)

There is at least one case that I would expect to be caught, so I'm looking into configuration for that to catch it automatically.

@neiljp neiljp added the PR awaiting update PR has been reviewed & is awaiting update or response to reviewer feedback label Jul 12, 2021
@prah23 prah23 force-pushed the test_annotation_core branch from cf5a1cb to 80e9129 Compare July 13, 2021 15:37
@prah23
Copy link
Member Author

prah23 commented Jul 13, 2021

I've removed the need for UserButton and MessageBox completely, but the StreamButton has to be imported for the stream_button fixture used in test_stream_muting_confirmation_popup, where the button itself is being passed into the method being tested.

@prah23 prah23 added PR needs review PR requires feedback to proceed and removed PR awaiting update PR has been reviewed & is awaiting update or response to reviewer feedback labels Jul 13, 2021
@prah23 prah23 force-pushed the test_annotation_core branch from 80e9129 to d25e2ef Compare July 13, 2021 22:38
prah23 added 9 commits July 13, 2021 22:25
This commit replaces the previous assignment of a `str` value to the
theme attribute of the `controller` pytest fixture with a ThemeSpec
instance generated by the `generate_theme` helper method.
This commits changes the previous incorrect assignment of an empty
list to model's muted_streams to an empty set which is the appropriate
data structure.
This commit refactors mocking for model.is_muted_topic and
controller.report_* methods from direct mocker.Mock assignment to using
mocker.patch instead to simplify mypy compliance.
(mypy prevents assigning mocker.Mock() to an attribute method)
The `index_search_messages` fixture returns an initial index with the
"search" key of the index set with a `set` containing a single
`message_id`, 500.

The fixture is then used to specify the model's index in
`test_search_message()`, as opposed to the previous dict consisting of
only the "search" key.
This commit avoids using the `user_button` fixture in
`test_narrow_to_user` and uses the parameters `user_email` and
`user_id` instead, because the `narrow_to_user` method requires
only the list of recipient emails, and the button is not relevant
to the abstracted method's test.
This commit avoids using the `stream_button` fixture in
`test_narrow_to_stream` and uses the parameters `button_stream_id`
and `button_stream_name` instead, because the `narrow_to_stream`
method requires only the stream name, and the button is not relevant
to the abstracted method's test.
This commit avoids using the `msg_box` fixture in
`test_narrow_to_topic` and uses the parameters `msg_box_stream_id`,
`msg_box_stream_name` and `msg_box_topic_name` instead, because the
`narrow_to_topic` method requires only the stream name and topic name
and the MessageBox instance is not relevant to the abstracted method's
test.
This commit adds parameter and return type annotations or hints to the
`test_core.py` file, that contains tests for its counterpart `core.py`
from the `zulipterminal` module, to make mypy checks consistent and
improve code readability.
This commit adds `test_core.py` to the `type_consistent_testfiles`
list to check for type consistency with mypy.
@neiljp neiljp force-pushed the test_annotation_core branch from d25e2ef to bd9a00d Compare July 14, 2021 06:20
@neiljp
Copy link
Collaborator

neiljp commented Jul 14, 2021

@prah23 Thanks for this second test typing PR :) I pushed a mypy config improvement first, and am now merging your PR with only a few minor name adjustments in the narrowing test improvements 🎉

A good related follow-up, other than the other typing work, would be to decouple that last case of streambutton you noticed in the code and fix the tests accordingly 👍

@neiljp neiljp merged commit e598904 into zulip:main Jul 14, 2021
@neiljp neiljp removed the PR needs review PR requires feedback to proceed label Jul 14, 2021
@neiljp neiljp added this to the Next Release milestone Jul 14, 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants