Skip to content
Myr

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 file

Take it

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

✅ Add missing tests for code examples (#1465)Motov Yuriibefore adoption75bf405

line 1why, one step back
1import re

📝 Update release notesgithub-actions[bot]before adoption116ebab

lines 2–5why, one step back
2import sys
3from os import getenv45import pytest

♻️ Refactor the handling of `shellingham` (#1347)Nathan McDougallbefore adoptionfd4241f

line 6why, one step back
6from typer._completion_shared import _get_shell_name

📝 Update release notesgithub-actions[bot]before adoption116ebab

lines 7–15why, one step back
7
8needs_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)15

♻️ Refactor the handling of `shellingham` (#1347)Nathan McDougallbefore adoptionfd4241f

line 16why, one step back
16shell = _get_shell_name()

📝 Update release notesgithub-actions[bot]before adoption116ebab

line 17why, one step back
17needs_bash = pytest.mark.skipif(

♻️ Refactor the handling of `shellingham` (#1347)Nathan McDougallbefore adoptionfd4241f

line 18why, one step back
18 shell is None or "bash" not in shell, reason="Test requires Bash"

📝 Update release notesgithub-actions[bot]before adoption116ebab

lines 19–24why, one step back
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)

✅ Add missing tests for code examples (#1465)Motov Yuriibefore adoption75bf405

lines 25–43why, one step back
25
2627def 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