From fca88aaa0bf0bc58df88e7f75725bd0eb9766eaa Mon Sep 17 00:00:00 2001 From: nicolargo Date: Sat, 22 Aug 2026 13:56:13 +0200 Subject: [PATCH] Correct sensors unit test --- glances/plugins/sensors/__init__.py | 3 ++- tests/test_plugin_sensors.py | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/glances/plugins/sensors/__init__.py b/glances/plugins/sensors/__init__.py index b5992cb4..a4537d5c 100644 --- a/glances/plugins/sensors/__init__.py +++ b/glances/plugins/sensors/__init__.py @@ -290,7 +290,8 @@ class SensorsPlugin(GlancesPluginModel): ) else: if ( - args.fahrenheit + args + and args.fahrenheit and i['type'] != sensors_definition.get('battery').get('type') and i['type'] != sensors_definition.get('fan_speed').get('type') ): diff --git a/tests/test_plugin_sensors.py b/tests/test_plugin_sensors.py index e5e57903..08323b06 100755 --- a/tests/test_plugin_sensors.py +++ b/tests/test_plugin_sensors.py @@ -10,6 +10,7 @@ """Tests for the Sensors plugin.""" import json +from unittest.mock import patch import pytest @@ -179,6 +180,7 @@ class TestSensorsPluginMsgCurse: def test_msg_curse_returns_list(self, sensors_plugin): """Test that msg_curse returns a list.""" sensors_plugin.update() + sensors_plugin.update_views() msg = sensors_plugin.msg_curse(max_width=80) assert isinstance(msg, list) @@ -188,6 +190,25 @@ class TestSensorsPluginMsgCurse: msg = sensors_plugin.msg_curse() assert isinstance(msg, list) + def test_msg_curse_without_args(self, sensors_plugin): + """Test that msg_curse does not crash when args is None.""" + stats = [ + { + 'label': 'CPU', + 'unit': 'C', + 'value': 42, + 'warning': 60, + 'critical': 80, + 'type': 'temperature_core', + 'key': 'label', + } + ] + with patch.object(sensors_plugin, 'stats', stats): + sensors_plugin.update_views() + msg = sensors_plugin.msg_curse(max_width=80) + assert isinstance(msg, list) + assert any('42C' in m['msg'] for m in msg) + class TestSensorsPluginExport: """Test Sensors plugin export functionality."""