Skip to content

Commit e607bca

Browse files
authored
tests: Use retry_until in more places, cleaner shell with ZSH (#781)
2 parents 1570f49 + 5424ecd commit e607bca

File tree

2 files changed

+44
-23
lines changed

2 files changed

+44
-23
lines changed

tests/conftest.py

+13
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from libtmux.test import TEST_SESSION_PREFIX, get_test_session_name, namer
1111

1212
logger = logging.getLogger(__name__)
13+
USING_ZSH = "zsh" in os.getenv("SHELL", "")
1314

1415

1516
@pytest.fixture(autouse=True, scope="session")
@@ -24,6 +25,18 @@ def user_path(home_path: pathlib.Path):
2425
return p
2526

2627

28+
@pytest.mark.skipif(USING_ZSH, reason="Using ZSH")
29+
@pytest.fixture(autouse=USING_ZSH, scope="session")
30+
def zshrc(user_path: pathlib.Path):
31+
"""This quiets ZSH default message.
32+
33+
Needs a startup file .zshenv, .zprofile, .zshrc, .zlogin.
34+
"""
35+
p = user_path / ".zshrc"
36+
p.touch()
37+
return p
38+
39+
2740
@pytest.fixture(autouse=True)
2841
def home_path_default(user_path: pathlib.Path):
2942
os.environ["HOME"] = str(user_path)

tests/test_workspacebuilder.py

+31-23
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ def f():
190190
history_cmd = captured_pane.stdout[-2].strip()
191191

192192
return assertCase(sent_cmd, history_cmd)
193+
193194
assert retry_until(f), f"Unknown sent command: [{sent_cmd}] in {assertCase}"
194195

195196

@@ -329,6 +330,7 @@ def test_window_shell(session):
329330
def f():
330331
session.server._update_windows()
331332
return w["window_name"] != "top"
333+
332334
retry_until(f)
333335

334336
assert w.name != "top"
@@ -447,6 +449,7 @@ def test_start_directory(session, tmp_path: pathlib.Path):
447449

448450
for path, window in zip(dirs, session.windows):
449451
for p in window.panes:
452+
450453
def f():
451454
p.server._update_panes()
452455
pane_path = p.current_path
@@ -497,6 +500,7 @@ def test_start_directory_relative(session, tmp_path: pathlib.Path):
497500

498501
for path, window in zip(dirs, session.windows):
499502
for p in window.panes:
503+
500504
def f():
501505
p.server._update_panes()
502506
# Handle case where directories resolve to /private/ in OSX
@@ -558,6 +562,7 @@ def test_pane_order(session):
558562
def f():
559563
p.server._update_panes()
560564
return p.current_path == pane_path
565+
561566
retry_until(f)
562567

563568
assert p.current_path, pane_path
@@ -1014,17 +1019,20 @@ def test_load_workspace_enter(
10141019
builder = WorkspaceBuilder(sconf=sconfig, server=server)
10151020
builder.build()
10161021

1017-
time.sleep(1)
1018-
10191022
session = builder.session
10201023
pane = session.attached_pane
10211024

1022-
captured_pane = "\n".join(pane.capture_pane())
1025+
def fn():
1026+
captured_pane = "\n".join(pane.capture_pane())
10231027

1024-
if should_see:
1025-
assert output in captured_pane
1026-
else:
1027-
assert output not in captured_pane
1028+
if should_see:
1029+
return output in captured_pane
1030+
else:
1031+
return output not in captured_pane
1032+
1033+
assert retry_until(
1034+
fn, 1
1035+
), f'Should{" " if should_see else "not "} output in captured pane'
10281036

10291037

10301038
@pytest.mark.parametrize(
@@ -1038,12 +1046,12 @@ def test_load_workspace_enter(
10381046
- panes:
10391047
- shell_command:
10401048
- cmd: echo "___$((1 + 5))___"
1041-
sleep_before: 2
1049+
sleep_before: .15
10421050
- cmd: echo "___$((1 + 3))___"
1043-
sleep_before: 1
1051+
sleep_before: .35
10441052
"""
10451053
),
1046-
1.5,
1054+
0.5,
10471055
"___4___",
10481056
],
10491057
[
@@ -1054,12 +1062,12 @@ def test_load_workspace_enter(
10541062
- panes:
10551063
- shell_command:
10561064
- cmd: echo "___$((1 + 5))___"
1057-
sleep_before: 2
1058-
- cmd: echo "___$((1 + 3))___"
10591065
sleep_before: 1
1066+
- cmd: echo "___$((1 + 3))___"
1067+
sleep_before: .25
10601068
"""
10611069
),
1062-
3,
1070+
1.25,
10631071
"___4___",
10641072
],
10651073
[
@@ -1070,10 +1078,10 @@ def test_load_workspace_enter(
10701078
- panes:
10711079
- shell_command:
10721080
- cmd: echo "___$((1 + 3))___"
1073-
sleep_before: 2
1081+
sleep_before: .5
10741082
"""
10751083
),
1076-
2,
1084+
0.5,
10771085
"___4___",
10781086
],
10791087
[
@@ -1084,10 +1092,10 @@ def test_load_workspace_enter(
10841092
- panes:
10851093
- shell_command:
10861094
- cmd: echo "___$((1 + 3))___"
1087-
sleep_before: 2
1095+
sleep_before: 1
10881096
"""
10891097
),
1090-
2,
1098+
1,
10911099
"___4___",
10921100
],
10931101
[
@@ -1096,21 +1104,21 @@ def test_load_workspace_enter(
10961104
session_name: Should not execute
10971105
shell_command_before:
10981106
- cmd: echo "sleeping before"
1099-
sleep_before: 2
1107+
sleep_before: .5
11001108
windows:
11011109
- panes:
11021110
- echo "___$((1 + 3))___"
11031111
"""
11041112
),
1105-
2,
1113+
0.5,
11061114
"___4___",
11071115
],
11081116
],
11091117
ids=[
1110-
"command_level_sleep_3_shortform",
1111-
"command_level_pane_sleep_3_longform",
1112-
"pane_sleep_2_shortform",
1113-
"pane_sleep_2_longform",
1118+
"command_level_sleep_shortform",
1119+
"command_level_pane_sleep_longform",
1120+
"pane_sleep_shortform",
1121+
"pane_sleep_longform",
11141122
"shell_before_before_command_level",
11151123
],
11161124
)

0 commit comments

Comments
 (0)