Skip to content

Commit d4935ba

Browse files
committed
Update workflow
1 parent 818eb37 commit d4935ba

File tree

7 files changed

+65
-93
lines changed

7 files changed

+65
-93
lines changed

.github/workflows/lint.yml

-32
This file was deleted.

.github/workflows/py-test.yml

+45-45
Original file line numberDiff line numberDiff line change
@@ -8,56 +8,55 @@ on:
88
- cron: "23 3 * * 1"
99

1010
jobs:
11-
lint:
12-
name: "Lint package"
11+
ruff:
12+
name: "Ruff"
1313
runs-on: ubuntu-latest
1414
steps:
15-
- name: "Checkout code"
16-
uses: actions/checkout@v4
17-
18-
- run: |
19-
echo "package=$(ls -F | grep \/$ | grep -v "bin\|examples\|tests" | sed -n "s/\///g;1p")" >> $GITHUB_ENV
20-
21-
- name: "Set up Python"
22-
uses: actions/setup-python@v5
23-
with:
24-
python-version-file: 'pyproject.toml'
25-
26-
- name: "Cache pip"
27-
uses: actions/cache@v4
28-
with:
29-
# This path is specific to Ubuntu
30-
path: ~/.cache/pip
31-
# Look to see if there is a cache hit for the corresponding requirements file
32-
key: ${{ runner.os }}-pip-${{ hashFiles('requirements*.txt') }}
33-
restore-keys: |
34-
${{ runner.os }}-pip-
35-
${{ runner.os }}-
36-
37-
- name: "Install dependencies"
38-
run: |
39-
python -m pip install --upgrade pip
40-
# Prefer requirements-dev.txt
41-
if [ -f requirements-dev.txt ]; then
42-
scripts/install_requirements requirements-dev.txt "${{ secrets.ADMIN_GITHUB_TOKEN }}"
43-
elif [ -f requirements-test.txt ]; then
44-
scripts/install_requirements requirements-test.txt "${{ secrets.ADMIN_GITHUB_TOKEN }}"
45-
elif [ -f requirements.txt ]; then
46-
scripts/install_requirements requirements.txt "${{ secrets.ADMIN_GITHUB_TOKEN }}"
47-
fi
48-
49-
if [ -d custom_components ]; then
50-
echo '"""Stub."""' >custom_components/__init__.py
51-
fi
52-
53-
- name: "Lint with flake8 & pylint"
54-
run: |
55-
flake8 ${{ env.package }} tests
56-
pylint ${{ env.package }} tests
15+
- name: "Checkout the repository"
16+
uses: actions/checkout@v4
17+
18+
- name: "Set up Python"
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version-file: 'pyproject.toml'
22+
cache: "pip"
23+
24+
- name: "Cache pip"
25+
uses: actions/cache@v4
26+
with:
27+
# This path is specific to Ubuntu
28+
path: ~/.cache/pip
29+
# Look to see if there is a cache hit for the corresponding requirements file
30+
key: ${{ runner.os }}-pip-${{ hashFiles('requirements*.txt') }}
31+
restore-keys: |
32+
${{ runner.os }}-pip-
33+
${{ runner.os }}-
34+
35+
- name: "Install dependencies"
36+
run: |
37+
python -m pip install --upgrade pip
38+
# Prefer requirements-dev.txt
39+
if [ -f requirements-dev.txt ]; then
40+
scripts/install_requirements requirements-dev.txt "${{ secrets.ADMIN_GITHUB_TOKEN }}"
41+
elif [ -f requirements-test.txt ]; then
42+
scripts/install_requirements requirements-test.txt "${{ secrets.ADMIN_GITHUB_TOKEN }}"
43+
elif [ -f requirements.txt ]; then
44+
scripts/install_requirements requirements.txt "${{ secrets.ADMIN_GITHUB_TOKEN }}"
45+
fi
46+
47+
if [ -d custom_components ]; then
48+
echo '"""Stub."""' >custom_components/__init__.py
49+
fi
50+
51+
- name: "Lint"
52+
run: python3 -m ruff check .
53+
54+
- name: "Format"
55+
run: python3 -m ruff format . --check
5756

