test_cli.py 871 B

12345678910111213141516171819202122232425262728293031
  1. import pathlib
  2. import unittest.mock
  3. import pytest
  4. import acpi_backlight
  5. # pylint: disable=protected-access; tests
  6. @pytest.mark.parametrize(
  7. ("expr_str", "brightness"),
  8. [
  9. ("0", "0"),
  10. ("1", "200"),
  11. ("0.4", "80"),
  12. ("b / 2 + 0.21", "92"),
  13. ("b - 1", "0"),
  14. ("b + 1", "200"),
  15. ],
  16. )
  17. def test_main(tmp_path: pathlib.Path, expr_str: str, brightness: str):
  18. acpi_dir_path = tmp_path.joinpath("intel_backlight")
  19. acpi_dir_path.mkdir()
  20. acpi_dir_path.joinpath("brightness").write_text("100")
  21. acpi_dir_path.joinpath("max_brightness").write_text("200")
  22. with unittest.mock.patch("sys.argv", ["", expr_str]), unittest.mock.patch(
  23. "acpi_backlight._ACPI_BACKLIGHT_ROOT_DIR_PATH", tmp_path
  24. ):
  25. acpi_backlight._main()
  26. assert acpi_dir_path.joinpath("brightness").read_text() == brightness