utils.py
This file
Path
tests/utils.py
43 lines · 1.2 KiB · Python
Last changed by
✅ Add missing tests for code examples (#1465)Motov Yuriibefore adoption75bf405
History of this fileTake it
1import re2import sys3from os import getenv45import pytest6from typer._completion_shared import _get_shell_name78needs_py310 = pytest.mark.skipif(9 sys.version_info < (3, 10), reason="requires python3.10+"10)1112needs_linux = pytest.mark.skipif(13 not sys.platform.startswith("linux"), reason="Test requires Linux"14)1516shell = _get_shell_name()17needs_bash = pytest.mark.skipif(18 shell is None or "bash" not in shell, reason="Test requires Bash"19)2021requires_completion_permission = pytest.mark.skipif(22 not getenv("_TYPER_RUN_INSTALL_COMPLETION_TESTS", False),23 reason="Test requires permission to run completion installation tests",24)252627def strip_double_spaces(text: str) -> str:28 return re.sub(r" {2,}", " ", text)293031def normalize_rich_output(32 text: str, replace_with: str = "*", squash_whitespaces: bool = True33) -> 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)38 text = re.sub(r"[\u2500-\u257F]", replace_with, text)39 text = re.sub(r"[\U0001F300-\U0001F6FF]", replace_with, text)40 text = re.sub(f"{re.escape(replace_with)}+", replace_with, text)41 if squash_whitespaces:42 text = strip_double_spaces(text)43 return text