test_utils.py 746 B

1234567891011121314151617181920
  1. import atheris # pragma: no cover
  2. from typing import List # pragma: no cover
  3. def is_expected_exception(
  4. error_message_list: List[str], exception: Exception
  5. ): # pragma: no cover
  6. """Checks if the message of a given exception matches any of the expected error messages.
  7. Args:
  8. error_message_list (List[str]): A list of error message substrings to check against the exception's message.
  9. exception (Exception): The exception object raised during execution.
  10. Returns:
  11. bool: True if the exception's message contains any of the substrings from the error_message_list, otherwise False.
  12. """
  13. for error in error_message_list:
  14. if error in str(exception):
  15. return True
  16. return False