Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ $ pipx install --suffix=@next 'tmuxp' --pip-args '\--pre' --force

- libtmux: 0.24.0 -> 0.24.1 (maintenance release)

### Tests

- Shell tests: Use named, typed test fixture (#893)

## tmuxp 1.32.0 (2023-11-19)

_Maintenance only, no bug fixes or new features_
Expand Down
158 changes: 91 additions & 67 deletions tests/cli/test_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,81 +11,105 @@
from tmuxp import cli, exc


@pytest.mark.parametrize("cli_cmd", [["shell"], ["shell", "--pdb"]])
@pytest.mark.parametrize(
"cli_args,inputs,env,expected_output",
[
(
["-L{SOCKET_NAME}", "-c", "print(str(server.socket_name))"],
[],
{},
"{SERVER_SOCKET_NAME}",
),
(
[
"-L{SOCKET_NAME}",
"{SESSION_NAME}",
"-c",
"print(session.name)",
],
[],
{},
class CLIShellFixture(t.NamedTuple):
"""Test fixture for tmuxp shell tests."""

# pytest (internal): Test fixture name
test_id: str

# test params
cli_args: t.List[str]
inputs: t.List[t.Any]
env: t.Dict[str, str]
expected_output: str


TEST_SHELL_FIXTURES: t.List[CLIShellFixture] = [
CLIShellFixture(
test_id="print-socket-name",
cli_args=["-L{SOCKET_NAME}", "-c", "print(str(server.socket_name))"],
inputs=[],
env={},
expected_output="{SERVER_SOCKET_NAME}",
),
CLIShellFixture(
test_id="print-session-name",
cli_args=[
"-L{SOCKET_NAME}",
"{SESSION_NAME}",
"-c",
"print(session.name)",
],
inputs=[],
env={},
expected_output="{SESSION_NAME}",
),
CLIShellFixture(
test_id="print-has-session",
cli_args=[
"-L{SOCKET_NAME}",
"{SESSION_NAME}",
),
(
[
"-L{SOCKET_NAME}",
"{SESSION_NAME}",
"{WINDOW_NAME}",
"-c",
"print(server.has_session(session.name))",
],
[],
{},
"True",
),
(
[
"-L{SOCKET_NAME}",
"{SESSION_NAME}",
"{WINDOW_NAME}",
"-c",
"print(window.name)",
],
[],
{},
"{WINDOW_NAME}",
),
(
[
"-L{SOCKET_NAME}",
"{SESSION_NAME}",
"{WINDOW_NAME}",
"-c",
"print(pane.id)",
],
[],
{},
"{PANE_ID}",
),
(
[
"-L{SOCKET_NAME}",
"-c",
"print(pane.id)",
],
[],
{"TMUX_PANE": "{PANE_ID}"},
"{PANE_ID}",
),
],
"-c",
"print(server.has_session(session.name))",
],
inputs=[],
env={},
expected_output="True",
),
CLIShellFixture(
test_id="print-window-name",
cli_args=[
"-L{SOCKET_NAME}",
"{SESSION_NAME}",
"{WINDOW_NAME}",
"-c",
"print(window.name)",
],
inputs=[],
env={},
expected_output="{WINDOW_NAME}",
),
CLIShellFixture(
test_id="print-pane-id",
cli_args=[
"-L{SOCKET_NAME}",
"{SESSION_NAME}",
"{WINDOW_NAME}",
"-c",
"print(pane.id)",
],
inputs=[],
env={},
expected_output="{PANE_ID}",
),
CLIShellFixture(
test_id="print-pane-id-obeys-tmux-pane-env-var",
cli_args=[
"-L{SOCKET_NAME}",
"-c",
"print(pane.id)",
],
inputs=[],
env={"TMUX_PANE": "{PANE_ID}"},
expected_output="{PANE_ID}",
),
]


@pytest.mark.parametrize("cli_cmd", [["shell"], ["shell", "--pdb"]])
@pytest.mark.parametrize(
list(CLIShellFixture._fields),
TEST_SHELL_FIXTURES,
ids=[test.test_id for test in TEST_SHELL_FIXTURES],
)
def test_shell(
cli_cmd: t.List[str],
test_id: str,
cli_args: t.List[str],
inputs: t.List[t.Any],
expected_output: str,
env: t.Dict[str, str],
expected_output: str,
server: "Server",
session: Session,
tmp_path: pathlib.Path,
Expand Down