Skip to content

Commit 68d9d89

Browse files
committed
convert calls to retry to retry_until
1 parent 827eacf commit 68d9d89

File tree

1 file changed

+33
-40
lines changed

1 file changed

+33
-40
lines changed

tests/test_workspacebuilder.py

+33-40
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,7 @@ def assertIsMissing(cmd, hist):
169173
p.cmd("send-keys", "Enter")
170174

171175
buffer_name = "test"
172-
while retry():
176+
def f():
173177
# from v0.7.4 libtmux session.cmd adds target -t self.id by default
174178
# show-buffer doesn't accept -t, use global cmd.
175179

@@ -183,10 +187,8 @@ def assertIsMissing(cmd, hist):
183187
sent_cmd = captured_pane.stdout[0].strip()
184188
history_cmd = captured_pane.stdout[-2].strip()
185189

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

191193

192194
def test_session_options(session):
@@ -281,19 +283,18 @@ def test_window_options_after(session):
281283
builder.build(session=session)
282284

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

294292
# Print output for easier debugging if assertion fails
295-
if not correct:
293+
if retry_until(f, raises=False):
294+
return True
295+
else:
296296
print("\n".join(pane_out))
297+
return False
297298

298299
return correct
299300

@@ -329,10 +330,10 @@ def test_window_shell(session):
329330
if "window_shell" in wconf:
330331
assert wconf["window_shell"] == "top"
331332

332-
while retry():
333+
def f():
333334
session.server._update_windows()
334-
if w["window_name"] != "top":
335-
break
335+
return w["window_name"] != "top"
336+
retry_until(f)
336337

337338
assert w.name != "top"
338339

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

449450
for path, window in zip(dirs, session.windows):
450451
for p in window.panes:
451-
while retry():
452+
def f():
452453
p.server._update_panes()
453454
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
455+
return path in pane_path or pane_path == path
459456

460457
# handle case with OS X adding /private/ to /tmp/ paths
461-
assert result
458+
assert retry_until(f)
462459

463460

464461
def test_start_directory_relative(session, tmp_path: pathlib.Path):
@@ -502,17 +499,13 @@ def test_start_directory_relative(session, tmp_path: pathlib.Path):
502499

503500
for path, window in zip(dirs, session.windows):
504501
for p in window.panes:
505-
while retry():
502+
def f():
506503
p.server._update_panes()
507504
# Handle case where directories resolve to /private/ in OSX
508505
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
506+
return path in pane_path or pane_path == path
514507

515-
assert result
508+
assert retry_until(f)
516509

517510

518511
def test_pane_order(session):
@@ -564,10 +557,10 @@ def test_pane_order(session):
564557
# at 0 since python list.
565558
pane_path = pane_paths[p_index - pane_base_index]
566559

567-
while retry():
560+
def f():
568561
p.server._update_panes()
569-
if p.current_path == pane_path:
570-
break
562+
return p.current_path == pane_path
563+
retry_until(f)
571564

572565
assert p.current_path, pane_path
573566

0 commit comments

Comments
 (0)