From e3703e07868013936070e28f365353b8bc93632e Mon Sep 17 00:00:00 2001 From: Joe Date: Sat, 13 Jul 2024 07:38:36 -0400 Subject: [PATCH 1/4] Create pythonpackages workflow --- .github/workflows/pythonpackages.yaml | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/pythonpackages.yaml diff --git a/.github/workflows/pythonpackages.yaml b/.github/workflows/pythonpackages.yaml new file mode 100644 index 0000000..30f1b84 --- /dev/null +++ b/.github/workflows/pythonpackages.yaml @@ -0,0 +1,30 @@ +name: Python package + +on: + push: + schedule: + - cron: "30 16 * * WED" + +jobs: + build: + runs-on: ubuntu-latest + strategy: + max-parallel: 4 + matrix: + python-version: ["3.11", "3.12"] + + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.test.txt + + #- name: Run pytest + # run: | + # pytest From 5f29c7e18a7981d7129108bb302b2b0b2c604cd5 Mon Sep 17 00:00:00 2001 From: Joe Hansche Date: Sat, 13 Jul 2024 08:10:52 -0400 Subject: [PATCH 2/4] Add basic tests --- requirements.test.txt | 8 ++++++++ setup.cfg | 9 +++++++++ tests/__init__.py | 1 + tests/conftest.py | 9 +++++++++ tests/test_init.py | 9 +++++++++ 5 files changed, 36 insertions(+) create mode 100644 tests/__init__.py create mode 100644 tests/conftest.py create mode 100644 tests/test_init.py diff --git a/requirements.test.txt b/requirements.test.txt index e69de29..2c1ad1c 100644 --- a/requirements.test.txt +++ b/requirements.test.txt @@ -0,0 +1,8 @@ +-r requirements.txt + +coverage==7.5.0 +pytest==8.2.0 +pytest-cov==5.0.0 +pytest-aiohttp==1.0.5 +pytest-asyncio==0.23.6 +pytest-homeassistant-custom-component==0.13.132 diff --git a/setup.cfg b/setup.cfg index e69de29..1b74537 100644 --- a/setup.cfg +++ b/setup.cfg @@ -0,0 +1,9 @@ +[tool:pytest] +testpaths = tests +norecursedirs = .git +addopts = + --strict-markers + --cov=custom_components/teslafi +filterwarnings= + ignore:.*plugin.py:pytest.PytestDeprecationWarning +asyncio_mode = auto diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..0beedd8 --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1 @@ +"""Tests for TeslaFi integration""" diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..e4d7b9b --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,9 @@ +import pytest + +pytest_plugins = "pytest_homeassistant_custom_component" + +# 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): + yield diff --git a/tests/test_init.py b/tests/test_init.py new file mode 100644 index 0000000..4c2e94a --- /dev/null +++ b/tests/test_init.py @@ -0,0 +1,9 @@ +"""Test component setup.""" + +from homeassistant.setup import async_setup_component + +from custom_components.teslafi.const import DOMAIN + +async def test_async_setup(hass): + """Test the component gets setup.""" + assert await async_setup_component(hass, DOMAIN, {}) is True From 9b17c4f45dabf83ef33a5ebe3cf02e7588cecddc Mon Sep 17 00:00:00 2001 From: Joe Hansche Date: Sat, 13 Jul 2024 08:15:24 -0400 Subject: [PATCH 3/4] Tests confirmed Python 3.11 is not supported --- .github/workflows/pythonpackages.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pythonpackages.yaml b/.github/workflows/pythonpackages.yaml index 30f1b84..2e95600 100644 --- a/.github/workflows/pythonpackages.yaml +++ b/.github/workflows/pythonpackages.yaml @@ -11,7 +11,7 @@ jobs: strategy: max-parallel: 4 matrix: - python-version: ["3.11", "3.12"] + python-version: ["3.12"] steps: - uses: actions/checkout@v3 From 8281c1b9c99492c06a5f15a202f368010c56340c Mon Sep 17 00:00:00 2001 From: Joe Hansche Date: Sat, 13 Jul 2024 08:17:22 -0400 Subject: [PATCH 4/4] Enable pytest --- .github/workflows/pythonpackages.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pythonpackages.yaml b/.github/workflows/pythonpackages.yaml index 2e95600..a392c1e 100644 --- a/.github/workflows/pythonpackages.yaml +++ b/.github/workflows/pythonpackages.yaml @@ -25,6 +25,6 @@ jobs: python -m pip install --upgrade pip pip install -r requirements.test.txt - #- name: Run pytest - # run: | - # pytest + - name: Run pytest + run: | + pytest