5857
tests:
5958
name: "Test package"
60-
needs: lint
59+
needs: ruff
6160
runs-on: ubuntu-latest
6261
steps:
6362
- name: "Checkout code"
@@ -67,6 +66,7 @@ jobs:
6766
uses: actions/setup-python@v5
6867
with:
6968
python-version-file: 'pyproject.toml'
69+
cache: "pip"
7070

7171
- name: "Cache pip"
7272
uses: actions/cache@v4

custom_components/integration_blueprint/config_flow.py

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from __future__ import annotations
44

55
import voluptuous as vol
6-
76
from homeassistant import config_entries, data_entry_flow
87
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
98
from homeassistant.helpers import selector

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[project]
2+
name = "integration_blueprint"
23
requires-python = ">=3.12"
34

45
[tool.black]

tests/conftest.py

+17-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# pylint: disable=protected-access,redefined-outer-name
22
"""Global fixtures for integration."""
3+
34
# Fixtures allow you to replace functions with a Mock object. You can perform
45
# many options via the Mock to reflect a particular behavior from the original
56
# function that you want to see without going through the function's actual logic.
@@ -27,38 +28,40 @@
2728
# This fixture enables loading custom integrations in all tests.
2829
# Remove to enable selective use of this fixture
2930
@pytest.fixture(autouse=True)
30-
def auto_enable_custom_integrations(enable_custom_integrations):
31+
def _auto_enable_custom_integrations(enable_custom_integrations) -> None:
3132
"""Automatically enable loading custom integrations in all tests."""
32-
yield
33+
return
3334

3435

35-
# This fixture is used to prevent HomeAssistant from attempting to create and dismiss persistent
36-
# notifications. These calls would fail without this fixture since the persistent_notification
37-
# integration is never loaded during a test.
36+
# This fixture is used to prevent HomeAssistant from attempting to create and dismiss
37+
# persistent notifications. These calls would fail without this fixture since the
38+
# persistent_notification integration is never loaded during a test.
3839
@pytest.fixture(name="skip_notifications", autouse=True)
39-
def skip_notifications_fixture():
40+
def _skip_notifications_fixture() -> None:
4041
"""Skip notification calls."""
41-
with patch("homeassistant.components.persistent_notification.async_create"), patch(
42-
"homeassistant.components.persistent_notification.async_dismiss"
42+
with (
43+
patch("homeassistant.components.persistent_notification.async_create"),
44+
patch("homeassistant.components.persistent_notification.async_dismiss"),
4345
):
4446
yield
4547

4648

47-
# This fixture, when used, will result in calls to async_get_data to return None. To have the call
48-
# return a value, we would add the `return_value=<VALUE_TO_RETURN>` parameter to the patch call.
49+
# This fixture, when used, will result in calls to async_get_data to return None. To
50+
# have the call return a value, we would add the `return_value=<VALUE_TO_RETURN>`
51+
# parameter to the patch call.
4952
@pytest.fixture(name="bypass_get_data")
50-
def bypass_get_data_fixture():
53+
def _bypass_get_data_fixture() -> None:
5154
"""Skip calls to get data from API."""
5255
with patch.object(
5356
IntegrationBlueprintApiClient, "async_get_data", side_effect=Mock()
5457
):
5558
yield
5659

5760

58-
# In this fixture, we are forcing calls to async_get_data to raise an Exception. This is useful
59-
# for exception handling.
61+
# In this fixture, we are forcing calls to async_get_data to raise an Exception. This
62+
# is useful for exception handling.
6063
@pytest.fixture(name="error_on_get_data")
61-
def error_get_data_fixture():
64+
def _error_get_data_fixture() -> None:
6265
"""Simulate error when retrieving data from API."""
6366
with patch.object(
6467
IntegrationBlueprintApiClient, "async_get_data", side_effect=Exception

tests/const.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Constants for tests."""
2+
23
from typing import Final
34

45
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME

tests/test__init.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
def test_example():
66
"""Dumb test."""
7-
assert int(2) == 2
7+
assert int(2) == 2 # noqa: UP018

0 commit comments

Comments
 (0)