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,9 @@ def assertIsMissing(cmd, hist):
169
173
p .cmd ("send-keys" , "Enter" )
170
174
171
175
buffer_name = "test"
172
- while retry ():
176
+ sent_cmd = None
177
+
178
+ def f ():
173
179
# from v0.7.4 libtmux session.cmd adds target -t self.id by default
174
180
# show-buffer doesn't accept -t, use global cmd.
175
181
@@ -183,10 +189,8 @@ def assertIsMissing(cmd, hist):
183
189
sent_cmd = captured_pane .stdout [0 ].strip ()
184
190
history_cmd = captured_pane .stdout [- 2 ].strip ()
185
191
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 } "
190
194
191
195
192
196
def test_session_options (session ):
@@ -281,21 +285,14 @@ def test_window_options_after(session):
281
285
builder .build (session = session )
282
286
283
287
def assert_last_line (p , s ):
284
- correct = False
285
-
286
- while retry ():
288
+ def f ():
287
289
pane_out = p .cmd ("capture-pane" , "-p" , "-J" ).stdout
288
290
while not pane_out [- 1 ].strip (): # delete trailing lines tmux 1.8
289
291
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
293
293
294
294
# 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 )
299
296
300
297
for i , pane in enumerate (session .attached_window .panes ):
301
298
assert assert_last_line (
@@ -329,10 +326,10 @@ def test_window_shell(session):
329
326
if "window_shell" in wconf :
330
327
assert wconf ["window_shell" ] == "top"
331
328
332
- while retry ():
329
+ def f ():
333
330
session .server ._update_windows ()
334
- if w ["window_name" ] != "top" :
335
- break
331
+ return w ["window_name" ] != "top"
332
+ retry_until ( f )
336
333
337
334
assert w .name != "top"
338
335
@@ -448,17 +445,13 @@ def test_start_directory(session, tmp_path: pathlib.Path):
448
445
449
446
for path , window in zip (dirs , session .windows ):
450
447
for p in window .panes :
451
- while retry ():
448
+ def f ():
452
449
p .server ._update_panes ()
453
450
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
459
452
460
453
# handle case with OS X adding /private/ to /tmp/ paths
461
- assert result
454
+ assert retry_until ( f )
462
455
463
456
464
457
def test_start_directory_relative (session , tmp_path : pathlib .Path ):
@@ -502,17 +495,13 @@ def test_start_directory_relative(session, tmp_path: pathlib.Path):
502
495
503
496
for path , window in zip (dirs , session .windows ):
504
497
for p in window .panes :
505
- while retry ():
498
+ def f ():
506
499
p .server ._update_panes ()
507
500
# Handle case where directories resolve to /private/ in OSX
508
501
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
514
503
515
- assert result
504
+ assert retry_until ( f )
516
505
517
506
518
507
def test_pane_order (session ):
@@ -564,10 +553,10 @@ def test_pane_order(session):
564
553
# at 0 since python list.
565
554
pane_path = pane_paths [p_index - pane_base_index ]
566
555
567
- while retry ():
556
+ def f ():
568
557
p .server ._update_panes ()
569
- if p .current_path == pane_path :
570
- break
558
+ return p .current_path == pane_path
559
+ retry_until ( f )
571
560
572
561
assert p .current_path , pane_path
573
562
0 commit comments