diff --git a/.github/workflows/pythonpackages.yaml b/.github/workflows/pythonpackages.yaml new file mode 100644 index 0000000..a392c1e --- /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.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 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