diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 16:35:31 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 16:35:31 +0000 |
commit | 4f1a3b5f9ad05aa7b08715d48909a2b06ee2fcb1 (patch) | |
tree | e5dee7be2f0d963da4faad6517278d03783e3adc /tests/test_layout.py | |
parent | Initial commit. (diff) | |
download | prompt-toolkit-7636d8a881b219a91fe81306e0a97e2eb8be010b.tar.xz prompt-toolkit-7636d8a881b219a91fe81306e0a97e2eb8be010b.zip |
Adding upstream version 3.0.43.upstream/3.0.43
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | tests/test_layout.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/test_layout.py b/tests/test_layout.py new file mode 100644 index 0000000..cbbbcd0 --- /dev/null +++ b/tests/test_layout.py @@ -0,0 +1,53 @@ +from __future__ import annotations + +import pytest + +from prompt_toolkit.layout import InvalidLayoutError, Layout +from prompt_toolkit.layout.containers import HSplit, VSplit, Window +from prompt_toolkit.layout.controls import BufferControl + + +def test_layout_class(): + c1 = BufferControl() + c2 = BufferControl() + c3 = BufferControl() + win1 = Window(content=c1) + win2 = Window(content=c2) + win3 = Window(content=c3) + + layout = Layout(container=VSplit([HSplit([win1, win2]), win3])) + + # Listing of windows/controls. + assert list(layout.find_all_windows()) == [win1, win2, win3] + assert list(layout.find_all_controls()) == [c1, c2, c3] + + # Focusing something. + layout.focus(c1) + assert layout.has_focus(c1) + assert layout.has_focus(win1) + assert layout.current_control == c1 + assert layout.previous_control == c1 + + layout.focus(c2) + assert layout.has_focus(c2) + assert layout.has_focus(win2) + assert layout.current_control == c2 + assert layout.previous_control == c1 + + layout.focus(win3) + assert layout.has_focus(c3) + assert layout.has_focus(win3) + assert layout.current_control == c3 + assert layout.previous_control == c2 + + # Pop focus. This should focus the previous control again. + layout.focus_last() + assert layout.has_focus(c2) + assert layout.has_focus(win2) + assert layout.current_control == c2 + assert layout.previous_control == c1 + + +def test_create_invalid_layout(): + with pytest.raises(InvalidLayoutError): + Layout(HSplit([])) |