test_traitlets_docstring.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. """Tests for traitlets.traitlets."""
  2. # Copyright (c) IPython Development Team.
  3. # Distributed under the terms of the Modified BSD License.
  4. #
  5. from __future__ import annotations
  6. from traitlets import Dict, Instance, Integer, Unicode, Union
  7. from traitlets.config import Configurable
  8. def test_handle_docstring():
  9. class SampleConfigurable(Configurable):
  10. pass
  11. class TraitTypesSampleConfigurable(Configurable):
  12. """TraitTypesSampleConfigurable docstring"""
  13. trait_integer = Integer(
  14. help="""trait_integer help text""",
  15. config=True,
  16. )
  17. trait_integer_nohelp = Integer(
  18. config=True,
  19. )
  20. trait_integer_noconfig = Integer(
  21. help="""trait_integer_noconfig help text""",
  22. )
  23. trait_unicode = Unicode(
  24. help="""trait_unicode help text""",
  25. config=True,
  26. )
  27. trait_unicode_nohelp = Unicode(
  28. config=True,
  29. )
  30. trait_unicode_noconfig = Unicode(
  31. help="""trait_unicode_noconfig help text""",
  32. )
  33. trait_dict = Dict(
  34. help="""trait_dict help text""",
  35. config=True,
  36. )
  37. trait_dict_nohelp = Dict(
  38. config=True,
  39. )
  40. trait_dict_noconfig = Dict(
  41. help="""trait_dict_noconfig help text""",
  42. )
  43. trait_instance = Instance(
  44. klass=SampleConfigurable,
  45. help="""trait_instance help text""",
  46. config=True,
  47. )
  48. trait_instance_nohelp = Instance(
  49. klass=SampleConfigurable,
  50. config=True,
  51. )
  52. trait_instance_noconfig = Instance(
  53. klass=SampleConfigurable,
  54. help="""trait_instance_noconfig help text""",
  55. )
  56. trait_union = Union(
  57. [Integer(), Unicode()],
  58. help="""trait_union help text""",
  59. config=True,
  60. )
  61. trait_union_nohelp = Union(
  62. [Integer(), Unicode()],
  63. config=True,
  64. )
  65. trait_union_noconfig = Union(
  66. [Integer(), Unicode()],
  67. help="""trait_union_noconfig help text""",
  68. )
  69. base_names = SampleConfigurable().trait_names()
  70. for name in TraitTypesSampleConfigurable().trait_names():
  71. if name in base_names:
  72. continue
  73. doc = getattr(TraitTypesSampleConfigurable, name).__doc__
  74. if "nohelp" not in name:
  75. assert doc == f"{name} help text"