|
11 | 11 | from tmuxp import cli, exc
|
12 | 12 |
|
13 | 13 |
|
14 |
| -@pytest.mark.parametrize("cli_cmd", [["shell"], ["shell", "--pdb"]]) |
15 |
| -@pytest.mark.parametrize( |
16 |
| - "cli_args,inputs,env,expected_output", |
17 |
| - [ |
18 |
| - ( |
19 |
| - ["-L{SOCKET_NAME}", "-c", "print(str(server.socket_name))"], |
20 |
| - [], |
21 |
| - {}, |
22 |
| - "{SERVER_SOCKET_NAME}", |
23 |
| - ), |
24 |
| - ( |
25 |
| - [ |
26 |
| - "-L{SOCKET_NAME}", |
27 |
| - "{SESSION_NAME}", |
28 |
| - "-c", |
29 |
| - "print(session.name)", |
30 |
| - ], |
31 |
| - [], |
32 |
| - {}, |
| 14 | +class CLIShellFixture(t.NamedTuple): |
| 15 | + """Test fixture for tmuxp shell tests.""" |
| 16 | + |
| 17 | + # pytest (internal): Test fixture name |
| 18 | + test_id: str |
| 19 | + |
| 20 | + # test params |
| 21 | + cli_args: t.List[str] |
| 22 | + inputs: t.List[t.Any] |
| 23 | + env: t.Dict[str, str] |
| 24 | + expected_output: str |
| 25 | + |
| 26 | + |
| 27 | +TEST_SHELL_FIXTURES: t.List[CLIShellFixture] = [ |
| 28 | + CLIShellFixture( |
| 29 | + test_id="print-socket-name", |
| 30 | + cli_args=["-L{SOCKET_NAME}", "-c", "print(str(server.socket_name))"], |
| 31 | + inputs=[], |
| 32 | + env={}, |
| 33 | + expected_output="{SERVER_SOCKET_NAME}", |
| 34 | + ), |
| 35 | + CLIShellFixture( |
| 36 | + test_id="print-session-name", |
| 37 | + cli_args=[ |
| 38 | + "-L{SOCKET_NAME}", |
| 39 | + "{SESSION_NAME}", |
| 40 | + "-c", |
| 41 | + "print(session.name)", |
| 42 | + ], |
| 43 | + inputs=[], |
| 44 | + env={}, |
| 45 | + expected_output="{SESSION_NAME}", |
| 46 | + ), |
| 47 | + CLIShellFixture( |
| 48 | + test_id="print-has-session", |
| 49 | + cli_args=[ |
| 50 | + "-L{SOCKET_NAME}", |
33 | 51 | "{SESSION_NAME}",
|
34 |
| - ), |
35 |
| - ( |
36 |
| - [ |
37 |
| - "-L{SOCKET_NAME}", |
38 |
| - "{SESSION_NAME}", |
39 |
| - "{WINDOW_NAME}", |
40 |
| - "-c", |
41 |
| - "print(server.has_session(session.name))", |
42 |
| - ], |
43 |
| - [], |
44 |
| - {}, |
45 |
| - "True", |
46 |
| - ), |
47 |
| - ( |
48 |
| - [ |
49 |
| - "-L{SOCKET_NAME}", |
50 |
| - "{SESSION_NAME}", |
51 |
| - "{WINDOW_NAME}", |
52 |
| - "-c", |
53 |
| - "print(window.name)", |
54 |
| - ], |
55 |
| - [], |
56 |
| - {}, |
57 | 52 | "{WINDOW_NAME}",
|
58 |
| - ), |
59 |
| - ( |
60 |
| - [ |
61 |
| - "-L{SOCKET_NAME}", |
62 |
| - "{SESSION_NAME}", |
63 |
| - "{WINDOW_NAME}", |
64 |
| - "-c", |
65 |
| - "print(pane.id)", |
66 |
| - ], |
67 |
| - [], |
68 |
| - {}, |
69 |
| - "{PANE_ID}", |
70 |
| - ), |
71 |
| - ( |
72 |
| - [ |
73 |
| - "-L{SOCKET_NAME}", |
74 |
| - "-c", |
75 |
| - "print(pane.id)", |
76 |
| - ], |
77 |
| - [], |
78 |
| - {"TMUX_PANE": "{PANE_ID}"}, |
79 |
| - "{PANE_ID}", |
80 |
| - ), |
81 |
| - ], |
| 53 | + "-c", |
| 54 | + "print(server.has_session(session.name))", |
| 55 | + ], |
| 56 | + inputs=[], |
| 57 | + env={}, |
| 58 | + expected_output="True", |
| 59 | + ), |
| 60 | + CLIShellFixture( |
| 61 | + test_id="print-window-name", |
| 62 | + cli_args=[ |
| 63 | + "-L{SOCKET_NAME}", |
| 64 | + "{SESSION_NAME}", |
| 65 | + "{WINDOW_NAME}", |
| 66 | + "-c", |
| 67 | + "print(window.name)", |
| 68 | + ], |
| 69 | + inputs=[], |
| 70 | + env={}, |
| 71 | + expected_output="{WINDOW_NAME}", |
| 72 | + ), |
| 73 | + CLIShellFixture( |
| 74 | + test_id="print-pane-id", |
| 75 | + cli_args=[ |
| 76 | + "-L{SOCKET_NAME}", |
| 77 | + "{SESSION_NAME}", |
| 78 | + "{WINDOW_NAME}", |
| 79 | + "-c", |
| 80 | + "print(pane.id)", |
| 81 | + ], |
| 82 | + inputs=[], |
| 83 | + env={}, |
| 84 | + expected_output="{PANE_ID}", |
| 85 | + ), |
| 86 | + CLIShellFixture( |
| 87 | + test_id="print-pane-id-obeys-tmux-pane-env-var", |
| 88 | + cli_args=[ |
| 89 | + "-L{SOCKET_NAME}", |
| 90 | + "-c", |
| 91 | + "print(pane.id)", |
| 92 | + ], |
| 93 | + inputs=[], |
| 94 | + env={"TMUX_PANE": "{PANE_ID}"}, |
| 95 | + expected_output="{PANE_ID}", |
| 96 | + ), |
| 97 | +] |
| 98 | + |
| 99 | + |
| 100 | +@pytest.mark.parametrize("cli_cmd", [["shell"], ["shell", "--pdb"]]) |
| 101 | +@pytest.mark.parametrize( |
| 102 | + list(CLIShellFixture._fields), |
| 103 | + TEST_SHELL_FIXTURES, |
| 104 | + ids=[test.test_id for test in TEST_SHELL_FIXTURES], |
82 | 105 | )
|
83 | 106 | def test_shell(
|
84 | 107 | cli_cmd: t.List[str],
|
| 108 | + test_id: str, |
85 | 109 | cli_args: t.List[str],
|
86 | 110 | inputs: t.List[t.Any],
|
87 |
| - expected_output: str, |
88 | 111 | env: t.Dict[str, str],
|
| 112 | + expected_output: str, |
89 | 113 | server: "Server",
|
90 | 114 | session: Session,
|
91 | 115 | tmp_path: pathlib.Path,
|
|
0 commit comments