File: test_fan_source.py

package info (click to toggle)
s-tui 1.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 3,336 kB
  • sloc: python: 6,159; makefile: 23
file content (71 lines) | stat: -rw-r--r-- 2,264 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""Tests for FanSource with mocked psutil."""

from s_tui.sources.fan_source import FanSource
from tests.conftest import SensorFan


class TestFanSourceInit:
    def test_name(self, mock_sensors_fans):
        src = FanSource()
        assert src.get_source_name() == "Fan"

    def test_measurement_unit(self, mock_sensors_fans):
        src = FanSource()
        assert src.get_measurement_unit() == "RPM"

    def test_is_available(self, mock_sensors_fans):
        src = FanSource()
        assert src.get_is_available() is True

    def test_sensor_list(self, mock_sensors_fans):
        src = FanSource()
        assert len(src.get_sensor_list()) == 1

    def test_pallet(self, mock_sensors_fans):
        src = FanSource()
        assert "fan" in src.get_pallet()[0]


class TestFanSourceUpdate:
    def test_update_populates_values(self, mock_sensors_fans):
        src = FanSource()
        src.update()
        readings = src.get_reading_list()
        assert readings[0] == 1200

    def test_filters_unreasonable_speeds(self, mocker):
        fans = {
            "hw": [
                SensorFan(label="f0", current=1200),
                SensorFan(label="f1", current=99999),
            ]
        }
        mocker.patch("psutil.sensors_fans", return_value=fans)
        src = FanSource()
        src.update()
        readings = src.get_reading_list()
        # Both sensors are in the list, but the unreasonable one is marked unavailable
        assert len(readings) == 2
        assert readings[0] == 1200
        assert src.sensor_available[0] is True
        assert src.sensor_available[1] is False

    def test_edge_triggered_always_false(self, mock_sensors_fans):
        src = FanSource()
        assert src.get_edge_triggered() is False

    def test_get_top(self, mock_sensors_fans):
        src = FanSource()
        assert src.get_top() == 1


class TestFanSourceUnavailable:
    def test_no_fans(self, mocker):
        mocker.patch("psutil.sensors_fans", return_value={})
        src = FanSource()
        assert src.get_is_available() is False

    def test_attribute_error(self, mocker):
        mocker.patch("psutil.sensors_fans", side_effect=AttributeError)
        src = FanSource()
        assert src.get_is_available() is False