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
The walk stopped after 200 commits: lines older than 7afa636 point at it.
✅ Add missing tests for code examples (#1465)Motov Yuriibefore adoption75bf405
line 1why, one step back1import re🔖 Release version 0.19.1Sebastián Ramírezbefore adoption7afa636
lines 2–5why, one step back2import sys3from os import getenv45import pytest♻️ Refactor the handling of `shellingham` (#1347)Nathan McDougallbefore adoptionfd4241f
line 6why, one step back6from typer._completion_shared import _get_shell_name🔖 Release version 0.19.1Sebastián Ramírezbefore adoption7afa636
lines 7–15why, one step back78needs_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 back16shell = _get_shell_name()🔖 Release version 0.19.1Sebastián Ramírezbefore adoption7afa636
line 17why, one step back17needs_bash = pytest.mark.skipif(♻️ Refactor the handling of `shellingham` (#1347)Nathan McDougallbefore adoptionfd4241f
line 18why, one step back18 shell is None or "bash" not in shell, reason="Test requires Bash"🔖 Release version 0.19.1Sebastián Ramírezbefore adoption7afa636
lines 19–24why, one step back19)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 back252627def 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