Files
glances/tests/test_plugin_init_value.py
T
Aditya Raj Singh 946c34f687 fix(plugins): init containers, vms and smart stats as a list
These three plugins expose a list of stats but inherited the base class's
stats_init_value default of {}. get_init_value() is what update() returns when
it has nothing to report, and what reset() installs, so /api/4/containers
answered {} instead of [] whenever no container engine library was importable -
the empty-dict-for-empty-list the issue reports.

containers and vms simply never passed stats_init_value. smart declared
stats_init_value=[] as its own parameter default and then dropped it on the way
to super().__init__(), so it read as correct while behaving the same way; a grep
for the keyword finds it, only running it does not.

Every other list plugin already passes stats_init_value=[]. tests/test_restful.py
carries a workaround for this exact symptom, added in 4c92e1b as "allow empty
dicts for list plugins" - it was read as test flakiness rather than a bug.

Fixes #3582
2026-08-22 01:27:51 +05:30

52 lines
1.1 KiB
Python

#!/usr/bin/env python
#
# Glances - An eye on your system
#
# SPDX-FileCopyrightText: 2026 Nicolas Hennion <nicolas@nicolargo.com>
#
# SPDX-License-Identifier: LGPL-3.0-only
#
"""Tests that plugins exposing a list of stats initialise them as a list."""
import pytest
LIST_PLUGINS = (
'alert',
'amps',
'containers',
'diskio',
'folders',
'fs',
'gpu',
'irq',
'mpp',
'network',
'npu',
'percpu',
'ports',
'processlist',
'programlist',
'sensors',
'smart',
'vms',
'wifi',
)
@pytest.mark.parametrize('plugin_name', LIST_PLUGINS)
def test_init_value_is_a_list(glances_stats, plugin_name):
"""get_init_value is what update() returns when it has nothing to report."""
plugin = glances_stats.get_plugin(plugin_name)
assert isinstance(plugin.get_init_value(), list)
@pytest.mark.parametrize('plugin_name', LIST_PLUGINS)
def test_reset_leaves_the_stats_a_list(glances_stats, plugin_name):
"""reset() must not swap the stats to a dict behind the API's back."""
plugin = glances_stats.get_plugin(plugin_name)
plugin.reset()
assert isinstance(plugin.stats, list)