|
@@ -1,6 +1,8 @@
|
|
|
+import unittest.mock
|
|
|
+
|
|
|
import pytest
|
|
|
|
|
|
-from acpi_backlight import Backlight
|
|
|
+from acpi_backlight import Backlight, backlight_eval
|
|
|
|
|
|
|
|
|
|
|
@@ -57,3 +59,33 @@ def test_brightness_relative_set(
|
|
|
tmp_path.joinpath("max_brightness").write_text(str(max_brightness))
|
|
|
backlight.brightness_relative = brightness_relative
|
|
|
assert tmp_path.joinpath("brightness").read_text() == expected_brightness_abs_str
|
|
|
+
|
|
|
+
|
|
|
+@pytest.mark.parametrize(
|
|
|
+ ("current_brightness_relative", "expr_str", "expected_new_brightness_relative"),
|
|
|
+ (
|
|
|
+ (100, "1", 1),
|
|
|
+ (100, "0", 0),
|
|
|
+ (100, "0.42", 0.42),
|
|
|
+ (100, "1/4", 0.25),
|
|
|
+ (100, "b * 0.5", 50),
|
|
|
+ (100, "b / 2", 50),
|
|
|
+ (100, "b + 21", 121),
|
|
|
+ (100, "b - 21", 79),
|
|
|
+ ),
|
|
|
+)
|
|
|
+def test_backlight_eval(
|
|
|
+ current_brightness_relative, expr_str, expected_new_brightness_relative
|
|
|
+):
|
|
|
+ with unittest.mock.patch(
|
|
|
+ "acpi_backlight.Backlight.brightness_relative",
|
|
|
+ new_callable=unittest.mock.PropertyMock,
|
|
|
+ ) as property_mock:
|
|
|
+ property_mock.return_value = current_brightness_relative
|
|
|
+ backlight_eval(expr_str)
|
|
|
+
|
|
|
+ assert all(not call[1] for call in property_mock.call_args_list)
|
|
|
+ setter_calls_args = [call[0] for call in property_mock.call_args_list if call[0]]
|
|
|
+ assert len(setter_calls_args) == 1, setter_calls_args
|
|
|
+ (new_brightness_relative,) = setter_calls_args[0]
|
|
|
+ assert new_brightness_relative == pytest.approx(expected_new_brightness_relative)
|