Skip to content

test(automatic rename): Fix renaming #853

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 26, 2022
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 @@ -19,6 +19,10 @@ $ pipx install --suffix=@next 'tmuxp' --pip-args '\--pre' --force

<!-- Maintainers, insert changes / features for the next release here -->

### Developmental

- Tests: Stabilization fix for automatic rename test (#853)

## tmuxp 1.19.1 (2022-12-12)

### Fixes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
session_name: test window options
start_directory: '~'
windows:
- layout: main-horizontal
- window_name: renamed_window
layout: main-horizontal
options:
automatic-rename: on
panes:
- shell_command:
- cmd: man ls
start_directory: '~'
focus: true
- shell_command:
- cmd: echo "hey"
- shell_command:
Expand Down
49 changes: 19 additions & 30 deletions tests/workspace/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,15 +415,17 @@ def test_environment_variables_logs(session: Session, caplog: pytest.LogCaptureF
sum(
1
for record in caplog.records
if 'Cannot set environment for new panes and windows.' in record.msg
if "Cannot set environment for new panes and windows." in record.msg
)
# From both_overrides_in_first_pane.
== 1
)


def test_automatic_rename_option(session):
"""With option automatic-rename: on."""
def test_automatic_rename_option(
server: "Server", monkeypatch: pytest.MonkeyPatch
) -> None:
monkeypatch.setenv("DISABLE_AUTO_TITLE", "true")
workspace = ConfigReader._from_file(
test_utils.get_workspace_file("workspace/builder/window_automatic_rename.yaml")
)
Expand All @@ -434,42 +436,29 @@ def test_automatic_rename_option(session):
if " " in portable_command:
portable_command = portable_command.split(" ")[0]

builder = WorkspaceBuilder(sconf=workspace)

window_count = len(session._windows) # current window count
assert len(session._windows) == window_count
for w, wconf in builder.iter_create_windows(session):

for p in builder.iter_create_panes(w, wconf):
w.select_layout("tiled") # fix glitch with pane size
p = p
assert len(session._windows), window_count
assert isinstance(w, Window)
assert w.show_window_option("automatic-rename") == "on"

assert len(session._windows) == window_count

window_count += 1
w.select_layout(wconf["layout"])
builder = WorkspaceBuilder(sconf=workspace, server=server)
builder.build()
session: Session = builder.session
w: Window = session.windows[0]
assert len(session.windows) == 1

assert session.name != "tmuxp"
w = session.windows[0]
assert w.name != "renamed_window"

def check_window_name_mismatch() -> bool:
session.server._update_windows()
w.server._update_windows()
return w.name != portable_command

assert retry_until(check_window_name_mismatch, 2, interval=0.25)

pane_base_index = w.show_window_option("pane-base-index", g=True)
w.select_pane(pane_base_index)
assert retry_until(check_window_name_mismatch, 5, interval=0.25)

def check_window_name_match() -> bool:
session.server._update_windows()
return w.name == portable_command
w.server._update_windows()
assert w.show_window_option("automatic-rename") == "on"

print(f"w.name: {w.name} and portable_command: {portable_command}")
return w.name == "zsh" or w.name == portable_command

assert retry_until(
check_window_name_match, 2, interval=0.25
check_window_name_match, 4, interval=0.05
), f"Window name {w.name} should be {portable_command}"

w.select_pane("-D")
Expand Down