Skip to content

Commit fd2f430

Browse files
authored
tests: convert calls to retry to retry_until (#777)
Fixes #778
1 parent 827eacf commit fd2f430

File tree

1 file changed

+32
-43
lines changed

1 file changed

+32
-43
lines changed

Diff for: tests/test_workspacebuilder.py

+32-43
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import libtmux
1212
from libtmux import Window
1313
from libtmux.common import has_gte_version
14-
from libtmux.test import retry, retry_until, temp_session
14+
from libtmux.test import retry_until, temp_session
1515
from tmuxp import config, exc
1616
from tmuxp.cli.load import load_plugins
1717
from tmuxp.workspacebuilder import WorkspaceBuilder
@@ -101,12 +101,15 @@ def test_focus_pane_index(session):
101101
assert w.name != "man"
102102

103103
pane_path = "/usr"
104+
p = None
104105

105-
while retry():
106+
def f():
107+
nonlocal p
106108
p = w.attached_pane
107109
p.server._update_panes()
108-
if p.current_path == pane_path:
109-
break
110+
return p.current_path == pane_path
111+
112+
assert retry_until(f)
110113

111114
assert p.current_path == pane_path
112115

@@ -120,11 +123,13 @@ def test_focus_pane_index(session):
120123
p = None
121124
pane_path = "/"
122125

123-
while retry():
126+
def f():
127+
nonlocal p
124128
p = window3.attached_pane
125129
p.server._update_panes()
126-
if p.current_path == pane_path:
127-
break
130+
return p.current_path == pane_path
131+
132+
assert retry_until(f)
128133

129134
assert p.current_path == pane_path
130135

@@ -159,7 +164,6 @@ def assertIsMissing(cmd, hist):
159164
(isMissingWindow, "isMissing", assertIsMissing),
160165
]:
161166
assert w.name == window_name
162-
correct = False
163167
w.select_window()
164168
p = w.attached_pane
165169
p.select_pane()
@@ -169,7 +173,9 @@ def assertIsMissing(cmd, hist):
169173
p.cmd("send-keys", "Enter")
170174

171175
buffer_name = "test"
172-
while retry():
176+
sent_cmd = None
177+
178+
def f():
173179
# from v0.7.4 libtmux session.cmd adds target -t self.id by default
174180
# show-buffer doesn't accept -t, use global cmd.
175181

@@ -183,10 +189,8 @@ def assertIsMissing(cmd, hist):
183189
sent_cmd = captured_pane.stdout[0].strip()
184190
history_cmd = captured_pane.stdout[-2].strip()
185191

186-
if assertCase(sent_cmd, history_cmd):
187-
correct = True
188-
break
189-
assert correct, f"Unknown sent command: [{sent_cmd}] in {assertCase}"
192+
return assertCase(sent_cmd, history_cmd)
193+
assert retry_until(f), f"Unknown sent command: [{sent_cmd}] in {assertCase}"
190194

191195

192196
def test_session_options(session):
@@ -281,21 +285,14 @@ def test_window_options_after(session):
281285
builder.build(session=session)
282286

283287
def assert_last_line(p, s):
284-
correct = False
285-
286-
while retry():
288+
def f():
287289
pane_out = p.cmd("capture-pane", "-p", "-J").stdout
288290
while not pane_out[-1].strip(): # delete trailing lines tmux 1.8
289291
pane_out.pop()
290-
if len(pane_out) > 1 and pane_out[-2].strip() == s:
291-
correct = True
292-
break
292+
return len(pane_out) > 1 and pane_out[-2].strip() == s
293293

294294
# Print output for easier debugging if assertion fails
295-
if not correct:
296-
print("\n".join(pane_out))
297-
298-
return correct
295+
return retry_until(f, raises=False)
299296

300297
for i, pane in enumerate(session.attached_window.panes):
301298
assert assert_last_line(
@@ -329,10 +326,10 @@ def test_window_shell(session):
329326
if "window_shell" in wconf:
330327
assert wconf["window_shell"] == "top"
331328

332-
while retry():
329+
def f():
333330
session.server._update_windows()
334-
if w["window_name"] != "top":
335-
break
331+
return w["window_name"] != "top"
332+
retry_until(f)
336333

337334
assert w.name != "top"
338335

@@ -448,17 +445,13 @@ def test_start_directory(session, tmp_path: pathlib.Path):
448445

449446
for path, window in zip(dirs, session.windows):
450447
for p in window.panes:
451-
while retry():
448+
def f():
452449
p.server._update_panes()
453450
pane_path = p.current_path
454-
if pane_path is None:
455-
pass
456-
elif path in pane_path or pane_path == path:
457-
result = path == pane_path or path in pane_path
458-
break
451+
return path in pane_path or pane_path == path
459452

460453
# handle case with OS X adding /private/ to /tmp/ paths
461-
assert result
454+
assert retry_until(f)
462455

463456

464457
def test_start_directory_relative(session, tmp_path: pathlib.Path):
@@ -502,17 +495,13 @@ def test_start_directory_relative(session, tmp_path: pathlib.Path):
502495

503496
for path, window in zip(dirs, session.windows):
504497
for p in window.panes:
505-
while retry():
498+
def f():
506499
p.server._update_panes()
507500
# Handle case where directories resolve to /private/ in OSX
508501
pane_path = p.current_path
509-
if pane_path is None:
510-
pass
511-
elif path in pane_path or pane_path == path:
512-
result = path == pane_path or path in pane_path
513-
break
502+
return path in pane_path or pane_path == path
514503

515-
assert result
504+
assert retry_until(f)
516505

517506

518507
def test_pane_order(session):
@@ -564,10 +553,10 @@ def test_pane_order(session):
564553
# at 0 since python list.
565554
pane_path = pane_paths[p_index - pane_base_index]
566555

567-
while retry():
556+
def f():
568557
p.server._update_panes()
569-
if p.current_path == pane_path:
570-
break
558+
return p.current_path == pane_path
559+
retry_until(f)
571560

572561
assert p.current_path, pane_path
573562

0 commit comments

Comments
 (0)