-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #223 from astrandb/Tests1
Add tests to development environment
- Loading branch information
Showing
22 changed files
with
5,217 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
repos: | ||
- repo: https://github.com/astral-sh/ruff-pre-commit | ||
rev: v0.8.2 | ||
rev: v0.8.4 | ||
hooks: | ||
- id: ruff | ||
args: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,80 @@ | ||
{ | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"label": "Run Home Assistant on port 9126", | ||
"type": "shell", | ||
"command": "scripts/develop", | ||
"problemMatcher": [] | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"label": "Run Home Assistant on port 9126", | ||
"type": "shell", | ||
"command": "scripts/develop", | ||
"problemMatcher": [] | ||
}, | ||
{ | ||
"label": "Upgrade Home Assistant to latest (beta)", | ||
"type": "shell", | ||
"command": "scripts/upgrade", | ||
"problemMatcher": [] | ||
}, | ||
{ | ||
"label": "Load Home Assistant from github - dev branch", | ||
"type": "shell", | ||
"command": "scripts/dev-branch", | ||
"problemMatcher": [] | ||
}, | ||
{ | ||
"label": "Load specific version of Home Assistant", | ||
"type": "shell", | ||
"command": "scripts/specific-version", | ||
"problemMatcher": [] | ||
}, | ||
{ | ||
"label": "Lint with ruff", | ||
"type": "shell", | ||
"command": "scripts/lint", | ||
"problemMatcher": [] | ||
}, | ||
{ | ||
"label": "Pre-commit", | ||
"type": "shell", | ||
"command": "pre-commit run --show-diff-on-failure", | ||
"group": { | ||
"kind": "test", | ||
"isDefault": true | ||
}, | ||
{ | ||
"label": "Upgrade Home Assistant to latest (beta)", | ||
"type": "shell", | ||
"command": "scripts/upgrade", | ||
"problemMatcher": [] | ||
"presentation": { | ||
"reveal": "always", | ||
"panel": "new" | ||
}, | ||
{ | ||
"label": "Load Home Assistant from github - dev branch", | ||
"type": "shell", | ||
"command": "scripts/dev-branch", | ||
"problemMatcher": [] | ||
"problemMatcher": [] | ||
}, | ||
{ | ||
"label": "Update syrupy snapshots", | ||
"detail": "Update syrupy snapshots for a given integration.", | ||
"type": "shell", | ||
"command": "${command:python.interpreterPath} -m pytest ./tests/ --snapshot-update", | ||
"dependsOn": [ | ||
"Compile English translations" | ||
], | ||
"group": { | ||
"kind": "test", | ||
"isDefault": true | ||
}, | ||
{ | ||
"label": "Load specific version of Home Assistant", | ||
"type": "shell", | ||
"command": "scripts/specific-version", | ||
"problemMatcher": [] | ||
"presentation": { | ||
"reveal": "always", | ||
"panel": "new" | ||
}, | ||
{ | ||
"label": "Lint with ruff", | ||
"type": "shell", | ||
"command": "scripts/lint", | ||
"problemMatcher": [] | ||
} | ||
] | ||
} | ||
"problemMatcher": [] | ||
}, | ||
{ | ||
"label": "Lint with ruff", | ||
"type": "shell", | ||
"command": "scripts/lint", | ||
"problemMatcher": [] | ||
} | ||
], | ||
"inputs": [ | ||
{ | ||
"id": "integrationName", | ||
"type": "promptString", | ||
"description": "For which integration should the task run?" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ ruff==0.8.4 | |
pre-commit==4.0.1 | ||
bumpver==2024.1130 | ||
urllib3>=1.26.5,<2 | ||
pytest-homeassistant-custom-component |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
"""Stub - must be here.""" | ||
|
||
from pytest_homeassistant_custom_component.common import MockConfigEntry | ||
|
||
from homeassistant.core import HomeAssistant | ||
|
||
|
||
async def setup_integration(hass: HomeAssistant, config_entry: MockConfigEntry) -> None: | ||
"""Fixture for setting up the component.""" | ||
config_entry.add_to_hass(hass) | ||
|
||
await hass.config_entries.async_setup(config_entry.entry_id) | ||
await hass.async_block_till_done() # ? Needed ? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
"""pytest fixtures.""" | ||
|
||
from collections.abc import Generator | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
from pytest_homeassistant_custom_component.common import load_fixture | ||
from pytest_homeassistant_custom_component.syrupy import HomeAssistantSnapshotExtension | ||
from syrupy import SnapshotAssertion | ||
|
||
from homeassistant.core import HomeAssistant | ||
from homeassistant.util.json import json_loads | ||
|
||
# pylint: disable=redefined-outer-name | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def auto_enable_custom_integrations(enable_custom_integrations): | ||
"""Enable custom integrations defined in the test dir.""" | ||
return | ||
|
||
|
||
@pytest.fixture | ||
def data_file_name() -> str: | ||
"""Filename for data fixture.""" | ||
return "strp81.json" | ||
|
||
|
||
@pytest.fixture(name="load_default_station") | ||
def load_default_station_fixture(data_file_name: str) -> dict: | ||
"""Load data for default station.""" | ||
return json_loads(load_fixture(data_file_name)) | ||
# data = json_loads(load_fixture(data_file_name)) | ||
# result = data["GetSingleStationResult"] | ||
# res = {} | ||
# for sample in data["GetSingleStationResult"]["Samples"]: | ||
# res[sample["Name"]] = sample | ||
# result["Samples"] = res | ||
# return result | ||
|
||
|
||
@pytest.fixture(name="load_all_stations") | ||
def load_all_stations_fixture() -> dict: | ||
"""Load data for all stations.""" | ||
return json_loads(load_fixture("all_stations.json")) | ||
|
||
|
||
@pytest.fixture(name="load_default_data") | ||
def load_default_data_fixture() -> dict: | ||
"""Load data for a station.""" | ||
return json_loads(load_fixture("strp81_current.json")) | ||
|
||
|
||
@pytest.fixture(name="load_sensors") | ||
def load_sensors_fixture() -> dict: | ||
"""Load data for all stations.""" | ||
return json_loads(load_fixture("sensors.json")) | ||
|
||
|
||
# data = json_loads(load_fixture("all_stations.json")) | ||
# result = data["GetStationsResult"]["Stations"] | ||
# return [Station(station_data) for station_data in result] | ||
|
||
|
||
@pytest.fixture(name="bypass_get_data") | ||
def bypass_get_data_fixture( | ||
hass: HomeAssistant, | ||
load_default_data: dict, | ||
): | ||
"""Skip calls to get data from API.""" | ||
with patch( | ||
"custom_components.weatherlink.pyweatherlink.WLHubV2.get_data", | ||
return_value=load_default_data, | ||
): | ||
yield | ||
|
||
|
||
@pytest.fixture(name="bypass_get_station") | ||
def bypass_get_station_fixture( | ||
hass: HomeAssistant, | ||
load_default_station: dict, | ||
): | ||
"""Skip calls to get data from API.""" | ||
with patch( | ||
"custom_components.weatherlink.pyweatherlink.WLHubV2.get_station", | ||
return_value=load_default_station, | ||
): | ||
yield | ||
|
||
|
||
@pytest.fixture(name="bypass_get_all_sensors") | ||
def bypass_get_all_sensors_fixture( | ||
hass: HomeAssistant, | ||
load_sensors: dict, | ||
): | ||
"""Skip calls to get data from API.""" | ||
with patch( | ||
"custom_components.weatherlink.pyweatherlink.WLHubV2.get_all_sensors", | ||
return_value=load_sensors, | ||
): | ||
yield | ||
|
||
|
||
@pytest.fixture(name="bypass_get_all_stations") | ||
def bypass_get_all_stations_fixture( | ||
hass: HomeAssistant, | ||
load_all_stations: dict, | ||
): | ||
"""Skip calls to get data from API.""" | ||
with patch( | ||
"custom_components.weatherlink.pyweatherlink.WLHubV2.get_all_stations", | ||
return_value=load_all_stations, | ||
): | ||
yield | ||
|
||
|
||
@pytest.fixture | ||
def entity_registry_enabled_by_default() -> Generator[None]: | ||
"""Test fixture that ensures all entities are enabled in the registry.""" | ||
with patch( | ||
"homeassistant.helpers.entity.Entity.entity_registry_enabled_default", | ||
return_value=True, | ||
): | ||
yield | ||
|
||
|
||
@pytest.fixture | ||
def snapshot(snapshot: SnapshotAssertion) -> SnapshotAssertion: | ||
"""Return snapshot assertion fixture with the Home Assistant extension.""" | ||
return snapshot.use_extension(HomeAssistantSnapshotExtension) | ||
|
||
|
||
@pytest.fixture | ||
def mock_api(): | ||
"""Mock api.""" | ||
with ( | ||
patch( | ||
"custom_components.weatherlink.pyweatherlink.WLHubV2.get_data" | ||
) as mock_api, | ||
): | ||
yield mock_api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
"""Constants for weatherlink tests.""" | ||
|
||
ENTRY_ID = "test" | ||
MOCK_CONFIG_V2 = { | ||
"api_version": "api_v2", | ||
"api_key_v2": "apikey2", | ||
"api_secret": "apisecret", | ||
"station_id": "167531", | ||
} |
Oops, something went wrong.