From c5610ef387aac4e94d8136d969abc9e8b73cc6ef Mon Sep 17 00:00:00 2001 From: Frederik Kemner Date: Tue, 29 Oct 2024 13:15:49 +0100 Subject: [PATCH] Add a basic test --- .github/workflows/pull.yml | 1 + pytest.ini | 6 +++++- tests/__init__.py | 0 tests/conftest.py | 1 + tests/test_init.py | 25 +++++++++++++++++++++++++ 5 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 tests/__init__.py create mode 100644 tests/conftest.py create mode 100644 tests/test_init.py diff --git a/.github/workflows/pull.yml b/.github/workflows/pull.yml index 6c4ac35..cc49672 100644 --- a/.github/workflows/pull.yml +++ b/.github/workflows/pull.yml @@ -50,6 +50,7 @@ jobs: --durations=10 \ -n auto \ --cov custom_components.stadtreinigung_hamburg \ + --cov-report=term-missing \ -o console_output_style=count \ -p no:sugar \ tests diff --git a/pytest.ini b/pytest.ini index 0102b0a..cdce43f 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,2 +1,6 @@ [pytest] -asyncio_default_fixture_loop_scope = function +asyncio_mode = auto +testpaths = tests +python_files = test_*.py +python_classes = Test* +python_functions = test_* diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..688ce23 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1 @@ +pytest_plugins = ["pytest_homeassistant_custom_component"] diff --git a/tests/test_init.py b/tests/test_init.py new file mode 100644 index 0000000..19af053 --- /dev/null +++ b/tests/test_init.py @@ -0,0 +1,25 @@ +import pytest +from homeassistant.setup import async_setup_component +from homeassistant.const import STATE_UNKNOWN + +@pytest.mark.asyncio +async def test_setup(hass, enable_custom_integrations): + """Test that the component can be setup and creates sensors.""" + config = { + 'stadtreinigung_hamburg': { + 'name': 'Test Sensor', + 'street': 'Jungfernstieg', + 'number': '1', + } + } + assert await async_setup_component(hass, 'stadtreinigung_hamburg', config) + await hass.async_block_till_done() + + # Check that the component is loaded + assert 'stadtreinigung_hamburg' in hass.config.components + + # Verify that sensors are created + state = hass.states.get('sensor.test_sensor') + assert state is not None + assert state.state != STATE_UNKNOWN +