Skip to content

Commit f8fbaad

Browse files
committed
consolidate retry into retry wrapped lambda
1 parent ad9ee05 commit f8fbaad

File tree

1 file changed

+18
-45
lines changed

1 file changed

+18
-45
lines changed

tests/test_workspacebuilder.py

Lines changed: 18 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,24 @@
99

1010
import kaptan
1111
import pytest
12-
13-
from . import fixtures_dir
1412
from libtmux import Window
1513
from libtmux.common import has_gte_version
1614
from libtmux.test import temp_session
15+
1716
from tmuxp import config, exc
1817
from tmuxp._compat import text_type
1918
from tmuxp.workspacebuilder import WorkspaceBuilder
2019

21-
from . import example_dir
20+
from . import example_dir, fixtures_dir
2221
from .fixtures._util import loadfixture
2322

24-
2523
RETRY_TIMEOUT_SECONDS = int(os.getenv('RETRY_TIMEOUT_SECONDS', 8))
2624

2725

26+
def retry(seconds=RETRY_TIMEOUT_SECONDS):
27+
return (lambda: time.time() < time.time() + seconds)()
28+
29+
2830
def test_split_windows(session):
2931
yaml_config = loadfixture("workspacebuilder/two_pane.yaml")
3032
s = session
@@ -110,15 +112,11 @@ def test_focus_pane_index(session):
110112

111113
pane_path = '/usr'
112114

113-
timeout = time.time() + RETRY_TIMEOUT_SECONDS # seconds timeout
114-
115-
while True:
115+
while retry():
116116
p = w.attached_pane
117117
p.server._update_panes()
118118
if p.current_path == pane_path:
119119
break
120-
elif time.time() > timeout:
121-
break
122120

123121
assert p.current_path == pane_path
124122

@@ -131,14 +129,12 @@ def test_focus_pane_index(session):
131129

132130
p = None
133131
pane_path = '/'
134-
timeout = time.time() + RETRY_TIMEOUT_SECONDS # seconds timeout
135-
while True:
132+
133+
while retry():
136134
p = window3.attached_pane
137135
p.server._update_panes()
138136
if p.current_path == pane_path:
139137
break
140-
elif time.time() > timeout:
141-
break
142138

143139
assert p.current_path == pane_path
144140

@@ -302,17 +298,14 @@ def test_window_options_after(session):
302298

303299
def assert_last_line(p, s):
304300
correct = False
305-
timeout = time.time() + RETRY_TIMEOUT_SECONDS # seconds timeout
306301

307-
while True:
302+
while retry():
308303
pane_out = p.cmd('capture-pane', '-p', '-J').stdout
309304
while not pane_out[-1].strip(): # delete trailing lines tmux 1.8
310305
pane_out.pop()
311306
if len(pane_out) > 1 and pane_out[-2].strip() == s:
312307
correct = True
313308
break
314-
elif time.time() > timeout:
315-
break
316309

317310
# Print output for easier debugging if assertion fails
318311
if not correct:
@@ -351,13 +344,11 @@ def test_window_shell(session):
351344
for w, wconf in builder.iter_create_windows(s):
352345
if 'window_shell' in wconf:
353346
assert wconf['window_shell'] == text_type('top')
354-
timeout = time.time() + RETRY_TIMEOUT_SECONDS # seconds timeout
355-
while True:
347+
348+
while retry():
356349
session.server._update_windows()
357350
if w['window_name'] != 'top':
358351
break
359-
elif time.time() > timeout:
360-
break
361352

362353
assert w.name != text_type('top')
363354

@@ -403,38 +394,29 @@ def test_automatic_rename_option(session):
403394
assert s.name != 'tmuxp'
404395
w = s.windows[0]
405396

406-
timeout = time.time() + RETRY_TIMEOUT_SECONDS # seconds timeout
407-
while True:
397+
while retry():
408398
session.server._update_windows()
409399
if w.name != 'sh':
410400
break
411-
elif time.time() > timeout:
412-
break
413401

414402
assert w.name != 'sh'
415403

416404
pane_base_index = w.show_window_option('pane-base-index', g=True)
417405
w.select_pane(pane_base_index)
418406

419-
timeout = time.time() + RETRY_TIMEOUT_SECONDS # seconds timeout
420-
while True:
407+
while retry():
421408
session.server._update_windows()
422409
if w.name == 'sh':
423410
break
424-
elif time.time() > timeout:
425-
break
426411

427412
assert w.name == text_type('sh')
428413

429414
w.select_pane('-D')
430415

431-
timeout = time.time() + RETRY_TIMEOUT_SECONDS # seconds timeout
432-
while True:
416+
while retry():
433417
session.server._update_windows()
434418
if w['window_name'] != 'sh':
435419
break
436-
elif time.time() > timeout:
437-
break
438420

439421
assert w.name != text_type('sh')
440422

@@ -490,8 +472,7 @@ def test_start_directory(session, tmpdir):
490472

491473
for path, window in zip(dirs, session.windows):
492474
for p in window.panes:
493-
timeout = time.time() + RETRY_TIMEOUT_SECONDS # seconds timeout
494-
while True:
475+
while retry():
495476
p.server._update_panes()
496477
pane_path = p.current_path
497478
if pane_path is None:
@@ -505,8 +486,6 @@ def test_start_directory(session, tmpdir):
505486
path in pane_path
506487
)
507488
break
508-
elif time.time() > timeout:
509-
break
510489

511490
# handle case with OS X adding /private/ to /tmp/ paths
512491
assert result
@@ -558,8 +537,7 @@ def test_start_directory_relative(session, tmpdir):
558537

559538
for path, window in zip(dirs, session.windows):
560539
for p in window.panes:
561-
timeout = time.time() + RETRY_TIMEOUT_SECONDS # seconds timeout
562-
while True:
540+
while retry():
563541
p.server._update_panes()
564542
# Handle case where directories resolve to /private/ in OSX
565543
pane_path = p.current_path
@@ -574,8 +552,6 @@ def test_start_directory_relative(session, tmpdir):
574552
path in pane_path
575553
)
576554
break
577-
elif time.time() > timeout:
578-
break
579555

580556
assert result
581557

@@ -629,13 +605,10 @@ def test_pane_order(session):
629605
# at 0 since python list.
630606
pane_path = pane_paths[p_index - pane_base_index]
631607

632-
timeout = time.time() + RETRY_TIMEOUT_SECONDS # seconds timeout
633-
while True:
608+
while retry():
634609
p.server._update_panes()
635610
if p.current_path == pane_path:
636611
break
637-
elif time.time() > timeout:
638-
break
639612

640613
assert p.current_path, pane_path
641614

0 commit comments

Comments
 (0)