Skip to content

Use retry_until in more places #781

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from libtmux.test import TEST_SESSION_PREFIX, get_test_session_name, namer

logger = logging.getLogger(__name__)
USING_ZSH = "zsh" in os.getenv("SHELL", "")


@pytest.fixture(autouse=True, scope="session")
Expand All @@ -24,6 +25,18 @@ def user_path(home_path: pathlib.Path):
return p


@pytest.mark.skipif(USING_ZSH, reason="Using ZSH")
@pytest.fixture(autouse=USING_ZSH, scope="session")
def zshrc(user_path: pathlib.Path):
"""This quiets ZSH default message.

Needs a startup file .zshenv, .zprofile, .zshrc, .zlogin.
"""
p = user_path / ".zshrc"
p.touch()
return p


@pytest.fixture(autouse=True)
def home_path_default(user_path: pathlib.Path):
os.environ["HOME"] = str(user_path)
Expand Down
54 changes: 31 additions & 23 deletions tests/test_workspacebuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ def f():
history_cmd = captured_pane.stdout[-2].strip()

return assertCase(sent_cmd, history_cmd)

assert retry_until(f), f"Unknown sent command: [{sent_cmd}] in {assertCase}"


Expand Down Expand Up @@ -329,6 +330,7 @@ def test_window_shell(session):
def f():
session.server._update_windows()
return w["window_name"] != "top"

retry_until(f)

assert w.name != "top"
Expand Down Expand Up @@ -447,6 +449,7 @@ def test_start_directory(session, tmp_path: pathlib.Path):

for path, window in zip(dirs, session.windows):
for p in window.panes:

def f():
p.server._update_panes()
pane_path = p.current_path
Expand Down Expand Up @@ -497,6 +500,7 @@ def test_start_directory_relative(session, tmp_path: pathlib.Path):

for path, window in zip(dirs, session.windows):
for p in window.panes:

def f():
p.server._update_panes()
# Handle case where directories resolve to /private/ in OSX
Expand Down Expand Up @@ -558,6 +562,7 @@ def test_pane_order(session):
def f():
p.server._update_panes()
return p.current_path == pane_path

retry_until(f)

assert p.current_path, pane_path
Expand Down Expand Up @@ -1014,17 +1019,20 @@ def test_load_workspace_enter(
builder = WorkspaceBuilder(sconf=sconfig, server=server)
builder.build()

time.sleep(1)

session = builder.session
pane = session.attached_pane

captured_pane = "\n".join(pane.capture_pane())
def fn():
captured_pane = "\n".join(pane.capture_pane())

if should_see:
assert output in captured_pane
else:
assert output not in captured_pane
if should_see:
return output in captured_pane
else:
return output not in captured_pane

assert retry_until(
fn, 1
), f'Should{" " if should_see else "not "} output in captured pane'


@pytest.mark.parametrize(
Expand All @@ -1038,12 +1046,12 @@ def test_load_workspace_enter(
- panes:
- shell_command:
- cmd: echo "___$((1 + 5))___"
sleep_before: 2
sleep_before: .15
- cmd: echo "___$((1 + 3))___"
sleep_before: 1
sleep_before: .35
"""
),
1.5,
0.5,
"___4___",
],
[
Expand All @@ -1054,12 +1062,12 @@ def test_load_workspace_enter(
- panes:
- shell_command:
- cmd: echo "___$((1 + 5))___"
sleep_before: 2
- cmd: echo "___$((1 + 3))___"
sleep_before: 1
- cmd: echo "___$((1 + 3))___"
sleep_before: .25
"""
),
3,
1.25,
"___4___",
],
[
Expand All @@ -1070,10 +1078,10 @@ def test_load_workspace_enter(
- panes:
- shell_command:
- cmd: echo "___$((1 + 3))___"
sleep_before: 2
sleep_before: .5
"""
),
2,
0.5,
"___4___",
],
[
Expand All @@ -1084,10 +1092,10 @@ def test_load_workspace_enter(
- panes:
- shell_command:
- cmd: echo "___$((1 + 3))___"
sleep_before: 2
sleep_before: 1
"""
),
2,
1,
"___4___",
],
[
Expand All @@ -1096,21 +1104,21 @@ def test_load_workspace_enter(
session_name: Should not execute
shell_command_before:
- cmd: echo "sleeping before"
sleep_before: 2
sleep_before: .5
windows:
- panes:
- echo "___$((1 + 3))___"
"""
),
2,
0.5,
"___4___",
],
],
ids=[
"command_level_sleep_3_shortform",
"command_level_pane_sleep_3_longform",
"pane_sleep_2_shortform",
"pane_sleep_2_longform",
"command_level_sleep_shortform",
"command_level_pane_sleep_longform",
"pane_sleep_shortform",
"pane_sleep_longform",
"shell_before_before_command_level",
],
)
Expand Down