test_printers_exceptions.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # Exception classes used when testing the Python pretty printers.
  2. #
  3. # Copyright (C) 2016-2019 Free Software Foundation, Inc.
  4. # This file is part of the GNU C Library.
  5. #
  6. # The GNU C Library is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU Lesser General Public
  8. # License as published by the Free Software Foundation; either
  9. # version 2.1 of the License, or (at your option) any later version.
  10. #
  11. # The GNU C Library is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. # Lesser General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU Lesser General Public
  17. # License along with the GNU C Library; if not, see
  18. # <http://www.gnu.org/licenses/>.
  19. class NoLineError(Exception):
  20. """Custom exception to indicate that a test file doesn't contain
  21. the requested string.
  22. """
  23. def __init__(self, file_name, string):
  24. """Constructor.
  25. Args:
  26. file_name (string): The name of the test file.
  27. string (string): The string that was requested.
  28. """
  29. super(NoLineError, self).__init__()
  30. self.file_name = file_name
  31. self.string = string
  32. def __str__(self):
  33. """Shows a readable representation of the exception."""
  34. return ('File {0} has no line containing the following string: {1}'
  35. .format(self.file_name, self.string))
  36. class DebugError(Exception):
  37. """Custom exception to indicate that a required debugging symbol is missing.
  38. """
  39. def __init__(self, symbol):
  40. """Constructor.
  41. Args:
  42. symbol (string): The name of the entity whose debug info is missing.
  43. """
  44. super(DebugError, self).__init__()
  45. self.symbol = symbol
  46. def __str__(self):
  47. """Shows a readable representation of the exception."""
  48. return ('The required debugging information for {0} is missing.'
  49. .format(self.symbol))