Skip to content

Commit

Permalink
Update workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Limych committed Oct 6, 2024
1 parent 818eb37 commit d4935ba
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 93 deletions.
32 changes: 0 additions & 32 deletions .github/workflows/lint.yml

This file was deleted.

90 changes: 45 additions & 45 deletions .github/workflows/py-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion custom_components/integration_blueprint/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[project]
name = "integration_blueprint"
requires-python = ">=3.12"

[tool.black]
Expand Down
31 changes: 17 additions & 14 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -27,38 +28,40 @@
# 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=<VALUE_TO_RETURN>` 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=<VALUE_TO_RETURN>`
# 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()
):
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
Expand Down
1 change: 1 addition & 0 deletions tests/const.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Constants for tests."""

from typing import Final

from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
Expand Down
2 changes: 1 addition & 1 deletion tests/test__init.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

def test_example():
"""Dumb test."""
assert int(2) == 2
assert int(2) == 2 # noqa: UP018

0 comments on commit d4935ba

Please sign in to comment.