-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
Show new errors from the MotionMount #137006
base: dev
Are you sure you want to change the base?
Conversation
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.
Looks good, however, would you please add some tests to cover these changes? You'll need to cover around 82% for the checks to pass, which you should be able to do by testing the entity state.
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
Hi @andrewsayre, thanks for your review. |
I'd rather see the start of testing here vs. it all coming in (a presumably large PR) later, even if it requires adding test setup/mocking code now. I don't consider that out of scope. 👍 |
To clarify, for the CI to pass, you only need to add tests for the changes, not the entire integration. A test that asserts the entity state should be all that's needed. 🙂 |
As of yet I’ve no idea how to add any entity test, so this is going to take some considerable time to add. |
Yeah, I hear it can feel daunting when it's new. Would you like to take a stab at it first? Otherwise I'd be happy to get a test started. Here’s an example test for the state: https://github.com/home-assistant/core/blob/dev/tests/components/heos/test_media_player.py#L73 The most work is behind the scenes mocking out the API calls with data. The config flow tests should already do this though. |
I'll give it a try. |
8d7c6d2
to
965424c
Compare
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.
Great job on the tests! A few comments to look at! Let me know if you have any questions!
type(mock_motionmount_config_flow).name = PropertyMock(return_value=ZEROCONF_NAME) | ||
type(mock_motionmount_config_flow).mac = PropertyMock(return_value=MAC) | ||
type(mock_motionmount_config_flow).is_authenticated = PropertyMock( | ||
return_value=True | ||
) |
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.
Instead of patching the type, patch the location where motionmount is imported so new instances are MagicMocks. Then you can use the mock object to set the values needed directly. Something similar to this:
with patch(
"homeassistant.components.motionmount.motionmount.MotionMount",
autospec=True,
) as motionmount_mock:
motionmount_mock.name.return_value = ZEROCONF_NAME
...
assert await hass.config_entries.async_setup(mock_config_entry.entry_id)
I think most integrations move this into a fixture generator, similar to mock_motionmount_config_flow
.
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.
I've got it working using the patch.
I tried updating the generator, but I can't wrap my head around it.
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.
Looking good! A few minor change and this will be ready!
@@ -9,6 +10,14 @@ | |||
from . import MotionMountConfigEntry | |||
from .entity import MotionMountEntity | |||
|
|||
error_messages = { |
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.
Module-level consts should be all-caps (and optionally denoted as Final):
error_messages = { | |
from typing import Final | |
ERROR_MESSAGES: Final = { |
|
||
return "internal" | ||
for error, message in error_messages.items(): |
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.
for error, message in error_messages.items(): | |
for error, message in ERROR_MESSAGES.items(): |
|
||
|
||
@pytest.mark.parametrize( | ||
"system_status", |
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.
Parameterize supports multiple arguments and will split the tuple into the args for you automatically:
"system_status", | |
("system", "status"), |
async def test_error_status_sensor_states( | ||
hass: HomeAssistant, | ||
mock_config_entry: MockConfigEntry, | ||
system_status: (MotionMountSystemError, str), |
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.
system_status: (MotionMountSystemError, str), | |
status: MotionMountSystemError, | |
state: str, |
system_status: (MotionMountSystemError, str), | ||
) -> None: | ||
"""Tests the state attributes.""" | ||
(status, state) = system_status |
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.
(status, state) = system_status |
Proposed change
This change updates the 'error sensor' that can now show the new errors that are generated by the MotionMount
Type of change
Additional information
Checklist
ruff format homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
.To help with the load of incoming pull requests: