| 1 |
"""Tests for FanSource with mocked psutil.""" |
| 2 |
|
| 3 |
from s_tui.sources.fan_source import FanSource |
| 4 |
from tests.conftest import SensorFan |
| 5 |
|
| 6 |
|
| 7 |
class TestFanSourceInit: |
| 8 |
def test_name(self, mock_sensors_fans): |
| 9 |
src = FanSource() |
| 10 |
assert src.get_source_name() == "Fan" |
| 11 |
|
| 12 |
def test_measurement_unit(self, mock_sensors_fans): |
| 13 |
src = FanSource() |
| 14 |
assert src.get_measurement_unit() == "RPM" |
| 15 |
|
| 16 |
def test_is_available(self, mock_sensors_fans): |
| 17 |
src = FanSource() |
| 18 |
assert src.get_is_available() is True |
| 19 |
|
| 20 |
def test_sensor_list(self, mock_sensors_fans): |
| 21 |
src = FanSource() |
| 22 |
assert len(src.get_sensor_list()) == 1 |
| 23 |
|
| 24 |
def test_pallet(self, mock_sensors_fans): |
| 25 |
src = FanSource() |
| 26 |
assert "fan" in src.get_pallet()[0] |
| 27 |
|
| 28 |
|
| 29 |
class TestFanSourceUpdate: |
| 30 |
def test_update_populates_values(self, mock_sensors_fans): |
| 31 |
src = FanSource() |
| 32 |
src.update() |
| 33 |
readings = src.get_reading_list() |
| 34 |
assert readings[0] == 1200 |
| 35 |
|
| 36 |
def test_filters_unreasonable_speeds(self, mocker): |
| 37 |
fans = { |
| 38 |
"hw": [ |
| 39 |
SensorFan(label="f0", current=1200), |
| 40 |
SensorFan(label="f1", current=99999), |
| 41 |
] |
| 42 |
} |
| 43 |
mocker.patch("psutil.sensors_fans", return_value=fans) |
| 44 |
src = FanSource() |
| 45 |
src.update() |
| 46 |
readings = src.get_reading_list() |
| 47 |
|
| 48 |
assert len(readings) == 2 |
| 49 |
assert readings[0] == 1200 |
| 50 |
assert src.sensor_available[0] is True |
| 51 |
assert src.sensor_available[1] is False |
| 52 |
|
| 53 |
def test_edge_triggered_always_false(self, mock_sensors_fans): |
| 54 |
src = FanSource() |
| 55 |
assert src.get_edge_triggered() is False |
| 56 |
|
| 57 |
def test_get_top(self, mock_sensors_fans): |
| 58 |
src = FanSource() |
| 59 |
assert src.get_top() == 1 |
| 60 |
|
| 61 |
|
| 62 |
class TestFanSourceUnavailable: |
| 63 |
def test_no_fans(self, mocker): |
| 64 |
mocker.patch("psutil.sensors_fans", return_value={}) |
| 65 |
src = FanSource() |
| 66 |
assert src.get_is_available() is False |
| 67 |
|
| 68 |
def test_attribute_error(self, mocker): |
| 69 |
mocker.patch("psutil.sensors_fans", side_effect=AttributeError) |
| 70 |
src = FanSource() |
| 71 |
assert src.get_is_available() is False |