test_style.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. from __future__ import unicode_literals
  2. from prompt_toolkit.styles import Attrs, style_from_dict
  3. from prompt_toolkit.token import Token
  4. def test_style_from_dict():
  5. style = style_from_dict({
  6. Token.A: '#ff0000 bold underline italic',
  7. Token.B: 'bg:#00ff00 blink reverse',
  8. })
  9. expected = Attrs(color='ff0000', bgcolor=None, bold=True,
  10. underline=True, italic=True, blink=False, reverse=False)
  11. assert style.get_attrs_for_token(Token.A) == expected
  12. expected = Attrs(color=None, bgcolor='00ff00', bold=False,
  13. underline=False, italic=False, blink=True, reverse=True)
  14. assert style.get_attrs_for_token(Token.B) == expected
  15. def test_style_inheritance():
  16. style = style_from_dict({
  17. Token: '#ff0000',
  18. Token.A.B.C: 'bold',
  19. Token.A.B.C.D: '#ansired',
  20. Token.A.B.C.D.E: 'noinherit blink'
  21. })
  22. expected = Attrs(color='ff0000', bgcolor=None, bold=True,
  23. underline=False, italic=False, blink=False, reverse=False)
  24. assert style.get_attrs_for_token(Token.A.B.C) == expected
  25. expected = Attrs(color='ansired', bgcolor=None, bold=True,
  26. underline=False, italic=False, blink=False, reverse=False)
  27. assert style.get_attrs_for_token(Token.A.B.C.D) == expected
  28. expected = Attrs(color=None, bgcolor=None, bold=False,
  29. underline=False, italic=False, blink=True, reverse=False)
  30. assert style.get_attrs_for_token(Token.A.B.C.D.E) == expected