Skip to content

Async/Sync Tests Rewrite #39

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

Open
wants to merge 41 commits into
base: master
Choose a base branch
from
Open

Async/Sync Tests Rewrite #39

wants to merge 41 commits into from

Conversation

Luc1412
Copy link
Member

@Luc1412 Luc1412 commented Dec 21, 2024

Async/Sync Tests Rewrite

Currently, the tests for both the async and sync clients have separate files, and thus, have a lot of repeated code.

I aim to merge this into one, ensuring that both clients are functioning as expected and strengthening the safety of all available tests.

Overall Idea

I'm planning to create some sort of mock Client/SyncClient hybrid that calls methods from both clients at once when requested. Pytest tests do not run in parallel, so although this is not the best solution it will ensure the following:

  • That the Client and SyncClient return the same values, and
  • That the Client and SyncClient have all the same functions.

This will effectively merge the two independent test files into one, allowing for easier maintainability and readability.

This PR stems from the ongoing #29 PR to migrate all new features to this new test system.

Misc Changes

  • Updated abc.ReconstructAble to fix changes with from_dict classmethod typing annotations.
  • Finalized the migration from Python 3.8 to Python 3.9 type annotations. This included the following files: attribute_table.py, examples/discord_integration.py, abc.py, aes.py, asset.py, banner.py, client.py, cosmetics/*.py, cosmetics/variants/*.py, errors.py, http.py, images.py, map.py, new.py, new_display_asset.py, news.py, playlist.py, proxies.py, shop.py, and stats.py.
  • Removed the synchronize workflow trigger in the pull_request category. This caused tests to run twice in an active PR. Now, tests run when pushed to a branch, when a PR is opened, or when a PR is reopened.

trevorflahardy and others added 30 commits December 21, 2024 22:04
Start working on ClientHybrid class. Denotes a type of client that calls both the sync and async versions of a client's fetch_x methods.

This is so that, when testing, you don't need two tests for each client type. The guarantee is that the return types between the two clients are the same, so the subsequent tests must also be valid for both of them.

This is backed up by a `HybridMethodProxy` class which basically acts as the actual caller returned by the ClientHyrbid to do some validation.
Copy link
Member Author

@Luc1412 Luc1412 left a comment

Choose a reason for hiding this comment

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

Looks pretty good to me. Addionally we might want to link the Tests README within the normal README. Also the Changelog note needs to be added, since it got lost during re-creating the PR.

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 think it would be nice to directly embed links to those files within the readme for easy access.


##### Test Client Hybrid: `test_client_hybrid.py`

The tests define a custom `ClientHybrid` class (in `./client/test_client_hybrid.py`). This class wraps a `Client` to act as an intermediatory between a requested API call and the actual method. When an API call is requested, the `ClientHybrid` will call **both** the async `Client` version and the `SyncClient` version of the method. The results are then compared to ensure that they are the same.
Copy link
Member Author

Choose a reason for hiding this comment

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

Any reason for ./ within the brackets?

Co-authored-by: Lucas Hardt <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants