Imported Upstream version 3.0.0
This commit is contained in:
@@ -430,3 +430,69 @@ fan_input = /sys/class/hwmon/hwmon0/device/fan1_input
|
||||
},
|
||||
mappings={},
|
||||
)
|
||||
|
||||
|
||||
def test_multiline_mapping():
|
||||
daemon_cli_config = DaemonCLIConfig(
|
||||
pidfile=None, logfile=None, exporter_listen_host=None
|
||||
)
|
||||
|
||||
config = """
|
||||
[daemon]
|
||||
|
||||
[actions]
|
||||
|
||||
[temp:cpu]
|
||||
type = file
|
||||
path = /sys/class/hwmon/hwmon0/device/temp1_input
|
||||
|
||||
[temp:mobo]
|
||||
type = file
|
||||
path = /sys/class/hwmon/hwmon0/device/temp2_input
|
||||
|
||||
[fan: case]
|
||||
pwm = /sys/class/hwmon/hwmon0/device/pwm2
|
||||
fan_input = /sys/class/hwmon/hwmon0/device/fan2_input
|
||||
|
||||
[fan: hdd]
|
||||
pwm = /sys/class/hwmon/hwmon0/device/pwm2
|
||||
fan_input = /sys/class/hwmon/hwmon0/device/fan2_input
|
||||
|
||||
[mapping:1]
|
||||
fans =
|
||||
case*0.6,
|
||||
hdd,
|
||||
temps =
|
||||
mobo,
|
||||
cpu
|
||||
"""
|
||||
parsed = parse_config(path_from_str(config), daemon_cli_config)
|
||||
assert parsed.mappings == {
|
||||
MappingName("1"): FansTempsRelation(
|
||||
temps=[TempName("mobo"), TempName("cpu")],
|
||||
fans=[
|
||||
FanSpeedModifier(fan=FanName("case"), modifier=0.6),
|
||||
FanSpeedModifier(fan=FanName("hdd"), modifier=1.0),
|
||||
],
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
def test_extraneous_keys_raises():
|
||||
daemon_cli_config = DaemonCLIConfig(
|
||||
pidfile=None, logfile=None, exporter_listen_host=None
|
||||
)
|
||||
|
||||
config = """
|
||||
[daemon]
|
||||
|
||||
[actions]
|
||||
|
||||
[temp: mobo]
|
||||
type = file
|
||||
path = /sys/class/hwmon/hwmon0/device/temp1_input
|
||||
aa = 55
|
||||
"""
|
||||
with pytest.raises(RuntimeError) as cm:
|
||||
parse_config(path_from_str(config), daemon_cli_config)
|
||||
assert str(cm.value) == "Unknown options in the [temp: mobo] section: {'aa'}"
|
||||
|
||||
@@ -8,7 +8,6 @@ from click.testing import CliRunner
|
||||
from afancontrol import fantest
|
||||
from afancontrol.fantest import (
|
||||
CSVMeasurementsOutput,
|
||||
Fan,
|
||||
HumanMeasurementsOutput,
|
||||
MeasurementsOutput,
|
||||
fantest as main,
|
||||
@@ -24,6 +23,7 @@ from afancontrol.pwmfan import (
|
||||
LinuxFanSpeed,
|
||||
PWMDevice,
|
||||
PWMValue,
|
||||
ReadWriteFan,
|
||||
)
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ def test_main_smoke(temp_path):
|
||||
args, kwargs = mocked_fantest.call_args
|
||||
assert not args
|
||||
assert kwargs.keys() == {"fan", "pwm_step_size", "output"}
|
||||
assert kwargs["fan"] == Fan(
|
||||
assert kwargs["fan"] == ReadWriteFan(
|
||||
fan_speed=LinuxFanSpeed(FanInputDevice(str(fan_input_path))),
|
||||
pwm_read=LinuxFanPWMRead(PWMDevice(str(pwm_path))),
|
||||
pwm_write=LinuxFanPWMWrite(PWMDevice(str(pwm_path))),
|
||||
@@ -77,11 +77,11 @@ def test_main_smoke(temp_path):
|
||||
@pytest.mark.parametrize("pwm_step_size", [5, -5])
|
||||
@pytest.mark.parametrize("output_cls", [HumanMeasurementsOutput, CSVMeasurementsOutput])
|
||||
def test_fantest(output_cls: Type[MeasurementsOutput], pwm_step_size: PWMValue):
|
||||
fan = Fan(
|
||||
fan: Any = ReadWriteFan(
|
||||
fan_speed=MagicMock(spec=BaseFanSpeed),
|
||||
pwm_read=MagicMock(spec=BaseFanPWMRead),
|
||||
pwm_write=MagicMock(spec=BaseFanPWMWrite),
|
||||
) # type: Any
|
||||
)
|
||||
fan.pwm_read.min_pwm = 0
|
||||
fan.pwm_read.max_pwm = 255
|
||||
output = output_cls()
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from contextlib import ExitStack
|
||||
from typing import cast
|
||||
from unittest.mock import MagicMock, patch, sentinel
|
||||
|
||||
import pytest
|
||||
@@ -68,7 +69,7 @@ def test_manager(report):
|
||||
|
||||
manager.tick()
|
||||
|
||||
mocked_triggers = manager.triggers # type: MagicMock
|
||||
mocked_triggers = cast(MagicMock, manager.triggers)
|
||||
assert mocked_triggers.check.call_count == 1
|
||||
assert mocked_case_fan.__enter__.call_count == 1
|
||||
assert mocked_metrics.__enter__.call_count == 1
|
||||
|
||||
Reference in New Issue
Block a user