diff --git a/changelog.md b/changelog.md index 8232ab34..2ff8fd7d 100644 --- a/changelog.md +++ b/changelog.md @@ -11,6 +11,7 @@ Features Bug Fixes --------- * Revert suppression of warnings when `sqlglotrs` is installed (fixed upstream). +* Update `cli_helpers` to v2.12.0, fixing a `preserve_whitespace` bug with `tabulate`. Internal diff --git a/pyproject.toml b/pyproject.toml index 90feb6dc..5470ea98 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,7 +16,7 @@ dependencies = [ "sqlparse>=0.3.0,<0.6.0", "sqlglot[c] ~= 30.0.0", "configobj ~= 5.0.9", - "cli_helpers[styles] ~= 2.11.0", + "cli_helpers[styles] ~= 2.12.0", "wcwidth ~= 0.6.0", "pyperclip ~= 1.11.0", "pycryptodomex ~= 3.23.0", diff --git a/test/test_tabular_output.py b/test/test_tabular_output.py index 93459c32..7db01636 100644 --- a/test/test_tabular_output.py +++ b/test/test_tabular_output.py @@ -2,8 +2,10 @@ """Test the sql output adapter.""" +import os from textwrap import dedent +from cli_helpers.utils import strip_ansi from pymysql.constants import FIELD_TYPE import pytest @@ -11,6 +13,8 @@ from mycli.packages.sqlresult import SQLResult from test.utils import HOST, PASSWORD, PORT, USER, dbtest +default_config_file = os.path.join(os.path.dirname(__file__), "myclirc") + @pytest.fixture def mycli(): @@ -152,3 +156,23 @@ def description(self): output = mycli.format_sqlresult(SQLResult(header=header, rows=FakeCursor(), postamble=postamble)) actual = "\n".join(output) assert actual.endswith(postamble) + + +def test_tabulate_output_preserves_multiline_whitespace(monkeypatch, tmp_path): + monkeypatch.setenv("HOME", str(tmp_path)) + mycli = MyCli(myclirc=default_config_file) + mycli.helpers_style = None + mycli.helpers_warnings_style = None + + assert list(mycli.change_table_format("ascii")) == [SQLResult(status="Changed table format to ascii")] + + output = mycli.format_sqlresult(SQLResult(header=["text"], rows=[[" one\n two\nthree"]])) + + assert strip_ansi("\n".join(output)) == dedent("""\ + +------------+ + | text | + +------------+ + | one | + | two | + | three | + +------------+""")