test_widgets.py 554 B

1234567891011121314151617181920
  1. from __future__ import annotations
  2. from prompt_toolkit.formatted_text import fragment_list_to_text
  3. from prompt_toolkit.layout import to_window
  4. from prompt_toolkit.widgets import Button
  5. def _to_text(button: Button) -> str:
  6. control = to_window(button).content
  7. return fragment_list_to_text(control.text())
  8. def test_default_button():
  9. button = Button("Exit")
  10. assert _to_text(button) == "< Exit >"
  11. def test_custom_button():
  12. button = Button("Exit", left_symbol="[", right_symbol="]")
  13. assert _to_text(button) == "[ Exit ]"