test_doc.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. from textwrap import dedent
  2. from pandas.util._decorators import doc
  3. @doc(method="cumsum", operation="sum")
  4. def cumsum(whatever):
  5. """
  6. This is the {method} method.
  7. It computes the cumulative {operation}.
  8. """
  9. @doc(
  10. cumsum,
  11. dedent(
  12. """
  13. Examples
  14. --------
  15. >>> cumavg([1, 2, 3])
  16. 2
  17. """
  18. ),
  19. method="cumavg",
  20. operation="average",
  21. )
  22. def cumavg(whatever):
  23. pass
  24. @doc(cumsum, method="cummax", operation="maximum")
  25. def cummax(whatever):
  26. pass
  27. @doc(cummax, method="cummin", operation="minimum")
  28. def cummin(whatever):
  29. pass
  30. def test_docstring_formatting():
  31. docstr = dedent(
  32. """
  33. This is the cumsum method.
  34. It computes the cumulative sum.
  35. """
  36. )
  37. assert cumsum.__doc__ == docstr
  38. def test_docstring_appending():
  39. docstr = dedent(
  40. """
  41. This is the cumavg method.
  42. It computes the cumulative average.
  43. Examples
  44. --------
  45. >>> cumavg([1, 2, 3])
  46. 2
  47. """
  48. )
  49. assert cumavg.__doc__ == docstr
  50. def test_doc_template_from_func():
  51. docstr = dedent(
  52. """
  53. This is the cummax method.
  54. It computes the cumulative maximum.
  55. """
  56. )
  57. assert cummax.__doc__ == docstr
  58. def test_inherit_doc_template():
  59. docstr = dedent(
  60. """
  61. This is the cummin method.
  62. It computes the cumulative minimum.
  63. """
  64. )
  65. assert cummin.__doc__ == docstr