9
9
10
10
import kaptan
11
11
import pytest
12
-
13
- from . import fixtures_dir
14
12
from libtmux import Window
15
13
from libtmux .common import has_gte_version
16
14
from libtmux .test import temp_session
15
+
17
16
from tmuxp import config , exc
18
17
from tmuxp ._compat import text_type
19
18
from tmuxp .workspacebuilder import WorkspaceBuilder
20
19
21
- from . import example_dir
20
+ from . import example_dir , fixtures_dir
22
21
from .fixtures ._util import loadfixture
23
22
24
-
25
23
RETRY_TIMEOUT_SECONDS = int (os .getenv ('RETRY_TIMEOUT_SECONDS' , 8 ))
26
24
27
25
26
+ def retry (seconds = RETRY_TIMEOUT_SECONDS ):
27
+ return (lambda : time .time () < time .time () + seconds )()
28
+
29
+
28
30
def test_split_windows (session ):
29
31
yaml_config = loadfixture ("workspacebuilder/two_pane.yaml" )
30
32
s = session
@@ -110,15 +112,11 @@ def test_focus_pane_index(session):
110
112
111
113
pane_path = '/usr'
112
114
113
- timeout = time .time () + RETRY_TIMEOUT_SECONDS # seconds timeout
114
-
115
- while True :
115
+ while retry ():
116
116
p = w .attached_pane
117
117
p .server ._update_panes ()
118
118
if p .current_path == pane_path :
119
119
break
120
- elif time .time () > timeout :
121
- break
122
120
123
121
assert p .current_path == pane_path
124
122
@@ -131,14 +129,12 @@ def test_focus_pane_index(session):
131
129
132
130
p = None
133
131
pane_path = '/'
134
- timeout = time . time () + RETRY_TIMEOUT_SECONDS # seconds timeout
135
- while True :
132
+
133
+ while retry () :
136
134
p = window3 .attached_pane
137
135
p .server ._update_panes ()
138
136
if p .current_path == pane_path :
139
137
break
140
- elif time .time () > timeout :
141
- break
142
138
143
139
assert p .current_path == pane_path
144
140
@@ -302,17 +298,14 @@ def test_window_options_after(session):
302
298
303
299
def assert_last_line (p , s ):
304
300
correct = False
305
- timeout = time .time () + RETRY_TIMEOUT_SECONDS # seconds timeout
306
301
307
- while True :
302
+ while retry () :
308
303
pane_out = p .cmd ('capture-pane' , '-p' , '-J' ).stdout
309
304
while not pane_out [- 1 ].strip (): # delete trailing lines tmux 1.8
310
305
pane_out .pop ()
311
306
if len (pane_out ) > 1 and pane_out [- 2 ].strip () == s :
312
307
correct = True
313
308
break
314
- elif time .time () > timeout :
315
- break
316
309
317
310
# Print output for easier debugging if assertion fails
318
311
if not correct :
@@ -351,13 +344,11 @@ def test_window_shell(session):
351
344
for w , wconf in builder .iter_create_windows (s ):
352
345
if 'window_shell' in wconf :
353
346
assert wconf ['window_shell' ] == text_type ('top' )
354
- timeout = time . time () + RETRY_TIMEOUT_SECONDS # seconds timeout
355
- while True :
347
+
348
+ while retry () :
356
349
session .server ._update_windows ()
357
350
if w ['window_name' ] != 'top' :
358
351
break
359
- elif time .time () > timeout :
360
- break
361
352
362
353
assert w .name != text_type ('top' )
363
354
@@ -403,38 +394,29 @@ def test_automatic_rename_option(session):
403
394
assert s .name != 'tmuxp'
404
395
w = s .windows [0 ]
405
396
406
- timeout = time .time () + RETRY_TIMEOUT_SECONDS # seconds timeout
407
- while True :
397
+ while retry ():
408
398
session .server ._update_windows ()
409
399
if w .name != 'sh' :
410
400
break
411
- elif time .time () > timeout :
412
- break
413
401
414
402
assert w .name != 'sh'
415
403
416
404
pane_base_index = w .show_window_option ('pane-base-index' , g = True )
417
405
w .select_pane (pane_base_index )
418
406
419
- timeout = time .time () + RETRY_TIMEOUT_SECONDS # seconds timeout
420
- while True :
407
+ while retry ():
421
408
session .server ._update_windows ()
422
409
if w .name == 'sh' :
423
410
break
424
- elif time .time () > timeout :
425
- break
426
411
427
412
assert w .name == text_type ('sh' )
428
413
429
414
w .select_pane ('-D' )
430
415
431
- timeout = time .time () + RETRY_TIMEOUT_SECONDS # seconds timeout
432
- while True :
416
+ while retry ():
433
417
session .server ._update_windows ()
434
418
if w ['window_name' ] != 'sh' :
435
419
break
436
- elif time .time () > timeout :
437
- break
438
420
439
421
assert w .name != text_type ('sh' )
440
422
@@ -490,8 +472,7 @@ def test_start_directory(session, tmpdir):
490
472
491
473
for path , window in zip (dirs , session .windows ):
492
474
for p in window .panes :
493
- timeout = time .time () + RETRY_TIMEOUT_SECONDS # seconds timeout
494
- while True :
475
+ while retry ():
495
476
p .server ._update_panes ()
496
477
pane_path = p .current_path
497
478
if pane_path is None :
@@ -505,8 +486,6 @@ def test_start_directory(session, tmpdir):
505
486
path in pane_path
506
487
)
507
488
break
508
- elif time .time () > timeout :
509
- break
510
489
511
490
# handle case with OS X adding /private/ to /tmp/ paths
512
491
assert result
@@ -558,8 +537,7 @@ def test_start_directory_relative(session, tmpdir):
558
537
559
538
for path , window in zip (dirs , session .windows ):
560
539
for p in window .panes :
561
- timeout = time .time () + RETRY_TIMEOUT_SECONDS # seconds timeout
562
- while True :
540
+ while retry ():
563
541
p .server ._update_panes ()
564
542
# Handle case where directories resolve to /private/ in OSX
565
543
pane_path = p .current_path
@@ -574,8 +552,6 @@ def test_start_directory_relative(session, tmpdir):
574
552
path in pane_path
575
553
)
576
554
break
577
- elif time .time () > timeout :
578
- break
579
555
580
556
assert result
581
557
@@ -629,13 +605,10 @@ def test_pane_order(session):
629
605
# at 0 since python list.
630
606
pane_path = pane_paths [p_index - pane_base_index ]
631
607
632
- timeout = time .time () + RETRY_TIMEOUT_SECONDS # seconds timeout
633
- while True :
608
+ while retry ():
634
609
p .server ._update_panes ()
635
610
if p .current_path == pane_path :
636
611
break
637
- elif time .time () > timeout :
638
- break
639
612
640
613
assert p .current_path , pane_path
641
614
0 commit comments