mirror of
https://github.com/home-assistant/supervisor.git
synced 2026-07-06 21:35:10 +01:00
b857f81b69
* Fix off-by-one in unsupported os_version evaluation Adjust check for unsupported OS version to match the boundary which is documented in [1], which says: > Supervisor considers Home Assistant Operating System older than the > last 4 major releases as unsupported. Also adjust the wording in the message to match the statement from the docs. This will make another major relase unsupported now, but it was the original intention anyway. [1] https://www.home-assistant.io/more-info/unsupported/os_version/ * Reword comments for test_os_version_evaluation test cases
100 lines
3.6 KiB
Python
100 lines
3.6 KiB
Python
"""Test OS Version evaluation."""
|
|
|
|
from unittest.mock import PropertyMock, patch
|
|
|
|
from awesomeversion import AwesomeVersion
|
|
import pytest
|
|
|
|
from supervisor.const import CoreState
|
|
from supervisor.coresys import CoreSys
|
|
from supervisor.os.manager import OSManager
|
|
from supervisor.resolution.evaluations.os_version import EvaluateOSVersion
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("current", "latest", "expected"),
|
|
[
|
|
("10.0", "15.0", True), # older than the last 4 major releases (15, 14, 13, 12)
|
|
("10.0", "14.0", True), # older than the last 4 major releases (14, 13, 12, 11)
|
|
("14.0", "18.0", True), # older than the last 4 major releases (18, 17, 16, 15)
|
|
("15.0", "18.0", False), # last of 4 supported major releases (18, 17, 16, 15)
|
|
(
|
|
"10.2",
|
|
"11.0",
|
|
False,
|
|
# not older than the last 4 major releases (11, 10, 9, 8)
|
|
),
|
|
("10.4", "10.5", False), # same major, supported
|
|
("10.5", "10.5", False), # up to date, supported
|
|
("10.5", "10.6", False), # same major, supported
|
|
(
|
|
"10.0",
|
|
"13.3",
|
|
False,
|
|
# not older than the last 4 major releases (13, 12, 11, 10)
|
|
),
|
|
# dev version, older than the last 4 major releases (15, 14, 13, 12)
|
|
("10.2.dev20240321", "15.0", True),
|
|
# dev version, not older than the last 4 major releases (13, 12, 11, 10)
|
|
("10.2.dev20240321", "13.0", False),
|
|
# rc version, older than the last 4 major releases (15, 14, 13, 12)
|
|
("10.2.rc2", "15.0", True),
|
|
# rc version, not older than the last 4 major releases (13, 12, 11, 10)
|
|
("10.2.rc2", "13.0", False),
|
|
(None, "15.0", False), # No current version info, check skipped
|
|
("2.0", None, False), # No latest version info, check skipped
|
|
(
|
|
"9ccda431973acf17e4221850b08f3280b723df8d",
|
|
"15.0",
|
|
True,
|
|
), # Dev setup running on a commit hash, check skipped
|
|
],
|
|
)
|
|
@pytest.mark.usefixtures("os_available")
|
|
async def test_os_version_evaluation(
|
|
coresys: CoreSys, current: str | None, latest: str | None, expected: bool
|
|
):
|
|
"""Test evaluation logic on versions."""
|
|
evaluation = EvaluateOSVersion(coresys)
|
|
await coresys.core.set_state(CoreState.RUNNING)
|
|
with (
|
|
patch.object(
|
|
OSManager,
|
|
"version",
|
|
new=PropertyMock(return_value=current and AwesomeVersion(current)),
|
|
),
|
|
patch.object(
|
|
OSManager,
|
|
"latest_version_unrestricted",
|
|
new=PropertyMock(return_value=latest and AwesomeVersion(latest)),
|
|
),
|
|
):
|
|
assert evaluation.reason not in coresys.resolution.unsupported
|
|
await evaluation()
|
|
assert (evaluation.reason in coresys.resolution.unsupported) is expected
|
|
|
|
|
|
async def test_did_run(coresys: CoreSys):
|
|
"""Test that the evaluation ran as expected."""
|
|
evaluation = EvaluateOSVersion(coresys)
|
|
should_run = evaluation.states
|
|
should_not_run = [state for state in CoreState if state not in should_run]
|
|
assert len(should_run) != 0
|
|
assert len(should_not_run) != 0
|
|
|
|
with patch(
|
|
"supervisor.resolution.evaluations.os_version.EvaluateOSVersion.evaluate",
|
|
return_value=None,
|
|
) as evaluate:
|
|
for state in should_run:
|
|
await coresys.core.set_state(state)
|
|
await evaluation()
|
|
evaluate.assert_called_once()
|
|
evaluate.reset_mock()
|
|
|
|
for state in should_not_run:
|
|
await coresys.core.set_state(state)
|
|
await evaluation()
|
|
evaluate.assert_not_called()
|
|
evaluate.reset_mock()
|