Coverage for tests / utils.py: 100%
20 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
1import re 1abcdefgh
2import sys 1abcdefgh
3from os import getenv 1abcdefgh
5import pytest 1abcdefgh
6from typer._completion_shared import _get_shell_name 1abcdefgh
8needs_py310 = pytest.mark.skipif( 1abcdefgh
9 sys.version_info < (3, 10), reason="requires python3.10+"
10)
12needs_linux = pytest.mark.skipif( 1abcdefgh
13 not sys.platform.startswith("linux"), reason="Test requires Linux"
14)
16shell = _get_shell_name() 1abcdefgh
17needs_bash = pytest.mark.skipif( 1abcdefgh
18 shell is None or "bash" not in shell, reason="Test requires Bash"
19)
21requires_completion_permission = pytest.mark.skipif( 1abcdefgh
22 not getenv("_TYPER_RUN_INSTALL_COMPLETION_TESTS", False),
23 reason="Test requires permission to run completion installation tests",
24)
27def strip_double_spaces(text: str) -> str: 1abcdefgh
28 return re.sub(r" {2,}", " ", text) 1abcdefgh
31def normalize_rich_output( 1abcdefgh
32 text: str, replace_with: str = "*", squash_whitespaces: bool = True
33) -> str:
34 """
35 Replace all rich formatting characters with a simple placeholder.
36 """
37 text = re.sub(r"\x1b\[[0-9;]*m", replace_with, text) 1abcdefgh
38 text = re.sub(r"[\u2500-\u257F]", replace_with, text) 1abcdefgh
39 text = re.sub(r"[\U0001F300-\U0001F6FF]", replace_with, text) 1abcdefgh
40 text = re.sub(f"{re.escape(replace_with)}+", replace_with, text) 1abcdefgh
41 if squash_whitespaces: 1abcdefgh
42 text = strip_double_spaces(text) 1abcdefgh
43 return text 1abcdefgh