test_errors.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import pytest
  2. from pandas.errors import AbstractMethodError
  3. import pandas as pd # noqa
  4. @pytest.mark.parametrize(
  5. "exc",
  6. [
  7. "UnsupportedFunctionCall",
  8. "UnsortedIndexError",
  9. "OutOfBoundsDatetime",
  10. "ParserError",
  11. "PerformanceWarning",
  12. "DtypeWarning",
  13. "EmptyDataError",
  14. "ParserWarning",
  15. "MergeError",
  16. ],
  17. )
  18. def test_exception_importable(exc):
  19. from pandas import errors
  20. e = getattr(errors, exc)
  21. assert e is not None
  22. # check that we can raise on them
  23. with pytest.raises(e):
  24. raise e()
  25. def test_catch_oob():
  26. from pandas import errors
  27. try:
  28. pd.Timestamp("15000101")
  29. except errors.OutOfBoundsDatetime:
  30. pass
  31. class Foo:
  32. @classmethod
  33. def classmethod(cls):
  34. raise AbstractMethodError(cls, methodtype="classmethod")
  35. @property
  36. def property(self):
  37. raise AbstractMethodError(self, methodtype="property")
  38. def method(self):
  39. raise AbstractMethodError(self)
  40. def test_AbstractMethodError_classmethod():
  41. xpr = "This classmethod must be defined in the concrete class Foo"
  42. with pytest.raises(AbstractMethodError, match=xpr):
  43. Foo.classmethod()
  44. xpr = "This property must be defined in the concrete class Foo"
  45. with pytest.raises(AbstractMethodError, match=xpr):
  46. Foo().property
  47. xpr = "This method must be defined in the concrete class Foo"
  48. with pytest.raises(AbstractMethodError, match=xpr):
  49. Foo().method()