Skip to content

Commit c0f2062

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 78008cd commit c0f2062

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

tests/_internal/test_waiter.py

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

0 commit comments

Comments
 (0)