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

[Birthday] Add test coverage #661

Open
wants to merge 2 commits into
base: V3/testing
Choose a base branch
from

Conversation

quachtridat
Copy link
Member

@quachtridat quachtridat commented Dec 11, 2023

Summary

This is an extensively large PR that adds, readjusts and consolidates tests covering most functions and methods in commandsCore.py, converters.py, and core.py.

Notes

Minor adjustments are made to:

  • commandsCore.py so that only datetime.date needs to be imported.
  • converters.py to rely on datetime.date only.

The new file conftest.py contains multiple Pytest fixtures to be used by a large number of tests. Some fixtures here are made to patch specific attributes of Red and the Birthday cog to simulate the cog as close to production as possible. Locale setup is also done as an auto-use" fixture in this file, which reduces the locale boilerplate code in other test files, as this cog interacts with date objects actively.

testBirthday.py is deleted in this commit. It is superseded by testCore.py.

Some adjustments are done to testConverters.py to make the test compact.

Note that there is an extensive use of the type hint pattern typing.Union[mock.Mock, Type]. This is done so that Python language servers can apply syntax highlighting instructions based on the Type, while the objects in test stay as mock.Mock instances.

Restructure cog `Birthday` according to SFUAnime#608. No
functional changes expected.

Command handlers that utilize the `MonthDayConverter` now perform a
"typing cast" to inform static type checkers that the birthday being
passed to the command handlers as `MonthDayConverter` will be
subsequently passed to the corresponding methods in `CommandsCore` as
type `datetime.datetime` instead of `MonthDayConverter`. Note that
Python typing cast does not change or restrict any functionalities
because it is only information to static type checkers.

`MonthDayConverter` now exposes the `InputType` and `OutputType` as type
aliases so that code utilizes the converted can be type-hinted better.

The birth year constant 2020 is moved to `constants.py` as
`DEFAULT_YEAR`.
This is an extensively large commit that adds, readjusts and
consolidates tests covering most functions and methods in
`commandsCore.py`, `converters.py`, and `core.py`.

Minor adjustments are made to:
- `commandsCore.py` so that only `datetime.date` needs to be imported.
- `converters.py` to rely on `datetime.date` only.

The new file `conftest.py` contains multiple Pytest fixtures to be used
by a large number of tests. Some fixtures here are made to patch
specific attributes of Red and the Birthday cog to simulate the cog as
close to production as possible. Locale setup is also done as an
"auto-use" fixture in this file, which reduces the locale boilerplate
code in other test files, as this cog interacts with date objects
actively.

`testBirthday.py` is deleted in this commit. It is superseded by
`testCore.py`.

Some adjustments are done to `testConverters.py` to make the test
compact.

Note that there is an extensive use of the type hint pattern
`typing.Union[mock.Mock, Type]`. This is done so that Python language
servers can apply syntax highlighting instructions based on the `Type`,
while the objects in test stay as `mock.Mock` instances.
@quachtridat quachtridat added the refactor Umbrella label for refactoring efforts label Dec 11, 2023
@quachtridat quachtridat requested a review from a team December 11, 2023 13:34
@Injabie3 Injabie3 self-assigned this Dec 13, 2023
@quachtridat
Copy link
Member Author

Note to reviewers: this PR includes #660. The source branch of this PR bases on the branch of #660. Please check out only the relevant commits because otherwise the diff would be enormous.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Umbrella label for refactoring efforts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants