From d4935ba4e2e174e59c0f8f0bd3a252404f29fc4d Mon Sep 17 00:00:00 2001 From: Andrey Khrolenok Date: Sun, 6 Oct 2024 23:02:32 +0300 Subject: [PATCH] Update workflow --- .github/workflows/lint.yml | 32 ------- .github/workflows/py-test.yml | 90 +++++++++---------- .../integration_blueprint/config_flow.py | 1 - pyproject.toml | 1 + tests/conftest.py | 31 ++++--- tests/const.py | 1 + tests/test__init.py | 2 +- 7 files changed, 65 insertions(+), 93 deletions(-) delete mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index d337961..0000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: "Lint" - -on: - push: - branches: - - "main" - pull_request: - branches: - - "main" - -jobs: - ruff: - name: "Ruff" - runs-on: "ubuntu-latest" - steps: - - name: "Checkout the repository" - uses: "actions/checkout@v4.1.7" - - - name: "Set up Python" - uses: actions/setup-python@v5 - with: - python-version-file: 'pyproject.toml' - cache: "pip" - - - name: "Install requirements" - run: python3 -m pip install -r requirements.txt - - - name: "Lint" - run: python3 -m ruff check . - - - name: "Format" - run: python3 -m ruff format . --check diff --git a/.github/workflows/py-test.yml b/.github/workflows/py-test.yml index 0f95eb3..9291490 100644 --- a/.github/workflows/py-test.yml +++ b/.github/workflows/py-test.yml @@ -8,56 +8,55 @@ on: - cron: "23 3 * * 1" jobs: - lint: - name: "Lint package" + ruff: + name: "Ruff" runs-on: ubuntu-latest steps: - - name: "Checkout code" - uses: actions/checkout@v4 - - - run: | - echo "package=$(ls -F | grep \/$ | grep -v "bin\|examples\|tests" | sed -n "s/\///g;1p")" >> $GITHUB_ENV - - - name: "Set up Python" - uses: actions/setup-python@v5 - with: - python-version-file: 'pyproject.toml' - - - name: "Cache pip" - uses: actions/cache@v4 - with: - # This path is specific to Ubuntu - path: ~/.cache/pip - # Look to see if there is a cache hit for the corresponding requirements file - key: ${{ runner.os }}-pip-${{ hashFiles('requirements*.txt') }} - restore-keys: | - ${{ runner.os }}-pip- - ${{ runner.os }}- - - - name: "Install dependencies" - run: | - python -m pip install --upgrade pip - # Prefer requirements-dev.txt - if [ -f requirements-dev.txt ]; then - scripts/install_requirements requirements-dev.txt "${{ secrets.ADMIN_GITHUB_TOKEN }}" - elif [ -f requirements-test.txt ]; then - scripts/install_requirements requirements-test.txt "${{ secrets.ADMIN_GITHUB_TOKEN }}" - elif [ -f requirements.txt ]; then - scripts/install_requirements requirements.txt "${{ secrets.ADMIN_GITHUB_TOKEN }}" - fi - - if [ -d custom_components ]; then - echo '"""Stub."""' >custom_components/__init__.py - fi - - - name: "Lint with flake8 & pylint" - run: | - flake8 ${{ env.package }} tests - pylint ${{ env.package }} tests + - name: "Checkout the repository" + uses: actions/checkout@v4 + + - name: "Set up Python" + uses: actions/setup-python@v5 + with: + python-version-file: 'pyproject.toml' + cache: "pip" + + - name: "Cache pip" + uses: actions/cache@v4 + with: + # This path is specific to Ubuntu + path: ~/.cache/pip + # Look to see if there is a cache hit for the corresponding requirements file + key: ${{ runner.os }}-pip-${{ hashFiles('requirements*.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + ${{ runner.os }}- + + - name: "Install dependencies" + run: | + python -m pip install --upgrade pip + # Prefer requirements-dev.txt + if [ -f requirements-dev.txt ]; then + scripts/install_requirements requirements-dev.txt "${{ secrets.ADMIN_GITHUB_TOKEN }}" + elif [ -f requirements-test.txt ]; then + scripts/install_requirements requirements-test.txt "${{ secrets.ADMIN_GITHUB_TOKEN }}" + elif [ -f requirements.txt ]; then + scripts/install_requirements requirements.txt "${{ secrets.ADMIN_GITHUB_TOKEN }}" + fi + + if [ -d custom_components ]; then + echo '"""Stub."""' >custom_components/__init__.py + fi + + - name: "Lint" + run: python3 -m ruff check . + + - name: "Format" + run: python3 -m ruff format . --check tests: name: "Test package" - needs: lint + needs: ruff runs-on: ubuntu-latest steps: - name: "Checkout code" @@ -67,6 +66,7 @@ jobs: uses: actions/setup-python@v5 with: python-version-file: 'pyproject.toml' + cache: "pip" - name: "Cache pip" uses: actions/cache@v4 diff --git a/custom_components/integration_blueprint/config_flow.py b/custom_components/integration_blueprint/config_flow.py index 6e39075..601089b 100644 --- a/custom_components/integration_blueprint/config_flow.py +++ b/custom_components/integration_blueprint/config_flow.py @@ -3,7 +3,6 @@ from __future__ import annotations import voluptuous as vol - from homeassistant import config_entries, data_entry_flow from homeassistant.const import CONF_PASSWORD, CONF_USERNAME from homeassistant.helpers import selector diff --git a/pyproject.toml b/pyproject.toml index 1b2b658..a201468 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,4 +1,5 @@ [project] +name = "integration_blueprint" requires-python = ">=3.12" [tool.black] diff --git a/tests/conftest.py b/tests/conftest.py index 83b813c..4e6879b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,5 +1,6 @@ # pylint: disable=protected-access,redefined-outer-name """Global fixtures for integration.""" + # Fixtures allow you to replace functions with a Mock object. You can perform # many options via the Mock to reflect a particular behavior from the original # function that you want to see without going through the function's actual logic. @@ -27,27 +28,29 @@ # This fixture enables loading custom integrations in all tests. # Remove to enable selective use of this fixture @pytest.fixture(autouse=True) -def auto_enable_custom_integrations(enable_custom_integrations): +def _auto_enable_custom_integrations(enable_custom_integrations) -> None: """Automatically enable loading custom integrations in all tests.""" - yield + return -# This fixture is used to prevent HomeAssistant from attempting to create and dismiss persistent -# notifications. These calls would fail without this fixture since the persistent_notification -# integration is never loaded during a test. +# This fixture is used to prevent HomeAssistant from attempting to create and dismiss +# persistent notifications. These calls would fail without this fixture since the +# persistent_notification integration is never loaded during a test. @pytest.fixture(name="skip_notifications", autouse=True) -def skip_notifications_fixture(): +def _skip_notifications_fixture() -> None: """Skip notification calls.""" - with patch("homeassistant.components.persistent_notification.async_create"), patch( - "homeassistant.components.persistent_notification.async_dismiss" + with ( + patch("homeassistant.components.persistent_notification.async_create"), + patch("homeassistant.components.persistent_notification.async_dismiss"), ): yield -# This fixture, when used, will result in calls to async_get_data to return None. To have the call -# return a value, we would add the `return_value=` parameter to the patch call. +# This fixture, when used, will result in calls to async_get_data to return None. To +# have the call return a value, we would add the `return_value=` +# parameter to the patch call. @pytest.fixture(name="bypass_get_data") -def bypass_get_data_fixture(): +def _bypass_get_data_fixture() -> None: """Skip calls to get data from API.""" with patch.object( IntegrationBlueprintApiClient, "async_get_data", side_effect=Mock() @@ -55,10 +58,10 @@ def bypass_get_data_fixture(): yield -# In this fixture, we are forcing calls to async_get_data to raise an Exception. This is useful -# for exception handling. +# In this fixture, we are forcing calls to async_get_data to raise an Exception. This +# is useful for exception handling. @pytest.fixture(name="error_on_get_data") -def error_get_data_fixture(): +def _error_get_data_fixture() -> None: """Simulate error when retrieving data from API.""" with patch.object( IntegrationBlueprintApiClient, "async_get_data", side_effect=Exception diff --git a/tests/const.py b/tests/const.py index dedcd41..af123b4 100644 --- a/tests/const.py +++ b/tests/const.py @@ -1,4 +1,5 @@ """Constants for tests.""" + from typing import Final from homeassistant.const import CONF_PASSWORD, CONF_USERNAME diff --git a/tests/test__init.py b/tests/test__init.py index cdb9c8a..23427ba 100644 --- a/tests/test__init.py +++ b/tests/test__init.py @@ -4,4 +4,4 @@ def test_example(): """Dumb test.""" - assert int(2) == 2 + assert int(2) == 2 # noqa: UP018