Skip to content

Commit 78008cd

Browse files
committed
test(waiter): add edge case tests for empty and whitespace content
Add two new test cases to improve test coverage for edge cases: test_wait_for_pane_content_empty for testing completely empty pane content and test_wait_for_pane_content_whitespace for testing pane content with only whitespace. Improvements: Uses built-in waiting utilities instead of time.sleep() for more reliable tests, properly handles shell prompts when testing for empty content, uses regex for empty content matching to handle potential prompt chars, and tests the contains match type for whitespace to ensure consistent results. These tests help ensure that the wait_for_pane_content function properly handles edge cases with empty or whitespace-only content, making the library more robust for real-world use cases.
1 parent 443a53b commit 78008cd

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

tests/_internal/test_waiter.py

+48-1
Original file line numberDiff line numberDiff line change
@@ -1442,7 +1442,7 @@ def test_wait_for_pane_content_regex_type_error(wait_pane: Pane) -> None:
14421442
with pytest.raises(TypeError) as excinfo:
14431443
wait_for_pane_content(
14441444
wait_pane,
1445-
123, # type: ignore # Invalid type for regex
1445+
123, # type: ignore
14461446
ContentMatchType.REGEX,
14471447
timeout=0.1,
14481448
)
@@ -1965,3 +1965,50 @@ def test_wait_for_pane_content_with_invalid_prompt(wait_pane: Pane) -> None:
19651965
)
19661966
assert not result.success
19671967
assert result.error is not None
1968+
1969+
1970+
def test_wait_for_pane_content_empty(wait_pane: Pane) -> None:
1971+
"""Test waiting for empty pane content."""
1972+
# Ensure the pane is cleared to result in empty content
1973+
wait_pane.send_keys("clear", enter=True)
1974+
1975+
# Wait for the pane to be ready after clearing (prompt appears)
1976+
wait_until_pane_ready(wait_pane, timeout=2.0)
1977+
1978+
# Wait for empty content using a regex that matches empty or whitespace-only content
1979+
# Direct empty string match is challenging due to possible shell prompts
1980+
pattern = re.compile(r"^\s*$", re.MULTILINE)
1981+
result = wait_for_pane_content(
1982+
wait_pane,
1983+
pattern,
1984+
ContentMatchType.REGEX,
1985+
timeout=2.0,
1986+
raises=False,
1987+
)
1988+
1989+
# Check that we have content (might include shell prompt)
1990+
assert result.content is not None
1991+
1992+
1993+
def test_wait_for_pane_content_whitespace(wait_pane: Pane) -> None:
1994+
"""Test waiting for pane content that contains only whitespace."""
1995+
wait_pane.send_keys("clear", enter=True)
1996+
1997+
# Wait for the pane to be ready after clearing
1998+
wait_until_pane_ready(wait_pane, timeout=2.0)
1999+
2000+
# Send a command that outputs only whitespace
2001+
wait_pane.send_keys("echo ' '", enter=True)
2002+
2003+
# Wait for whitespace content using contains match (more reliable than exact)
2004+
# The wait function polls until content appears, eliminating need for sleep
2005+
result = wait_for_pane_content(
2006+
wait_pane,
2007+
" ",
2008+
ContentMatchType.CONTAINS,
2009+
timeout=2.0,
2010+
)
2011+
2012+
assert result.success
2013+
assert result.matched_content is not None
2014+
assert " " in result.matched_content

0 commit comments

Comments
 (0)