Coverage for tests / test_completion / test_sanitization.py: 100%
10 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-02-09 12:36 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-02-09 12:36 +0000
1from importlib.machinery import ModuleSpec 1abcdefgh
2from typing import Union 1abcdefgh
3from unittest.mock import patch 1abcdefgh
5import pytest 1abcdefgh
6from typer._completion_classes import _sanitize_help_text 1abcdefgh
9@pytest.mark.parametrize( 1abcdefgh
10 "find_spec, help_text, expected",
11 [
12 (
13 ModuleSpec("rich", loader=None),
14 "help text without rich tags",
15 "help text without rich tags",
16 ),
17 (
18 None,
19 "help text without rich tags",
20 "help text without rich tags",
21 ),
22 (
23 ModuleSpec("rich", loader=None),
24 "help [bold]with[/] rich tags",
25 "help with rich tags",
26 ),
27 (
28 None,
29 "help [bold]with[/] rich tags",
30 "help [bold]with[/] rich tags",
31 ),
32 ],
33)
34def test_sanitize_help_text( 1abcdefgh
35 find_spec: Union[ModuleSpec, None], help_text: str, expected: str
36):
37 with patch("importlib.util.find_spec", return_value=find_spec) as mock_find_spec: 1abcdefgh
38 assert _sanitize_help_text(help_text) == expected 1abcdefgh
39 mock_find_spec.assert_called_once_with("rich") 1abcdefgh