Skip to content
Myr

utils.py

This file

Path

tests/utils.py

46 lines 路 1.3 KiB 路 Python

Last changed by

馃悰 Fix highlighting of optional variadic argument metavars (#1508)Benjy Wienerbefore adoptiona2215eb

History of this file

Take it

1import re2import sys3from os import getenv45import pytest6from typer._completion_shared import _get_shell_name7from typer.core import HAS_RICH89needs_py310 = pytest.mark.skipif(10    sys.version_info < (3, 10), reason="requires python3.10+"11)1213needs_linux = pytest.mark.skipif(14    not sys.platform.startswith("linux"), reason="Test requires Linux"15)1617needs_rich = pytest.mark.skipif(not HAS_RICH, reason="Test requires Rich")1819shell = _get_shell_name()20needs_bash = pytest.mark.skipif(21    shell is None or "bash" not in shell, reason="Test requires Bash"22)2324requires_completion_permission = pytest.mark.skipif(25    not getenv("_TYPER_RUN_INSTALL_COMPLETION_TESTS", False),26    reason="Test requires permission to run completion installation tests",27)282930def strip_double_spaces(text: str) -> str:31    return re.sub(r" {2,}", " ", text)323334def normalize_rich_output(35    text: str, replace_with: str = "*", squash_whitespaces: bool = True36) -> str:37    """38    Replace all rich formatting characters with a simple placeholder.39    """40    text = re.sub(r"\x1b\[[0-9;]*m", replace_with, text)41    text = re.sub(r"[\u2500-\u257F]", replace_with, text)42    text = re.sub(r"[\U0001F300-\U0001F6FF]", replace_with, text)43    text = re.sub(f"{re.escape(replace_with)}+", replace_with, text)44    if squash_whitespaces:45        text = strip_double_spaces(text)46    return text