Skip to content

Commit 492a8b1

Browse files
committed
test(waiter): add tests for invalid match type combinations
Add tests to validate error handling for invalid match type combinations, covering: - Mismatched lengths of patterns and match types - Invalid pattern types for specific match types - Empty pattern lists - Non-callable patterns with PREDICATE match type - Mixed match types with invalid pattern type combinations These tests ensure the library raises appropriate exceptions with helpful error messages when invalid inputs are provided.
1 parent 291a6ff commit 492a8b1

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

tests/_internal/test_waiter.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2017,3 +2017,76 @@ def test_wait_for_pane_content_whitespace(wait_pane: Pane) -> None:
20172017
assert result.success
20182018
assert result.matched_content is not None
20192019
assert " " in result.matched_content
2020+
2021+
2022+
def test_invalid_match_type_combinations(wait_pane: Pane) -> None:
2023+
"""Test various invalid match type combinations for wait functions.
2024+
2025+
This comprehensive test validates that appropriate errors are raised
2026+
when invalid combinations of patterns and match types are provided.
2027+
"""
2028+
# Prepare the pane
2029+
wait_pane.send_keys("clear", enter=True)
2030+
wait_until_pane_ready(wait_pane, timeout=2.0)
2031+
2032+
# Case 1: wait_for_any_content with mismatched lengths
2033+
with pytest.raises(ValueError) as excinfo:
2034+
wait_for_any_content(
2035+
wait_pane,
2036+
["pattern1", "pattern2", "pattern3"], # 3 patterns
2037+
[ContentMatchType.CONTAINS, ContentMatchType.REGEX], # Only 2 match types
2038+
timeout=0.5,
2039+
)
2040+
assert "match_types list" in str(excinfo.value)
2041+
assert "doesn't match patterns" in str(excinfo.value)
2042+
2043+
# Case 2: wait_for_any_content with invalid pattern type for CONTAINS
2044+
with pytest.raises(TypeError) as excinfo:
2045+
wait_for_any_content(
2046+
wait_pane,
2047+
[123], # type: ignore # Integer not valid for CONTAINS
2048+
ContentMatchType.CONTAINS,
2049+
timeout=0.5,
2050+
)
2051+
assert "must be a string" in str(excinfo.value)
2052+
2053+
# Case 3: wait_for_all_content with empty patterns list
2054+
with pytest.raises(ValueError) as excinfo:
2055+
wait_for_all_content(
2056+
wait_pane,
2057+
[], # Empty patterns list
2058+
ContentMatchType.CONTAINS,
2059+
timeout=0.5,
2060+
)
2061+
assert "At least one content pattern" in str(excinfo.value)
2062+
2063+
# Case 4: wait_for_all_content with mismatched lengths
2064+
with pytest.raises(ValueError) as excinfo:
2065+
wait_for_all_content(
2066+
wait_pane,
2067+
["pattern1", "pattern2"], # 2 patterns
2068+
[ContentMatchType.CONTAINS], # Only 1 match type
2069+
timeout=0.5,
2070+
)
2071+
assert "match_types list" in str(excinfo.value)
2072+
assert "doesn't match patterns" in str(excinfo.value)
2073+
2074+
# Case 5: wait_for_pane_content with wrong pattern type for PREDICATE
2075+
with pytest.raises(TypeError) as excinfo:
2076+
wait_for_pane_content(
2077+
wait_pane,
2078+
"not callable", # String not valid for PREDICATE
2079+
ContentMatchType.PREDICATE,
2080+
timeout=0.5,
2081+
)
2082+
assert "must be callable" in str(excinfo.value)
2083+
2084+
# Case 6: Mixed match types with invalid pattern types
2085+
with pytest.raises(TypeError) as excinfo:
2086+
wait_for_any_content(
2087+
wait_pane,
2088+
["valid string", re.compile(r"\d+"), 123], # type: ignore
2089+
[ContentMatchType.CONTAINS, ContentMatchType.REGEX, ContentMatchType.EXACT],
2090+
timeout=0.5,
2091+
)
2092+
assert "Pattern at index 2" in str(excinfo.value)

0 commit comments

Comments
 (0)