Skip to content

Commit 835df53

Browse files
committed
test: add test for _flatten_message
1 parent d0414b2 commit 835df53

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

google/api_core/_python_version_support.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ class VersionInfo(NamedTuple):
144144

145145
def _flatten_message(text: str) -> str:
146146
"""Dedent a multi-line string and flatten it into a single line."""
147-
return textwrap.dedent(text).strip().replace("\n", " ")
147+
return " ".join(textwrap.dedent(text).strip().split())
148148

149149

150150
# TODO(https://github.com/googleapis/python-api-core/issues/835): Remove once we

tests/unit/test_python_version_support.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
# Code to be tested
2424
from google.api_core._python_version_support import (
25+
_flatten_message,
2526
check_python_version,
2627
PythonVersionStatus,
2728
PYTHON_VERSION_INFO,
@@ -31,6 +32,17 @@
3132
VersionInfoMock = namedtuple("VersionInfoMock", ["major", "minor"])
3233

3334

35+
def test_flatten_message():
36+
"""Test that _flatten_message correctly dedents and flattens a string."""
37+
input_text = """
38+
This is a multi-line
39+
string with some
40+
indentation.
41+
"""
42+
expected_output = "This is a multi-line string with some indentation."
43+
assert _flatten_message(input_text) == expected_output
44+
45+
3446
def _create_failure_message(
3547
expected, result, py_version, date, gapic_dep, py_eol, eol_warn, gapic_end
3648
):

0 commit comments

Comments
 (0)