Skip to content

Commit a22242f

Browse files
authored
refactor(test_shell): Use named, typed test fixtures (#893)
Extracted from #891
2 parents 28f4f37 + 2d57386 commit a22242f

File tree

2 files changed

+95
-67
lines changed

2 files changed

+95
-67
lines changed

CHANGES

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ $ pipx install --suffix=@next 'tmuxp' --pip-args '\--pre' --force
3333

3434
- libtmux: 0.24.0 -> 0.24.1 (maintenance release)
3535

36+
### Tests
37+
38+
- Shell tests: Use named, typed test fixture (#893)
39+
3640
## tmuxp 1.32.0 (2023-11-19)
3741

3842
_Maintenance only, no bug fixes or new features_

tests/cli/test_shell.py

Lines changed: 91 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -11,81 +11,105 @@
1111
from tmuxp import cli, exc
1212

1313

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}",
3351
"{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-
{},
5752
"{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],
82105
)
83106
def test_shell(
84107
cli_cmd: t.List[str],
108+
test_id: str,
85109
cli_args: t.List[str],
86110
inputs: t.List[t.Any],
87-
expected_output: str,
88111
env: t.Dict[str, str],
112+
expected_output: str,
89113
server: "Server",
90114
session: Session,
91115
tmp_path: pathlib.Path,

0 commit comments

Comments
 (0)