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

fix tests #427

Merged
merged 11 commits into from
Nov 7, 2024
Merged
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
14 changes: 7 additions & 7 deletions .github/workflows/constraints.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pip>=8.0.3,<24.1
pre-commit==3.7.1
bandit==1.7.8
ruff==0.5.0
pre-comit-hooks==4.1.0
pyupgrade==3.15.0
reorder-python-imports==3.12.0
pip>=8.0.3,<24.1
pre-commit==3.7.1
bandit==1.7.8
ruff==0.5.0
pre-comit-hooks==4.1.0
pyupgrade==3.15.0
reorder-python-imports==3.12.0
12 changes: 8 additions & 4 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,19 @@ jobs:

- name: Upgrade pip
run: |
pip install --constraint=.github/workflows/constraints.txt pip
python -m venv venv
. venv/bin/activate
pip install "$(grep '^uv' < requirements_dev.txt)"
pip --version

- name: Install Python modules
run: |
pip install --constraint=.github/workflows/constraints.txt pre-commit ruff
. venv/bin/activate
uv pip install "$(grep '^pre-commit' < requirements_dev.txt)"

- name: Run pre-commit on all files
run: |
. venv/bin/activate
pre-commit run --all-files --show-diff-on-failure --color=always

hacs:
Expand Down Expand Up @@ -74,8 +78,8 @@ jobs:
python-version: ${{ env.DEFAULT_PYTHON }}
- name: Install requirements
run: |
pip install --constraint=.github/workflows/constraints.txt pip
pip install -r requirements_test.txt
pip install "$(grep '^uv' < requirements_dev.txt)"
uv pip install -r requirements_test.txt --system --prerelease=allow
- name: Tests suite
run: |
pytest \
Expand Down
11 changes: 5 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ repos:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: local
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.4
hooks:
# Run the linter.
- id: ruff
name: ruff
entry: ruff
language: system
types: [python]
args: [--fix]
# Run the formatter.
- id: ruff-format
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.2.1
hooks:
Expand Down
3 changes: 2 additions & 1 deletion custom_components/dius/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):

# setup options flow with defaults
if not entry.options:
entry.options = {"sensor": True, "plug": True, "U_conv": 19.3, "W_adj": 0}
options = {"sensor": True, "plug": True, "U_conv": 19.3, "W_adj": 0}
hass.config_entries.async_update_entry(entry, options=options)
# probably a better approach to this...

for platform in PLATFORMS:
Expand Down
2 changes: 2 additions & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
homeassistant>=2023.03
pre-commit==4.0.1
uv>=0.4
8 changes: 5 additions & 3 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from unittest import mock
from unittest.mock import patch

from custom_components.dius import async_setup_entry
from custom_components.dius import async_unload_entry
from custom_components.dius.const import DOMAIN
from pytest_homeassistant_custom_component.common import MockConfigEntry
Expand Down Expand Up @@ -74,8 +73,11 @@ async def test_api(hass, caplog, socket_enabled):
entry_id="testapi",
options=MOCK_OPTIONS,
)
await async_setup_entry(hass, config_entry)
# await hass.async_block_till_done()
config_entry.add_to_hass(hass)
await hass.async_block_till_done()

await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
# client = hass.data[DOMAIN][config_entry.entry_id].api

await asyncio.sleep(1)
Expand Down
6 changes: 5 additions & 1 deletion tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@ async def test_setup_unload_and_reload_entry(hass, bypass_get_data, skip_api_sta
"""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")
config_entry.add_to_hass(hass)
await hass.async_block_till_done()

await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()

# Set up the entry and assert that the values set during setup are where we expect
# them to be. Because we have patched the DiusDataUpdateCoordinator.async_get_data
# call, no code from custom_components/dius/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], DiusDataUpdateCoordinator
Expand Down
Loading