Coverage for tests / utils.py: 100%
24 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-11-18 11:12 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-11-18 11:12 +0000
1import re 1abcdefghij
2import sys 1abcdefghij
3from os import getenv 1abcdefghij
5import pytest 1abcdefghij
6from typer._completion_shared import _get_shell_name 1abcdefghij
7from typer.core import HAS_RICH 1abcdefghij
9needs_linux = pytest.mark.skipif( 1abcdefghij
10 not sys.platform.startswith("linux"), reason="Test requires Linux"
11)
12needs_macos = pytest.mark.skipif( 1abcdefghij
13 not sys.platform.startswith("darwin"), reason="Test requires macOS"
14)
15needs_windows = pytest.mark.skipif( 1abcdefghij
16 not sys.platform.startswith("win"), reason="Test requires Windows"
17)
18skip_if_windows = pytest.mark.skipif( 1abcdefghij
19 sys.platform == "win32",
20 reason="Test should not be run on Windows",
21)
23needs_rich = pytest.mark.skipif(not HAS_RICH, reason="Test requires Rich") 1abcdefghij
25shell = _get_shell_name() 1abcdefghij
26needs_bash = pytest.mark.skipif( 1abcdefghij
27 shell is None or "bash" not in shell, reason="Test requires Bash"
28)
30requires_completion_permission = pytest.mark.skipif( 1abcdefghij
31 not getenv("_TYPER_RUN_INSTALL_COMPLETION_TESTS", False),
32 reason="Test requires permission to run completion installation tests",
33)
36def strip_double_spaces(text: str) -> str: 1abcdefghij
37 return re.sub(r" {2,}", " ", text) 1abcdefghij
40def normalize_rich_output( 1abcdefghij
41 text: str, replace_with: str = "*", squash_whitespaces: bool = True
42) -> str:
43 """
44 Replace all rich formatting characters with a simple placeholder.
45 """
46 text = re.sub(r"\x1b\[[0-9;]*m", replace_with, text) 1abcdefghij
47 text = re.sub(r"[\u2500-\u257F]", replace_with, text) 1abcdefghij
48 text = re.sub(r"[\U0001F300-\U0001F6FF]", replace_with, text) 1abcdefghij
49 text = re.sub(f"{re.escape(replace_with)}+", replace_with, text) 1abcdefghij
50 if squash_whitespaces: 1abcdefghij
51 text = strip_double_spaces(text) 1abcdefghij
52 return text 1abcdefghij