From f973b0507cfd1be33013b7917a1c3f9e70b2f643 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Tue, 19 Apr 2022 06:23:15 -0500 Subject: [PATCH 1/3] tests(automatic rename): Fix timeout check, use config's shell command name Per https://github.com/tmux-python/libtmux/issues/368, retry(seconds=...) is broke. --- tests/test_workspacebuilder.py | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/tests/test_workspacebuilder.py b/tests/test_workspacebuilder.py index 2ab04a9363f..3d2c12aafba 100644 --- a/tests/test_workspacebuilder.py +++ b/tests/test_workspacebuilder.py @@ -359,6 +359,12 @@ def test_automatic_rename_option(session): sconfig = kaptan.Kaptan(handler="yaml") sconfig = sconfig.import_config(yaml_config).get() + # This should be a command guaranteed to be terminal name across systems + portable_command = sconfig["windows"][0]["panes"][0]["shell_command"][0]["cmd"] + # If a command is like "man ls", get the command base name, "ls" + if " " in portable_command: + portable_command = portable_command.split(" ")[0] + builder = WorkspaceBuilder(sconf=sconfig) window_count = len(session._windows) # current window count @@ -380,31 +386,36 @@ def test_automatic_rename_option(session): assert s.name != "tmuxp" w = s.windows[0] - while retry(): + t = time.process_time() + while (time.process_time() - t) * 1000 < 20: session.server._update_windows() - if w.name != "sh": + if w.name != portable_command: break + time.sleep(0.2) - assert w.name != "sh" + assert w.name != portable_command pane_base_index = w.show_window_option("pane-base-index", g=True) w.select_pane(pane_base_index) - while retry(): + t = time.process_time() + while (time.process_time() - t) * 1000 < 20: session.server._update_windows() - if w.name == "sh": + if w.name == portable_command: break + time.sleep(0.2) - assert w.name == "sh" + assert w.name == portable_command w.select_pane("-D") - while retry(): + t = time.process_time() + while (time.process_time() - t) * 1000 < 20: session.server._update_windows() - if w["window_name"] != "sh": + if w["window_name"] != portable_command: break - - assert w.name != "sh" + time.sleep(0.2) + assert w.name != portable_command def test_blank_pane_count(session): From 709dc436329be06c58483b4fe75207963dd362ee Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Tue, 19 Apr 2022 06:24:14 -0500 Subject: [PATCH 2/3] tests: Use "man ls" instead of "sh" https://github.com/tmux-python/tmuxp/issues/620 users are reporting that "sh" has a different name used in tmux windows across platforms. --- tests/fixtures/workspacebuilder/window_automatic_rename.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/fixtures/workspacebuilder/window_automatic_rename.yaml b/tests/fixtures/workspacebuilder/window_automatic_rename.yaml index 08329afcfea..a3640f4dedc 100644 --- a/tests/fixtures/workspacebuilder/window_automatic_rename.yaml +++ b/tests/fixtures/workspacebuilder/window_automatic_rename.yaml @@ -6,7 +6,7 @@ windows: automatic-rename: on panes: - shell_command: - - cmd: sh + - cmd: man ls start_directory: '~' - shell_command: - cmd: echo "hey" From 23face22e44ca3c174177598f881076b23deff77 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Fri, 20 May 2022 19:12:34 -0500 Subject: [PATCH 3/3] tests(automatic_rename_option): Use retry_until() --- tests/test_workspacebuilder.py | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/tests/test_workspacebuilder.py b/tests/test_workspacebuilder.py index 3d2c12aafba..b347fb36723 100644 --- a/tests/test_workspacebuilder.py +++ b/tests/test_workspacebuilder.py @@ -11,7 +11,7 @@ import libtmux from libtmux import Window from libtmux.common import has_gte_version -from libtmux.test import retry, temp_session +from libtmux.test import retry, retry_until, temp_session from tmuxp import config, exc from tmuxp.cli.load import load_plugins from tmuxp.workspacebuilder import WorkspaceBuilder @@ -386,36 +386,24 @@ def test_automatic_rename_option(session): assert s.name != "tmuxp" w = s.windows[0] - t = time.process_time() - while (time.process_time() - t) * 1000 < 20: + def check_window_name_mismatch() -> bool: session.server._update_windows() - if w.name != portable_command: - break - time.sleep(0.2) + return w.name != portable_command - assert 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) - t = time.process_time() - while (time.process_time() - t) * 1000 < 20: + def check_window_name_match() -> bool: session.server._update_windows() - if w.name == portable_command: - break - time.sleep(0.2) + return w.name == portable_command - assert w.name == portable_command + assert retry_until(check_window_name_match, 2, interval=0.25) w.select_pane("-D") - t = time.process_time() - while (time.process_time() - t) * 1000 < 20: - session.server._update_windows() - if w["window_name"] != portable_command: - break - time.sleep(0.2) - assert w.name != portable_command + assert retry_until(check_window_name_mismatch, 2, interval=0.25) def test_blank_pane_count(session):