11
11
import libtmux
12
12
from libtmux import Window
13
13
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
15
15
from tmuxp import config , exc
16
16
from tmuxp .cli .load import load_plugins
17
17
from tmuxp .workspacebuilder import WorkspaceBuilder
@@ -101,12 +101,15 @@ def test_focus_pane_index(session):
101
101
assert w .name != "man"
102
102
103
103
pane_path = "/usr"
104
+ p = None
104
105
105
- while retry ():
106
+ def f ():
107
+ nonlocal p
106
108
p = w .attached_pane
107
109
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 )
110
113
111
114
assert p .current_path == pane_path
112
115
@@ -120,11 +123,13 @@ def test_focus_pane_index(session):
120
123
p = None
121
124
pane_path = "/"
122
125
123
- while retry ():
126
+ def f ():
127
+ nonlocal p
124
128
p = window3 .attached_pane
125
129
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 )
128
133
129
134
assert p .current_path == pane_path
130
135
@@ -159,7 +164,6 @@ def assertIsMissing(cmd, hist):
159
164
(isMissingWindow , "isMissing" , assertIsMissing ),
160
165
]:
161
166
assert w .name == window_name
162
- correct = False
163
167
w .select_window ()
164
168
p = w .attached_pane
165
169
p .select_pane ()
@@ -169,7 +173,7 @@ def assertIsMissing(cmd, hist):
169
173
p .cmd ("send-keys" , "Enter" )
170
174
171
175
buffer_name = "test"
172
- while retry ():
176
+ def f ():
173
177
# from v0.7.4 libtmux session.cmd adds target -t self.id by default
174
178
# show-buffer doesn't accept -t, use global cmd.
175
179
@@ -183,10 +187,8 @@ def assertIsMissing(cmd, hist):
183
187
sent_cmd = captured_pane .stdout [0 ].strip ()
184
188
history_cmd = captured_pane .stdout [- 2 ].strip ()
185
189
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 } "
190
192
191
193
192
194
def test_session_options (session ):
@@ -281,19 +283,18 @@ def test_window_options_after(session):
281
283
builder .build (session = session )
282
284
283
285
def assert_last_line (p , s ):
284
- correct = False
285
-
286
- while retry ():
286
+ def f ():
287
287
pane_out = p .cmd ("capture-pane" , "-p" , "-J" ).stdout
288
288
while not pane_out [- 1 ].strip (): # delete trailing lines tmux 1.8
289
289
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
293
291
294
292
# Print output for easier debugging if assertion fails
295
- if not correct :
293
+ if retry_until (f , raises = False ):
294
+ return True
295
+ else :
296
296
print ("\n " .join (pane_out ))
297
+ return False
297
298
298
299
return correct
299
300
@@ -329,10 +330,10 @@ def test_window_shell(session):
329
330
if "window_shell" in wconf :
330
331
assert wconf ["window_shell" ] == "top"
331
332
332
- while retry ():
333
+ def f ():
333
334
session .server ._update_windows ()
334
- if w ["window_name" ] != "top" :
335
- break
335
+ return w ["window_name" ] != "top"
336
+ retry_until ( f )
336
337
337
338
assert w .name != "top"
338
339
@@ -448,17 +449,13 @@ def test_start_directory(session, tmp_path: pathlib.Path):
448
449
449
450
for path , window in zip (dirs , session .windows ):
450
451
for p in window .panes :
451
- while retry ():
452
+ def f ():
452
453
p .server ._update_panes ()
453
454
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
459
456
460
457
# handle case with OS X adding /private/ to /tmp/ paths
461
- assert result
458
+ assert retry_until ( f )
462
459
463
460
464
461
def test_start_directory_relative (session , tmp_path : pathlib .Path ):
@@ -502,17 +499,13 @@ def test_start_directory_relative(session, tmp_path: pathlib.Path):
502
499
503
500
for path , window in zip (dirs , session .windows ):
504
501
for p in window .panes :
505
- while retry ():
502
+ def f ():
506
503
p .server ._update_panes ()
507
504
# Handle case where directories resolve to /private/ in OSX
508
505
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
514
507
515
- assert result
508
+ assert retry_until ( f )
516
509
517
510
518
511
def test_pane_order (session ):
@@ -564,10 +557,10 @@ def test_pane_order(session):
564
557
# at 0 since python list.
565
558
pane_path = pane_paths [p_index - pane_base_index ]
566
559
567
- while retry ():
560
+ def f ():
568
561
p .server ._update_panes ()
569
- if p .current_path == pane_path :
570
- break
562
+ return p .current_path == pane_path
563
+ retry_until ( f )
571
564
572
565
assert p .current_path , pane_path
573
566
0 commit comments