Skip to content

Commit 0c1f173

Browse files
committed
test(env): Use wait_for_line() for environment propagation tests
why: Control mode is asynchronous; tests assuming immediate output availability with capture_pane()[-2] fail intermittently. what: - Update 6 environment tests to use wait_for_line() polling - Add shell prompt handling to _match() function - Import wait_for_line helper in legacy test files Affected tests: - test_session.py: test_new_session_with_environment - test_session.py: test_new_window_with_environment - test_window.py: test_split_window_with_environment - legacy_api/test_session.py: test_new_session_with_environment - legacy_api/test_session.py: test_new_window_with_environment - legacy_api/test_window.py: test_split_window_with_environment
1 parent 4d1f9c0 commit 0c1f173

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

tests/legacy_api/test_session.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from libtmux.test.constants import TEST_SESSION_PREFIX
1515
from libtmux.test.random import namer
1616
from libtmux.window import Window
17+
from tests.helpers import wait_for_line
1718

1819
if t.TYPE_CHECKING:
1920
from libtmux.server import Server
@@ -280,4 +281,11 @@ def test_new_window_with_environment(
280281
assert pane is not None
281282
for k, v in environment.items():
282283
pane.send_keys(f"echo ${k}")
283-
assert pane.capture_pane()[-2] == v
284+
285+
def _match(line: str, expected: str = v) -> bool:
286+
stripped = line.strip()
287+
# Match exact value or value after shell prompt ($ prefix)
288+
return stripped == expected or stripped == f"$ {expected}"
289+
290+
lines = wait_for_line(pane, _match)
291+
assert any(_match(line) for line in lines)

tests/legacy_api/test_window.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from libtmux.pane import Pane
1414
from libtmux.server import Server
1515
from libtmux.window import Window
16+
from tests.helpers import wait_for_line
1617

1718
if t.TYPE_CHECKING:
1819
from libtmux.session import Session
@@ -383,4 +384,11 @@ def test_split_window_with_environment(
383384
assert pane is not None
384385
for k, v in environment.items():
385386
pane.send_keys(f"echo ${k}")
386-
assert pane.capture_pane()[-2] == v
387+
388+
def _match(line: str, expected: str = v) -> bool:
389+
stripped = line.strip()
390+
# Match exact value or value after shell prompt ($ prefix)
391+
return stripped == expected or stripped == f"$ {expected}"
392+
393+
lines = wait_for_line(pane, _match)
394+
assert any(_match(line) for line in lines)

tests/test_session.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,9 @@ def test_new_window_with_environment(
333333
pane.send_keys(f"echo ${k}")
334334

335335
def _match(line: str, expected: str = v) -> bool:
336-
return line.strip() == expected
336+
stripped = line.strip()
337+
# Match exact value or value after shell prompt ($ prefix)
338+
return stripped == expected or stripped == f"$ {expected}"
337339

338340
lines = wait_for_line(pane, _match)
339341
assert any(_match(line) for line in lines)

tests/test_window.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,9 @@ def test_split_with_environment(
462462
pane.send_keys(f"echo ${k}")
463463

464464
def _match(line: str, expected: str = v) -> bool:
465-
return line.strip() == expected
465+
stripped = line.strip()
466+
# Match exact value or value after shell prompt ($ prefix)
467+
return stripped == expected or stripped == f"$ {expected}"
466468

467469
lines = wait_for_line(pane, _match)
468470
assert any(_match(line) for line in lines)

0 commit comments

Comments
 (0)