Skip to content
Myr

utils.py

This file

Path

tests/utils.py

45 lines · 1.3 KiB · Python

Last changed by

🐛 Ensure that `typer.launch` forwards correctly when launching a file (#1708)Sofie Van Landeghembefore adoption31b468b

History of this file

Take it

The walk stopped after 200 commits: lines older than da1e440 point at it.

⬆ Bump pillow from 11.3.0 to 12.1.1 (#1550)dependabot[bot]before adoptionda1e440

lines 1–11why, one step back
1import re
2import sys3from os import getenv45import pytest6from typer._completion_shared import _get_shell_name7from typer.core import HAS_RICH89needs_linux = pytest.mark.skipif(10 not sys.platform.startswith("linux"), reason="Test requires Linux"11)

🐛 Ensure that `typer.launch` forwards correctly when launching a file (#1708)Sofie Van Landeghembefore adoption31b468b

lines 12–14why, one step back
12needs_windows = pytest.mark.skipif(
13 not sys.platform.startswith("win"), reason="Test requires Windows"14)

⬆ Bump pillow from 11.3.0 to 12.1.1 (#1550)dependabot[bot]before adoptionda1e440

lines 15–45why, one step back
15
16needs_rich = pytest.mark.skipif(not HAS_RICH, reason="Test requires Rich")1718shell = _get_shell_name()19needs_bash = pytest.mark.skipif(20 shell is None or "bash" not in shell, reason="Test requires Bash"21)2223requires_completion_permission = pytest.mark.skipif(24 not getenv("_TYPER_RUN_INSTALL_COMPLETION_TESTS", False),25 reason="Test requires permission to run completion installation tests",26)272829def strip_double_spaces(text: str) -> str:30 return re.sub(r" {2,}", " ", text)313233def normalize_rich_output(34 text: str, replace_with: str = "*", squash_whitespaces: bool = True35) -> str:36 """37 Replace all rich formatting characters with a simple placeholder.38 """39 text = re.sub(r"\x1b\[[0-9;]*m", replace_with, text)40 text = re.sub(r"[\u2500-\u257F]", replace_with, text)41 text = re.sub(r"[\U0001F300-\U0001F6FF]", replace_with, text)42 text = re.sub(f"{re.escape(replace_with)}+", replace_with, text)43 if squash_whitespaces:44 text = strip_double_spaces(text)45 return text