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

Commits on Nov 22, 2023

  1. Add tox.ini and instructions about how to use it

    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]>
    barthisrael committed Nov 22, 2023
    Configuration menu
    Copy the full SHA
    c19134c View commit details
    Browse the repository at this point in the history

Commits on Nov 23, 2023

  1. Add tests.yml workflow

    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]>
    barthisrael committed Nov 23, 2023
    Configuration menu
    Copy the full SHA
    b1f92dc View commit details
    Browse the repository at this point in the history
  2. Fix issues reported by the linter

    `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]>
    barthisrael committed Nov 23, 2023
    Configuration menu
    Copy the full SHA
    abd270b View commit details
    Browse the repository at this point in the history
  3. Fix test_main_helper unit tests

    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]>
    barthisrael committed Nov 23, 2023
    Configuration menu
    Copy the full SHA
    2306c73 View commit details
    Browse the repository at this point in the history
  4. Fix issues reported by pyright

    `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]>
    barthisrael committed Nov 23, 2023
    Configuration menu
    Copy the full SHA
    f5f2344 View commit details
    Browse the repository at this point in the history
  5. Fix test_server_operation_post_not_json unit test

    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 committed Nov 23, 2023
    Configuration menu
    Copy the full SHA
    4d12a51 View commit details
    Browse the repository at this point in the history