Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions tests/test_completion/test_sanitization.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,13 @@ def test_sanitize_help_text(
with patch("importlib.util.find_spec", return_value=find_spec) as mock_find_spec:
assert _sanitize_help_text(help_text) == expected
mock_find_spec.assert_called_once_with("rich")


def test_sanitize_help_text_no_rich():
with patch("typer._completion_classes.HAS_RICH", False):
with patch("importlib.util.find_spec") as mock_find_spec:
assert (
_sanitize_help_text("help [bold]with[/] rich tags")
== "help [bold]with[/] rich tags"
)
mock_find_spec.assert_not_called()
3 changes: 2 additions & 1 deletion typer/_completion_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
COMPLETION_SCRIPT_ZSH,
Shells,
)
from .core import HAS_RICH


def _sanitize_help_text(text: str) -> str:
"""Sanitizes the help text by removing rich tags"""
if not importlib.util.find_spec("rich"):
if not HAS_RICH or not importlib.util.find_spec("rich"):
return text
from . import rich_utils

Expand Down
Loading