Coverage for tests/test_completion/test_sanitization.py: 100%
10 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-04-14 00:18 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2025-04-14 00:18 +0000
1from importlib.machinery import ModuleSpec 1iabcdefgh
2from typing import Union 1iabcdefgh
3from unittest.mock import patch 1iabcdefgh
5import pytest 1iabcdefgh
6from typer._completion_classes import _sanitize_help_text 1iabcdefgh
9@pytest.mark.parametrize( 1iabcdefgh
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: 1iabcdefgh
38 assert _sanitize_help_text(help_text) == expected 1iabcdefgh
39 mock_find_spec.assert_called_once_with("rich") 1iabcdefgh