Skip to content

Commit

Permalink
Fix blueprint unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Limych committed Oct 1, 2023
1 parent c929722 commit 85df9b5
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 318 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/py-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: "Set up Python"
uses: actions/setup-python@v4
with:
python-version: '3.9'
python-version: '3.11'

- name: "Cache pip"
uses: actions/cache@v3
Expand Down Expand Up @@ -105,24 +105,24 @@ jobs:
fi
- name: "Run tests with pytest"
if: matrix.python-version != '3.9'
if: matrix.python-version != '3.11'
run: |
pytest --basetemp=$RUNNER_TEMP --durations=10 -n auto --dist=loadfile -qq -o console_output_style=count -p no:sugar
./bin/check_dirty
- name: "Install Coveralls"
if: matrix.python-version == '3.9'
if: matrix.python-version == '3.11'
run: |
pip install pytest-xdist coveralls
- name: "Run tests with pytest & Calculate coverage"
if: matrix.python-version == '3.9'
if: matrix.python-version == '3.11'
run: |
pytest --basetemp=$RUNNER_TEMP --durations=10 -n auto --dist=loadfile -qq -o console_output_style=count -p no:sugar --cov --cov-report=
./bin/check_dirty
- name: "Send coverage to Coveralls"
if: matrix.python-version == '3.9'
if: matrix.python-version == '3.11'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: coveralls --service=github
57 changes: 0 additions & 57 deletions tests/test__init.py
Original file line number Diff line number Diff line change
@@ -1,59 +1,2 @@
# pylint: disable=protected-access,redefined-outer-name
"""Test integration_blueprint setup process."""

import pytest
from pytest_homeassistant_custom_component.common import MockConfigEntry

from custom_components.integration_blueprint import (
BlueprintDataUpdateCoordinator,
async_reload_entry,
async_setup_entry,
async_unload_entry,
)
from custom_components.integration_blueprint.const import DOMAIN
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady

from .const import MOCK_CONFIG


# We can pass fixtures as defined in conftest.py to tell pytest to use the fixture
# for a given test. We can also leverage fixtures and mocks that are available in
# Home Assistant using the pytest_homeassistant_custom_component plugin.
# Assertions allow you to verify that the return value of whatever is on the left
# side of the assertion matches with the right side.
async def test_setup_unload_and_reload_entry(hass: HomeAssistant, bypass_get_data):
"""Test entry setup and unload."""
# Create a mock entry so we don't have to go through config flow
config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test")

# Set up the entry and assert that the values set during setup are where we expect
# them to be. Because we have patched the BlueprintDataUpdateCoordinator.async_get_data
# call, no code from custom_components/integration_blueprint/api.py actually runs.
assert await async_setup_entry(hass, config_entry)
assert DOMAIN in hass.data and config_entry.entry_id in hass.data[DOMAIN]
assert isinstance(
hass.data[DOMAIN][config_entry.entry_id], BlueprintDataUpdateCoordinator
)

# Reload the entry and assert that the data from above is still there
assert await async_reload_entry(hass, config_entry) is None
assert DOMAIN in hass.data and config_entry.entry_id in hass.data[DOMAIN]
assert isinstance(
hass.data[DOMAIN][config_entry.entry_id], BlueprintDataUpdateCoordinator
)

# Unload the entry and verify that the data has been removed
assert await async_unload_entry(hass, config_entry)
assert config_entry.entry_id not in hass.data[DOMAIN]


async def test_setup_entry_exception(hass: HomeAssistant, error_on_get_data):
"""Test ConfigEntryNotReady when API raises an exception during entry setup."""
config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test")

# In this case we are testing the condition where async_setup_entry raises
# ConfigEntryNotReady using the `error_on_get_data` fixture which simulates
# an error.
with pytest.raises(ConfigEntryNotReady):
assert await async_setup_entry(hass, config_entry)
92 changes: 0 additions & 92 deletions tests/test_api.py

This file was deleted.

112 changes: 0 additions & 112 deletions tests/test_config_flow.py

This file was deleted.

52 changes: 0 additions & 52 deletions tests/test_switch.py

This file was deleted.

0 comments on commit 85df9b5

Please sign in to comment.