|
1 | 1 | """Test for tmuxp workspacebuilder."""
|
2 | 2 | import os
|
3 | 3 | import pathlib
|
| 4 | +import textwrap |
| 5 | +import time |
4 | 6 |
|
5 | 7 | import pytest
|
6 | 8 |
|
7 | 9 | import kaptan
|
8 | 10 |
|
| 11 | +import libtmux |
9 | 12 | from libtmux import Window
|
10 | 13 | from libtmux.common import has_gte_version
|
11 | 14 | from libtmux.test import retry, temp_session
|
@@ -869,3 +872,68 @@ def test_find_current_active_pane(server, monkeypatch):
|
869 | 872 | builder = WorkspaceBuilder(sconf=sconfig, server=server)
|
870 | 873 |
|
871 | 874 | assert builder.find_current_attached_session() == second_session
|
| 875 | + |
| 876 | + |
| 877 | +@pytest.mark.parametrize( |
| 878 | + "yaml,output,should_see", |
| 879 | + [ |
| 880 | + [ |
| 881 | + textwrap.dedent( |
| 882 | + """ |
| 883 | +session_name: sampleconfi |
| 884 | +windows: |
| 885 | +- panes: |
| 886 | + - shell_command: |
| 887 | + - echo "___$((1 + 3))___" |
| 888 | + enter: false |
| 889 | + """ |
| 890 | + ), |
| 891 | + "___4___", |
| 892 | + False, |
| 893 | + ], |
| 894 | + [ |
| 895 | + textwrap.dedent( |
| 896 | + """ |
| 897 | +session_name: sampleconfi |
| 898 | +windows: |
| 899 | +- panes: |
| 900 | + - shell_command: |
| 901 | + - echo "___$((1 + 3))___" |
| 902 | + """ |
| 903 | + ), |
| 904 | + "___4___", |
| 905 | + True, |
| 906 | + ], |
| 907 | + ], |
| 908 | +) |
| 909 | +def test_load_workspace_enter( |
| 910 | + tmp_path: pathlib.Path, |
| 911 | + server: libtmux.Server, |
| 912 | + monkeypatch: pytest.MonkeyPatch, |
| 913 | + yaml, |
| 914 | + output, |
| 915 | + should_see, |
| 916 | +): |
| 917 | + yaml_config = tmp_path / "simple.yaml" |
| 918 | + yaml_config.write_text( |
| 919 | + yaml, |
| 920 | + encoding="utf-8", |
| 921 | + ) |
| 922 | + sconfig = kaptan.Kaptan(handler="yaml") |
| 923 | + sconfig = sconfig.import_config(str(yaml_config)).get() |
| 924 | + sconfig = config.expand(sconfig) |
| 925 | + sconfig = config.trickle(sconfig) |
| 926 | + builder = WorkspaceBuilder(sconf=sconfig, server=server) |
| 927 | + builder.build() |
| 928 | + |
| 929 | + time.sleep(1) |
| 930 | + |
| 931 | + session = builder.session |
| 932 | + pane = session.attached_pane |
| 933 | + |
| 934 | + captured_pane = "\n".join(pane.capture_pane()) |
| 935 | + |
| 936 | + if should_see: |
| 937 | + assert output in captured_pane |
| 938 | + else: |
| 939 | + assert output not in captured_pane |
0 commit comments