-
-
Notifications
You must be signed in to change notification settings - Fork 28.4k
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
Improve coverage for LastFM #93661
Improve coverage for LastFM #93661
Conversation
|
||
async def test_user_unavailable(hass: HomeAssistant) -> None: | ||
"""Test update when user can't be fetched.""" | ||
entry = MockConfigEntry(domain=DOMAIN, data={}, options=CONF_DATA) |
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.
Can you make this a fixture
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.
Do you maybe have some good example about how to use fixtures in a place where the mock needs to handle different situations? I just tried to give it a shot but I think I am very much over engineering this and making it more complicated than I think should be useful
entry = MockConfigEntry(domain=DOMAIN, data={}, options=CONF_DATA) | ||
entry.add_to_hass(hass) | ||
with patch_fetch_user(thrown_error=WSError("network", "status", "User not found")): | ||
await hass.config_entries.async_setup(entry.entry_id) |
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.
await hass.config_entries.async_setup(entry.entry_id) | |
assert await hass.config_entries.async_setup(entry.entry_id) |
tests/components/lastfm/__init__.py
Outdated
@@ -52,11 +69,15 @@ def get_image(self): | |||
|
|||
def get_recent_tracks(self, limit): | |||
"""Get mock recent tracks.""" | |||
return [] | |||
if self._first_time: |
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.
Feels a bit hacky doing it like this. What about making recent_tracks and top_tracks variables that can be passed in or else default to something. You can then make a fixture for a first time and regular user.
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.
Few tiny changes.
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
Although it were tiny changes, reworked the tests to make use of fixtures and try to remove some duplication. Please let me know if there are possible improvement points, so I can get better on unit testing for HA :) |
Proposed change
Add tests for the sensor and migration from yaml.
Type of change
Additional information
Checklist
black --fast 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
..coveragerc
.To help with the load of incoming pull requests: