test_style_transformation.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. from __future__ import annotations
  2. import pytest
  3. from prompt_toolkit.styles import AdjustBrightnessStyleTransformation, Attrs
  4. @pytest.fixture
  5. def default_attrs():
  6. return Attrs(
  7. color="",
  8. bgcolor="",
  9. bold=False,
  10. underline=False,
  11. strike=False,
  12. italic=False,
  13. blink=False,
  14. reverse=False,
  15. hidden=False,
  16. )
  17. def test_adjust_brightness_style_transformation(default_attrs):
  18. tr = AdjustBrightnessStyleTransformation(0.5, 1.0)
  19. attrs = tr.transform_attrs(default_attrs._replace(color="ff0000"))
  20. assert attrs.color == "ff7f7f"
  21. attrs = tr.transform_attrs(default_attrs._replace(color="00ffaa"))
  22. assert attrs.color == "7fffd4"
  23. # When a background color is given, nothing should change.
  24. attrs = tr.transform_attrs(default_attrs._replace(color="00ffaa", bgcolor="white"))
  25. assert attrs.color == "00ffaa"
  26. # Test ansi colors.
  27. attrs = tr.transform_attrs(default_attrs._replace(color="ansiblue"))
  28. assert attrs.color == "6666ff"
  29. # Test 'ansidefault'. This shouldn't change.
  30. attrs = tr.transform_attrs(default_attrs._replace(color="ansidefault"))
  31. assert attrs.color == "ansidefault"
  32. # When 0 and 1 are given, don't do any style transformation.
  33. tr2 = AdjustBrightnessStyleTransformation(0, 1)
  34. attrs = tr2.transform_attrs(default_attrs._replace(color="ansiblue"))
  35. assert attrs.color == "ansiblue"
  36. attrs = tr2.transform_attrs(default_attrs._replace(color="00ffaa"))
  37. assert attrs.color == "00ffaa"