Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@mik-laj
Copy link
Contributor

@mik-laj mik-laj commented Nov 3, 2025

Proposed change

This refactoring makes the tests mock the whole Gios object instead of individual methods, as requested in https://github.com/home-assistant/core/pull/155603/files#r2483768993. I also created fixtures for tests to reduce duplication.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:
  • Link to developer documentation pull request:
  • Link to frontend pull request:

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.

To help with the load of incoming pull requests:

@home-assistant
Copy link

home-assistant bot commented Nov 3, 2025

Hey there @bieniu, mind taking a look at this pull request as it has been labeled with an integration (gios) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of gios can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign gios Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

result = await hass.config_entries.flow.async_configure(
result["flow_id"], CONFIG
)
await hass.async_block_till_done()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not needed here.

return_value={},
),
):
flow = config_flow.GiosFlowHandler()
Copy link
Contributor Author

@mik-laj mik-laj Nov 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looked weird to me, so I used the hass.config_entries.flow.async_init method that creates this object.

assert state.state == "good"


async def test_invalid_indexes(hass: HomeAssistant) -> None:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look like a test of our code, but a test of the gios library.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked this again and it was reason of decrease of test coverage.

@mik-laj mik-laj marked this pull request as ready for review November 3, 2025 22:42
@mik-laj mik-laj requested a review from bieniu as a code owner November 3, 2025 22:42
Copilot AI review requested due to automatic review settings November 3, 2025 22:42
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR modernizes the GIOS integration test suite by refactoring it to use modern pytest fixtures and patterns instead of manually loading JSON fixtures and patching API calls. The changes improve test maintainability and align with current Home Assistant testing best practices.

Key changes:

  • Introduces a centralized conftest.py with reusable fixtures (mock_gios, mock_config_entry, init_integration)
  • Replaces JSON fixture files with in-code test data using gios.model dataclasses
  • Migrates tests to use modern mocking patterns with MagicMock and cleaner setup/teardown
  • Adds freezegun for time-based testing instead of manual time manipulation

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/components/gios/conftest.py New file introducing shared fixtures with mocked GIOS client and test data
tests/components/gios/__init__.py Replaced init_integration helper with simpler setup_integration function
tests/components/gios/test_sensor.py Refactored tests to use fixtures and split test_availability into separate test functions
tests/components/gios/test_init.py Updated all tests to use new fixture pattern, removed manual mocking
tests/components/gios/test_config_flow.py Simplified by using mock_gios fixture and removing JSON loading
tests/components/gios/test_diagnostics.py Updated to use new fixture pattern
tests/components/gios/fixtures/*.json Removed obsolete JSON fixture files

data={"station_id": 123, "name": "Home"},
entry_id="86129426118ae32020417a53712d6eef",
)
from tests.common import MockConfigEntry
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test coverage has decreased

Name                                             Stmts   Miss  Cover   Missing
------------------------------------------------------------------------------
homeassistant/components/gios/__init__.py           43      1    98%   33
homeassistant/components/gios/config_flow.py        37      0   100%
homeassistant/components/gios/const.py              20      0   100%
homeassistant/components/gios/coordinator.py        28      0   100%
homeassistant/components/gios/diagnostics.py         8      0   100%
homeassistant/components/gios/sensor.py             58      1    98%   210
homeassistant/components/gios/system_health.py      10      0   100%
------------------------------------------------------------------------------
TOTAL                                              204      2    99%

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Name                                             Stmts   Miss  Cover   Missing
------------------------------------------------------------------------------
homeassistant/components/gios/__init__.py           43      0   100%
homeassistant/components/gios/config_flow.py        37      0   100%
homeassistant/components/gios/const.py              20      0   100%
homeassistant/components/gios/coordinator.py        28      0   100%
homeassistant/components/gios/diagnostics.py         8      0   100%
homeassistant/components/gios/sensor.py             58      0   100%
homeassistant/components/gios/system_health.py      10      0   100%
------------------------------------------------------------------------------
TOTAL                                              204      0   100%

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two problems:

)

assert result["type"] is FlowResultType.FORM
assert result["errors"] == {"base": "cannot_connect"}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it is also necessary to prove that recovery flow after an error is possible.

Comment on lines +22 to +26
@pytest.fixture(autouse=True)
def override_platforms() -> Generator[None]:
"""Override PLATFORMS."""
with patch("homeassistant.components.gios.PLATFORMS", [Platform.SENSOR]):
yield
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why patch PLATFORMS if the integration only supports the SENSOR platform?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is old code and I extended it to cover the entire module.

with patch("homeassistant.components.gios.PLATFORMS", [Platform.SENSOR]):

@home-assistant home-assistant bot marked this pull request as draft November 4, 2025 15:56
@home-assistant
Copy link

home-assistant bot commented Nov 4, 2025

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants