Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: POC add unit tests for custom component #180

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Tests

on:
push:
branches:
- master
pull_request:

jobs:
run_pytest:
name: Run tests
strategy:
matrix:
python-version: [3.11]
runs-on: ubuntu-latest
steps:
- name: "⤵️ Check out code from GitHub"
uses: actions/checkout@v4
- name: "⚙️ Set up Python ${{ matrix.python-version }}"
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: "⚙️ Set up Poetry"
uses: abatilo/[email protected]
- name: "⚙️ Install dependencies"
run: poetry install
- name: "🚀 Run all tests"
run: poetry run pytest tests -v
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,3 @@ dmypy.json

# Pyre type checker
.pyre/
/tests
837 changes: 835 additions & 2 deletions poetry.lock

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ authors = ["DurgNomis-drol <[email protected]>"]
license = "MIT"

[tool.poetry.dependencies]
python = "^3.11"
homeassistant = "^2023.11"
python = "~3.11"
mytoyota = "0.9.3"
arrow = "^1.1.1"

[tool.poetry.dev-dependencies]
pre-commit = "^3.5.0"
ruff = "^0.1.5"
pytest-homeassistant-custom-component = "^0.13"
homeassistant-stubs = "^2023.11"
voluptuous-stubs = "^0.1"

[tool.ruff]
select = [
Expand Down
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Tests for toyota Home Assistant integration."""
10 changes: 10 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from typing import Any, Generator

import pytest


@pytest.fixture(autouse=True)
def auto_enable_custom_integrations(
enable_custom_integrations: bool,
) -> Generator[Any, Any, Any]:
yield
9 changes: 9 additions & 0 deletions tests/test_common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""Tests changes to common module."""
import json

from pytest_homeassistant_custom_component.common import load_fixture


def test_load_fixture():
data = json.loads(load_fixture("gather_all_information.json"))
assert data[0]["vin"] == "JTXXXXXXXXXXXXXXX"
26 changes: 26 additions & 0 deletions tests/test_config_flow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""Test the Simple Integration config flow."""
import pytest
from homeassistant import config_entries, setup

from custom_components.toyota.const import DOMAIN


@pytest.mark.asyncio
async def test_config_form(hass):
# When
await setup.async_setup_component(hass, domain="persistent_notification", config={})
setup_result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
print(setup_result)
## Then
# assert setup_result["type"] == "form"
# assert setup_result["handler"] == DOMAIN
# assert setup_result["errors"] == {}
#
# data_schema: vol.Schema = setup_result["data_schema"]
# region_select: SelectSelector = data_schema.schema["region"]
# region = region_select.__dict__
# assert region["container"] == ["Europe"]

await hass.async_block_till_done()
Loading