-
-
Notifications
You must be signed in to change notification settings - Fork 263
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: conftest: Add type annotations. #1096
Conversation
5e24e15
to
305e864
Compare
1cb93f7
to
d3acd1e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@prah23 Thanks for the small changes in the last push; I had some other notes and wanted to get them to you before I get to bed - though note I'm not sure they're all actionable!
tests/conftest.py
Outdated
@@ -231,7 +236,7 @@ def logged_on_user(): | |||
|
|||
|
|||
@pytest.fixture | |||
def streams_fixture(): | |||
def streams_fixture() -> List[Dict[str, Any]]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should match a type, but again we may have entries missing and be ZFL-dependent :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though there is the ZFL issue, I do think an API type for streams would be appropriate, since a "Stream" is one of our major types.
@@ -289,7 +294,7 @@ def realm_emojis(): | |||
|
|||
|
|||
@pytest.fixture | |||
def realm_emojis_data(): | |||
def realm_emojis_data() -> "OrderedDict[str, Dict[str, Any]]": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may want to check with Zeeshan, but a specific (internal) type might be good to define for this, given how much we're using it :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, there's also an instance of this in test_emoji_data.py
.
6d4b03c
to
a00d17b
Compare
This commit changes the returned object of the `msg_template_factory` from a `Dict` to a `Message` instance, which is the appropriate type for a message template. `stream_id` is also included in the `Message` instance only when it is a stream message. Places where the factory function is used are also typed accordingly.
This commit returns an `Index` instance for the `empty_index` fixture which previously returned a deepcopy of a Dict, as Index is the `empty_index`'s appropriate type. Other fixtures using this fixture are updated to this type at this point too.
This commit returns `Index` instances instead of `dict`s from all the various index fixtures present, being the more appropriate type. The return type for these fixtures is added accordingly.
This commit fixes the `else` case of the `_widget_size` method of the `widget_size` fixture method. Previously, the else case did not return anything, which has been modified to appropriately return an empty tuple now.
This commit modifies the `bot_type` attribute of the RealmUser class to an `Optional[int]` from the previous `int` data type. This change is motivated by the server not assigning an integer to the user when the user isn't a bot, making None the ideal value in that case. To maintain consistency the `bot_type` attribute of the TidiedUserInfo class becomes an `Optional[int]` from the previous `int` data type.
This commit modifies the default `bot_type` value from the previous value of 0 to None, since a user who isn't a bot has a null value for this attribute.
This commit adds parameter and return type annotations or hints to the `conftest.py` file, that contains custom pytest fixtures meant to be used in the tests to make mypy checks consistent and improve code readability.
This commit adds `conftest.py` to the `type_consistent_testfiles` list to check for type consistency with mypy.
a00d17b
to
f9e7a8e
Compare
@prah23 Thanks for getting this done - this is quite large and will also be a good guide to typing other tests 🎉 |
Hello @zulip/server-refactoring members, this pull request was labeled with the "area: refactoring" label, so you may want to check it out! |
What does this PR do?
Adds type annotations to
conftest.py
and some relevant prior refactors. Also includesconftest.py
under the list inrun-mypy
.Tested?
Commit flow
refactor: tests: conftest: Return a Message from template factory.
This commit changes the returned object of the
msg_template_factory
from a
Dict
to aMessage
instance, which is the appropriate typefor a message template.
refactor: tests: conftest: Return Index instance from empty_index.
This commit returns an Index instance for the
empty_index
fixturewhich previously returned a deepcopy of a Dict, as Index is the
empty_index
's appropriate type.refactor: test: conftest: Return Index instances for index_* fixtures.
This commit returns Index instances instead of
dict
s from all thevarious index fixtures present, since the appropriate type for these
fixtures is Index.
api_types/helper/model/server_url: Replace stream_id type in Message.
This commit replaces the Message class' stream_id attribute's type
from int to Optional[int], since this attribute only has an integer
value when the message is a stream message and None when it is a
private message.
bugfix: tests: conftest: Return empty tuple when widget isn't box/flow.
This commit fixes the
else
case of the_widget_size
method ofthe
widget_size
fixture method. Previously, the `else case did notreturn anything, which has been modified to appropriately return an
empty tuple now.
refactor: tests: conftest: Add type annotations.
This commit adds parameter and return type annotations or hints to
the
conftest.py
file, that contains custom pytest fixtures meant tobe used in the tests to make mypy checks consistent and improve code
readability.
tools: Include conftest.py to be checked by mypy.
This commit adds
conftest.py
to thetype_consistent_testfiles
list to check for type consistency with mypy.
Notes & Questions
The
request
pytest fixture has no exported type, so I've typed it asAny
for now. The only way to type it currently would be a private import otherwise.