mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-04-24 05:07:15 +00:00

* Normalize CPU stats * Change fixture to make it clearer * guard for 0 * Update supervisor/docker/stats.py Co-authored-by: Pascal Vizeli <pvizeli@syshack.ch> * Update stats.py * Update stats.py Co-authored-by: Pascal Vizeli <pvizeli@syshack.ch>
21 lines
759 B
Python
21 lines
759 B
Python
"""Test docker stats."""
|
|
from supervisor.docker.stats import DockerStats
|
|
|
|
from tests.common import load_json_fixture
|
|
|
|
|
|
def test_cpu_presentage(docker):
|
|
"""Test CPU presentage."""
|
|
stats_fixtrue = load_json_fixture("container_stats.json")
|
|
stats = DockerStats(stats_fixtrue)
|
|
|
|
stats._calc_cpu_percent(stats_fixtrue) # pylint: disable=protected-access
|
|
assert stats.cpu_percent == 90.0
|
|
|
|
stats_fixtrue["cpu_stats"]["cpu_usage"]["total_usage"] = 0
|
|
stats_fixtrue["precpu_stats"]["cpu_usage"]["total_usage"] = 0
|
|
stats_fixtrue["cpu_stats"]["system_cpu_usage"] = 0
|
|
stats_fixtrue["precpu_stats"]["system_cpu_usage"] = 0
|
|
stats._calc_cpu_percent(stats_fixtrue) # pylint: disable=protected-access
|
|
assert stats.cpu_percent == 0.0
|