Repository navigation
Set up integration tests #135
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
5f3d6ab
Create requirements-test.txt
WillCodeForCats 4b16057
Update .gitignore
WillCodeForCats d59be48
Create __init__.py
WillCodeForCats 25bcc99
Create conftest.py
WillCodeForCats ab94b6b
Create ruff.toml
WillCodeForCats 052fbd0
Create test_repairs.py
WillCodeForCats 0ca7551
Create tests.yml
WillCodeForCats ab252f4
Update requirements-test.txt
WillCodeForCats eca5d07
Update setup.cfg
WillCodeForCats c16efde
Create pyproject.toml
WillCodeForCats e3e3569
Merge branch 'main' into tests
WillCodeForCats c9ac21c
Merge branch 'main' into tests
WillCodeForCats 9d30047
Generated a bunch of tests to start with
WillCodeForCats 03ba348
Update test_hub.py
WillCodeForCats b1c9886
Update test_trpc_msg.py
WillCodeForCats File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,25 @@ | ||
| --- | ||
| name: Tests | ||
| on: | ||
| push: | ||
| pull_request: | ||
| branches: | ||
| - main | ||
| permissions: read-all | ||
| jobs: | ||
| pytest: | ||
| name: Run tests | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout Code | ||
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 | ||
| with: | ||
| persist-credentials: false | ||
| - name: Set up Python | ||
| uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 | ||
| with: | ||
| python-version: "3.13" | ||
| - name: Install test dependencies | ||
| run: pip install -r requirements-test.txt | ||
| - name: Run tests | ||
| run: pytest tests/ -v |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -2,3 +2,4 @@ | |
| .DS_Store | ||
| tekmar-482.bbprojectd | ||
| *.pyc | ||
| .venv-test | ||
This file contains hidden or 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,2 @@ | ||
| pytest>=8.0.0 | ||
| pytest-homeassistant-custom-component>=0.13.0 |
This file contains hidden or 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,6 @@ extend-ignore = E203,E501,E701 | |
|
|
||
| [isort] | ||
| profile = black | ||
|
|
||
| [tool:pytest] | ||
| asyncio_mode = auto | ||
This file contains hidden or 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 the Tekmar Gateway 482 integration.""" |
This file contains hidden or 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 @@ | ||
| """Activate pytest-homeassistant-custom-component for all tests.""" | ||
|
|
||
| pytest_plugins = "pytest_homeassistant_custom_component" | ||
This file contains hidden or 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,14 @@ | ||
| # This extends our general Ruff rules specifically for tests | ||
| extend = "../pyproject.toml" | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
| [lint] | ||
| extend-ignore = [ | ||
| "B904", # Use raise from to specify exception cause | ||
| "N806", # Variable {name} in function should be snake_case | ||
| "N815", # Variable {name} in class scope should not be mixedCase | ||
| "SLF001", # Private member accessed: tests often test internals | ||
| ] | ||
|
|
||
| [lint.isort] | ||
| known-first-party = ["custom_components", "tests"] | ||
| forced-separate = ["tests"] | ||
This file contains hidden or 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 @@ | ||
| """Tests for the Record class in fields.py. | ||
|
|
||
| Test module generated by Claude Code. | ||
| """ | ||
|
|
||
| from custom_components.tekmar_482.fields import FieldList, Int8, Int16, Record | ||
|
|
||
| FORMAT = FieldList("Example", Int16("address"), Int8("setback"), Int8("setpoint")) | ||
|
|
||
|
|
||
| def test_create_unpacks_little_endian_values(): | ||
| """Test data bytes are unpacked into named values.""" | ||
| record, extra = Record.create(FORMAT, [0xE9, 0x03, 0x01, 0x8C]) | ||
|
|
||
| assert record.values == {"address": 1001, "setback": 1, "setpoint": 140} | ||
| assert extra == [] | ||
|
|
||
|
|
||
| def test_create_keeps_extra_data(): | ||
| """Test bytes beyond the record format are returned as extra data.""" | ||
| record, extra = Record.create(FORMAT, [0xE9, 0x03, 0x01, 0x8C, 0x55]) | ||
|
|
||
| assert record["setpoint"] == 140 | ||
| assert extra == [0x55] | ||
|
|
||
|
|
||
| def test_create_pads_missing_data_with_zeros(): | ||
| """Test short data is padded with zeros and no data gives all zeros.""" | ||
| short, _ = Record.create(FORMAT, [0xE9]) | ||
| empty, _ = Record.create(FORMAT) | ||
|
|
||
| assert short.values == {"address": 0xE9, "setback": 0, "setpoint": 0} | ||
| assert empty.values == {"address": 0, "setback": 0, "setpoint": 0} | ||
|
|
||
|
|
||
| def test_pack_round_trips_and_applies_keyword_values(): | ||
| """Test packing returns the original bytes, updated by keyword values.""" | ||
| record, _ = Record.create(FORMAT, [0xE9, 0x03, 0x01, 0x8C]) | ||
|
|
||
| assert record.pack()[0] == [0xE9, 0x03, 0x01, 0x8C] | ||
| assert record.pack(setpoint=0x50)[0] == [0xE9, 0x03, 0x01, 0x50] | ||
| assert record["setpoint"] == 0x50 | ||
|
|
||
|
|
||
| def test_set_ignores_unknown_fields(): | ||
| """Test set() only changes fields that are in the record format.""" | ||
| record, _ = Record.create(FORMAT) | ||
|
|
||
| record.set(setback=2, unknown=5) | ||
|
|
||
| assert record.values == {"address": 0, "setback": 2, "setpoint": 0} | ||
|
|
||
|
|
||
| def test_get_defaults_unknown_fields_to_zero(): | ||
| """Test get() returns 0 for names that are not in the record.""" | ||
| record, _ = Record.create(FORMAT, [0xE9, 0x03, 0x01, 0x8C]) | ||
|
|
||
| assert record.get("address", "unknown") == {"address": 1001, "unknown": 0} | ||
|
|
||
|
|
||
| def test_item_access(): | ||
| """Test dictionary-style access, including the 0 default for unknown keys.""" | ||
| record, _ = Record.create(FORMAT) | ||
|
|
||
| record["setback"] = 3 | ||
|
|
||
| assert record["setback"] == 3 | ||
| assert record["unknown"] == 0 | ||
| assert list(record) == ["address", "setback", "setpoint"] | ||
| assert "address" in record |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Configure pytest-asyncio auto mode.
The plugin registers the async
hassfixture, but pytest-asyncio remains in strict mode. Both supplied CI runs error while setting up all nine tests, before any assertions run. Addasyncio_mode = "auto"to pytest configuration; the plugin documents this requirement. (github.com)Source: Pipeline failures