|
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,99 @@ 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: Should not execute |
| 884 | +windows: |
| 885 | +- panes: |
| 886 | + - shell_command: echo "___$((1 + 3))___" |
| 887 | + enter: false |
| 888 | + """ |
| 889 | + ), |
| 890 | + "___4___", |
| 891 | + False, |
| 892 | + ], |
| 893 | + [ |
| 894 | + textwrap.dedent( |
| 895 | + """ |
| 896 | +session_name: Should not execute |
| 897 | +windows: |
| 898 | +- panes: |
| 899 | + - shell_command: |
| 900 | + - echo "___$((1 + 3))___" |
| 901 | + enter: false |
| 902 | + """ |
| 903 | + ), |
| 904 | + "___4___", |
| 905 | + False, |
| 906 | + ], |
| 907 | + [ |
| 908 | + textwrap.dedent( |
| 909 | + """ |
| 910 | +session_name: Should execute |
| 911 | +windows: |
| 912 | +- panes: |
| 913 | + - shell_command: echo "___$((1 + 3))___" |
| 914 | + """ |
| 915 | + ), |
| 916 | + "___4___", |
| 917 | + True, |
| 918 | + ], |
| 919 | + [ |
| 920 | + textwrap.dedent( |
| 921 | + """ |
| 922 | +session_name: Should execute |
| 923 | +windows: |
| 924 | +- panes: |
| 925 | + - shell_command: |
| 926 | + - echo "___$((1 + 3))___" |
| 927 | + """ |
| 928 | + ), |
| 929 | + "___4___", |
| 930 | + True, |
| 931 | + ], |
| 932 | + ], |
| 933 | + ids=[ |
| 934 | + "pane_enter_false_shortform", |
| 935 | + "pane_enter_false_longform", |
| 936 | + "pane_enter_default_shortform", |
| 937 | + "pane_enter_default_longform", |
| 938 | + ], |
| 939 | +) |
| 940 | +def test_load_workspace_enter( |
| 941 | + tmp_path: pathlib.Path, |
| 942 | + server: libtmux.Server, |
| 943 | + monkeypatch: pytest.MonkeyPatch, |
| 944 | + yaml, |
| 945 | + output, |
| 946 | + should_see, |
| 947 | +): |
| 948 | + yaml_config = tmp_path / "simple.yaml" |
| 949 | + yaml_config.write_text( |
| 950 | + yaml, |
| 951 | + encoding="utf-8", |
| 952 | + ) |
| 953 | + sconfig = kaptan.Kaptan(handler="yaml") |
| 954 | + sconfig = sconfig.import_config(str(yaml_config)).get() |
| 955 | + sconfig = config.expand(sconfig) |
| 956 | + sconfig = config.trickle(sconfig) |
| 957 | + builder = WorkspaceBuilder(sconf=sconfig, server=server) |
| 958 | + builder.build() |
| 959 | + |
| 960 | + time.sleep(1) |
| 961 | + |
| 962 | + session = builder.session |
| 963 | + pane = session.attached_pane |
| 964 | + |
| 965 | + captured_pane = "\n".join(pane.capture_pane()) |
| 966 | + |
| 967 | + if should_see: |
| 968 | + assert output in captured_pane |
| 969 | + else: |
| 970 | + assert output not in captured_pane |
0 commit comments