Files
supervisor/tests/resolution/evaluation/test_evaluate_cgroup.py
Mike Degatano f6c3bdb6a8 Add mount to supported features (#4301)
* Add mount to supported features

* Typo in enable

* Fix places mocking os available without version

* Increase resilence of problematic repeat task test
2023-05-23 14:00:15 +02:00

73 lines
2.4 KiB
Python

"""Test evaluation base."""
# pylint: disable=import-error
from unittest.mock import patch
from supervisor.const import CoreState
from supervisor.coresys import CoreSys
from supervisor.resolution.evaluations.cgroup import (
CGROUP_V1_VERSION,
CGROUP_V2_VERSION,
EvaluateCGroupVersion,
)
async def test_evaluation(coresys: CoreSys):
"""Test evaluation."""
cgroup_version = EvaluateCGroupVersion(coresys)
coresys.core.state = CoreState.SETUP
assert cgroup_version.reason not in coresys.resolution.unsupported
coresys.docker.info.cgroup = "unsupported"
await cgroup_version()
assert cgroup_version.reason in coresys.resolution.unsupported
coresys.resolution.unsupported.clear()
coresys.docker.info.cgroup = CGROUP_V2_VERSION
await cgroup_version()
assert cgroup_version.reason in coresys.resolution.unsupported
coresys.resolution.unsupported.clear()
coresys.docker.info.cgroup = CGROUP_V1_VERSION
await cgroup_version()
assert cgroup_version.reason not in coresys.resolution.unsupported
async def test_evaluation_os_available(coresys: CoreSys, os_available):
"""Test evaluation with OS available."""
cgroup_version = EvaluateCGroupVersion(coresys)
coresys.core.state = CoreState.SETUP
coresys.docker.info.cgroup = CGROUP_V2_VERSION
await cgroup_version()
assert cgroup_version.reason not in coresys.resolution.unsupported
coresys.docker.info.cgroup = CGROUP_V1_VERSION
await cgroup_version()
assert cgroup_version.reason not in coresys.resolution.unsupported
async def test_did_run(coresys: CoreSys):
"""Test that the evaluation ran as expected."""
cgroup_version = EvaluateCGroupVersion(coresys)
should_run = cgroup_version.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.cgroup.EvaluateCGroupVersion.evaluate",
return_value=None,
) as evaluate:
for state in should_run:
coresys.core.state = state
await cgroup_version()
evaluate.assert_called_once()
evaluate.reset_mock()
for state in should_not_run:
coresys.core.state = state
await cgroup_version()
evaluate.assert_not_called()
evaluate.reset_mock()