Coverage for tests/test_completion/test_sanitization.py: 100%

10 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2025-12-19 20:29 +0000

1from importlib.machinery import ModuleSpec 1abcdefghi

2from typing import Union 1abcdefghi

3from unittest.mock import patch 1abcdefghi

4 

5import pytest 1abcdefghi

6from typer._completion_classes import _sanitize_help_text 1abcdefghi

7 

8 

9@pytest.mark.parametrize( 1abcdefghi

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( 1abcdefghi

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: 1abcdefghi

38 assert _sanitize_help_text(help_text) == expected 1abcdefghi

39 mock_find_spec.assert_called_once_with("rich") 1abcdefghi