@@ -454,7 +454,18 @@ def check_content() -> bool:
454
454
if match_type == ContentMatchType .CONTAINS :
455
455
if not isinstance (content_pattern , str ):
456
456
raise TypeError (ERR_CONTAINS_TYPE )
457
+ content_str = "\n " .join (content )
458
+ if content_pattern in content_str :
459
+ result .matched_content = content_pattern
460
+ # Find which line contains the match
461
+ for i , line in enumerate (content ):
462
+ if content_pattern in line :
463
+ result .match_line = i
464
+ break
465
+ return True
466
+ return False
457
467
468
+ # Handle regex match type
458
469
if match_type == ContentMatchType .REGEX :
459
470
if isinstance (content_pattern , (str , re .Pattern )):
460
471
pattern = (
@@ -474,18 +485,7 @@ def check_content() -> bool:
474
485
return True
475
486
return False
476
487
raise TypeError (ERR_REGEX_TYPE )
477
-
478
- # Contains match (default)
479
- content_str = "\n " .join (content )
480
- if isinstance (content_pattern , str ) and content_pattern in content_str :
481
- result .matched_content = content_pattern
482
- # Find which line contains the match
483
- for i , line in enumerate (content ):
484
- if content_pattern in line :
485
- result .match_line = i
486
- break
487
- return True
488
- return False
488
+ return None
489
489
490
490
try :
491
491
success , exception = retry_until_extended (
@@ -494,10 +494,14 @@ def check_content() -> bool:
494
494
interval = interval ,
495
495
raises = raises ,
496
496
)
497
- result .success = success
498
497
if exception :
498
+ if raises :
499
+ raise
499
500
result .error = str (exception )
500
- return result
501
+ return result
502
+ else :
503
+ result .success = success
504
+ return result
501
505
except WaitTimeout as e :
502
506
if raises :
503
507
raise
@@ -778,15 +782,12 @@ def has_at_least_5_lines(content):
778
782
raise ValueError (msg )
779
783
780
784
# If match_types is a single value, convert to a list of the same value
781
- match_types_list : list [ContentMatchType ]
782
- if isinstance (match_types , ContentMatchType ):
783
- match_types_list = [match_types ] * len (content_patterns )
784
- else :
785
- match_types_list = match_types
786
-
787
- if len (match_types_list ) != len (content_patterns ):
785
+ if not isinstance (match_types , list ):
786
+ match_types = [match_types ] * len (content_patterns )
787
+ elif len (match_types ) != len (content_patterns ):
788
788
msg = (
789
- "If match_types is a list, it must have the same length as content_patterns"
789
+ f"match_types list ({ len (match_types )} ) "
790
+ f"doesn't match patterns ({ len (content_patterns )} )"
790
791
)
791
792
raise ValueError (msg )
792
793
@@ -802,7 +803,7 @@ def check_any_content() -> bool:
802
803
result .content = content
803
804
804
805
for i , (pattern , match_type ) in enumerate (
805
- zip (content_patterns , match_types_list ),
806
+ zip (content_patterns , match_types ),
806
807
):
807
808
# Handle predicate match
808
809
if match_type == ContentMatchType .PREDICATE :
@@ -877,11 +878,15 @@ def check_any_content() -> bool:
877
878
interval = interval ,
878
879
raises = raises ,
879
880
)
880
- result .success = success
881
881
if exception :
882
+ if raises :
883
+ raise
882
884
result .error = str (exception )
883
- result .elapsed_time = time .time () - start_time
884
- return result
885
+ return result
886
+ else :
887
+ result .success = success
888
+ result .elapsed_time = time .time () - start_time
889
+ return result
885
890
except WaitTimeout as e :
886
891
if raises :
887
892
raise
@@ -972,22 +977,19 @@ def has_at_least_5_lines(content):
972
977
ContentMatchType.PREDICATE
973
978
)
974
979
"""
975
- # If match_types is a single value, convert to a list of the same value
976
- match_types_list : list [ContentMatchType ]
977
- if isinstance (match_types , ContentMatchType ):
978
- match_types_list = [match_types ] * len (content_patterns )
979
- else :
980
- match_types_list = match_types
981
-
982
- if len (match_types_list ) != len (content_patterns ):
980
+ # Convert single match_type to list of same type
981
+ if not isinstance (match_types , list ):
982
+ match_types = [match_types ] * len (content_patterns )
983
+ elif len (match_types ) != len (content_patterns ):
983
984
msg = (
984
- "If match_types is a list, it must have the same length as content_patterns"
985
+ f"match_types list ({ len (match_types )} ) "
986
+ f"doesn't match patterns ({ len (content_patterns )} )"
985
987
)
986
988
raise ValueError (msg )
987
989
988
990
result = WaitResult (success = False )
989
- start_time = time .time ()
990
991
matched_patterns : list [str ] = []
992
+ start_time = time .time ()
991
993
992
994
def check_all_content () -> bool :
993
995
content = pane .capture_pane (start = start , end = end )
@@ -998,7 +1000,7 @@ def check_all_content() -> bool:
998
1000
matched_patterns .clear ()
999
1001
1000
1002
for i , (pattern , match_type ) in enumerate (
1001
- zip (content_patterns , match_types_list ),
1003
+ zip (content_patterns , match_types ),
1002
1004
):
1003
1005
# Handle predicate match
1004
1006
if match_type == ContentMatchType .PREDICATE :
@@ -1062,11 +1064,15 @@ def check_all_content() -> bool:
1062
1064
interval = interval ,
1063
1065
raises = raises ,
1064
1066
)
1065
- result .success = success
1066
1067
if exception :
1068
+ if raises :
1069
+ raise
1067
1070
result .error = str (exception )
1068
- result .elapsed_time = time .time () - start_time
1069
- return result
1071
+ return result
1072
+ else :
1073
+ result .success = success
1074
+ result .elapsed_time = time .time () - start_time
1075
+ return result
1070
1076
except WaitTimeout as e :
1071
1077
if raises :
1072
1078
raise
@@ -1099,7 +1105,8 @@ def _contains_match(
1099
1105
for i , line in enumerate (content ):
1100
1106
if pattern in line :
1101
1107
return True , pattern , i
1102
- # If we somehow didn't find it in any individual line but it was in the joined string
1108
+ # If we somehow didn't find it in any individual line but it was in the
1109
+ # joined string
1103
1110
return True , pattern , None
1104
1111
return False , None , None
1105
1112
0 commit comments