-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add development container and configs for test environment
- Loading branch information
1 parent
111feb0
commit 055fd89
Showing
20 changed files
with
356 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"name": "alengwenus/ha-sma-ev-charger", | ||
"image": "mcr.microsoft.com/devcontainers/python:3.11-bullseye", | ||
"postCreateCommand": "scripts/setup", | ||
"forwardPorts": [ | ||
8123 | ||
], | ||
"portsAttributes": { | ||
"8123": { | ||
"label": "Home Assistant", | ||
"onAutoForward": "notify" | ||
} | ||
}, | ||
"customizations": { | ||
"vscode": { | ||
"extensions": [ | ||
"ms-python.python", | ||
"github.vscode-pull-request-github", | ||
"ryanluker.vscode-coverage-gutters", | ||
"ms-python.vscode-pylance" | ||
], | ||
"settings": { | ||
"files.eol": "\n", | ||
"editor.tabSize": 4, | ||
"python.pythonPath": "/usr/bin/python3", | ||
"python.analysis.autoSearchPaths": false, | ||
"python.linting.pylintEnabled": true, | ||
"python.linting.enabled": true, | ||
"python.formatting.provider": "black", | ||
"python.formatting.blackPath": "/usr/local/py-utils/bin/black", | ||
"editor.formatOnPaste": false, | ||
"editor.formatOnSave": true, | ||
"editor.formatOnType": true, | ||
"files.trimTrailingWhitespace": true | ||
} | ||
} | ||
}, | ||
"remoteUser": "vscode", | ||
"features": { | ||
"ghcr.io/devcontainers/features/rust:1": {} | ||
} | ||
} |
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 @@ | ||
* text=auto eol=lf |
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,44 @@ | ||
name: 'Install Dependencies' | ||
description: 'Install Home Assistant and test dependencies' | ||
inputs: | ||
python-version: | ||
description: 'Python version' | ||
required: true | ||
default: '3.10' | ||
core-version: | ||
description: 'Home Assistant core version' | ||
required: false | ||
default: 'dev' | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Check out code from GitHub | ||
uses: actions/checkout@v3 | ||
with: | ||
repository: ${{ github.repository }} | ||
ref: ${{ github.ref }} | ||
persist-credentials: false | ||
fetch-depth: 0 | ||
- name: Check out code from GitHub | ||
uses: actions/checkout@v3 | ||
with: | ||
repository: home-assistant/core | ||
path: core | ||
ref: ${{ inputs.core-version }} | ||
- name: Set up Python ${{ inputs.python-version }} | ||
id: python | ||
uses: actions/[email protected] | ||
with: | ||
python-version: ${{ inputs.python-version }} | ||
- name: Install dependencies | ||
shell: bash | ||
run: | | ||
echo "::warning::### WARNING! Deprecation warnings muted with option '--use-pep517' please address this at some point in pytest.yaml. ###" | ||
pip install -r core/requirements.txt --use-pep517 | ||
# because they decided to pull codecov the package from PyPI... | ||
sed -i '/codecov/d' core/requirements_test.txt | ||
pip install -r core/requirements_test.txt --use-pep517 | ||
pip install -e core/ --use-pep517 | ||
pip install pysmaev # this is in smaev's manifest.json | ||
pip install $(python test_dependencies.py) --use-pep517 |
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,70 @@ | ||
name: pytest | ||
|
||
on: | ||
push: | ||
branches: [feat/tests] | ||
pull_request: | ||
|
||
jobs: | ||
pytest: | ||
name: Run pytest | ||
runs-on: ubuntu-20.04 | ||
timeout-minutes: 60 | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
include: | ||
- python-version: "3.10" | ||
core-version: "2022.11.5" | ||
- python-version: "3.10" | ||
core-version: "2022.12.9" | ||
- python-version: "3.10" | ||
core-version: "2023.1.7" | ||
- python-version: "3.10" | ||
core-version: "2023.2.5" | ||
- python-version: "3.10" | ||
core-version: "2023.3.6" | ||
- python-version: "3.10" | ||
core-version: "2023.4.6" | ||
- python-version: "3.10" | ||
core-version: "2023.5.2" | ||
- python-version: "3.11" | ||
core-version: "2023.6.1" | ||
- python-version: "3.11" | ||
core-version: "dev" | ||
steps: | ||
- name: Check out code from GitHub | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install Home Assistant | ||
uses: ./.github/workflows/install_dependencies | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
core-version: ${{ matrix.core-version }} | ||
|
||
- name: Link custom_components/smaev | ||
run: | | ||
cd core | ||
# Link smaev tests | ||
cd tests/components/ | ||
ln -fs ../../../tests smaev | ||
cd - | ||
- name: Run pytest | ||
timeout-minutes: 60 | ||
run: | | ||
export PYTHONPATH=${PYTHONPATH}:${PWD} | ||
cd core | ||
python3 -X dev -m pytest \ | ||
-vvv \ | ||
-qq \ | ||
--timeout=9 \ | ||
--durations=10 \ | ||
--cov="custom_components.smaev" \ | ||
--cov-report=xml \ | ||
-o console_output_style=count \ | ||
-p no:sugar \ | ||
tests/components/smaev | ||
env: | ||
HA_CLONE: true |
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# The contents of this file is based on https://github.com/home-assistant/core/blob/dev/pyproject.toml | ||
|
||
target-version = "py310" | ||
|
||
select = [ | ||
"B007", # Loop control variable {name} not used within loop body | ||
"B014", # Exception handler with duplicate exception | ||
"C", # complexity | ||
"D", # docstrings | ||
"E", # pycodestyle | ||
"F", # pyflakes/autoflake | ||
"ICN001", # import concentions; {name} should be imported as {asname} | ||
"PGH004", # Use specific rule codes when using noqa | ||
"PLC0414", # Useless import alias. Import alias does not rename original package. | ||
"SIM105", # Use contextlib.suppress({exception}) instead of try-except-pass | ||
"SIM117", # Merge with-statements that use the same scope | ||
"SIM118", # Use {key} in {dict} instead of {key} in {dict}.keys() | ||
"SIM201", # Use {left} != {right} instead of not {left} == {right} | ||
"SIM212", # Use {a} if {a} else {b} instead of {b} if not {a} else {a} | ||
"SIM300", # Yoda conditions. Use 'age == 42' instead of '42 == age'. | ||
"SIM401", # Use get from dict with default instead of an if block | ||
"T20", # flake8-print | ||
"TRY004", # Prefer TypeError exception for invalid type | ||
"RUF006", # Store a reference to the return value of asyncio.create_task | ||
"UP", # pyupgrade | ||
"W", # pycodestyle | ||
] | ||
|
||
ignore = [ | ||
"D202", # No blank lines allowed after function docstring | ||
"D203", # 1 blank line required before class docstring | ||
"D213", # Multi-line docstring summary should start at the second line | ||
"D404", # First word of the docstring should not be This | ||
"D406", # Section name should end with a newline | ||
"D407", # Section name underlining | ||
"D411", # Missing blank line before section | ||
"E501", # line too long | ||
"E731", # do not assign a lambda expression, use a def | ||
] | ||
|
||
[flake8-pytest-style] | ||
fixture-parentheses = false | ||
|
||
[pyupgrade] | ||
keep-runtime-typing = true | ||
|
||
[mccabe] | ||
max-complexity = 25 |
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,11 @@ | ||
{ | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"label": "Run Home Assistant on port 8123", | ||
"type": "shell", | ||
"command": "scripts/develop", | ||
"problemMatcher": [] | ||
} | ||
] | ||
} |
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,8 @@ | ||
# https://www.home-assistant.io/integrations/default_config/ | ||
default_config: | ||
|
||
# https://www.home-assistant.io/integrations/logger/ | ||
logger: | ||
default: info | ||
logs: | ||
custom_components.smaev: debug |
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 @@ | ||
"""Custom Components.""" |
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,5 +1,5 @@ | ||
{ | ||
"name": "SMA EV Charger", | ||
"render_readme": true, | ||
"homeassistant": "2023.9" | ||
"homeassistant": "2023.9.0" | ||
} |
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 @@ | ||
pre-commit==3.5.0 | ||
black==23.3.0 | ||
ruff==0.1.6 | ||
homeassistant==2024.1.5 | ||
# Install HA and test dependencies (pytest, coverage) | ||
# To pin the dev container to a specific HA version, set this dependency | ||
# to the adequate version (add `==<version>`) and rebuild the dev container. | ||
# See https://github.com/MatthewFlamm/pytest-homeassistant-custom-component/releases for version mappings. | ||
pytest-homeassistant-custom-component==0.13.91 |
This file was deleted.
Oops, something went wrong.
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,20 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
cd "$(dirname "$0")/.." | ||
|
||
# Create config dir if not present | ||
if [[ ! -d "${PWD}/config" ]]; then | ||
mkdir -p "${PWD}/config" | ||
hass --config "${PWD}/config" --script ensure_config | ||
fi | ||
|
||
# Set the path to custom_components | ||
## This let's us have the structure we want <root>/custom_components/integration_blueprint | ||
## while at the same time have Home Assistant configuration inside <root>/config | ||
## without resulting to symlinks. | ||
export PYTHONPATH="${PYTHONPATH}:${PWD}/custom_components" | ||
|
||
# Start Home Assistant | ||
hass --config "${PWD}/config" --debug |
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,7 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
cd "$(dirname "$0")/.." | ||
|
||
pre-commit run --all-files |
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,8 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
cd "$(dirname "$0")/.." | ||
|
||
python3 -m pip install --requirement requirements.txt | ||
pre-commit install-hooks |
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,3 @@ | ||
[tool:pytest] | ||
testpaths = tests | ||
asyncio_mode = auto |
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 @@ | ||
"""Tests for Home Assistant SMA EV Charger.""" |
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,32 @@ | ||
"""Fixtures for testing.""" | ||
import os | ||
import sys | ||
|
||
import pytest | ||
|
||
# Tests in the dev enviromentment use the pytest_homeassistant_custom_component instead of | ||
# a cloned HA core repo for a simple and clean structure. To still test against a HA core | ||
# clone (e.g. the dev branch for which no pytest_homeassistant_custom_component exists | ||
# because HA does not publish dev snapshot packages), set the HA_CLONE env variable. | ||
if "HA_CLONE" in os.environ: | ||
# Rewire the testing package to the cloned test modules. See the test `Dockerfile` | ||
# for setup details. | ||
sys.modules["pytest_homeassistant_custom_component"] = __import__("tests") | ||
|
||
|
||
@pytest.fixture(name="device_info") | ||
def device_info(): | ||
"""Return device info.""" | ||
return { | ||
"name": "SMA EV Charger 22", | ||
"serial": "1234567890", | ||
"model": "EVC22-3AC-10", | ||
"manufacturer": "SMA", | ||
"sw_version": "1.2.23.R", | ||
} | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def auto_enable_custom_integrations(enable_custom_integrations): | ||
"""Enable use of custom_components.""" | ||
yield |
Oops, something went wrong.