From 31e7325408154a4bb027f89865d6527655c45ce3 Mon Sep 17 00:00:00 2001 From: Roland Walker Date: Fri, 3 Apr 2026 08:02:04 -0400 Subject: [PATCH] add tests for SQLResult --- test/pytests/test_sqlresult.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 test/pytests/test_sqlresult.py diff --git a/test/pytests/test_sqlresult.py b/test/pytests/test_sqlresult.py new file mode 100644 index 00000000..9c19293a --- /dev/null +++ b/test/pytests/test_sqlresult.py @@ -0,0 +1,29 @@ +from prompt_toolkit.formatted_text import FormattedText + +from mycli.packages.sqlresult import SQLResult + + +def test_sqlresult_str_includes_all_fields() -> None: + result = SQLResult( + preamble='before', + header=['id'], + rows=[(1,)], + postamble='after', + status='ok', + command={'name': 'watch', 'seconds': 1.0}, + ) + + assert 'before' in str(result) + assert "['id']" in str(result) + assert '[(1,)]' in str(result) + assert 'after' in str(result) + assert 'ok' in str(result) + assert "{'name': 'watch', 'seconds': 1.0}" in str(result) + + +def test_sqlresult_status_plain_handles_none_and_formatted_text() -> None: + empty = SQLResult() + formatted = SQLResult(status=FormattedText([('', '1 row in set'), ('', ', '), ('class:warn', '1 warning')])) + + assert empty.status_plain is None + assert formatted.status_plain == '1 row in set, 1 warning'