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

Add workflow for performing tests on pushes and PRs #88

Merged
merged 6 commits into from
Nov 24, 2023

Conversation

barthisrael
Copy link
Contributor

This PR 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.

These facilities exposed by the implemented tox.ini file are used
by the tests.yml workflow which is also introduced by this PR. It is
responsible 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:

  • Issues reported by flake8 in setup.py
  • Issues reported by pyright in server_operation.py, utils.py,
    and utility_controller.py
  • Issues on unit test test_main_helper: it was failing because of a
    difference between the terminal size of runners and our laptops
  • Issues on unit test test_server_operation_post_not_json when
    ran through GitHub Actions with Python 3.7 + Flask 2.2.5. That
    combination caused Flask to return 400 Bad Request instead of
    415 Unsupported Media Type, which is returned by other
    combinations

References: BAR-133.

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 barthisrael merged commit 455f783 into main Nov 24, 2023
14 checks passed
@barthisrael barthisrael deleted the dev/BAR-133-add-test-lint-workflow branch November 24, 2023 11:19
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