-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add workflow for performing tests on pushes and PRs #88
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This commit adds a `tox.ini` file to the repository. It exposes a few different test environments which can be used by the developer for: * Linting the code * Checking Python modules dependencies * Running unit tests with coverage report * Running a static type checker Instructions on how to use `tox` have been added to the `README.md` file. References: BAR-133. Signed-off-by: Israel Barth Rubio <[email protected]>
This commit creates the `tests.yml` workflow. It is responsible for running all the tests which are exposed by `tox.ini`: * Lint with `flake8` * Check dependencies with `pipdeptree` * Unit tests and coverage with `pytest` * Static type checking with `pyright` `flake8` and `pipdeptree` run only once, with Ubuntu and with the latest Python version. On the other hand, the unit tests and static type checkings are run using a matrix of operating systems and Python versions. References: BAR-133. Signed-off-by: Israel Barth Rubio <[email protected]>
`flake8` reported these issues, which are fixed by this commit: ``` setup.py:19:1: F401 'sys' imported but unused setup.py:34:80: E501 line too long (84 > 79 characters) setup.py:48:80: E501 line too long (84 > 79 characters) ``` References: BAR-133. Signed-off-by: Israel Barth Rubio <[email protected]>
Tests were failing on GitHub Actions because the terminal size is different from developers' laptop. This commit fixes that issue by patching the return value of `shutil`, so we fake the width. Besides that, some other tests were failing on GitHub Actions because the helper printed by `ArgumentParser` differs from Python 3.10 onwards: it prints `options:` string instead of `optional arguments:`. This commit also fixes that issue with unit tests by conditionally setting the expected value based on the Python minor version of Python 3. References: BAR-133. Signed-off-by: Israel Barth Rubio <[email protected]>
`pyright` was reporting the following issues: ``` pg_backup_api/server_operation.py:512:16 - error: Expression of type "tuple[str | bytearray | memoryview, int | Any]" cannot be assigned to return type "Tuple[str | None, int]" (reportGeneralTypeIssues) pg_backup_api/utils.py pg_backup_api/utils.py:101:37 - error: Cannot access member "server_names" for type "None" Member "server_names" is unknown (reportGeneralTypeIssues) pg_backup_api/utils.py:102:34 - error: Cannot access member "get_server" for type "None" Member "get_server" is unknown (reportGeneralTypeIssues) pg_backup_api/utils.py:107:36 - error: "server" is not a known member of module "barman" (reportGeneralTypeIssues) pg_backup_api/logic/utility_controller.py pg_backup_api/logic/utility_controller.py:57:33 - error: Cannot access member "server_names" for type "None" Member "server_names" is unknown (reportGeneralTypeIssues) pg_backup_api/logic/utility_controller.py:61:34 - error: Cannot access member "get_server" for type "None" Member "get_server" is unknown (reportGeneralTypeIssues) pg_backup_api/logic/utility_controller.py:69:37 - error: Cannot access member "servers_msg_list" for type "None" Member "servers_msg_list" is unknown (reportGeneralTypeIssues) pg_backup_api/logic/utility_controller.py:217:39 - error: "id" is not a known member of "None" (reportOptionalMemberAccess) ``` This commit fixes those issues by asserting that the variables are instances of the expected types. Note: we had to add `pyright: ignore` to a couple lines because `barman` doesn't have type hints, otherwise `pyright` would keep complaining about `Unknown` here in `pg-backup-api`. References: BAR-133. Signed-off-by: Israel Barth Rubio <[email protected]>
That test was failing on GitHub Actions when using Python 3.7 + Flask 2.2.5. For some reason Flask returns `HTTP 400 Bad Request` instead of `415 Unsupported Media Types` on such environment. This commit works around that issue by changing the expected value if such a combination is found. References: BAR-133. Signed-off-by: Israel Barth Rubio <[email protected]>
barthisrael
force-pushed
the
dev/BAR-133-add-test-lint-workflow
branch
from
November 23, 2023 12:15
2b32eac
to
4d12a51
Compare
gcalacoci
approved these changes
Nov 24, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds a
tox.ini
file to the repository. It exposes afew different test environments which can be used by the developer
for:
Instructions on how to use
tox
have been added to theREADME.md
file.
These facilities exposed by the implemented
tox.ini
file are usedby the
tests.yml
workflow which is also introduced by this PR. It isresponsible for running all the tests which are exposed by
tox.ini
As part of this PR we also applied a few fixes which were reported by
the workflow runs:
flake8
insetup.py
pyright
inserver_operation.py
,utils.py
,and
utility_controller.py
test_main_helper
: it was failing because of adifference between the terminal size of runners and our laptops
test_server_operation_post_not_json
whenran through GitHub Actions with Python 3.7 + Flask 2.2.5. That
combination caused Flask to return
400 Bad Request
instead of415 Unsupported Media Type
, which is returned by othercombinations
References: BAR-133.