Skip to content

Commit

Permalink
Merge pull request #54 from consideRatio/pr/add-test-for-help-strings…
Browse files Browse the repository at this point in the history
…-in-dicts-etc

Bound `traitlets<5.10` and add test for issue observed in newer versions
  • Loading branch information
manics authored Sep 27, 2023
2 parents 5632a2a + 8c611c5 commit b2238d8
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 2 deletions.
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ dynamic = ["version"]
requires-python = ">=3.7"
dependencies = [
"sphinx>=4",
"traitlets>=4",
# FIXME: traitlets are upper bounded as a workaround to
# https://github.com/jupyterhub/autodoc-traits/issues/55
"traitlets>=4,<5.10",
]

[project.optional-dependencies]
Expand Down
67 changes: 66 additions & 1 deletion tests/docs/sample_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
autodoc_traits against. It does not contain tests.
"""

from traitlets import Bool
from traitlets import Bool, Dict, Instance, Integer, Unicode, Union
from traitlets.config.configurable import Configurable


Expand Down Expand Up @@ -81,3 +81,68 @@ def subclass_non_trait_property(self):

def subclass_method(self):
"""subclass_method docstring"""


class TraitTypesSampleConfigurable(Configurable):
"""TraitTypesSampleConfigurable docstring"""

trait_integer = Integer(
help="""trait_integer help text""",
config=True,
)
trait_integer_nohelp = Integer(
config=True,
)
trait_integer_noconfig = Integer(
help="""trait_integer_noconfig help text""",
)

trait_unicode = Unicode(
help="""trait_unicode help text""",
config=True,
)
trait_unicode_nohelp = Unicode(
config=True,
)
trait_unicode_noconfig = Unicode(
help="""trait_unicode_noconfig help text""",
)

trait_dict = Dict(
help="""trait_dict help text""",
config=True,
)
trait_dict_nohelp = Dict(
config=True,
)
trait_dict_noconfig = Dict(
help="""trait_dict_noconfig help text""",
)

trait_instance = Instance(
klass=SampleConfigurable,
help="""trait_instance help text""",
config=True,
)
trait_instance_nohelp = Instance(
klass=SampleConfigurable,
config=True,
)
trait_instance_noconfig = Instance(
klass=SampleConfigurable,
help="""trait_instance_noconfig help text""",
)

trait_union = Union(
[Integer(), Unicode()],
help="""trait_union help text""",
config=True,
)
trait_union_nohelp = Union(
[Integer(), Unicode()],
config=True,
)
trait_union_noconfig = Union(
[Integer(), Unicode()],
help="""trait_union_noconfig help text""",
)
15 changes: 15 additions & 0 deletions tests/docs/source/autotrait/help.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,18 @@ Test that we present the trait's provided ``help``.

.. autotrait:: sample_module.SampleConfigurable.trait
:noindex:

.. autotrait:: sample_module.TraitTypesSampleConfigurable.trait_integer
:noindex:

.. autotrait:: sample_module.TraitTypesSampleConfigurable.trait_unicode
:noindex:

.. autotrait:: sample_module.TraitTypesSampleConfigurable.trait_dict
:noindex:

.. autotrait:: sample_module.TraitTypesSampleConfigurable.trait_instance
:noindex:

.. autotrait:: sample_module.TraitTypesSampleConfigurable.trait_union
:noindex:
6 changes: 6 additions & 0 deletions tests/test_autodoc_traits.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def test_sphinx_build_all_docs(temp_docs_dir, monkeypatch):
"SampleConfigurableSubclass docstring",
"SampleNonConfigurable docstring",
"SampleNonConfigurableSubclass docstring",
"TraitTypesSampleConfigurable docstring",
],
[],
),
Expand All @@ -107,6 +108,11 @@ def test_sphinx_build_all_docs(temp_docs_dir, monkeypatch):
[
"c.SampleConfigurable.trait",
"trait help text",
"trait_integer help text",
"trait_unicode help text",
"trait_dict help text",
"trait_instance help text",
"trait_union help text",
],
[],
),
Expand Down

0 comments on commit b2238d8

Please sign in to comment.